Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): let a marker's note be renamed from its own pane

Elian Doran1a54da327f54
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.css
index 909a4e8141..afc1806b2b 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.css
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css
@@ -1,73 +1,59 @@
/*
- * The pane stands in the trailing corner of the map, held off its edges by as much as everything
- * else over the map is.
+ * An island in the trailing corner rather than a wall against the edge: everything else over this
+ * map is one, and the map is a widget inside a note rather than a screen of its own, so a pane flush
+ * to its edge reads as cropping it.
*
- * An island rather than a wall against the edge: every other thing standing over this map is one —
- * the bar of buttons, the scale and the attribution beside it, and the mind map's panel opposite
- * them all — and the map here is a widget inside a note rather than a screen of its own, so a pane
- * flush to its edge reads as cropping the map instead of standing over it.
- *
- * The width has to agree with `PANE_WIDTH` in DetailPane.tsx, which is what the map is told to hold
- * a selected marker clear of.
+ * The width must agree with `PANE_WIDTH` in DetailPane.tsx.
*/
.geo-map-container {
--geo-detail-pane-width: 380px;
}
.geo-map-container .geo-detail-pane {
- /*
- * The room kept at the foot of the map for the bar of buttons, which stands in this very corner
- * — its own room and as much again over it, so that the two are parted by the same air that
- * holds the bar off the edge. The mind map's panel reckons its own foot the same way.
- *
- * Standing clear of the bar rather than moving it aside: the bar belongs to the map and keeps
- * its corner whatever is opened over it, and a pane that ends above it needs no second file to
- * agree about how wide it is.
- */
+ /* Room at the foot for the bar of buttons, which stands in this same corner: its own height and
+ as much air again. Standing clear of it rather than moving it aside — the mind map's panel
+ reckons its foot the same way. */
--detail-pane-foot: calc(var(--geo-map-inset) + var(--geo-map-toolbar-height) + var(--geo-map-inset));
position: absolute;
- /* The height of the map, less what is kept at either end: a pane that stood only as tall as
- what it holds would be a different pane for every marker, growing and shrinking under the
- pointer as the reader moved from one to the next. What it holds scrolls within it instead
- (see OverlayPanel.css). */
+ /* A fixed height rather than one sized to its contents, which would be a different pane for
+ every marker. What it holds scrolls within it (see OverlayPanel.css). */
top: var(--geo-map-inset);
bottom: var(--detail-pane-foot);
inset-inline-end: var(--geo-map-inset);
width: var(--geo-detail-pane-width);
/* An embedded map may be narrower than the pane would like to be. */
max-width: calc(100% - 2 * var(--geo-map-inset));
- /* Above the canvas and clear of MapLibre's own control corners, which sit at 2 — the same
- reckoning the bar of buttons makes (see MapToolbar.css). */
+ /* Clear of MapLibre's own control corners, which sit at 2 (see MapToolbar.css). */
z-index: 3;
}
/*
- * The ways of opening the note, side by side at the head of the pane — where the first thing to be
- * done with a place is offered on any map that shows you one.
- *
- * Named by their tooltips rather than beside their icons, as every other row of actions in a panel
- * is (see the picture's row in NodePanel): a label apiece would have four of them wrapping onto two
- * lines in a pane this narrow, and these are the same four actions, under the same four icons, that
- * a note is opened by everywhere else in Trilium.
+ * The app's own title row heads the pane (see TitleRow), so a note is renamed from a marker the way
+ * it is renamed anywhere else. It brings no placing of its own, the shared panel giving that only to
+ * its own heading, so the padding and the rule under it are handed over here.
+ */
+.geo-map-container .geo-detail-pane .tn-overlay-panel-header > .title-row {
+ box-sizing: content-box;
+ padding-block: 9px;
+ padding-inline-start: 9px;
+ /* Clear of the close button laid over the end of the row (see OverlayPanel.css). */
+ padding-inline-end: 36px;
+ border-bottom: 1px solid var(--main-border-color);
+}
+
+/*
+ * The ways of opening the note, at the head of the pane. Named by tooltips rather than labels, as
+ * every other row of actions in a panel is: labels would wrap four buttons onto two lines here.
*/
.geo-map-container .geo-detail-pane .geo-detail-pane-actions {
display: flex;
align-items: center;
gap: 4px;
- /* Taking a marker off the map is the one thing in the row that writes rather than reads, so it
- stands at the far end of it: away from the four the reader is reaching for over and over, and
- not somewhere the pointer lands by being a moment early. */
+ /* The one thing in the row that writes rather than reads stands apart from the four being
+ reached for repeatedly, so the pointer cannot land on it by being a moment early. */
.geo-detail-pane-remove {
margin-inline-start: auto;
}
}
-
-/*
- * The pane is dressed in the app's own colors rather than the map's, which is what the bar beside it
- * does (see MapToolbar.css): what stands here is a note, and a note belongs to the app — the same
- * reasoning that leaves a marker's preview dressed as the app's tooltip. Nothing to write for it,
- * the shared panel reading the app's menu colors already; said here so that the difference between
- * the two is a decision on the record rather than an omission.
- */
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index 1d6434446f..699ac4223e 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -6,6 +6,7 @@ import appContext from "../../../components/app_context";
import Component from "../../../components/component";
import type FNote from "../../../entities/fnote";
import attributes from "../../../services/attributes";
+import froca from "../../../services/froca";
import link from "../../../services/link";
import { buildNote } from "../../../test/easy-froca";
import { ParentComponent } from "../../react/react_utils";
@@ -27,10 +28,8 @@ type Listener = (e?: unknown) => void;
const MAP_WIDTH = 1200;
/**
- * A map that records what the pane asks of it, standing in for MapLibre.
- *
- * What it has to answer is the hit test: the pane is bound to the map at large rather than to the
- * marker layer, and asks what is under the point that was clicked (see DetailPane).
+ * A map that records what the pane asks of it, standing in for MapLibre. What it has to answer is
+ * the hit test: the pane is bound to the map at large, not to the marker layer (see DetailPane).
*/
function fakeMap({ width = MAP_WIDTH, features = [] as unknown[] } = {}) {
const listeners = new Map<string, Set<Listener>>();
@@ -75,8 +74,8 @@ describe("DetailPane", () => {
container = document.createElement("div");
document.body.appendChild(container);
- // The pane asks where the reader is hoisted, which the app has settled by the time a map is
- // ever drawn and a test has not: `tabManager` is only built when the app starts.
+ // `tabManager` is only built when the app starts, and the pane asks it where the reader is
+ // hoisted.
(appContext as unknown as { tabManager: unknown }).tabManager = {
getActiveContext: () => undefined,
openContextWithNote: async () => undefined
@@ -85,6 +84,7 @@ describe("DetailPane", () => {
afterEach(() => {
(appContext as unknown as { tabManager: unknown }).tabManager = undefined;
+ mapComponent = undefined;
if (container) {
render(null, container);
@@ -93,11 +93,15 @@ describe("DetailPane", () => {
}
});
+ /** Stands in for the map's own component, which is what the pane hangs under. */
+ let mapComponent: Component | undefined;
+
/** Renders into the same container, so calling it again is a re-render with fresh props. */
function mount(notes: FNote[], map: ReturnType<typeof fakeMap>, placing = false, isReadOnly = false) {
+ mapComponent ??= new Component();
return act(async () => {
render(
- <ParentComponent.Provider value={new Component()}>
+ <ParentComponent.Provider value={mapComponent as Component}>
<ParentMap.Provider value={map as never}>
<DetailPane notes={notes} placing={placing} isReadOnly={isReadOnly} />
</ParentMap.Provider>
@@ -107,12 +111,25 @@ describe("DetailPane", () => {
});
}
+ /** Lets the pane's note context resolve its path and announce the note it landed on. */
+ async function settle() {
+ await act(async () => {
+ for (let i = 0; i < 20; i++) await new Promise((resolve) => setTimeout(resolve));
+ });
+ }
+
function pane() {
return container?.querySelector(".geo-detail-pane") ?? null;
}
+ /**
+ * The title row reads the note out of a note context rather than taking one as a prop, so what
+ * this asserts is that the pane points that context at the marker clicked.
+ */
it("stands for the marker that was clicked, naming its note", async () => {
- const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ // Hung under the root so there is a path to point the note context at.
+ buildNote({ id: "root", title: "root", children: [ { id: "somewhere", title: "Somewhere", "#geolocation": "1,2" } ] });
+ const note = froca.notes["somewhere"];
const map = fakeMap();
await mount([ note ], map);
@@ -121,15 +138,41 @@ describe("DetailPane", () => {
map.setUnderPointer([ markerFeature(note) ]);
await act(async () => map.click());
+ await settle();
- expect(pane()?.querySelector(".tn-overlay-panel-title-text")?.textContent).toBe("Somewhere");
+ // A field and a picker, not a heading drawn for the occasion.
+ expect(pane()?.querySelector<HTMLInputElement>(".title-row input")?.value).toBe("Somewhere");
+ expect(pane()?.querySelector<HTMLButtonElement>(".title-row .note-icon")?.disabled).toBe(false);
});
/**
- * The pane covers the trailing edge of the map, so the marker it stands for is brought to the
- * middle of what is left uncovered rather than to the middle of the map — where the pane itself
- * would be sitting on top of it.
+ * Regression test for a click on a marker whiting out the map and losing its WebGL context.
+ *
+ * An unbound `useNoteContext` rebinds to whatever context a note switch names. Announced to the
+ * map's component, the collection view around the pane rebound to the marker's note and tore the
+ * map down mid-click. The pane keeps its own component so its switches reach only its contents.
*/
+ it("keeps its own note switches from reaching the map's component", async () => {
+ buildNote({ id: "root", title: "root", children: [ { id: "somewhere", title: "Somewhere", "#geolocation": "1,2" } ] });
+ const note = froca.notes["somewhere"];
+ const map = fakeMap();
+ await mount([ note ], map);
+
+ const heardByTheMap = vi.fn();
+ for (const event of [ "noteSwitched", "noteSwitchedAndActivated", "beforeNoteSwitch" ] as const) {
+ mapComponent?.registerHandler(event, heardByTheMap);
+ }
+
+ map.setUnderPointer([ markerFeature(note) ]);
+ await act(async () => map.click());
+ await settle();
+
+ // The pane heard its own switch — it is showing the note — and nothing else did.
+ expect(pane()?.querySelector<HTMLInputElement>(".title-row input")?.value).toBe("Somewhere");
+ expect(heardByTheMap).not.toHaveBeenCalled();
+ });
+
+ /** The marker is brought to the middle of what the pane leaves uncovered, not of the map. */
it("holds the marker it opens for clear of itself", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap();
@@ -138,12 +181,11 @@ describe("DetailPane", () => {
map.setUnderPointer([ markerFeature(note, [ 2, 1 ]) ]);
await act(async () => map.click());
- // Half of what the pane reaches into the map: its own width, plus the air it is held off
- // the edge by.
+ // Half of what the pane reaches into the map: its width plus the gap it stands off by.
expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ -200, 0 ] } ]);
});
- /** An embedded map may be narrower than the pane wants to be, and then there is nowhere to move to. */
+ /** An embedded map may be narrower than the pane, leaving nowhere to move to. */
it("leaves the marker where it is on a map the pane covers whole", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap({ width: 300 });
@@ -177,11 +219,7 @@ describe("DetailPane", () => {
});
- /**
- * The panel stops the key presses made inside it from reaching what is underneath, which is a
- * map with shortcuts of its own — and which would stop them reaching the pane's own listener
- * too, were that one not heard on the way down.
- */
+ /** The panel stops key presses reaching the map, which would stop them reaching this too. */
it("closes on Escape pressed with the focus inside the pane", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap();
@@ -210,11 +248,8 @@ describe("DetailPane", () => {
expect(map.eased).toEqual([]);
});
- /**
- * Taking a marker off the map clears the note's location and leaves the note itself exactly where
- * it was, so the pane cannot wait to be told the note has gone — there is no pin left for it to
- * stand for either way.
- */
+ /** Removal clears the location and leaves the note in the tree, so the pane cannot wait to be
+ * told the note has gone. */
it("goes away when its marker leaves the map, whether the note does or not", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap();
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index 2e60ed96f3..dcfdc6179b 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -4,27 +4,26 @@ import type { Map as MapLibreGLMap, MapMouseEvent } from "maplibre-gl";
import { useContext, useEffect, useState } from "preact/hooks";
import appContext from "../../../components/app_context";
-import { openInCurrentNoteContext } from "../../../components/note_context";
+import Component from "../../../components/component";
+import NoteContext, { openInCurrentNoteContext } from "../../../components/note_context";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import link from "../../../services/link";
+import TitleRow from "../../layout/TitleRow";
import ActionButton from "../../react/ActionButton";
-import { useNoteIcon, useNoteLabel, useNoteProperty } from "../../react/hooks";
-import OverlayPanel, { OverlayPanelBody, OverlayPanelTitle } from "../../react/OverlayPanel";
+import { useNoteLabel } from "../../react/hooks";
+import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";
+import { NoteContextContext, ParentComponent } from "../../react/react_utils";
import { moveMarker } from "./api";
import { ParentMap } from "./map";
import { LOCATION_ATTRIBUTE, MARKER_LAYER, parseLocation } from "./Markers";
/**
- * What is known about the marker that has been clicked, standing against the trailing edge of the
- * map for as long as one is selected.
+ * The pane standing against the trailing edge of the map for as long as a marker is selected.
*
- * The pane is drawn over the map rather than beside it — the map is what goes fullscreen (see
- * MapToolbar), so a pane standing outside it would leave the screen the moment it was filled, and an
- * embedded map may be narrower than the pane is wide. What makes it read as a dock instead of a card
- * laid over the map is that the map keeps out of its way: the marker is brought to the middle of
- * what is left uncovered rather than to the middle of the map (see {@link paneOffset}), and the bar
- * of buttons in the corner steps aside for it (see DetailPane.css).
+ * Drawn over the map rather than beside it: the map is what goes fullscreen (see MapToolbar), so a
+ * pane outside it would leave the screen. It reads as a dock because the map keeps out of its way
+ * (see {@link paneOffset}).
*/
export default function DetailPane({ notes, placing, isReadOnly }: {
notes: FNote[];
@@ -38,20 +37,16 @@ export default function DetailPane({ notes, placing, isReadOnly }: {
const note = notes.find((note) => note.noteId === selectedNoteId);
const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);
- // A note that is no longer on the map takes the pane with it, rather than leaving it standing
- // for a marker that is not there any more: the note may have left the collection, or been
- // deleted, or merely had its location cleared — which is what "remove from map" does, and which
- // leaves the note itself exactly where it was.
+ // A note no longer on the map takes the pane with it. Its location may merely have been cleared
+ // — which is all "remove from map" does — so the note being gone is not the only case.
useEffect(() => {
if (selectedNoteId && (!note || !parseLocation(location))) {
setSelectedNoteId(null);
}
}, [ selectedNoteId, note, location ]);
- // What is under the pointer decides: a marker is selected, and a click anywhere else clears the
- // selection, the way clicking off a place closes its card. Read off the rendered layer rather
- // than bound to it (`map.on("click", MARKER_LAYER, ...)`), so that one handler answers both
- // cases and there is no order between two of them to rely on.
+ // A marker selects, anywhere else clears. Read off the rendered layer rather than bound to it
+ // (`map.on("click", MARKER_LAYER, ...)`) so one handler answers both, with no ordering to rely on.
useEffect(() => {
if (!map || placing) return;
@@ -73,9 +68,8 @@ export default function DetailPane({ notes, placing, isReadOnly }: {
return () => { map.off("click", onClick); };
}, [ map, placing ]);
- // The way out that every transient surface in the app answers to. Bound only while there is a
- // selection, so that the map's other Escape — the one that gives up placing a marker (see
- // index.tsx) — is the only listener standing when there is nothing selected.
+ // Bound only while something is selected, so the map's other Escape — giving up on placing a
+ // marker (see index.tsx) — stands alone when nothing is.
useEffect(() => {
if (!selectedNoteId) return;
@@ -84,11 +78,8 @@ export default function DetailPane({ notes, placing, isReadOnly }: {
setSelectedNoteId(null);
}
};
- // Heard on the way down rather than on the way up: the panel stops the key presses made
- // inside it from reaching what is underneath (see OverlayPanel), which is right — what is
- // underneath is a map with shortcuts of its own — but it also stops them reaching this. On
- // the way down nothing has had the chance to stop them yet, so Escape closes the pane from
- // within it as readily as from the map.
+ // Captured, not bubbled: the panel stops key presses made inside it from reaching the map
+ // underneath (see OverlayPanel), which would stop them reaching this listener too.
window.addEventListener("keydown", onKeyDown, true);
return () => window.removeEventListener("keydown", onKeyDown, true);
}, [ selectedNoteId ]);
@@ -100,77 +91,114 @@ export default function DetailPane({ notes, placing, isReadOnly }: {
return <MarkerDetails note={note} isReadOnly={isReadOnly} onClose={() => setSelectedNoteId(null)} />;
}
-/**
- * How wide the pane stands.
- *
- * Has to agree with `--geo-detail-pane-width` in DetailPane.css: the map is told how much of itself
- * the pane covers so that it can hold the selected marker clear of it, and a number is the only form
- * that side of the pair can take.
- */
+/** Must agree with `--geo-detail-pane-width` in DetailPane.css. */
const PANE_WIDTH = 380;
-/** How far the pane is held off the edge it stands against, matching `--geo-map-inset` (index.css). */
+/** Must agree with `--geo-map-inset` in index.css. */
const PANE_INSET = 20;
-/**
- * How far into the map the pane reaches from that edge. The gap counts as covered: it is the pane's
- * own air, and a marker sitting in it reads as tucked behind the pane rather than beside it.
- */
+/** How far into the map the pane reaches: its width plus the gap, which it also covers. */
const PANE_REACH = PANE_WIDTH + PANE_INSET;
/**
- * How far off its own centre the map has to hold a marker for the pane not to cover it.
+ * How far off centre to hold a marker so the pane does not cover it.
*
- * Handed over as `offset` rather than as camera `padding`, though padding is what it is for: padding
- * becomes part of the transform and stays there, so `getCenter()` — which is what the view is saved
- * from (see map.tsx) — would report the middle of the uncovered half from then on, and the saved
- * viewport would walk sideways every time the pane was opened. An offset applies to the one
- * animation and leaves nothing behind.
+ * An `offset` rather than camera `padding`, though padding is what it is for: padding stays in the
+ * transform, so `getCenter()` — which the view is saved from (see map.tsx) — would report the middle
+ * of the uncovered half from then on, walking the saved viewport sideways on every open.
*/
function paneOffset(map: MapLibreGLMap): [number, number] {
- // A pane with the whole map under it — an embedded one narrower than the pane — leaves nowhere
- // to hold the marker clear of, so it is left where it is.
+ // An embedded map narrower than the pane leaves nowhere to hold the marker clear of.
if (map.getContainer().clientWidth <= PANE_REACH) {
return [ 0, 0 ];
}
- // The pane stands at the trailing edge, which is the left one where the app reads right to left.
+ // The pane stands at the trailing edge, which is the left one in a right-to-left app.
const shift = PANE_REACH / 2;
return [ glob.isRtl ? shift : -shift, 0 ];
}
/** The pane itself, for a marker there is one to draw. */
function MarkerDetails({ note, isReadOnly, onClose }: { note: FNote; isReadOnly: boolean; onClose(): void }) {
- const icon = useNoteIcon(note);
- const title = useNoteProperty(note, "title");
+ const { noteContext, paneComponent } = usePaneNoteContext(note);
return (
- <OverlayPanel
- className="geo-detail-pane"
- header={<OverlayPanelTitle icon={icon ?? note.getIcon()} text={title ?? note.title} />}
- close={{ text: t("geo-map.close-details"), onClick: onClose }}
- >
- <OverlayPanelBody>
- <MarkerActions note={note} isReadOnly={isReadOnly} />
- </OverlayPanelBody>
- </OverlayPanel>
+ // What the pane holds reads the note out of the context rather than being handed one (see
+ // TitleRow), and answers to the pane's own component rather than the map's (see below).
+ <ParentComponent.Provider value={paneComponent}>
+ <NoteContextContext.Provider value={noteContext}>
+ <OverlayPanel
+ className="geo-detail-pane"
+ header={<TitleRow compact />}
+ close={{ text: t("geo-map.close-details"), onClick: onClose }}
+ >
+ <OverlayPanelBody>
+ <MarkerActions note={note} isReadOnly={isReadOnly} />
+ </OverlayPanelBody>
+ </OverlayPanel>
+ </NoteContextContext.Provider>
+ </ParentComponent.Provider>
);
}
+/** The pane's own ntxId, as the quick editor has one of its own. */
+const PANE_NTX_ID = "_geo-detail-pane";
+
+/**
+ * A note context of the pane's own, pointed at whichever marker is selected — the arrangement the
+ * quick editor makes, so that the icon and title widgets work and a rename saves the usual way.
+ *
+ * One context for the pane rather than one per marker: moving between markers is a note switch
+ * within a standing pane, not a new pane.
+ */
+function usePaneNoteContext(note: FNote) {
+ const parentComponent = useContext(ParentComponent);
+ const [ noteContext ] = useState(() => new NoteContext(PANE_NTX_ID));
+ // Stands between the map's component and the pane's contents. See below for why.
+ const [ paneComponent ] = useState(() => new Component());
+
+ useEffect(() => {
+ if (!parentComponent) return;
+
+ // A child of the map's component, so app-wide events still travel down into the pane — a
+ // component hanging off nothing would never hear that its note was edited elsewhere.
+ parentComponent.child(paneComponent);
+ return () => parentComponent.removeChild(paneComponent);
+ }, [ parentComponent, paneComponent ]);
+
+ useEffect(() => {
+ /*
+ * The context was built here rather than by the tab manager, so it has no parent to raise
+ * events through and is given one by hand — the pane's component, not the map's.
+ *
+ * Pointing a note context at a note announces a note switch, and an unbound `useNoteContext`
+ * rebinds to whatever context it hears named (see hooks.tsx). The quick editor gets away
+ * with announcing to its parent because it is a dialog at the root; the pane is inside the
+ * map, so the collection view around it would rebind to the marker's note, tear the map down
+ * and take the WebGL context with it.
+ */
+ noteContext.triggerEvent = (name, data) => paneComponent.handleEventInChildren(name, data);
+ }, [ noteContext, paneComponent ]);
+
+ useEffect(() => {
+ const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
+ // Selecting a marker is not the kind of navigation that should dismiss an open dialog.
+ void noteContext.setNote(notePath, { keepActiveDialog: true });
+ }, [ noteContext, note.noteId ]);
+
+ return { noteContext, paneComponent };
+}
+
/**
- * What can be done with the note behind the marker: the ways of opening it, and the way of opening
- * where it is.
+ * The ways of opening the note, named as the link menu names them.
*
- * These are the ways every note in Trilium is opened, which is why they are named as they are named
- * everywhere else — the same strings the link menu offers them under. What is not among them is
- * the quick editor: it used to be what a click on a marker raised, and the pane took that click
- * over, so offering it here would only put a modal back over the pane that replaced it.
+ * The quick editor is deliberately absent: it is what a click on a marker used to raise, and the
+ * pane took that click over — offering it here would put a modal back over the pane that replaced it.
*/
function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: boolean }) {
const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
- // The path the note is best reached by from wherever the reader is hoisted, rather than its id:
- // a note may hang in several places, and every one of these opens a path.
+ // A path rather than an id: a note may hang in several places, and each of these opens a path.
const notePath = note.getBestNotePathString(hoistedNoteId);
const latLng = parseLocation(location);
@@ -179,8 +207,8 @@ function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: boolean
<ActionButton
icon="bx bx-log-in"
text={t("geo-map.open-note")}
- // Handed the event so that the note lands in the pane's own tab, which is the one
- // the map is in — `openInCurrentNoteContext` reads it off the element clicked.
+ // Handed the event: `openInCurrentNoteContext` reads the target tab off the element
+ // clicked, which lands the note in the tab the map is in.
onClick={(e) => notePath && openInCurrentNoteContext(e as MouseEvent, notePath)}
disabled={!notePath}
/>
@@ -202,27 +230,23 @@ function MarkerActions({ note, isReadOnly }: { note: FNote; isReadOnly: boolean
<ActionButton
icon="bx bx-map-alt"
text={t("geo-map-context.open-location")}
- // Where the note is, handed to whatever the system opens a place with, as the map's
- // own right-click menu does with the point that was clicked.
+ // Handed to whatever the system opens a place with, as the right-click menu does.
onClick={() => latLng && link.goToLinkExt(null, `geo:${latLng[1]},${latLng[0]}`)}
disabled={!latLng}
/>
- {/* Left out rather than shown spent on a map that cannot be edited, as the map's own
- right-click menu leaves it out: the rest of the row reads a note, and this is the
- one thing here that writes one. */}
+ {/* Left out rather than disabled on a read-only map, as the right-click menu leaves it
+ out: everything else in the row reads the note, this alone writes it. */}
{!isReadOnly && (
<ActionButton
className="geo-detail-pane-remove"
icon="bx bx-trash"
text={t("geo-map-context.remove-from-map")}
- // Only the note's location goes; the note itself stays exactly where it was in
- // the tree. Nothing closes the pane afterwards because nothing has to — a note
- // with nowhere to be drawn is a note the pane stops standing for (see above).
+ // Only the location goes; the note stays in the tree. Nothing closes the pane
+ // afterwards because the effect above already stands it down.
//
- // Called rather than commanded, though `deleteFromMap` is a command the map
- // already answers: a command is broadcast, and every geo map open at the time
- // would take the same note off the same map in turn.
+ // Called rather than commanded: `deleteFromMap` is broadcast, so every open geo
+ // map would take the same note off in turn.
onClick={() => void moveMarker(note.noteId, null)}
/>
)}
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index 2879222d0f..5064a70812 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx
@@ -13,13 +13,10 @@ import utils from "../../services/utils";
import NoteList from "../collections/NoteList";
import FloatingButtons from "../FloatingButtons";
import { DESKTOP_FLOATING_BUTTONS, POPUP_HIDDEN_FLOATING_BUTTONS } from "../FloatingButtonsDefinitions";
-import NoteBadges from "../layout/NoteBadges";
-import NoteIcon from "../note_icon";
-import NoteTitleWidget from "../note_title";
+import TitleRow from "../layout/TitleRow";
import NoteDetail from "../NoteDetail";
import PromotedAttributes from "../PromotedAttributes";
import { useContainedLinkNavigation, useNoteContext, useNoteLabel, useTriliumEvent } from "../react/hooks";
-import Icon from "../react/Icon";
import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
import ReadOnlyNoteInfoBar from "../ReadOnlyNoteInfoBar";
@@ -166,46 +163,3 @@ export function DialogWrapper({ children }: { children: ComponentChildren }) {
</div>
);
}
-
-export function TitleRow() {
- const { viewScope } = useNoteContext();
-
- if (viewScope?.attachmentId) {
- return <AttachmentTitleRow attachmentId={viewScope.attachmentId} />;
- }
-
- return (
- <div className="title-row">
- <NoteIcon />
- <NoteTitleWidget />
- {isNewLayout && <NoteBadges />}
- </div>
- );
-}
-
-/**
- * The header shown when the popup displays an attachment instead of a note. Attachments are not
- * editable in place, so the title is plain read-only text, prefixed to make clear that what is
- * displayed is an attachment of the note and not the note itself.
- */
-function AttachmentTitleRow({ attachmentId }: { attachmentId: string }) {
- const [ title, setTitle ] = useState<string>();
-
- function refresh() {
- froca.getAttachment(attachmentId).then(attachment => setTitle(attachment?.title));
- }
-
- useEffect(refresh, [ attachmentId ]);
- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- if (loadResults.getAttachmentRows().some(row => row.attachmentId === attachmentId)) {
- refresh();
- }
- });
-
- return (
- <div className="title-row attachment-title-row">
- <Icon icon="bx bx-paperclip" />
- <span className="attachment-title">{t("popup-editor.attachment_title", { title })}</span>
- </div>
- );
-}
diff --git a/apps/client/src/widgets/dialogs/TreePopupEditor.tsx b/apps/client/src/widgets/dialogs/TreePopupEditor.tsx
index 411d7b55b5..73d9f99c6f 100644
--- a/apps/client/src/widgets/dialogs/TreePopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/TreePopupEditor.tsx
@@ -4,13 +4,13 @@ import { useCallback, useContext, useEffect, useRef, useState } from "preact/hoo
import appContext from "../../components/app_context";
import NoteContext from "../../components/note_context";
+import TitleRow from "../layout/TitleRow";
import NoteTreeWidget from "../note_tree";
import NoteDetail from "../NoteDetail";
import PromotedAttributes from "../PromotedAttributes";
import { useContainedLinkNavigation, useLegacyWidget, useTriliumEvent } from "../react/hooks";
import Modal from "../react/Modal";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
-import { TitleRow } from "./PopupEditor";
/**
* A quick-edit-style popup whose sidebar is a hoisted note tree.
diff --git a/apps/client/src/widgets/layout/TitleRow.css b/apps/client/src/widgets/layout/TitleRow.css
new file mode 100644
index 0000000000..1ef3134d7f
--- /dev/null
+++ b/apps/client/src/widgets/layout/TitleRow.css
@@ -0,0 +1,35 @@
+/*
+ * The title row sized as chrome rather than as a note's heading.
+ *
+ * It is written for the head of a note split — 50px tall, title at 180%, and `display: flex` coming
+ * from the split rather than from the row itself, so anywhere else its children stack. Gathered here
+ * so each narrow header (the quick editor's, the geo map's pane) need not work it out again.
+ */
+.title-row.tn-title-row-compact {
+ display: flex;
+ align-items: center;
+ height: 32px;
+ min-height: unset;
+
+ .note-icon-widget {
+ display: flex;
+ align-items: center;
+ height: 32px;
+ min-height: unset;
+ margin-inline-start: 0;
+ }
+
+ /* The title takes what the icon leaves, as it does in a split (see note_title.css); all that is
+ wanted here is a row for it to do that in. */
+ .note-title-widget {
+ display: flex;
+ align-items: center;
+ --note-title-padding-inline: 8px;
+ }
+
+ /* Both are sized in the heading's terms — the title at 180% of it — and neither is a heading. */
+ .note-icon-widget button.note-icon,
+ .note-title-widget input.note-title {
+ font-size: 1em;
+ }
+}
diff --git a/apps/client/src/widgets/layout/TitleRow.tsx b/apps/client/src/widgets/layout/TitleRow.tsx
new file mode 100644
index 0000000000..3edb970b24
--- /dev/null
+++ b/apps/client/src/widgets/layout/TitleRow.tsx
@@ -0,0 +1,69 @@
+import "./TitleRow.css";
+
+import clsx from "clsx";
+import { useEffect, useState } from "preact/hooks";
+
+import { isExperimentalFeatureEnabled } from "../../services/experimental_features";
+import froca from "../../services/froca";
+import { t } from "../../services/i18n";
+import NoteIcon from "../note_icon";
+import NoteTitleWidget from "../note_title";
+import { useNoteContext, useTriliumEvent } from "../react/hooks";
+import Icon from "../react/Icon";
+import NoteBadges from "./NoteBadges";
+
+const isNewLayout = isExperimentalFeatureEnabled("new-layout");
+
+/**
+ * What heads a note shown outside a split of its own: icon, title and badges, each editable in place
+ * and each reading the note out of the surrounding note context rather than being handed one.
+ *
+ * Shared by the quick editor and the geo map's marker pane, so a rename from either saves the same
+ * way — through the title widget.
+ */
+export default function TitleRow({ compact }: {
+ /** Standing in a narrow header rather than at the head of a split (see TitleRow.css). */
+ compact?: boolean;
+} = {}) {
+ const { viewScope } = useNoteContext();
+ const className = clsx("title-row", compact && "tn-title-row-compact");
+
+ if (viewScope?.attachmentId) {
+ return <AttachmentTitleRow className={className} attachmentId={viewScope.attachmentId} />;
+ }
+
+ return (
+ <div className={className}>
+ <NoteIcon />
+ <NoteTitleWidget />
+ {isNewLayout && <NoteBadges />}
+ </div>
+ );
+}
+
+/**
+ * The header shown when an attachment is displayed instead of a note. Attachments are not editable
+ * in place, so the title is plain read-only text, prefixed to make clear that what is displayed is
+ * an attachment of the note and not the note itself.
+ */
+function AttachmentTitleRow({ className, attachmentId }: { className: string; attachmentId: string }) {
+ const [ title, setTitle ] = useState<string>();
+
+ function refresh() {
+ froca.getAttachment(attachmentId).then(attachment => setTitle(attachment?.title));
+ }
+
+ useEffect(refresh, [ attachmentId ]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (loadResults.getAttachmentRows().some(row => row.attachmentId === attachmentId)) {
+ refresh();
+ }
+ });
+
+ return (
+ <div className={clsx(className, "attachment-title-row")}>
+ <Icon icon="bx bx-paperclip" />
+ <span className="attachment-title">{t("popup-editor.attachment_title", { title })}</span>
+ </div>
+ );
+}