Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): grow the event card in place instead of handing to quick edit

Elian Doran5402f4298e20
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index a17dbeabfb..cdc108a289 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1007,6 +1007,8 @@
"pin_date": "Pin the current date so the calendar always opens on this interval instead of today",
"unpin_date": "Unpin the date so the calendar opens on today's date again",
"close_details": "Close event details",
+ "expand_details": "Expand the event to fill the window",
+ "restore_details": "Put the event back beside its place in the calendar",
"dates": {
"all_day": "All day",
"date": "Date",
diff --git a/apps/client/src/widgets/EmbeddedNotePane.tsx b/apps/client/src/widgets/EmbeddedNotePane.tsx
index df6bc9c6e8..7a02d2a970 100644
--- a/apps/client/src/widgets/EmbeddedNotePane.tsx
+++ b/apps/client/src/widgets/EmbeddedNotePane.tsx
@@ -271,21 +271,49 @@ export const OTHER_WAYS_TO_OPEN = [
{ command: "openNoteInPopup", icon: "bx bx-edit", title: () => t("link_context_menu.open_note_in_popup") }
] as const;
+/**
+ * The button a pane is grown by, whatever growing means to the host: the quick editor for a pane
+ * that has no larger form of its own (see {@link MaximizeToQuickEditAction}), or the pane's own
+ * larger form where it has one — the calendar's event card, which grows in place so that what is
+ * being edited within it is never torn down (see EventPopover).
+ *
+ * Stands beside the header's X and is dressed as its neighbour is (see EmbeddedNotePane.css). Named
+ * by the host, there being no one word for it: what it does is the host's to say, and a card that
+ * can be put back down again says something different from one that hands over to another surface.
+ */
+export function MaximizeAction({ text, icon, onClick }: {
+ text: string;
+ /** The stock expand, unless the host has a way back and wants the arrows the other way about. */
+ icon?: string;
+ onClick(): void;
+}) {
+ return (
+ <ActionButton
+ className="tn-embedded-note-maximize"
+ icon={icon ?? "bx bx-expand-alt"}
+ text={text}
+ onClick={onClick}
+ />
+ );
+}
+
/**
* 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).
+ * save.
+ *
+ * For a pane with no larger form of its own — the geo map's, whose note has nothing of the map
+ * about it to be carried into a bigger card. A pane that has one grows into that instead, and keeps
+ * what is peculiar to it.
*
* 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"
+ <MaximizeAction
text={t("embedded_note.maximize")}
onClick={() => {
const notePath = note.getBestNotePathString(appContext.tabManager.getActiveContext()?.hoistedNoteId);
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.css b/apps/client/src/widgets/collections/calendar/EventPopover.css
index 56e7349dcb..512668e655 100644
--- a/apps/client/src/widgets/collections/calendar/EventPopover.css
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.css
@@ -1,14 +1,23 @@
.calendar-event-popover {
- /* One width whatever event it stands for, and as tall as that event needs; what it holds
- scrolls within it (see the body below). Both are held to what the window can spare: the card
- is anchored beside a chip rather than laid over the page, and Popper answers a card too big
- for the room by shifting it into the viewport rather than by narrowing it (see the
- preventOverflow modifier in Popover.tsx) — so a width the window cannot take would hang off
- the edge instead of being given back.
- The width must agree with `MAX_ANCHOR_WIDTH` in selection.ts. */
+ /* Held to the window: Popper shifts a card too wide for the room into the viewport rather than
+ narrowing it, so an unclamped width would hang off the edge.
+ Must agree with `MAX_ANCHOR_WIDTH` in selection.ts. */
width: min(480px, calc(100vw - 4rem));
+ /* As tall as the event needs; what it holds scrolls within it (see the body below). */
max-height: min(640px, 85vh);
+ /* The same card grown to the window (see the maximize in EventDetails); it takes its height
+ from the insets in `.maximized` in Popover.css, so the anchored ceiling is given up here. */
+ &.maximized {
+ width: min(var(--preferred-max-content-width, 900px), calc(100vw - 4rem));
+ max-height: none;
+
+ /* The card is now taller than the event, so the column has to take up the difference. */
+ .calendar-event-popover-inner {
+ flex: 1;
+ }
+ }
+
.calendar-event-popover-inner {
display: flex;
flex-direction: column;
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.tsx b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
index d8fa7ee0da..e6857db4c1 100644
--- a/apps/client/src/widgets/collections/calendar/EventPopover.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import { isMobile } from "../../../services/utils";
-import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeToQuickEditAction, NoteColorAction, OpenNoteActions, useEmbeddedNoteContext, useFollowLinksWithin } from "../../EmbeddedNotePane";
+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeAction, NoteColorAction, OpenNoteActions, useEmbeddedNoteContext, useFollowLinksWithin } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
@@ -55,6 +55,17 @@ export default function EventPopover({ noteId, anchor, container, parentNote, is
const note = useNote(noteId);
const { noteContext, component } = useEmbeddedNoteContext(note ?? undefined, POPOVER_NTX_ID);
+ /**
+ * Whether the card has been grown to the window (see the maximize in {@link EventDetails}, and
+ * `maximized` in Popover for what it does to the card). A state of the standing card and not a
+ * surface of its own, so that growing it neither saves nor reloads anything: the note's editor
+ * is the same editor either side of it, mid-edit and all.
+ *
+ * Kept across a switch from one event to another, a reader who asked for the room being taken
+ * to have meant the asking rather than the event they happened to ask it on.
+ */
+ const [ maximized, setMaximized ] = useState(false);
+
/**
* Lets the surface go, having given whatever is being edited in it the chance to save — the
* geo pane's bargain (see its closePane): announced first, while the editors are still
@@ -83,6 +94,8 @@ export default function EventPopover({ noteId, anchor, container, parentNote, is
updateKey={noteId}
parentNote={parentNote}
isEditable={isEditable}
+ maximized={maximized}
+ setMaximized={setMaximized}
onClose={close}
onFollowLink={onFollowLink}
/>
@@ -91,16 +104,22 @@ export default function EventPopover({ noteId, anchor, container, parentNote, is
);
}
-/** The event beside its chip, as a desktop shows it. */
-function EventPopoverShell({ note, anchorRect, updateKey, parentNote, isEditable, onClose, onFollowLink }: {
+/** The event beside its chip, as a desktop shows it — or grown to the window, which is the same
+ * card and the same standing editors (see {@link maximized} in Popover). */
+function EventPopoverShell({ note, anchorRect, updateKey, parentNote, isEditable, maximized, setMaximized, onClose, onFollowLink }: {
note: FNote;
anchorRect(): DOMRect;
updateKey: string;
parentNote: FNote;
isEditable: boolean;
+ maximized: boolean;
+ setMaximized(maximized: boolean): void;
onClose(): void;
onFollowLink(noteId: string): boolean;
}) {
+ // Escape closes the card whether it stands beside its chip or fills the window, as a press
+ // outside it does and as every dialog in the app answers the key. Being grown is a way the card
+ // is drawn rather than a mode to be let out of, and the maximize is its own way back down.
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose();
@@ -121,9 +140,14 @@ function EventPopoverShell({ note, anchorRect, updateKey, parentNote, isEditable
// Named by the attribute eventDidMount stamps on every chip rather than by a
// FullCalendar class: v7 emits hashed class names, so `.fc-event` no longer exists.
keepOpenSelector="[data-event-note-id]"
+ maximized={maximized}
onDismiss={onClose}
>
- <EventDetails note={note} parentNote={parentNote} isEditable={isEditable} onClose={onClose} onFollowLink={onFollowLink} />
+ <EventDetails
+ note={note} parentNote={parentNote} isEditable={isEditable}
+ maximized={maximized} setMaximized={setMaximized}
+ onClose={onClose} onFollowLink={onFollowLink}
+ />
</Popover>
);
}
@@ -188,10 +212,12 @@ function EventSheet({ note, parentNote, isEditable, onClose, onFollowLink }: {
const POPOVER_NTX_ID = "_calendar-event-popover";
/** The popover's contents: what heads it, and the event under that. */
-function EventDetails({ note, parentNote, isEditable, onClose, onFollowLink }: {
+function EventDetails({ note, parentNote, isEditable, maximized, setMaximized, onClose, onFollowLink }: {
note: FNote;
parentNote: FNote;
isEditable: boolean;
+ maximized: boolean;
+ setMaximized(maximized: boolean): void;
onClose(): void;
onFollowLink(noteId: string): boolean;
}) {
@@ -210,7 +236,11 @@ function EventDetails({ note, parentNote, isEditable, onClose, onFollowLink }: {
<div className="calendar-event-popover-header">
<TitleRow compact />
{/* A sheet is offered no maximize: it already has the whole screen to grow into. */}
- <MaximizeToQuickEditAction note={note} onClose={onClose} />
+ <MaximizeAction
+ icon={maximized ? "bx bx-collapse-alt" : "bx bx-expand-alt"}
+ text={maximized ? t("calendar.restore_details") : t("calendar.expand_details")}
+ onClick={() => setMaximized(!maximized)}
+ />
<ActionButton
icon="bx bx-x"
text={t("calendar.close_details")}
diff --git a/apps/client/src/widgets/react/Popover.css b/apps/client/src/widgets/react/Popover.css
index 342998a90e..68c5626463 100644
--- a/apps/client/src/widgets/react/Popover.css
+++ b/apps/client/src/widgets/react/Popover.css
@@ -12,6 +12,9 @@
/* Above the note split's own layers; menus and dialogs stand higher still. */
z-index: 998;
+ /* Popper writes this too, but gives it back as it is destroyed; without it here the panel
+ falls into the page's flow for a frame on the way back from being maximized. */
+ position: fixed;
display: flex;
flex-direction: column;
box-sizing: border-box;
@@ -23,6 +26,33 @@
backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));
}
+/* The card let go of its anchor and grown to the window (see `maximized` in Popover.tsx). Popper
+ takes the placement attribute off as it is destroyed, so its absence is what says the inline
+ placement has been given back and the stylesheet may place the card itself. */
+.tn-popover.maximized:not([data-popper-placement]) {
+ position: fixed;
+ inset-block: 5vh;
+ inset-inline: 0;
+ margin-inline: auto;
+ max-width: calc(100vw - 4rem);
+}
+
+.tn-popover.maximized > .tn-popover-arrow {
+ display: none;
+}
+
+/* The card's sibling rather than its child: `backdrop-filter` above makes the card the containing
+ block for anything fixed within it. */
+.tn-popover-backdrop {
+ position: fixed;
+ inset: 0;
+ z-index: 997;
+ /* Each theme states the colour opaque and leaves the dimming to `.modal-backdrop.show`, which
+ is Bootstrap's and not in play here. */
+ background: var(--modal-backdrop-color, #000);
+ opacity: 0.5;
+}
+
/*
* The arrow: which side the popover is on says where it stands, and Popper slides it along that
* side to sit over the anchor (see the arrow modifier in Popover.tsx).
diff --git a/apps/client/src/widgets/react/Popover.maximized.spec.tsx b/apps/client/src/widgets/react/Popover.maximized.spec.tsx
new file mode 100644
index 0000000000..aabab9faf4
--- /dev/null
+++ b/apps/client/src/widgets/react/Popover.maximized.spec.tsx
@@ -0,0 +1,94 @@
+import { render } from "preact";
+import { act } from "preact/test-utils";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import Popover from "./Popover";
+
+/**
+ * Growing an anchored card to fill the window (see `maximized` in Popover), which is a way the same
+ * card is drawn and not a surface put up in its place. What that buys is the point of these: a note
+ * being edited within the card lives across the change, where a dialog raised instead would tear
+ * the editor down and build it again with whatever was typed still unsaved.
+ */
+describe("Popover, maximized", () => {
+ let container: HTMLElement;
+
+ beforeEach(() => {
+ container = document.createElement("div");
+ document.body.appendChild(container);
+ });
+
+ afterEach(() => {
+ render(null, container);
+ container.remove();
+ document.body.innerHTML = "";
+ });
+
+ const anchorRect = () => new DOMRect(100, 100, 50, 20);
+
+ /**
+ * Drawn, and then given the turn of the loop Popper places a card in: `createPopper` schedules
+ * its first placement rather than doing it there and then, so the attribute that says where the
+ * card ended up is not on it until the microtasks have run out.
+ */
+ async function mount(maximized: boolean) {
+ await act(async () => {
+ render(
+ <Popover getAnchorRect={anchorRect} maximized={maximized}>
+ <div className="held-content" />
+ </Popover>,
+ container);
+ await Promise.resolve();
+ });
+ }
+
+ const popover = () => document.querySelector<HTMLElement>(".tn-popover");
+ const backdrop = () => document.querySelector<HTMLElement>(".tn-popover-backdrop");
+ const held = () => document.querySelector<HTMLElement>(".held-content");
+
+ it("keeps what it holds across the change, rather than building it again", async () => {
+ await mount(false);
+ const before = held();
+ expect(before).toBeTruthy();
+
+ await mount(true);
+ expect(held()).toBe(before);
+
+ // And back down again: the card is anchored once more and what it holds has still never
+ // been away.
+ await mount(false);
+ expect(held()).toBe(before);
+ });
+
+ it("lets go of the anchor as it grows, and takes hold again as it comes down", async () => {
+ await mount(false);
+ // Popper places the card and says where it ended up; the styling of a grown card waits on
+ // that attribute being gone (see the `.maximized` rules in Popover.css).
+ expect(popover()?.getAttribute("data-popper-placement")).toBeTruthy();
+
+ await mount(true);
+ expect(popover()?.classList.contains("maximized")).toBe(true);
+ // Given back as the popper is destroyed, along with the inline placement it wrote — which
+ // is what leaves the stylesheet free to put the card where it likes.
+ expect(popover()?.hasAttribute("data-popper-placement")).toBe(false);
+ expect(popover()?.style.transform).toBe("");
+
+ await mount(false);
+ expect(popover()?.classList.contains("maximized")).toBe(false);
+ expect(popover()?.getAttribute("data-popper-placement")).toBeTruthy();
+ });
+
+ it("dims the page only while it is grown", async () => {
+ await mount(false);
+ expect(backdrop()).toBeNull();
+
+ await mount(true);
+ // A sibling of the card and not a child: the card carries a backdrop filter, which would
+ // make it the containing block of anything fixed within it (see Popover.css).
+ expect(backdrop()).toBeTruthy();
+ expect(backdrop()?.contains(popover() ?? null)).toBe(false);
+
+ await mount(false);
+ expect(backdrop()).toBeNull();
+ });
+});
diff --git a/apps/client/src/widgets/react/Popover.tsx b/apps/client/src/widgets/react/Popover.tsx
index eac6547447..6ad7f70f58 100644
--- a/apps/client/src/widgets/react/Popover.tsx
+++ b/apps/client/src/widgets/react/Popover.tsx
@@ -37,6 +37,18 @@ export interface PopoverProps {
* press itself still lands where it fell — dismissal must not swallow it, or pressing the
* thing the popover stands beside would take two tries. */
onDismiss?(): void;
+ /**
+ * Lets go of the anchor: the panel keeps its place in the body and is left to the stylesheet to
+ * put where it likes — a card grown to fill the window (see the `.maximized` rules in
+ * Popover.css), rather than one standing beside something.
+ *
+ * A state of this popover and not a surface of its own, which is the whole of the point: what
+ * the card holds — a note's editor, mid-edit — stays mounted across the change, where a dialog
+ * raised in its place would tear it down and build it again with whatever was typed still
+ * unsaved. Popper is not merely stopped but taken down, its `applyStyles` giving back the
+ * inline placement it wrote (see the effect below) so the stylesheet has the field to itself.
+ */
+ maximized?: boolean;
children: ComponentChildren;
}
@@ -46,7 +58,7 @@ export interface PopoverProps {
* container clips it and no containment root flattens its frosting (see the Dropdown notes in
* CLAUDE.md); positioned by Popper, which also keeps it in place while ancestors scroll.
*/
-export default function Popover({ getAnchorRect, placement, updateKey, className, keepOpenSelector, onDismiss, children }: PopoverProps) {
+export default function Popover({ getAnchorRect, placement, updateKey, className, keepOpenSelector, onDismiss, maximized, children }: PopoverProps) {
const elRef = useRef<HTMLDivElement>(null);
const arrowRef = useRef<HTMLDivElement>(null);
const popperRef = useRef<Instance>();
@@ -58,7 +70,11 @@ export default function Popover({ getAnchorRect, placement, updateKey, className
useEffect(() => {
const el = elRef.current;
- if (!el) return;
+ // A maximized card is placed by the stylesheet rather than beside anything, so it is given
+ // no popper at all. Tearing down the one it had is what hands its placement back: Popper's
+ // `applyStyles` remembers the inline styles it found and restores them as it is destroyed,
+ // which the cleanup below runs on the way into this state.
+ if (!el || maximized) return;
const anchor: VirtualElement = { getBoundingClientRect: () => getRectRef.current() };
const popper = createPopper(anchor, el, {
@@ -89,7 +105,7 @@ export default function Popover({ getAnchorRect, placement, updateKey, className
popperRef.current = undefined;
popper.destroy();
};
- }, [ placement ]);
+ }, [ placement, maximized ]);
useEffect(() => {
void popperRef.current?.update();
@@ -122,13 +138,21 @@ export default function Popover({ getAnchorRect, placement, updateKey, className
}, [ onDismiss, keepOpenSelector ]);
return createPortal(
- <div ref={elRef} className={clsx("tn-popover", className)}>
- {/* What the popover is pointing at, drawn by Popper against whichever side it ended up
- on (see the placements in Popover.css). First in the panel so its static position is
- the panel's own corner, which is what Popper's offset is reckoned from. */}
- <div ref={arrowRef} className="tn-popover-arrow" />
- {children}
- </div>,
+ <>
+ {/* What dims the page behind a maximized card — its sibling rather than its child, for
+ the reason given in Popover.css. Drawn before it, so it stands behind it whatever
+ the two are given to stand at. */}
+ {maximized && <div className="tn-popover-backdrop" />}
+
+ <div ref={elRef} className={clsx("tn-popover", maximized && "maximized", className)}>
+ {/* What the popover is pointing at, drawn by Popper against whichever side it ended
+ up on (see the placements in Popover.css). First in the panel so its static
+ position is the panel's own corner, which is what Popper's offset is reckoned
+ from. */}
+ <div ref={arrowRef} className="tn-popover-arrow" />
+ {children}
+ </div>
+ </>,
document.body
);
}