@remit/ui 0.0.211 → 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/index.ts +1 -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
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,
|
|
@@ -983,7 +947,6 @@ export {
|
|
|
983
947
|
formatRunLabel,
|
|
984
948
|
formatShortDay,
|
|
985
949
|
formatSpan,
|
|
986
|
-
freeAhead,
|
|
987
950
|
freeStretchesFromSpans,
|
|
988
951
|
freeStretchesOn,
|
|
989
952
|
groupOverlapping,
|
|
@@ -995,7 +958,6 @@ export {
|
|
|
995
958
|
monthLabel,
|
|
996
959
|
type NextUp,
|
|
997
960
|
readNextUp,
|
|
998
|
-
shortMonthLabel,
|
|
999
961
|
type WallSpan,
|
|
1000
962
|
wallSpanOn,
|
|
1001
963
|
weekdayLongLabel,
|
|
@@ -1070,11 +1032,7 @@ export {
|
|
|
1070
1032
|
sanitizeInlineStyle,
|
|
1071
1033
|
sanitizeStyleElementCss,
|
|
1072
1034
|
} from "./lib/email-sanitizer.js";
|
|
1073
|
-
export {
|
|
1074
|
-
addMinutesToClock,
|
|
1075
|
-
type PhraseParse,
|
|
1076
|
-
parseEventPhrase,
|
|
1077
|
-
} from "./lib/event-phrase.js";
|
|
1035
|
+
export { addMinutesToClock } from "./lib/event-phrase.js";
|
|
1078
1036
|
export {
|
|
1079
1037
|
collapseFolderTree,
|
|
1080
1038
|
filterFolderTree,
|
|
@@ -1141,20 +1099,16 @@ export {
|
|
|
1141
1099
|
} from "./lib/property-prefill.js";
|
|
1142
1100
|
export {
|
|
1143
1101
|
type CustomRecurrence,
|
|
1144
|
-
dayOfMonthLabel,
|
|
1145
1102
|
defaultCustomRecurrence,
|
|
1146
1103
|
defaultEndDate,
|
|
1147
1104
|
endDateLabel,
|
|
1148
1105
|
formatCustomRecurrence,
|
|
1149
1106
|
type MonthlyMode,
|
|
1150
1107
|
NO_REPEAT,
|
|
1151
|
-
ordinalWeekdayLabel,
|
|
1152
1108
|
type RecurrenceEnd,
|
|
1153
1109
|
type RecurrenceUnit,
|
|
1154
1110
|
readCustomRecurrence,
|
|
1155
1111
|
repeatChoices,
|
|
1156
|
-
WEEKDAY_INITIALS,
|
|
1157
|
-
weekdayName,
|
|
1158
1112
|
} from "./lib/recurrence.js";
|
|
1159
1113
|
export {
|
|
1160
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 {
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typing is the create path, so the field is never off screen and the reading
|
|
3
|
-
* of the sentence is shown back with the words each part came from. Where the
|
|
4
|
-
* sentence has two honest readings the reader is asked, and that question is a
|
|
5
|
-
* control rather than a note — both are asserted here.
|
|
6
|
-
*/
|
|
7
|
-
import "@remit/test-dom";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { describe, it } from "node:test";
|
|
10
|
-
import { createElement } from "react";
|
|
11
|
-
import { renderToString } from "react-dom/server";
|
|
12
|
-
import {
|
|
13
|
-
AgendaComposer,
|
|
14
|
-
type AgendaComposerProps,
|
|
15
|
-
AgendaPhraseField,
|
|
16
|
-
PhraseReading,
|
|
17
|
-
} from "./agenda-composer.js";
|
|
18
|
-
import type {
|
|
19
|
-
AgendaParse,
|
|
20
|
-
CalendarDescriptor,
|
|
21
|
-
EventDraft,
|
|
22
|
-
} from "./calendar-types.js";
|
|
23
|
-
|
|
24
|
-
const calendars: CalendarDescriptor[] = [
|
|
25
|
-
{
|
|
26
|
-
id: "c1",
|
|
27
|
-
accountId: "a1",
|
|
28
|
-
accountLabel: "Work",
|
|
29
|
-
name: "Northwind",
|
|
30
|
-
color: "cal-1",
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
const draft: EventDraft = {
|
|
35
|
-
title: "Lunch with Jane",
|
|
36
|
-
date: "2026-06-12",
|
|
37
|
-
startTime: "13:00",
|
|
38
|
-
endDate: "2026-06-12",
|
|
39
|
-
endTime: "14:00",
|
|
40
|
-
allDay: false,
|
|
41
|
-
calendarId: "c1",
|
|
42
|
-
location: "",
|
|
43
|
-
guests: "Jane",
|
|
44
|
-
notes: "",
|
|
45
|
-
repeat: "",
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const parse: AgendaParse = {
|
|
49
|
-
title: "Lunch with Jane",
|
|
50
|
-
date: "2026-06-12",
|
|
51
|
-
dateText: "friday",
|
|
52
|
-
startTime: "13:00",
|
|
53
|
-
startTimeText: "1pm",
|
|
54
|
-
endTime: "14:00",
|
|
55
|
-
durationMinutes: 60,
|
|
56
|
-
durationText: "",
|
|
57
|
-
attendees: ["Jane"],
|
|
58
|
-
attendeesText: "with Jane",
|
|
59
|
-
location: "",
|
|
60
|
-
locationText: "",
|
|
61
|
-
repeat: "",
|
|
62
|
-
repeatText: "",
|
|
63
|
-
assumptions: ["An hour, because the sentence never said."],
|
|
64
|
-
unresolved: [],
|
|
65
|
-
choices: [],
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const ambiguous: AgendaParse = {
|
|
69
|
-
...parse,
|
|
70
|
-
unresolved: ["No place given."],
|
|
71
|
-
choices: [
|
|
72
|
-
{
|
|
73
|
-
id: "which_friday",
|
|
74
|
-
question: "Which Friday?",
|
|
75
|
-
source: "friday",
|
|
76
|
-
options: [
|
|
77
|
-
{ id: "this", label: "12 June", date: "2026-06-12", startTime: "" },
|
|
78
|
-
{ id: "next", label: "19 June", date: "2026-06-19", startTime: "" },
|
|
79
|
-
],
|
|
80
|
-
chosenId: "this",
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const base: AgendaComposerProps = {
|
|
86
|
-
phrase: "lunch with Jane friday 1pm",
|
|
87
|
-
onPhraseChange: () => {},
|
|
88
|
-
parse,
|
|
89
|
-
picks: {},
|
|
90
|
-
onPick: () => {},
|
|
91
|
-
draft,
|
|
92
|
-
onDraftChange: () => {},
|
|
93
|
-
calendars,
|
|
94
|
-
expanded: false,
|
|
95
|
-
onToggleExpanded: () => {},
|
|
96
|
-
onSave: () => {},
|
|
97
|
-
onCancel: () => {},
|
|
98
|
-
open: true,
|
|
99
|
-
onOpen: () => {},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const render = (props: Partial<AgendaComposerProps> = {}) =>
|
|
103
|
-
renderToString(createElement(AgendaComposer, { ...base, ...props }));
|
|
104
|
-
|
|
105
|
-
describe("AgendaPhraseField", () => {
|
|
106
|
-
it("names the field rather than leaving the placeholder to do it", () => {
|
|
107
|
-
const html = renderToString(
|
|
108
|
-
createElement(AgendaPhraseField, {
|
|
109
|
-
phrase: "",
|
|
110
|
-
onPhraseChange: () => {},
|
|
111
|
-
onOpen: () => {},
|
|
112
|
-
onCommit: () => {},
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
assert.match(html, /aria-label="Describe the event"/);
|
|
116
|
-
assert.match(html, /placeholder="lunch with Jane friday 1pm"/);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("grows the field where a finger has to hit it", () => {
|
|
120
|
-
const html = renderToString(
|
|
121
|
-
createElement(AgendaPhraseField, {
|
|
122
|
-
phrase: "",
|
|
123
|
-
onPhraseChange: () => {},
|
|
124
|
-
onOpen: () => {},
|
|
125
|
-
onCommit: () => {},
|
|
126
|
-
touch: true,
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
assert.match(html, /min-h-11/);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe("AgendaComposer", () => {
|
|
134
|
-
it("folds the form away until the reader opens it", () => {
|
|
135
|
-
assert.doesNotMatch(render({ open: false }), /Northwind/);
|
|
136
|
-
assert.match(render(), /Northwind/);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("shows the reading back with the words each part came from", () => {
|
|
140
|
-
const html = render();
|
|
141
|
-
assert.match(html, /When/);
|
|
142
|
-
assert.match(html, /friday 1pm/);
|
|
143
|
-
assert.match(html, /Fri 12 Jun 13:00 – 14:00/);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("keeps the reading off screen while there is nothing to read", () => {
|
|
147
|
-
const html = render({ phrase: " " });
|
|
148
|
-
assert.doesNotMatch(html, /An hour, because the sentence never said./);
|
|
149
|
-
assert.doesNotMatch(html, /bg-accent-2-soft/);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("says a date on its own when the sentence gave no clock", () => {
|
|
153
|
-
const html = renderToString(
|
|
154
|
-
createElement(PhraseReading, {
|
|
155
|
-
parse: { ...parse, startTime: "", startTimeText: "" },
|
|
156
|
-
picks: {},
|
|
157
|
-
onPick: () => {},
|
|
158
|
-
}),
|
|
159
|
-
);
|
|
160
|
-
assert.match(html, /Fri 12 Jun/);
|
|
161
|
-
assert.doesNotMatch(html, /13:00/);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("asks about a reading it could not settle instead of choosing", () => {
|
|
165
|
-
const html = render({ parse: ambiguous });
|
|
166
|
-
assert.match(html, /Which Friday\?/);
|
|
167
|
-
assert.match(html, /12 June/);
|
|
168
|
-
assert.match(html, /19 June/);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("says which reading is currently applied", () => {
|
|
172
|
-
const html = render({ parse: ambiguous });
|
|
173
|
-
assert.match(html, /aria-pressed="true"/);
|
|
174
|
-
assert.match(html, /aria-pressed="false"/);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("lets an answer override the reading the parser chose", () => {
|
|
178
|
-
const html = renderToString(
|
|
179
|
-
createElement(PhraseReading, {
|
|
180
|
-
parse: ambiguous,
|
|
181
|
-
picks: { which_friday: "next" },
|
|
182
|
-
onPick: () => {},
|
|
183
|
-
}),
|
|
184
|
-
);
|
|
185
|
-
const chosen = html.indexOf('aria-pressed="true"');
|
|
186
|
-
assert.ok(chosen > html.indexOf("12 June"), "the second option is pressed");
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("separates what it assumed from what the sentence never said", () => {
|
|
190
|
-
assert.match(render(), /An hour, because the sentence never said\./);
|
|
191
|
-
assert.match(render({ parse: ambiguous }), /No place given\./);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("names the guests the sentence carried", () => {
|
|
195
|
-
assert.match(render(), /with Jane/);
|
|
196
|
-
});
|
|
197
|
-
});
|