Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): share the embedded-note plumbing between the two panes

Elian Doran2ce07bc1c8e6
diff --git a/apps/client/src/widgets/EmbeddedNotePane.css b/apps/client/src/widgets/EmbeddedNotePane.css
new file mode 100644
index 0000000000..1f92b08209
--- /dev/null
+++ b/apps/client/src/widgets/EmbeddedNotePane.css
@@ -0,0 +1,83 @@
+/*
+ * The body of a pane holding an embedded note (see EmbeddedNotePane.tsx): the note's own widgets,
+ * laid out for a third of the width they are written for. The class goes on the element that holds
+ * them — the geo pane's body, the calendar dock's body — which brings the column they stand in;
+ * whatever else that element is (its padding, whether it scrolls) stays with its own class.
+ */
+.tn-embedded-note-pane {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+
+ /*
+ * The note fills the rest of the pane rather than ending where its content does, so that
+ * clicking below a short note still puts the caret in it — as it does in a note of its own.
+ */
+ .note-detail {
+ flex: 1;
+ /* Written for a note split, where the split hands it one; there is no split here, and an
+ unset `--max-content-width` would leave `max-width` invalid rather than absent. */
+ max-width: none;
+ /* A floor rather than the 0 a flex item needs to scroll its own content: the fields above
+ it are as many as the note asks for, and without one they would squeeze the note out of
+ the pane instead of the body scrolling. Above the floor a long note still scrolls within
+ itself. */
+ min-height: 120px;
+ }
+
+ /*
+ * The note's promoted fields. A field reads across one line — its name, then what it holds —
+ * and stays that way here; what changes is the row they stand in. Across a note they stand side
+ * by side, each as wide as what it holds; in the pane there is room for one, so they come down
+ * the column instead, each taking the whole width.
+ */
+ .promoted-attributes-container {
+ flex-direction: column;
+ align-items: stretch;
+ gap: 8px;
+ margin: 0;
+ /* The body of the pane is the one thing that scrolls; a scroller inside it would take the
+ wheel off whichever of the two the pointer happened to be over. */
+ max-height: none;
+ overflow: visible;
+ }
+
+ .promoted-attribute-cell {
+ margin: 0;
+
+ /* The field takes whatever its name leaves, rather than the width of what it holds: a card
+ standing alone on its line has that room whether it needs it or not. */
+ > .input-group,
+ > .promoted-attribute-values {
+ flex: 1;
+ min-width: 0;
+ margin-inline-start: 8px;
+ }
+
+ /* Both are given a width in ems, which is a card's own width where cards stand side by
+ side. Marked as the theme marks them, there being no other way past it. */
+ input[type="text"],
+ input[type="number"] {
+ width: auto !important;
+ }
+
+ /* A name longer than the pane is cut short rather than pushing the field it names off the
+ end. */
+ > label {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ .tn-field {
+ min-width: 0;
+ padding: 0;
+ }
+ }
+
+ /* The widget stands whether the note promotes anything or not, and an empty one would still
+ take its share of the gap between what stands above and below it. */
+ .promoted-attributes-widget:not(:has(.promoted-attribute-cell)) {
+ display: none;
+ }
+}
diff --git a/apps/client/src/widgets/EmbeddedNotePane.tsx b/apps/client/src/widgets/EmbeddedNotePane.tsx
new file mode 100644
index 0000000000..ce4fc83ce7
--- /dev/null
+++ b/apps/client/src/widgets/EmbeddedNotePane.tsx
@@ -0,0 +1,107 @@
+import "./EmbeddedNotePane.css";
+
+import { ComponentChildren } from "preact";
+import { useContext, useEffect, useState } from "preact/hooks";
+
+import appContext from "../components/app_context";
+import Component from "../components/component";
+import NoteContext from "../components/note_context";
+import FNote from "../entities/fnote";
+import { NoteContextContext, ParentComponent } from "./react/react_utils";
+
+/*
+ * A note embedded in a pane of its host view — the geo map's marker pane, the calendar's detail
+ * dock: the note-context wiring such a pane needs to hold the real note widgets (TitleRow,
+ * PromotedAttributes, NoteDetail), and, in EmbeddedNotePane.css, the layout that fits them into a
+ * third of the width they are written for. The pane itself — where it stands, how it opens and
+ * closes, what it offers around the note — stays with the view that owns it.
+ */
+
+/**
+ * A note context of the pane's own, pointed at whichever note the pane stands for — 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 note: moving between notes is a note switch within a
+ * standing pane, not a new pane.
+ *
+ * The returned component stands between the host view's component and the pane's contents. 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 host'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 its view, so the collection view around it would
+ * rebind to the pane's note and tear the view down. It still hangs off the host's component as a
+ * child, so app-wide events travel down into the pane — a component hanging off nothing would never
+ * hear that its note was edited elsewhere.
+ */
+export function useEmbeddedNoteContext(note: FNote | undefined, ntxId: string) {
+ const parentComponent = useContext(ParentComponent);
+ const [ noteContext ] = useState(() => new NoteContext(ntxId));
+ const [ component ] = useState(() => new Component());
+
+ useEffect(() => {
+ if (!parentComponent) return;
+
+ parentComponent.child(component);
+ return () => parentComponent.removeChild(component);
+ }, [ parentComponent, component ]);
+
+ useEffect(() => {
+ noteContext.triggerEvent = (name, data) => component.handleEventInChildren(name, data);
+ }, [ noteContext, component ]);
+
+ useEffect(() => {
+ if (!note) return;
+
+ const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
+ void noteContext.setNote(notePath, {
+ // Selecting a note in the pane is not the kind of navigation that should dismiss an
+ // open dialog.
+ keepActiveDialog: true,
+ viewScope: {
+ // A note held read-only only because of its size is editable here, as it is in the
+ // quick editor; one the reader has marked read-only stays that way.
+ readOnlyTemporarilyDisabled: !note.hasLabel("readOnly"),
+ // The pane has a third of a note's width, which is not a toolbar's worth: the
+ // editor's own follows the selection instead of standing in a bar (see link.ts).
+ floatingToolbar: true
+ }
+ });
+ }, [ noteContext, note?.noteId ]);
+
+ return { noteContext, component };
+}
+
+/**
+ * Announces that the pane's note context is going, giving whatever is being edited in it the chance
+ * to save. Closing a pane announces nothing on its own — the widgets are simply unmounted — so the
+ * event a note context is removed under is raised here in its place, which is what the editors are
+ * listening for (see the spaced updates in hooks.tsx). The contents must still be mounted when it
+ * is raised, or there is nobody left to hear it.
+ *
+ * Best not waited on: the save is under way by the time the call returns, and a request already in
+ * flight does not care that what started it has gone. Waiting would hold the pane open for a round
+ * trip to the server every time it was closed with something unsaved in it.
+ */
+export function announceEmbeddedNoteClosing(component: Component, ntxId: string) {
+ return component.handleEventInChildren("beforeNoteContextRemove", { ntxIds: [ ntxId ] });
+}
+
+/**
+ * What the pane's contents live under: the pane's own component and note context, so that the
+ * widgets inside read the embedded note rather than the host's, and answer to the pane's component
+ * rather than the host's.
+ */
+export function EmbeddedNoteScope({ component, noteContext, children }: {
+ component: Component;
+ noteContext: NoteContext;
+ children: ComponentChildren;
+}) {
+ return (
+ <ParentComponent.Provider value={component}>
+ <NoteContextContext.Provider value={noteContext}>
+ {children}
+ </NoteContextContext.Provider>
+ </ParentComponent.Provider>
+ );
+}
diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.css b/apps/client/src/widgets/collections/calendar/DetailDock.css
index 04c42cd28d..ed16a7df27 100644
--- a/apps/client/src/widgets/collections/calendar/DetailDock.css
+++ b/apps/client/src/widgets/collections/calendar/DetailDock.css
@@ -42,66 +42,13 @@
}
}
+ /* The note's own widgets are laid out by the shared class (see EmbeddedNotePane.css), which
+ also brings the column they stand in; what is peculiar to the dock is that its body is the
+ thing that scrolls. */
.calendar-detail-dock-body {
flex: 1;
min-height: 0;
overflow-y: auto;
- display: flex;
- flex-direction: column;
- gap: 10px;
padding: 10px;
}
-
- /* The note fills the rest of the dock rather than ending where its content does, so that
- clicking below a short note still puts the caret in it. */
- .note-detail {
- flex: 1;
- /* Written for a note split, where the split hands it one; there is no split here. */
- max-width: none;
- min-height: 120px;
- }
-
- /* The note's promoted fields, one under the other: laid out for a third of the width they are
- written for (as the geo pane lays them). */
- .promoted-attributes-container {
- flex-direction: column;
- align-items: stretch;
- gap: 8px;
- margin: 0;
- /* The body of the dock is the one thing that scrolls. */
- max-height: none;
- overflow: visible;
- }
-
- .promoted-attribute-cell {
- margin: 0;
-
- > .input-group,
- > .promoted-attribute-values {
- flex: 1;
- min-width: 0;
- margin-inline-start: 8px;
- }
-
- input[type="text"],
- input[type="number"] {
- width: auto !important;
- }
-
- > label {
- min-width: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- .tn-field {
- min-width: 0;
- padding: 0;
- }
- }
-
- /* An event promoting nothing would still take its share of the body's gap. */
- .promoted-attributes-widget:not(:has(.promoted-attribute-cell)) {
- display: none;
- }
}
diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.tsx b/apps/client/src/widgets/collections/calendar/DetailDock.tsx
index 742a755736..b5695c416d 100644
--- a/apps/client/src/widgets/collections/calendar/DetailDock.tsx
+++ b/apps/client/src/widgets/collections/calendar/DetailDock.tsx
@@ -1,19 +1,16 @@
import "./DetailDock.css";
import clsx from "clsx";
-import { useContext, useEffect, useRef, useState } from "preact/hooks";
+import { useEffect, useRef, useState } from "preact/hooks";
-import appContext from "../../../components/app_context";
-import Component from "../../../components/component";
-import NoteContext from "../../../components/note_context";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
+import { announceEmbeddedNoteClosing, EmbeddedNoteScope, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
import ActionButton from "../../react/ActionButton";
import { useLegacyComponentElement, useNote } from "../../react/hooks";
-import { NoteContextContext, ParentComponent } from "../../react/react_utils";
/**
* The dates the calendar already draws the event by, so their fields are not repeated in the dock.
@@ -24,9 +21,6 @@ const EVENT_DATE_LABELS = [ "startDate", "endDate", "startTime", "endTime" ];
/**
* A pane docked at the trailing edge of the calendar, holding the note of the selected event — the
* calendar reflowing beside it as it comes and goes.
- *
- * SPIKE: the note-context plumbing is lifted from the geo map's DetailPane (see usePaneNoteContext
- * there); if this lands, the shared parts should be extracted rather than kept twice.
*/
export default function DetailDock({ noteId, onClose }: {
/** The note of the selected event, or `null` for a dock that is closed. */
@@ -38,18 +32,17 @@ export default function DetailDock({ noteId, onClose }: {
const [ shownNote, setShownNote ] = useState<FNote>();
const open = !!note;
const contentNote = note ?? shownNote;
- const { noteContext, dockComponent } = useDockNoteContext(contentNote);
+ const { noteContext, component: dockComponent } = useEmbeddedNoteContext(contentNote, DOCK_NTX_ID);
useEffect(() => {
if (note) setShownNote(note);
}, [ note ]);
// Closing announces the note context's removal, which is what the editors save on — the content
- // is still mounted through the slide, so the event still finds them. Not waited on, as the geo
- // pane does not wait: the save is under way by the time the call returns.
+ // is still mounted through the slide, so the event still finds them.
useEffect(() => {
if (!open && shownNote) {
- void dockComponent.handleEventInChildren("beforeNoteContextRemove", { ntxIds: [ DOCK_NTX_ID ] });
+ void announceEmbeddedNoteClosing(dockComponent, DOCK_NTX_ID);
}
}, [ open ]);
@@ -71,11 +64,9 @@ export default function DetailDock({ noteId, onClose }: {
}}
>
{contentNote && (
- <ParentComponent.Provider value={dockComponent}>
- <NoteContextContext.Provider value={noteContext}>
- <DockContent onClose={onClose} />
- </NoteContextContext.Provider>
- </ParentComponent.Provider>
+ <EmbeddedNoteScope component={dockComponent} noteContext={noteContext}>
+ <DockContent onClose={onClose} />
+ </EmbeddedNoteScope>
)}
</div>
);
@@ -84,44 +75,6 @@ export default function DetailDock({ noteId, onClose }: {
/** The dock's own ntxId, as the geo pane and the quick editor have one of their own. */
const DOCK_NTX_ID = "_calendar-detail-dock";
-/**
- * A note context of the dock's own, pointed at whichever event is selected, behind a component of
- * its own so the collection view around the calendar does not hear the dock's note switches and
- * rebind to them. Lifted from the geo map's usePaneNoteContext, where each choice is explained.
- */
-function useDockNoteContext(note: FNote | undefined) {
- const parentComponent = useContext(ParentComponent);
- const [ noteContext ] = useState(() => new NoteContext(DOCK_NTX_ID));
- const [ dockComponent ] = useState(() => new Component());
-
- useEffect(() => {
- if (!parentComponent) return;
-
- parentComponent.child(dockComponent);
- return () => parentComponent.removeChild(dockComponent);
- }, [ parentComponent, dockComponent ]);
-
- useEffect(() => {
- noteContext.triggerEvent = (name, data) => dockComponent.handleEventInChildren(name, data);
- }, [ noteContext, dockComponent ]);
-
- useEffect(() => {
- if (!note) return;
-
- const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
- void noteContext.setNote(notePath, {
- keepActiveDialog: true,
- viewScope: {
- readOnlyTemporarilyDisabled: !note.hasLabel("readOnly"),
- // The dock has a third of a note's width, which is not a toolbar's worth.
- floatingToolbar: true
- }
- });
- }, [ noteContext, note?.noteId ]);
-
- return { noteContext, dockComponent };
-}
-
/** The dock's contents, reading the note out of the context the dock provides. */
function DockContent({ onClose }: { onClose(): void }) {
// The dock stands for its component in the DOM, which is how the text editor finds its host —
@@ -141,7 +94,7 @@ function DockContent({ onClose }: { onClose(): void }) {
/>
</div>
- <div className="calendar-detail-dock-body">
+ <div className="calendar-detail-dock-body tn-embedded-note-pane">
<PromotedAttributes omit={EVENT_DATE_LABELS} />
<NoteDetail />
</div>
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.css
index ebe1fb3c39..85637ab415 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.css
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css
@@ -59,31 +59,13 @@
}
/*
- * The pane's one body: the row of actions, then the note itself. A column so that the note takes
- * whatever the row above leaves, however tall the pane happens to be.
+ * The pane's one body: the row of actions, then the note itself — the note's own widgets laid out
+ * by the shared class (see EmbeddedNotePane.css), which also brings the column they stand in.
*/
.geo-map-container .geo-detail-pane .geo-detail-pane-body {
- display: flex;
- flex-direction: column;
- gap: 10px;
padding-top: 0;
}
-/*
- * The note fills the rest of the pane rather than ending where its content does, so that clicking
- * below a short note still puts the caret in it — as it does in a note of its own.
- */
-.geo-map-container .geo-detail-pane .note-detail {
- flex: 1;
- /* Written for a note split, where the split hands it one; there is no split here, and an unset
- `--max-content-width` would leave `max-width` invalid rather than absent. */
- max-width: none;
- /* A floor rather than the 0 a flex item needs to scroll its own content: the fields above it are
- as many as the note asks for, and without one they would squeeze the note out of the pane
- instead of the body scrolling. Above the floor a long note still scrolls within itself. */
- min-height: 120px;
-}
-
/*
* Where the marker stands, reading as a subtitle to the name above it rather than as one more thing
* to press: it is a line of text that happens to answer to a click, so it stands on no plate of its
@@ -110,63 +92,6 @@
}
}
-/*
- * The note's promoted fields, laid out for a third of the width they are written for.
- *
- * A field reads across one line — its name, then what it holds — and stays that way here; what
- * changes is the row they stand in. Across a note they stand side by side, each as wide as what it
- * holds; in the pane there is room for one, so they come down the column instead, each taking the
- * whole width.
- */
-.geo-map-container .geo-detail-pane .promoted-attributes-container {
- flex-direction: column;
- align-items: stretch;
- gap: 8px;
- margin: 0;
- /* The body of the pane is the one thing that scrolls; a scroller inside it would take the wheel
- off whichever of the two the pointer happened to be over. */
- max-height: none;
- overflow: visible;
-}
-
-.geo-map-container .geo-detail-pane .promoted-attribute-cell {
- margin: 0;
-
- /* The field takes whatever its name leaves, rather than the width of what it holds: a card
- standing alone on its line has that room whether it needs it or not. */
- > .input-group,
- > .promoted-attribute-values {
- flex: 1;
- min-width: 0;
- margin-inline-start: 8px;
- }
-
- /* Both are given a width in ems, which is a card's own width where cards stand side by side.
- Marked as the theme marks them, there being no other way past it. */
- input[type="text"],
- input[type="number"] {
- width: auto !important;
- }
-
- /* A name longer than the pane is cut short rather than pushing the field it names off the end. */
- > label {
- min-width: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- }
-
- .tn-field {
- min-width: 0;
- padding: 0;
- }
-}
-
-/* The widget stands whether the note promotes anything or not, and an empty one would still take
- its share of the gap between the actions above it and the note below. */
-.geo-map-container .geo-detail-pane .promoted-attributes-widget:not(:has(.promoted-attribute-cell)) {
- display: none;
-}
-
/*
* 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.
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index b4434ca4ee..04199c1d69 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -2,17 +2,17 @@ import "./DetailPane.css";
import clsx from "clsx";
import type { GeoJSONSource, MapGeoJSONFeature, Map as MapLibreGLMap, MapMouseEvent, MapSourceDataEvent } from "maplibre-gl";
-import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
+import { useCallback, useContext, useEffect, useMemo, useRef } from "preact/hooks";
import appContext from "../../../components/app_context";
-import Component from "../../../components/component";
-import NoteContext, { openInCurrentNoteContext } from "../../../components/note_context";
+import { openInCurrentNoteContext } from "../../../components/note_context";
import FNote from "../../../entities/fnote";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker";
import linkContextMenu from "../../../menus/link_context_menu";
import { copyTextWithToast } from "../../../services/clipboard_ext";
import { t } from "../../../services/i18n";
import link from "../../../services/link";
+import { announceEmbeddedNoteClosing, EmbeddedNoteScope, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
@@ -21,7 +21,7 @@ import Dropdown from "../../react/Dropdown";
import { FormListItem } from "../../react/FormList";
import { useLegacyComponentElement, useNoteColorClass, useNoteContext, useNoteLabel, useStaticTooltip } from "../../react/hooks";
import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";
-import { NoteContextContext, ParentComponent } from "../../react/react_utils";
+import { ParentComponent } from "../../react/react_utils";
import { removeFromMap } from "./api";
import { GPX_MIME, trackHitLayers, trackSourceId } from "./GpxTrack";
import { ParentMap } from "./map";
@@ -79,22 +79,15 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
const map = useContext(ParentMap);
const note = notes.find((note) => note.noteId === selection?.noteId);
const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);
- const { noteContext, paneComponent } = usePaneNoteContext(note);
+ const { noteContext, component: paneComponent } = useEmbeddedNoteContext(note, PANE_NTX_ID);
/**
- * Lets the pane go, having given whatever is being edited in it the chance to save.
- *
- * Switching from one marker to another needs no such thing: that is a note switch within the
- * pane, and the context announces it. Closing announces nothing at all — the widgets are simply
- * unmounted — so the event a note context is removed under is raised here in its place, which is
- * what the editors are listening for (see the spaced updates in hooks.tsx).
- *
- * Raised but not waited on: the save is under way by the time the call returns, and a request
- * already in flight does not care that what started it has gone. Waiting would hold the pane
- * open for a round trip to the server every time it was closed with something unsaved in it.
+ * Lets the pane go, having given whatever is being edited in it the chance to save (see
+ * {@link announceEmbeddedNoteClosing}). Switching from one marker to another needs no such
+ * thing: that is a note switch within the pane, and the context announces it.
*/
const closePane = useCallback(() => {
- void paneComponent.handleEventInChildren("beforeNoteContextRemove", { ntxIds: [ PANE_NTX_ID ] });
+ void announceEmbeddedNoteClosing(paneComponent, PANE_NTX_ID);
onSelect(null);
}, [ paneComponent, onSelect ]);
@@ -239,13 +232,13 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
return (
// 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}>
- <MarkerDetails note={note} parentNote={parentNote} isReadOnly={isReadOnly} onClose={closePane} onRelocate={relocate} onFollowLink={followLink} />
- {selection?.isNew && <SelectTitleOnFirstOpen />}
- </NoteContextContext.Provider>
- </ParentComponent.Provider>
+ // TitleRow), and answers to the pane's own component rather than the map's (see
+ // 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} />
+ {selection?.isNew && <SelectTitleOnFirstOpen />}
+ </EmbeddedNoteScope>
);
}
@@ -458,7 +451,7 @@ function MarkerDetails({ note, parentNote, isReadOnly, onClose, onRelocate, onFo
header={<TitleRow compact />}
close={{ text: t("geo-map.close-details"), onClick: onClose }}
>
- <OverlayPanelBody className="geo-detail-pane-body">
+ <OverlayPanelBody className="geo-detail-pane-body tn-embedded-note-pane">
<MarkerLocation note={note} />
<MarkerActions note={note} parentNote={parentNote} isReadOnly={isReadOnly} onRelocate={onRelocate} />
@@ -485,63 +478,6 @@ function MarkerDetails({ note, parentNote, isReadOnly, onClose, onRelocate, onFo
/** 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 | undefined) {
- 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(() => {
- if (!note) return;
-
- const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
- void noteContext.setNote(notePath, {
- // Selecting a marker is not the kind of navigation that should dismiss an open dialog.
- keepActiveDialog: true,
- viewScope: {
- // A note held read-only only because of its size is editable here, as it is in the
- // quick editor; one the reader has marked read-only stays that way.
- readOnlyTemporarilyDisabled: !note.hasLabel("readOnly"),
- // The pane has a third of a note's width, which is not a toolbar's worth: the
- // editor's own follows the selection instead of standing in a bar (see link.ts).
- floatingToolbar: true
- }
- });
- }, [ noteContext, note?.noteId ]);
-
- return { noteContext, paneComponent };
-}
-
/**
* What can be done with the marker: the ways of opening its note, then the ways of changing it.
*