@remit/ui 0.0.224 → 0.0.225
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/app-shell-slotted.js +1 -1
- package/dist/components/app-switcher.d.ts +15 -0
- package/dist/components/app-switcher.js +31 -0
- package/dist/components/calendar-event-popup.d.ts +43 -0
- package/dist/components/calendar-event-popup.js +18 -0
- package/dist/components/calendar-event-sidebar.d.ts +34 -0
- package/dist/components/calendar-event-sidebar.js +16 -0
- package/dist/components/calendar-grid.d.ts +8 -7
- package/dist/components/calendar-grid.js +39 -108
- package/dist/components/calendar-popover.d.ts +25 -0
- package/dist/components/calendar-popover.js +84 -0
- package/dist/components/calendar-quick-create.d.ts +35 -0
- package/dist/components/calendar-quick-create.js +26 -0
- package/dist/components/calendar-screen-toolbar.d.ts +30 -0
- package/dist/components/calendar-screen-toolbar.js +24 -0
- package/dist/components/calendar-sheet.d.ts +14 -0
- package/dist/components/calendar-sheet.js +34 -0
- package/dist/components/calendar-side-pane.d.ts +20 -0
- package/dist/components/calendar-side-pane.js +11 -0
- package/dist/components/calendar-time-grid.d.ts +64 -0
- package/dist/components/calendar-time-grid.js +666 -0
- package/dist/components/calendar-toolbar.d.ts +0 -31
- package/dist/components/calendar-toolbar.js +0 -27
- package/dist/components/calendar-year.d.ts +11 -0
- package/dist/components/calendar-year.js +9 -0
- package/dist/components/compose-fab.js +3 -1
- package/dist/components/mini-month.d.ts +19 -0
- package/dist/components/mini-month.js +34 -0
- package/dist/index.d.ts +19 -3
- package/dist/index.js +19 -3
- package/dist/lib/calendar-range.d.ts +10 -0
- package/dist/lib/calendar-range.js +39 -0
- package/dist/lib/calendar-slot-pick.d.ts +29 -0
- package/dist/lib/calendar-slot-pick.js +67 -0
- package/dist/lib/event-drag.d.ts +20 -0
- package/dist/lib/event-drag.js +50 -0
- package/dist/lib/grid-keyboard.d.ts +15 -0
- package/dist/lib/grid-keyboard.js +46 -0
- package/dist/lib/iso-week.d.ts +2 -0
- package/dist/lib/iso-week.js +13 -0
- package/dist/lib/long-press.d.ts +25 -0
- package/dist/lib/long-press.js +37 -0
- package/dist/lib/mini-month.d.ts +27 -0
- package/dist/lib/mini-month.js +33 -0
- package/dist/lib/popup-placement.d.ts +22 -0
- package/dist/lib/popup-placement.js +39 -0
- package/dist/lib/time-grid-layout.d.ts +38 -0
- package/dist/lib/time-grid-layout.js +94 -0
- package/package.json +1 -1
- package/dist/components/event-detail.d.ts +0 -38
- package/dist/components/event-detail.js +0 -21
|
@@ -71,5 +71,5 @@ export function AppShellSlotted({ nav, list, reading, intelligence, intelligence
|
|
|
71
71
|
const share = listShare(listBias, density);
|
|
72
72
|
const contentPanes = (_jsxs(ResizablePanelGroup, { direction: "horizontal", className: "min-h-0 flex-1", children: [_jsx(ResizablePanel, { id: "list", order: 1, defaultSize: showReadingPane ? share.size : 100, minSize: 22, maxSize: showReadingPane ? share.max : 100, className: "min-w-0", children: list }), showReadingPane && (_jsxs(_Fragment, { children: [_jsx(ResizableHandle, {}), _jsx(ResizablePanel, { id: "reading", order: 2, minSize: 29, className: "min-w-0", children: _jsx(WholePixelWidth, { className: "h-full", children: reading }) })] })), showIntelligencePanel && (_jsxs(_Fragment, { children: [_jsx(ResizableHandle, {}), _jsx(ResizablePanel, { id: "intelligence", order: 3, defaultSize: 25, minSize: 18, maxSize: 39, className: "min-w-0", children: intelligence })] }))] }, showReadingPane ? "list-reading" : "list-only"));
|
|
73
73
|
const content = (_jsxs("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", children: [!showNavPane && header && _jsx("div", { className: "shrink-0", children: header }), contentPanes] }));
|
|
74
|
-
return (_jsx(AppShellLayoutCtx.Provider, { value: layoutCtx, children: _jsx("div", { ref: containerRef, className: "safe-area-frame @container flex h-
|
|
74
|
+
return (_jsx(AppShellLayoutCtx.Provider, { value: layoutCtx, children: _jsx("div", { ref: containerRef, className: "safe-area-frame @container flex h-full w-full flex-col overflow-hidden bg-canvas font-sans text-fg", children: isLoading && skeleton ? (skeleton) : (_jsxs(_Fragment, { children: [topBar, navPaneVisible ? (_jsxs(ResizablePanelGroup, { direction: "horizontal", className: "min-h-0 flex-1", children: [_jsx(ResizablePanel, { id: "nav", order: 1, defaultSize: 17, minSize: 12, maxSize: 24, className: "min-w-0", children: nav }), _jsx(ResizableHandle, {}), _jsx(ResizablePanel, { id: "content", order: 2, className: "flex min-w-0 flex-col", children: content })] })) : (content), !showNavPane && (_jsx(Dialog, { open: navOpen, onClose: closeNav, title: "Folders", anchor: "left", children: nav })), overlay] })) }) }));
|
|
75
75
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type AppId = "mail" | "calendar";
|
|
2
|
+
export interface AppSwitchItem {
|
|
3
|
+
id: AppId;
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AppSwitcherProps {
|
|
8
|
+
items: readonly AppSwitchItem[];
|
|
9
|
+
active: AppId;
|
|
10
|
+
/** Runs on a plain click; a modified click follows the link natively. */
|
|
11
|
+
onNavigate: (id: AppId) => void;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function AppBar({ items, active, onNavigate, className, }: AppSwitcherProps): import("react").JSX.Element;
|
|
15
|
+
export declare function AppTabBar({ items, active, onNavigate, className, }: AppSwitcherProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CalendarDays, Mail } from "lucide-react";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { cn } from "../lib/cn.js";
|
|
5
|
+
import { useRovingFocus } from "../lib/roving-focus.js";
|
|
6
|
+
const ICONS = { mail: Mail, calendar: CalendarDays };
|
|
7
|
+
const APP_ITEM_SELECTOR = "[data-app-item]";
|
|
8
|
+
const isPlainClick = (click) => click.button === 0 &&
|
|
9
|
+
!click.metaKey &&
|
|
10
|
+
!click.ctrlKey &&
|
|
11
|
+
!click.shiftKey &&
|
|
12
|
+
!click.altKey;
|
|
13
|
+
function AppLink({ item, active, onNavigate, className, iconClassName, }) {
|
|
14
|
+
const Icon = ICONS[item.id];
|
|
15
|
+
return (_jsxs("a", { href: item.href, "data-app-item": "", "aria-current": active ? "page" : undefined, onClick: (click) => {
|
|
16
|
+
if (!isPlainClick(click))
|
|
17
|
+
return;
|
|
18
|
+
click.preventDefault();
|
|
19
|
+
onNavigate(item.id);
|
|
20
|
+
}, className: cn("flex flex-col items-center justify-center gap-0.5 rounded-lg outline-none transition-colors", "focus-visible:ring-2 focus-visible:ring-ring", active
|
|
21
|
+
? "bg-accent-soft text-accent"
|
|
22
|
+
: "text-fg-muted hover:bg-surface-sunken hover:text-fg", className), children: [_jsx(Icon, { className: iconClassName, "aria-hidden": "true" }), _jsx("span", { className: "text-2xs font-medium", children: item.label })] }));
|
|
23
|
+
}
|
|
24
|
+
export function AppBar({ items, active, onNavigate, className, }) {
|
|
25
|
+
const navRef = useRef(null);
|
|
26
|
+
useRovingFocus({ containerRef: navRef, itemSelector: APP_ITEM_SELECTOR });
|
|
27
|
+
return (_jsx("nav", { ref: navRef, "aria-label": "Apps", className: cn("flex w-16 shrink-0 flex-col items-center gap-1 border-r border-line bg-surface py-2", className), children: items.map((item) => (_jsx(AppLink, { item: item, active: item.id === active, onNavigate: onNavigate, className: "size-14", iconClassName: "size-5" }, item.id))) }));
|
|
28
|
+
}
|
|
29
|
+
export function AppTabBar({ items, active, onNavigate, className, }) {
|
|
30
|
+
return (_jsx("nav", { "aria-label": "Apps", className: cn("flex shrink-0 items-stretch justify-around border-t border-line bg-surface px-2 pt-1 pb-[max(0.25rem,env(safe-area-inset-bottom))]", className), children: items.map((item) => (_jsx(AppLink, { item: item, active: item.id === active, onNavigate: onNavigate, className: "min-h-12 min-w-16 flex-1", iconClassName: "size-5" }, item.id))) }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from "react";
|
|
2
|
+
import type { CalendarColorId } from "./calendar-types.js";
|
|
3
|
+
export interface CalendarFailure {
|
|
4
|
+
text: string;
|
|
5
|
+
reportHref: string;
|
|
6
|
+
onRetry: () => void;
|
|
7
|
+
/** "Try again" unless the way forward is something else. */
|
|
8
|
+
retryLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
/** A failure stated where it happened, with Try again and a prefilled report. */
|
|
11
|
+
export declare function CalendarFailureBlock({ failure, focusRef, }: {
|
|
12
|
+
failure: CalendarFailure;
|
|
13
|
+
focusRef?: Ref<HTMLDivElement>;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
export interface CalendarEventPopupCardProps {
|
|
16
|
+
headingId: string;
|
|
17
|
+
headingRef?: Ref<HTMLHeadingElement>;
|
|
18
|
+
title: string;
|
|
19
|
+
color: CalendarColorId;
|
|
20
|
+
/** "Wednesday, 4 November · 18:00 – 22:00". */
|
|
21
|
+
when: string;
|
|
22
|
+
location: string;
|
|
23
|
+
calendarName: string;
|
|
24
|
+
/** "Busy" or "Free". */
|
|
25
|
+
availability: string;
|
|
26
|
+
/** Absent on a read-only calendar. */
|
|
27
|
+
onEdit?: () => void;
|
|
28
|
+
onDelete?: () => void;
|
|
29
|
+
deleting?: boolean;
|
|
30
|
+
onClose: () => void;
|
|
31
|
+
failure?: CalendarFailure;
|
|
32
|
+
failureRef?: Ref<HTMLDivElement>;
|
|
33
|
+
/** Shown under the details: the recurrence scope question. */
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
/** What the event popup says about one stored event. */
|
|
37
|
+
export declare function CalendarEventPopupCard({ headingId, headingRef, title, color, when, location, calendarName, availability, onEdit, onDelete, deleting, onClose, failure, failureRef, children, }: CalendarEventPopupCardProps): import("react").JSX.Element;
|
|
38
|
+
/** The popup for an event the address names that is no longer stored. */
|
|
39
|
+
export declare function CalendarEventGone({ headingId, onClose, closeRef, }: {
|
|
40
|
+
headingId: string;
|
|
41
|
+
onClose: () => void;
|
|
42
|
+
closeRef?: Ref<HTMLButtonElement>;
|
|
43
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CalendarDays, MapPin, Pencil, Trash2, X } from "lucide-react";
|
|
3
|
+
import { calendarColorClasses } from "../lib/calendar-color.js";
|
|
4
|
+
import { cn } from "../lib/cn.js";
|
|
5
|
+
/** A failure stated where it happened, with Try again and a prefilled report. */
|
|
6
|
+
export function CalendarFailureBlock({ failure, focusRef, }) {
|
|
7
|
+
return (_jsxs("div", { ref: focusRef, role: "alert", tabIndex: -1, className: "flex flex-col gap-2 rounded-md border border-danger/40 bg-danger-soft p-3 text-sm outline-none", children: [_jsx("p", { className: "text-danger", children: failure.text }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("button", { type: "button", onClick: failure.onRetry, className: "rounded-md border border-line bg-surface px-3 py-1 text-sm font-medium hover:bg-surface-sunken focus-visible:ring-2 focus-visible:ring-ring", children: failure.retryLabel ?? "Try again" }), _jsx("a", { href: failure.reportHref, target: "_blank", rel: "noreferrer", className: "text-sm font-medium text-accent hover:underline", children: "Report an issue" })] })] }));
|
|
8
|
+
}
|
|
9
|
+
const iconButton = "flex size-9 items-center justify-center rounded-full text-fg-muted outline-none hover:bg-surface-sunken hover:text-fg focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40";
|
|
10
|
+
/** What the event popup says about one stored event. */
|
|
11
|
+
export function CalendarEventPopupCard({ headingId, headingRef, title, color, when, location, calendarName, availability, onEdit, onDelete, deleting = false, onClose, failure, failureRef, children, }) {
|
|
12
|
+
const hue = calendarColorClasses(color);
|
|
13
|
+
return (_jsxs("div", { className: "flex flex-col gap-3 p-3", children: [_jsxs("div", { className: "flex justify-end gap-1", children: [onEdit && (_jsx("button", { type: "button", "aria-label": "Edit", onClick: onEdit, className: iconButton, children: _jsx(Pencil, { className: "size-4" }) })), onDelete && (_jsx("button", { type: "button", "aria-label": "Delete", onClick: onDelete, disabled: deleting, className: iconButton, children: _jsx(Trash2, { className: "size-4" }) })), _jsx("button", { type: "button", "aria-label": "Close", onClick: onClose, className: iconButton, children: _jsx(X, { className: "size-4" }) })] }), _jsxs("div", { className: "flex gap-3 px-2", children: [_jsx("span", { className: cn("mt-1.5 size-3.5 shrink-0 rounded-sm", hue.solid), "aria-hidden": "true" }), _jsxs("div", { className: "min-w-0", children: [_jsx("h2", { id: headingId, ref: headingRef, tabIndex: -1, className: "text-xl font-normal break-words text-fg outline-none", children: title === "" ? "(No title)" : title }), _jsx("p", { className: "mt-1 text-sm text-fg-muted", children: when })] })] }), _jsxs("dl", { className: "flex flex-col gap-2 px-2 text-sm", children: [location !== "" && (_jsxs("div", { className: "flex gap-3", children: [_jsx("dt", { children: _jsx(MapPin, { className: "size-4 text-fg-subtle", "aria-label": "Location" }) }), _jsx("dd", { className: "min-w-0 break-words", children: location })] })), _jsxs("div", { className: "flex gap-3", children: [_jsx("dt", { children: _jsx(CalendarDays, { className: "size-4 text-fg-subtle", "aria-label": "Calendar" }) }), _jsxs("dd", { children: [calendarName, " \u00B7 ", availability] })] })] }), children, failure && (_jsx(CalendarFailureBlock, { failure: failure, focusRef: failureRef }))] }));
|
|
14
|
+
}
|
|
15
|
+
/** The popup for an event the address names that is no longer stored. */
|
|
16
|
+
export function CalendarEventGone({ headingId, onClose, closeRef, }) {
|
|
17
|
+
return (_jsxs("div", { className: "flex flex-col gap-3 p-4", children: [_jsx("h2", { id: headingId, className: "text-base font-medium text-fg", children: "This event was deleted or moved" }), _jsx("button", { ref: closeRef, type: "button", onClick: onClose, className: "self-end rounded-md border border-line px-3 py-1.5 text-sm font-medium hover:bg-surface-sunken focus-visible:ring-2 focus-visible:ring-ring", children: "Close" })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from "react";
|
|
2
|
+
import { type CalendarFailure } from "./calendar-event-popup.js";
|
|
3
|
+
import type { CalendarDescriptor, EventDraft } from "./calendar-types.js";
|
|
4
|
+
export interface CalendarEventSidebarProps {
|
|
5
|
+
heading: string;
|
|
6
|
+
draft: EventDraft;
|
|
7
|
+
onChange: (draft: EventDraft) => void;
|
|
8
|
+
/** Only the calendars that accept writes. */
|
|
9
|
+
calendars: readonly CalendarDescriptor[];
|
|
10
|
+
/** A stored event stays in its calendar. */
|
|
11
|
+
calendarEditable: boolean;
|
|
12
|
+
repeatEditable: boolean;
|
|
13
|
+
timeZone: string;
|
|
14
|
+
timeZones: readonly string[];
|
|
15
|
+
onTimeZone: (timeZone: string) => void;
|
|
16
|
+
busy: boolean;
|
|
17
|
+
onBusy: (busy: boolean) => void;
|
|
18
|
+
onSave: () => void;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
saving?: boolean;
|
|
21
|
+
/** The save button, "Save" unless the form adds something. */
|
|
22
|
+
saveLabel?: string;
|
|
23
|
+
/** Why the draft cannot be saved yet. */
|
|
24
|
+
problem?: string;
|
|
25
|
+
failure?: CalendarFailure;
|
|
26
|
+
failureRef?: Ref<HTMLDivElement>;
|
|
27
|
+
titleRef?: Ref<HTMLInputElement>;
|
|
28
|
+
/** A phone shows the editor over the whole screen with thumb-sized controls. */
|
|
29
|
+
touch?: boolean;
|
|
30
|
+
/** The scope question or the discard confirm, over the form. */
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
/** The full editor beside the grid, after Google Calendar's event page. */
|
|
34
|
+
export declare function CalendarEventSidebar({ heading, draft, onChange, calendars, calendarEditable, repeatEditable, timeZone, timeZones, onTimeZone, busy, onBusy, onSave, onCancel, saving, saveLabel, problem, failure, failureRef, titleRef, touch, children, }: CalendarEventSidebarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { X } from "lucide-react";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { CalendarFailureBlock, } from "./calendar-event-popup.js";
|
|
5
|
+
import { EventField, EventRepeatField, EventWhenField, endsBeforeStart, } from "./event-editor.js";
|
|
6
|
+
const control = "h-9 w-full rounded-md border border-line bg-surface-sunken px-2 text-sm text-fg outline-none focus-visible:border-line-strong focus-visible:ring-2 focus-visible:ring-ring/30 disabled:opacity-60";
|
|
7
|
+
/** The full editor beside the grid, after Google Calendar's event page. */
|
|
8
|
+
export function CalendarEventSidebar({ heading, draft, onChange, calendars, calendarEditable, repeatEditable, timeZone, timeZones, onTimeZone, busy, onBusy, onSave, onCancel, saving = false, saveLabel = "Save", problem = "", failure, failureRef, titleRef, touch = false, children, }) {
|
|
9
|
+
const field = cn(control, touch && "h-11");
|
|
10
|
+
const backwards = endsBeforeStart(draft);
|
|
11
|
+
return (_jsxs("form", { "aria-label": heading, "data-event-sidebar": "", className: "flex h-full min-h-0 flex-col bg-surface", onSubmit: (event) => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
if (!saving && !backwards)
|
|
14
|
+
onSave();
|
|
15
|
+
}, children: [_jsxs("div", { className: "flex shrink-0 items-center justify-between border-b border-line px-4 py-2", children: [_jsx("h2", { className: "text-base font-medium text-fg", children: heading }), _jsx("button", { type: "button", "aria-label": "Close", onClick: onCancel, className: cn("flex items-center justify-center rounded-full text-fg-muted outline-none hover:bg-surface-sunken focus-visible:ring-2 focus-visible:ring-ring", touch ? "size-11" : "size-8"), children: _jsx(X, { className: "size-4" }) })] }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 py-4", children: [_jsx("input", { ref: titleRef, "aria-label": "Title", placeholder: "Add title", value: draft.title, onChange: (event) => onChange({ ...draft, title: event.target.value }), className: "border-b-2 border-line bg-transparent pb-1 text-xl text-fg outline-none placeholder:text-fg-subtle focus:border-accent" }), _jsx(EventWhenField, { draft: draft, onChange: onChange, touch: touch }), _jsx(EventField, { label: "Time zone", children: _jsx("select", { "aria-label": "Time zone", value: timeZone, onChange: (event) => onTimeZone(event.target.value), className: field, children: timeZones.map((zone) => (_jsx("option", { value: zone, children: zone }, zone))) }) }), _jsx(EventField, { label: "Repeat", children: _jsx(EventRepeatField, { draft: draft, onChange: onChange, touch: touch, repeatEditable: repeatEditable }) }), _jsx(EventField, { label: "Calendar", children: _jsx("select", { "aria-label": "Calendar", value: draft.calendarId, disabled: !calendarEditable, onChange: (event) => onChange({ ...draft, calendarId: event.target.value }), className: field, children: calendars.map((calendar) => (_jsx("option", { value: calendar.id, children: calendar.name }, calendar.id))) }) }), _jsx(EventField, { label: "Location", children: _jsx("input", { "aria-label": "Location", placeholder: "Add location", value: draft.location, onChange: (event) => onChange({ ...draft, location: event.target.value }), className: field }) }), _jsx(EventField, { label: "Show as", children: _jsxs("select", { "aria-label": "Show as", value: busy ? "busy" : "free", onChange: (event) => onBusy(event.target.value === "busy"), className: field, children: [_jsx("option", { value: "busy", children: "Busy" }), _jsx("option", { value: "free", children: "Free" })] }) }), _jsx(EventField, { label: "Description", children: _jsx("textarea", { "aria-label": "Description", placeholder: "Add description", rows: 5, value: draft.notes, onChange: (event) => onChange({ ...draft, notes: event.target.value }), className: "w-full rounded-md border border-line bg-surface-sunken px-3 py-2 text-sm text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring/30" }) }), children] }), _jsxs("div", { className: "flex shrink-0 flex-col gap-2 border-t border-line px-4 py-3", children: [problem !== "" && (_jsx("p", { role: "alert", className: "text-sm text-danger", children: problem })), failure && (_jsx(CalendarFailureBlock, { failure: failure, focusRef: failureRef })), _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx("button", { type: "button", onClick: onCancel, className: cn("rounded-md border border-line px-4 text-sm font-medium hover:bg-surface-sunken focus-visible:ring-2 focus-visible:ring-ring", touch ? "min-h-11" : "h-9"), children: "Cancel" }), _jsx("button", { type: "submit", disabled: saving || backwards, className: cn("rounded-md bg-accent px-5 text-sm font-medium text-accent-fg hover:bg-accent-hover focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50", touch ? "min-h-11" : "h-9"), children: saving ? "Saving…" : saveLabel })] })] })] }));
|
|
16
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import "../calendar.css";
|
|
2
2
|
import type { Density } from "./app-shell-types.js";
|
|
3
|
-
import type { CalendarColorId, CalendarEventData, CalendarSlotPick
|
|
3
|
+
import type { CalendarColorId, CalendarEventData, CalendarSlotPick } from "./calendar-types.js";
|
|
4
4
|
export interface CalendarGridProps {
|
|
5
|
-
|
|
6
|
-
/** The day the view is centred on; changing it moves the grid. */
|
|
5
|
+
/** A day in the month on screen; changing it moves the grid. */
|
|
7
6
|
date: string;
|
|
8
7
|
events: CalendarEventData[];
|
|
9
8
|
/** Which calendar owns which hue. Anything missing falls back to cal-1. */
|
|
@@ -12,14 +11,16 @@ export interface CalendarGridProps {
|
|
|
12
11
|
selectedEventId: string;
|
|
13
12
|
/** IANA zone the grid's clock runs on, and the zone a pick is read in. */
|
|
14
13
|
timeZone: string;
|
|
15
|
-
/** The instant the grid calls now: the today marker
|
|
14
|
+
/** The instant the grid calls now: the today marker reads it. */
|
|
16
15
|
now: string;
|
|
17
16
|
onSelectEvent: (eventId: string) => void;
|
|
18
17
|
onPickSlot: (pick: CalendarSlotPick) => void;
|
|
19
|
-
/** The range title the grid computed, e.g. "8 – 14 Jun 2026". */
|
|
20
|
-
onRangeChange: (title: string) => void;
|
|
21
18
|
dayHref: (date: string) => string;
|
|
22
19
|
onZoomDay: (date: string) => void;
|
|
20
|
+
/** Whether an event may be dragged to other days; its calendar takes writes. */
|
|
21
|
+
canMove?: (eventId: string) => boolean;
|
|
22
|
+
/** A stored event dropped on other days, or stretched across more. */
|
|
23
|
+
onMoveEvent?: (eventId: string, range: CalendarSlotPick) => void;
|
|
23
24
|
className?: string;
|
|
24
25
|
}
|
|
25
|
-
export declare function CalendarGrid({
|
|
26
|
+
export declare function CalendarGrid({ date, events, colorByCalendarId, density, selectedEventId, timeZone, now, onSelectEvent, onPickSlot, dayHref, onZoomDay, canMove, onMoveEvent, className, }: CalendarGridProps): import("react").JSX.Element;
|
|
@@ -3,58 +3,21 @@ import "../calendar.css";
|
|
|
3
3
|
import FullCalendar from "@fullcalendar/react";
|
|
4
4
|
import dayGridPlugin from "@fullcalendar/react/daygrid";
|
|
5
5
|
import interactionPlugin from "@fullcalendar/react/interaction";
|
|
6
|
-
import listPlugin from "@fullcalendar/react/list";
|
|
7
|
-
import multiMonthPlugin from "@fullcalendar/react/multimonth";
|
|
8
|
-
import timeGridPlugin from "@fullcalendar/react/timegrid";
|
|
9
6
|
import { useEffect, useMemo, useRef } from "react";
|
|
10
7
|
import { calendarEventBodyClasses } from "../lib/calendar-event-shell.js";
|
|
11
8
|
import { isDraggedSelection, pointPick, rangePick, } from "../lib/calendar-slot-pick.js";
|
|
12
9
|
import { cn } from "../lib/cn.js";
|
|
13
10
|
import { CalendarEventChipContent } from "./calendar-event-chip-content.js";
|
|
14
11
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `*Class` props, so no rule here overrides one of the library's own.
|
|
12
|
+
* A month of days, drawn by the calendar engine and styled entirely through
|
|
13
|
+
* its per-element `*Class` props. The day and the week are the kit's own time
|
|
14
|
+
* grid (`CalendarTimeGrid`); only the month uses the engine.
|
|
19
15
|
*
|
|
20
16
|
* The component is presentational. It holds no events of its own, reads no
|
|
21
17
|
* clock of its own, and every gesture leaves through a callback.
|
|
22
18
|
*/
|
|
23
|
-
const PLUGINS = [
|
|
24
|
-
|
|
25
|
-
timeGridPlugin,
|
|
26
|
-
listPlugin,
|
|
27
|
-
multiMonthPlugin,
|
|
28
|
-
interactionPlugin,
|
|
29
|
-
];
|
|
30
|
-
const FC_VIEW = {
|
|
31
|
-
year: "multiMonthYear",
|
|
32
|
-
month: "dayGridMonth",
|
|
33
|
-
week: "timeGridWeek",
|
|
34
|
-
day: "timeGridDay",
|
|
35
|
-
agenda: "listWeek",
|
|
36
|
-
};
|
|
37
|
-
/* A week or a day names the date in its header. A month grid repeats the same
|
|
38
|
-
seven weekdays down the page, so the header names the weekday and the cells
|
|
39
|
-
own the dates; a year has room for one letter. */
|
|
40
|
-
const DAY_HEADER_FORMAT = {
|
|
41
|
-
year: { weekday: "narrow" },
|
|
42
|
-
month: { weekday: "short" },
|
|
43
|
-
week: { weekday: "short", day: "numeric" },
|
|
44
|
-
day: { weekday: "short", day: "numeric" },
|
|
45
|
-
agenda: { weekday: "short", day: "numeric" },
|
|
46
|
-
};
|
|
47
|
-
/** Views that draw every event as a horizontal pill rather than a block. */
|
|
48
|
-
const ROW_VIEWS = new Set(["year", "month", "agenda"]);
|
|
49
|
-
/**
|
|
50
|
-
* Density is a real change in how much of a day fits on screen, not a padding
|
|
51
|
-
* tweak: a tighter setting halves the slot height and drops the time off short
|
|
52
|
-
* chips.
|
|
53
|
-
*/
|
|
54
|
-
const DENSITY = {
|
|
55
|
-
comfortable: { slotMinutes: 30, slotMinHeight: 26, eventShortHeight: 34 },
|
|
56
|
-
compact: { slotMinutes: 60, slotMinHeight: 15, eventShortHeight: 22 },
|
|
57
|
-
};
|
|
19
|
+
const PLUGINS = [dayGridPlugin, interactionPlugin];
|
|
20
|
+
const MAX_EVENTS = { comfortable: 3, compact: 2 };
|
|
58
21
|
const FALLBACK_COLOR = "cal-1";
|
|
59
22
|
/** The placeholder the engine drags under the pointer, which is not one of ours. */
|
|
60
23
|
const MIRROR_EVENT = {
|
|
@@ -65,15 +28,6 @@ const MIRROR_EVENT = {
|
|
|
65
28
|
isRecurring: false,
|
|
66
29
|
zoneCertainty: "local",
|
|
67
30
|
};
|
|
68
|
-
function toInput(event) {
|
|
69
|
-
return {
|
|
70
|
-
id: event.id,
|
|
71
|
-
title: event.title,
|
|
72
|
-
start: event.start,
|
|
73
|
-
end: event.end,
|
|
74
|
-
allDay: event.allDay,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
31
|
const isoDayInZone = (instant, timeZone) => new Intl.DateTimeFormat("en-CA", {
|
|
78
32
|
timeZone,
|
|
79
33
|
year: "numeric",
|
|
@@ -85,15 +39,23 @@ const isModifiedClick = (click) => click.button !== 0 ||
|
|
|
85
39
|
click.ctrlKey ||
|
|
86
40
|
click.shiftKey ||
|
|
87
41
|
click.altKey;
|
|
88
|
-
export function CalendarGrid({
|
|
42
|
+
export function CalendarGrid({ date, events, colorByCalendarId, density, selectedEventId, timeZone, now, onSelectEvent, onPickSlot, dayHref, onZoomDay, canMove = () => false, onMoveEvent, className, }) {
|
|
89
43
|
const calendarRef = useRef(null);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
calendarRef.current?.getApi().changeView(FC_VIEW[view]);
|
|
92
|
-
}, [view]);
|
|
93
44
|
useEffect(() => {
|
|
94
45
|
calendarRef.current?.getApi().gotoDate(date);
|
|
95
46
|
}, [date]);
|
|
96
|
-
const eventInputs = useMemo(() => events.map(
|
|
47
|
+
const eventInputs = useMemo(() => events.map((event) => ({
|
|
48
|
+
id: event.id,
|
|
49
|
+
title: event.title,
|
|
50
|
+
start: event.start,
|
|
51
|
+
end: event.end,
|
|
52
|
+
allDay: event.allDay,
|
|
53
|
+
editable: onMoveEvent !== undefined && canMove(event.id),
|
|
54
|
+
})), [events, canMove, onMoveEvent]);
|
|
55
|
+
const dropped = (info) => {
|
|
56
|
+
info.revert();
|
|
57
|
+
onMoveEvent?.(info.event.id, rangePick(info.event.startStr, info.event.endStr === "" ? info.event.startStr : info.event.endStr, info.event.allDay));
|
|
58
|
+
};
|
|
97
59
|
const byId = useMemo(() => new Map(events.map((event) => [
|
|
98
60
|
event.id,
|
|
99
61
|
{
|
|
@@ -105,36 +67,11 @@ export function CalendarGrid({ view, date, events, colorByCalendarId, density, s
|
|
|
105
67
|
zoneCertainty: event.zoneCertainty,
|
|
106
68
|
},
|
|
107
69
|
])), [events, colorByCalendarId]);
|
|
108
|
-
const lookup =
|
|
109
|
-
|
|
110
|
-
/* The event element the engine built, dressed as the body of a
|
|
111
|
-
`CalendarEventChip`: same box, same hue, same states, one definition. A
|
|
112
|
-
grid cell is tight whatever the density does to the slots around it. */
|
|
113
|
-
const eventBody = useMemo(() => (info) => {
|
|
114
|
-
const event = lookup(info.event.id);
|
|
115
|
-
const isRow = isRowEvent(info);
|
|
116
|
-
return cn(calendarEventBodyClasses({
|
|
117
|
-
color: event.color,
|
|
118
|
-
layout: isRow ? "row" : "column",
|
|
119
|
-
density: "compact",
|
|
120
|
-
rsvp: event.rsvp,
|
|
121
|
-
status: event.status,
|
|
122
|
-
selected: info.event.id === selectedEventId,
|
|
123
|
-
stacked: false,
|
|
124
|
-
}), "cursor-pointer outline-none transition-colors", "focus-visible:ring-2 focus-visible:ring-ring",
|
|
125
|
-
/* Tighter than a chip drawn on its own: a grid cell is smaller than
|
|
126
|
-
anywhere else an event lands, and an all-day pill has to fit a band
|
|
127
|
-
one line high. */
|
|
128
|
-
isRow ? "my-px px-1 py-0" : "px-1 py-0.5");
|
|
129
|
-
}, [lookup, isRowEvent, selectedEventId]);
|
|
130
|
-
const slot = DENSITY[density];
|
|
131
|
-
const isTight = density === "compact";
|
|
132
|
-
return (_jsx("div", { "data-testid": "calendar-grid", className: cn("h-full min-h-0 w-full text-fg", className), children: _jsx(FullCalendar, { ref: calendarRef, plugins: PLUGINS, initialView: FC_VIEW[view], initialDate: date, now: now, timeZone: timeZone, height: "100%", headerToolbar: false, firstDay: 1, fixedWeekCount: false, nowIndicator: true, selectable: true, selectMirror: true, editable: false,
|
|
70
|
+
const lookup = (id) => byId.get(id) ?? MIRROR_EVENT;
|
|
71
|
+
return (_jsx("div", { "data-testid": "calendar-grid", className: cn("h-full min-h-0 w-full text-fg", className), children: _jsx(FullCalendar, { ref: calendarRef, plugins: PLUGINS, initialView: "dayGridMonth", initialDate: date, now: now, timeZone: timeZone, height: "100%", headerToolbar: false, firstDay: 1, fixedWeekCount: false, selectable: true, editable: false,
|
|
133
72
|
/* Events take focus and answer Enter, the way the toolbar's controls
|
|
134
73
|
do — the grid is not reachable by pointer only. */
|
|
135
|
-
eventInteractive: true, expandRows: true,
|
|
136
|
-
if (view !== "month")
|
|
137
|
-
return;
|
|
74
|
+
eventInteractive: true, expandRows: true, dayMaxEvents: MAX_EVENTS[density], dayCellTopContent: (info) => {
|
|
138
75
|
const day = isoDayInZone(info.date, timeZone);
|
|
139
76
|
return (_jsx("a", { href: dayHref(day), "aria-label": `Open ${info.date.toLocaleDateString("en-GB", { dateStyle: "full", timeZone })}`, className: "hover:underline", onClick: (click) => {
|
|
140
77
|
if (isModifiedClick(click))
|
|
@@ -143,8 +80,6 @@ export function CalendarGrid({ view, date, events, colorByCalendarId, density, s
|
|
|
143
80
|
onZoomDay(day);
|
|
144
81
|
}, children: Number(day.slice(8)) }));
|
|
145
82
|
}, dayCellDidMount: (info) => {
|
|
146
|
-
if (view !== "month")
|
|
147
|
-
return;
|
|
148
83
|
/* The engine hides a day number from assistive tech unless it is its
|
|
149
84
|
own nav link, and a link inside a hidden wrapper is unreachable. */
|
|
150
85
|
info.el
|
|
@@ -157,33 +92,29 @@ export function CalendarGrid({ view, date, events, colorByCalendarId, density, s
|
|
|
157
92
|
for (const type of ["mousedown", "touchstart", "pointerdown"]) {
|
|
158
93
|
link?.addEventListener(type, (press) => press.stopPropagation());
|
|
159
94
|
}
|
|
160
|
-
}, moreLinkClick: "popover", moreLinkText: (num) => `+${num}`,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
land. A dragged range is `select`'s.
|
|
166
|
-
|
|
167
|
-
Acting on both would report a point twice, and the second report
|
|
168
|
-
arrives late — the library finishes a click a task after the pointer
|
|
169
|
-
is up — by which time the pane the first report opened has rebuilt
|
|
170
|
-
the grid and left the second reading a detached cell. */
|
|
95
|
+
}, moreLinkClick: "popover", moreLinkText: (num) => `+${num}`, displayEventEnd: false, eventTimeFormat: { hour: "2-digit", minute: "2-digit", hour12: false }, dayHeaderFormat: { weekday: "short" }, events: eventInputs, eventClick: (info) => onSelectEvent(info.event.id), eventDrop: dropped, eventResize: dropped, eventDidMount: (info) => {
|
|
96
|
+
info.el.setAttribute("data-event-id", info.event.id);
|
|
97
|
+
},
|
|
98
|
+
/* A point is `dateClick`'s and a dragged run of days is `select`'s;
|
|
99
|
+
acting on both would report a point twice. */
|
|
171
100
|
dateClick: (info) => onPickSlot(pointPick(info.dateStr, info.allDay)), select: (info) => {
|
|
172
|
-
if (!isDraggedSelection(info.startStr, info.endStr,
|
|
173
|
-
/* The point reading is answering this one. Left alone the
|
|
174
|
-
selection would stay lit under the draft, a slot wide where
|
|
175
|
-
the draft is an hour, until a click somewhere else. */
|
|
101
|
+
if (!isDraggedSelection(info.startStr, info.endStr, true, 0)) {
|
|
176
102
|
info.view.calendar.unselect();
|
|
177
103
|
return;
|
|
178
104
|
}
|
|
179
|
-
onPickSlot(rangePick(info.startStr, info.endStr,
|
|
180
|
-
},
|
|
105
|
+
onPickSlot(rangePick(info.startStr, info.endStr, true));
|
|
106
|
+
},
|
|
181
107
|
/* ---- chrome, all of it ours ---- */
|
|
182
|
-
viewClass: "bg-surface", tableClass: "border-line", tableHeaderClass: "bg-surface", fillerClass: "border-line", dayHeaderRowClass: "h-pane-header", dayHeaderClass: (info) => cn("border-b border-line bg-surface", info.isToday ? "text-accent" : "text-fg-subtle"), dayHeaderInnerClass: "px-1 py-1 text-2xs font-semibold uppercase tracking-wider", dayHeaderDividerClass: "border-b border-line", dayCellClass: (info) => cn("border-line", info.isOther && "bg-surface-sunken"),
|
|
108
|
+
viewClass: "bg-surface", tableClass: "border-line", tableHeaderClass: "bg-surface", fillerClass: "border-line", dayHeaderRowClass: "h-pane-header", dayHeaderClass: (info) => cn("border-b border-line bg-surface", info.isToday ? "text-accent" : "text-fg-subtle"), dayHeaderInnerClass: "px-1 py-1 text-2xs font-semibold uppercase tracking-wider", dayHeaderDividerClass: "border-b border-line", dayCellClass: (info) => cn("border-line", info.isOther && "bg-surface-sunken"), dayCellTopInnerClass: (info) => cn("px-1 py-0.5 text-2xs tabular-nums", info.isToday ? "font-semibold text-accent" : "text-fg-muted"), dayRowClass: "border-line", highlightClass: "bg-accent-soft", moreLinkClass: "rounded-sm bg-surface-sunken text-2xs font-semibold text-fg-muted hover:bg-line hover:text-fg", moreLinkInnerClass: "px-1 py-0.5", popoverClass: "rounded-lg border border-line bg-surface-raised shadow-xl shadow-black/20", popoverCloseClass: "text-fg-subtle hover:text-fg", eventClass: (info) => cn(calendarEventBodyClasses({
|
|
109
|
+
color: lookup(info.event.id).color,
|
|
110
|
+
layout: "row",
|
|
111
|
+
density: "compact",
|
|
112
|
+
rsvp: lookup(info.event.id).rsvp,
|
|
113
|
+
status: lookup(info.event.id).status,
|
|
114
|
+
selected: info.event.id === selectedEventId,
|
|
115
|
+
stacked: false,
|
|
116
|
+
}), "my-px cursor-pointer px-1 py-0 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring"), eventContent: (info) => {
|
|
183
117
|
const event = lookup(info.event.id);
|
|
184
|
-
|
|
185
|
-
both — the title is the one worth keeping. */
|
|
186
|
-
const showTime = info.timeText !== "" && !isTight && !info.isNarrow;
|
|
187
|
-
return (_jsx(CalendarEventChipContent, { title: info.event.title, timeText: showTime ? info.timeText : "", layout: isRowEvent(info) ? "row" : "column", rsvp: event.rsvp, hasThread: event.hasThread, isRecurring: event.isRecurring, zoneCertainty: event.zoneCertainty }));
|
|
118
|
+
return (_jsx(CalendarEventChipContent, { title: info.event.title, timeText: density === "compact" ? "" : info.timeText, layout: "row", rsvp: event.rsvp, hasThread: event.hasThread, isRecurring: event.isRecurring, zoneCertainty: event.zoneCertainty }));
|
|
188
119
|
} }) }));
|
|
189
120
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type PointerEvent, type ReactNode, type Ref } from "react";
|
|
2
|
+
export interface CalendarPopoverProps {
|
|
3
|
+
/**
|
|
4
|
+
* What the popover sits beside, or a selector for it read after each render;
|
|
5
|
+
* null or out of view centres it.
|
|
6
|
+
*/
|
|
7
|
+
anchor: HTMLElement | string | null;
|
|
8
|
+
/** Changes whenever the anchor moves, so the popover follows it. */
|
|
9
|
+
anchorKey: string;
|
|
10
|
+
labelledBy: string;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/** A header drag moves the popover and leaves the anchor alone. */
|
|
13
|
+
header?: (dragHandle: {
|
|
14
|
+
onPointerDown: (event: PointerEvent<HTMLElement>) => void;
|
|
15
|
+
}) => ReactNode;
|
|
16
|
+
/** Tab wraps inside the popover, which traps nothing else. */
|
|
17
|
+
wrapTab?: boolean;
|
|
18
|
+
panelRef?: Ref<HTMLDivElement>;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A floating card beside a range or an event on the calendar grid: a
|
|
23
|
+
* non-modal `dialog`, placed on the side with room.
|
|
24
|
+
*/
|
|
25
|
+
export declare function CalendarPopover({ anchor, anchorKey, labelledBy, children, header, wrapTab, panelRef, className, }: CalendarPopoverProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef, useState, } from "react";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { placePopup } from "../lib/popup-placement.js";
|
|
5
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
6
|
+
/**
|
|
7
|
+
* A floating card beside a range or an event on the calendar grid: a
|
|
8
|
+
* non-modal `dialog`, placed on the side with room.
|
|
9
|
+
*/
|
|
10
|
+
export function CalendarPopover({ anchor, anchorKey, labelledBy, children, header, wrapTab = false, panelRef, className, }) {
|
|
11
|
+
const ownRef = useRef(null);
|
|
12
|
+
const [placement, setPlacement] = useState(null);
|
|
13
|
+
const [offset, setOffset] = useState({ key: anchorKey, x: 0, y: 0 });
|
|
14
|
+
const shift = offset.key === anchorKey ? offset : { x: 0, y: 0 };
|
|
15
|
+
useLayoutEffect(() => {
|
|
16
|
+
const panel = ownRef.current;
|
|
17
|
+
if (!panel || anchorKey === "")
|
|
18
|
+
return;
|
|
19
|
+
const place = () => {
|
|
20
|
+
const element = typeof anchor === "string"
|
|
21
|
+
? document.querySelector(anchor)
|
|
22
|
+
: anchor;
|
|
23
|
+
const rect = element?.getBoundingClientRect();
|
|
24
|
+
setPlacement(placePopup(rect
|
|
25
|
+
? {
|
|
26
|
+
left: rect.left,
|
|
27
|
+
top: rect.top,
|
|
28
|
+
width: rect.width,
|
|
29
|
+
height: rect.height,
|
|
30
|
+
}
|
|
31
|
+
: null, { width: panel.offsetWidth, height: panel.offsetHeight }, { width: window.innerWidth, height: window.innerHeight }));
|
|
32
|
+
};
|
|
33
|
+
place();
|
|
34
|
+
window.addEventListener("resize", place);
|
|
35
|
+
return () => window.removeEventListener("resize", place);
|
|
36
|
+
}, [anchor, anchorKey]);
|
|
37
|
+
const startDrag = (event) => {
|
|
38
|
+
if (event.button !== 0)
|
|
39
|
+
return;
|
|
40
|
+
if (event.target instanceof Element &&
|
|
41
|
+
event.target.closest("button, input, select, a"))
|
|
42
|
+
return;
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
const from = { x: event.clientX - shift.x, y: event.clientY - shift.y };
|
|
45
|
+
const move = (moved) => setOffset({
|
|
46
|
+
key: anchorKey,
|
|
47
|
+
x: moved.clientX - from.x,
|
|
48
|
+
y: moved.clientY - from.y,
|
|
49
|
+
});
|
|
50
|
+
const stop = () => {
|
|
51
|
+
window.removeEventListener("pointermove", move);
|
|
52
|
+
window.removeEventListener("pointerup", stop);
|
|
53
|
+
};
|
|
54
|
+
window.addEventListener("pointermove", move);
|
|
55
|
+
window.addEventListener("pointerup", stop);
|
|
56
|
+
};
|
|
57
|
+
const onKeyDown = (event) => {
|
|
58
|
+
if (!wrapTab || event.key !== "Tab")
|
|
59
|
+
return;
|
|
60
|
+
const items = Array.from(event.currentTarget.querySelectorAll(FOCUSABLE));
|
|
61
|
+
if (items.length === 0)
|
|
62
|
+
return;
|
|
63
|
+
const first = items[0];
|
|
64
|
+
const last = items[items.length - 1];
|
|
65
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
last.focus();
|
|
68
|
+
}
|
|
69
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
first.focus();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (_jsxs("div", { ref: (node) => {
|
|
75
|
+
ownRef.current = node;
|
|
76
|
+
if (typeof panelRef === "function")
|
|
77
|
+
panelRef(node);
|
|
78
|
+
else if (panelRef)
|
|
79
|
+
panelRef.current = node;
|
|
80
|
+
}, role: "dialog", "aria-modal": "false", "aria-labelledby": labelledBy, "data-calendar-popover": "", onKeyDown: onKeyDown, className: cn("fixed z-40 w-[26rem] max-w-[calc(100vw-1rem)] rounded-xl border border-line bg-surface-raised text-fg shadow-xl shadow-black/20", placement === null && "opacity-0", className), style: {
|
|
81
|
+
left: (placement?.left ?? 0) + shift.x,
|
|
82
|
+
top: (placement?.top ?? 0) + shift.y,
|
|
83
|
+
}, children: [header?.({ onPointerDown: startDrag }), children] }));
|
|
84
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PointerEvent, Ref } from "react";
|
|
2
|
+
import { type CalendarFailure } from "./calendar-event-popup.js";
|
|
3
|
+
import type { CalendarDescriptor, CalendarSlotPick } from "./calendar-types.js";
|
|
4
|
+
export interface QuickCreateFields {
|
|
5
|
+
title: string;
|
|
6
|
+
range: CalendarSlotPick;
|
|
7
|
+
location: string;
|
|
8
|
+
calendarId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CalendarQuickCreateCardProps {
|
|
11
|
+
headingId: string;
|
|
12
|
+
fields: QuickCreateFields;
|
|
13
|
+
/** Only the calendars that accept writes. */
|
|
14
|
+
calendars: readonly CalendarDescriptor[];
|
|
15
|
+
onChange: (fields: QuickCreateFields) => void;
|
|
16
|
+
onSave: () => void;
|
|
17
|
+
onMoreOptions: () => void;
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
saving?: boolean;
|
|
20
|
+
/** Why the draft cannot be saved yet, said in the form. */
|
|
21
|
+
problem?: string;
|
|
22
|
+
failure?: CalendarFailure;
|
|
23
|
+
failureRef?: Ref<HTMLDivElement>;
|
|
24
|
+
titleRef?: Ref<HTMLInputElement>;
|
|
25
|
+
/** Where the calendar settings live, for when no calendar accepts writes. */
|
|
26
|
+
settingsHref: string;
|
|
27
|
+
/** The header drag, from the popover around the card. */
|
|
28
|
+
dragHandle?: {
|
|
29
|
+
onPointerDown: (event: PointerEvent<HTMLElement>) => void;
|
|
30
|
+
};
|
|
31
|
+
/** A bottom sheet on a phone: thumb-sized controls, no drag header. */
|
|
32
|
+
touch?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Google Calendar's small create popup: title, when, where, which calendar. */
|
|
35
|
+
export declare function CalendarQuickCreateCard({ headingId, fields, calendars, onChange, onSave, onMoreOptions, onClose, saving, problem, failure, failureRef, titleRef, settingsHref, dragHandle, touch, }: CalendarQuickCreateCardProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { GripHorizontal, X } from "lucide-react";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { CalendarFailureBlock, } from "./calendar-event-popup.js";
|
|
5
|
+
const field = "h-9 rounded-md border border-line bg-surface-sunken px-2 text-sm text-fg outline-none focus-visible:border-line-strong focus-visible:ring-2 focus-visible:ring-ring/30";
|
|
6
|
+
const withRange = (fields, patch) => {
|
|
7
|
+
const range = { ...fields.range, ...patch };
|
|
8
|
+
if (patch.date !== undefined && !range.allDay)
|
|
9
|
+
range.endDate = patch.date;
|
|
10
|
+
if (patch.date !== undefined && range.allDay && range.endDate < patch.date)
|
|
11
|
+
range.endDate = patch.date;
|
|
12
|
+
return { ...fields, range };
|
|
13
|
+
};
|
|
14
|
+
/** Google Calendar's small create popup: title, when, where, which calendar. */
|
|
15
|
+
export function CalendarQuickCreateCard({ headingId, fields, calendars, onChange, onSave, onMoreOptions, onClose, saving = false, problem = "", failure, failureRef, titleRef, settingsHref, dragHandle, touch = false, }) {
|
|
16
|
+
const noWritable = calendars.length === 0;
|
|
17
|
+
const control = cn(field, touch && "h-11");
|
|
18
|
+
return (_jsxs("form", { className: "relative flex flex-col", onSubmit: (event) => {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
if (!noWritable && !saving)
|
|
21
|
+
onSave();
|
|
22
|
+
}, children: [_jsxs("div", { onPointerDown: dragHandle?.onPointerDown, className: cn("flex items-center justify-between rounded-t-xl bg-surface-sunken px-2 py-1", dragHandle && "cursor-grab"), children: [_jsx(GripHorizontal, { className: "size-4 text-fg-subtle", "aria-hidden": "true" }), _jsx("h2", { id: headingId, className: "sr-only", children: "New event" })] }), _jsxs("div", { className: "flex flex-col gap-3 p-4", children: [_jsx("input", { ref: titleRef, "aria-label": "Title", placeholder: "Add title", value: fields.title, onChange: (event) => onChange({ ...fields, title: event.target.value }), className: cn("border-b-2 border-line bg-transparent pb-1 text-xl text-fg outline-none placeholder:text-fg-subtle focus:border-accent") }), _jsxs("div", { className: "flex flex-wrap items-center gap-2 text-sm", children: [_jsx("input", { type: "date", "aria-label": "Date", value: fields.range.date, onChange: (event) => event.target.value !== "" &&
|
|
23
|
+
onChange(withRange(fields, { date: event.target.value })), className: control }), fields.range.allDay ? (_jsx("span", { className: "text-fg-muted", children: "All day" })) : (_jsxs(_Fragment, { children: [_jsx("input", { type: "time", "aria-label": "Start time", step: 900, value: fields.range.startTime, onChange: (event) => event.target.value !== "" &&
|
|
24
|
+
onChange(withRange(fields, { startTime: event.target.value })), className: control }), _jsx("span", { "aria-hidden": "true", children: "\u2013" }), _jsx("input", { type: "time", "aria-label": "End time", step: 900, value: fields.range.endTime, onChange: (event) => event.target.value !== "" &&
|
|
25
|
+
onChange(withRange(fields, { endTime: event.target.value })), className: control })] }))] }), _jsx("input", { "aria-label": "Location", placeholder: "Add location", value: fields.location, onChange: (event) => onChange({ ...fields, location: event.target.value }), className: control }), noWritable ? (_jsxs("p", { role: "status", tabIndex: -1, className: "text-sm text-fg-muted", children: ["None of your calendars accepts new events.", " ", _jsx("a", { href: settingsHref, className: "font-medium text-accent hover:underline", children: "Calendar settings" })] })) : (_jsx("select", { "aria-label": "Calendar", value: fields.calendarId, onChange: (event) => onChange({ ...fields, calendarId: event.target.value }), className: control, children: calendars.map((calendar) => (_jsx("option", { value: calendar.id, children: calendar.name }, calendar.id))) })), problem !== "" && (_jsx("p", { className: "text-sm text-danger", role: "status", children: problem })), failure && (_jsx(CalendarFailureBlock, { failure: failure, focusRef: failureRef }))] }), _jsxs("div", { className: "flex items-center justify-between px-4 pb-4", children: [_jsx("button", { type: "button", onClick: onMoreOptions, className: cn("rounded-md px-3 text-sm font-medium text-accent outline-none hover:bg-accent-soft focus-visible:ring-2 focus-visible:ring-ring", touch ? "min-h-11" : "h-9"), children: "More options" }), _jsx("button", { type: "submit", disabled: noWritable || saving, className: cn("rounded-md bg-accent px-5 text-sm font-medium text-accent-fg outline-none hover:bg-accent-hover focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50", touch ? "min-h-11" : "h-9"), children: saving ? "Saving…" : "Save" })] }), _jsx("button", { type: "button", "aria-label": "Close", onClick: onClose, className: cn("absolute top-0 right-1 flex items-center justify-center rounded-full text-fg-muted outline-none hover:bg-surface hover:text-fg focus-visible:ring-2 focus-visible:ring-ring", touch ? "size-11" : "size-8"), children: _jsx(X, { className: "size-4" }) })] }));
|
|
26
|
+
}
|