Migrate from 0.2.0 to the map element
0.2.0 exported the map interface as React components and hooks, in @mapcairn/map and in a package of its own, @mapcairn/react. The release after it, 0.3.0, draws the interface behind one element, <mapcairn-map>, and exports no component, hook or primitive. @mapcairn/react and @mapcairn/sdk/react are gone, and the release set is five packages. This page says what to change, for each way an app used 0.2.0. 0.3.0 is not published yet.
0.2.0 stays on npm and keeps working, so an app can stay on it until it is ready to move.
The deprecation notice that a removal usually gets was waived for this move only, so 0.2.0 carries none and the removal comes in one release. This page is the notice in its place. The public API still says how every other export is deprecated before it is removed.
The Before blocks are the code of 0.2.0. They are not compiled here, because the exports they use no longer exist. The After blocks are compiled in CI against the built packages of this repository.
Find your way
Find what your app did with 0.2.0, and read the section it points to. An app can fit several of these, and each section says who is affected.
- Rendered
MapViewandMapChromeinsideServicesProvider: the composed interface. - Rendered a single component or primitive, such as
SearchPill,AttributionorButton: single components and primitives. - Called a hook, such as
useServices,useMessages,useDataLayersoruseSearch: hooks. - Imported a constant or a helper function, such as
toMapVectororLONG_PRESS_DELAY_MS: helpers and constants. - Rendered
ChromeSkeletonor one of the other skeletons: the skeleton. - Imported
TourStepfrom@mapcairn/map, or used theScaleBarcomponent from@mapcairn/sdk: names that moved to core. - Imported from
@mapcairn/reactor@mapcairn/sdk/react, such asuseModelContextTooloruseLatestRef: the React package.
An app that already used only @mapcairn/core, @mapcairn/theme and the MapLibre adapter, with an interface of its own, changes nothing here.
What was removed
The groups below, with their counts, come from the difference between the API reports of 0.2.0 and this repository: 293 exports of @mapcairn/map and 9 of @mapcairn/react. A ...Props type goes with its component and a Use... type with its hook, and both are counted. Every name is listed in the section each item points to. @mapcairn/core, @mapcairn/theme and @mapcairn/adapter-maplibre lost no export.
MapViewandMapChrome, with their props (4): the composed interface.- Providers and contexts, such as
ServicesProviderandMapContext(18): the composed interface. - Interface components, their props and the types of their props (80): single components and primitives.
- Primitives, such as
ButtonandSwitch, with their props (40): single components and primitives. - Hooks, every export that starts with
use(48): hooks. - The state, result and option types of the hooks (49): hooks.
- Constants, every export written in capitals (27): helpers and constants.
- Helper functions (16): helpers and constants.
- The four skeleton components and their props (8): the skeleton.
ScaleBar(the component),ScaleBarPropsandTourStep(3): names that moved to core.- The nine exports of
@mapcairn/react, and the./reactentry of the umbrella (9): the React package.
The composed interface
Who is affected: an app that drew the map with MapView, put MapChrome around it and wrapped both in ServicesProvider. That was the documented way to use 0.2.0, so this is most apps.
What to change: draw the <mapcairn-map> element and set the services you built on its services property. The element draws the chrome, the sheet and the tools itself, and an app names the tools it wants.
Before, in 0.2.0:
import {
defaultBasemapFor,
FocusRegistryProvider,
LiveRegionProvider,
MapChrome,
MapView,
SearchPill,
ServicesProvider,
TooltipProvider,
useBasemaps,
useMap,
useTheme,
} from "@mapcairn/sdk";
import type { ReactNode } from "react";
function App() {
return (
<ServicesProvider services={services}>
<LiveRegionProvider>
<TooltipProvider>
<MapScreen />
</TooltipProvider>
</LiveRegionProvider>
</ServicesProvider>
);
}
function MapScreen() {
const basemaps = useBasemaps();
const { resolved } = useTheme();
return (
<MapView
initialView={{ center: { lat: -33.92, lng: 18.42 }, zoom: 11, bearing: 0 }}
basemap={defaultBasemapFor(basemaps, resolved)}
chrome={(background) => <Chrome background={background} />}
/>
);
}
function Chrome({ background }: { readonly background: ReactNode }) {
const map = useMap();
return (
<FocusRegistryProvider focusMap={map.focusMap}>
<MapChrome
background={background}
modal={false}
topStart={
<SearchPill
onSelect={(result) =>
map.adapter?.setView({ center: result.centre, zoom: 14 })
}
/>
}
/>
</FocusRegistryProvider>
);
}
After, in 0.3.0. Call defineMapCairnElement() before the first element is created, because a page sets an object such as services as a property only on an element that is already defined. This component defines the element and creates it in an effect, so it runs only in a browser:
/// <reference types="vite/client" />
import "@mapcairn/sdk/styles.css";
import {
createFakeServices,
defineMapCairnElement,
type MapCairnMapElement,
} from "@mapcairn/sdk";
import { createMapLibreMapAdapter } from "@mapcairn/sdk/adapter-maplibre";
import { useEffect, useRef } from "react";
const services = createFakeServices({
createMapAdapter: () =>
createMapLibreMapAdapter({
loadWorkerUrl: async () => {
const worker = await import(
"maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url"
);
return worker.default;
},
}),
});
export function MapScreen() {
const host = useRef<HTMLDivElement>(null);
useEffect(() => {
const node = host.current;
if (!node) {
return undefined;
}
defineMapCairnElement();
const map = document.createElement("mapcairn-map") as MapCairnMapElement;
map.setAttribute("latitude", "-33.92");
map.setAttribute("longitude", "18.42");
map.setAttribute("zoom", "11");
map.setAttribute("tools", "search");
map.services = services;
node.append(map);
return () => map.remove();
}, []);
return <div ref={host} className="map-host" />;
}
Get started builds the whole app, and Embed a map says what each part does. Give mapcairn-map display: block and a height in your stylesheet, or the map is zero pixels high.
Where each part of the composed interface went:
ServicesProvider. Theservicesproperty of the element.LiveRegionProvider,TooltipProvider,FocusRegistryProvider,SelectionProviderand the other providers and contexts have no replacement, because the element makes what it needs inside. Give a selection store asservices.selection.MapView'sinitialView. Thelatitude,longitude,zoomandbearingattributes, or theviewproperty. They are the first-visit default: the link thatservices.urlreads and the settingsservices.settingssaved (lastView) win over them, as the "What the map reads and writes" part of the map package's README says.MapView'sbasemap. Thebasemapattribute, also a first-visit default that the link and the savedbasemapIdwin over. Without it the element draws the default basemap for the theme. Later,chooseBasemap(id)picks one as a person does.MapView'sid. Theregion-idattribute.onViewChange,onClick,onEngineErrorand theonFeatureTapofMapDataLayers. The eventsmapcairn-view-change,mapcairn-click,mapcairn-errorandmapcairn-feature-tap, shown below. A basemap that fails to load is dealt with inside the element, which says so over the map with a Use previous basemap button, so theonBasemap...callbacks have no replacement.MapChrome's slots. The search box is thesearchtool, and the sheet, the end buttons, the measure, draw, directions and locate tools and Settings are the other names in thetoolsattribute. Zoom, the compass, the credits and the scale are always drawn. Thetourslot is thetourproperty. A mark and name above the sheet's title go in thebrandnode of the element. ThebottomStartandbottomCentreslots, andkeyHelp,cursorand the pointer and key callbacks ofMapView, have no equivalent: put your own content beside the element.- Children of
MapView, such asMapDataLayersandMapDirections. Thelayersproperty or the layer catalogue inservices, and thedirectionstool withservices.routing.
Events, which bubble and carry what happened in detail:
import type { MapCairnMapElement } from "@mapcairn/sdk";
export function followMap(map: MapCairnMapElement): void {
map.addEventListener("mapcairn-view-change", (event) => {
console.log(event.detail.zoom);
});
map.addEventListener("mapcairn-click", (event) => {
console.log(event.detail.lat, event.detail.lng);
});
map.addEventListener("mapcairn-feature-tap", (event) => {
console.log(event.detail.hits.length);
});
map.addEventListener("mapcairn-error", (event) => {
console.warn(event.detail.message);
});
}
The removed exports of this group are MapView, MapViewProps, MapChrome, MapChromeProps, and the providers and contexts BasemapAvailabilityProvider, ChromeLayoutProvider, ChromeLayoutProviderProps, ChromeLayoutValue, FocusRegistryProvider, FocusRegistryProviderProps, LiveRegionProvider, LiveRegionProviderProps, MapContext, MapContextValue, SelectionProvider, SelectionProviderProps, ServicesProvider, ServicesProviderProps, StatusMessageFocusProvider, StatusMessageFocusProviderProps, TooltipProvider and TooltipProviderProps.
Single components and primitives
Who is affected: an app that rendered a part of the interface in a layout of its own, such as the search box in a header or the credits in a footer, or used a primitive, such as Button, Switch or Icon, in its own pages.
What to change: there is no public replacement, and the interface is not offered in parts any more. Choose one of three ways:
- Use the element, and name the tools it should draw in
tools. This replaces the arrangement of components with the element's own. - Build your own part from native HTML elements and your own CSS. The design tokens of
@mapcairn/themeare still public, and Theme the interface says how a page uses them. Keep the accessibility the component gave you: a name for each control, keyboard use and a visible focus ring. - Build your own interface on
@mapcairn/coreand the MapLibre adapter, as Build a map without React does.
Before, in 0.2.0, a search box that moved the map:
import { SearchPill } from "@mapcairn/sdk";
<SearchPill onSelect={(result) => map.adapter?.setView({ center: result.centre, zoom: 14 })} />;
After, in 0.3.0, a search of your own over the search port of services, with showResult on the element to move the map as the search box does (it fits the result's bounds, or goes to its centre):
import type { MapCairnMapElement, Services } from "@mapcairn/sdk";
export async function searchAndShow(
services: Pick<Services, "search">,
map: MapCairnMapElement,
query: string,
): Promise<void> {
const [first] = await services.search.search(query);
if (first) {
map.showResult(first);
}
}
The removed interface components are AccuracyCircle, Attribution, BasemapPicker, CentreCrosshair, CursorCoordinates, DirectionsOverlay, DirectionsPanel, DrawMapBindings, DrawOverlay, DrawToolbar, EndStack, ExportSection, FeatureCard, HelpSection, IdentifyStatus, LayerItem, LayerKey, LayersSection, MapDataLayers, MapDirections, MapKey, MapOverlayLayer, MapReadout, MarkerGlyph, MeasureOverlay, MeasureToolbar, PinCard, PinMarker, PinSection, SearchPill, SelectionMarker, SettingsSection, ShapesSection and TourCard, each with its ...Props type, and the types AttributionAboutLink, EndStackDirections, HeadingLevel, HelpAbout, HelpAboutLink, IconComponent, LayerKeyLayout, MapKeyBlock, OverlayMap, SegmentedControlOption, StatusMessageVariant and TourCardCopy.
The removed primitives are Button, Chip, ControlGroup, EmptyState, Icon, IconButton, Isolate, ListRow, Section, SegmentedControl, Sheet, SheetContent, SkipLink, Slider, StatusMessage, Subheading, Surface, Switch, Tooltip and VisuallyHidden, each with its ...Props type.
Hooks
Who is affected: an app with components of its own that called the hooks of the interface, inside a ServicesProvider.
What to change: it depends on what the hook read.
- For a service or a catalogue:
useServices,useOptionalServices,useBasemaps,useLayers,useLanguages,useSelectionStore,useFeatureQuery,useSearchProvider,useSuggestionProvider,useRoutingProvider,useLocationProvider,useClipboard,useFileOpener,useFileSaver,useMapAdapterFactory,useThemeSourceanduseUrlState. Read the member of theservicesobject your app built, such asservices.searchorservices.selection. You made that object, so you already hold it. - For settings, preferences, theme and network:
useSettings,usePreferences,useThemeanduseOnline. Readservices.settingsandservices.preferences, and for the shown theme callresolveThemeof@mapcairn/corewithservices.theme.useSettings().update(patch)wrote throughservices.settings.set(patch), which you call yourself.useThemealso applied the shown theme to the page through the theme source; the element does that itself, throughservices.theme, so your app callsservices.theme.apply(theme)only for its own parts of the page. A person's or your app's choice of theme isservices.settings.set({ theme })or the element'sthemeattribute. - For text and language:
useMessages,useOptionalMessages,useFormatMessage,useResolveTextanduseLanguageLoad. Make a message store withcreateMessageStore, which you can also give the element asmessageStore, and read text withformatMessageandresolveTextof@mapcairn/core. - For the map and the interface's state:
useAnnounce,useBasemapAvailability,useChromeLayout,useDataLayers,useDirections,useDraw,useFeatureSelection,useFocusElement,useFocusReturn,useFocusTarget,useFreeCentre,useIdentifyFeedback,useLocate,useLongPress,useMap,useMeasure,usePlacement,useReverseAddress,useSearch,useSelection,useSuggestionsanduseTour. Use the element: its attributes, properties and events, itslayersStatestore and its handle. The hooks about focus, layout, announcements and placement have no replacement.
services.basemaps, services.languages, services.selection and services.featureQuery are optional. useBasemaps returned BUILT_IN_BASEMAP_CATALOGUE of @mapcairn/core when the app gave no basemaps.
Before, in 0.2.0, a component that switched a layer and read the catalogue and the message text:
import { useDataLayers, useMessages } from "@mapcairn/sdk";
function LayerSwitch({ id }: { readonly id: string }) {
const layers = useDataLayers();
const messages = useMessages();
const layer = layers.layers.find((entry) => entry.definition.id === id);
return (
<button
type="button"
aria-pressed={layer?.enabled ?? false}
onClick={() => layers.setEnabled(id, !layer?.enabled)}
>
{messages["settings.title"]}
</button>
);
}
After, in 0.3.0. The layers are read from the element's layersState store, which has getState() and subscribe(listener) and stays the same object across redraws, and a layer is switched with setLayerEnabled. catalogue says whether the layer list has loaded:
import type { MapCairnMapElement } from "@mapcairn/sdk";
export function watchLayers(
map: MapCairnMapElement,
onChange: (enabledIds: readonly string[]) => void,
): () => void {
const { layersState } = map;
return layersState.subscribe(() => {
const { catalogue, layers } = layersState.getState();
if (catalogue === "ready") {
onChange(layers.filter((layer) => layer.enabled).map((layer) => layer.id));
}
});
}
export function turnOn(map: MapCairnMapElement, id: string): void {
map.setLayerEnabled(id, true);
}
The services, settings, preferences and the selection are read from the object your app built, with the subscribe each port has:
import { resolveTheme, type Services } from "@mapcairn/sdk";
export function readState(services: Services) {
const settings = services.settings.get();
return {
online: services.preferences.get().online !== false,
shownTheme: resolveTheme(settings.theme, services.theme.getSystemTheme()),
selected: services.selection?.getState() ?? [],
};
}
export function onSettingsChange(
services: Services,
listener: () => void,
): () => void {
return services.settings.subscribe(listener);
}
Text and language come from a message store. getState() holds the active messages, a failed tag when a language did not load and retrying, and retry() asks again, which useLanguageLoad offered:
import {
createMessageStore,
resolveText,
type MapCairnMapElement,
type Services,
} from "@mapcairn/sdk";
export function connectMessages(
map: MapCairnMapElement,
services: Services,
): () => string {
const store = createMessageStore(services);
map.messageStore = store;
return () => resolveText(store.getState().messages, "settings.language.tryAgain");
}
Translate the interface builds a whole app around the message store.
The removed hooks are useAnnounce, useBasemapAvailability, useBasemaps, useChromeLayout, useClipboard, useDataLayers, useDirections, useDraw, useFeatureQuery, useFeatureSelection, useFileOpener, useFileSaver, useFocusElement, useFocusReturn, useFocusTarget, useFormatMessage, useFreeCentre, useIdentifyFeedback, useLanguageLoad, useLanguages, useLayers, useLocate, useLocationProvider, useLongPress, useMap, useMapAdapterFactory, useMeasure, useMessages, useOnline, useOptionalMessages, useOptionalServices, usePlacement, usePreferences, useResolveText, useReverseAddress, useRoutingProvider, useSearch, useSearchProvider, useSelection, useSelectionStore, useServices, useSettings, useSuggestionProvider, useSuggestions, useTheme, useThemeSource, useTour and useUrlState.
The removed state, result and option types are AddressState, Announce, AnnounceOptions, AnnouncePriority, AreaOutcome, BasemapAvailability, CatalogueView, DataLayerState, DataLayers, DetailState, DirectionsFailure, DirectionsOutcome, DirectionsState, DrawFeedback, FeatureOutline, FeatureSelectionState, FocusName, FreeCentre, HiddenSelection, IdentifyResult, LanguageLoad, LayerStatus, LocateState, MapCursor, MapLongPressEvent, ReverseAddress, RouteOutcome, SearchState, SelectedEntry, SelectedFeature, ShownSelection, TurnedOff, UndoHolder, UseDataLayersOptions, UseDirections, UseDraw, UseDrawOptions, UseFeatureSelectionOptions, UseLocate, UseLocateOptions, UseLongPress, UseLongPressOptions, UseMeasure, UseSearch, UseSearchOptions, UseSettings, UseTheme, UseTour and UseTourOptions. The element's MapLayerStatus and MapLayerState are the public types for what LayerStatus and DataLayerState were used for.
Helpers and constants
Who is affected: an app that imported one of the interface's helper functions or constants, usually to draw a layer or a shape on its own map.
What to change: nothing replaces them. They were the working parts of the interface, and the element keeps them inside. An app that drew layers itself works from the layer and adapter types of @mapcairn/core and the MapAdapter port, as Build a map without React does.
The removed helpers are drawingForImage, endStackMinHeightForZoom, featureBounds, featureOutlines, featurePosition, fillSlots, mapKeyBlocks, nextHeadingLevel, paletteColour, toLookRule, toMapFeatures, toMapHeatmap, toMapVector, toStyledShapes, toVectorHeatmaps and visuallyHidden.
The removed constants are AREA_LAYER_ID, ATTRIBUTION_FADE_MS, ATTRIBUTION_HOLD_MAX_MS, ATTRIBUTION_INTRO_MS, DRAW_ANNOUNCE_DELAY_MS, IDENTIFY_FEEDBACK_MS, IDENTIFY_TIMEOUT_MS, LONG_PRESS_DELAY_MS, MAX_IDENTIFY_LAYERS, MAX_OUTLINE_POINTS, MEASURE_ANNOUNCE_DELAY_MS, MEASURE_VERTEX_RADIUS_PX, MIN_ACCURACY_RADIUS_PX, MIN_SEARCH_LENGTH, MIN_SUGGEST_LENGTH, REVEAL_DETENT, ROUTE_CASING_LAYER_ID, ROUTE_LAYER_ID, SCALE_BAR_IDLE_MS, SCALE_BAR_MAX_WIDTH_PX, SHOW_ON_MAP_MIN_ZOOM, SUGGEST_COOLDOWN_MS, SUGGEST_DEBOUNCE_MS, SUGGEST_FAILURE_LIMIT, UNAVAILABLE_FOR_MS, UNDO_TIMEOUT_MS and VIEW_SETTLE_MS.
The skeleton
Who is affected: a page that a server renders and that drew ChromeSkeleton, AttributionSkeleton, EndStackSkeleton or SearchPillSkeleton as React components, so the controls have their places before any script runs.
What to change: chromeSkeletonHtml returns the whole skeleton as a string of HTML, with every word escaped. Its markup and class names are those of the components, and it adds no script and no style attribute. chromeSkeletonCopy, ChromeSkeletonCopy, EndStackSkeletonCopy and SearchPillSkeletonCopy are unchanged.
Before, in 0.2.0:
import { ChromeSkeleton, chromeSkeletonCopy } from "@mapcairn/map";
<div aria-busy="true">
<ChromeSkeleton copy={chromeSkeletonCopy(messages)} directions draw />
</div>;
After, in 0.3.0:
import type { MessageCatalogue } from "@mapcairn/core";
import { chromeSkeletonCopy, chromeSkeletonHtml } from "@mapcairn/map";
export function Skeleton({ messages }: { readonly messages: MessageCatalogue }) {
return (
<div
aria-busy="true"
dangerouslySetInnerHTML={{
__html: chromeSkeletonHtml({
copy: chromeSkeletonCopy(messages),
directions: true,
draw: true,
}),
}}
/>
);
}
The string can also be written into the markup of any server, with no React. The removed exports are ChromeSkeleton, ChromeSkeletonProps, AttributionSkeleton, AttributionSkeletonProps, EndStackSkeleton, EndStackSkeletonProps, SearchPillSkeleton and SearchPillSkeletonProps.
Names that moved to core
TourStep. It is no longer exported from @mapcairn/map. It lives in @mapcairn/core, and the umbrella still re-exports it, so an import from @mapcairn/sdk works in both releases. It gained an optional opens field, the section that Map options opens on while the step is current.
Before, in 0.2.0:
import type { TourStep } from "@mapcairn/map";
After, in 0.3.0:
import type { TourStep } from "@mapcairn/core";
export const steps: readonly TourStep[] = [];
An app that gives the element a tour passes tour as plain data. The map package's README describes it.
ScaleBar. The component ScaleBar and ScaleBarProps are removed from @mapcairn/map. The element draws its own scale. In 0.2.0, ScaleBar from @mapcairn/sdk was that component, and @mapcairn/core declared a type of the same name, which was reachable only at @mapcairn/sdk/core. Now ScaleBar from @mapcairn/sdk is the type of @mapcairn/core, the measurement that computeScaleBar returns, so the name is the same in the root and at ./core. An app that rendered the component draws the scale of its own interface from that measurement, or uses the element's.
Before, in 0.2.0:
import { ScaleBar } from "@mapcairn/sdk";
<ScaleBar units="metric" />;
After, in 0.3.0:
import type { ScaleBar } from "@mapcairn/sdk";
export function scaleText(scale: ScaleBar): string {
return scale.label;
}
The React package
Who is affected: an app that listed @mapcairn/react, imported from @mapcairn/sdk/react, which re-exported it, or imported one of its names from the root of @mapcairn/sdk, which re-exported it too. The package is not in the release set any more, and the umbrella has no ./react entry.
What to change: take what you used from the place the list below names, and remove @mapcairn/react from your dependencies. Its hooks were small, and nothing in the SDK needs them as public exports.
useReadingDirection: your own hook overdiron<html>, shown below.ReadingDirection: the same type from@mapcairn/coreor the root of@mapcairn/sdk.useLatestRef:useRefand a layout effect, shown below.useModelContextTool,isModelContextSupported,ModelContextProvider,ModelContextToolContentBlock,ModelContextToolDefinitionandModelContextToolResult: registration code of your own, shown below. A public registration is planned for a later release, in issue 1098.
Before, in 0.2.0:
import {
useLatestRef,
useModelContextTool,
useReadingDirection,
} from "@mapcairn/sdk/react";
After, in 0.3.0, the two small hooks written in your own code. useReadingDirection follows dir on <html>, including a change made while the page is open, and is "ltr" on the server. useLatestRef keeps a ref at the latest committed value:
import type { ReadingDirection } from "@mapcairn/sdk";
import { type RefObject, useLayoutEffect, useRef, useSyncExternalStore } from "react";
function subscribe(onChange: () => void): () => void {
const observer = new MutationObserver(onChange);
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ["dir"],
});
return () => observer.disconnect();
}
function readDirection(): ReadingDirection {
return document.documentElement.getAttribute("dir") === "rtl" ? "rtl" : "ltr";
}
export function useReadingDirection(): ReadingDirection {
return useSyncExternalStore(subscribe, readDirection, () => "ltr");
}
export function useLatestRef<T>(value: T): RefObject<T> {
const ref = useRef(value);
useLayoutEffect(() => {
ref.current = value;
}, [value]);
return ref;
}
A WebMCP tool is registered on document.modelContext, where a browser has one. registerModelContextTool does nothing without it, logs a registration the browser refuses, whether it rejects or throws at once, as useModelContextTool of 0.2.0 did, and returns the function that removes the tool. The execute function receives the tool's input, as in 0.2.0. examples/embed/src/modelContext.ts has a similar function, for a tool that takes no input, with a React hook over it that re-registers a tool only when its name changes:
export interface ToolDefinition {
readonly name: string;
readonly description: string;
readonly inputSchema: Readonly<Record<string, unknown>>;
readonly execute: (input: unknown) => Promise<{
readonly content: readonly { readonly type: "text"; readonly text: string }[];
}>;
}
interface ModelContext {
registerTool(
tool: ToolDefinition,
options: { readonly signal: AbortSignal },
): Promise<void>;
}
export function registerModelContextTool(definition: ToolDefinition): () => void {
const controller = new AbortController();
const modelContext = Reflect.get(document, "modelContext") as ModelContext | undefined;
try {
modelContext
?.registerTool(definition, { signal: controller.signal })
.catch((error: unknown) => {
console.error(`registerTool was refused for "${definition.name}"`, error);
});
} catch (error) {
console.error(`registerTool threw for "${definition.name}"`, error);
}
return () => controller.abort();
}
The umbrella package
@mapcairn/sdk is the one import most apps used, and its root changes with the packages it re-exports:
- It exports the element,
chromeSkeletonHtmland the rest of@mapcairn/mapas the map package lists them now, with all of@mapcairn/coreand@mapcairn/theme. Every name in this page that is removed from@mapcairn/mapis removed from the root too. ScaleBaris the measurement type of@mapcairn/core, as above. In0.2.0an explicit export chose the component.ReadingDirectionhas one declaration, in@mapcairn/core. In0.2.0@mapcairn/reactdeclared it too, with the same members, and an explicit export in the root chose core's. An import of the type from the root needs no change.- The names of
@mapcairn/reactleft the root, and@mapcairn/sdk/reactis removed. The other entries, including./core,./map,./theme,./adapter-maplibreand./styles.css, stay.
The umbrella, and @mapcairn/sdk/adapter-maplibre, work as before for an app that uses the element. The public API lists the entries.
If something is missing
The element does not offer everything that the components did. An app that needs a part of the interface that has no equivalent here can build its own on @mapcairn/core and the MapLibre adapter, as Build a map without React shows. Embed a map and the map package's README list what the element takes and sends.