Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): read an event where it stands, in a popover at its chip

Elian Doran6f112975263d
diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.css b/apps/client/src/widgets/collections/calendar/DetailDock.css
deleted file mode 100644
index db1e1c10d9..0000000000
--- a/apps/client/src/widgets/collections/calendar/DetailDock.css
+++ /dev/null
@@ -1,58 +0,0 @@
-.calendar-view .calendar-detail-dock {
- /* One fixed width for the animated shell and the inner column, so the contents keep their
- shape while the shell slides rather than reflowing at every frame of it. The percentage cap
- belongs to the shell alone: on the inner column it would resolve against the shell's own
- (already capped) width and halve the contents. On a narrow view the shell simply clips the
- trailing end of the column. */
- --calendar-dock-width: 360px;
-
- flex: 0 0 auto;
- width: 0;
- overflow: hidden;
- transition: width 250ms ease;
-
- &.open {
- width: min(var(--calendar-dock-width), 50%);
- }
-
- @media (prefers-reduced-motion: reduce) {
- transition: none;
- }
-
- .calendar-detail-dock-inner {
- width: var(--calendar-dock-width);
- height: 100%;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- border-inline-start: 1px solid var(--main-border-color);
- background: var(--main-background-color);
- }
-
- .calendar-detail-dock-header {
- display: flex;
- align-items: center;
- gap: 4px;
- padding: 4px 9px;
- border-bottom: 1px solid var(--main-border-color);
-
- > .title-row {
- flex: 1;
- min-width: 0;
- }
- }
-
- /* 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;
- padding: 10px;
- /* The scrollbar's room is kept whether or not it shows, so the fields hold one width
- across events instead of narrowing by its thickness when a longer note brings it. */
- scrollbar-gutter: stable;
- }
-
-}
diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.tsx b/apps/client/src/widgets/collections/calendar/DetailDock.tsx
deleted file mode 100644
index f574fa59c8..0000000000
--- a/apps/client/src/widgets/collections/calendar/DetailDock.tsx
+++ /dev/null
@@ -1,187 +0,0 @@
-import "./DetailDock.css";
-
-import clsx from "clsx";
-import { useEffect, useRef, useState } from "preact/hooks";
-
-import FNote from "../../../entities/fnote";
-import { t } from "../../../services/i18n";
-import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, NoteColorAction, OpenNoteActions, 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 { removeFromCalendar } from "./api";
-import EventDatesEditor from "./EventDatesEditor";
-import { EventFieldList } from "./EventField";
-import RecurrenceEditor from "./RecurrenceEditor";
-
-/**
- * The labels the dock already speaks for, so their fields are not repeated in the promoted grid:
- * the dates the calendar draws the event by, and the recurrence the dock's own field edits.
- * Only the stock names for now; a calendar naming its own (`calendar:startDate`) still shows those.
- */
-const EVENT_LABELS = [ "startDate", "endDate", "startTime", "endTime", "recurrence" ];
-
-/**
- * An event still being decided on: the range the reader dragged out, standing for a note that does
- * not exist yet. Nothing is created until the draft is committed (see GhostPopover), so a ghost
- * dismissed costs nothing — no note to clean up, no tombstone in the sync history.
- */
-export interface EventDraft {
- startDate: string;
- endDate?: string | null;
- startTime?: string | null;
- endTime?: string | null;
-}
-
-/**
- * Which event the view's selection stands for: the note of a chip clicked, which the dock holds,
- * or a range just dragged out whose note is yet to be — for which the dock stands closed, the
- * ghost popover standing beside the range instead (see GhostPopover).
- *
- * Owned by the calendar view rather than by either surface, because each is only one of the ways
- * in, and state a surface kept to itself could not be set from the code that hands selections over.
- */
-export type DockSelection =
- | { noteId: string }
- | {
- draft: EventDraft;
- /** Where the drag ended, in viewport coordinates, anchoring the ghost beside it. */
- anchor: { x: number; y: number } | null;
- };
-
-/**
- * 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 — or, for a draft, the ghost form the event is
- * decided in (see {@link DraftForm}).
- */
-export default function DetailDock({ selection, parentNote, isEditable, onClose }: {
- /** The view's selection. The dock holds its note; for a draft it stands closed, the ghost
- * popover standing for the selection instead. See {@link DockSelection}. */
- selection: DockSelection | null;
- /** The calendar's own note, which is how the tree is told what the calendar holds a note by. */
- parentNote: FNote;
- /** The calendar may not be edited, which leaves the dock the ways of opening a note and no
- * more — a calendar root's day notes are not events to be recoloured or taken off it. */
- isEditable: boolean;
- onClose(): void;
-}) {
- const note = useNote(selection && "noteId" in selection ? selection.noteId : undefined);
- // Held through the closing slide, so the dock empties only once it is out of sight.
- const [ shownNote, setShownNote ] = useState<FNote>();
- const open = !!note;
- const contentNote = note ?? shownNote;
- 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.
- useEffect(() => {
- if (!open && shownNote) {
- void announceEmbeddedNoteClosing(dockComponent, DOCK_NTX_ID);
- }
- }, [ open ]);
-
- useEffect(() => {
- if (!open) return;
-
- const onKeyDown = (e: KeyboardEvent) => {
- if (e.key === "Escape") onClose();
- };
- window.addEventListener("keydown", onKeyDown);
- return () => window.removeEventListener("keydown", onKeyDown);
- }, [ open, onClose ]);
-
- return (
- <div
- className={clsx("calendar-detail-dock", open && "open")}
- onTransitionEnd={(e) => {
- if (!open && e.propertyName === "width") setShownNote(undefined);
- }}
- >
- {contentNote && (
- <EmbeddedNoteScope component={dockComponent} noteContext={noteContext}>
- <DockContent note={contentNote} parentNote={parentNote} isEditable={isEditable} onClose={onClose} />
- </EmbeddedNoteScope>
- )}
- </div>
- );
-}
-
-/** 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";
-
-/** The dock's contents, reading the note out of the context the dock provides. */
-function DockContent({ note, parentNote, isEditable, onClose }: {
- note: FNote;
- parentNote: FNote;
- isEditable: boolean;
- onClose(): void;
-}) {
- // The dock stands for its component in the DOM, which is how the text editor finds its host —
- // without this it resolves the widget enclosing the calendar instead (see the geo pane).
- const innerRef = useRef<HTMLDivElement>(null);
- useLegacyComponentElement(innerRef);
-
- return (
- <div className="calendar-detail-dock-inner" ref={innerRef}>
- <div className="calendar-detail-dock-header">
- <TitleRow compact />
- <ActionButton
- className="calendar-detail-dock-close"
- icon="bx bx-x"
- text={t("calendar.close_details")}
- onClick={onClose}
- />
- </div>
-
- <div className="calendar-detail-dock-body tn-embedded-note-pane">
- {/* What can be done with the event: the ways of opening its note (see
- OpenNoteActions), then the ways of changing it — left out rather than disabled
- where the calendar may not be edited, as the geo pane leaves them out. */}
- <EmbeddedNoteActions>
- <OpenNoteActions note={note} />
-
- {isEditable && <>
- {/* Named for the chip it dresses, the colour it sets being worn everywhere
- the note shows (see NoteColorPicker). */}
- <NoteColorAction note={note} title={t("calendar_view.event_color")} />
-
- <ActionButton
- className="tn-embedded-note-remove"
- icon="bx bx-trash"
- text={t("calendar_view.remove_from_calendar")}
- // Whether the note goes with its event is asked before anything
- // happens, the two being different wishes. Closed by hand where
- // something was done: unlike the geo pane, the dock has no effect
- // watching the note leave the calendar — a removed event is still a
- // note of the collection.
- onClick={() => void removeFromCalendar(note, parentNote)
- .then((removed) => removed && onClose())}
- />
- </>}
- </EmbeddedNoteActions>
-
- {/* The event's own fields — when it happens, how it repeats — which are ways of
- changing it, so they go where the calendar may be edited: a calendar root's day
- notes are days, and a day neither moves nor recurs. */}
- {isEditable && (
- <EventFieldList>
- {/* The repeats field is handed to the dates editor to stand beside its
- all-day switch, the two being the one line of shape-of-the-event
- switches (see EventDatesEditor). */}
- <EventDatesEditor note={note} repeats={<RecurrenceEditor note={note} />} />
- </EventFieldList>
- )}
-
- <PromotedAttributes omit={EVENT_LABELS} />
- <NoteDetail />
- </div>
- </div>
- );
-}
-
diff --git a/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx b/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
index 9f1d6bf1dd..abb48c0a82 100644
--- a/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventDatesEditor.tsx
@@ -14,10 +14,11 @@ import { EventField, EventFieldControls, EventFieldRow } from "./EventField";
* Edits when the event happens, through the date and time labels the calendar draws it by (see
* event_builder.ts). Two shapes, told apart by the all-day switch: a whole-day event is a span of
* days — a start date and, where it runs longer, an end date — while a timed one is a single day
- * and the hours within it. Rendered as {@link EventField} rows, standing in the dock's field column
- * beside the recurrence.
+ * and the hours within it. Rendered as {@link EventField} rows, standing in the event popover's
+ * field column beside the recurrence.
*
- * Only the stock label names, as the dock reads only those (see EVENT_LABELS in DetailDock.tsx).
+ * Only the stock label names, as the popover reads only those (see EVENT_LABELS in
+ * EventPopover.tsx).
*/
export default function EventDatesEditor({ note, repeats }: {
note: FNote;
diff --git a/apps/client/src/widgets/collections/calendar/EventField.tsx b/apps/client/src/widgets/collections/calendar/EventField.tsx
index 0afa8cf774..d6e7a1f86c 100644
--- a/apps/client/src/widgets/collections/calendar/EventField.tsx
+++ b/apps/client/src/widgets/collections/calendar/EventField.tsx
@@ -4,10 +4,10 @@ import clsx from "clsx";
import { ComponentChildren } from "preact";
/**
- * The column of an event's own fields — how the dock will say what the calendar draws the event by
- * (its recurrence, and in time its start and end dates), those being kept out of the promoted grid
- * (see EVENT_DATE_LABELS in DetailDock.tsx). One shared shape so every field of the event reads as
- * a row of the same form.
+ * The column of an event's own fields — how the event popover says what the calendar draws the
+ * event by (its recurrence, and in time its start and end dates), those being kept out of the
+ * promoted grid (see EVENT_LABELS in EventPopover.tsx). One shared shape so every field of the
+ * event reads as a row of the same form.
*/
export function EventFieldList({ children }: { children: ComponentChildren }) {
return <div className="calendar-event-fields">{children}</div>;
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.css b/apps/client/src/widgets/collections/calendar/EventPopover.css
new file mode 100644
index 0000000000..225de5261d
--- /dev/null
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.css
@@ -0,0 +1,39 @@
+.calendar-event-popover {
+ width: 380px;
+ /* A fixed-width card as tall as its event needs, up to what the viewport can spare; what it
+ holds scrolls within it (see the body below). */
+ max-height: min(640px, 85vh);
+
+ .calendar-event-popover-inner {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ }
+
+ .calendar-event-popover-header {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 4px 9px;
+ border-bottom: 1px solid var(--main-border-color);
+ flex-shrink: 0;
+
+ > .title-row {
+ flex: 1;
+ min-width: 0;
+ }
+ }
+
+ /* 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 popover is that its body is
+ the thing that scrolls. */
+ .calendar-event-popover-body {
+ flex: 1;
+ min-height: 0;
+ overflow-y: auto;
+ padding: 10px;
+ /* The scrollbar's room is kept whether or not it shows, so the fields hold one width
+ across events instead of narrowing by its thickness when a longer note brings it. */
+ scrollbar-gutter: stable;
+ }
+}
diff --git a/apps/client/src/widgets/collections/calendar/EventPopover.tsx b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
new file mode 100644
index 0000000000..5d8ce58ce8
--- /dev/null
+++ b/apps/client/src/widgets/collections/calendar/EventPopover.tsx
@@ -0,0 +1,190 @@
+import "./EventPopover.css";
+
+import { useCallback, useEffect, useRef } from "preact/hooks";
+
+import FNote from "../../../entities/fnote";
+import { t } from "../../../services/i18n";
+import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, NoteColorAction, OpenNoteActions, 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 Popover from "../../react/Popover";
+import { removeFromCalendar } from "./api";
+import EventDatesEditor from "./EventDatesEditor";
+import { EventFieldList } from "./EventField";
+import RecurrenceEditor from "./RecurrenceEditor";
+import { AnchorPoint } from "./selection";
+
+/**
+ * The labels the popover already speaks for, so their fields are not repeated in the promoted grid:
+ * the dates the calendar draws the event by, and the recurrence the popover's own field edits.
+ * Only the stock names for now; a calendar naming its own (`calendar:startDate`) still shows those.
+ */
+const EVENT_LABELS = [ "startDate", "endDate", "startTime", "endTime", "recurrence" ];
+
+/**
+ * The whole of an event, in a popover standing beside its chip: the note's title, its own fields —
+ * when it happens, how it repeats — its promoted attributes and its content, each edited exactly as
+ * it is anywhere else (the embedded-note arrangement the geo map's pane makes; see
+ * EmbeddedNotePane). Anchored to the chip that was clicked rather than docked at an edge, so the
+ * grid never reflows and the event is read where it was found.
+ *
+ * One popover for the selection rather than one per event: clicking another chip is a note switch
+ * within a standing popover — the editors hear it and save — with the surface re-anchoring to the
+ * new chip (see the updateKey handed to Popover).
+ */
+export default function EventPopover({ noteId, anchor, container, parentNote, isEditable, onClose }: {
+ noteId: string;
+ /** Where the chip was clicked — which of the event's segments to stand by, and the anchor of
+ * last resort when no chip is on the grid at all (a note just committed from a ghost, whose
+ * chip has yet to be drawn). */
+ anchor: AnchorPoint | null;
+ /** The calendar the chips are read out of (see {@link eventAnchorRect}). */
+ container: HTMLElement | null;
+ /** The calendar's own note, which is how the tree is told what the calendar holds a note by. */
+ parentNote: FNote;
+ /** The calendar may not be edited, which leaves the popover the ways of opening a note and no
+ * more — a calendar root's day notes are not events to be recoloured or taken off it. */
+ isEditable: boolean;
+ onClose(): void;
+}) {
+ const note = useNote(noteId);
+ const { noteContext, component } = useEmbeddedNoteContext(note ?? undefined, POPOVER_NTX_ID);
+
+ /**
+ * Lets the popover 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
+ * mounted, and not waited on. Every way out leads through here; the popover closes at once,
+ * there being no slide to hold the editors up through.
+ */
+ const close = useCallback(() => {
+ void announceEmbeddedNoteClosing(component, POPOVER_NTX_ID);
+ onClose();
+ }, [ component, onClose ]);
+
+ useEffect(() => {
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") close();
+ };
+ window.addEventListener("keydown", onKeyDown);
+ return () => window.removeEventListener("keydown", onKeyDown);
+ }, [ close ]);
+
+ if (!note) {
+ return null;
+ }
+
+ return (
+ <Popover
+ className="calendar-event-popover"
+ placement={glob.isRtl ? "left-start" : "right-start"}
+ getAnchorRect={() => eventAnchorRect(container, noteId, anchor)}
+ updateKey={noteId}
+ onDismiss={close}
+ >
+ <EmbeddedNoteScope component={component} noteContext={noteContext}>
+ <EventDetails note={note} parentNote={parentNote} isEditable={isEditable} onClose={close} />
+ </EmbeddedNoteScope>
+ </Popover>
+ );
+}
+
+/** The popover's own ntxId, as the geo pane and the quick editor have one of their own. */
+const POPOVER_NTX_ID = "_calendar-event-popover";
+
+/** The popover's contents, reading the note out of the context the popover provides. */
+function EventDetails({ note, parentNote, isEditable, onClose }: {
+ note: FNote;
+ parentNote: FNote;
+ isEditable: boolean;
+ onClose(): void;
+}) {
+ // The popover stands for its component in the DOM, which is how the text editor finds its
+ // host — without this it resolves the widget enclosing the calendar instead (see the geo pane).
+ const innerRef = useRef<HTMLDivElement>(null);
+ useLegacyComponentElement(innerRef);
+
+ return (
+ <div className="calendar-event-popover-inner" ref={innerRef}>
+ <div className="calendar-event-popover-header">
+ <TitleRow compact />
+ <ActionButton
+ icon="bx bx-x"
+ text={t("calendar.close_details")}
+ onClick={onClose}
+ />
+ </div>
+
+ <div className="calendar-event-popover-body tn-embedded-note-pane">
+ {/* What can be done with the event: the ways of opening its note (see
+ OpenNoteActions), then the ways of changing it — left out rather than disabled
+ where the calendar may not be edited, as the geo pane leaves them out. */}
+ <EmbeddedNoteActions>
+ <OpenNoteActions note={note} />
+
+ {isEditable && <>
+ {/* Named for the chip it dresses, the colour it sets being worn everywhere
+ the note shows (see NoteColorPicker). */}
+ <NoteColorAction note={note} title={t("calendar_view.event_color")} />
+
+ <ActionButton
+ className="tn-embedded-note-remove"
+ icon="bx bx-trash"
+ text={t("calendar_view.remove_from_calendar")}
+ // Whether the note goes with its event is asked before anything
+ // happens, the two being different wishes. Closed by hand where
+ // something was done: a removed event is still a note of the
+ // collection, so no watcher stands the popover down.
+ onClick={() => void removeFromCalendar(note, parentNote)
+ .then((removed) => removed && onClose())}
+ />
+ </>}
+ </EmbeddedNoteActions>
+
+ {/* The event's own fields — when it happens, how it repeats — which are ways of
+ changing it, so they go where the calendar may be edited: a calendar root's day
+ notes are days, and a day neither moves nor recurs. */}
+ {isEditable && (
+ <EventFieldList>
+ {/* The repeats field is handed to the dates editor to stand beside its
+ all-day switch, the two being the one line of shape-of-the-event
+ switches (see EventDatesEditor). */}
+ <EventDatesEditor note={note} repeats={<RecurrenceEditor note={note} />} />
+ </EventFieldList>
+ )}
+
+ <PromotedAttributes omit={EVENT_LABELS} />
+ <NoteDetail />
+ </div>
+ </div>
+ );
+}
+
+/**
+ * Where the popover stands: beside the event's own chip, read back off the grid by the note id the
+ * chips are tagged with (see eventDidMount in index.tsx). An event crossing rows draws a chip per
+ * row, so the one under the click is the one pointed at, falling back to the first drawn, and to
+ * the bare click point where no chip is on the grid at all. Read afresh on every reposition (see
+ * Popover), so the popover follows the chip through scrolls and redraws.
+ */
+function eventAnchorRect(container: HTMLElement | null, noteId: string, point: AnchorPoint | null): DOMRect {
+ const chips = container?.querySelectorAll<HTMLElement>(`.fc-event[data-event-note-id="${CSS.escape(noteId)}"]`);
+
+ if (chips?.length) {
+ let pick: HTMLElement | undefined;
+ if (point) {
+ for (const el of chips) {
+ const r = el.getBoundingClientRect();
+ if (r.left <= point.x && point.x <= r.right && r.top <= point.y && point.y <= r.bottom) {
+ pick = el;
+ break;
+ }
+ }
+ }
+ return (pick ?? chips[0]).getBoundingClientRect();
+ }
+
+ return new DOMRect(point?.x ?? 0, point?.y ?? 0, 0, 0);
+}
diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.tsx b/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
index b6cf5a802c..a651cd0ed2 100644
--- a/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
@@ -7,7 +7,7 @@ import ActionButton from "../../react/ActionButton";
import Button from "../../react/Button";
import FormTextBox from "../../react/FormTextBox";
import Popover from "../../react/Popover";
-import { EventDraft } from "./DetailDock";
+import { AnchorPoint, EventDraft } from "./selection";
/**
* The ghost: a popover standing beside the dragged-out range, holding the form an event is decided
@@ -28,7 +28,7 @@ export default function GhostPopover({ draft, anchor, container, onCommit, onCan
draft: EventDraft;
/** Where the drag ended, in viewport coordinates — which of the shading's pieces to stand by,
* and the anchor of last resort when the shading cannot be found at all. */
- anchor: { x: number; y: number } | null;
+ anchor: AnchorPoint | null;
/** The calendar the range's shading is read out of (see {@link ghostAnchorRect}). */
container: HTMLElement | null;
onCommit(title: string): void;
@@ -105,7 +105,7 @@ export default function GhostPopover({ draft, anchor, container, onCommit, onCan
* drawn, and to the bare point where no shading is on the grid at all. Read afresh on every
* reposition (see Popover), so the ghost follows the shading through scrolls and redraws.
*/
-function ghostAnchorRect(container: HTMLElement | null, point: { x: number; y: number } | null): DOMRect {
+function ghostAnchorRect(container: HTMLElement | null, point: AnchorPoint | null): DOMRect {
const highlights = container?.querySelectorAll<HTMLElement>(".fc-highlight");
if (highlights?.length) {
diff --git a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
index e8ced332f6..0fa0304067 100644
--- a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
+++ b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx
@@ -27,11 +27,11 @@ import {
/**
* Edits how the event repeats, through the note's `#recurrence` label — structured fields for the
* everyday rules, the raw RRULE string for one saying more than they can (see recurrence.ts for
- * where that line runs). Rendered as {@link EventField} rows, so it stands in the dock's field
- * column beside the start and end dates when those grow editors of their own.
+ * where that line runs). Rendered as {@link EventField} rows, so it stands in the event popover's
+ * field column beside the start and end dates when those grow editors of their own.
*
- * Only the stock label name for now, as the dock reads only the stock names (see EVENT_DATE_LABELS
- * in DetailDock.tsx); a calendar naming its own via `#calendar:recurrence` edits that label by
+ * Only the stock label name for now, as the popover reads only the stock names (see EVENT_LABELS
+ * in EventPopover.tsx); a calendar naming its own via `#calendar:recurrence` edits that label by
* hand.
*/
export default function RecurrenceEditor({ note }: { note: FNote }) {
@@ -55,10 +55,10 @@ export default function RecurrenceEditor({ note }: { note: FNote }) {
setStoredValue(serializeRecurrence(next));
}, [ setStoredValue ]);
- // One row in the dock, the whole rule behind it: the button says what the rule amounts to, and
- // opening it lays the rule out to edit. Kept open through the edits (`autoClose: "outside"`) —
- // a rule is several choices, and the menu going down after the first would make it three trips.
- // Portaled to the body because the dock clips what overflows it (see DetailDock.css).
+ // One row in the popover, the whole rule behind it: the button says what the rule amounts to,
+ // and opening it lays the rule out to edit. Kept open through the edits (`autoClose: "outside"`)
+ // — a rule is several choices, and the menu going down after the first would make it three
+ // trips. Portaled to the body because the popover clips what overflows it (see EventPopover.css).
return (
<EventField name={t("calendar.recurrence.repeats")}>
<Dropdown
diff --git a/apps/client/src/widgets/collections/calendar/index.css b/apps/client/src/widgets/collections/calendar/index.css
index c21a656813..a4fdd802bc 100644
--- a/apps/client/src/widgets/collections/calendar/index.css
+++ b/apps/client/src/widgets/collections/calendar/index.css
@@ -39,18 +39,6 @@
bottom: 0;
}
-/* The calendar and the detail dock side by side, under the properties bar. */
-.calendar-view .calendar-body {
- flex: 1;
- min-height: 0;
- display: flex;
-}
-
-.calendar-view .calendar-main {
- flex: 1;
- min-width: 0;
-}
-
.calendar-container {
height: 100%;
--fc-page-bg-color: var(--main-background-color);
@@ -174,9 +162,9 @@
--border-color: var(--custom-color, var(--input-focus-outline-color));
}
-/* The event the detail dock stands for, marked the way a focused event is. */
-.calendar-view a.fc-timegrid-event.calendar-event-in-dock,
-.calendar-view a.fc-daygrid-event.calendar-event-in-dock {
+/* The event the popover stands for, marked the way a focused event is. */
+.calendar-view a.fc-timegrid-event.calendar-event-selected,
+.calendar-view a.fc-daygrid-event.calendar-event-selected {
--border-color: var(--custom-color, var(--input-focus-outline-color));
}
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index f611b48367..8db6c969bf 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -24,9 +24,10 @@ import { ParentComponent } from "../../react/react_utils";
import { ViewModeProps } from "../interface";
import { changeEvent, newEvent } from "./api";
import Calendar from "./calendar";
-import DetailDock, { DockSelection, EventDraft } from "./DetailDock";
+import EventPopover from "./EventPopover";
import GhostPopover from "./GhostPopover";
import { openCalendarContextMenu } from "./context_menu";
+import { CalendarSelection, EventDraft } from "./selection";
import { buildEvents, buildEventsForCalendar } from "./event_builder";
import { formatDateToLocalISO, isValidDuration, parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
@@ -113,11 +114,10 @@ export const LOCALE_MAPPINGS: Record<DISPLAYABLE_LOCALE_IDS, (() => Promise<{ de
export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarViewData>) {
const parentComponent = useContext(ParentComponent);
const containerRef = useRef<HTMLDivElement>(null);
- const calendarMainRef = useRef<HTMLDivElement>(null);
const calendarRef = useRef<FullCalendar>(null);
- // The event the dock at the trailing edge stands for — a chip clicked, or a note just created
- // by drag-selecting a range (see DockSelection).
- const [ selection, setSelection ] = useState<DockSelection | null>(null);
+ // The event the view's popovers stand for — a chip clicked, or a range just dragged out (see
+ // CalendarSelection).
+ const [ selection, setSelection ] = useState<CalendarSelection | null>(null);
const [ calendarRoot ] = useNoteLabelBoolean(note, "calendarRoot");
const [ workspaceCalendarRoot ] = useNoteLabelBoolean(note, "workspaceCalendarRoot");
@@ -130,9 +130,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
const [ slotLabelInterval ] = useNoteLabel(note, "calendar:slotLabelInterval");
const initialView = useRef(calendarView);
const viewSpacedUpdate = useSpacedUpdate(() => setCalendarView(initialView.current));
- // Observed on the calendar's own wrapper rather than the view root, so the grid also reflows
- // frame by frame while the detail dock slides open or closed beside it.
- useResizeObserver(calendarMainRef, () => calendarRef.current?.updateSize());
+ useResizeObserver(containerRef, () => calendarRef.current?.updateSize());
const isCalendarRoot = (calendarRoot || workspaceCalendarRoot);
const isEditable = !isCalendarRoot;
const eventBuilder = useMemo(() => {
@@ -151,7 +149,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
// Turns the standing ghost into the note: created only now, at the commit, and — where the
// reader typed nothing — named by the calendar's own titleTemplate, the very thing the old
- // title prompt used to override. The dock takes over from the ghost, opening on the new note.
+ // title prompt used to override. The event popover takes over from the ghost, opening on the
+ // new note at the ghost's own anchor — the chip itself has yet to be drawn.
const commitDraft = useCallback(async (title: string) => {
if (!selection || !("draft" in selection)) return;
@@ -161,7 +160,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
componentId: parentComponent?.componentId
});
if (created) {
- setSelection({ noteId: created.noteId });
+ setSelection({ noteId: created.noteId, anchor: selection.anchor });
}
}, [ selection, note, parentComponent?.componentId ]);
@@ -182,9 +181,9 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
}
}, [ isCalendarRoot, selection, noteIds ]);
- // A click on an event opens it into the dock instead of navigating to the popup the event's
- // `url` names. Not on mobile, where a tap is already spoken for (see eventDidMount) and the
- // dock would take the whole of the screen.
+ // A click on an event opens it into the popover instead of navigating to the popup the
+ // event's `url` names. Not on mobile, where a tap is already spoken for (see eventDidMount)
+ // and the popover would take the whole of the screen.
const onEventClick = useCallback((e: EventClickArg) => {
if (isMobile()) return;
@@ -195,7 +194,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
e.jsEvent.stopPropagation();
const noteId = e.event.extendedProps.noteId;
if (noteId) {
- setSelection({ noteId });
+ // The click names which of the event's chips to stand by (see eventAnchorRect).
+ setSelection({ noteId, anchor: { x: e.jsEvent.clientX, y: e.jsEvent.clientY } });
}
}, []);
@@ -228,49 +228,49 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
return (plugins &&
<div className="calendar-view" ref={containerRef} tabIndex={100}>
<CalendarCollectionProperties note={note} calendarRef={calendarRef} />
- <div className="calendar-body">
- <div className="calendar-main" ref={calendarMainRef}>
- <Calendar
- events={eventBuilder}
- calendarRef={calendarRef}
- plugins={plugins}
- initialView={initialView.current && SUPPORTED_CALENDAR_VIEW_TYPE.includes(initialView.current) ? initialView.current : "dayGridMonth"}
- headerToolbar={false}
- firstDay={firstDayOfWeek ?? 0}
- weekends={!hideWeekends}
- weekNumbers={weekNumbers}
- slotDuration={isValidDuration(slotDuration) ? slotDuration : DEFAULT_SLOT_DURATION}
- slotLabelInterval={isValidDuration(slotLabelInterval) ? slotLabelInterval : DEFAULT_SLOT_LABEL_INTERVAL}
- height="100%"
- nowIndicator
- handleWindowResize={false}
- initialDate={initialDate || undefined}
- locale={locale}
- {...editingProps}
- unselectAuto={false}
- eventClick={onEventClick}
- eventClassNames={(arg) => selection && "noteId" in selection && arg.event.extendedProps.noteId === selection.noteId ? [ "calendar-event-in-dock" ] : []}
- eventDidMount={eventDidMount}
- viewDidMount={({ view }) => {
- if (initialView.current !== view.type) {
- initialView.current = view.type;
- viewSpacedUpdate.scheduleUpdate();
- }
- }}
- />
- </div>
- <DetailDock
- selection={selection}
+ <Calendar
+ events={eventBuilder}
+ calendarRef={calendarRef}
+ plugins={plugins}
+ initialView={initialView.current && SUPPORTED_CALENDAR_VIEW_TYPE.includes(initialView.current) ? initialView.current : "dayGridMonth"}
+ headerToolbar={false}
+ firstDay={firstDayOfWeek ?? 0}
+ weekends={!hideWeekends}
+ weekNumbers={weekNumbers}
+ slotDuration={isValidDuration(slotDuration) ? slotDuration : DEFAULT_SLOT_DURATION}
+ slotLabelInterval={isValidDuration(slotLabelInterval) ? slotLabelInterval : DEFAULT_SLOT_LABEL_INTERVAL}
+ height="100%"
+ nowIndicator
+ handleWindowResize={false}
+ initialDate={initialDate || undefined}
+ locale={locale}
+ {...editingProps}
+ unselectAuto={false}
+ eventClick={onEventClick}
+ eventClassNames={(arg) => selection && "noteId" in selection && arg.event.extendedProps.noteId === selection.noteId ? [ "calendar-event-selected" ] : []}
+ eventDidMount={eventDidMount}
+ viewDidMount={({ view }) => {
+ if (initialView.current !== view.type) {
+ initialView.current = view.type;
+ viewSpacedUpdate.scheduleUpdate();
+ }
+ }}
+ />
+ {selection && "noteId" in selection && (
+ <EventPopover
+ noteId={selection.noteId}
+ anchor={selection.anchor}
+ container={containerRef.current}
parentNote={note}
isEditable={isEditable}
onClose={() => setSelection(null)}
/>
- </div>
+ )}
{selection && "draft" in selection && (
<GhostPopover
draft={selection.draft}
anchor={selection.anchor}
- container={calendarMainRef.current}
+ container={containerRef.current}
onCommit={(title) => void commitDraft(title)}
onCancel={() => setSelection(null)}
/>
@@ -477,6 +477,13 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u
const eventDidMount = useCallback((e: EventMountArg) => {
const { iconClass, promotedAttributes } = e.event.extendedProps;
+ // The chip is tagged with its note, which is how the event popover finds the chip to
+ // stand beside — FullCalendar redraws chips at will, so an element held onto would go
+ // stale (see eventAnchorRect in EventPopover).
+ if (e.event.extendedProps.noteId) {
+ e.el.dataset.eventNoteId = String(e.event.extendedProps.noteId);
+ }
+
// Prepend the icon to the title, if any.
if (iconClass) {
let titleContainer: HTMLElement | null = null;
diff --git a/apps/client/src/widgets/collections/calendar/selection.ts b/apps/client/src/widgets/collections/calendar/selection.ts
new file mode 100644
index 0000000000..9e58f1cd9e
--- /dev/null
+++ b/apps/client/src/widgets/collections/calendar/selection.ts
@@ -0,0 +1,31 @@
+/**
+ * An event still being decided on: the range the reader dragged out, standing for a note that does
+ * not exist yet. Nothing is created until the draft is committed (see GhostPopover), so a ghost
+ * dismissed costs nothing — no note to clean up, no tombstone in the sync history.
+ */
+export interface EventDraft {
+ startDate: string;
+ endDate?: string | null;
+ startTime?: string | null;
+ endTime?: string | null;
+}
+
+/** A point in viewport coordinates — where a click or a drag's end fell, anchoring a popover
+ * beside it where nothing better can be found on the grid (see the anchor helpers). */
+export interface AnchorPoint {
+ x: number;
+ y: number;
+}
+
+/**
+ * Which event the view's popovers stand for: the note of a chip clicked, held by the event
+ * popover, or a range just dragged out whose note is yet to be, held by the ghost (see
+ * {@link EventDraft}).
+ *
+ * Owned by the calendar view rather than by either popover, because each is only one of the ways
+ * in, and state a popover kept to itself could not be set from the code that hands selections
+ * over — a committed ghost becomes the event popover's note, at the ghost's own anchor.
+ */
+export type CalendarSelection =
+ | { noteId: string; anchor: AnchorPoint | null }
+ | { draft: EventDraft; anchor: AnchorPoint | null };
diff --git a/apps/client/src/widgets/react/Popover.tsx b/apps/client/src/widgets/react/Popover.tsx
index 5bc043d56b..1dc9ab3893 100644
--- a/apps/client/src/widgets/react/Popover.tsx
+++ b/apps/client/src/widgets/react/Popover.tsx
@@ -1,6 +1,6 @@
import "./Popover.css";
-import { createPopper, Placement, VirtualElement } from "@popperjs/core";
+import { createPopper, Instance, Placement, VirtualElement } from "@popperjs/core";
import clsx from "clsx";
import { ComponentChildren } from "preact";
import { createPortal } from "preact/compat";
@@ -16,6 +16,12 @@ export interface PopoverProps {
getAnchorRect(): DOMRect;
/** Which side of the anchor to stand on, flipped away from the viewport's edges as needed. */
placement?: Placement;
+ /**
+ * Repositions when it changes. Popper watches scrolling and resizing on its own, but cannot
+ * know the anchor moved for a reason of the caller's — the popover switching to stand for
+ * something else, say — which is what this says.
+ */
+ updateKey?: unknown;
className?: string;
/** Called on a press outside the popover; the owner decides what being dismissed means. The
* press itself still lands where it fell — dismissal must not swallow it, or pressing the
@@ -30,8 +36,9 @@ 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, className, onDismiss, children }: PopoverProps) {
+export default function Popover({ getAnchorRect, placement, updateKey, className, onDismiss, children }: PopoverProps) {
const elRef = useRef<HTMLDivElement>(null);
+ const popperRef = useRef<Instance>();
// Held in a ref so the popper built once keeps asking the newest question — rebuilding it on
// every render would reset the positioning mid-interaction.
@@ -52,10 +59,18 @@ export default function Popover({ getAnchorRect, placement, className, onDismiss
{ name: "preventOverflow", options: { padding: 8 } }
]
});
+ popperRef.current = popper;
- return () => popper.destroy();
+ return () => {
+ popperRef.current = undefined;
+ popper.destroy();
+ };
}, [ placement ]);
+ useEffect(() => {
+ void popperRef.current?.update();
+ }, [ updateKey ]);
+
useEffect(() => {
if (!onDismiss) return;