Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(geomap): give the zoom buttons the bar the mind map stands on
Elian Doranc4c6d716e787
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 9c60ecfc71..c5aeae8aa0 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2741,7 +2741,9 @@"create-child-note-text": "Add marker","create-child-note-instruction": "Click on the map to create a new note at that location or press Escape to dismiss.","create-child-note-toast-title": "New note",- "unable-to-load-map": "Unable to load map."+ "unable-to-load-map": "Unable to load map.",+ "zoom-in": "Zoom in",+ "zoom-out": "Zoom out"},"geo-map-context": {"open-location": "Open location",diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.css b/apps/client/src/widgets/collections/geomap/MapToolbar.cssnew file mode 100644index 0000000000..fd14ad9407--- /dev/null+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.css@@ -0,0 +1,18 @@+/*+ * The bar stands in the bottom corner, where every other bar floating over content in the app stands+ * — the mind map's own (see MapToolbar.css there), the relation map's zoom buttons — rather than in+ * the top corner MapLibre keeps its zoom buttons in. The corner is the map's to give: its attribution+ * has been moved to the foot of the other side, beside the scale (see map.tsx).+ *+ * Held off the edges by as much as MapLibre holds its own controls off them, so the bar and the scale+ * opposite it stand on the same line.+ *+ * Above the canvas whatever order the two end up in: MapLibre builds its part of the container+ * itself, so what Preact renders alongside is not reliably the later sibling. The number clears+ * MapLibre's own control corners, which sit at 2.+ */+.geo-map-container .geo-map-toolbar {+ bottom: 10px;+ inset-inline-end: 10px;+ z-index: 3;+}diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx b/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsxnew file mode 100644index 0000000000..abd9978574--- /dev/null+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.spec.tsx@@ -0,0 +1,123 @@+/**+ * The zoom buttons, which used to be MapLibre's own `NavigationControl` — a white box on a map that+ * may well be dark, dressed in neither Trilium's buttons nor its colors. What is checked here is what+ * the control did for us: the two steps, and a step that would carry the map past either end of the+ * range it is allowed being refused rather than merely doing nothing.+ */+import type { Map as MapLibreGLMap } from "maplibre-gl";+import { render } from "preact";+import { act } from "preact/test-utils";+import { describe, expect, it, vi } from "vitest";++import { renderInto } from "../../../test/render";+import { ParentMap } from "./map";+import MapToolbar from "./MapToolbar";++/** The order the bar lays its buttons out in. */+const ZOOM_IN = 0;+const ZOOM_OUT = 1;++/** A map that only zooms and says so, which is all this bar asks of one. */+function fakeMap({ zoom = 5, minZoom = 2, maxZoom = 22 } = {}) {+ const listeners = new Set<() => void>();++ const setZoom = (value: number) => {+ zoom = Math.min(Math.max(value, minZoom), maxZoom);+ for (const listener of listeners) listener();+ };++ return {+ getZoom: () => zoom,+ getMinZoom: () => minZoom,+ getMaxZoom: () => maxZoom,+ zoomIn: vi.fn(() => setZoom(zoom + 1)),+ zoomOut: vi.fn(() => setZoom(zoom - 1)),+ /** The map being zoomed by something other than these buttons — the wheel, or a pinch. */+ zoomTo: setZoom,+ on: (event: string, listener: () => void) => { if (event === "zoom") listeners.add(listener); },+ off: (event: string, listener: () => void) => { if (event === "zoom") listeners.delete(listener); },+ get listenerCount() { return listeners.size; }+ };+}++/** Builds the bar over a map and settles it, so that it is listening before it is spoken to. */+function renderToolbar(map: ReturnType<typeof fakeMap> | null) {+ let container: HTMLElement | undefined;+ act(() => {+ container = renderInto(+ <ParentMap.Provider value={map as unknown as MapLibreGLMap}>+ <MapToolbar />+ </ParentMap.Provider>+ );+ });+ if (!container) throw new Error("the toolbar was not rendered");+ return container;+}++function buttons(container: HTMLElement) {+ return [ ...container.querySelectorAll<HTMLButtonElement>(".tn-overlay-toolbar button") ];+}++function press(container: HTMLElement, index: number) {+ act(() => buttons(container)[index].click());+}++describe("geo map MapToolbar", () => {+ it("offers the two steps the map's own control did, in one row", () => {+ const container = renderToolbar(fakeMap());++ expect(buttons(container).map((button) => button.className)).toEqual([+ expect.stringContaining("bx-zoom-in"),+ expect.stringContaining("bx-zoom-out")+ ]);+ });++ it("stands aside until there is a map to zoom", () => {+ const container = renderToolbar(null);++ expect(buttons(container)).toHaveLength(0);+ });++ it("zooms the map in either direction", () => {+ const map = fakeMap();+ const container = renderToolbar(map);++ press(container, ZOOM_IN);+ expect(map.zoomIn).toHaveBeenCalled();++ press(container, ZOOM_OUT);+ expect(map.zoomOut).toHaveBeenCalled();+ });++ it("disables the step that would carry the map past the range it is allowed", () => {+ const atTheTop = renderToolbar(fakeMap({ zoom: 22 }));+ expect(buttons(atTheTop)[ZOOM_IN].disabled).toBe(true);+ expect(buttons(atTheTop)[ZOOM_OUT].disabled).toBe(false);++ const atTheBottom = renderToolbar(fakeMap({ zoom: 2 }));+ expect(buttons(atTheBottom)[ZOOM_IN].disabled).toBe(false);+ expect(buttons(atTheBottom)[ZOOM_OUT].disabled).toBe(true);+ });++ it("follows the zoom as the map reports it, not only as the buttons set it", () => {+ const map = fakeMap({ zoom: 5, maxZoom: 6 });+ const container = renderToolbar(map);+ expect(buttons(container)[ZOOM_IN].disabled).toBe(false);++ // As the wheel or a pinch would.+ act(() => map.zoomTo(6));++ expect(buttons(container)[ZOOM_IN].disabled).toBe(true);+ });++ it("stops listening to a map it is taken off", () => {+ const map = fakeMap();+ const container = renderToolbar(map);+ expect(map.listenerCount).toBe(1);++ // A map torn down under a bar that stayed behind would go on being reported to.+ act(() => { render(null, container); });++ expect(map.listenerCount).toBe(0);+ });+});diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.tsx b/apps/client/src/widgets/collections/geomap/MapToolbar.tsxnew file mode 100644index 0000000000..fc5484de1e--- /dev/null+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.tsx@@ -0,0 +1,73 @@+import "./MapToolbar.css";++import type { Map as MapLibreGLMap } from "maplibre-gl";+import { useContext, useEffect, useState } from "preact/hooks";++import { t } from "../../../services/i18n";+import OverlayToolbar, { OverlayToolbarButton } from "../../react/OverlayToolbar";+import { ParentMap } from "./map";++/**+ * The bar standing in the corner of a geo map: how close in the map is drawn.+ *+ * MapLibre offers a bar of its own for this (`NavigationControl`, which is what stood here), dressed+ * in neither Trilium's buttons nor Trilium's colors — a white box with two hairline-separated squares+ * in it, on a map that may well be dark. What it did is done here instead, on the surface every bar+ * standing over a canvas shares (see {@link OverlayToolbar}), which is what the mind map's own bar+ * stands on too.+ */+export default function MapToolbar() {+ const map = useContext(ParentMap);+ const zoom = useMapZoom(map);++ if (!map) return null;++ // Before the first report, which follows the very next tick: what the map already says it is.+ const current = zoom ?? map.getZoom();++ return (+ // The bar stands at the foot of the map, so its tooltips open away from that edge, where+ // they would otherwise fall off.+ <OverlayToolbar className="geo-map-toolbar" titlePosition="top">+ <OverlayToolbarButton+ icon="bx bx-zoom-in"+ text={t("geo-map.zoom-in")}+ disabled={current >= map.getMaxZoom()}+ onClick={() => map.zoomIn()}+ />++ <OverlayToolbarButton+ icon="bx bx-zoom-out"+ text={t("geo-map.zoom-out")}+ disabled={current <= map.getMinZoom()}+ onClick={() => map.zoomOut()}+ />+ </OverlayToolbar>+ );+}++/**+ * How close in the map is drawn, followed as it changes — by these buttons, by the wheel, or by the+ * view being restored. What it is read for is whether there is any room left to zoom, which is what+ * leaves a button that would do nothing disabled instead of idle: MapLibre clamps a step past either+ * end silently.+ *+ * `zoom` rather than `zoomend`, so that a button reaching the end of the range is disabled as the+ * map arrives there rather than a moment later — the two steps are animated.+ */+function useMapZoom(map: MapLibreGLMap | null) {+ const [ zoom, setZoom ] = useState<number | null>(null);++ useEffect(() => {+ if (!map) return;++ const report = () => setZoom(map.getZoom());+ // The map may have been moved between being built and being listened to.+ report();++ map.on("zoom", report);+ return () => { map.off("zoom", report); };+ }, [ map ]);++ return zoom;+}diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex e2e712e752..db7c55b0fe 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -22,6 +22,7 @@ import ContextMenus from "./ContextMenus";import { GpxTrack } from "./GpxTrack";import Map, { GeoMouseEvent } from "./map";import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, MapLayer } from "./map_layer";+import MapToolbar from "./MapToolbar";import Markers, { LOCATION_ATTRIBUTE } from "./Markers";import Tooltips from "./Tooltips";@@ -173,6 +174,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMonClick={onClick}scale={hasScale}>+ <MapToolbar /><Tooltips /><ContextMenus note={note} isReadOnly={isReadOnly} /><Markers notes={notes} hideLabels={hideLabels} isDarkTheme={layerData.isDarkTheme ?? false} clustered={clustered} />diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsxindex 11b87fa683..b81793b2c0 100644--- a/apps/client/src/widgets/collections/geomap/map.tsx+++ b/apps/client/src/widgets/collections/geomap/map.tsx@@ -1,6 +1,6 @@import "maplibre-gl/dist/maplibre-gl.css";-import { type ErrorEvent as MapErrorEvent, Map as MapLibreGLMap, MapMouseEvent, NavigationControl, type Point, ScaleControl, type StyleSpecification, type TransformStyleFunction } from "maplibre-gl";+import { AttributionControl, type ErrorEvent as MapErrorEvent, Map as MapLibreGLMap, MapMouseEvent, type Point, ScaleControl, type StyleSpecification, type TransformStyleFunction } from "maplibre-gl";import { ComponentChildren, createContext, RefObject } from "preact";import { useEffect, useImperativeHandle, useRef, useState } from "preact/hooks";@@ -112,9 +112,16 @@ export default function Map({ coordinates, zoom, layerData, viewportChanged, chi// single world (substituting an almost-full-world longitude range that avoids the// collapse) and clamps latitude to the Mercator limit, which is the Leaflet-parity// behavior we want.- renderWorldCopies: false+ renderWorldCopies: false,+ // Added by hand below, in the corner opposite the one MapLibre keeps it in.+ attributionControl: false});+ // The attribution stands at the foot of the map beside its scale, rather than in the corner+ // where the zoom buttons now are (see MapToolbar): a bar of buttons is reached for, and it+ // would otherwise sit on top of a line of small print that is itself made of links.+ mapInstance.addControl(new AttributionControl(), "bottom-left");+// An error MapLibre finds no listener for goes to `console.error` with the stack of the// fetch that failed, and a tile server answering 403 fails once per tile: a screenful of// identical stacks, none of which says anything the first one did not. Listening takes that@@ -127,13 +134,10 @@ export default function Map({ coordinates, zoom, layerData, viewportChanged, chiconsole.warn(`Geo map: ${message}`);});- // Zoom buttons, which Leaflet added of its own accord. No compass: nothing here persists a- // bearing, so the button would offer to undo a rotation the map never remembers.- mapInstance.addControl(new NavigationControl({- showCompass: false,- showZoom: true- }), "top-left");-+ // No navigation control of MapLibre's own: the zoom buttons are Trilium's (see MapToolbar),+ // dressed as every other bar standing over a canvas in the app. No compass either — nothing+ // here persists a bearing, so the button would offer to undo a rotation the map never+ // remembers.setMap(mapInstance);return () => {diff --git a/apps/client/src/widgets/react/OverlayToolbar.css b/apps/client/src/widgets/react/OverlayToolbar.cssnew file mode 100644index 0000000000..22bf8a271e--- /dev/null+++ b/apps/client/src/widgets/react/OverlayToolbar.css@@ -0,0 +1,54 @@+/*+ * A bar standing over a canvas: the same surface, border and blur a menu is drawn on, so that+ * everything floating over a map — bars, panels, whatever else — reads as one family rather than as+ * pieces from three places. Where each bar stands is settled by whoever puts it there.+ */+.tn-overlay-toolbar {+ position: absolute;+ display: flex;+ align-items: center;+ gap: 4px;+ padding: 4px;+ background: var(--menu-background-color);+ color: var(--menu-text-color);+ border: 1px solid var(--dropdown-border-color);+ border-radius: 8px;+ box-shadow: 0 2px 8px #0003;+ backdrop-filter: blur(10px);+}++/*+ * The buttons are on the bar's own surface rather than on the shell's, so they take their color+ * from it — as the ones inside a menu do.+ *+ * Their marks are centred by the button rather than by the text inside them, which is what a button+ * does of its own accord and what the theme leans on: `text-align` centres the glyph a font icon+ * paints, and has nothing to grip on a mark drawn as a box with a width of its own (see the mind+ * map's direction marks), leaving that one against the leading edge. Centring the box itself holds+ * for both, so marks of either kind sit alike.+ */+.tn-overlay-toolbar .tn-tool-button {+ display: flex;+ align-items: center;+ justify-content: center;+ color: inherit;+}++/* A button that would do nothing says as much rather than merely failing to answer. */+.tn-overlay-toolbar .tn-tool-button:disabled {+ opacity: .4;+ pointer-events: none;+}++/*+ * A button standing for a choice in force is shown held down. It is dressed in the fill the app+ * marks a chosen thing with rather than in the button group's raised chip: that chip is only told+ * apart from its neighbours by the recessed track behind it, and there is no track here — a bar of+ * glass is what these stand on. Held through a hover as well, so that pointing at the one already+ * chosen does not lower it.+ */+.tn-overlay-toolbar .tn-tool-button.active,+.tn-overlay-toolbar .tn-tool-button.active:hover {+ background: var(--active-item-background-color);+ color: var(--active-item-text-color);+}diff --git a/apps/client/src/widgets/react/OverlayToolbar.tsx b/apps/client/src/widgets/react/OverlayToolbar.tsxnew file mode 100644index 0000000000..ab68a60fc0--- /dev/null+++ b/apps/client/src/widgets/react/OverlayToolbar.tsx@@ -0,0 +1,58 @@+import "./OverlayToolbar.css";++import { type ComponentChildren, createContext } from "preact";+import { useContext } from "preact/hooks";++import ActionButton, { type ActionButtonProps } from "./ActionButton";++interface OverlayToolbarProps {+ /** Where the bar stands and what else is peculiar to it, styled by whoever puts it there. */+ className?: string;+ /** Which way the buttons' tooltips open — away from the edge the bar is pinned to. */+ titlePosition?: ActionButtonProps["titlePosition"];+ children: ComponentChildren;+}++/**+ * A bar of buttons standing over a canvas that is dragged and zoomed — a mind map, a geo map — where+ * what is done to the view has nowhere else to live.+ *+ * It brings the surface (see OverlayToolbar.css) and keeps itself out of the canvas's reach; where it+ * stands is left to the caller, which is the one thing that differs between two of them.+ */+export default function OverlayToolbar({ className, titlePosition, children }: OverlayToolbarProps) {+ return (+ <div+ className={`tn-overlay-toolbar ${className ?? ""}`}+ /* Keep interactions inside the bar from reaching the canvas underneath, which would+ otherwise take a press on a button for the start of a drag or a selection. */+ onMouseDown={(e) => e.stopPropagation()}+ >+ <TooltipDirection.Provider value={titlePosition ?? "top"}>+ {children}+ </TooltipDirection.Provider>+ </div>+ );+}++/**+ * A button on such a bar, dressed as the buttons floating over a rendered diagram are (see+ * SplitEditor's `PreviewButton`).+ *+ * Its tooltip opens the way the bar it stands on says, so that a bar at the foot of a canvas does not+ * open its tooltips off the bottom edge — overridable per button where one of them is placed+ * differently from its neighbours.+ */+export function OverlayToolbarButton({ titlePosition, ...props }: ActionButtonProps) {+ const barDirection = useContext(TooltipDirection);++ return <ActionButton+ {...props}+ className="tn-tool-button"+ noIconActionClass+ titlePosition={titlePosition ?? barDirection}+ />;+}++/** Which way the tooltips on a bar open, handed down by the bar rather than repeated on each button. */+const TooltipDirection = createContext<ActionButtonProps["titlePosition"]>("top");diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.cssindex e0cff96ef3..52e8a51285 100644--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css@@ -1,22 +1,10 @@/*- * The bars are dressed as the node panel is (see NodePanel.css): the same surface, the same border- * and the same blur, so that everything standing over a map reads as one family rather than as- * pieces from three places. Where they stand and how much room they leave the panel is settled- * between them in MindMap.css.+ * The bars are dressed as every bar standing over a canvas is (see OverlayToolbar.css), which is the+ * dress the node panel wears too (see NodePanel.css): the same surface, the same border and the same+ * blur, so that everything standing over a map reads as one family rather than as pieces from three+ * places. Left here is only what is the mind map's own — where they stand, and the marks a direction+ * is chosen by. How much room they leave the panel is settled between them in MindMap.css.*/-.mind-map-container .mind-map-toolbar {- position: absolute;- display: flex;- align-items: center;- gap: 4px;- padding: 4px;- background: var(--menu-background-color);- color: var(--menu-text-color);- border: 1px solid var(--dropdown-border-color);- border-radius: 8px;- box-shadow: 0 2px 8px #0003;- backdrop-filter: blur(10px);-}/* What is done with the view stands at the foot of the map, out of the way of its root. */.mind-map-container .mind-map-view-toolbar {@@ -30,43 +18,6 @@inset-inline-start: var(--mind-map-inset);}-/*- * The buttons are on the bar's own surface rather than on the shell's, so they take their color- * from it — as the ones inside a menu do.- *- * Their marks are centred by the button rather than by the text inside them, which is what a button- * does of its own accord and what the theme leans on: `text-align` centres the glyph a font icon- * paints, and has nothing to grip on a mark drawn as a box with a width of its own (see the- * direction marks below), leaving that one against the leading edge. Centring the box itself holds- * for both, so the seven marks sit alike whichever kind each is.- */-.mind-map-container .mind-map-toolbar .tn-tool-button {- display: flex;- align-items: center;- justify-content: center;- color: inherit;-}--/* A step that would carry the map past the scale it is allowed does nothing (see viewport.ts), and- the button for it says as much rather than merely failing to answer. */-.mind-map-container .mind-map-toolbar .tn-tool-button:disabled {- opacity: .4;- pointer-events: none;-}--/*- * The direction the map is laid out by is a choice among three rather than three things to do, so- * the one in force is shown held down. It is dressed in the fill the app marks a chosen thing with- * rather than in the button group's raised chip: that chip is only told apart from its neighbours by- * the recessed track behind it, and there is no track here — a bar of glass is what these stand on.- * Held through a hover as well, so that pointing at the one already chosen does not lower it.- */-.mind-map-container .mind-map-toolbar .tn-tool-button.active,-.mind-map-container .mind-map-toolbar .tn-tool-button.active:hover {- background: var(--active-item-background-color);- color: var(--active-item-text-color);-}-/** The three marks a direction is chosen by, which are Mind Elixir's own (MIT, © 2019 DjZhou): each* draws the very layout it sets, and Trilium's icon set has nothing that says it. They are drawn asdiff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsxindex 5bb4b3143a..f480b8c936 100644--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx@@ -90,7 +90,7 @@ const renderToolbar = (mind: MindElixirInstance) => renderBar(<MapToolbar mind={const renderDirections = (mind: MindElixirInstance) => renderBar(<DirectionToolbar mind={mind} />);function buttons(container: HTMLElement) {- return [ ...container.querySelectorAll<HTMLButtonElement>(".mind-map-toolbar button") ];+ return [ ...container.querySelectorAll<HTMLButtonElement>(".tn-overlay-toolbar button") ];}function press(container: HTMLElement, index: number) {diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsxindex f4867f3424..ef7999c194 100644--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx@@ -1,11 +1,10 @@import "./MapToolbar.css";import type { MindElixirInstance } from "mind-elixir";-import type { ComponentChildren } from "preact";import { useCallback, useEffect, useRef, useState } from "preact/hooks";import { t } from "../../../services/i18n";-import ActionButton, { type ActionButtonProps } from "../../react/ActionButton";+import OverlayToolbar, { OverlayToolbarButton } from "../../react/OverlayToolbar";import { centerMapOn, type MapPoint, readMapCenter, stepZoom } from "./viewport";interface MapToolbarProps {@@ -32,45 +31,47 @@ export default function MapToolbar({ mind }: MapToolbarProps) {const zoomedOut = stepZoom(scale, -1, limits);return (- <Toolbar className="mind-map-view-toolbar">+ // The bar stands at the foot of the map, so its tooltips open away from that edge, where+ // they would otherwise fall off.+ <OverlayToolbar className="mind-map-view-toolbar" titlePosition="top">{/* Leaving focus mode is about the map rather than about any one node, so it standshere rather than in the menu a node is right-clicked for — which is where MindElixir kept it, offered on every node whether the map was narrowed or not. It isonly here while there is something to leave, the map otherwise showing all it has. */}{isFocused && (- <ToolbarButton+ <OverlayToolbarButtonicon="bx bx-exit"text={t("mind-map.cancelFocus")}onClick={() => mind.cancelFocus()}/>)}- <ToolbarButton+ <OverlayToolbarButtonicon="bx bx-zoom-in"text={t("mind-map.zoom-in")}disabled={zoomedIn === null}onClick={() => zoomedIn !== null && mind.scale(zoomedIn)}/>- <ToolbarButton+ <OverlayToolbarButtonicon="bx bx-zoom-out"text={t("mind-map.zoom-out")}disabled={zoomedOut === null}onClick={() => zoomedOut !== null && mind.scale(zoomedOut)}/>- <ToolbarButton+ <OverlayToolbarButtonicon="bx bx-current-location"text={t("mind-map.center-map")}onClick={() => mind.toCenter()}/>- <ToolbarButton+ <OverlayToolbarButtonicon={isFullscreen ? "bx bx-exit-fullscreen" : "bx bx-fullscreen"}text={isFullscreen ? t("mind-map.exit-fullscreen") : t("mind-map.fullscreen")}onClick={toggleFullscreen}/>- </Toolbar>+ </OverlayToolbar>);}@@ -86,19 +87,18 @@ export function DirectionToolbar({ mind }: MapToolbarProps) {const direction = useMapDirection(mind);return (- <Toolbar className="mind-map-direction-toolbar">+ // The bar stands at the head of the map, where a tooltip over it would fall off.+ <OverlayToolbar className="mind-map-direction-toolbar" titlePosition="bottom">{buildDirections().map(({ value, icon, label, apply }) => (- <ToolbarButton+ <OverlayToolbarButtonkey={value}icon={`mind-map-direction-icon ${icon}`}text={label}active={direction === value}- // The bar stands at the head of the map, where a tooltip over it would fall off.- titlePosition="bottom"onClick={() => apply(mind)}/>))}- </Toolbar>+ </OverlayToolbar>);}@@ -131,31 +131,6 @@ function buildDirections() {];}-/** The surface both bars stand on, and the reach of the map they are kept out of. */-function Toolbar({ className, children }: { className: string, children: ComponentChildren }) {- return (- <div- className={`mind-map-toolbar ${className}`}- /* Keep interactions inside the bar from reaching the map underneath, which would- otherwise take a press on a button for the start of a drag or a selection. */- onMouseDown={(e) => e.stopPropagation()}- >- {children}- </div>- );-}--/** Dressed as the buttons floating over a rendered diagram are (see SplitEditor's `PreviewButton`). */-function ToolbarButton({ titlePosition, ...props }: ActionButtonProps) {- return <ActionButton- {...props}- className="tn-tool-button"- noIconActionClass- // Away from the edge of the map the bar stands at, where a tooltip would fall off it.- titlePosition={titlePosition ?? "top"}- />;-}-/*** The scale the map is drawn at, followed as it changes — by these buttons, by the wheel, or by the* map fitting itself. What it is read for is whether there is any room left to zoom, which is what