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
refactor(relation-map): drop the floating buttons for the controls on the map
Elian Doran6dac9ca3a155
diff --git a/CLAUDE.md b/CLAUDE.mdindex d76b6f728c..f4cf7eff05 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -175,8 +175,8 @@ Rules for `OverlayControlButton`, which cover every case seen so far:- **`icon` is a boxicons name** (`bx-plus-circle`), **`text` is what stands inside**. Given both, the component renders the mark as a child span itself — never put a `bx` class on a button that also wears words, since the icon font would fall on the words too.- **`active`/`disabled` are props**, not classes concatenated into `className`.- **Pass `overCanvas`** when the group stands over something that is dragged (a map), so a press on a button is not taken for the start of a drag.-- **Tooltip direction is the group's**, via `titlePosition` — a group at the foot of the content leaves it at the default `top`; one at the head passes `"bottom"`. Per-button overrides exist but are rarely right.-- **Positioning is the caller's**: pass a `className` and place the group in that widget's CSS. Only add a class to a *button* if a rule actually uses it.+- **Where the group stands is the group's own**, via `placement` (`top`/`bottom` × `start`/`center`/`end`): it pins itself over the nearest positioned ancestor, and its tooltips open away from that edge. **Never write `position: absolute` plus insets at the call site.** What the caller does hand over, in that widget's CSS, is the room to keep from the edges (`--overlay-group-inset`, or the per-edge `--overlay-group-inset-top`/`-bottom`/`-start`/`-end` where one edge differs — a fullscreen map clearing a notch) and the `z-index`. `titlePosition` overrides the tooltip direction and is rarely right; only add a class to a *button* if a rule actually uses it.+- **Overlay controls exist in every layout.** Never gate a group on `isExperimentalFeatureEnabled("new-layout")`, and when an action moves onto a group, **delete its twin in `FloatingButtonsDefinitions.tsx`** rather than keeping both: that bar only renders in the old layout (`desktop_layout.tsx` mounts it with `!isNewLayout`), so a layout-gated group plus a floating fallback means two implementations of one button that drift. Keep the underlying app commands (e.g. `relationMapResetZoomIn`) even once the group is their only caller — note scripts can fire them via `api.triggerCommand`.- Reuse shared labels from the `common` translation namespace (e.g. `common.fullscreen`) rather than adding a per-widget copy of a string the app already has.#### Dropdown menus and the backdrop blurdiff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsxindex 1bf8f5c47e..74b22151a7 100644--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx@@ -60,7 +60,6 @@ export const DESKTOP_FLOATING_BUTTONS: FloatingButtonsList = [OpenTriliumApiDocsButton,OpenElectronApiDocsButton,SaveToNoteButton,- RelationMapButtons,CopyImageReferenceButton,ExportImageButtons,ExportSpreadsheetButton,@@ -251,35 +250,6 @@ export function buildSaveSqlToNoteHandler(note: FNote) {};}-function RelationMapButtons({ note, isDefaultViewMode, triggerEvent }: FloatingButtonContext) {- const isEnabled = (note.type === "relationMap" && isDefaultViewMode);- return isEnabled && (- <>- {/* Adding a note is not offered here: it stands on the map itself, where the click that- places the note lands (see EditToolbar.tsx in the relation map). */}- <FloatingButton- icon="bx bx-crop"- text={t("relation_map_buttons.reset_pan_zoom_title")}- onClick={() => triggerEvent("relationMapResetPanZoom")}- />-- <div className="btn-group">- <FloatingButton- icon="bx bx-zoom-in"- text={t("relation_map_buttons.zoom_in_title")}- onClick={() => triggerEvent("relationMapResetZoomIn")}- />-- <FloatingButton- icon="bx bx-zoom-out"- text={t("relation_map_buttons.zoom_out_title")}- onClick={() => triggerEvent("relationMapResetZoomOut")}- />- </div>- </>- );-}-function CopyImageReferenceButton({ note, isDefaultViewMode }: FloatingButtonContext) {const hiddenImageCopyRef = useRef<HTMLDivElement>(null);const isEnabled = (diff --git a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsxindex 1871156820..d947b725a5 100644--- a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx@@ -21,15 +21,15 @@ interface MapToolbarProps {** They stand on the {@link OverlayControlGroup} the image viewer's zoom buttons stand on (see* {@link ImageViewer}), as the other two maps' controls and the diagram preview's do, in place of the- * three floating buttons that were here before. The readout between the steps says the scale the way+ * three buttons that floated above the note. The readout between the steps says the scale the way* those do — a hundred being the map drawn at its own size — and pressed, takes the map back there* and to the corner it started in, which is what the button wearing a crop mark did.*- * What the three do is asked for as commands rather than done here, the same commands the floating- * buttons above the map ask for (`RelationMapButtons` in FloatingButtonsDefinitions.tsx): the map is- * driven from two places, and how far a step goes is settled in the one place that answers them. The- * map itself is only read from — for the scale to show, and for the ends of its range, which is what- * leaves a step with nothing left to give disabled. Absent until there is a map to read.+ * What the three do is asked for as commands rather than done here — the same commands a script can+ * trigger (`api.triggerCommand`), which is why they outlive the floating buttons that were the other+ * caller. The map itself is only read from: for the scale to show, and for the ends of its range,+ * which is what leaves a step with nothing left to give disabled. Absent until there is a map to+ * read.*/export default function MapToolbar({ panZoom, onCommand }: MapToolbarProps) {const scale = useMapScale(panZoom);@@ -81,7 +81,7 @@ interface EditToolbarProps {* Adding a note is the one thing this map is edited by, so the button carries its name in words* rather than standing as a bare glyph, as the geo map's does. It wears the mark a note wears — the* very thing a press drops on the map, as the geo map's + wears the pin it drops — rather than the- * folder-and-plus it was given among the floating buttons: a folder is what a note wearing no mark of+ * folder-and-plus it wore among the floating buttons: a folder is what a note wearing no mark of* its own is drawn as once it has children (see `getNoteIcon` in commons), which is neither what this* makes nor what lands on the map. The adding is said by the words beside it, there being no* note-and-plus in the icon set, and that leaves the mark unlike the + of the zoom step opposite.diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsxindex 260bc915e4..f5559d512f 100644--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx@@ -12,7 +12,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"import FNote from "../../../entities/fnote";import dialog from "../../../services/dialog";-import { isExperimentalFeatureEnabled } from "../../../services/experimental_features";import { t } from "../../../services/i18n";import server from "../../../services/server";import toast from "../../../services/toast";@@ -26,8 +25,6 @@ import { NoteBox } from "./NoteBox";import setupOverlays, { uniDirectionalOverlays } from "./overlays";import { getMousePosition, getZoom, idToNoteId, noteIdToId, promptForRelationName } from "./utils";-const isNewLayout = isExperimentalFeatureEnabled("new-layout");-interface Clipboard {noteId: string;title: string;@@ -167,20 +164,18 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent))}</JsPlumb>- {/* Stands on the map in either layout, unlike the camera below, so that the one thing- the map is edited by is on the map itself wherever the rest of the note's buttons- happen to live. */}+ {/* Both groups stand on the map whatever layout the note is read in: what is done to a+ canvas belongs on the canvas, and the bar of buttons above the note is not where the+ reader is looking while dragging one. */}<EditToolbarisReadOnly={isReadOnly}onAddNote={() => parentComponent?.triggerEvent("relationMapCreateChildNote", { ntxId })}/>- {isNewLayout && (- <MapToolbar- panZoom={panZoom}- onCommand={(command) => parentComponent?.triggerEvent(command, { ntxId })}- />- )}+ <MapToolbar+ panZoom={panZoom}+ onCommand={(command) => parentComponent?.triggerEvent(command, { ntxId })}+ /></div>);}