@remit/ui 0.0.224 → 0.0.226
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 +45 -0
- package/dist/components/calendar-event-sidebar.js +19 -0
- package/dist/components/calendar-grid.d.ts +11 -7
- package/dist/components/calendar-grid.js +55 -109
- package/dist/components/calendar-guests.d.ts +80 -0
- package/dist/components/calendar-guests.js +102 -0
- 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 +53 -0
- package/dist/components/calendar-quick-create.js +43 -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-suggestion-list.d.ts +11 -0
- package/dist/components/calendar-suggestion-list.js +9 -0
- package/dist/components/calendar-task-popup.d.ts +28 -0
- package/dist/components/calendar-task-popup.js +17 -0
- package/dist/components/calendar-time-grid.d.ts +70 -0
- package/dist/components/calendar-time-grid.js +701 -0
- package/dist/components/calendar-toolbar.d.ts +0 -31
- package/dist/components/calendar-toolbar.js +0 -27
- package/dist/components/calendar-types.d.ts +12 -2
- package/dist/components/calendar-types.js +0 -5
- 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/event-editor.js +2 -1
- package/dist/components/intelligence-calendar.d.ts +1 -1
- package/dist/components/intelligence-calendar.js +10 -16
- package/dist/components/mini-month.d.ts +19 -0
- package/dist/components/mini-month.js +34 -0
- package/dist/components/recurrence-scope-prompt.d.ts +3 -1
- package/dist/components/recurrence-scope-prompt.js +4 -2
- package/dist/index.d.ts +24 -5
- package/dist/index.js +23 -4
- 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/guest-list.d.ts +17 -0
- package/dist/lib/guest-list.js +34 -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/calendar-suggestion-deck.d.ts +0 -18
- package/dist/components/calendar-suggestion-deck.js +0 -51
- package/dist/components/event-detail.d.ts +0 -38
- package/dist/components/event-detail.js +0 -21
|
@@ -59,3 +59,70 @@ export function isDraggedSelection(startStr, endStr, allDay, slotMinutes) {
|
|
|
59
59
|
return Math.round(span / MS_PER_DAY) > 1;
|
|
60
60
|
return span / MS_PER_MINUTE > slotMinutes;
|
|
61
61
|
}
|
|
62
|
+
/** Every range on the grid snaps to a quarter hour, as in Google Calendar. */
|
|
63
|
+
export const SNAP_MINUTES = 15;
|
|
64
|
+
/** A press that travels less than this is a click, not a drag. */
|
|
65
|
+
export const CLICK_THRESHOLD_PX = 4;
|
|
66
|
+
const MINUTES_PER_DAY = 1440;
|
|
67
|
+
/** Whether a press moved far enough to be a drag. */
|
|
68
|
+
export function isDrag(dx, dy) {
|
|
69
|
+
return Math.hypot(dx, dy) >= CLICK_THRESHOLD_PX;
|
|
70
|
+
}
|
|
71
|
+
/** The quarter hour a vertical offset falls in, from midnight. */
|
|
72
|
+
export function minuteAt(offsetY, hourHeight) {
|
|
73
|
+
const minutes = (offsetY / hourHeight) * 60;
|
|
74
|
+
const snapped = Math.floor(minutes / SNAP_MINUTES) * SNAP_MINUTES;
|
|
75
|
+
return Math.min(Math.max(snapped, 0), MINUTES_PER_DAY - SNAP_MINUTES);
|
|
76
|
+
}
|
|
77
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
78
|
+
/** `HH:MM` for minutes from midnight. */
|
|
79
|
+
export function clockAt(minutes) {
|
|
80
|
+
return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`;
|
|
81
|
+
}
|
|
82
|
+
/** Minutes from midnight for `HH:MM`. */
|
|
83
|
+
export function minutesOf(clock) {
|
|
84
|
+
const [hours, minutes] = clock.split(":").map(Number);
|
|
85
|
+
return hours * 60 + minutes;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A timed range dragged in one column, from the slot pressed to the slot the
|
|
89
|
+
* pointer is over, inclusive of both. A drag that runs to the bottom ends at
|
|
90
|
+
* midnight, which is the next day's `00:00`.
|
|
91
|
+
*/
|
|
92
|
+
export function timedRange(date, anchorMinute, currentMinute) {
|
|
93
|
+
const start = Math.min(anchorMinute, currentMinute);
|
|
94
|
+
const end = Math.max(anchorMinute, currentMinute) + SNAP_MINUTES;
|
|
95
|
+
return slotRange(date, start, end);
|
|
96
|
+
}
|
|
97
|
+
/** A range on one day from minutes, rolling an end at midnight onto the next day. */
|
|
98
|
+
export function slotRange(date, startMinute, endMinute) {
|
|
99
|
+
const atMidnight = endMinute >= MINUTES_PER_DAY;
|
|
100
|
+
return {
|
|
101
|
+
date,
|
|
102
|
+
endDate: atMidnight ? addDays(date, 1) : date,
|
|
103
|
+
startTime: clockAt(startMinute),
|
|
104
|
+
endTime: atMidnight ? "00:00" : clockAt(endMinute),
|
|
105
|
+
allDay: false,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** The hour a click lands on: from the quarter pressed, an hour long. */
|
|
109
|
+
export function clickRange(date, minute) {
|
|
110
|
+
return slotRange(date, minute, minute + DRAFT_MINUTES);
|
|
111
|
+
}
|
|
112
|
+
/** An all-day range across whichever days the drag covered, in either direction. */
|
|
113
|
+
export function allDayRange(anchor, current) {
|
|
114
|
+
const [first, last] = anchor <= current ? [anchor, current] : [current, anchor];
|
|
115
|
+
return {
|
|
116
|
+
date: first,
|
|
117
|
+
endDate: last,
|
|
118
|
+
startTime: "",
|
|
119
|
+
endTime: "",
|
|
120
|
+
allDay: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Minutes the range covers on its first day, end exclusive. */
|
|
124
|
+
export function rangeMinutes(range) {
|
|
125
|
+
const start = minutesOf(range.startTime);
|
|
126
|
+
const end = range.endDate > range.date ? MINUTES_PER_DAY : minutesOf(range.endTime);
|
|
127
|
+
return { start, end };
|
|
128
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ZonedMoment } from "./time-grid-layout.js";
|
|
2
|
+
/** A pointer travel in pixels as whole quarter hours. */
|
|
3
|
+
export declare function snappedMinutes(deltaY: number, hourHeight: number): number;
|
|
4
|
+
/**
|
|
5
|
+
* A timed event moved by whole days and quarter hours. It keeps its length,
|
|
6
|
+
* and its start lands on a quarter hour.
|
|
7
|
+
*/
|
|
8
|
+
export declare function moveTimed(start: ZonedMoment, end: ZonedMoment, dayDelta: number, minuteDelta: number): {
|
|
9
|
+
start: ZonedMoment;
|
|
10
|
+
end: ZonedMoment;
|
|
11
|
+
};
|
|
12
|
+
/** A timed event's end dragged by quarter hours, never shorter than one. */
|
|
13
|
+
export declare function resizeTimed(start: ZonedMoment, end: ZonedMoment, minuteDelta: number): ZonedMoment;
|
|
14
|
+
/** An all-day event, first and last day inclusive, moved by whole days. */
|
|
15
|
+
export declare function moveDays(first: string, last: string, dayDelta: number): {
|
|
16
|
+
first: string;
|
|
17
|
+
last: string;
|
|
18
|
+
};
|
|
19
|
+
/** An all-day event's last day dragged across days, never before its first. */
|
|
20
|
+
export declare function resizeDays(first: string, last: string, dayDelta: number): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { addDays } from "./agenda-time.js";
|
|
2
|
+
import { SNAP_MINUTES } from "./calendar-slot-pick.js";
|
|
3
|
+
const DAY = 1440;
|
|
4
|
+
/** A pointer travel in pixels as whole quarter hours. */
|
|
5
|
+
export function snappedMinutes(deltaY, hourHeight) {
|
|
6
|
+
return Math.round(((deltaY / hourHeight) * 60) / SNAP_MINUTES) * SNAP_MINUTES;
|
|
7
|
+
}
|
|
8
|
+
function shift(moment, minutes) {
|
|
9
|
+
const total = moment.minute + minutes;
|
|
10
|
+
const days = Math.floor(total / DAY);
|
|
11
|
+
return { date: addDays(moment.date, days), minute: total - days * DAY };
|
|
12
|
+
}
|
|
13
|
+
const span = (start, end) => {
|
|
14
|
+
let days = 0;
|
|
15
|
+
let cursor = start.date;
|
|
16
|
+
while (cursor < end.date) {
|
|
17
|
+
cursor = addDays(cursor, 1);
|
|
18
|
+
days += 1;
|
|
19
|
+
}
|
|
20
|
+
return days * DAY + end.minute - start.minute;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A timed event moved by whole days and quarter hours. It keeps its length,
|
|
24
|
+
* and its start lands on a quarter hour.
|
|
25
|
+
*/
|
|
26
|
+
export function moveTimed(start, end, dayDelta, minuteDelta) {
|
|
27
|
+
const length = span(start, end);
|
|
28
|
+
const moved = shift({ date: addDays(start.date, dayDelta), minute: start.minute }, minuteDelta);
|
|
29
|
+
const snapped = {
|
|
30
|
+
date: moved.date,
|
|
31
|
+
minute: Math.round(moved.minute / SNAP_MINUTES) * SNAP_MINUTES,
|
|
32
|
+
};
|
|
33
|
+
const startAt = snapped.minute === DAY ? shift(snapped, 0) : snapped;
|
|
34
|
+
return { start: startAt, end: shift(startAt, length) };
|
|
35
|
+
}
|
|
36
|
+
/** A timed event's end dragged by quarter hours, never shorter than one. */
|
|
37
|
+
export function resizeTimed(start, end, minuteDelta) {
|
|
38
|
+
const length = Math.max(span(start, end) + minuteDelta, SNAP_MINUTES);
|
|
39
|
+
const minutes = Math.round(length / SNAP_MINUTES) * SNAP_MINUTES;
|
|
40
|
+
return shift(start, minutes);
|
|
41
|
+
}
|
|
42
|
+
/** An all-day event, first and last day inclusive, moved by whole days. */
|
|
43
|
+
export function moveDays(first, last, dayDelta) {
|
|
44
|
+
return { first: addDays(first, dayDelta), last: addDays(last, dayDelta) };
|
|
45
|
+
}
|
|
46
|
+
/** An all-day event's last day dragged across days, never before its first. */
|
|
47
|
+
export function resizeDays(first, last, dayDelta) {
|
|
48
|
+
const next = addDays(last, dayDelta);
|
|
49
|
+
return next < first ? first : next;
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CalendarSlotPick } from "../components/calendar-types.js";
|
|
2
|
+
/** The quarter hour the grid's keyboard focus sits on. */
|
|
3
|
+
export interface GridSlot {
|
|
4
|
+
date: string;
|
|
5
|
+
minute: number;
|
|
6
|
+
}
|
|
7
|
+
/** The grid's tab stop: the current hour of today, or of the first day in view. */
|
|
8
|
+
export declare function initialFocus(days: readonly string[], today: string, nowMinute: number): GridSlot;
|
|
9
|
+
/** Where an arrow key moves the focus: a quarter hour up or down, a day across. */
|
|
10
|
+
export declare function moveFocus(slot: GridSlot, key: string, days: readonly string[]): GridSlot | null;
|
|
11
|
+
/**
|
|
12
|
+
* The range Shift and the arrows stretch out, from the slot the stretch began
|
|
13
|
+
* on to the focused slot, both included.
|
|
14
|
+
*/
|
|
15
|
+
export declare function stretchRange(anchor: GridSlot, focus: GridSlot): CalendarSlotPick;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { clockAt, SNAP_MINUTES, slotRange } from "./calendar-slot-pick.js";
|
|
2
|
+
const LAST_SLOT = 1440 - SNAP_MINUTES;
|
|
3
|
+
/** The grid's tab stop: the current hour of today, or of the first day in view. */
|
|
4
|
+
export function initialFocus(days, today, nowMinute) {
|
|
5
|
+
return {
|
|
6
|
+
date: days.includes(today) ? today : days[0],
|
|
7
|
+
minute: Math.floor(nowMinute / 60) * 60,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Where an arrow key moves the focus: a quarter hour up or down, a day across. */
|
|
11
|
+
export function moveFocus(slot, key, days) {
|
|
12
|
+
const index = days.indexOf(slot.date);
|
|
13
|
+
switch (key) {
|
|
14
|
+
case "ArrowUp":
|
|
15
|
+
return { ...slot, minute: Math.max(0, slot.minute - SNAP_MINUTES) };
|
|
16
|
+
case "ArrowDown":
|
|
17
|
+
return {
|
|
18
|
+
...slot,
|
|
19
|
+
minute: Math.min(LAST_SLOT, slot.minute + SNAP_MINUTES),
|
|
20
|
+
};
|
|
21
|
+
case "ArrowLeft":
|
|
22
|
+
return { ...slot, date: days[Math.max(0, index - 1)] };
|
|
23
|
+
case "ArrowRight":
|
|
24
|
+
return { ...slot, date: days[Math.min(days.length - 1, index + 1)] };
|
|
25
|
+
default:
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const order = (a, b) => a.date === b.date ? a.minute - b.minute : a.date < b.date ? -1 : 1;
|
|
30
|
+
/**
|
|
31
|
+
* The range Shift and the arrows stretch out, from the slot the stretch began
|
|
32
|
+
* on to the focused slot, both included.
|
|
33
|
+
*/
|
|
34
|
+
export function stretchRange(anchor, focus) {
|
|
35
|
+
const [first, last] = order(anchor, focus) <= 0 ? [anchor, focus] : [focus, anchor];
|
|
36
|
+
if (first.date === last.date)
|
|
37
|
+
return slotRange(first.date, first.minute, last.minute + SNAP_MINUTES);
|
|
38
|
+
const end = slotRange(last.date, last.minute, last.minute + SNAP_MINUTES);
|
|
39
|
+
return {
|
|
40
|
+
date: first.date,
|
|
41
|
+
startTime: clockAt(first.minute),
|
|
42
|
+
endDate: end.endDate,
|
|
43
|
+
endTime: end.endTime,
|
|
44
|
+
allDay: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** One guest as the Guests field holds them. */
|
|
2
|
+
export interface GuestEntry {
|
|
3
|
+
/** What the reader typed for this guest, kept so an invalid entry can be shown and fixed. */
|
|
4
|
+
text: string;
|
|
5
|
+
email: string;
|
|
6
|
+
/** The name before the address, or the address itself when none was given. */
|
|
7
|
+
displayName: string;
|
|
8
|
+
valid: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** One typed entry: `ann@example.com`, or `Ann Smith <ann@example.com>`. */
|
|
11
|
+
export declare function parseGuest(text: string): GuestEntry;
|
|
12
|
+
/** A guest the server already holds, by address and the name it stored. */
|
|
13
|
+
export declare function storedGuest(email: string, displayName: string): GuestEntry;
|
|
14
|
+
/** The list with one more guest, unless that address is already on it. */
|
|
15
|
+
export declare function withGuest(guests: readonly GuestEntry[], guest: GuestEntry): GuestEntry[];
|
|
16
|
+
/** The first entry that is not an email address, which blocks a save. */
|
|
17
|
+
export declare function invalidGuest(guests: readonly GuestEntry[]): GuestEntry | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const EMAIL = /^[^\s@<>",;]+@[^\s@<>",;]+\.[^\s@<>",;]+$/;
|
|
2
|
+
const NAMED = /^\s*"?([^"<]*?)"?\s*<([^>]+)>\s*$/;
|
|
3
|
+
/** One typed entry: `ann@example.com`, or `Ann Smith <ann@example.com>`. */
|
|
4
|
+
export function parseGuest(text) {
|
|
5
|
+
const trimmed = text.trim();
|
|
6
|
+
const named = NAMED.exec(trimmed);
|
|
7
|
+
const email = (named?.[2] ?? trimmed).trim().toLowerCase();
|
|
8
|
+
const name = named?.[1]?.trim() ?? "";
|
|
9
|
+
return {
|
|
10
|
+
text: trimmed,
|
|
11
|
+
email,
|
|
12
|
+
displayName: name === "" ? email : name,
|
|
13
|
+
valid: EMAIL.test(email),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** A guest the server already holds, by address and the name it stored. */
|
|
17
|
+
export function storedGuest(email, displayName) {
|
|
18
|
+
return {
|
|
19
|
+
text: email,
|
|
20
|
+
email,
|
|
21
|
+
displayName: displayName === "" ? email : displayName,
|
|
22
|
+
valid: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** The list with one more guest, unless that address is already on it. */
|
|
26
|
+
export function withGuest(guests, guest) {
|
|
27
|
+
if (guest.valid && guests.some((other) => other.email === guest.email))
|
|
28
|
+
return [...guests];
|
|
29
|
+
return [...guests, guest];
|
|
30
|
+
}
|
|
31
|
+
/** The first entry that is not an email address, which blocks a save. */
|
|
32
|
+
export function invalidGuest(guests) {
|
|
33
|
+
return guests.find((guest) => !guest.valid);
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const MS_PER_DAY = 86_400_000;
|
|
2
|
+
const parse = (date) => {
|
|
3
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
4
|
+
return new Date(Date.UTC(year, month - 1, day));
|
|
5
|
+
};
|
|
6
|
+
/** The ISO 8601 week a `YYYY-MM-DD` date falls in: weeks start on Monday, and week 1 holds the year's first Thursday. */
|
|
7
|
+
export function isoWeek(date) {
|
|
8
|
+
const day = parse(date);
|
|
9
|
+
const weekday = (day.getUTCDay() + 6) % 7;
|
|
10
|
+
const thursday = new Date(day.getTime() + (3 - weekday) * MS_PER_DAY);
|
|
11
|
+
const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
|
|
12
|
+
return Math.floor((thursday.getTime() - yearStart) / MS_PER_DAY / 7) + 1;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CalendarSlotPick } from "../components/calendar-types.js";
|
|
2
|
+
/** How long a finger holds still before a slot is selected, as in Google Calendar. */
|
|
3
|
+
export declare const HOLD_MS = 500;
|
|
4
|
+
/** How far a finger may drift during the hold before it counts as a scroll. */
|
|
5
|
+
export declare const SCROLL_SLOP_PX = 8;
|
|
6
|
+
export type Press = {
|
|
7
|
+
phase: "pending";
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
at: number;
|
|
11
|
+
} | {
|
|
12
|
+
phase: "held";
|
|
13
|
+
} | {
|
|
14
|
+
phase: "scrolled";
|
|
15
|
+
};
|
|
16
|
+
export declare function pressStart(x: number, y: number, at: number): Press;
|
|
17
|
+
/** A finger that moves during the hold is scrolling, and never selects. */
|
|
18
|
+
export declare function pressMove(press: Press, x: number, y: number): Press;
|
|
19
|
+
/** A hold that outlasted the delay without moving becomes a selection. */
|
|
20
|
+
export declare function pressTick(press: Press, now: number): Press;
|
|
21
|
+
/**
|
|
22
|
+
* A handle dragged by `deltaY` pixels, in quarter-hour steps. The other end
|
|
23
|
+
* stays put, and the block never gets shorter than a quarter hour.
|
|
24
|
+
*/
|
|
25
|
+
export declare function stepHandle(range: CalendarSlotPick, edge: "start" | "end", deltaY: number, hourHeight: number): CalendarSlotPick;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { rangeMinutes, SNAP_MINUTES, slotRange } from "./calendar-slot-pick.js";
|
|
2
|
+
/** How long a finger holds still before a slot is selected, as in Google Calendar. */
|
|
3
|
+
export const HOLD_MS = 500;
|
|
4
|
+
/** How far a finger may drift during the hold before it counts as a scroll. */
|
|
5
|
+
export const SCROLL_SLOP_PX = 8;
|
|
6
|
+
export function pressStart(x, y, at) {
|
|
7
|
+
return { phase: "pending", x, y, at };
|
|
8
|
+
}
|
|
9
|
+
/** A finger that moves during the hold is scrolling, and never selects. */
|
|
10
|
+
export function pressMove(press, x, y) {
|
|
11
|
+
if (press.phase !== "pending")
|
|
12
|
+
return press;
|
|
13
|
+
return Math.hypot(x - press.x, y - press.y) > SCROLL_SLOP_PX
|
|
14
|
+
? { phase: "scrolled" }
|
|
15
|
+
: press;
|
|
16
|
+
}
|
|
17
|
+
/** A hold that outlasted the delay without moving becomes a selection. */
|
|
18
|
+
export function pressTick(press, now) {
|
|
19
|
+
if (press.phase !== "pending")
|
|
20
|
+
return press;
|
|
21
|
+
return now - press.at >= HOLD_MS ? { phase: "held" } : press;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A handle dragged by `deltaY` pixels, in quarter-hour steps. The other end
|
|
25
|
+
* stays put, and the block never gets shorter than a quarter hour.
|
|
26
|
+
*/
|
|
27
|
+
export function stepHandle(range, edge, deltaY, hourHeight) {
|
|
28
|
+
const steps = Math.round((deltaY / hourHeight) * (60 / SNAP_MINUTES));
|
|
29
|
+
const { start, end } = rangeMinutes(range);
|
|
30
|
+
const moved = steps * SNAP_MINUTES;
|
|
31
|
+
if (edge === "start") {
|
|
32
|
+
const next = Math.min(Math.max(0, start + moved), end - SNAP_MINUTES);
|
|
33
|
+
return slotRange(range.date, next, end);
|
|
34
|
+
}
|
|
35
|
+
const next = Math.max(Math.min(1440, end + moved), start + SNAP_MINUTES);
|
|
36
|
+
return slotRange(range.date, start, next);
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface MiniMonthDay {
|
|
2
|
+
date: string;
|
|
3
|
+
day: number;
|
|
4
|
+
inMonth: boolean;
|
|
5
|
+
isToday: boolean;
|
|
6
|
+
inRange: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface MiniMonthWeek {
|
|
9
|
+
weekNumber: number;
|
|
10
|
+
days: MiniMonthDay[];
|
|
11
|
+
}
|
|
12
|
+
export interface MiniMonthInput {
|
|
13
|
+
/** Any `YYYY-MM-DD` in the month to draw. */
|
|
14
|
+
month: string;
|
|
15
|
+
today: string;
|
|
16
|
+
/** The range on the grid, inclusive; empty strings mark none. */
|
|
17
|
+
rangeStart: string;
|
|
18
|
+
rangeEnd: string;
|
|
19
|
+
}
|
|
20
|
+
/** The first of the month a date is in, moved by a number of months. */
|
|
21
|
+
export declare function shiftMonth(date: string, months: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* The weeks a month spans, Monday first, each with its ISO week number. The
|
|
24
|
+
* days around the month fill its first and last week, the way a paper
|
|
25
|
+
* calendar prints them.
|
|
26
|
+
*/
|
|
27
|
+
export declare function miniMonthWeeks({ month, today, rangeStart, rangeEnd, }: MiniMonthInput): MiniMonthWeek[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { datesFrom, weekStart } from "./calendar-range.js";
|
|
2
|
+
import { isoWeek } from "./iso-week.js";
|
|
3
|
+
/** The first of the month a date is in, moved by a number of months. */
|
|
4
|
+
export function shiftMonth(date, months) {
|
|
5
|
+
const [year, month] = date.split("-").map(Number);
|
|
6
|
+
const index = year * 12 + (month - 1) + months;
|
|
7
|
+
const nextYear = Math.floor(index / 12);
|
|
8
|
+
const nextMonth = (index % 12) + 1;
|
|
9
|
+
return `${nextYear}-${String(nextMonth).padStart(2, "0")}-01`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The weeks a month spans, Monday first, each with its ISO week number. The
|
|
13
|
+
* days around the month fill its first and last week, the way a paper
|
|
14
|
+
* calendar prints them.
|
|
15
|
+
*/
|
|
16
|
+
export function miniMonthWeeks({ month, today, rangeStart, rangeEnd, }) {
|
|
17
|
+
const first = `${month.slice(0, 7)}-01`;
|
|
18
|
+
const last = shiftMonth(first, 1);
|
|
19
|
+
const weeks = [];
|
|
20
|
+
let start = weekStart(first);
|
|
21
|
+
while (start < last) {
|
|
22
|
+
const days = datesFrom(start, 7).map((date) => ({
|
|
23
|
+
date,
|
|
24
|
+
day: Number(date.slice(8)),
|
|
25
|
+
inMonth: date.slice(0, 7) === first.slice(0, 7),
|
|
26
|
+
isToday: date === today,
|
|
27
|
+
inRange: rangeStart !== "" && date >= rangeStart && date <= rangeEnd,
|
|
28
|
+
}));
|
|
29
|
+
weeks.push({ weekNumber: isoWeek(start), days });
|
|
30
|
+
start = datesFrom(start, 8)[7];
|
|
31
|
+
}
|
|
32
|
+
return weeks;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Box {
|
|
2
|
+
left: number;
|
|
3
|
+
top: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Size {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Placement {
|
|
12
|
+
left: number;
|
|
13
|
+
top: number;
|
|
14
|
+
side: "right" | "left" | "below" | "above" | "center";
|
|
15
|
+
}
|
|
16
|
+
export declare function centred(popup: Size, viewport: Size): Placement;
|
|
17
|
+
/**
|
|
18
|
+
* Where a popup goes beside what it describes: to the right when there is
|
|
19
|
+
* room, else to the left, else below or above, and never over the anchor. An
|
|
20
|
+
* anchor that is missing or out of view centres the popup instead.
|
|
21
|
+
*/
|
|
22
|
+
export declare function placePopup(anchor: Box | null, popup: Size, viewport: Size): Placement;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const GAP = 8;
|
|
2
|
+
const clamp = (value, low, high) => Math.min(Math.max(value, low), Math.max(low, high));
|
|
3
|
+
const inView = (anchor, viewport) => anchor.width > 0 &&
|
|
4
|
+
anchor.height > 0 &&
|
|
5
|
+
anchor.left < viewport.width &&
|
|
6
|
+
anchor.left + anchor.width > 0 &&
|
|
7
|
+
anchor.top < viewport.height &&
|
|
8
|
+
anchor.top + anchor.height > 0;
|
|
9
|
+
export function centred(popup, viewport) {
|
|
10
|
+
return {
|
|
11
|
+
left: Math.max(GAP, (viewport.width - popup.width) / 2),
|
|
12
|
+
top: Math.max(GAP, (viewport.height - popup.height) / 2),
|
|
13
|
+
side: "center",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Where a popup goes beside what it describes: to the right when there is
|
|
18
|
+
* room, else to the left, else below or above, and never over the anchor. An
|
|
19
|
+
* anchor that is missing or out of view centres the popup instead.
|
|
20
|
+
*/
|
|
21
|
+
export function placePopup(anchor, popup, viewport) {
|
|
22
|
+
if (!anchor || !inView(anchor, viewport))
|
|
23
|
+
return centred(popup, viewport);
|
|
24
|
+
const top = clamp(anchor.top, GAP, viewport.height - popup.height - GAP);
|
|
25
|
+
const right = anchor.left + anchor.width + GAP;
|
|
26
|
+
if (right + popup.width <= viewport.width - GAP)
|
|
27
|
+
return { left: right, top, side: "right" };
|
|
28
|
+
const left = anchor.left - GAP - popup.width;
|
|
29
|
+
if (left >= GAP)
|
|
30
|
+
return { left, top, side: "left" };
|
|
31
|
+
const across = clamp(anchor.left, GAP, viewport.width - popup.width - GAP);
|
|
32
|
+
const below = anchor.top + anchor.height + GAP;
|
|
33
|
+
if (below + popup.height <= viewport.height - GAP)
|
|
34
|
+
return { left: across, top: below, side: "below" };
|
|
35
|
+
const above = anchor.top - GAP - popup.height;
|
|
36
|
+
if (above >= GAP)
|
|
37
|
+
return { left: across, top: above, side: "above" };
|
|
38
|
+
return centred(popup, viewport);
|
|
39
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A moment as a wall clock reads it in one zone: the day and minutes from midnight. */
|
|
2
|
+
export interface ZonedMoment {
|
|
3
|
+
date: string;
|
|
4
|
+
minute: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function zonedMoment(iso: string, timeZone: string): ZonedMoment;
|
|
7
|
+
export interface TimedSpan {
|
|
8
|
+
id: string;
|
|
9
|
+
start: ZonedMoment;
|
|
10
|
+
end: ZonedMoment;
|
|
11
|
+
}
|
|
12
|
+
export interface PlacedSpan {
|
|
13
|
+
id: string;
|
|
14
|
+
/** Minutes from midnight on this day, end exclusive. */
|
|
15
|
+
top: number;
|
|
16
|
+
bottom: number;
|
|
17
|
+
column: number;
|
|
18
|
+
columns: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The timed events on one day, clipped to it and laid out side by side where
|
|
22
|
+
* they overlap: each cluster of overlapping events shares its width evenly.
|
|
23
|
+
*/
|
|
24
|
+
export declare function layoutDay(date: string, spans: readonly TimedSpan[]): PlacedSpan[];
|
|
25
|
+
export interface DaySpan {
|
|
26
|
+
id: string;
|
|
27
|
+
/** First and last day, inclusive. */
|
|
28
|
+
first: string;
|
|
29
|
+
last: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PlacedBar {
|
|
32
|
+
id: string;
|
|
33
|
+
startIndex: number;
|
|
34
|
+
span: number;
|
|
35
|
+
lane: number;
|
|
36
|
+
}
|
|
37
|
+
/** All-day events as bars across the days in view, stacked into lanes. */
|
|
38
|
+
export declare function layoutAllDay(days: readonly string[], spans: readonly DaySpan[]): PlacedBar[];
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const partsFormat = new Map();
|
|
2
|
+
function formatter(timeZone) {
|
|
3
|
+
let format = partsFormat.get(timeZone);
|
|
4
|
+
if (!format) {
|
|
5
|
+
format = new Intl.DateTimeFormat("en-CA", {
|
|
6
|
+
timeZone,
|
|
7
|
+
year: "numeric",
|
|
8
|
+
month: "2-digit",
|
|
9
|
+
day: "2-digit",
|
|
10
|
+
hour: "2-digit",
|
|
11
|
+
minute: "2-digit",
|
|
12
|
+
hourCycle: "h23",
|
|
13
|
+
});
|
|
14
|
+
partsFormat.set(timeZone, format);
|
|
15
|
+
}
|
|
16
|
+
return format;
|
|
17
|
+
}
|
|
18
|
+
export function zonedMoment(iso, timeZone) {
|
|
19
|
+
const parts = Object.fromEntries(formatter(timeZone)
|
|
20
|
+
.formatToParts(new Date(iso))
|
|
21
|
+
.map((part) => [part.type, part.value]));
|
|
22
|
+
return {
|
|
23
|
+
date: `${parts.year}-${parts.month}-${parts.day}`,
|
|
24
|
+
minute: Number(parts.hour) * 60 + Number(parts.minute),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The timed events on one day, clipped to it and laid out side by side where
|
|
29
|
+
* they overlap: each cluster of overlapping events shares its width evenly.
|
|
30
|
+
*/
|
|
31
|
+
export function layoutDay(date, spans) {
|
|
32
|
+
const onDay = spans
|
|
33
|
+
.filter((span) => span.start.date <= date && span.end.date >= date)
|
|
34
|
+
.map((span) => ({
|
|
35
|
+
id: span.id,
|
|
36
|
+
top: span.start.date < date ? 0 : span.start.minute,
|
|
37
|
+
bottom: span.end.date > date ? 1440 : span.end.minute,
|
|
38
|
+
}))
|
|
39
|
+
.filter((span) => span.bottom > span.top || span.top === span.bottom)
|
|
40
|
+
.map((span) => ({ ...span, bottom: Math.max(span.bottom, span.top + 15) }))
|
|
41
|
+
.sort((a, b) => a.top - b.top || b.bottom - a.bottom);
|
|
42
|
+
const placed = [];
|
|
43
|
+
let cluster = [];
|
|
44
|
+
let clusterEnd = -1;
|
|
45
|
+
const close = () => {
|
|
46
|
+
const columns = Math.max(0, ...cluster.map((span) => span.column)) + 1;
|
|
47
|
+
for (const span of cluster)
|
|
48
|
+
span.columns = columns;
|
|
49
|
+
placed.push(...cluster);
|
|
50
|
+
cluster = [];
|
|
51
|
+
};
|
|
52
|
+
for (const span of onDay) {
|
|
53
|
+
if (span.top >= clusterEnd && cluster.length > 0)
|
|
54
|
+
close();
|
|
55
|
+
const taken = new Set(cluster
|
|
56
|
+
.filter((other) => other.bottom > span.top)
|
|
57
|
+
.map((other) => other.column));
|
|
58
|
+
let column = 0;
|
|
59
|
+
while (taken.has(column))
|
|
60
|
+
column += 1;
|
|
61
|
+
cluster.push({ ...span, column, columns: 1 });
|
|
62
|
+
clusterEnd = Math.max(clusterEnd, span.bottom);
|
|
63
|
+
}
|
|
64
|
+
if (cluster.length > 0)
|
|
65
|
+
close();
|
|
66
|
+
return placed;
|
|
67
|
+
}
|
|
68
|
+
/** All-day events as bars across the days in view, stacked into lanes. */
|
|
69
|
+
export function layoutAllDay(days, spans) {
|
|
70
|
+
const lanes = [];
|
|
71
|
+
const bars = [];
|
|
72
|
+
const visible = spans
|
|
73
|
+
.filter((span) => span.last >= days[0] && span.first <= days[days.length - 1])
|
|
74
|
+
.sort((a, b) => a.first.localeCompare(b.first) || b.last.localeCompare(a.last));
|
|
75
|
+
for (const span of visible) {
|
|
76
|
+
const startIndex = Math.max(0, days.indexOf(span.first < days[0] ? days[0] : span.first));
|
|
77
|
+
const lastDay = span.last > days[days.length - 1] ? days[days.length - 1] : span.last;
|
|
78
|
+
const endIndex = days.indexOf(lastDay);
|
|
79
|
+
let lane = lanes.findIndex((taken) => taken.every((index) => index < startIndex || index > endIndex));
|
|
80
|
+
if (lane === -1) {
|
|
81
|
+
lane = lanes.length;
|
|
82
|
+
lanes.push([]);
|
|
83
|
+
}
|
|
84
|
+
for (let index = startIndex; index <= endIndex; index += 1)
|
|
85
|
+
lanes[lane].push(index);
|
|
86
|
+
bars.push({
|
|
87
|
+
id: span.id,
|
|
88
|
+
startIndex,
|
|
89
|
+
span: endIndex - startIndex + 1,
|
|
90
|
+
lane,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return bars;
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
export interface CalendarSuggestionDeckProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
/** False when the deck has nothing left. */
|
|
5
|
-
hasCard: boolean;
|
|
6
|
-
onConfirm: () => void;
|
|
7
|
-
onReject: () => void;
|
|
8
|
-
/** True while the top card cannot be confirmed — an unsettled clock. */
|
|
9
|
-
blocked: boolean;
|
|
10
|
-
blockedReason: string;
|
|
11
|
-
remaining: number;
|
|
12
|
-
/** What the swipe badge says in the confirming direction. */
|
|
13
|
-
confirmLabel?: string;
|
|
14
|
-
/** What an empty deck says. */
|
|
15
|
-
emptyText?: string;
|
|
16
|
-
className?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function CalendarSuggestionDeck({ children, hasCard, onConfirm, onReject, blocked, blockedReason, remaining, confirmLabel, emptyText, className, }: CalendarSuggestionDeckProps): import("react").JSX.Element;
|