Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(calendar): stand the ghost beside the range it was dragged from
Elian Doran43999837684b
diff --git a/apps/client/package.json b/apps/client/package.jsonindex 8049c9a931..1a6fe3ccf0 100644--- a/apps/client/package.json+++ b/apps/client/package.json@@ -26,6 +26,7 @@"@fullcalendar/rrule": "6.1.21","@fullcalendar/timegrid": "6.1.21","@mermaid-js/layout-elk": "0.2.2",+ "@popperjs/core": "2.11.8","@preact/signals": "2.10.0","@triliumnext/ckeditor5": "workspace:*","@triliumnext/codemirror": "workspace:*",diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.css b/apps/client/src/widgets/collections/calendar/DetailDock.cssindex 0728f02339..db1e1c10d9 100644--- a/apps/client/src/widgets/collections/calendar/DetailDock.css+++ b/apps/client/src/widgets/collections/calendar/DetailDock.css@@ -55,31 +55,4 @@scrollbar-gutter: stable;}- /* The ghost face (see DraftForm): a heading standing where the note's title row will, and the- little there is to say laid down the same column the note's widgets will use. */- .calendar-detail-dock-draft-heading {- flex: 1;- min-width: 0;- padding: 6px 0;- font-weight: 600;- }-- .calendar-detail-dock-draft-body {- display: flex;- flex-direction: column;- gap: 12px;- }-- .calendar-detail-dock-draft-when {- display: flex;- align-items: center;- gap: 6px;- color: var(--muted-text-color);- font-size: 0.9em;- }-- .calendar-detail-dock-draft-actions {- display: flex;- justify-content: flex-end;- }}diff --git a/apps/client/src/widgets/collections/calendar/DetailDock.tsx b/apps/client/src/widgets/collections/calendar/DetailDock.tsxindex dade9e24e9..f574fa59c8 100644--- a/apps/client/src/widgets/collections/calendar/DetailDock.tsx+++ b/apps/client/src/widgets/collections/calendar/DetailDock.tsx@@ -10,8 +10,6 @@ import TitleRow from "../../layout/TitleRow";import NoteDetail from "../../NoteDetail";import PromotedAttributes from "../../PromotedAttributes";import ActionButton from "../../react/ActionButton";-import Button from "../../react/Button";-import FormTextBox from "../../react/FormTextBox";import { useLegacyComponentElement, useNote } from "../../react/hooks";import { removeFromCalendar } from "./api";import EventDatesEditor from "./EventDatesEditor";@@ -27,8 +25,8 @@ const EVENT_LABELS = [ "startDate", "endDate", "startTime", "endTime", "recurren/*** 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 {@link DraftForm}), so a- * ghost dismissed costs nothing — no note to clean up, no tombstone in the sync history.+ * 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;@@ -38,69 +36,55 @@ export interface EventDraft {}/**- * Which event the dock stands for, and why it came to be selected: the note of a chip clicked, or- * a range just dragged out whose note is yet to be (see {@link EventDraft}).+ * 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 the dock, because a click on a chip is not the only- * way in, and state the dock kept to itself could not be set from the code that hands drafts over.+ * 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 };+ | {+ 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, onCommitDraft, onClose }: {- /** The event the dock stands for, or `null` for a dock that is closed. See {@link DockSelection}. */+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;- /** Asks for the standing draft to become a note, under the given title — or, given a blank- * one, under whatever name the calendar's own titleTemplate writes. */- onCommitDraft(title: string): void;onClose(): void;}) {- const draft = selection && "draft" in selection ? selection.draft : null;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 [ shownDraft, setShownDraft ] = useState<EventDraft>();- const open = !!note || !!draft;- // The note keeps the pane until its closing has been announced (the effect below), so the- // editors are still mounted when the announcement is raised — whether the pane is sliding- // shut or a draft is taking it over.+ const open = !!note;const contentNote = note ?? shownNote;- const contentDraft = draft ?? (open ? undefined : shownDraft);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 (draft) {- setShownDraft(draft);- } else if (note) {- // Committed into the note the dock now holds, or moved on from: the form goes at once.- setShownDraft(undefined);+ if (!open && shownNote) {+ void announceEmbeddedNoteClosing(dockComponent, DOCK_NTX_ID);}- }, [ draft, note ]);-- // The editors save through the note context's removal announcement, raised while they are- // still mounted: a closing dock keeps them up through the slide, and a draft taking the pane- // over lets them go only here, once the announcement is out.- useEffect(() => {- if (note || !shownNote) return;-- void announceEmbeddedNoteClosing(dockComponent, DOCK_NTX_ID);- if (draft) setShownNote(undefined);- }, [ note, draft, shownNote, dockComponent ]);+ }, [ open ]);useEffect(() => {if (!open) return;@@ -116,19 +100,14 @@ export default function DetailDock({ selection, parentNote, isEditable, onCommit<divclassName={clsx("calendar-detail-dock", open && "open")}onTransitionEnd={(e) => {- if (!open && e.propertyName === "width") {- setShownNote(undefined);- setShownDraft(undefined);- }+ if (!open && e.propertyName === "width") setShownNote(undefined);}}>- {contentNote ? (+ {contentNote && (<EmbeddedNoteScope component={dockComponent} noteContext={noteContext}><DockContent note={contentNote} parentNote={parentNote} isEditable={isEditable} onClose={onClose} /></EmbeddedNoteScope>- ) : contentDraft ? (- <DraftForm draft={contentDraft} onCommit={onCommitDraft} onCancel={onClose} />- ) : null}+ )}</div>);}@@ -206,94 +185,3 @@ function DockContent({ note, parentNote, isEditable, onClose }: {);}-/**- * The dock's ghost face: the form an event is decided in before its note exists. It asks for the- * one thing the drag did not say — the name — and writes out the one thing it did; everything else- * an event can hold waits for the note, one commit away. Dismissed — Escape, the close button, a- * click that selects something else — the draft simply evaporates: nothing was created.- *- * Committing with the title blank is allowed and meaningful: the note is then named by the- * calendar's own `#titleTemplate` where one is set (see getNewNoteTitle in trilium-core), which- * the old title prompt used to override with whatever stood in its box.- */-function DraftForm({ draft, onCommit, onCancel }: {- draft: EventDraft;- onCommit(title: string): void;- onCancel(): void;-}) {- const [ title, setTitle ] = useState("");- // Committing is asked for once, however many times Enter falls before the note arrives and- // the form goes: each ask would make its own note.- const [ committing, setCommitting ] = useState(false);-- const commit = () => {- if (committing) return;- setCommitting(true);- onCommit(title);- };-- return (- <div className="calendar-detail-dock-inner calendar-detail-dock-draft">- <div className="calendar-detail-dock-header">- <span className="calendar-detail-dock-draft-heading">{t("calendar_view.new_event")}</span>- <ActionButton- className="calendar-detail-dock-close"- icon="bx bx-x"- text={t("calendar.close_details")}- onClick={onCancel}- />- </div>-- <div className="calendar-detail-dock-body calendar-detail-dock-draft-body">- <FormTextBox- autoFocus- currentValue={title}- placeholder={t("calendar_view.draft_title_placeholder")}- onChange={setTitle}- onKeyDown={(e) => {- if (e.key === "Enter") commit();- }}- />-- <div className="calendar-detail-dock-draft-when">- <span className="bx bx-calendar" />- {describeDraft(draft)}- </div>-- <div className="calendar-detail-dock-draft-actions">- <Button- kind="primary"- text={t("calendar_view.create_event")}- disabled={committing}- onClick={commit}- />- </div>- </div>- </div>- );-}--/**- * When the draft happens, written out for the form: the one thing the drag already decided.- * Decorative and short-lived — the note's real date fields take over the moment the draft is- * committed — so the browser's own formatter is enough.- */-function describeDraft({ startDate, endDate, startTime, endTime }: EventDraft) {- // Taken apart by hand: `new Date("2026-08-05")` reads as UTC midnight, which is the evening- // before in half the world's timezones.- const date = (iso: string) => {- const [ year, month, day ] = iso.split("-").map(Number);- return new Date(year, month - 1, day)- .toLocaleDateString(undefined, { weekday: "short", day: "numeric", month: "short", year: "numeric" });- };-- const spansDays = !!endDate && endDate !== startDate;-- if (startTime) {- return spansDays- ? `${date(startDate)}, ${startTime} – ${date(endDate ?? startDate)}, ${endTime ?? ""}`- : `${date(startDate)}, ${startTime}${endTime ? ` – ${endTime}` : ""}`;- }-- return spansDays ? `${date(startDate)} – ${date(endDate ?? startDate)}` : date(startDate);-}diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.css b/apps/client/src/widgets/collections/calendar/GhostPopover.cssnew file mode 100644index 0000000000..66aad8335e--- /dev/null+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.css@@ -0,0 +1,38 @@+.calendar-ghost-popover {+ width: 300px;++ .calendar-ghost-header {+ display: flex;+ align-items: center;+ gap: 4px;+ padding: 4px 9px;+ border-bottom: 1px solid var(--main-border-color);+ }++ .calendar-ghost-heading {+ flex: 1;+ min-width: 0;+ padding: 6px 0;+ font-weight: 600;+ }++ .calendar-ghost-body {+ display: flex;+ flex-direction: column;+ gap: 12px;+ padding: 10px;+ }++ .calendar-ghost-when {+ display: flex;+ align-items: center;+ gap: 6px;+ color: var(--muted-text-color);+ font-size: 0.9em;+ }++ .calendar-ghost-actions {+ display: flex;+ justify-content: flex-end;+ }+}diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.tsx b/apps/client/src/widgets/collections/calendar/GhostPopover.tsxnew file mode 100644index 0000000000..b6cf5a802c--- /dev/null+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.tsx@@ -0,0 +1,149 @@+import "./GhostPopover.css";++import { useEffect, useState } from "preact/hooks";++import { t } from "../../../services/i18n";+import ActionButton from "../../react/ActionButton";+import Button from "../../react/Button";+import FormTextBox from "../../react/FormTextBox";+import Popover from "../../react/Popover";+import { EventDraft } from "./DetailDock";++/**+ * The ghost: a popover standing beside the dragged-out range, holding the form an event is decided+ * in before its note exists. It asks for the one thing the drag did not say — the name — and writes+ * out the one thing it did; everything else an event can hold waits for the note, one commit away.+ * Dismissed — Escape, the close button, a press anywhere else — the draft simply evaporates:+ * nothing was created.+ *+ * A popover rather than the dock, because a draft is born of a place: the form appears beside the+ * range that called for it instead of at the far edge, and the grid does not reflow under the very+ * range just dragged. The dock takes over at the commit, opening on the note the draft became.+ *+ * Committing with the title blank is allowed and meaningful: the note is then named by the+ * calendar's own `#titleTemplate` where one is set (see getNewNoteTitle in trilium-core), which+ * the old title prompt used to override with whatever stood in its box.+ */+export default function GhostPopover({ draft, anchor, container, onCommit, onCancel }: {+ 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;+ /** The calendar the range's shading is read out of (see {@link ghostAnchorRect}). */+ container: HTMLElement | null;+ onCommit(title: string): void;+ onCancel(): void;+}) {+ const [ title, setTitle ] = useState("");+ // Committing is asked for once, however many times Enter falls before the note arrives and+ // the form goes: each ask would make its own note.+ const [ committing, setCommitting ] = useState(false);++ const commit = () => {+ if (committing) return;+ setCommitting(true);+ onCommit(title);+ };++ useEffect(() => {+ const onKeyDown = (e: KeyboardEvent) => {+ if (e.key === "Escape") onCancel();+ };+ window.addEventListener("keydown", onKeyDown);+ return () => window.removeEventListener("keydown", onKeyDown);+ }, [ onCancel ]);++ return (+ <Popover+ className="calendar-ghost-popover"+ placement={glob.isRtl ? "left-start" : "right-start"}+ getAnchorRect={() => ghostAnchorRect(container, anchor)}+ onDismiss={onCancel}+ >+ <div className="calendar-ghost-header">+ <span className="calendar-ghost-heading">{t("calendar_view.new_event")}</span>+ <ActionButton+ icon="bx bx-x"+ text={t("calendar.close_details")}+ onClick={onCancel}+ />+ </div>++ <div className="calendar-ghost-body">+ <FormTextBox+ autoFocus+ currentValue={title}+ placeholder={t("calendar_view.draft_title_placeholder")}+ onChange={setTitle}+ onKeyDown={(e) => {+ if (e.key === "Enter") commit();+ }}+ />++ <div className="calendar-ghost-when">+ <span className="bx bx-calendar" />+ {describeDraft(draft)}+ </div>++ <div className="calendar-ghost-actions">+ <Button+ kind="primary"+ text={t("calendar_view.create_event")}+ disabled={committing}+ onClick={commit}+ />+ </div>+ </div>+ </Popover>+ );+}++/**+ * Where the ghost stands: beside the range's own shading, read back off the grid. FullCalendar+ * draws the selection as one `.fc-highlight` per row it crosses, so the piece under the mouseup is+ * the one pointed at — where the drag ended is where the eye is — falling back to the last piece+ * 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 {+ const highlights = container?.querySelectorAll<HTMLElement>(".fc-highlight");++ if (highlights?.length) {+ let pick: HTMLElement | undefined;+ if (point) {+ for (const el of highlights) {+ 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 ?? highlights[highlights.length - 1]).getBoundingClientRect();+ }++ return new DOMRect(point?.x ?? 0, point?.y ?? 0, 0, 0);+}++/**+ * When the draft happens, written out for the form: the one thing the drag already decided.+ * Decorative and short-lived — the note's real date fields take over the moment the draft is+ * committed — so the browser's own formatter is enough.+ */+function describeDraft({ startDate, endDate, startTime, endTime }: EventDraft) {+ // Taken apart by hand: `new Date("2026-08-05")` reads as UTC midnight, which is the evening+ // before in half the world's timezones.+ const date = (iso: string) => {+ const [ year, month, day ] = iso.split("-").map(Number);+ return new Date(year, month - 1, day)+ .toLocaleDateString(undefined, { weekday: "short", day: "numeric", month: "short", year: "numeric" });+ };++ if (startTime) {+ return endDate && endDate !== startDate+ ? `${date(startDate)}, ${startTime} – ${date(endDate)}, ${endTime ?? ""}`+ : `${date(startDate)}, ${startTime}${endTime ? ` – ${endTime}` : ""}`;+ }++ return endDate && endDate !== startDate ? `${date(startDate)} – ${date(endDate)}` : date(startDate);+}diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex 145bdf1438..f611b48367 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -25,6 +25,7 @@ import { ViewModeProps } from "../interface";import { changeEvent, newEvent } from "./api";import Calendar from "./calendar";import DetailDock, { DockSelection, EventDraft } from "./DetailDock";+import GhostPopover from "./GhostPopover";import { openCalendarContextMenu } from "./context_menu";import { buildEvents, buildEventsForCalendar } from "./event_builder";import { formatDateToLocalISO, isValidDuration, parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";@@ -146,11 +147,11 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarViconst { eventDidMount } = useEventDisplayCustomization(note, parentComponent?.componentId);const editingProps = useEditing(note, isEditable, isCalendarRoot, parentComponent?.componentId,- (draft) => setSelection({ draft }));+ (draft, anchor) => setSelection({ draft, anchor }));// 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.+ // title prompt used to override. The dock takes over from the ghost, opening on the new note.const commitDraft = useCallback(async (title: string) => {if (!selection || !("draft" in selection)) return;@@ -165,7 +166,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi}, [ selection, note, parentComponent?.componentId ]);// The dragged range keeps its shading for as long as the ghost stands for it — unselectAuto is- // off, so pressing into the dock's own form does not clear it — and is let go the moment the+ // off, so pressing into the ghost's own form does not clear it — and is let go the moment the// selection is anything else: committed into a note, moved on from, or gone.useEffect(() => {if (!selection || !("draft" in selection)) {@@ -262,10 +263,18 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarViselection={selection}parentNote={note}isEditable={isEditable}- onCommitDraft={(title) => void commitDraft(title)}onClose={() => setSelection(null)}/></div>+ {selection && "draft" in selection && (+ <GhostPopover+ draft={selection.draft}+ anchor={selection.anchor}+ container={calendarMainRef.current}+ onCommit={(title) => void commitDraft(title)}+ onCancel={() => setSelection(null)}+ />+ )}</div>);}@@ -401,15 +410,16 @@ function useLocale() {}function useEditing(note: FNote, isEditable: boolean, isCalendarRoot: boolean, componentId: string | undefined,- onDraft: (draft: EventDraft) => void) {+ onDraft: (draft: EventDraft, anchor: { x: number; y: number } | null) => void) {const onCalendarSelection = useCallback(async (e: DateSelectArg) => {const { startDate, endDate } = parseStartEndDateFromEvent(e);if (!startDate) return;const { startTime, endTime } = parseStartEndTimeFromEvent(e);- // On a phone the dock does not open (see the event click), so the title is still asked for- // up front, in the dialog this flow always led with. Unselected by hand either way round:- // unselectAuto is off for the ghost's sake, so nothing else clears the drag's shading.+ // On a phone the ghost does not open (see the event click), so the title is still asked+ // for up front, in the dialog this flow always led with. Unselected by hand either way+ // round: unselectAuto is off for the ghost's sake, so nothing else clears the drag's+ // shading.if (isMobile()) {const title = await dialog.prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") });if (title?.trim()) {@@ -419,11 +429,15 @@ function useEditing(note: FNote, isEditable: boolean, isCalendarRoot: boolean, creturn;}- // Nothing is created yet: the range is handed over as a draft for the dock's ghost form,- // and a note is made only when the draft is committed (see commitDraft) — a stray drag- // dismissed costs nothing. The range keeps its shading meanwhile, standing on the grid for- // the event to be; the view lets it go when the draft resolves.- onDraft({ startDate, endDate, startTime, endTime });+ // Nothing is created yet: the range is handed over as a draft for the ghost popover, and a+ // note is made only when the draft is committed (see commitDraft) — a stray drag dismissed+ // costs nothing. The range keeps its shading meanwhile, standing on the grid for the event+ // to be; the view lets it go when the draft resolves. Where the drag ended anchors the+ // ghost beside it (see ghostAnchorRect).+ onDraft(+ { startDate, endDate, startTime, endTime },+ e.jsEvent ? { x: e.jsEvent.clientX, y: e.jsEvent.clientY } : null+ );}, [ note, componentId, onDraft ]);const onEventChange = useCallback(async (e: EventChangeArg) => {diff --git a/apps/client/src/widgets/react/Popover.css b/apps/client/src/widgets/react/Popover.cssnew file mode 100644index 0000000000..5a4586c574--- /dev/null+++ b/apps/client/src/widgets/react/Popover.css@@ -0,0 +1,18 @@+/*+ * The surface an anchored popover is drawn on: the sheet the overlay panels wear (see+ * OverlayPanel.css), stood beside its anchor rather than over a canvas. What it holds and how wide+ * it is are the caller's.+ */+.tn-popover {+ /* Above the note split's own layers; menus and dialogs stand higher still. */+ z-index: 998;+ display: flex;+ flex-direction: column;+ box-sizing: border-box;+ background: var(--menu-background-color);+ color: var(--menu-text-color);+ border: 1px solid var(--dropdown-border-color);+ border-radius: 8px;+ box-shadow: 0 2px 8px #0003;+ backdrop-filter: var(--dropdown-backdrop-filter, blur(10px));+}diff --git a/apps/client/src/widgets/react/Popover.tsx b/apps/client/src/widgets/react/Popover.tsxnew file mode 100644index 0000000000..5bc043d56b--- /dev/null+++ b/apps/client/src/widgets/react/Popover.tsx@@ -0,0 +1,80 @@+import "./Popover.css";++import { createPopper, Placement, VirtualElement } from "@popperjs/core";+import clsx from "clsx";+import { ComponentChildren } from "preact";+import { createPortal } from "preact/compat";+import { useEffect, useRef } from "preact/hooks";++export interface PopoverProps {+ /**+ * Where the popover points: a rectangle in viewport coordinates, asked for afresh on every+ * reposition. A function rather than a rect or an element, so an anchor that is redrawn by+ * whatever it stands on — a canvas re-rendering its selection, say — is followed rather than+ * remembered.+ */+ getAnchorRect(): DOMRect;+ /** Which side of the anchor to stand on, flipped away from the viewport's edges as needed. */+ placement?: Placement;+ 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+ * thing the popover stands beside would take two tries. */+ onDismiss?(): void;+ children: ComponentChildren;+}++/**+ * A small surface anchored beside something — a dragged-out calendar range, a clicked chip —+ * rather than docked at an edge or centred as a dialog. Portaled to the body, so no scroll+ * 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) {+ const elRef = useRef<HTMLDivElement>(null);++ // 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.+ const getRectRef = useRef(getAnchorRect);+ getRectRef.current = getAnchorRect;++ useEffect(() => {+ const el = elRef.current;+ if (!el) return;++ const anchor: VirtualElement = { getBoundingClientRect: () => getRectRef.current() };+ const popper = createPopper(anchor, el, {+ placement: placement ?? "right-start",+ // Fixed, as the element stands in the body rather than beside its anchor.+ strategy: "fixed",+ modifiers: [+ { name: "offset", options: { offset: [ 0, 12 ] } },+ { name: "preventOverflow", options: { padding: 8 } }+ ]+ });++ return () => popper.destroy();+ }, [ placement ]);++ useEffect(() => {+ if (!onDismiss) return;++ const onPointerDown = (e: PointerEvent) => {+ const el = elRef.current;+ if (el && e.target instanceof Node && !el.contains(e.target)) {+ onDismiss();+ }+ };+ // Captured, so the popover hears of the press wherever it lands — including places that+ // stop propagation for reasons of their own.+ document.addEventListener("pointerdown", onPointerDown, true);+ return () => document.removeEventListener("pointerdown", onPointerDown, true);+ }, [ onDismiss ]);++ return createPortal(+ <div ref={elRef} className={clsx("tn-popover", className)}>+ {children}+ </div>,+ document.body+ );+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0cefb2e38c..59c7198d52 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -218,6 +218,9 @@ importers:'@mermaid-js/layout-elk':specifier: 0.2.2version: 0.2.2([email protected])+ '@popperjs/core':+ specifier: 2.11.8+ version: 2.11.8'@preact/signals':specifier: 2.10.0version: 2.10.0([email protected])