Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): share the way an embedded note grows into the quick editor

Elian Doran10248b79459a
diff --git a/apps/client/src/widgets/EmbeddedNotePane.css b/apps/client/src/widgets/EmbeddedNotePane.css
index f8d58d8387..67ea44fedf 100644
--- a/apps/client/src/widgets/EmbeddedNotePane.css
+++ b/apps/client/src/widgets/EmbeddedNotePane.css
@@ -100,3 +100,18 @@
:root .tn-embedded-note-pane .tn-embedded-note-remove.icon-action {
color: var(--dropdown-item-icon-destructive-color);
}
+
+/*
+ * The maximize button (see MaximizeToQuickEditAction), dressed as the X it stands beside: the
+ * compact round surface the theme reserves for close crosses (`.icon-action.bx-x` in
+ * theme-next/forms.css), minus the red close hover. The icon keeps the stock ratio rather than the
+ * X's 0.8 — the expand glyph fills its em box where the X's does not, so the stock size is what
+ * stands at the X's visual weight. Stated from `:root` and with the icon's own class doubled on,
+ * so as to outweigh the theme's blanket `border-radius` whichever way the stylesheets are ordered
+ * (the bargain the attribute list's delete button strikes; see AttributeList.css).
+ */
+:root .icon-action.bx-expand-alt.tn-embedded-note-maximize {
+ --icon-button-size: 24px;
+
+ border-radius: 50%;
+}
diff --git a/apps/client/src/widgets/EmbeddedNotePane.tsx b/apps/client/src/widgets/EmbeddedNotePane.tsx
index cc78b7fdc2..030055e714 100644
--- a/apps/client/src/widgets/EmbeddedNotePane.tsx
+++ b/apps/client/src/widgets/EmbeddedNotePane.tsx
@@ -229,6 +229,31 @@ export const OTHER_WAYS_TO_OPEN = [
{ command: "openNoteInPopup", icon: "bx bx-edit", title: () => t("link_context_menu.open_note_in_popup") }
] as const;
+/**
+ * The pane grown into the quick editor: the same note in the larger surface, taking the pane's
+ * place rather than standing over it — opened first and closed after, as the quick editor's own
+ * maximize hands over to a tab. Which is what earns it the place in the header that the quick-edit
+ * menu entry is denied in the row (see {@link OTHER_WAYS_TO_OPEN}): a maximize replaces the pane
+ * instead of putting a modal back over it, the close giving whatever is being edited the chance to
+ * save. Stands beside the header's X, and is dressed as its neighbour is (see EmbeddedNotePane.css).
+ *
+ * A path rather than an id, as the menu passes one, so the two roads into the quick editor agree.
+ */
+export function MaximizeToQuickEditAction({ note, onClose }: { note: FNote; onClose(): void }) {
+ return (
+ <ActionButton
+ className="tn-embedded-note-maximize"
+ icon="bx bx-expand-alt"
+ text={t("embedded_note.maximize")}
+ onClick={() => {
+ const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
+ appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath || note.noteId });
+ onClose();
+ }}
+ />
+ );
+}
+
/**
* The colour the note's marker, chip or card is drawn in, which the pane already wears in its title
* but would otherwise have no way of setting — the right-click menu was the only place it could be
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.css b/apps/client/src/widgets/collections/calendar/EventPopover.css
index 6b4f99beb2..6ed02505a1 100644
--- a/apps/client/src/widgets/collections/calendar/EventPopover.css
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.css
@@ -22,17 +22,6 @@
flex: 1;
min-width: 0;
}
-
- /* The maximize button, dressed as the X beside it is (see "The 'x' icon button" in
- theme-next/forms.css) minus the red close hover: the same small round surface, with the
- stock hover underneath. The icon keeps the stock ratio rather than the X's 0.8 — the
- expand glyph fills its em box where the X's does not, so the stock size is what stands
- at the X's visual weight. */
- > .icon-action.bx-expand-alt {
- --icon-button-size: 24px;
-
- border-radius: 50%;
- }
}
/* The note's own widgets are laid out by the shared class (see EmbeddedNotePane.css), which
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.tsx b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
index bc6bd1e71d..d4a6dc3f80 100644
--- a/apps/client/src/widgets/collections/calendar/EventPopover.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
@@ -2,11 +2,10 @@ import "./EventPopover.css";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
-import appContext from "../../../components/app_context";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import { isMobile } from "../../../services/utils";
-import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, NoteColorAction, OpenNoteActions, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeToQuickEditAction, NoteColorAction, OpenNoteActions, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
@@ -200,23 +199,8 @@ function EventDetails({ note, parentNote, isEditable, onClose }: {
<div className="calendar-event-popover-inner" ref={innerRef}>
<div className="calendar-event-popover-header">
<TitleRow compact />
- {/* The popover grown into the quick editor: the same note in the larger surface,
- taking the popover's place rather than standing over it — opened first and
- closed after, as the quick editor's own maximize hands over to a tab. A path
- rather than an id, as the more-ways-to-open menu passes one (see
- OpenNoteActions), so the two roads into the quick editor agree.
-
- A sheet is offered none: it already has the whole screen to grow into. */}
- <ActionButton
- icon="bx bx-expand-alt"
- text={t("calendar.maximize_details")}
- onClick={() => {
- const notePath = note.getBestNotePathString(
- appContext.tabManager.getActiveContext()?.hoistedNoteId);
- appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath || note.noteId });
- onClose();
- }}
- />
+ {/* A sheet is offered no maximize: it already has the whole screen to grow into. */}
+ <MaximizeToQuickEditAction note={note} onClose={onClose} />
<ActionButton
icon="bx bx-x"
text={t("calendar.close_details")}
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.css
index d4448e8600..b799040409 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.css
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css
@@ -53,8 +53,8 @@
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;
+ /* Clear of the maximize and close buttons laid over the end of the row (see OverlayPanel.css). */
+ padding-inline-end: 64px;
border-bottom: 1px solid var(--main-border-color);
}
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index e6143189b6..0ff04fa69f 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, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeToQuickEditAction, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
@@ -415,6 +415,7 @@ function MarkerDetails({ note, parentNote, isReadOnly, onClose, onRelocate, onFo
containerRef={paneRef}
className={clsx("geo-detail-pane", colorClass)}
header={<TitleRow compact />}
+ headerActions={<MaximizeToQuickEditAction note={note} onClose={onClose} />}
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/react/OverlayPanel.css b/apps/client/src/widgets/react/OverlayPanel.css
index d7f9e79cb9..fc7accebcd 100644
--- a/apps/client/src/widgets/react/OverlayPanel.css
+++ b/apps/client/src/widgets/react/OverlayPanel.css
@@ -34,18 +34,22 @@
}
/*
- * At the end of the row and centred on it, whichever header it is standing at. What it looks like
- * is the theme's — an "x" icon button is dressed as the one closing a tab is, here as everywhere.
+ * At the end of the row and centred on it, whichever header it is standing at: whatever the header
+ * offers, and last of all the way out. What they look like is the theme's — an "x" icon button is
+ * dressed as the one closing a tab is, here as everywhere.
*
- * Laid over the row rather than standing in it: a strip of tabs is centred on the panel, and a
- * button taking its own place beside it would push it off centre. There is room to spare next to
- * two tabs and next to one word, so the two never meet.
+ * Laid over the row rather than standing in it: a strip of tabs is centred on the panel, and
+ * buttons taking their own place beside it would push it off centre. There is room to spare next
+ * to two tabs and next to one word, so the two never meet.
*/
-.tn-overlay-panel .tn-overlay-panel-close {
+.tn-overlay-panel .tn-overlay-panel-header-actions {
position: absolute;
inset-inline-end: 6px;
top: 50%;
transform: translateY(-50%);
+ display: flex;
+ align-items: center;
+ gap: 4px;
}
/*
diff --git a/apps/client/src/widgets/react/OverlayPanel.tsx b/apps/client/src/widgets/react/OverlayPanel.tsx
index 6e3d3d8dca..96cdd4df59 100644
--- a/apps/client/src/widgets/react/OverlayPanel.tsx
+++ b/apps/client/src/widgets/react/OverlayPanel.tsx
@@ -18,6 +18,9 @@ interface OverlayPanelProps {
* {@link OverlayPanelTitle} where there is only the one thing to show.
*/
header: ComponentChildren;
+ /** Whatever else the header row offers, standing between the header and the close button —
+ * the geo pane's maximize, say (see MaximizeToQuickEditAction). */
+ headerActions?: ComponentChildren;
/** 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?: {
@@ -38,7 +41,7 @@ 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, close, children }: OverlayPanelProps) {
+export default function OverlayPanel({ className, containerRef, header, headerActions, close, children }: OverlayPanelProps) {
return (
<div
ref={containerRef}
@@ -53,13 +56,19 @@ export default function OverlayPanel({ className, containerRef, header, close, c
<div className="tn-overlay-panel-header">
{header}
- {close && (
- <ActionButton
- className="tn-overlay-panel-close"
- icon="bx bx-x"
- text={close.text}
- onClick={close.onClick}
- />
+ {(headerActions || close) && (
+ <div className="tn-overlay-panel-header-actions">
+ {headerActions}
+
+ {close && (
+ <ActionButton
+ className="tn-overlay-panel-close"
+ icon="bx bx-x"
+ text={close.text}
+ onClick={close.onClick}
+ />
+ )}
+ </div>
)}
</div>