@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,37 @@
|
|
|
1
|
+
import { Icon } from "../Icon/Icon.js";
|
|
2
|
+
import { chip, selectedMark } from "./Chip.styles.js";
|
|
3
|
+
import { Check } from "lucide-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/ui/Chip/Chip.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A small pill. With `onClick` it is a toggle `button` with `aria-pressed`;
|
|
8
|
+
* without it, a static `span` that only labels.
|
|
9
|
+
*/
|
|
10
|
+
function Chip({ children, icon, selected = false, onClick, className, ...rest }) {
|
|
11
|
+
const actionable = onClick !== void 0;
|
|
12
|
+
const classes = chip({
|
|
13
|
+
actionable,
|
|
14
|
+
selected
|
|
15
|
+
});
|
|
16
|
+
const merged = className ? `${classes} ${className}` : classes;
|
|
17
|
+
const glyph = selected ? /* @__PURE__ */ jsx(Icon, {
|
|
18
|
+
icon: Check,
|
|
19
|
+
className: selectedMark
|
|
20
|
+
}) : icon ? /* @__PURE__ */ jsx(Icon, { icon }) : null;
|
|
21
|
+
if (actionable) return /* @__PURE__ */ jsxs("button", {
|
|
22
|
+
...rest,
|
|
23
|
+
type: "button",
|
|
24
|
+
className: merged,
|
|
25
|
+
"aria-pressed": selected,
|
|
26
|
+
onClick,
|
|
27
|
+
children: [glyph, children]
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
30
|
+
...rest,
|
|
31
|
+
className: merged,
|
|
32
|
+
children: [glyph, children]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export { Chip };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=Chip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chip.js","names":[],"sources":["../../../src/ui/Chip/Chip.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { Check } from \"lucide-react\";\nimport type { HTMLAttributes, MouseEventHandler, ReactNode } from \"react\";\nimport { Icon, type IconComponent } from \"../Icon\";\nimport { chip, selectedMark } from \"./Chip.css\";\n\n/** Props for {@link Chip}. */\nexport interface ChipProps\n extends Omit<HTMLAttributes<HTMLElement>, \"children\" | \"onClick\"> {\n /** The chip text. */\n readonly children: ReactNode;\n /** A leading icon, imported by name from `lucide-react`. */\n readonly icon?: IconComponent;\n /**\n * Whether the chip is on. Shown with a check icon in place of the leading\n * icon. On a chip with `onClick` it is also `aria-pressed`.\n */\n readonly selected?: boolean;\n /** Makes the chip a toggle button. Without it the chip is a plain label. */\n readonly onClick?: MouseEventHandler<HTMLButtonElement>;\n}\n\n/**\n * A small pill. With `onClick` it is a toggle `button` with `aria-pressed`;\n * without it, a static `span` that only labels.\n */\nexport function Chip({\n children,\n icon,\n selected = false,\n onClick,\n className,\n ...rest\n}: ChipProps) {\n const actionable = onClick !== undefined;\n const classes = chip({ actionable, selected });\n const merged = className ? `${classes} ${className}` : classes;\n const leadingIcon = icon ? <Icon icon={icon} /> : null;\n const glyph = selected ? (\n <Icon icon={Check} className={selectedMark} />\n ) : (\n leadingIcon\n );\n if (actionable) {\n return (\n <button\n {...rest}\n type=\"button\"\n className={merged}\n aria-pressed={selected}\n onClick={onClick}\n >\n {glyph}\n {children}\n </button>\n );\n }\n return (\n <span {...rest} className={merged}>\n {glyph}\n {children}\n </span>\n );\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,KAAK,EACnB,UACA,MACA,WAAW,OACX,SACA,WACA,GAAG,QACS;CACZ,MAAM,aAAa,YAAY,KAAA;CAC/B,MAAM,UAAU,KAAK;EAAE;EAAY;CAAS,CAAC;CAC7C,MAAM,SAAS,YAAY,GAAG,QAAQ,GAAG,cAAc;CAEvD,MAAM,QAAQ,WACZ,oBAAC,MAAD;EAAM,MAAM;EAAO,WAAW;CAAe,CAAA,IAF3B,OAAO,oBAAC,MAAD,EAAY,KAAO,CAAA,IAAI;CAMlD,IAAI,YACF,OACE,qBAAC,UAAD;EACE,GAAI;EACJ,MAAK;EACL,WAAW;EACX,gBAAc;EACL;EALX,UAAA,CAOG,OACA,QACK;;CAGZ,OACE,qBAAC,QAAD;EAAM,GAAI;EAAM,WAAW;EAA3B,UAAA,CACG,OACA,QACG;;AAEV"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
4
|
+
// src/ui/Chip/Chip.css.ts
|
|
5
|
+
var chip = createRuntimeFn({
|
|
6
|
+
defaultClassName: "_1ek6et30",
|
|
7
|
+
variantClassNames: {
|
|
8
|
+
actionable: {
|
|
9
|
+
true: "_1ek6et31",
|
|
10
|
+
false: "_1ek6et32"
|
|
11
|
+
},
|
|
12
|
+
selected: {
|
|
13
|
+
true: "_1ek6et33",
|
|
14
|
+
false: "_1ek6et34"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
actionable: false,
|
|
19
|
+
selected: false
|
|
20
|
+
},
|
|
21
|
+
compoundVariants: [[{
|
|
22
|
+
actionable: true,
|
|
23
|
+
selected: false
|
|
24
|
+
}, "_1ek6et35"]]
|
|
25
|
+
});
|
|
26
|
+
var selectedMark = "_1ek6et36";
|
|
27
|
+
export { chip, selectedMark };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=Chip.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chip.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Surface } from "../Surface/Surface.js";
|
|
2
|
+
import { controlGroup } from "./ControlGroup.styles.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/ui/ControlGroup/ControlGroup.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Icon buttons stacked on one floating surface, separated by hairlines. It is
|
|
7
|
+
* a plain `group`, not a toolbar, so it adds no arrow-key behaviour.
|
|
8
|
+
* @remarks Children should be `IconButton`s, which keep their 48 px targets.
|
|
9
|
+
* Pass `data-chrome` through for the layout owner.
|
|
10
|
+
*/
|
|
11
|
+
function ControlGroup({ label, className, children, ...rest }) {
|
|
12
|
+
return /* @__PURE__ */ jsx(Surface, {
|
|
13
|
+
...rest,
|
|
14
|
+
role: "group",
|
|
15
|
+
"aria-label": label,
|
|
16
|
+
radius: "control",
|
|
17
|
+
className: className ? `${controlGroup} ${className}` : controlGroup,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { ControlGroup };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=ControlGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlGroup.js","names":[],"sources":["../../../src/ui/ControlGroup/ControlGroup.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { HTMLAttributes } from \"react\";\nimport { Surface } from \"../Surface\";\nimport { controlGroup } from \"./ControlGroup.css\";\n\n/** Props for {@link ControlGroup}. */\nexport interface ControlGroupProps\n extends Omit<HTMLAttributes<HTMLElement>, \"aria-label\" | \"role\"> {\n /** The accessible name of the group, for example \"Zoom\". */\n readonly label: string;\n}\n\n/**\n * Icon buttons stacked on one floating surface, separated by hairlines. It is\n * a plain `group`, not a toolbar, so it adds no arrow-key behaviour.\n * @remarks Children should be `IconButton`s, which keep their 48 px targets.\n * Pass `data-chrome` through for the layout owner.\n */\nexport function ControlGroup({\n label,\n className,\n children,\n ...rest\n}: ControlGroupProps) {\n return (\n <Surface\n {...rest}\n role=\"group\"\n aria-label={label}\n radius=\"control\"\n className={className ? `${controlGroup} ${className}` : controlGroup}\n >\n {children}\n </Surface>\n );\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,aAAa,EAC3B,OACA,WACA,UACA,GAAG,QACiB;CACpB,OACE,oBAAC,SAAD;EACE,GAAI;EACJ,MAAK;EACL,cAAY;EACZ,QAAO;EACP,WAAW,YAAY,GAAG,aAAa,GAAG,cAAc;EAEvD;CACM,CAAA;AAEb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlGroup.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Icon } from "../Icon/Icon.js";
|
|
2
|
+
import { action, body, emptyIcon, emptyState, heading } from "./EmptyState.styles.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/ui/EmptyState/EmptyState.tsx
|
|
5
|
+
/**
|
|
6
|
+
* What a list or panel shows when it has nothing to show: an icon, a real
|
|
7
|
+
* heading, an explanation and an optional action. The heading is never empty,
|
|
8
|
+
* because a blank heading is announced as a heading with no name.
|
|
9
|
+
*/
|
|
10
|
+
function EmptyState({ icon, heading: headingText, headingLevel = 2, children, action: actionNode, className, ...rest }) {
|
|
11
|
+
const Heading = `h${headingLevel}`;
|
|
12
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
13
|
+
...rest,
|
|
14
|
+
className: className ? `${emptyState} ${className}` : emptyState,
|
|
15
|
+
children: [
|
|
16
|
+
icon ? /* @__PURE__ */ jsx(Icon, {
|
|
17
|
+
icon,
|
|
18
|
+
className: emptyIcon
|
|
19
|
+
}) : null,
|
|
20
|
+
headingText.trim() === "" ? null : /* @__PURE__ */ jsx(Heading, {
|
|
21
|
+
className: heading,
|
|
22
|
+
children: headingText
|
|
23
|
+
}),
|
|
24
|
+
children ? /* @__PURE__ */ jsx("p", {
|
|
25
|
+
className: body,
|
|
26
|
+
children
|
|
27
|
+
}) : null,
|
|
28
|
+
actionNode ? /* @__PURE__ */ jsx("div", {
|
|
29
|
+
className: action,
|
|
30
|
+
children: actionNode
|
|
31
|
+
}) : null
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export { EmptyState };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=EmptyState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmptyState.js","names":[],"sources":["../../../src/ui/EmptyState/EmptyState.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { Icon, type IconComponent } from \"../Icon\";\nimport { action, body, emptyIcon, emptyState, heading } from \"./EmptyState.css\";\n\n/** Props for {@link EmptyState}. */\nexport interface EmptyStateProps\n extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** A decorative icon above the heading, imported by name from `lucide-react`. */\n readonly icon?: IconComponent;\n /** The heading text. A blank heading renders no heading element at all. */\n readonly heading: string;\n /** The heading level, 2 to 6. Pick the level that fits the page outline. */\n readonly headingLevel?: 2 | 3 | 4 | 5 | 6;\n /** The explanation, rendered as one paragraph. */\n readonly children?: ReactNode;\n /** An optional next step, usually a `Button`. */\n readonly action?: ReactNode;\n}\n\n/**\n * What a list or panel shows when it has nothing to show: an icon, a real\n * heading, an explanation and an optional action. The heading is never empty,\n * because a blank heading is announced as a heading with no name.\n */\nexport function EmptyState({\n icon,\n heading: headingText,\n headingLevel = 2,\n children,\n action: actionNode,\n className,\n ...rest\n}: EmptyStateProps) {\n const Heading = `h${headingLevel}` as const;\n return (\n <div\n {...rest}\n className={className ? `${emptyState} ${className}` : emptyState}\n >\n {icon ? <Icon icon={icon} className={emptyIcon} /> : null}\n {headingText.trim() === \"\" ? null : (\n <Heading className={heading}>{headingText}</Heading>\n )}\n {children ? <p className={body}>{children}</p> : null}\n {actionNode ? <div className={action}>{actionNode}</div> : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,WAAW,EACzB,MACA,SAAS,aACT,eAAe,GACf,UACA,QAAQ,YACR,WACA,GAAG,QACe;CAClB,MAAM,UAAU,IAAI;CACpB,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,WAAW,YAAY,GAAG,WAAW,GAAG,cAAc;EAFxD,UAAA;GAIG,OAAO,oBAAC,MAAD;IAAY;IAAM,WAAW;GAAY,CAAA,IAAI;GACpD,YAAY,KAAK,MAAM,KAAK,OAC3B,oBAAC,SAAD;IAAS,WAAW;IAAU,UAAA;GAAqB,CAAA;GAEpD,WAAW,oBAAC,KAAD;IAAG,WAAW;IAAO;GAAY,CAAA,IAAI;GAChD,aAAa,oBAAC,OAAD;IAAK,WAAW;IAAS,UAAA;GAAgB,CAAA,IAAI;EACxD;;AAET"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
// src/ui/EmptyState/EmptyState.css.ts
|
|
3
|
+
var emptyState = "_10svanz0";
|
|
4
|
+
var emptyIcon = "_10svanz1";
|
|
5
|
+
var heading = "_10svanz2";
|
|
6
|
+
var body = "_10svanz3";
|
|
7
|
+
var action = "_10svanz4";
|
|
8
|
+
export { action, body, emptyIcon, emptyState, heading };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=EmptyState.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmptyState.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { icon, mirroredInRtl, spinning } from "./Icon.styles.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/ui/Icon/Icon.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Draws one icon at the system size and stroke width. Decorative by default
|
|
6
|
+
* (`aria-hidden`); pass `label` when it carries meaning on its own.
|
|
7
|
+
*/
|
|
8
|
+
function Icon({ icon: Glyph, label, spinning: isSpinning = false, mirrorInRtl = false, className, ...rest }) {
|
|
9
|
+
const classes = [
|
|
10
|
+
icon,
|
|
11
|
+
isSpinning ? spinning : "",
|
|
12
|
+
mirrorInRtl ? mirroredInRtl : "",
|
|
13
|
+
className ?? ""
|
|
14
|
+
].filter(Boolean).join(" ");
|
|
15
|
+
const accessibility = label === void 0 ? { "aria-hidden": true } : {
|
|
16
|
+
role: "img",
|
|
17
|
+
"aria-label": label
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(Glyph, {
|
|
20
|
+
focusable: "false",
|
|
21
|
+
...rest,
|
|
22
|
+
...accessibility,
|
|
23
|
+
className: classes
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { Icon };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=Icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.js","names":[],"sources":["../../../src/ui/Icon/Icon.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { ComponentType, SVGProps } from \"react\";\nimport { icon, mirroredInRtl, spinning } from \"./Icon.css\";\n\n/**\n * The shape of an icon component such as a lucide icon. Callers import the\n * icon by name from `lucide-react` and pass it in.\n */\nexport type IconComponent = ComponentType<\n SVGProps<SVGSVGElement> & {\n size?: number | string;\n strokeWidth?: number | string;\n }\n>;\n\n/** Props for {@link Icon}. */\nexport interface IconProps\n extends Omit<SVGProps<SVGSVGElement>, \"ref\" | \"children\"> {\n /** The icon component to draw, for example `Search` from `lucide-react`. */\n readonly icon: IconComponent;\n /**\n * An accessible name. Give one only when the icon is the sole content of\n * something; the icon then becomes `role=\"img\"`. Without it the icon is\n * hidden from assistive technology.\n */\n readonly label?: string;\n /** Rotates the icon continuously. Stops under `prefers-reduced-motion`. */\n readonly spinning?: boolean;\n /**\n * Flips the icon when the page reads right to left. Set it on an icon that\n * points along the reading direction, such as a back arrow or a next\n * chevron; leave it off for one that does not.\n */\n readonly mirrorInRtl?: boolean;\n}\n\n/**\n * Draws one icon at the system size and stroke width. Decorative by default\n * (`aria-hidden`); pass `label` when it carries meaning on its own.\n */\nexport function Icon({\n icon: Glyph,\n label,\n spinning: isSpinning = false,\n mirrorInRtl = false,\n className,\n ...rest\n}: IconProps) {\n const classes = [\n icon,\n isSpinning ? spinning : \"\",\n mirrorInRtl ? mirroredInRtl : \"\",\n className ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n const accessibility =\n label === undefined\n ? ({ \"aria-hidden\": true } as const)\n : ({ role: \"img\", \"aria-label\": label } as const);\n return (\n <Glyph focusable=\"false\" {...rest} {...accessibility} className={classes} />\n );\n}\n"],"mappings":";;;;;;;AAyCA,SAAgB,KAAK,EACnB,MAAM,OACN,OACA,UAAU,aAAa,OACvB,cAAc,OACd,WACA,GAAG,QACS;CACZ,MAAM,UAAU;EACd;EACA,aAAa,WAAW;EACxB,cAAc,gBAAgB;EAC9B,aAAa;CACf,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;CACX,MAAM,gBACJ,UAAU,KAAA,IACL,EAAE,eAAe,KAAK,IACtB;EAAE,MAAM;EAAO,cAAc;CAAM;CAC1C,OACE,oBAAC,OAAD;EAAO,WAAU;EAAQ,GAAI;EAAM,GAAI;EAAe,WAAW;CAAU,CAAA;AAE/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Icon } from "../Icon/Icon.js";
|
|
2
|
+
import { iconButton, iconSlot, pressedBar } from "./IconButton.styles.js";
|
|
3
|
+
import { LoaderCircle } from "lucide-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/ui/IconButton/IconButton.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A button that shows only an icon. It activates on click (pointer up or
|
|
8
|
+
* keyboard) and never on pointer down, so a press can be cancelled by moving
|
|
9
|
+
* away before release.
|
|
10
|
+
*/
|
|
11
|
+
function IconButton({ label, icon, mirrorInRtl = false, pressed, busy = false, disabled = false, expanded, controls, size = "control", className, onClick, ...rest }) {
|
|
12
|
+
const classes = iconButton({
|
|
13
|
+
size,
|
|
14
|
+
pressed: pressed === true
|
|
15
|
+
});
|
|
16
|
+
const handleClick = (event) => {
|
|
17
|
+
if (disabled || busy) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
onClick?.(event);
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
24
|
+
...rest,
|
|
25
|
+
type: "button",
|
|
26
|
+
className: className ? `${classes} ${className}` : classes,
|
|
27
|
+
"aria-label": label,
|
|
28
|
+
"aria-pressed": pressed,
|
|
29
|
+
"aria-expanded": expanded,
|
|
30
|
+
"aria-controls": controls,
|
|
31
|
+
"aria-busy": busy ? true : void 0,
|
|
32
|
+
"aria-disabled": disabled ? true : void 0,
|
|
33
|
+
onClick: handleClick,
|
|
34
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
35
|
+
icon: busy ? LoaderCircle : icon,
|
|
36
|
+
spinning: busy,
|
|
37
|
+
mirrorInRtl,
|
|
38
|
+
className: iconSlot
|
|
39
|
+
}), pressed === true ? /* @__PURE__ */ jsx("span", {
|
|
40
|
+
className: pressedBar,
|
|
41
|
+
"aria-hidden": "true"
|
|
42
|
+
}) : null]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export { IconButton };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=IconButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconButton.js","names":[],"sources":["../../../src/ui/IconButton/IconButton.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { LoaderCircle } from \"lucide-react\";\nimport type { ButtonHTMLAttributes, MouseEvent } from \"react\";\nimport { Icon, type IconComponent } from \"../Icon\";\nimport { iconButton, iconSlot, pressedBar } from \"./IconButton.css\";\n\n/** Props for {@link IconButton}. */\nexport interface IconButtonProps\n extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n | \"aria-busy\"\n | \"aria-controls\"\n | \"aria-disabled\"\n | \"aria-expanded\"\n | \"aria-label\"\n | \"aria-pressed\"\n | \"children\"\n | \"disabled\"\n | \"type\"\n > {\n /** The accessible name. Describe the action, for example \"Zoom in\". */\n readonly label: string;\n /** The icon to show, imported by name from `lucide-react`. */\n readonly icon: IconComponent;\n /** Flips the icon when the page reads right to left, for one that points along the reading direction. */\n readonly mirrorInRtl?: boolean;\n /**\n * Makes it a toggle. Renders `aria-pressed` and a shape change (tinted fill\n * plus a bar under the icon). Leave undefined for a plain action button.\n */\n readonly pressed?: boolean;\n /**\n * Shows a loader in place of the icon and sets `aria-busy`. Clicks are\n * ignored while busy. The loader spins only when motion is allowed.\n */\n readonly busy?: boolean;\n /**\n * Disables the action with `aria-disabled`. The button stays focusable so\n * its name is still discoverable, and clicks do nothing.\n */\n readonly disabled?: boolean;\n /** Sets `aria-expanded` for a button that opens a popover or panel. */\n readonly expanded?: boolean;\n /** Sets `aria-controls` to the id of the element it opens or changes. */\n readonly controls?: string;\n /** `control` is 48 px square and `compact` is 44 px. Defaults to `control`. */\n readonly size?: \"control\" | \"compact\";\n}\n\n/**\n * A button that shows only an icon. It activates on click (pointer up or\n * keyboard) and never on pointer down, so a press can be cancelled by moving\n * away before release.\n */\nexport function IconButton({\n label,\n icon,\n mirrorInRtl = false,\n pressed,\n busy = false,\n disabled = false,\n expanded,\n controls,\n size = \"control\",\n className,\n onClick,\n ...rest\n}: IconButtonProps) {\n const classes = iconButton({ size, pressed: pressed === true });\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n if (disabled || busy) {\n event.preventDefault();\n return;\n }\n onClick?.(event);\n };\n return (\n <button\n {...rest}\n type=\"button\"\n className={className ? `${classes} ${className}` : classes}\n aria-label={label}\n aria-pressed={pressed}\n aria-expanded={expanded}\n aria-controls={controls}\n aria-busy={busy ? true : undefined}\n aria-disabled={disabled ? true : undefined}\n onClick={handleClick}\n >\n <Icon\n icon={busy ? LoaderCircle : icon}\n spinning={busy}\n mirrorInRtl={mirrorInRtl}\n className={iconSlot}\n />\n {pressed === true ? (\n <span className={pressedBar} aria-hidden=\"true\" />\n ) : null}\n </button>\n );\n}\n"],"mappings":";;;;;;;;;;AAuDA,SAAgB,WAAW,EACzB,OACA,MACA,cAAc,OACd,SACA,OAAO,OACP,WAAW,OACX,UACA,UACA,OAAO,WACP,WACA,SACA,GAAG,QACe;CAClB,MAAM,UAAU,WAAW;EAAE;EAAM,SAAS,YAAY;CAAK,CAAC;CAC9D,MAAM,eAAe,UAAyC;EAC5D,IAAI,YAAY,MAAM;GACpB,MAAM,eAAe;GACrB;EACF;EACA,UAAU,KAAK;CACjB;CACA,OACE,qBAAC,UAAD;EACE,GAAI;EACJ,MAAK;EACL,WAAW,YAAY,GAAG,QAAQ,GAAG,cAAc;EACnD,cAAY;EACZ,gBAAc;EACd,iBAAe;EACf,iBAAe;EACf,aAAW,OAAO,OAAO,KAAA;EACzB,iBAAe,WAAW,OAAO,KAAA;EACjC,SAAS;EAVX,UAAA,CAYE,oBAAC,MAAD;GACE,MAAM,OAAO,eAAe;GAC5B,UAAU;GACG;GACb,WAAW;EACZ,CAAA,GACA,YAAY,OACX,oBAAC,QAAD;GAAM,WAAW;GAAY,eAAY;EAAQ,CAAA,IAC/C,IACE;;AAEZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
4
|
+
// src/ui/IconButton/IconButton.css.ts
|
|
5
|
+
var iconButton = createRuntimeFn({
|
|
6
|
+
defaultClassName: "_1y0yfb70",
|
|
7
|
+
variantClassNames: {
|
|
8
|
+
size: {
|
|
9
|
+
control: "_1y0yfb71",
|
|
10
|
+
compact: "_1y0yfb72"
|
|
11
|
+
},
|
|
12
|
+
pressed: {
|
|
13
|
+
true: "_1y0yfb73",
|
|
14
|
+
false: "_1y0yfb74"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
size: "control",
|
|
19
|
+
pressed: false
|
|
20
|
+
},
|
|
21
|
+
compoundVariants: []
|
|
22
|
+
});
|
|
23
|
+
var iconSlot = "_1y0yfb75";
|
|
24
|
+
var pressedBar = "_1y0yfb76";
|
|
25
|
+
export { iconButton, iconSlot, pressedBar };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=IconButton.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconButton.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
// src/ui/Isolate/Isolate.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Keeps a run of text in its own bidirectional context. Use it for anything
|
|
5
|
+
* that is not copy from the message catalogue and may differ in direction or
|
|
6
|
+
* language from its surroundings: a place name, an address, a feature title, a
|
|
7
|
+
* coordinate, a scale label or a number with its unit. In right-to-left text
|
|
8
|
+
* these would otherwise reorder, because the neighbouring punctuation and
|
|
9
|
+
* numbers take the direction of the paragraph.
|
|
10
|
+
*
|
|
11
|
+
* @remarks Renders a `bdi`, which isolates its content and, unless `figure` is
|
|
12
|
+
* set, takes its direction from the first strong letter. Pass `lang` where
|
|
13
|
+
* the language is known, so a screen reader pronounces a name in its own
|
|
14
|
+
* language. Text the catalogue substitutes into a sentence is isolated by
|
|
15
|
+
* the catalogue instead (`isolateParameters` in `createMessageCatalogue`).
|
|
16
|
+
*/
|
|
17
|
+
function Isolate({ figure = false, ...rest }) {
|
|
18
|
+
return figure ? /* @__PURE__ */ jsx("bdi", {
|
|
19
|
+
...rest,
|
|
20
|
+
dir: "ltr",
|
|
21
|
+
translate: "no"
|
|
22
|
+
}) : /* @__PURE__ */ jsx("bdi", { ...rest });
|
|
23
|
+
}
|
|
24
|
+
export { Isolate };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=Isolate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Isolate.js","names":[],"sources":["../../../src/ui/Isolate/Isolate.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { HTMLAttributes } from \"react\";\n\n/** Props for {@link Isolate}. */\nexport interface IsolateProps extends Omit<HTMLAttributes<HTMLElement>, \"dir\"> {\n /**\n * Marks ASCII figures that always read left to right, such as the signed\n * coordinates `formatLatLng` writes. It sets `dir=\"ltr\"` and\n * `translate=\"no\"`. Leave it off for a name, a distance or any text whose\n * direction depends on its letters.\n */\n readonly figure?: boolean;\n}\n\n/**\n * Keeps a run of text in its own bidirectional context. Use it for anything\n * that is not copy from the message catalogue and may differ in direction or\n * language from its surroundings: a place name, an address, a feature title, a\n * coordinate, a scale label or a number with its unit. In right-to-left text\n * these would otherwise reorder, because the neighbouring punctuation and\n * numbers take the direction of the paragraph.\n *\n * @remarks Renders a `bdi`, which isolates its content and, unless `figure` is\n * set, takes its direction from the first strong letter. Pass `lang` where\n * the language is known, so a screen reader pronounces a name in its own\n * language. Text the catalogue substitutes into a sentence is isolated by\n * the catalogue instead (`isolateParameters` in `createMessageCatalogue`).\n */\nexport function Isolate({ figure = false, ...rest }: IsolateProps) {\n return figure ? (\n <bdi {...rest} dir=\"ltr\" translate=\"no\" />\n ) : (\n <bdi {...rest} />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,SAAgB,QAAQ,EAAE,SAAS,OAAO,GAAG,QAAsB;CACjE,OAAO,SACL,oBAAC,OAAD;EAAK,GAAI;EAAM,KAAI;EAAM,WAAU;CAAM,CAAA,IAEzC,oBAAC,OAAD,EAAK,GAAI,KAAO,CAAA;AAEpB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/ui/Isolate/fillSlots.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Matches `{name}`, with the isolate controls a right-to-left catalogue puts
|
|
6
|
+
* around a substituted value (U+2068 before, U+2069 after) when the value was
|
|
7
|
+
* a placeholder of its own.
|
|
8
|
+
*/
|
|
9
|
+
var SLOT = /?\{(\w+)\}?/;
|
|
10
|
+
/**
|
|
11
|
+
* Splits `text` around its `{name}` slots and puts `slots[name]` in each, so
|
|
12
|
+
* a value in a sentence can be an element of its own, such as an `Isolate`.
|
|
13
|
+
* Get `text` from the catalogue by passing each slot's own placeholder as its
|
|
14
|
+
* parameter, for example `t("tools.directions.leg", { distance: "{distance}" })`.
|
|
15
|
+
* A name with no entry in `slots` is left as written.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function fillSlots(text, slots) {
|
|
20
|
+
return text.split(SLOT).map((part, index) => {
|
|
21
|
+
const piece = index % 2 === 0 ? part : slots[part] ?? `{${part}}`;
|
|
22
|
+
return /* @__PURE__ */ jsx(Fragment, { children: piece }, index);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export { fillSlots };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=fillSlots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fillSlots.js","names":[],"sources":["../../../src/ui/Isolate/fillSlots.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { Fragment, type ReactNode } from \"react\";\n\n/**\n * Matches `{name}`, with the isolate controls a right-to-left catalogue puts\n * around a substituted value (U+2068 before, U+2069 after) when the value was\n * a placeholder of its own.\n */\nconst SLOT = /?\\{(\\w+)\\}?/;\n\n/**\n * Splits `text` around its `{name}` slots and puts `slots[name]` in each, so\n * a value in a sentence can be an element of its own, such as an `Isolate`.\n * Get `text` from the catalogue by passing each slot's own placeholder as its\n * parameter, for example `t(\"tools.directions.leg\", { distance: \"{distance}\" })`.\n * A name with no entry in `slots` is left as written.\n *\n * @internal\n */\nexport function fillSlots(\n text: string,\n slots: Readonly<Record<string, ReactNode>>,\n): ReactNode {\n return text.split(SLOT).map((part, index) => {\n // `split` with one capture group alternates text and slot names.\n const piece = index % 2 === 0 ? part : (slots[part] ?? `{${part}}`);\n // biome-ignore lint/suspicious/noArrayIndexKey: the pieces are positional and never reorder.\n return <Fragment key={index}>{piece}</Fragment>;\n });\n}\n"],"mappings":";;;;;;;;AASA,IAAM,OAAO;;;;;;;;;;AAWb,SAAgB,UACd,MACA,OACW;CACX,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,MAAM,UAAU;EAE3C,MAAM,QAAQ,QAAQ,MAAM,IAAI,OAAQ,MAAM,SAAS,IAAI,KAAK;EAEhE,OAAO,oBAAC,UAAD,EAAA,UAAuB,MAAgB,GAAxB,KAAwB;CAChD,CAAC;AACH"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Icon } from "../Icon/Icon.js";
|
|
2
|
+
import { check, listRow, row, secondary, text, trailing } from "./ListRow.styles.js";
|
|
3
|
+
import { Check } from "lucide-react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/ui/ListRow/ListRow.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A list item for lists of places, layers and options. Render rows inside a
|
|
8
|
+
* `ul` (or `ol`). Without `onClick` the row is plain content; with it the row
|
|
9
|
+
* is a single full-width button, so the whole row is the target.
|
|
10
|
+
*/
|
|
11
|
+
function ListRow({ icon, label, secondary: secondaryText, trailing: trailingNode, selected = false, onClick, className, ...rest }) {
|
|
12
|
+
const classes = className ? `${listRow} ${className}` : listRow;
|
|
13
|
+
const current = selected ? "true" : void 0;
|
|
14
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15
|
+
icon ? /* @__PURE__ */ jsx(Icon, { icon }) : null,
|
|
16
|
+
/* @__PURE__ */ jsxs("span", {
|
|
17
|
+
className: text,
|
|
18
|
+
children: [/* @__PURE__ */ jsx("span", { children: label }), secondaryText ? /* @__PURE__ */ jsx("span", {
|
|
19
|
+
className: secondary,
|
|
20
|
+
children: secondaryText
|
|
21
|
+
}) : null]
|
|
22
|
+
}),
|
|
23
|
+
trailingNode ? /* @__PURE__ */ jsx("span", {
|
|
24
|
+
className: trailing,
|
|
25
|
+
children: trailingNode
|
|
26
|
+
}) : null,
|
|
27
|
+
selected ? /* @__PURE__ */ jsx(Icon, {
|
|
28
|
+
icon: Check,
|
|
29
|
+
className: check
|
|
30
|
+
}) : null
|
|
31
|
+
] });
|
|
32
|
+
const rowClass = row({
|
|
33
|
+
actionable: onClick !== void 0,
|
|
34
|
+
selected
|
|
35
|
+
});
|
|
36
|
+
if (onClick) return /* @__PURE__ */ jsx("li", {
|
|
37
|
+
...rest,
|
|
38
|
+
className: classes,
|
|
39
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
40
|
+
type: "button",
|
|
41
|
+
className: rowClass,
|
|
42
|
+
"aria-current": current,
|
|
43
|
+
onClick,
|
|
44
|
+
children: body
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
return /* @__PURE__ */ jsx("li", {
|
|
48
|
+
...rest,
|
|
49
|
+
className: classes,
|
|
50
|
+
"aria-current": current,
|
|
51
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
52
|
+
className: rowClass,
|
|
53
|
+
children: body
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { ListRow };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=ListRow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListRow.js","names":["_Fragment"],"sources":["../../../src/ui/ListRow/ListRow.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { Check } from \"lucide-react\";\nimport type { LiHTMLAttributes, MouseEventHandler, ReactNode } from \"react\";\nimport { Icon, type IconComponent } from \"../Icon\";\nimport { check, listRow, row, secondary, text, trailing } from \"./ListRow.css\";\n\n/** Props for {@link ListRow}. */\nexport interface ListRowProps\n extends Omit<LiHTMLAttributes<HTMLLIElement>, \"children\" | \"onClick\"> {\n /** A leading icon, imported by name from `lucide-react`. */\n readonly icon?: IconComponent;\n /** The row's main text. */\n readonly label: ReactNode;\n /** A second, quieter line under the label. */\n readonly secondary?: ReactNode;\n /** Anything to show at the end, such as a value. Rendered before the check. */\n readonly trailing?: ReactNode;\n /**\n * Marks the row as the current choice. Shown with a check icon and\n * `aria-current`, so selection does not depend on colour.\n */\n readonly selected?: boolean;\n /** Makes the whole row a full-width button inside the `li`. */\n readonly onClick?: MouseEventHandler<HTMLButtonElement>;\n}\n\n/**\n * A list item for lists of places, layers and options. Render rows inside a\n * `ul` (or `ol`). Without `onClick` the row is plain content; with it the row\n * is a single full-width button, so the whole row is the target.\n */\nexport function ListRow({\n icon,\n label,\n secondary: secondaryText,\n trailing: trailingNode,\n selected = false,\n onClick,\n className,\n ...rest\n}: ListRowProps) {\n const classes = className ? `${listRow} ${className}` : listRow;\n const current = selected ? (\"true\" as const) : undefined;\n const body = (\n <>\n {icon ? <Icon icon={icon} /> : null}\n <span className={text}>\n <span>{label}</span>\n {secondaryText ? (\n <span className={secondary}>{secondaryText}</span>\n ) : null}\n </span>\n {trailingNode ? <span className={trailing}>{trailingNode}</span> : null}\n {selected ? <Icon icon={Check} className={check} /> : null}\n </>\n );\n const rowClass = row({ actionable: onClick !== undefined, selected });\n if (onClick) {\n return (\n <li {...rest} className={classes}>\n <button\n type=\"button\"\n className={rowClass}\n aria-current={current}\n onClick={onClick}\n >\n {body}\n </button>\n </li>\n );\n }\n return (\n <li {...rest} className={classes} aria-current={current}>\n <div className={rowClass}>{body}</div>\n </li>\n );\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,QAAQ,EACtB,MACA,OACA,WAAW,eACX,UAAU,cACV,WAAW,OACX,SACA,WACA,GAAG,QACY;CACf,MAAM,UAAU,YAAY,GAAG,QAAQ,GAAG,cAAc;CACxD,MAAM,UAAU,WAAY,SAAmB,KAAA;CAC/C,MAAM,OACJ,qBAAAA,UAAA,EAAA,UAAA;EACG,OAAO,oBAAC,MAAD,EAAY,KAAO,CAAA,IAAI;EAC/B,qBAAC,QAAD;GAAM,WAAW;GAAjB,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA,GAClB,gBACC,oBAAC,QAAD;IAAM,WAAW;IAAY,UAAA;GAAoB,CAAA,IAC/C,IACA;;EACL,eAAe,oBAAC,QAAD;GAAM,WAAW;GAAW,UAAA;EAAmB,CAAA,IAAI;EAClE,WAAW,oBAAC,MAAD;GAAM,MAAM;GAAO,WAAW;EAAQ,CAAA,IAAI;CACtD,EAAA,CAAA;CAEJ,MAAM,WAAW,IAAI;EAAE,YAAY,YAAY,KAAA;EAAW;CAAS,CAAC;CACpE,IAAI,SACF,OACE,oBAAC,MAAD;EAAI,GAAI;EAAM,WAAW;EACvB,UAAA,oBAAC,UAAD;GACE,MAAK;GACL,WAAW;GACX,gBAAc;GACL;GAER,UAAA;EACK,CAAA;CACN,CAAA;CAGR,OACE,oBAAC,MAAD;EAAI,GAAI;EAAM,WAAW;EAAS,gBAAc;EAC9C,UAAA,oBAAC,OAAD;GAAK,WAAW;GAAW,UAAA;EAAU,CAAA;CACnC,CAAA;AAER"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
4
|
+
// src/ui/ListRow/ListRow.css.ts
|
|
5
|
+
var listRow = "a7b7ee0";
|
|
6
|
+
var row = createRuntimeFn({
|
|
7
|
+
defaultClassName: "a7b7ee1",
|
|
8
|
+
variantClassNames: {
|
|
9
|
+
actionable: {
|
|
10
|
+
true: "a7b7ee2",
|
|
11
|
+
false: "a7b7ee3"
|
|
12
|
+
},
|
|
13
|
+
selected: {
|
|
14
|
+
true: "a7b7ee4",
|
|
15
|
+
false: "a7b7ee5"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
actionable: false,
|
|
20
|
+
selected: false
|
|
21
|
+
},
|
|
22
|
+
compoundVariants: []
|
|
23
|
+
});
|
|
24
|
+
var text = "a7b7ee6";
|
|
25
|
+
var secondary = "a7b7ee7";
|
|
26
|
+
var trailing = "a7b7ee8";
|
|
27
|
+
var check = "a7b7ee9";
|
|
28
|
+
export { check, listRow, row, secondary, text, trailing };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=ListRow.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ListRow.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useOptionalMessages } from "../../services/hooks.js";
|
|
2
|
+
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
3
|
+
import { createAnnouncer } from "./announcer.js";
|
|
4
|
+
import { formatMessage } from "@mapcairn/core";
|
|
5
|
+
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
8
|
+
// src/ui/LiveRegion/LiveRegion.tsx
|
|
9
|
+
function isDevelopment() {
|
|
10
|
+
return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
|
|
11
|
+
}
|
|
12
|
+
var LiveRegionContext = createContext(null);
|
|
13
|
+
/** How many providers are mounted, to warn in development about a second. */
|
|
14
|
+
var mountedProviders = 0;
|
|
15
|
+
var warnedMissingProvider = false;
|
|
16
|
+
/** Does nothing. Returned outside a provider so callers need no null check. */
|
|
17
|
+
var ignore = () => void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Mounts the one app-wide announcer: a visually hidden polite `status` region
|
|
20
|
+
* and a visually hidden assertive `alert` region. Nothing else in the app may
|
|
21
|
+
* create a live region except `StatusMessage`, which is a visible message.
|
|
22
|
+
* @remarks Mount it once, near the root. A second provider logs a warning in
|
|
23
|
+
* development, because two announcers would read the same message twice.
|
|
24
|
+
*/
|
|
25
|
+
function LiveRegionProvider({ children }) {
|
|
26
|
+
const [texts, setTexts] = useState({
|
|
27
|
+
polite: "",
|
|
28
|
+
assertive: ""
|
|
29
|
+
});
|
|
30
|
+
const catalogueRef = useLatestRef(useOptionalMessages());
|
|
31
|
+
const [announcer] = useState(() => createAnnouncer({ setText: (priority, text) => setTexts((current) => ({
|
|
32
|
+
...current,
|
|
33
|
+
[priority]: text
|
|
34
|
+
})) }));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
mountedProviders += 1;
|
|
37
|
+
if (isDevelopment() && mountedProviders > 1) console.warn("LiveRegionProvider is mounted more than once. Mount a single provider so messages are announced once.");
|
|
38
|
+
return () => {
|
|
39
|
+
mountedProviders -= 1;
|
|
40
|
+
announcer.dispose();
|
|
41
|
+
};
|
|
42
|
+
}, [announcer]);
|
|
43
|
+
const announce = useCallback((message, options) => announcer.announce(typeof message === "string" ? message : formatMessage(catalogueRef.current, message), options), [announcer, catalogueRef]);
|
|
44
|
+
return /* @__PURE__ */ jsxs(LiveRegionContext.Provider, {
|
|
45
|
+
value: announce,
|
|
46
|
+
children: [
|
|
47
|
+
children,
|
|
48
|
+
/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
49
|
+
as: "div",
|
|
50
|
+
role: "status",
|
|
51
|
+
"aria-live": "polite",
|
|
52
|
+
"aria-atomic": "true",
|
|
53
|
+
"data-testid": "live-region-polite",
|
|
54
|
+
children: texts.polite
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
57
|
+
as: "div",
|
|
58
|
+
role: "alert",
|
|
59
|
+
"aria-live": "assertive",
|
|
60
|
+
"aria-atomic": "true",
|
|
61
|
+
"data-testid": "live-region-assertive",
|
|
62
|
+
children: texts.assertive
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns `announce(message, { priority?, keep? })`, which reads a message out
|
|
69
|
+
* through the app-wide live regions. The message is text or a `Message` from
|
|
70
|
+
* core, which is formatted with the active catalogue. Pass `keep` for the outcome of something
|
|
71
|
+
* the person did, so a later message cannot replace it while it waits for the
|
|
72
|
+
* throttle window. The function is stable between renders.
|
|
73
|
+
* Outside a `LiveRegionProvider` it does nothing, and warns once in development.
|
|
74
|
+
*/
|
|
75
|
+
function useAnnounce() {
|
|
76
|
+
const announce = useContext(LiveRegionContext);
|
|
77
|
+
const missing = announce === null;
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (missing && isDevelopment() && !warnedMissingProvider) {
|
|
80
|
+
warnedMissingProvider = true;
|
|
81
|
+
console.warn("useAnnounce was called outside a LiveRegionProvider.");
|
|
82
|
+
}
|
|
83
|
+
}, [missing]);
|
|
84
|
+
return useCallback((message, options) => (announce ?? ignore)(message, options), [announce]);
|
|
85
|
+
}
|
|
86
|
+
export { LiveRegionProvider, useAnnounce };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=LiveRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveRegion.js","names":[],"sources":["../../../src/ui/LiveRegion/LiveRegion.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { formatMessage } from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { useOptionalMessages } from \"../../services/hooks\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport {\n type Announce,\n type AnnouncePriority,\n createAnnouncer,\n} from \"./announcer\";\n\nexport type { Announce, AnnounceOptions, AnnouncePriority } from \"./announcer\";\n\n/**\n * Ambient and type-only: this package has no dependency on `@types/node`, and\n * bundlers replace the literal `process.env.NODE_ENV`, so production builds\n * drop the development warnings. Outside a bundler the guard keeps the check\n * from throwing.\n */\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\nfunction isDevelopment(): boolean {\n return (\n typeof process !== \"undefined\" && process.env?.NODE_ENV !== \"production\"\n );\n}\n\nconst LiveRegionContext = createContext<Announce | null>(null);\n\n/** How many providers are mounted, to warn in development about a second. */\nlet mountedProviders = 0;\nlet warnedMissingProvider = false;\n\n/** Does nothing. Returned outside a provider so callers need no null check. */\nconst ignore: Announce = () => undefined;\n\n/** Props for {@link LiveRegionProvider}. */\nexport interface LiveRegionProviderProps {\n readonly children?: ReactNode;\n}\n\n/**\n * Mounts the one app-wide announcer: a visually hidden polite `status` region\n * and a visually hidden assertive `alert` region. Nothing else in the app may\n * create a live region except `StatusMessage`, which is a visible message.\n * @remarks Mount it once, near the root. A second provider logs a warning in\n * development, because two announcers would read the same message twice.\n */\nexport function LiveRegionProvider({ children }: LiveRegionProviderProps) {\n const [texts, setTexts] = useState<Record<AnnouncePriority, string>>({\n polite: \"\",\n assertive: \"\",\n });\n const catalogueRef = useLatestRef(useOptionalMessages());\n const [announcer] = useState(() =>\n createAnnouncer({\n setText: (priority, text) =>\n setTexts((current) => ({ ...current, [priority]: text })),\n }),\n );\n\n useEffect(() => {\n mountedProviders += 1;\n if (isDevelopment() && mountedProviders > 1) {\n console.warn(\n \"LiveRegionProvider is mounted more than once. Mount a single provider so messages are announced once.\",\n );\n }\n return () => {\n mountedProviders -= 1;\n announcer.dispose();\n };\n }, [announcer]);\n\n const announce = useCallback<Announce>(\n (message, options) =>\n announcer.announce(\n typeof message === \"string\"\n ? message\n : formatMessage(catalogueRef.current, message),\n options,\n ),\n [announcer, catalogueRef],\n );\n\n return (\n <LiveRegionContext.Provider value={announce}>\n {children}\n <VisuallyHidden\n as=\"div\"\n role=\"status\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n data-testid=\"live-region-polite\"\n >\n {texts.polite}\n </VisuallyHidden>\n <VisuallyHidden\n as=\"div\"\n role=\"alert\"\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n data-testid=\"live-region-assertive\"\n >\n {texts.assertive}\n </VisuallyHidden>\n </LiveRegionContext.Provider>\n );\n}\n\n/**\n * Returns `announce(message, { priority?, keep? })`, which reads a message out\n * through the app-wide live regions. The message is text or a `Message` from\n * core, which is formatted with the active catalogue. Pass `keep` for the outcome of something\n * the person did, so a later message cannot replace it while it waits for the\n * throttle window. The function is stable between renders.\n * Outside a `LiveRegionProvider` it does nothing, and warns once in development.\n */\nexport function useAnnounce(): Announce {\n const announce = useContext(LiveRegionContext);\n const missing = announce === null;\n useEffect(() => {\n if (missing && isDevelopment() && !warnedMissingProvider) {\n warnedMissingProvider = true;\n console.warn(\"useAnnounce was called outside a LiveRegionProvider.\");\n }\n }, [missing]);\n return useCallback<Announce>(\n (message, options) => (announce ?? ignore)(message, options),\n [announce],\n );\n}\n"],"mappings":";;;;;;;;AA8BA,SAAS,gBAAyB;CAChC,OACE,OAAO,YAAY,eAAA,QAAA,IAAA,aAAyC;AAEhE;AAEA,IAAM,oBAAoB,cAA+B,IAAI;;AAG7D,IAAI,mBAAmB;AACvB,IAAI,wBAAwB;;AAG5B,IAAM,eAAyB,KAAA;;;;;;;;AAc/B,SAAgB,mBAAmB,EAAE,YAAqC;CACxE,MAAM,CAAC,OAAO,YAAY,SAA2C;EACnE,QAAQ;EACR,WAAW;CACb,CAAC;CACD,MAAM,eAAe,aAAa,oBAAoB,CAAC;CACvD,MAAM,CAAC,aAAa,eAClB,gBAAgB,EACd,UAAU,UAAU,SAClB,UAAU,aAAa;EAAE,GAAG;GAAU,WAAW;CAAK,EAAE,EAC5D,CAAC,CACH;CAEA,gBAAgB;EACd,oBAAoB;EACpB,IAAI,cAAc,KAAK,mBAAmB,GACxC,QAAQ,KACN,uGACF;EAEF,aAAa;GACX,oBAAoB;GACpB,UAAU,QAAQ;EACpB;CACF,GAAG,CAAC,SAAS,CAAC;CAEd,MAAM,WAAW,aACd,SAAS,YACR,UAAU,SACR,OAAO,YAAY,WACf,UACA,cAAc,aAAa,SAAS,OAAO,GAC/C,OACF,GACF,CAAC,WAAW,YAAY,CAC1B;CAEA,OACE,qBAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAAnC,UAAA;GACG;GACD,oBAAC,gBAAD;IACE,IAAG;IACH,MAAK;IACL,aAAU;IACV,eAAY;IACZ,eAAY;IAEX,UAAA,MAAM;GACO,CAAA;GAChB,oBAAC,gBAAD;IACE,IAAG;IACH,MAAK;IACL,aAAU;IACV,eAAY;IACZ,eAAY;IAEX,UAAA,MAAM;GACO,CAAA;EACU;;AAEhC;;;;;;;;;AAUA,SAAgB,cAAwB;CACtC,MAAM,WAAW,WAAW,iBAAiB;CAC7C,MAAM,UAAU,aAAa;CAC7B,gBAAgB;EACd,IAAI,WAAW,cAAc,KAAK,CAAC,uBAAuB;GACxD,wBAAwB;GACxB,QAAQ,KAAK,sDAAsD;EACrE;CACF,GAAG,CAAC,OAAO,CAAC;CACZ,OAAO,aACJ,SAAS,aAAa,YAAY,OAAA,CAAQ,SAAS,OAAO,GAC3D,CAAC,QAAQ,CACX;AACF"}
|