@remit/ui 0.0.210 → 0.0.212
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 +1 -1
- package/src/components/agenda-panels.render.test.ts +2 -117
- package/src/components/agenda-panels.stories.tsx +2 -72
- package/src/components/agenda-panels.tsx +3 -253
- package/src/components/calendar-types.ts +0 -50
- package/src/components/intelligence-panel-calendar.stories.tsx +1 -1
- package/src/components/pane-header.render.test.ts +22 -0
- package/src/components/pane-header.stories.tsx +76 -0
- package/src/components/pane-header.tsx +33 -0
- package/src/index.ts +2 -47
- package/src/lib/agenda-time.test.ts +0 -2
- package/src/lib/agenda-time.ts +0 -7
- package/src/lib/event-phrase.test.ts +1 -73
- package/src/lib/event-phrase.ts +0 -217
- package/src/lib/recurrence.ts +0 -3
- package/src/components/agenda-composer.render.test.ts +0 -197
- package/src/components/agenda-composer.stories.tsx +0 -227
- package/src/components/agenda-composer.tsx +0 -284
- package/src/components/custom-recurrence.stories.tsx +0 -107
- package/src/components/custom-recurrence.tsx +0 -411
- package/src/components/event-quick-entry.render.test.ts +0 -40
- package/src/components/event-quick-entry.stories.tsx +0 -57
- package/src/components/event-quick-entry.tsx +0 -159
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { cn } from "../lib/cn.js";
|
|
3
|
+
|
|
4
|
+
export interface PaneHeaderProps {
|
|
5
|
+
title?: string;
|
|
6
|
+
leading?: ReactNode;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function PaneHeader({
|
|
12
|
+
title,
|
|
13
|
+
leading,
|
|
14
|
+
children,
|
|
15
|
+
className,
|
|
16
|
+
}: PaneHeaderProps) {
|
|
17
|
+
return (
|
|
18
|
+
<header
|
|
19
|
+
className={cn(
|
|
20
|
+
"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
>
|
|
24
|
+
{leading}
|
|
25
|
+
{title !== undefined && (
|
|
26
|
+
<h1 className="min-w-0 flex-1 truncate text-sm font-semibold text-fg">
|
|
27
|
+
{title}
|
|
28
|
+
</h1>
|
|
29
|
+
)}
|
|
30
|
+
{children}
|
|
31
|
+
</header>
|
|
32
|
+
);
|
|
33
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -57,13 +57,6 @@ export {
|
|
|
57
57
|
type EnvelopeAddress,
|
|
58
58
|
} from "./components/address-display.js";
|
|
59
59
|
export { AddressTag, type AddressTagProps } from "./components/address-tag.js";
|
|
60
|
-
export {
|
|
61
|
-
AgendaComposer,
|
|
62
|
-
type AgendaComposerProps,
|
|
63
|
-
AgendaPhraseField,
|
|
64
|
-
type AgendaPhraseFieldProps,
|
|
65
|
-
PhraseReading,
|
|
66
|
-
} from "./components/agenda-composer.js";
|
|
67
60
|
export {
|
|
68
61
|
type AgendaDensity,
|
|
69
62
|
AgendaFlow,
|
|
@@ -71,14 +64,8 @@ export {
|
|
|
71
64
|
type AgendaScrollTarget,
|
|
72
65
|
} from "./components/agenda-flow.js";
|
|
73
66
|
export {
|
|
74
|
-
AgendaDensityControl,
|
|
75
|
-
type AgendaDensityControlProps,
|
|
76
|
-
FreeTimeList,
|
|
77
|
-
type FreeTimeListProps,
|
|
78
67
|
NextUpCard,
|
|
79
68
|
type NextUpCardProps,
|
|
80
|
-
PositionMap,
|
|
81
|
-
type PositionMapProps,
|
|
82
69
|
} from "./components/agenda-panels.js";
|
|
83
70
|
export {
|
|
84
71
|
AppPasswordHint,
|
|
@@ -232,7 +219,6 @@ export {
|
|
|
232
219
|
segmentClassName,
|
|
233
220
|
} from "./components/calendar-toolbar.js";
|
|
234
221
|
export {
|
|
235
|
-
type AgendaParse,
|
|
236
222
|
type CalendarAttendee,
|
|
237
223
|
type CalendarClash,
|
|
238
224
|
type CalendarColorId,
|
|
@@ -245,12 +231,9 @@ export {
|
|
|
245
231
|
type CalendarProposal,
|
|
246
232
|
type CalendarSlotPick,
|
|
247
233
|
type CalendarViewId,
|
|
248
|
-
type ChoicePicks,
|
|
249
234
|
calendarColorIds,
|
|
250
235
|
type EventDraft,
|
|
251
236
|
type EventSuggestion,
|
|
252
|
-
type PhraseChoice,
|
|
253
|
-
type PhraseChoiceOption,
|
|
254
237
|
type RecurrenceScope,
|
|
255
238
|
type RsvpState,
|
|
256
239
|
type ZoneCertainty,
|
|
@@ -326,12 +309,6 @@ export {
|
|
|
326
309
|
ConfirmDialog,
|
|
327
310
|
type ConfirmDialogProps,
|
|
328
311
|
} from "./components/confirm-dialog.js";
|
|
329
|
-
export {
|
|
330
|
-
CustomRecurrenceDialog,
|
|
331
|
-
type CustomRecurrenceDialogProps,
|
|
332
|
-
CustomRecurrenceEditor,
|
|
333
|
-
type CustomRecurrenceEditorProps,
|
|
334
|
-
} from "./components/custom-recurrence.js";
|
|
335
312
|
export {
|
|
336
313
|
DangerZoneSection,
|
|
337
314
|
type DangerZoneSectionProps,
|
|
@@ -350,18 +327,9 @@ export {
|
|
|
350
327
|
type EventDetailProps,
|
|
351
328
|
} from "./components/event-detail.js";
|
|
352
329
|
export {
|
|
353
|
-
EventCalendarField,
|
|
354
330
|
EventEditor,
|
|
355
331
|
type EventEditorLayout,
|
|
356
332
|
type EventEditorProps,
|
|
357
|
-
EventField,
|
|
358
|
-
type EventFieldProps,
|
|
359
|
-
EventGuestsField,
|
|
360
|
-
EventLocationField,
|
|
361
|
-
EventNotesField,
|
|
362
|
-
EventRepeatField,
|
|
363
|
-
EventTitleField,
|
|
364
|
-
EventWhenField,
|
|
365
333
|
endsBeforeStart,
|
|
366
334
|
withAllDay,
|
|
367
335
|
withStartDate,
|
|
@@ -370,10 +338,6 @@ export {
|
|
|
370
338
|
EventEditorPane,
|
|
371
339
|
type EventEditorPaneProps,
|
|
372
340
|
} from "./components/event-editor-pane.js";
|
|
373
|
-
export {
|
|
374
|
-
EventQuickEntry,
|
|
375
|
-
type EventQuickEntryProps,
|
|
376
|
-
} from "./components/event-quick-entry.js";
|
|
377
341
|
export {
|
|
378
342
|
EventSuggestionCard,
|
|
379
343
|
type EventSuggestionCardProps,
|
|
@@ -645,6 +609,7 @@ export {
|
|
|
645
609
|
type OutboxStatusBadgeProps,
|
|
646
610
|
outboxStatusConfig,
|
|
647
611
|
} from "./components/outbox-status-badge.js";
|
|
612
|
+
export { PaneHeader, type PaneHeaderProps } from "./components/pane-header.js";
|
|
648
613
|
export {
|
|
649
614
|
PasswordInput,
|
|
650
615
|
type PasswordInputProps,
|
|
@@ -982,7 +947,6 @@ export {
|
|
|
982
947
|
formatRunLabel,
|
|
983
948
|
formatShortDay,
|
|
984
949
|
formatSpan,
|
|
985
|
-
freeAhead,
|
|
986
950
|
freeStretchesFromSpans,
|
|
987
951
|
freeStretchesOn,
|
|
988
952
|
groupOverlapping,
|
|
@@ -994,7 +958,6 @@ export {
|
|
|
994
958
|
monthLabel,
|
|
995
959
|
type NextUp,
|
|
996
960
|
readNextUp,
|
|
997
|
-
shortMonthLabel,
|
|
998
961
|
type WallSpan,
|
|
999
962
|
wallSpanOn,
|
|
1000
963
|
weekdayLongLabel,
|
|
@@ -1069,11 +1032,7 @@ export {
|
|
|
1069
1032
|
sanitizeInlineStyle,
|
|
1070
1033
|
sanitizeStyleElementCss,
|
|
1071
1034
|
} from "./lib/email-sanitizer.js";
|
|
1072
|
-
export {
|
|
1073
|
-
addMinutesToClock,
|
|
1074
|
-
type PhraseParse,
|
|
1075
|
-
parseEventPhrase,
|
|
1076
|
-
} from "./lib/event-phrase.js";
|
|
1035
|
+
export { addMinutesToClock } from "./lib/event-phrase.js";
|
|
1077
1036
|
export {
|
|
1078
1037
|
collapseFolderTree,
|
|
1079
1038
|
filterFolderTree,
|
|
@@ -1140,20 +1099,16 @@ export {
|
|
|
1140
1099
|
} from "./lib/property-prefill.js";
|
|
1141
1100
|
export {
|
|
1142
1101
|
type CustomRecurrence,
|
|
1143
|
-
dayOfMonthLabel,
|
|
1144
1102
|
defaultCustomRecurrence,
|
|
1145
1103
|
defaultEndDate,
|
|
1146
1104
|
endDateLabel,
|
|
1147
1105
|
formatCustomRecurrence,
|
|
1148
1106
|
type MonthlyMode,
|
|
1149
1107
|
NO_REPEAT,
|
|
1150
|
-
ordinalWeekdayLabel,
|
|
1151
1108
|
type RecurrenceEnd,
|
|
1152
1109
|
type RecurrenceUnit,
|
|
1153
1110
|
readCustomRecurrence,
|
|
1154
1111
|
repeatChoices,
|
|
1155
|
-
WEEKDAY_INITIALS,
|
|
1156
|
-
weekdayName,
|
|
1157
1112
|
} from "./lib/recurrence.js";
|
|
1158
1113
|
export {
|
|
1159
1114
|
LIST_ROW_ATTRIBUTE,
|
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
minuteOfDay,
|
|
36
36
|
monthLabel,
|
|
37
37
|
readNextUp,
|
|
38
|
-
shortMonthLabel,
|
|
39
38
|
wallSpanOn,
|
|
40
39
|
weekdayLongLabel,
|
|
41
40
|
weekdayShortLabel,
|
|
@@ -589,7 +588,6 @@ describe("labels and arithmetic", () => {
|
|
|
589
588
|
it("names a day the same in every machine zone", () => {
|
|
590
589
|
inEveryZone(() => {
|
|
591
590
|
assert.equal(monthLabel(TODAY), "June 2026");
|
|
592
|
-
assert.equal(shortMonthLabel(TODAY), "Jun");
|
|
593
591
|
assert.equal(formatShortDay(TODAY), "Wed 10 Jun");
|
|
594
592
|
assert.equal(weekdayLongLabel(TODAY), "Wednesday");
|
|
595
593
|
assert.equal(weekdayShortLabel(TODAY), "Wed");
|
package/src/lib/agenda-time.ts
CHANGED
|
@@ -76,13 +76,6 @@ export function monthLabel(date: string): string {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export function shortMonthLabel(date: string): string {
|
|
80
|
-
const [year, month, day] = date.split("-").map(Number);
|
|
81
|
-
return new Date(year, month - 1, day).toLocaleDateString("en-GB", {
|
|
82
|
-
month: "short",
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
79
|
/** "Thu 11 Jun". */
|
|
87
80
|
export function formatShortDay(date: string): string {
|
|
88
81
|
const [year, month, day] = date.split("-").map(Number);
|
|
@@ -1,78 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import { addMinutesToClock
|
|
4
|
-
|
|
5
|
-
/** Wednesday 10 June 2026, 09:30 local — the fixtures' fixed "now". */
|
|
6
|
-
const NOW = new Date(2026, 5, 10, 9, 30);
|
|
7
|
-
|
|
8
|
-
describe("parseEventPhrase", () => {
|
|
9
|
-
it("reads a title, a guest, a weekday and a time", () => {
|
|
10
|
-
const parse = parseEventPhrase("lunch with Jane friday 1pm", NOW);
|
|
11
|
-
assert.equal(parse.title, "lunch");
|
|
12
|
-
assert.deepEqual(parse.attendees, ["Jane"]);
|
|
13
|
-
assert.equal(parse.date, "2026-06-12");
|
|
14
|
-
assert.equal(parse.startTime, "13:00");
|
|
15
|
-
assert.equal(parse.dateText, "friday");
|
|
16
|
-
assert.equal(parse.startTimeText, "1pm");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("assumes an hour when no length is given, and says so", () => {
|
|
20
|
-
const parse = parseEventPhrase("standup tomorrow 9:30", NOW);
|
|
21
|
-
assert.equal(parse.date, "2026-06-11");
|
|
22
|
-
assert.equal(parse.startTime, "09:30");
|
|
23
|
-
assert.equal(parse.durationMinutes, 60);
|
|
24
|
-
assert.deepEqual(parse.assumptions, ["No length given — using an hour"]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("reads an explicit length instead of assuming one", () => {
|
|
28
|
-
const parse = parseEventPhrase("dentist next tuesday 15:00 for 45m", NOW);
|
|
29
|
-
assert.equal(parse.title, "dentist");
|
|
30
|
-
assert.equal(parse.date, "2026-06-23");
|
|
31
|
-
assert.equal(parse.durationMinutes, 45);
|
|
32
|
-
assert.deepEqual(parse.assumptions, []);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("splits several guests", () => {
|
|
36
|
-
const parse = parseEventPhrase("coffee with Marcus and Dana thu 8am", NOW);
|
|
37
|
-
assert.equal(parse.title, "coffee");
|
|
38
|
-
assert.deepEqual(parse.attendees, ["Marcus", "Dana"]);
|
|
39
|
-
assert.equal(parse.date, "2026-06-11");
|
|
40
|
-
assert.equal(parse.startTime, "08:00");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("reports a missing time rather than inventing one", () => {
|
|
44
|
-
const parse = parseEventPhrase("design review monday", NOW);
|
|
45
|
-
assert.equal(parse.startTime, "");
|
|
46
|
-
assert.deepEqual(parse.unresolved, ["No time given"]);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("reports the day it fell back to", () => {
|
|
50
|
-
const parse = parseEventPhrase("call the plumber 3pm", NOW);
|
|
51
|
-
assert.equal(parse.date, "2026-06-10");
|
|
52
|
-
assert.deepEqual(parse.assumptions[0], "No day given — using today");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("reads a named hour", () => {
|
|
56
|
-
const parse = parseEventPhrase("sandwich noon", NOW);
|
|
57
|
-
assert.equal(parse.startTime, "12:00");
|
|
58
|
-
assert.equal(parse.title, "sandwich");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("has nothing to report on an empty phrase but the gaps", () => {
|
|
62
|
-
const parse = parseEventPhrase("", NOW);
|
|
63
|
-
assert.deepEqual(parse.unresolved, ["No title yet", "No time given"]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("keeps the same weekday when it is today", () => {
|
|
67
|
-
const parse = parseEventPhrase("retro wednesday 4pm", NOW);
|
|
68
|
-
assert.equal(parse.date, "2026-06-10");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("reads hours as well as minutes", () => {
|
|
72
|
-
const parse = parseEventPhrase("workshop friday 10am 2h", NOW);
|
|
73
|
-
assert.equal(parse.durationMinutes, 120);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
3
|
+
import { addMinutesToClock } from "./event-phrase.js";
|
|
76
4
|
|
|
77
5
|
describe("addMinutesToClock", () => {
|
|
78
6
|
it("advances a clock", () => {
|
package/src/lib/event-phrase.ts
CHANGED
|
@@ -1,224 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A deliberately small natural-language reader for the quick-entry field.
|
|
3
|
-
*
|
|
4
|
-
* It handles the phrasings a person actually types at a calendar — a title, a
|
|
5
|
-
* day, a time, a length, and who is coming — and it reports what it consumed
|
|
6
|
-
* for each one. The point is not coverage; it is that the machine's reading is
|
|
7
|
-
* on screen, attributed to the words it came from, before anything is
|
|
8
|
-
* committed. Whatever it could not settle comes back in `unresolved`, and
|
|
9
|
-
* whatever it filled in for you comes back in `assumptions`. Both are meant to
|
|
10
|
-
* be rendered, not swallowed.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export interface PhraseParse {
|
|
14
|
-
/** What is left after the day, time, length and guests are taken out. */
|
|
15
|
-
title: string;
|
|
16
|
-
/** `YYYY-MM-DD`, empty when the phrase named no day. */
|
|
17
|
-
date: string;
|
|
18
|
-
/** The words the day was read from, e.g. "friday". */
|
|
19
|
-
dateText: string;
|
|
20
|
-
/** `HH:MM` on a 24-hour clock, empty when the phrase named no time. */
|
|
21
|
-
startTime: string;
|
|
22
|
-
startTimeText: string;
|
|
23
|
-
/** Minutes; 0 when the phrase named no length. */
|
|
24
|
-
durationMinutes: number;
|
|
25
|
-
durationText: string;
|
|
26
|
-
attendees: string[];
|
|
27
|
-
attendeesText: string;
|
|
28
|
-
/** Things the phrase never said, in the words the UI should show. */
|
|
29
|
-
unresolved: string[];
|
|
30
|
-
/** Defaults applied on the reader's own authority. */
|
|
31
|
-
assumptions: string[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const WEEKDAYS: Record<string, number> = {
|
|
35
|
-
sun: 0,
|
|
36
|
-
sunday: 0,
|
|
37
|
-
mon: 1,
|
|
38
|
-
monday: 1,
|
|
39
|
-
tue: 2,
|
|
40
|
-
tues: 2,
|
|
41
|
-
tuesday: 2,
|
|
42
|
-
wed: 3,
|
|
43
|
-
weds: 3,
|
|
44
|
-
wednesday: 3,
|
|
45
|
-
thu: 4,
|
|
46
|
-
thur: 4,
|
|
47
|
-
thurs: 4,
|
|
48
|
-
thursday: 4,
|
|
49
|
-
fri: 5,
|
|
50
|
-
friday: 5,
|
|
51
|
-
sat: 6,
|
|
52
|
-
saturday: 6,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const WEEKDAY_ALTERNATION = Object.keys(WEEKDAYS)
|
|
56
|
-
.sort((a, b) => b.length - a.length)
|
|
57
|
-
.join("|");
|
|
58
|
-
|
|
59
|
-
const DURATION_RE =
|
|
60
|
-
/\b(?:for\s+)?(\d+(?:[.,]\d+)?)\s*(hours|hour|hrs|hr|h|minutes|minute|mins|min|m)\b/i;
|
|
61
|
-
const CLOCK_RE =
|
|
62
|
-
/\b(\d{1,2})(?:[:.](\d{2}))?\s*(am|pm)\b|\b(\d{1,2}):(\d{2})\b/i;
|
|
63
|
-
const NOON_RE = /\b(noon|midday|midnight)\b/i;
|
|
64
|
-
const RELATIVE_DAY_RE = /\b(today|tonight|tomorrow)\b/i;
|
|
65
|
-
const NEXT_WEEKDAY_RE = new RegExp(
|
|
66
|
-
`\\bnext\\s+(${WEEKDAY_ALTERNATION})\\b`,
|
|
67
|
-
"i",
|
|
68
|
-
);
|
|
69
|
-
const WEEKDAY_RE = new RegExp(`\\b(?:on\\s+)?(${WEEKDAY_ALTERNATION})\\b`, "i");
|
|
70
|
-
const WITH_RE = /\bwith\s+(.+)$/i;
|
|
71
|
-
|
|
72
1
|
function pad(n: number): string {
|
|
73
2
|
return String(n).padStart(2, "0");
|
|
74
3
|
}
|
|
75
4
|
|
|
76
|
-
function isoDate(d: Date): string {
|
|
77
|
-
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function addDays(d: Date, days: number): Date {
|
|
81
|
-
const next = new Date(d);
|
|
82
|
-
next.setDate(next.getDate() + days);
|
|
83
|
-
return next;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** The soonest day with this weekday, today included. */
|
|
87
|
-
function comingWeekday(now: Date, weekday: number): Date {
|
|
88
|
-
return addDays(now, (weekday - now.getDay() + 7) % 7);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function minutesFrom(amount: number, unit: string): number {
|
|
92
|
-
const isHours = /^h/i.test(unit);
|
|
93
|
-
return Math.round(isHours ? amount * 60 : amount);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function cut(source: string, match: RegExpMatchArray): string {
|
|
97
|
-
const at = match.index ?? 0;
|
|
98
|
-
return `${source.slice(0, at)} ${source.slice(at + match[0].length)}`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function tidy(text: string): string {
|
|
102
|
-
return text
|
|
103
|
-
.replace(/\s+/g, " ")
|
|
104
|
-
.replace(/^[\s,;–-]+|[\s,;–-]+$/g, "")
|
|
105
|
-
.replace(/\s+(on|at|with|for|from)$/i, "")
|
|
106
|
-
.trim();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function splitNames(clause: string): string[] {
|
|
110
|
-
return clause
|
|
111
|
-
.split(/\s*(?:,|\band\b|&)\s*/i)
|
|
112
|
-
.map((name) => tidy(name))
|
|
113
|
-
.filter((name) => name.length > 0);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function readClock(match: RegExpMatchArray): string {
|
|
117
|
-
if (match[3]) {
|
|
118
|
-
const meridiem = match[3].toLowerCase();
|
|
119
|
-
const hour12 = Number(match[1]) % 12;
|
|
120
|
-
const hour = meridiem === "pm" ? hour12 + 12 : hour12;
|
|
121
|
-
return `${pad(hour)}:${pad(Number(match[2] ?? 0))}`;
|
|
122
|
-
}
|
|
123
|
-
return `${pad(Number(match[4]))}:${pad(Number(match[5]))}`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Reads `phrase` against `now`. `now` is a parameter rather than a call to the
|
|
128
|
-
* clock so the same phrase always gives the same answer in a story and a test.
|
|
129
|
-
*/
|
|
130
|
-
export function parseEventPhrase(phrase: string, now: Date): PhraseParse {
|
|
131
|
-
let rest = ` ${phrase} `;
|
|
132
|
-
const unresolved: string[] = [];
|
|
133
|
-
const assumptions: string[] = [];
|
|
134
|
-
|
|
135
|
-
let durationMinutes = 0;
|
|
136
|
-
let durationText = "";
|
|
137
|
-
const duration = rest.match(DURATION_RE);
|
|
138
|
-
if (duration) {
|
|
139
|
-
durationMinutes = minutesFrom(
|
|
140
|
-
Number(duration[1].replace(",", ".")),
|
|
141
|
-
duration[2],
|
|
142
|
-
);
|
|
143
|
-
durationText = duration[0].trim();
|
|
144
|
-
rest = cut(rest, duration);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let startTime = "";
|
|
148
|
-
let startTimeText = "";
|
|
149
|
-
const named = rest.match(NOON_RE);
|
|
150
|
-
const clock = rest.match(CLOCK_RE);
|
|
151
|
-
if (named) {
|
|
152
|
-
const word = named[1].toLowerCase();
|
|
153
|
-
startTime = word === "midnight" ? "00:00" : "12:00";
|
|
154
|
-
startTimeText = named[0].trim();
|
|
155
|
-
rest = cut(rest, named);
|
|
156
|
-
} else if (clock) {
|
|
157
|
-
startTime = readClock(clock);
|
|
158
|
-
startTimeText = clock[0].trim();
|
|
159
|
-
rest = cut(rest, clock);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
let date = "";
|
|
163
|
-
let dateText = "";
|
|
164
|
-
const relative = rest.match(RELATIVE_DAY_RE);
|
|
165
|
-
const nextWeekday = rest.match(NEXT_WEEKDAY_RE);
|
|
166
|
-
const weekday = rest.match(WEEKDAY_RE);
|
|
167
|
-
if (relative) {
|
|
168
|
-
const word = relative[1].toLowerCase();
|
|
169
|
-
date = isoDate(word === "tomorrow" ? addDays(now, 1) : now);
|
|
170
|
-
dateText = relative[0].trim();
|
|
171
|
-
rest = cut(rest, relative);
|
|
172
|
-
} else if (nextWeekday) {
|
|
173
|
-
date = isoDate(
|
|
174
|
-
addDays(comingWeekday(now, WEEKDAYS[nextWeekday[1].toLowerCase()]), 7),
|
|
175
|
-
);
|
|
176
|
-
dateText = nextWeekday[0].trim();
|
|
177
|
-
rest = cut(rest, nextWeekday);
|
|
178
|
-
} else if (weekday) {
|
|
179
|
-
date = isoDate(comingWeekday(now, WEEKDAYS[weekday[1].toLowerCase()]));
|
|
180
|
-
dateText = weekday[0].trim();
|
|
181
|
-
rest = cut(rest, weekday);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let attendees: string[] = [];
|
|
185
|
-
let attendeesText = "";
|
|
186
|
-
const guests = tidy(rest).match(WITH_RE);
|
|
187
|
-
if (guests) {
|
|
188
|
-
attendees = splitNames(guests[1]);
|
|
189
|
-
attendeesText = guests[0].trim();
|
|
190
|
-
rest = tidy(rest).slice(0, guests.index ?? 0);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const title = tidy(rest);
|
|
194
|
-
|
|
195
|
-
if (title === "") unresolved.push("No title yet");
|
|
196
|
-
if (date === "") {
|
|
197
|
-
date = isoDate(now);
|
|
198
|
-
assumptions.push("No day given — using today");
|
|
199
|
-
}
|
|
200
|
-
if (startTime === "") {
|
|
201
|
-
unresolved.push("No time given");
|
|
202
|
-
} else if (durationMinutes === 0) {
|
|
203
|
-
durationMinutes = 60;
|
|
204
|
-
assumptions.push("No length given — using an hour");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
title,
|
|
209
|
-
date,
|
|
210
|
-
dateText,
|
|
211
|
-
startTime,
|
|
212
|
-
startTimeText,
|
|
213
|
-
durationMinutes,
|
|
214
|
-
durationText,
|
|
215
|
-
attendees,
|
|
216
|
-
attendeesText,
|
|
217
|
-
unresolved,
|
|
218
|
-
assumptions,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
5
|
/** `13:00` + 90 → `14:30`. Empty in, empty out. */
|
|
223
6
|
export function addMinutesToClock(clock: string, minutes: number): string {
|
|
224
7
|
if (clock === "") return "";
|
package/src/lib/recurrence.ts
CHANGED
|
@@ -90,9 +90,6 @@ export interface CustomRecurrence {
|
|
|
90
90
|
ends: RecurrenceEnd;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
/** Single-letter weekday labels, Sunday first, for a row of toggles. */
|
|
94
|
-
export const WEEKDAY_INITIALS = ["S", "M", "T", "W", "T", "F", "S"];
|
|
95
|
-
|
|
96
93
|
export const weekdayName = (index: number): string => WEEKDAY_NAMES[index];
|
|
97
94
|
|
|
98
95
|
function parseDate(date: string): Date | undefined {
|