Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(geomap): grow the detail pane over the map instead of handing to quick edit
Elian Doran3b2545e5451c
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex cdc108a289..5e0542448f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2853,6 +2853,8 @@"quick-edit": "Quick edit"},"geo-map": {+ "expand-details": "Expand the note to fill the map",+ "restore-details": "Put the note back beside the map","create-child-note-title": "Create a new child note and add it to the map","create-child-note-cancel": "Cancel adding the note","add-marker": "Add marker",diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.cssindex b799040409..1d5acc5daa 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.css+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css@@ -24,6 +24,13 @@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));++ /* Grown over the map (see the maximize in MarkerDetails). Only the width gives: the pane+ already stands the height of the map. What the map places around the pane is suppressed+ while it is grown rather than recomputed — see `maximized` in DetailPane.tsx. */+ &.maximized {+ width: calc(100% - 2 * var(--geo-map-inset));+ }/* Clear of MapLibre's own control corners, which sit at 2 (see MapToolbar.css). */z-index: 3;}diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsxindex e42e74442d..b6c1f4699f 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx@@ -187,6 +187,8 @@ describe("DetailPane", () => {notes: FNote[]; placing: boolean; isReadOnly: boolean; initialSelection?: PaneSelection;}) {const [ selection, setSelection ] = useState<PaneSelection | null>(initialSelection ?? null);+ // Held here for the same reason, the map view owning whether the pane stands over it.+ const [ maximized, setMaximized ] = useState(false);return <DetailPanenotes={notes}parentNote={froca.notes["root"] ?? buildNote({ id: "root", title: "root" })}@@ -195,6 +197,8 @@ describe("DetailPane", () => {selection={selection}onSelect={setSelection}onRelocate={onRelocate}+ maximized={maximized}+ onMaximizedChange={setMaximized}/>;}@@ -662,35 +666,74 @@ describe("DetailPane", () => {});/**- * The maximize in the header: the pane grown into the quick editor, which takes the pane's- * place rather than standing over it — the quick editor opened on the path the menu's own- * entry would open, and the pane standing down having told its editors to save (see- * MaximizeToQuickEditAction).+ * The maximize in the header grows the pane over the map rather than handing the note to the+ * quick editor, which has none of what the pane offers — the place under the title, the ways+ * of moving the marker or taking it off the map. Growing the surface would have shrunk what+ * could be done in it.+ *+ * What is pinned here above all is that the note's editor is the very same element on the+ * other side of it: the pane is restyled where it stands, so nothing it holds is torn down+ * and nothing has to be saved and read back to grow it. A pane replaced by a larger one+ * would lose whatever had been typed and not yet saved.*/- it("maximizes into the quick editor, the pane standing down behind it", async () => {+ it("grows over the map without rebuilding what it holds, and comes back down again", async () => {const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });const map = fakeMap();-- const notePath = "root/places/somewhere";- const bestNotePath = vi.spyOn(note, "getBestNotePathString").mockReturnValue(notePath);const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined as never);try {await openPaneFor(note, map);+ const editorEl = pane()?.querySelector(".note-detail-stub");+ expect(editorEl).toBeTruthy();- await act(async () => {+ const maximize = () => act(async () => {pane()?.querySelector<HTMLButtonElement>(".tn-overlay-panel-header-actions button.tn-embedded-note-maximize")?.click();});- expect(triggerCommand).toHaveBeenCalledWith("openInPopup", { noteIdOrPath: notePath });- expect(editorAskedToSave).toHaveBeenCalled();- expect(pane()).toBeNull();+ await maximize();+ expect(pane()?.classList.contains("maximized")).toBe(true);+ // The same editor, never having been away.+ expect(pane()?.querySelector(".note-detail-stub")).toBe(editorEl);+ // Neither a hand-over to another surface nor a dismissal: the pane is still up, and+ // nothing was asked to save because nothing is closing.+ expect(triggerCommand).not.toHaveBeenCalledWith("openInPopup", expect.anything());+ expect(editorAskedToSave).not.toHaveBeenCalled();++ await maximize();+ expect(pane()?.classList.contains("maximized")).toBe(false);+ expect(pane()?.querySelector(".note-detail-stub")).toBe(editorEl);} finally {- bestNotePath.mockRestore();triggerCommand.mockRestore();}});+ /**+ * The map holds a selected marker clear of the pane, which a pane covering the whole map+ * leaves nowhere to hold it in — so the offset is given up while it is grown, and taken up+ * again as it comes back down (see paneOffset).+ */+ it("stops holding the marker clear of itself while it covers the map", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap();+ await openPaneFor(note, map);++ const maximize = () => act(async () => {+ pane()?.querySelector<HTMLButtonElement>(".tn-overlay-panel-header-actions button.tn-embedded-note-maximize")?.click();+ });++ await maximize();+ await maximize();++ // Held clear of the pane as it opens; brought back to the middle as the pane grows over+ // the map, there being no uncovered half left to hold it in; and held clear once more as+ // the pane comes down, rather than left under it until something else moves the camera.+ expect(map.eased).toEqual([+ { center: [ 2, 1 ], offset: [ -200, 0 ] },+ { center: [ 2, 1 ], offset: [ 0, 0 ] },+ { center: [ 2, 1 ], offset: [ -200, 0 ] }+ ]);+ });+/*** The rest are gathered behind one button, and are the same ways a link offers anywhere in* the app — which is how a split view, the one worth having beside a map, comes to bediff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsxindex 6af7c7ee1a..bf35192cf8 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx@@ -8,7 +8,7 @@ import FNote from "../../../entities/fnote";import { copyTextWithToast } from "../../../services/clipboard_ext";import { t } from "../../../services/i18n";import link from "../../../services/link";-import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeToQuickEditAction, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext, useFollowLinksWithin } from "../../EmbeddedNotePane";+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeAction, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext, useFollowLinksWithin } from "../../EmbeddedNotePane";import TitleRow from "../../layout/TitleRow";import NoteDetail from "../../NoteDetail";import PromotedAttributes from "../../PromotedAttributes";@@ -54,7 +54,7 @@ export type PaneFocus =* 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, parentNote, placing, isReadOnly, selection, onSelect, onRelocate }: {+export default function DetailPane({ notes, parentNote, placing, isReadOnly, selection, onSelect, onRelocate, maximized, onMaximizedChange }: {notes: FNote[];/** The map's own note, which is how the tree is told what the map holds a note by. */parentNote: FNote;@@ -68,6 +68,15 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, selonSelect: (selection: PaneSelection | null) => void;/** Arms this map for the selected marker to be put somewhere else, the next click being where. */onRelocate: (noteId: string) => void;+ /**+ * The pane has been grown to cover the map (see {@link MaximizeAction} in the header below).+ * Owned by the map view rather than by the pane for the reason the selection is: the map places+ * what it draws around the pane, and a pane covering the whole of it leaves nothing to place+ * around — the marker previews have nowhere to stand clear to (see Tooltips), and the camera has+ * no uncovered half to hold the marker in (see {@link paneOffset}).+ */+ maximized: boolean;+ onMaximizedChange: (maximized: boolean) => void;}) {const map = useContext(ParentMap);const note = notes.find((note) => note.noteId === selection?.noteId);@@ -112,6 +121,15 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, selreturn true;}, [ notes, onSelect ]);+ // The pane comes back up beside the map rather than over it, however it was left: the state+ // outlives the pane, being the map's (see the props), where a card that is taken down and built+ // again would have forgotten by itself. Switching from one marker to another keeps it — the room+ // was asked for, not the marker it was asked on — which is why this waits on the pane going down+ // rather than on the note changing.+ useEffect(() => {+ if (!selection) onMaximizedChange(false);+ }, [ selection, onMaximizedChange ]);+// 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. A GPX// track is on the map by being one: its place is its line, not a location label.@@ -160,7 +178,7 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel// were reading at, exactly as a note marker is — flying out to frame the whole file// would lose the very flag they clicked.if (focus && "at" in focus) {- map.easeTo({ center: focus.at, offset: paneOffset(map) });+ map.easeTo({ center: focus.at, offset: paneOffset(map, maximized) });return;}@@ -175,7 +193,7 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, selif (done || !bounds) return;done = true;map.off("sourcedata", onSourceData);- map.fitBounds(bounds, { padding: trackFitPadding(map), maxZoom: TRACK_FIT_MAX_ZOOM });+ map.fitBounds(bounds, { padding: trackFitPadding(map, maximized), maxZoom: TRACK_FIT_MAX_ZOOM });};// A track selected the moment it was brought onto the map has no line yet: its content@@ -198,10 +216,14 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, selconst coordinates = parseLocation(location);if (!coordinates) return;- map.easeTo({ center: coordinates, offset: paneOffset(map) });+ map.easeTo({ center: coordinates, offset: paneOffset(map, maximized) });// The focus is depended on by identity, which a click renews even on the same note: every// click is a fresh ask, and re-clicking what is already open brings it back into view.- }, [ map, note?.noteId, location, selection?.focus ]);+ //+ // Growing and shrinking the pane are asks of the same kind, the room the camera is aiming+ // into being what changed: a pane put back down brings its marker clear of it again, rather+ // than leaving it under the pane until something else happens to move the camera.+ }, [ map, note?.noteId, location, selection?.focus, maximized ]);// 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.@@ -229,7 +251,11 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel// EmbeddedNotePane) — the map would otherwise rebind to the marker's note, tear the map// down and take the WebGL context with it.<EmbeddedNoteScope component={paneComponent} noteContext={noteContext}>- <MarkerDetails note={note} parentNote={parentNote} isReadOnly={isReadOnly} onClose={closePane} onRelocate={relocate} onFollowLink={followLink} />+ <MarkerDetails+ note={note} parentNote={parentNote} isReadOnly={isReadOnly}+ maximized={maximized} onMaximizedChange={onMaximizedChange}+ onClose={closePane} onRelocate={relocate} onFollowLink={followLink}+ />{selection?.isNew && <SelectTitleOnFirstOpen />}</EmbeddedNoteScope>);@@ -254,9 +280,11 @@ export const PANE_REACH = PANE_WIDTH + PANE_INSET;* 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] {- // An embedded map narrower than the pane leaves nowhere to hold the marker clear of.- if (map.getContainer().clientWidth <= PANE_REACH) {+function paneOffset(map: MapLibreGLMap, maximized: boolean): [number, number] {+ // A pane grown over the whole map leaves nowhere to hold the marker clear of, as an embedded map+ // narrower than the pane does. Reading the note is what a grown pane is for; the marker is+ // brought clear again as it is put back down (see the camera effect above).+ if (maximized || map.getContainer().clientWidth <= PANE_REACH) {return [ 0, 0 ];}@@ -353,12 +381,14 @@ async function trackBounds(map: MapLibreGLMap, noteId: string, track?: number):* the map does not clip the fit but forfeits it: MapLibre cannot solve the camera and leaves it* where it stands.*/-function trackFitPadding(map: MapLibreGLMap) {+function trackFitPadding(map: MapLibreGLMap, maximized: boolean) {const { clientWidth, clientHeight } = map.getContainer();const air = Math.max(0, Math.min(TRACK_FIT_AIR, Math.floor(Math.min(clientWidth, clientHeight) / 4)));const padding = { top: air, bottom: air, left: air, right: air };- if (clientWidth > PANE_REACH + 2 * air) {+ // Nothing is reserved for a pane that covers the map: there is no uncovered side to fit the+ // track into, and reserving one would forfeit the fit outright (see above).+ if (!maximized && clientWidth > PANE_REACH + 2 * air) {padding[glob.isRtl ? "left" : "right"] += PANE_REACH;}@@ -366,10 +396,12 @@ function trackFitPadding(map: MapLibreGLMap) {}/** The pane itself, for a marker there is one to draw. */-function MarkerDetails({ note, parentNote, isReadOnly, onClose, onRelocate, onFollowLink }: {+function MarkerDetails({ note, parentNote, isReadOnly, maximized, onMaximizedChange, onClose, onRelocate, onFollowLink }: {note: FNote;parentNote: FNote;isReadOnly: boolean;+ maximized: boolean;+ onMaximizedChange(maximized: boolean): void;onClose(): void;onRelocate(): void;/** Offered a link's note; answers whether the map took the navigation over. */@@ -400,7 +432,14 @@ function MarkerDetails({ note, parentNote, isReadOnly, onClose, onRelocate, onFocontainerRef={paneRef}className={clsx("geo-detail-pane", colorClass)}header={<TitleRow compact />}- headerActions={<MaximizeToQuickEditAction note={note} onClose={onClose} />}+ maximized={maximized}+ headerActions={+ <MaximizeAction+ icon={maximized ? "bx bx-collapse-alt" : "bx bx-expand-alt"}+ text={maximized ? t("geo-map.restore-details") : t("geo-map.expand-details")}+ onClick={() => onMaximizedChange(!maximized)}+ />+ }close={{ text: t("geo-map.close-details"), onClick: onClose }}><OverlayPanelBody className="geo-detail-pane-body tn-embedded-note-pane">diff --git a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsxindex d881485dff..aee8e2580d 100644--- a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx@@ -173,12 +173,13 @@ describe("Tooltips", () => {});/** Mounts — or, called again, re-renders — the component. `selectedNoteId` is the marker the- * detail pane stands for, as the map view passes it down. */- function mount(map: ReturnType<typeof fakeMap>, selectedNoteId: string | null = null) {+ * detail pane stands for and `paneMaximized` whether that pane covers the map, as the map view+ * passes the two of them down. */+ function mount(map: ReturnType<typeof fakeMap>, selectedNoteId: string | null = null, paneMaximized = false) {return act(async () => {render(<ParentMap.Provider value={map as never}>- <Tooltips selectedNoteId={selectedNoteId} />+ <Tooltips selectedNoteId={selectedNoteId} paneMaximized={paneMaximized} /></ParentMap.Provider>,container as HTMLElement);@@ -356,6 +357,33 @@ describe("Tooltips", () => {expect(popup?.options.offset).toEqual([ (1200 - 8 - 400) - PREVIEW_WIDTH / 2 - 1000, -(MARKER_HEIGHT + 8) ]);});+ /**+ * A pane grown over the map leaves nowhere for a preview to be slid to, and the markers it would+ * preview are behind it. Nothing is shown at all rather than shown somewhere out of sight — and+ * a preview already up is taken down as the pane grows, rather than left standing over it.+ */+ it("shows nothing at all while the detail pane covers the map", async () => {+ const selected = buildNote({ title: "Open in the pane", "#geolocation": "5,6" });+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap({ width: 1200, point: { x: 1000, y: 300 } });+ await mount(map, selected.noteId);++ map.hover(note);+ await advance(500);+ expect(shownPreview()).toContain("Body of Somewhere");++ // The pane grows over the map with the preview still up.+ await mount(map, selected.noteId, true);+ expect(shownPreview()).toBeUndefined();++ // And nothing the pointer does while it is grown brings one back.+ renderTooltip.mockClear();+ map.hover(note);+ await advance(500);+ expect(shownPreview()).toBeUndefined();+ expect(renderTooltip).not.toHaveBeenCalled();+ });+it("centres on the pin where the map is too narrow to slide within", async () => {const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });const map = fakeMap({ width: 400, point: { x: 200, y: 300 } });diff --git a/apps/client/src/widgets/collections/geomap/Tooltips.tsx b/apps/client/src/widgets/collections/geomap/Tooltips.tsxindex 769ccfa2ac..db63a55b76 100644--- a/apps/client/src/widgets/collections/geomap/Tooltips.tsx+++ b/apps/client/src/widgets/collections/geomap/Tooltips.tsx@@ -74,15 +74,21 @@ const EDGE_PADDING = 8;* on click for the same reason (see note_tooltip.ts). Without this, a preview whose marker was* clicked stood exactly where the pane then opened, and one still on its way landed on top of it.*/-export default function Tooltips({ selectedNoteId }: {+export default function Tooltips({ selectedNoteId, paneMaximized }: {/** The note the detail pane stands for, or `null` while the pane is down and every marker* previews. See the selection in DetailPane. */selectedNoteId: string | null;+ /** The pane has been grown over the map, which leaves no room a preview could be shown in. See+ * the maximized pane in DetailPane. */+ paneMaximized: boolean;}) {const map = useContext(ParentMap);useEffect(() => {- if (!map) return;+ // Nothing previews while the pane covers the map: there is no room left for a preview to be+ // slid into, and the markers it would preview are behind the pane. Gated here rather than+ // at the placing, so a preview already up is taken down with the handlers as the pane grows.+ if (!map || paneMaximized) return;const tooltip = new Popup({closeButton: false,@@ -232,7 +238,7 @@ export default function Tooltips({ selectedNoteId }: {// Depending on the selection makes every change of it a dismissal in itself, which covers// the selections no click announces: a note created onto the map is opened into the pane// by the code that created it (see index.tsx).- }, [ map, selectedNoteId ]);+ }, [ map, selectedNoteId, paneMaximized ]);return null;}diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 345c96defe..0e3ecb032f 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -61,6 +61,9 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM// Which marker the detail pane stands for. Held here rather than in the pane so that creating a// note can open the pane on it (see createNoteAt below).const [ selection, setSelection ] = useState<PaneSelection | null>(null);+ // Whether that pane has been grown over the map. Held here for the reason the selection is: what+ // the map places around the pane has to know of it too (see the maximized pane in DetailPane).+ const [ paneMaximized, setPaneMaximized ] = useState(false);const [ coordinates, setCoordinates ] = useState(viewConfig?.view?.center);const [ zoom, setZoom ] = useState(viewConfig?.view?.zoom);const [ hasScale ] = useNoteLabelBoolean(note, "map:scale");@@ -249,12 +252,16 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMonTogglePlacement={toggleNotePlacement}onAddGpxTrack={addGpxTrack}/>- <Tooltips selectedNoteId={selection?.noteId ?? null} />+ <Tooltips selectedNoteId={selection?.noteId ?? null} paneMaximized={paneMaximized} />{/* The preview under the pointer while a click is armed to mean a place — the notebeing moved wearing its own pin, a note to be created wearing the pin it will begiven (see api.ts). */}{placement && <GhostPin note={placement.mode === "move" ? notes.find((n) => n.noteId === placement.noteId) : undefined} />}- <DetailPane notes={notes} parentNote={note} placing={!!placement} isReadOnly={isReadOnly} selection={selection} onSelect={setSelection} onRelocate={startMarkerRelocation} />+ <DetailPane+ notes={notes} parentNote={note} placing={!!placement} isReadOnly={isReadOnly}+ selection={selection} onSelect={setSelection} onRelocate={startMarkerRelocation}+ maximized={paneMaximized} onMaximizedChange={setPaneMaximized}+ /><ContextMenus parentNote={note} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} onCreateNote={createNoteAt} />{/* Stood up only while the view is leaned over, so the 3D button changes the mapand not merely the angle it is seen from. */}diff --git a/apps/client/src/widgets/react/OverlayPanel.tsx b/apps/client/src/widgets/react/OverlayPanel.tsxindex 96cdd4df59..a017e48514 100644--- a/apps/client/src/widgets/react/OverlayPanel.tsx+++ b/apps/client/src/widgets/react/OverlayPanel.tsx@@ -19,8 +19,14 @@ interface OverlayPanelProps {*/header: ComponentChildren;/** Whatever else the header row offers, standing between the header and the close button —- * the geo pane's maximize, say (see MaximizeToQuickEditAction). */+ * the geo pane's maximize, say (see MaximizeAction). */headerActions?: ComponentChildren;+ /**+ * The panel has been grown to fill the canvas it stands over, which is a way it is drawn and+ * not a surface of its own: what it holds — a note's editor, mid-edit — is never unmounted for+ * it. Where it grows to is the caller's to state, as where it stands is (see the CSS).+ */+ maximized?: boolean;/** The way to send the panel away, offered at the end of the header row. Left out, the panel* has no way of dismissing itself. */close?: {@@ -41,11 +47,11 @@ interface OverlayPanelProps {* left to the caller, which is what differs between two of them. The same division* {@link OverlayToolbar} makes for the bars those canvases carry.*/-export default function OverlayPanel({ className, containerRef, header, headerActions, close, children }: OverlayPanelProps) {+export default function OverlayPanel({ className, containerRef, header, headerActions, close, maximized, children }: OverlayPanelProps) {return (<divref={containerRef}- className={clsx("tn-overlay-panel", className)}+ className={clsx("tn-overlay-panel", maximized && "maximized", className)}/* Keep interactions inside the panel from reaching the canvas underneath. */onMouseDown={(e) => e.stopPropagation()}onKeyDown={(e) => e.stopPropagation()}