Skip to content

Build your personal knowledge base with Trilium Notes

feat(relation_map): place notes like the geo map and edit them in a side panel

Elian Doran7248390667b4
diff --git a/apps/client/src/translations/en-GB/translation.json b/apps/client/src/translations/en-GB/translation.json
index e5ed7fbd61..336841b60f 100644
--- a/apps/client/src/translations/en-GB/translation.json
+++ b/apps/client/src/translations/en-GB/translation.json
@@ -246,5 +246,8 @@
},
"sync_2": {
"effective_server_disabled": "Synchronisation is turned off."
+ },
+ "relation_map": {
+ "note_color": "Note colour"
}
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 6919796e54..22bca1996e 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1232,7 +1232,9 @@
},
"relation_map_buttons": {
"create_child_note_title": "Create child note and add it to map",
- "create_child_note_text": "Add note"
+ "create_child_note_text": "Add note",
+ "create_child_note_cancel_title": "Cancel adding the note",
+ "create_child_note_cancel_text": "Cancel"
},
"image_navigation": {
"previous": "Previous image: {{- title}}",
@@ -1727,9 +1729,14 @@
"note_not_found": "Note {{noteId}} not found!",
"cannot_match_transform": "Cannot match transform: {{transform}}",
"note_already_in_diagram": "Note \"{{title}}\" is already in the diagram.",
- "enter_title_of_new_note": "Enter title of new note",
"default_new_note_title": "new note",
- "click_on_canvas_to_place_new_note": "Click on canvas to place new note"
+ "add_note_toast_title": "New note",
+ "add_note_instruction": "Click on the map to place a new note there or press Escape to dismiss.",
+ "close_note_pane": "Close",
+ "expand_note_pane": "Expand the note to fill the map",
+ "restore_note_pane": "Put the note back beside the map",
+ "note_color": "Note color",
+ "remove_from_map": "Remove from map"
},
"render": {
"setup_title": "Display custom HTML or Preact JSX inside this note",
diff --git a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.spec.tsx b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.spec.tsx
index 21bddf3802..63b70ff1a4 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.spec.tsx
@@ -65,15 +65,23 @@ describe("relation map MapToolbar", () => {
describe("relation map EditToolbar", () => {
it("offers to add a note in words as well as in a mark, and hands the asking to the map view", () => {
- const { button, onAddNote } = renderEditToolbar();
+ const { button, onTogglePlacement } = renderEditToolbar();
// The mark is a child of the button rather than the button's own class — the words beside it
// are to stay words (see OverlayControlGroup.tsx).
expect(button()?.querySelector(".bx-note")).not.toBeNull();
expect(button()?.textContent).toBe("relation_map_buttons.create_child_note_text");
+ expect(button()?.classList.contains("active")).toBe(false);
act(() => button()?.click());
- expect(onAddNote).toHaveBeenCalledTimes(1);
+ expect(onTogglePlacement).toHaveBeenCalledTimes(1);
+ });
+
+ it("shows as pressed while the map is armed, and offers to cancel", () => {
+ const { button } = renderEditToolbar({ placing: true });
+
+ expect(button()?.classList.contains("active")).toBe(true);
+ expect(button()?.textContent).toBe("relation_map_buttons.create_child_note_cancel_text");
});
it("refuses on a map that may not be edited", () => {
@@ -114,16 +122,16 @@ function renderToolbar({ withMap = true } = {}) {
}
/** Builds the editing group, which asks for nothing beyond what its one button is driven by. */
-function renderEditToolbar({ isReadOnly = false } = {}) {
- const onAddNote = vi.fn();
+function renderEditToolbar({ isReadOnly = false, placing = false } = {}) {
+ const onTogglePlacement = vi.fn();
let container: HTMLElement | undefined;
act(() => {
- container = renderInto(<EditToolbar isReadOnly={isReadOnly} onAddNote={onAddNote} />);
+ container = renderInto(<EditToolbar isReadOnly={isReadOnly} placing={placing} onTogglePlacement={onTogglePlacement} />);
});
if (!container) throw new Error("the toolbar was not rendered");
return {
- onAddNote,
+ onTogglePlacement,
button: () => container?.querySelector<HTMLButtonElement>(".relation-map-edit-toolbar button") ?? null
};
}
diff --git a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx
index cc921ca9ac..9156940bc4 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/MapToolbar.tsx
@@ -53,9 +53,11 @@ export default function MapToolbar({ panZoom, onCommand }: MapToolbarProps) {
interface EditToolbarProps {
/** The map may not be edited, which is every one of these buttons refused at once. */
isReadOnly: boolean;
- /** Asks for a title and leaves the note waiting for a place to be clicked (see `useNoteCreation`
- * in RelationMap.tsx). */
- onAddNote: () => void;
+ /** The map is armed for the next click to place a new note, which the button shows as pressed. */
+ placing: boolean;
+ /** Arms the map for a note to be placed, or disarms it (see `useNotePlacement` in
+ * RelationMap.tsx). */
+ onTogglePlacement: () => void;
}
/**
@@ -78,19 +80,20 @@ interface EditToolbarProps {
* note-and-plus in the icon set, and that leaves the mark unlike the + of the zoom step opposite.
*
* It stands on the map rather than in the note's own bar of actions, where it was: what it starts is
- * finished by a click on the map, so it belongs beside the canvas that answers it — the toast that
- * follows says as much in words.
+ * finished by a click on the map, so it belongs beside the canvas that answers it. While the map is
+ * armed the button shows as pressed, and a second press disarms it.
*/
-export function EditToolbar({ isReadOnly, onAddNote }: EditToolbarProps) {
+export function EditToolbar({ isReadOnly, placing, onTogglePlacement }: EditToolbarProps) {
return (
<OverlayControlGroup className="relation-map-edit-toolbar" placement="bottom-center">
<OverlayControlButton
- title={t("relation_map_buttons.create_child_note_title")}
+ title={placing ? t("relation_map_buttons.create_child_note_cancel_title") : t("relation_map_buttons.create_child_note_title")}
icon="bx-note"
- text={t("relation_map_buttons.create_child_note_text")}
+ text={placing ? t("relation_map_buttons.create_child_note_cancel_text") : t("relation_map_buttons.create_child_note_text")}
className="relation-map-add-note-button"
disabled={isReadOnly}
- onClick={onAddNote}
+ active={placing}
+ onClick={onTogglePlacement}
/>
</OverlayControlGroup>
);
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx b/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
index efb566a4e2..285414736b 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
@@ -28,9 +28,11 @@ const NOTE_BOX_TARGET_CONFIG = {
interface NoteBoxProps extends MapDataNoteEntry {
mapApiRef: RefObject<RelationMapApi | null>;
+ /** The note is open in the note pane. */
+ selected?: boolean;
}
-export function NoteBox({ noteId, x, y, mapApiRef }: NoteBoxProps) {
+export function NoteBox({ noteId, x, y, mapApiRef, selected }: NoteBoxProps) {
const [ note, setNote ] = useState<FNote | null>();
const title = useNoteProperty(note, "title");
useEffect(() => {
@@ -47,6 +49,7 @@ export function NoteBox({ noteId, x, y, mapApiRef }: NoteBoxProps) {
className={`note-box ${note?.getCssClass()}`}
onContextMenu={contextMenuHandler}
x={x} y={y}
+ selected={selected}
draggable={{
start() {},
drag() {},
@@ -64,3 +67,16 @@ export function NoteBox({ noteId, x, y, mapApiRef }: NoteBoxProps) {
</JsPlumbItem>
)
}
+
+/**
+ * The translucent box that follows the pointer while the map waits for a click to place a new
+ * note. `RelationMap` moves it by writing `left`/`top` straight onto the element, so a pointer
+ * moving across the map does not render on every event.
+ */
+export function GhostNoteBox({ elementRef }: { elementRef: RefObject<HTMLDivElement | null> }) {
+ return (
+ <div ref={elementRef} className="note-box relation-map-ghost-note" aria-hidden="true">
+ <span className="title">{t("relation_map.default_new_note_title")}</span>
+ </div>
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NotePane.css b/apps/client/src/widgets/type_widgets/relation_map/NotePane.css
new file mode 100644
index 0000000000..4fe7b1d4ef
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/relation_map/NotePane.css
@@ -0,0 +1,25 @@
+.relation-map-wrapper {
+ --relation-map-inset: var(--overlay-button-inset, 10px);
+ /* Must agree with `PANE_WIDTH` in RelationMap.tsx. */
+ --relation-map-pane-width: 380px;
+}
+
+.relation-map-note-pane-host {
+ display: contents;
+}
+
+.relation-map-wrapper .relation-map-note-pane {
+ position: absolute;
+ top: var(--relation-map-inset);
+ /* Clear of the toolbars along the foot of the map. */
+ bottom: calc(2 * var(--relation-map-inset) + var(--overlay-button-height, 28px));
+ inset-inline-end: var(--relation-map-inset);
+ width: var(--relation-map-pane-width);
+ max-width: calc(100% - 2 * var(--relation-map-inset));
+ /* Over the note boxes, under the toolbars (see MapToolbar.css). */
+ z-index: 9;
+
+ &.maximized {
+ width: calc(100% - 2 * var(--relation-map-inset));
+ }
+}
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx b/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx
new file mode 100644
index 0000000000..4f35d19c92
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/relation_map/NotePane.spec.tsx
@@ -0,0 +1,200 @@
+import { render } from "preact";
+import { useRef, useState } from "preact/hooks";
+import { act } from "preact/test-utils";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import appContext from "../../../components/app_context";
+import Component from "../../../components/component";
+import server from "../../../services/server";
+import { buildNote } from "../../../test/easy-froca";
+import { useNoteContext, useTriliumEvent } from "../../react/hooks";
+import { ParentComponent } from "../../react/react_utils";
+import type RelationMapApi from "./api";
+import NotePane, { type NotePaneHandle, type PaneSelection } from "./NotePane";
+
+/** Stands in for the note's editor, listening for what a real editor listens for. */
+const editorAskedToSave = vi.fn();
+vi.mock("../../NoteDetail", () => ({
+ default: () => {
+ const { note } = useNoteContext();
+ useTriliumEvent("beforeNoteContextRemove", editorAskedToSave);
+ return <div className="note-detail-stub">{note?.title}</div>;
+ }
+}));
+
+const confirmDelete = vi.fn();
+vi.mock("../../../services/dialog", async (importOriginal) => ({
+ default: {
+ ...((await importOriginal<{ default: object }>()).default),
+ confirmDeleteNoteBoxWithNote: (...args: unknown[]) => confirmDelete(...args)
+ }
+}));
+
+// A promoted text field asks the server for the values other notes hold under its name.
+server.get = (async () => []) as unknown as typeof server.get;
+
+interface MountOptions {
+ noteIdsOnMap?: string[];
+ isReadOnly?: boolean;
+ selection?: PaneSelection | null;
+}
+
+describe("relation map NotePane", () => {
+ let container: HTMLElement | undefined;
+ let mapComponent: Component | undefined;
+ let handle: { current: NotePaneHandle | null } = { current: null };
+ const removeItem = vi.fn();
+ const mapApi = { branchIdFor: () => "branch", removeItem } as unknown as RelationMapApi;
+
+ beforeEach(() => {
+ container = document.createElement("div");
+ document.body.appendChild(container);
+ (appContext as unknown as { tabManager: unknown }).tabManager = {
+ getActiveContext: () => undefined,
+ getActiveContextNotePath: () => undefined
+ };
+ buildNote({
+ id: "root", title: "root", children: [
+ { id: "mapnote", title: "Map", children: [
+ { id: "first", title: "First" },
+ { id: "second", title: "Second" }
+ ] }
+ ]
+ });
+ editorAskedToSave.mockClear();
+ removeItem.mockClear();
+ confirmDelete.mockReset();
+ });
+
+ afterEach(() => {
+ if (container) {
+ render(null, container);
+ container.remove();
+ container = undefined;
+ }
+ mapComponent = undefined;
+ (appContext as unknown as { tabManager: unknown }).tabManager = undefined;
+ });
+
+ /** Stands in for `RelationMap`, which owns the selection and the notes on the map. */
+ function Harness({ noteIdsOnMap, isReadOnly, initialSelection }: {
+ noteIdsOnMap: string[]; isReadOnly: boolean; initialSelection: PaneSelection | null;
+ }) {
+ const [ selection, setSelection ] = useState(initialSelection);
+ const paneRef = useRef<NotePaneHandle>(null);
+ handle = paneRef;
+ const mapApiRef = useRef(mapApi);
+ return <NotePane
+ paneRef={paneRef} noteIdsOnMap={noteIdsOnMap} mapApiRef={mapApiRef}
+ isReadOnly={isReadOnly} selection={selection} onSelect={setSelection}
+ />;
+ }
+
+ /** Mounts the pane afresh, with the map's selection set to `selection`. */
+ async function mount(options: MountOptions = {}) {
+ if (container) render(null, container);
+ await update(options);
+ }
+
+ /** Re-renders with new props, keeping the selection the pane has now. */
+ async function update({ noteIdsOnMap = [ "first", "second" ], isReadOnly = false, selection = { noteId: "first" } }: MountOptions = {}) {
+ mapComponent ??= new Component();
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={mapComponent as Component}>
+ <Harness noteIdsOnMap={noteIdsOnMap} isReadOnly={isReadOnly} initialSelection={selection} />
+ </ParentComponent.Provider>,
+ container as HTMLElement
+ );
+ });
+ await settle();
+ }
+
+ async function settle() {
+ await act(async () => {
+ for (let i = 0; i < 20; i++) await new Promise((resolve) => setTimeout(resolve));
+ });
+ }
+
+ const pane = () => container?.querySelector(".relation-map-note-pane") ?? null;
+ const title = () => pane()?.querySelector<HTMLInputElement>(".title-row input")?.value;
+
+ it("shows the selected note, and closes from its button after asking the editor to save", async () => {
+ await mount();
+
+ expect(title()).toBe("First");
+ expect(pane()?.querySelector(".note-detail-stub")?.textContent).toBe("First");
+
+ const close = pane()?.querySelector<HTMLButtonElement>(".tn-overlay-panel-close");
+ expect(close).toBeTruthy();
+ await act(async () => close?.click());
+
+ expect(editorAskedToSave).toHaveBeenCalledTimes(1);
+ expect(pane()).toBeNull();
+ });
+
+ it("closes on Escape and through the handle the map holds", async () => {
+ await mount();
+ await act(async () => { window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })); });
+ expect(pane()).toBeNull();
+
+ await mount({ selection: { noteId: "second" } });
+ expect(title()).toBe("Second");
+ await act(async () => handle.current?.close());
+ expect(editorAskedToSave).toHaveBeenCalled();
+ expect(pane()).toBeNull();
+ });
+
+ it("stays closed for a note that is not on the map, and closes once its note leaves it", async () => {
+ await mount({ noteIdsOnMap: [ "second" ] });
+ expect(pane()).toBeNull();
+
+ await mount({ selection: { noteId: "second" } });
+ expect(title()).toBe("Second");
+
+ await update({ noteIdsOnMap: [ "first" ] });
+ expect(pane()).toBeNull();
+ });
+
+ it("switches to a note on the map when a link to it is followed inside the pane", async () => {
+ await mount();
+
+ const anchor = document.createElement("a");
+ anchor.setAttribute("href", "#root/mapnote/second");
+ pane()?.querySelector(".relation-map-note-pane-body")?.appendChild(anchor);
+ await act(async () => anchor.click());
+ await settle();
+
+ expect(title()).toBe("Second");
+ });
+
+ it("removes the note from the map once confirmed, and offers no edits on a read-only map", async () => {
+ confirmDelete.mockResolvedValue({ confirmed: true, isDeleteNoteChecked: false });
+ await mount();
+
+ const remove = pane()?.querySelector<HTMLButtonElement>(".tn-embedded-note-remove");
+ expect(remove).toBeTruthy();
+ await act(async () => remove?.click());
+ await settle();
+ expect(removeItem).toHaveBeenCalledWith("first", false);
+
+ await mount({ isReadOnly: true });
+ expect(pane()).toBeTruthy();
+ expect(pane()?.querySelector(".tn-embedded-note-remove")).toBeNull();
+ expect(pane()?.querySelector(".tn-embedded-note-color")).toBeNull();
+ });
+
+ it("keeps wheel and double clicks inside the pane from reaching the map", async () => {
+ const reached = vi.fn();
+ container?.addEventListener("wheel", reached);
+ container?.addEventListener("dblclick", reached);
+ await mount();
+
+ const body = pane()?.querySelector(".relation-map-note-pane-body");
+ expect(body).toBeTruthy();
+ body?.dispatchEvent(new WheelEvent("wheel", { bubbles: true }));
+ body?.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
+
+ expect(reached).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx b/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx
new file mode 100644
index 0000000000..933cbb3c1b
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/relation_map/NotePane.tsx
@@ -0,0 +1,138 @@
+import "./NotePane.css";
+
+import { RefObject } from "preact";
+import { useCallback, useEffect, useImperativeHandle, useState } from "preact/hooks";
+
+import { t } from "../../../services/i18n";
+import { isMobile } from "../../../services/utils";
+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, EmbeddedNoteSurface, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
+import NoteDetail from "../../NoteDetail";
+import PromotedAttributes from "../../PromotedAttributes";
+import ActionButton from "../../react/ActionButton";
+import { useNote } from "../../react/hooks";
+import RelationMapApi from "./api";
+import { confirmRemoveFromMap } from "./context_menu";
+
+/** Which note the pane shows. Owned by the map, which opens the pane on a note it has just created. */
+export interface PaneSelection {
+ noteId: string;
+ /** The note was just created, so the pane opens with its stock title selected. */
+ isNew?: boolean;
+}
+
+export interface NotePaneHandle {
+ /** Closes the pane, giving the note's editor the chance to save first. */
+ close(): void;
+}
+
+/**
+ * The note pane standing against the trailing edge of a relation map while a box is selected: the
+ * note's title, promoted attributes and content, editable in place.
+ */
+export default function NotePane({ paneRef, noteIdsOnMap, mapApiRef, isReadOnly, selection, onSelect }: {
+ paneRef: RefObject<NotePaneHandle | null>;
+ /** The notes the map shows, which keep the pane open and which a link inside it can switch to. */
+ noteIdsOnMap: string[];
+ mapApiRef: RefObject<RelationMapApi | null>;
+ /** The map cannot be edited, so the pane offers only the ways of opening the note. */
+ isReadOnly: boolean;
+ /** The note the pane shows, or `null` while the pane is closed. */
+ selection: PaneSelection | null;
+ onSelect(selection: PaneSelection | null): void;
+}) {
+ const note = useNote(selection?.noteId, true);
+ const [ maximized, setMaximized ] = useState(false);
+ const { noteContext, component: paneComponent } = useEmbeddedNoteContext(note ?? undefined, PANE_NTX_ID_PREFIX);
+
+ const closePane = useCallback(() => {
+ if (noteContext.ntxId) {
+ void announceEmbeddedNoteClosing(paneComponent, noteContext.ntxId);
+ }
+ onSelect(null);
+ }, [ paneComponent, noteContext, onSelect ]);
+ useImperativeHandle<NotePaneHandle | null, NotePaneHandle | null>(paneRef, () => ({ close: closePane }), [ closePane ]);
+
+ const followLink = useCallback((noteId: string) => {
+ if (!noteIdsOnMap.includes(noteId)) return false;
+ onSelect({ noteId });
+ return true;
+ }, [ noteIdsOnMap, onSelect ]);
+
+ // The pane opens beside the map each time, however it was left.
+ useEffect(() => {
+ if (!selection) setMaximized(false);
+ }, [ selection ]);
+
+ // A note taken off the map, or deleted, closes the pane.
+ const isOnMap = !!selection && noteIdsOnMap.includes(selection.noteId);
+ useEffect(() => {
+ if (selection && (!isOnMap || note === null)) {
+ closePane();
+ }
+ }, [ selection, isOnMap, note, closePane ]);
+
+ // A phone's dialog answers Escape itself.
+ useEffect(() => {
+ if (!selection || isMobile()) return;
+
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") closePane();
+ };
+ // Captured, since `OverlayPanel` stops key presses made inside it from bubbling.
+ window.addEventListener("keydown", onKeyDown, true);
+ return () => window.removeEventListener("keydown", onKeyDown, true);
+ }, [ selection?.noteId, closePane ]);
+
+ if (!note || !isOnMap) return null;
+
+ return (
+ // `relation-map-note-pane-host` keeps the wheel, double clicks and touches made in the pane
+ // from reaching `panzoom`, which listens on the whole map.
+ <div
+ className="relation-map-note-pane-host"
+ onWheel={stopPropagation}
+ onDblClick={stopPropagation}
+ onTouchStart={stopPropagation}
+ >
+ <EmbeddedNoteScope component={paneComponent} noteContext={noteContext}>
+ <EmbeddedNoteSurface
+ note={note}
+ panelClassName="relation-map-note-pane"
+ sheetClassName="relation-map-note-sheet"
+ bodyClassName="relation-map-note-pane-body"
+ closeText={t("relation_map.close_note_pane")}
+ maximize={{
+ maximized,
+ onChange: setMaximized,
+ expandText: t("relation_map.expand_note_pane"),
+ restoreText: t("relation_map.restore_note_pane")
+ }}
+ onClose={closePane}
+ onFollowLink={followLink}
+ >
+ <EmbeddedNoteActions>
+ <OpenNoteActions note={note} />
+ {!isReadOnly && <>
+ <NoteColorAction note={note} title={t("relation_map.note_color")} />
+ <ActionButton
+ className="tn-embedded-note-remove"
+ icon="bx bx-trash"
+ text={t("relation_map.remove_from_map")}
+ onClick={() => void confirmRemoveFromMap(note, mapApiRef)}
+ />
+ </>}
+ </EmbeddedNoteActions>
+ <PromotedAttributes />
+ <NoteDetail />
+ </EmbeddedNoteSurface>
+ {selection?.isNew && <SelectTitleOnFirstOpen />}
+ </EmbeddedNoteScope>
+ </div>
+ );
+}
+
+const PANE_NTX_ID_PREFIX = "_relation-map-note-pane";
+
+function stopPropagation(e: Event) {
+ e.stopPropagation();
+}
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.css b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.css
index 3f371d8e21..354e0c0e57 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.css
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.css
@@ -85,3 +85,23 @@
.note-detail-relation-map .ui-contextmenu {
z-index: 100;
}
+
+.relation-map-wrapper.placing-note {
+ cursor: crosshair;
+}
+
+.note-detail-relation-map .note-box.relation-map-ghost-note {
+ border-style: dashed;
+ pointer-events: none;
+ opacity: 0;
+
+ &.visible {
+ opacity: 0.5;
+ }
+}
+
+.note-detail-relation-map .note-box.selected {
+ border-color: var(--input-focus-outline-color);
+ box-shadow: 0 0 0 2px var(--input-focus-outline-color);
+ opacity: 1;
+}
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.spec.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.spec.tsx
new file mode 100644
index 0000000000..4b98b5b501
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.spec.tsx
@@ -0,0 +1,114 @@
+import { render } from "preact";
+import { useRef } from "preact/hooks";
+import { act } from "preact/test-utils";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import { useCanvasClicks } from "./RelationMap";
+import { noteIdToId } from "./utils";
+
+describe("relation map canvas clicks", () => {
+ let container: HTMLElement | undefined;
+ const onPlace = vi.fn();
+ const onSelectNote = vi.fn();
+ const onClickEmpty = vi.fn();
+
+ beforeEach(() => {
+ container = document.createElement("div");
+ document.body.appendChild(container);
+ for (const fn of [ onPlace, onSelectNote, onClickEmpty ]) fn.mockClear();
+ });
+
+ afterEach(() => {
+ if (container) {
+ render(null, container);
+ container.remove();
+ container = undefined;
+ }
+ });
+
+ /** The wrapper, the panned canvas with a box on it, and a toolbar standing over the canvas. */
+ function Harness({ placing }: { placing: boolean }) {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const clickProps = useCanvasClicks({ containerRef, placing, onPlace, onSelectNote, onClickEmpty });
+ return (
+ <div className="wrapper" {...clickProps}>
+ <div ref={containerRef} className="canvas">
+ <div id={noteIdToId("boxnote")} className="note-box">
+ <a className="title" href="#root/boxnote">Box</a>
+ </div>
+ </div>
+ <button className="toolbar" type="button" />
+ </div>
+ );
+ }
+
+ function mount(placing = false) {
+ act(() => render(<Harness placing={placing} />, container as HTMLElement));
+ const find = (selector: string) => {
+ const element = container?.querySelector<HTMLElement>(selector);
+ if (!element) throw new Error(`${selector} was not rendered`);
+ return element;
+ };
+ return { wrapper: find(".wrapper"), canvas: find(".canvas"), title: find(".title"), toolbar: find(".toolbar") };
+ }
+
+ /** A press and release at the same spot, or `moved` pixels apart. */
+ function click(target: HTMLElement, { moved = 0, ...init }: MouseEventInit & { moved?: number } = {}) {
+ target.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, clientX: 10, clientY: 10 }));
+ const event = new MouseEvent("click", { bubbles: true, cancelable: true, clientX: 10 + moved, clientY: 10, ...init });
+ act(() => { target.dispatchEvent(event); });
+ return event;
+ }
+
+ /** Clicks that reach the document, where `link.ts` handles a click on a link. */
+ const reachedDocument = vi.fn();
+ beforeEach(() => {
+ reachedDocument.mockClear();
+ document.addEventListener("click", reachedDocument);
+ });
+ afterEach(() => document.removeEventListener("click", reachedDocument));
+
+ it("selects the box clicked, keeping its title link from navigating", () => {
+ const { title } = mount();
+
+ const event = click(title);
+
+ expect(onSelectNote).toHaveBeenCalledWith("boxnote");
+ expect(event.defaultPrevented).toBe(true);
+ expect(reachedDocument).not.toHaveBeenCalled();
+ });
+
+ it("leaves a modified click to the link, and a pan or drag to the map", () => {
+ const { title, canvas } = mount();
+
+ click(title, { ctrlKey: true });
+ expect(reachedDocument).toHaveBeenCalledTimes(1);
+ click(title, { moved: 20 });
+ click(canvas, { moved: 20 });
+
+ expect(onSelectNote).not.toHaveBeenCalled();
+ expect(onClickEmpty).not.toHaveBeenCalled();
+ });
+
+ it("closes the pane on empty canvas, but not on what stands over the map", () => {
+ const { wrapper, canvas, toolbar } = mount();
+
+ click(canvas);
+ click(wrapper);
+ expect(onClickEmpty).toHaveBeenCalledTimes(2);
+
+ click(toolbar);
+ expect(onClickEmpty).toHaveBeenCalledTimes(2);
+ });
+
+ it("places a note wherever an armed map is clicked, a box included", () => {
+ const { title, toolbar } = mount(true);
+
+ const event = click(title);
+ click(toolbar);
+
+ expect(onPlace).toHaveBeenCalledTimes(1);
+ expect(event.defaultPrevented).toBe(true);
+ expect(onSelectNote).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
index 31e035a040..daf04c31bc 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
@@ -1,6 +1,7 @@
import "./RelationMap.css";
-import { CreateChildrenResponse, RelationMapPostResponse } from "@triliumnext/commons";
+import { RelationMapPostResponse } from "@triliumnext/commons";
+import clsx from "clsx";
import { jsPlumbInstance, OnConnectionBindInfo } from "jsplumb";
// The library's own types rather than the hand-written `PanZoom` in types.d.ts, which stops at the
// handful of calls the map made when it was written and knows nothing of the rest — the ends of the
@@ -10,8 +11,8 @@ import { HTMLAttributes, RefObject } from "preact";
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
-import dialog from "../../../services/dialog";
import { t } from "../../../services/i18n";
+import note_create from "../../../services/note_create";
import server from "../../../services/server";
import toast from "../../../services/toast";
import { useEditorSpacedUpdate, useNoteLabelBoolean, useTriliumEvent, useTriliumEvents } from "../../react/hooks";
@@ -20,16 +21,12 @@ import RelationMapApi, { ClientRelation, MapData, MapDataNoteEntry, RelationType
import { buildRelationContextMenuHandler } from "./context_menu";
import { JsPlumb } from "./jsplumb";
import MapToolbar, { EditToolbar } from "./MapToolbar";
-import { NoteBox } from "./NoteBox";
+import { GhostNoteBox, NoteBox } from "./NoteBox";
+import NotePane, { type NotePaneHandle, type PaneSelection } from "./NotePane";
import setupOverlays, { uniDirectionalOverlays } from "./overlays";
import RelationNamePopover, { type AskRelationName, useRelationNamePrompt } from "./RelationNamePopover";
import { getMousePosition, getZoom, idToNoteId, noteIdToId } from "./utils";
-interface Clipboard {
- noteId: string;
- title: string;
-}
-
declare module "jsplumb" {
interface Connection {
@@ -110,11 +107,24 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
pbApiRef.current.setZoom(zoom);
}, [ data ]);
- const clickCallback = useNoteCreation({
+ const [ selection, setSelection ] = useState<PaneSelection | null>(null);
+ const noteIdsOnMap = useMemo(() => data?.notes.map((entry) => entry.noteId) ?? [], [ data ]);
+ const paneRef = useRef<NotePaneHandle>(null);
+ const placement = useNotePlacement({
containerRef,
note,
ntxId,
- mapApiRef
+ mapApiRef,
+ // The click that places the note has to reach the map, which the pane partly covers.
+ onArm: () => paneRef.current?.close(),
+ onCreated: (noteId) => setSelection({ noteId, isNew: true })
+ });
+ const clickProps = useCanvasClicks({
+ containerRef,
+ placing: placement.placing,
+ onPlace: placement.placeAt,
+ onSelectNote: (noteId) => setSelection({ noteId }),
+ onClickEmpty: () => paneRef.current?.close()
});
const dragProps = useNoteDragging({ containerRef, mapApiRef });
@@ -143,8 +153,10 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
return (
<div
- className="relation-map-wrapper"
- onClick={clickCallback}
+ className={clsx("relation-map-wrapper", placement.placing && "placing-note")}
+ onMouseMove={placement.followPointer}
+ onMouseLeave={placement.hideGhost}
+ {...clickProps}
{...dragProps}
>
<JsPlumb
@@ -161,8 +173,9 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
onConnection={connectionCallback}
>
{data?.notes.map(note => (
- <NoteBox {...note} mapApiRef={mapApiRef} />
+ <NoteBox {...note} mapApiRef={mapApiRef} selected={note.noteId === selection?.noteId} />
))}
+ {placement.placing && <GhostNoteBox elementRef={placement.ghostRef} />}
</JsPlumb>
{/* Both groups stand on the map whatever layout the note is read in: what is done to a
@@ -170,7 +183,8 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
reader is looking while dragging one. */}
<EditToolbar
isReadOnly={isReadOnly}
- onAddNote={() => parentComponent?.triggerEvent("relationMapCreateChildNote", { ntxId })}
+ placing={placement.placing}
+ onTogglePlacement={() => parentComponent?.triggerEvent("relationMapCreateChildNote", { ntxId })}
/>
<MapToolbar
@@ -178,6 +192,15 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
onCommand={(command) => parentComponent?.triggerEvent(command, { ntxId })}
/>
+ <NotePane
+ paneRef={paneRef}
+ noteIdsOnMap={noteIdsOnMap}
+ mapApiRef={mapApiRef}
+ isReadOnly={isReadOnly}
+ selection={selection}
+ onSelect={setSelection}
+ />
+
{relationNamePrompt.request && (
<RelationNamePopover
key={relationNamePrompt.request.id}
@@ -332,45 +355,156 @@ async function useRelationData(noteId: string, mapData: MapData | undefined, map
}, [ relations, mapData ]);
}
-function useNoteCreation({ ntxId, note, containerRef, mapApiRef }: {
+/**
+ * Arms the map for the next click to place a new note, and creates the note where it lands.
+ *
+ * Pressing the button again disarms the map, as Escape does. A translucent box follows the pointer
+ * while the map is armed (see {@link GhostNoteBox}). The note is created without a title, so it takes
+ * the name any new note takes (or the map's `#titleTemplate`), and the pane opens on it with that
+ * name selected.
+ */
+function useNotePlacement({ ntxId, note, containerRef, mapApiRef, onArm, onCreated }: {
ntxId: string | null | undefined;
note: FNote;
containerRef: RefObject<HTMLDivElement | null>;
mapApiRef: RefObject<RelationMapApi | null>;
+ onArm(): void;
+ onCreated(noteId: string): void;
}) {
- const clipboardRef = useRef<Clipboard>(null);
- useTriliumEvent("relationMapCreateChildNote", async ({ ntxId: eventNtxId }) => {
+ const [ placing, setPlacing ] = useState(false);
+ const ghostRef = useRef<HTMLDivElement>(null);
+
+ useTriliumEvent("relationMapCreateChildNote", ({ ntxId: eventNtxId }) => {
if (eventNtxId !== ntxId) return;
- const title = await dialog.prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") });
- if (!title?.trim()) return;
+ if (!placing) onArm();
+ setPlacing(!placing);
+ });
- const { note: createdNote } = await server.post<CreateChildrenResponse>(`notes/${note.noteId}/children?target=into`, {
- title,
- content: "",
- type: "text"
+ // Tied to the state rather than to what armed it, so the toast and the listener go on cancel,
+ // on placement and on unmount alike.
+ useEffect(() => {
+ if (!placing) return;
+
+ const toastId = `relation-map-placement-${ntxId}`;
+ toast.showPersistent({
+ id: toastId,
+ icon: "plus",
+ title: t("relation_map.add_note_toast_title"),
+ message: t("relation_map.add_note_instruction")
});
- toast.showMessage(t("relation_map.click_on_canvas_to_place_new_note"));
- clipboardRef.current = {
- noteId: createdNote.noteId,
- title
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setPlacing(false);
};
- });
- const onClickHandler = useCallback((e: MouseEvent) => {
- const clipboard = clipboardRef.current;
- if (clipboard && containerRef.current && mapApiRef.current) {
- const zoom = getZoom(containerRef.current);
- let { x, y } = getMousePosition(e, containerRef.current, zoom);
+ window.addEventListener("keydown", onKeyDown);
+
+ return () => {
+ window.removeEventListener("keydown", onKeyDown);
+ toast.closePersistent(toastId);
+ };
+ }, [ placing, ntxId ]);
- // modifying position so that the cursor is on the top-center of the box
- x -= 80;
- y -= 15;
+ const followPointer = useCallback((e: MouseEvent) => {
+ const ghost = ghostRef.current;
+ const container = containerRef.current;
+ if (!ghost || !container) return;
- mapApiRef.current.createItem({ noteId: clipboard.noteId, x, y });
- clipboardRef.current = null;
+ const { x, y } = boxPositionAt(e, container);
+ ghost.style.left = `${x}px`;
+ ghost.style.top = `${y}px`;
+ // Hidden over the toolbars, which a click does not place a note through.
+ ghost.classList.toggle("visible", isOnCanvas(e, container));
+ }, [ containerRef ]);
+
+ const hideGhost = useCallback(() => ghostRef.current?.classList.remove("visible"), []);
+
+ const placeAt = useCallback(async (e: MouseEvent) => {
+ const container = containerRef.current;
+ if (!container) return;
+
+ // Disarmed first, so a failure to create the note does not leave the map armed.
+ setPlacing(false);
+ const position = boxPositionAt(e, container);
+
+ const { note: created } = await note_create.createNote(note.noteId, {
+ content: "",
+ type: "text",
+ activate: false,
+ isProtected: note.isProtected
+ });
+ if (!created || !mapApiRef.current) return;
+
+ mapApiRef.current.createItem({ noteId: created.noteId, ...position });
+ onCreated(created.noteId);
+ }, [ note, containerRef, mapApiRef, onCreated ]);
+
+ return { placing, ghostRef, followPointer, hideGhost, placeAt };
+}
+
+/**
+ * Routes a click on the map: it places a new note while the map is armed, selects the box it lands
+ * on, or closes the pane when it lands on empty canvas. A click that ends a pan or a drag counts as
+ * none of these, and clicks on whatever stands over the map (toolbars, the pane, the relation name
+ * popover) are left alone.
+ *
+ * Captured, so a box's title link does not navigate away from the map. A modified click on the
+ * title still reaches the link, which opens the note in a new tab or window.
+ */
+export function useCanvasClicks({ containerRef, placing, onPlace, onSelectNote, onClickEmpty }: {
+ containerRef: RefObject<HTMLDivElement | null>;
+ placing: boolean;
+ onPlace(e: MouseEvent): void;
+ onSelectNote(noteId: string): void;
+ onClickEmpty(): void;
+}): Pick<HTMLAttributes<HTMLDivElement>, "onPointerDownCapture" | "onClickCapture"> {
+ const pressedAt = useRef<{ x: number; y: number }>(null);
+
+ return {
+ onPointerDownCapture(e) {
+ pressedAt.current = { x: e.clientX, y: e.clientY };
+ },
+ onClickCapture(e) {
+ const container = containerRef.current;
+ const pressed = pressedAt.current;
+ if (!container || !isOnCanvas(e, container) || e.button !== 0) return;
+ if (pressed && Math.hypot(e.clientX - pressed.x, e.clientY - pressed.y) > CLICK_TOLERANCE) return;
+
+ if (placing) {
+ e.preventDefault();
+ e.stopPropagation();
+ onPlace(e);
+ return;
+ }
+
+ const box = e.target instanceof Element ? e.target.closest<HTMLElement>(".note-box") : null;
+ if (!box) {
+ onClickEmpty();
+ return;
+ }
+ if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
+
+ e.preventDefault();
+ e.stopPropagation();
+ onSelectNote(idToNoteId(box.id));
}
- }, []);
- return onClickHandler;
+ };
+}
+
+/** Where the pointer stands on a box being placed: the top centre of its title. */
+const PLACEMENT_OFFSET = { x: 80, y: 15 };
+
+/** How far, in pixels, the pointer can move between press and release for the click to count. */
+const CLICK_TOLERANCE = 4;
+
+/** The map position, in unzoomed map pixels, of a box placed under the pointer. */
+function boxPositionAt(e: MouseEvent, container: HTMLDivElement) {
+ const { x, y } = getMousePosition(e, container, getZoom(container));
+ return { x: x - PLACEMENT_OFFSET.x, y: y - PLACEMENT_OFFSET.y };
+}
+
+/** Whether the event happened on the map itself, rather than on something standing over it. */
+function isOnCanvas(e: MouseEvent, container: HTMLDivElement) {
+ return e.target === e.currentTarget || (e.target instanceof Node && container.contains(e.target));
}
function useNoteDragging({ containerRef, mapApiRef }: {
diff --git a/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts b/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
index 5bbf1891a2..41254245bd 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
+++ b/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
@@ -45,20 +45,7 @@ export function buildNoteContextMenuHandler(note: FNote | null | undefined, mapA
{
title: t("relation_map.remove_note"),
uiIcon: "bx bx-trash",
- handler: async () => {
- if (!note) return;
-
- // The branch is all the dialog is told: from it, it works out for itself
- // whether ticking the box would delete the note or merely unfile it here,
- // and says so (see confirmDeleteNoteBoxWithNote).
- const result = await dialog.confirmDeleteNoteBoxWithNote(note.title, {
- noteId: note.noteId,
- branchId: mapApiRef.current?.branchIdFor(note.noteId)
- });
- if (typeof result !== "object" || !result.confirmed) return;
-
- mapApiRef.current?.removeItem(note.noteId, result.isDeleteNoteChecked);
- }
+ handler: () => confirmRemoveFromMap(note, mapApiRef)
},
],
selectMenuItemHandler({ command }) {
@@ -69,6 +56,23 @@ export function buildNoteContextMenuHandler(note: FNote | null | undefined, mapA
};
}
+/**
+ * Asks whether to take the note off the map, and whether to delete it from the tree as well, then
+ * does so. Serves the box's context menu and the note pane.
+ */
+export async function confirmRemoveFromMap(note: FNote, mapApiRef: RefObject<RelationMapApi | null>) {
+ // The branch is all the dialog is told: from it, it works out for itself whether ticking the
+ // box would delete the note or merely unfile it here, and says so (see
+ // confirmDeleteNoteBoxWithNote).
+ const result = await dialog.confirmDeleteNoteBoxWithNote(note.title, {
+ noteId: note.noteId,
+ branchId: mapApiRef.current?.branchIdFor(note.noteId)
+ });
+ if (typeof result !== "object" || !result.confirmed) return;
+
+ await mapApiRef.current?.removeItem(note.noteId, result.isDeleteNoteChecked);
+}
+
export function buildRelationContextMenuHandler(connection: Connection, mapApiRef: RefObject<RelationMapApi | null>, askRelationName: AskRelationName) {
return (_, event: MouseEvent) => {
if (connection.getType().includes("link")) {
diff --git a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
index 12644224ad..9c3e91e664 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
@@ -55,13 +55,16 @@ export function JsPlumb({ className, props, children, containerRef: externalCont
)
}
-export function JsPlumbItem({ x, y, children, draggable, sourceConfig, targetConfig, ...restProps }: {
+export function JsPlumbItem({ x, y, children, draggable, sourceConfig, targetConfig, selected, ...restProps }: {
x: number;
y: number;
children: ComponentChildren;
draggable?: DragOptions;
sourceConfig?: object;
targetConfig?: object;
+ /** Adds the `selected` class. Toggled on the element rather than through `className`, which
+ * would drop the classes jsPlumb adds to it. */
+ selected?: boolean;
} & Pick<HTMLAttributes<HTMLDivElement>, "id" | "className" | "onContextMenu">) {
const containerRef = useRef<HTMLDivElement>(null);
const apiRef = useContext(JsPlumbInstance);
@@ -81,6 +84,10 @@ export function JsPlumbItem({ x, y, children, draggable, sourceConfig, targetCon
apiRef.current.makeTarget(containerRef.current, targetConfig);
}, [ targetConfig ]);
+ useEffect(() => {
+ containerRef.current?.classList.toggle("selected", !!selected);
+ }, [ selected, restProps.className ]);
+
return (
<div
ref={containerRef}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Relation Map.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Relation Map.html
index c2fdff6684..deda66c83b 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Relation Map.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Relation Map.html
@@ -2,11 +2,15 @@
href="#root/_help_zEY4DaJG4YT5">relations</a>.</p>
<h2>Interaction</h2>
<ul>
- <li>To create a new note and add it to the board, press the plus button in
- the&nbsp;<a class="reference-link" href="#root/_help_XpOYSgsLkTJy">Floating buttons</a>.
+ <li>To create a new note and add it to the map, press the <span class="tn-icon bx bx-note"></span> <em>Add note</em> button
+ at the bottom of the map, then click anywhere on the map to place it there.
<ul>
- <li>Afterwards, click anywhere on the map to place it there.</li>
- <li>The note will be placed as a sub-child of the map.</li>
+ <li>While the map waits for the click, a translucent box follows the mouse
+ to show where the note will go. To cancel, press the button again (now
+ labeled <em>Cancel</em>) or press <kbd>Esc</kbd>.</li>
+ <li>The note is created as a child of the map, with the default title of a
+ new note. It opens in the note panel (see below) with its title selected,
+ so you can type its name straight away.</li>
</ul>
</li>
<li>An existing note can also be dragged from the&nbsp;<a class="reference-link"
@@ -33,13 +37,45 @@
or click elsewhere on the map.</li>
</ul>
</li>
- <li>To open a note, either click on the note (opening it in the current view)
- or use the right click menu to open in a new tab.</li>
+ <li>To view or edit a note, click it on the map. This opens the note panel
+ (see below).
+ <ul>
+ <li>To open the note in a new tab instead, <kbd>Ctrl</kbd>+click its title,
+ or use the right click menu.</li>
+ </ul>
+ </li>
<li>To edit the title of a note or to delete it (either from the map, or delete
it completely), right click the note.</li>
<li>To rename or delete a relationship, right click it and select the corresponding
option.</li>
</ul>
+<h2>Note panel</h2>
+<p>When a note on the map is clicked, a panel opens to the right of the map
+ and the note is highlighted. The panel contains:</p>
+<ul>
+ <li>The title and icon of the note, both editable.</li>
+ <li>A button to expand the panel over the whole map, and to restore it afterwards.</li>
+ <li>Buttons to interact with the note:
+ <ul>
+ <li>Open the note in the current tab, or, through the <span class="tn-icon bx bx-dots-horizontal-rounded"></span> menu,
+ in a new tab, split, window or the quick edit popup.</li>
+ <li>A color picker to change the color of the note.</li>
+ <li>A button to remove the note from the map, which can optionally delete
+ the note as well.</li>
+ </ul>
+ </li>
+ <li>The <a class="reference-link" href="#root/_help_OFXdgB2nNk1F">Promoted Attributes</a> of
+ the note, if any.</li>
+ <li>The note's content, which can be edited directly from the panel.</li>
+</ul>
+<p>The color picker and the remove button are not shown if the map is read-only.</p>
+<p>Clicking another note on the map switches the panel to it. Similarly,
+ clicking an <a class="reference-link" href="#root/_help_hrZ1D00cLbal">Internal (reference) links</a> inside
+ the panel switches the panel to that note, as long as it is on the map.</p>
+<p>To close the panel, press the X button at its top-right, click an empty
+ part of the map, or press <kbd>Esc</kbd>.</p>
+<p>On mobile, the note opens as a dialog over the whole screen instead of
+ a panel.</p>
<h2>Development process demo</h2>
<p>This is a basic example how you can create simple diagram using relation
maps:</p>
diff --git a/docs/User Guide/User Guide/Note Types/Relation Map.md b/docs/User Guide/User Guide/Note Types/Relation Map.md
index 5ba8831e48..ed06420ae4 100644
--- a/docs/User Guide/User Guide/Note Types/Relation Map.md
+++ b/docs/User Guide/User Guide/Note Types/Relation Map.md
@@ -3,9 +3,9 @@ Relation map is a type of note which visualizes notes and their [relations](..
## Interaction
-* To create a new note and add it to the board, press the plus button in the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Floating%20buttons.md">Floating buttons</a>.
- * Afterwards, click anywhere on the map to place it there.
- * The note will be placed as a sub-child of the map.
+* To create a new note and add it to the map, press the <span class="tn-icon bx bx-note"></span> _Add note_ button at the bottom of the map, then click anywhere on the map to place it there.
+ * While the map waits for the click, a translucent box follows the mouse to show where the note will go. To cancel, press the button again (now labeled _Cancel_) or press <kbd>Esc</kbd>.
+ * The note is created as a child of the map, with the default title of a new note. It opens in the note panel (see below) with its title selected, so you can type its name straight away.
* An existing note can also be dragged from the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tree.md">Note Tree</a>. It will be placed at the position it's dragged on.
* Multiple notes can also be dragged via <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tree/Multiple%20selection.md">Multiple selection</a>. The notes will be positioned near the dragged position without overlapping.
* The dragged note can be a sub-child of the map, or it can be at any arbitrary position.
@@ -13,10 +13,32 @@ Relation map is a type of note which visualizes notes and their [relations](..
* Drag it over another note to create a relationship pointing from the first note to the second one.
* Drag over the same note to create a self-referencing relationship (represented as a loop).
* Once dragged, a popover next to the relationship asks for its name. Type a new name and press <kbd>Enter</kbd>, or pick a relation name already in use from the suggestions. To cancel, press <kbd>Esc</kbd>, close the popover or click elsewhere on the map.
-* To open a note, either click on the note (opening it in the current view) or use the right click menu to open in a new tab.
+* To view or edit a note, click it on the map. This opens the note panel (see below).
+ * To open the note in a new tab instead, <kbd>Ctrl</kbd>+click its title, or use the right click menu.
* To edit the title of a note or to delete it (either from the map, or delete it completely), right click the note.
* To rename or delete a relationship, right click it and select the corresponding option.
+## Note panel
+
+When a note on the map is clicked, a panel opens to the right of the map and the note is highlighted. The panel contains:
+
+* The title and icon of the note, both editable.
+* A button to expand the panel over the whole map, and to restore it afterwards.
+* Buttons to interact with the note:
+ * Open the note in the current tab, or, through the <span class="tn-icon bx bx-dots-horizontal-rounded"></span> menu, in a new tab, split, window or the quick edit popup.
+ * A color picker to change the color of the note.
+ * A button to remove the note from the map, which can optionally delete the note as well.
+* The <a class="reference-link" href="../Advanced%20Usage/Attributes/Promoted%20Attributes.md">Promoted Attributes</a> of the note, if any.
+* The note's content, which can be edited directly from the panel.
+
+The color picker and the remove button are not shown if the map is read-only.
+
+Clicking another note on the map switches the panel to it. Similarly, clicking an <a class="reference-link" href="Text/Links/Internal%20(reference)%20links.md">Internal (reference) links</a> inside the panel switches the panel to that note, as long as it is on the map.
+
+To close the panel, press the X button at its top-right, click an empty part of the map, or press <kbd>Esc</kbd>.
+
+On mobile, the note opens as a dialog over the whole screen instead of a panel.
+
## Development process demo
This is a basic example how you can create simple diagram using relation maps: