@remit/ui 0.0.155 → 0.0.157
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/package.json +5 -2
- package/src/calendar.css +4 -0
- package/src/components/agenda-composer.render.test.ts +196 -0
- package/src/components/agenda-composer.stories.tsx +225 -0
- package/src/components/agenda-composer.tsx +283 -0
- package/src/components/agenda-flow.render.test.ts +217 -0
- package/src/components/agenda-flow.stories.tsx +215 -0
- package/src/components/agenda-flow.tsx +887 -0
- package/src/components/agenda-panels.render.test.ts +252 -0
- package/src/components/agenda-panels.stories.tsx +207 -0
- package/src/components/agenda-panels.tsx +421 -0
- package/src/components/calendar-event-chip-content.tsx +102 -0
- package/src/components/calendar-event-chip.stories.tsx +5 -7
- package/src/components/calendar-event-chip.tsx +47 -47
- package/src/components/calendar-grid.render.test.ts +309 -0
- package/src/components/calendar-grid.stories.tsx +203 -0
- package/src/components/calendar-grid.tsx +370 -0
- package/src/components/calendar-types.ts +85 -0
- package/src/index.ts +82 -0
- package/src/lib/agenda-time.test.ts +539 -0
- package/src/lib/agenda-time.ts +505 -0
- package/src/lib/calendar-event-shell.ts +55 -0
- package/src/lib/calendar-slot-pick.test.ts +140 -0
- package/src/lib/calendar-slot-pick.ts +65 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CalendarSlotPick } from "../components/calendar-types.js";
|
|
2
|
+
import { addMinutesToClock } from "./event-phrase.js";
|
|
3
|
+
|
|
4
|
+
/** How long a new event is when nobody said — the hour every other path starts from. */
|
|
5
|
+
export const DRAFT_MINUTES = 60;
|
|
6
|
+
|
|
7
|
+
const MS_PER_MINUTE = 60_000;
|
|
8
|
+
const MS_PER_DAY = 86_400_000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A pick is read off the ISO strings the calendar hands the callback, never off
|
|
12
|
+
* its `Date`. The grid runs in the calendar's own zone; a `Date` read through
|
|
13
|
+
* `getHours()` is that instant in the host's zone, so a UTC runner would draft
|
|
14
|
+
* 09:00 for a click on 11:00.
|
|
15
|
+
*/
|
|
16
|
+
export function rangePick(
|
|
17
|
+
startStr: string,
|
|
18
|
+
endStr: string,
|
|
19
|
+
allDay: boolean,
|
|
20
|
+
): CalendarSlotPick {
|
|
21
|
+
if (allDay) return allDayPick(startStr);
|
|
22
|
+
return {
|
|
23
|
+
date: startStr.slice(0, 10),
|
|
24
|
+
startTime: startStr.slice(11, 16),
|
|
25
|
+
endTime: endStr.slice(11, 16),
|
|
26
|
+
allDay: false,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A single point on the grid, an hour long because nothing said otherwise. */
|
|
31
|
+
export function pointPick(dateStr: string, allDay: boolean): CalendarSlotPick {
|
|
32
|
+
if (allDay) return allDayPick(dateStr);
|
|
33
|
+
const startTime = dateStr.slice(11, 16);
|
|
34
|
+
return {
|
|
35
|
+
date: dateStr.slice(0, 10),
|
|
36
|
+
startTime,
|
|
37
|
+
endTime: addMinutesToClock(startTime, DRAFT_MINUTES),
|
|
38
|
+
allDay: false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function allDayPick(dateStr: string): CalendarSlotPick {
|
|
43
|
+
return {
|
|
44
|
+
date: dateStr.slice(0, 10),
|
|
45
|
+
startTime: "",
|
|
46
|
+
endTime: "",
|
|
47
|
+
allDay: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether a selection was dragged across the grid rather than landing on it.
|
|
53
|
+
* One slot, or one day, is as small as a selection gets, which is exactly what
|
|
54
|
+
* a click leaves behind — and a click is already a pick of its own.
|
|
55
|
+
*/
|
|
56
|
+
export function isDraggedSelection(
|
|
57
|
+
startStr: string,
|
|
58
|
+
endStr: string,
|
|
59
|
+
allDay: boolean,
|
|
60
|
+
slotMinutes: number,
|
|
61
|
+
): boolean {
|
|
62
|
+
const span = Date.parse(endStr) - Date.parse(startStr);
|
|
63
|
+
if (allDay) return Math.round(span / MS_PER_DAY) > 1;
|
|
64
|
+
return span / MS_PER_MINUTE > slotMinutes;
|
|
65
|
+
}
|