@burdenoff/microfe-calendar 2026.1124.3 → 2026.1124.4

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.
Files changed (88) hide show
  1. package/dist/generated/wspace-operations.d.ts +342 -69
  2. package/dist/generated/wspace-operations.js +73 -31
  3. package/dist/generated/wspace-operations.js.map +1 -1
  4. package/dist/generated/wspace-types.d.ts +405 -6
  5. package/dist/translations/en.d.ts +22 -4
  6. package/dist/v2/CalendarPageV2.js +45 -41
  7. package/dist/v2/CalendarPageV2.js.map +1 -1
  8. package/dist/v2/CalendarRoutesV2.js +64 -64
  9. package/dist/v2/CalendarRoutesV2.js.map +1 -1
  10. package/dist/v2/data/errors.d.ts +5 -0
  11. package/dist/v2/data/errors.js +6 -2
  12. package/dist/v2/data/errors.js.map +1 -1
  13. package/dist/v2/data/normalize.d.ts +31 -3
  14. package/dist/v2/data/normalize.js +57 -13
  15. package/dist/v2/data/normalize.js.map +1 -1
  16. package/dist/v2/data/seriesDateLookup.d.ts +9 -0
  17. package/dist/v2/data/seriesDateLookup.js +12 -0
  18. package/dist/v2/data/seriesDateLookup.js.map +1 -0
  19. package/dist/v2/data/useEventActions.d.ts +9 -3
  20. package/dist/v2/data/useEventActions.js +239 -186
  21. package/dist/v2/data/useEventActions.js.map +1 -1
  22. package/dist/v2/data/useEventForPeek.js +63 -21
  23. package/dist/v2/data/useEventForPeek.js.map +1 -1
  24. package/dist/v2/data/useEventsInRangeV2.d.ts +40 -2
  25. package/dist/v2/data/useEventsInRangeV2.js +76 -47
  26. package/dist/v2/data/useEventsInRangeV2.js.map +1 -1
  27. package/dist/v2/day/DayPanel.js +1 -1
  28. package/dist/v2/day/DayPanel.js.map +1 -1
  29. package/dist/v2/event/EventDialog.d.ts +13 -3
  30. package/dist/v2/event/EventDialog.js +189 -166
  31. package/dist/v2/event/EventDialog.js.map +1 -1
  32. package/dist/v2/event/EventDialogs.js +57 -50
  33. package/dist/v2/event/EventDialogs.js.map +1 -1
  34. package/dist/v2/event/EventMoreTab.js +8 -7
  35. package/dist/v2/event/EventMoreTab.js.map +1 -1
  36. package/dist/v2/event/EventPlaceTab.js +2 -2
  37. package/dist/v2/event/EventPlaceTab.js.map +1 -1
  38. package/dist/v2/event/FindTimeDialog.js +1 -1
  39. package/dist/v2/event/FindTimeDialog.js.map +1 -1
  40. package/dist/v2/event/RepeatField.js +10 -7
  41. package/dist/v2/event/RepeatField.js.map +1 -1
  42. package/dist/v2/event/dialogLogic.d.ts +10 -0
  43. package/dist/v2/event/dialogLogic.js +25 -22
  44. package/dist/v2/event/dialogLogic.js.map +1 -1
  45. package/dist/v2/event/dialogModel.d.ts +3 -0
  46. package/dist/v2/event/dialogModel.js.map +1 -1
  47. package/dist/v2/event/eventForm.d.ts +26 -0
  48. package/dist/v2/event/eventForm.js +145 -92
  49. package/dist/v2/event/eventForm.js.map +1 -1
  50. package/dist/v2/event/findTimeSource.js +44 -44
  51. package/dist/v2/event/findTimeSource.js.map +1 -1
  52. package/dist/v2/event/rrule.js.map +1 -1
  53. package/dist/v2/event/savePlan.d.ts +125 -15
  54. package/dist/v2/event/savePlan.js +162 -68
  55. package/dist/v2/event/savePlan.js.map +1 -1
  56. package/dist/v2/event/useEventData.d.ts +7 -2
  57. package/dist/v2/event/useEventData.js +107 -80
  58. package/dist/v2/event/useEventData.js.map +1 -1
  59. package/dist/v2/event/useEventDialogModel.d.ts +16 -3
  60. package/dist/v2/event/useEventDialogModel.js +82 -67
  61. package/dist/v2/event/useEventDialogModel.js.map +1 -1
  62. package/dist/v2/event/useEventSave.d.ts +20 -4
  63. package/dist/v2/event/useEventSave.js +181 -90
  64. package/dist/v2/event/useEventSave.js.map +1 -1
  65. package/dist/v2/events/eventLook.js +16 -16
  66. package/dist/v2/events/eventLook.js.map +1 -1
  67. package/dist/v2/events/eventModel.d.ts +17 -4
  68. package/dist/v2/events/eventModel.js +46 -34
  69. package/dist/v2/events/eventModel.js.map +1 -1
  70. package/dist/v2/events/localChanges.d.ts +4 -1
  71. package/dist/v2/events/localChanges.js +4 -2
  72. package/dist/v2/events/localChanges.js.map +1 -1
  73. package/dist/v2/page/CalendarPageContext.d.ts +2 -2
  74. package/dist/v2/page/CalendarPageContext.js.map +1 -1
  75. package/dist/v2/page/useCalendarPageModel.js +141 -139
  76. package/dist/v2/page/useCalendarPageModel.js.map +1 -1
  77. package/dist/v2/page/viewState.d.ts +9 -1
  78. package/dist/v2/page/viewState.js +5 -3
  79. package/dist/v2/page/viewState.js.map +1 -1
  80. package/dist/v2/peek/PeekEvent.js +210 -204
  81. package/dist/v2/peek/PeekEvent.js.map +1 -1
  82. package/dist/v2/rail/useMonthEventDates.js +1 -1
  83. package/dist/v2/rail/useMonthEventDates.js.map +1 -1
  84. package/dist/v2/states/CalendarStates.d.ts +15 -0
  85. package/dist/v2/states/CalendarStates.js +42 -11
  86. package/dist/v2/states/CalendarStates.js.map +1 -1
  87. package/dist/v2/types.d.ts +30 -2
  88. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"eventForm.js","names":["MINUTE_MS","LENGTH_CHIPS","startWall","instantToZoned","form","endWall","firstDayOf","startInstant","endInstant","addDays","lengthMinutes","lengthChip","length","startingAt","start","followingStart","after","repeatFollowingStart","before","anchorOf","withStartDate","date","days","dayDifference","wall","zonedTimeToInstant","withStartTime","minutes","withEndTime","day","nextDay","withEndClock","withEndDate","withLength","withAllDay","allDay","first","lastMoment","last","withTimeZone","timeZone","end","wallIn","withSlot","slot","repeat","followStart","offered","presetsFor","presetRule","repeatRuleOf","rruleOf","rule","buildRRule","repeatStateOf","parsed","parseRRule","rrule","anchor","preset","presetOf","isEmailAddress","text","guestKey","guest","addressOfGuest","email","withGuests","guests","keys","changed","person","people","organizerId","key","address","same","already","withoutGuest","withReminder","reminder","minutesBefore","channel","reminders","a","b","withoutReminder","videoOf","event","addressOf","location","locationIsRoomName","availabilitySpan","startOfDayInZone","calendarTimeZone","name","eventRoom","defaultReminders","defaults","draftLength","from","newEventForm","draft","startMinutes","formFromEvent","room","activeRoom","eventDays","formIssues","issues","safeWebUrl","problem","ruleProblem","hasIssues","sameForm","comparable"],"sources":["../../../src/v2/event/eventForm.ts"],"sourcesContent":["/**\n * The event dialog's form (BOFF-15698 A2): what the person sets, and the rules between the\n * fields. Pure.\n *\n * - A timed event is its start and end instants, shown on its own zone's clock (the Time zone\n * field). Instants, not clock times, so an event ending in the second 01:30 of 25 October in\n * London keeps its end: a clock time names only the first. Lengths are real time: \"1 h\" from\n * 00:30 on 29 March ends at 02:30; a clock time the clocks skip (01:30 then) becomes the time\n * after the gap (02:30), as the grid reads it.\n * - An all-day event is its first and last day, floating: it is written at UTC midnights (the\n * API's own rule, which the .ics export and free/busy read), the same days wherever it is read.\n * Its start and end instants are kept meanwhile: switching All day back off restores them.\n * - Changing the time zone keeps the clock times shown (\"09:00 in New York\") and moves the\n * instants; `wallIn` says where they land on the calendar's clock.\n * - Moving the start keeps the length. The end can't come before the start.\n */\nimport { addDays, type DateValue } from '@burdenoff/fe-libs/ui';\nimport { eventRoom, safeWebUrl } from '../events/eventModel';\nimport {\n dayDifference,\n eventDays,\n instantToZoned,\n startOfDayInZone,\n zonedTimeToInstant,\n} from '../time/calendarTime';\nimport type {\n CalendarEventV2,\n CalendarV2EventDraft,\n EventResponseV2,\n EventVisibilityV2,\n} from '../types';\nimport {\n buildRRule,\n followStart,\n parseRRule,\n presetOf,\n presetRule,\n presetsFor,\n ruleProblem,\n type RepeatPreset,\n type RepeatRule,\n type RuleAnchor,\n type RuleProblem,\n} from './rrule';\n\nconst MINUTE_MS = 60_000;\n\n/** The Length chips, in minutes. */\nexport const LENGTH_CHIPS: readonly number[] = [30, 45, 60, 90];\n\nexport interface GuestDraft {\n /** `u:<userId>` for a member, `e:<email>` for anyone else. */\n key: string;\n userId: string | null;\n email: string | null;\n name: string | null;\n optional: boolean;\n /** The guest's row, for someone the event already has. */\n attendeeId: string | null;\n response: EventResponseV2 | null;\n}\n\nexport type ReminderChannelV2 = 'IN_APP' | 'EMAIL' | 'SMS';\n\nexport interface ReminderDraft {\n /** `r:<id>` for a reminder the event has, `<channel>:<minutes>` for a new one. */\n key: string;\n minutesBefore: number;\n channel: ReminderChannelV2;\n /** The reminder's row, for one the event already has. */\n reminderId: string | null;\n}\n\nexport type RepeatState =\n | { kind: 'none' }\n /** A menu preset, worked out from the start whenever it moves. */\n | { kind: 'preset'; preset: RepeatPreset }\n | { kind: 'custom'; rule: RepeatRule }\n /** A stored rule the builder can't hold, kept as it is. */\n | { kind: 'kept'; text: string };\n\nexport interface EventForm {\n title: string;\n allDay: boolean;\n /** Timed: when it starts and ends. All-day: the times to go back to when it is switched off. */\n start: Date;\n end: Date;\n /** All-day: the first and last day, both included. */\n firstDay: DateValue;\n lastDay: DateValue;\n timeZone: string;\n repeat: RepeatState;\n description: string;\n guests: GuestDraft[];\n roomId: string | null;\n videoUrl: string;\n address: string;\n calendarId: string | null;\n visibility: EventVisibilityV2;\n reminders: ReminderDraft[];\n}\n\n/** What a new event starts with besides its draft. */\nexport interface NewFormDefaults {\n /** The calendar's zone. */\n timeZone: string;\n today: DateValue;\n /** Minutes. */\n defaultLength: number;\n /** Minutes before, or null for none. */\n defaultReminder: number | null;\n defaultCalendarId: string | null;\n}\n\n/** A day, and minutes after its midnight on a clock. */\nexport interface WallTime {\n date: DateValue;\n minutes: number;\n}\n\n// ── Times ────────────────────────────────────────────────────────────────────\n\n/** Where the start shows on the event's own clock. */\nexport function startWall(form: EventForm): WallTime {\n return instantToZoned(form.start, form.timeZone);\n}\n\n/** Where the end shows on the event's own clock. */\nexport function endWall(form: EventForm): WallTime {\n return instantToZoned(form.end, form.timeZone);\n}\n\n/** The event's first day: an all-day event's own, else its start's on its clock. */\nexport function firstDayOf(form: EventForm): DateValue {\n return form.allDay ? form.firstDay : startWall(form).date;\n}\n\n/** When the event starts: the instant, or the UTC midnight of an all-day event's first day. */\nexport function startInstant(form: EventForm): Date {\n return form.allDay ? new Date(`${form.firstDay}T00:00:00.000Z`) : form.start;\n}\n\n/** When it ends: the instant, or the UTC midnight after an all-day event's last day. */\nexport function endInstant(form: EventForm): Date {\n return form.allDay ? new Date(`${addDays(form.lastDay, 1)}T00:00:00.000Z`) : form.end;\n}\n\n/** How long a timed event lasts, in real minutes. */\nexport function lengthMinutes(form: EventForm): number {\n return Math.round((form.end.getTime() - form.start.getTime()) / MINUTE_MS);\n}\n\n/** The Length chip the event's length is, if it is one. */\nexport function lengthChip(form: EventForm): number | null {\n if (form.allDay) return null;\n const length = lengthMinutes(form);\n return LENGTH_CHIPS.includes(length) ? length : null;\n}\n\n/** A start, and an end `length` real minutes after it (the length never below a minute). */\nfunction startingAt(form: EventForm, start: Date, length: number): EventForm {\n return { ...form, start, end: new Date(start.getTime() + Math.max(1, length) * MINUTE_MS) };\n}\n\n/** The form after its start moved: its repeat follows, so the start stays an occurrence. */\nfunction followingStart(before: EventForm, after: EventForm): EventForm {\n return {\n ...after,\n repeat: repeatFollowingStart(before.repeat, anchorOf(before), anchorOf(after)),\n };\n}\n\n/** The start on another day, the length kept (all-day: the number of days kept). */\nexport function withStartDate(form: EventForm, date: DateValue): EventForm {\n if (form.allDay) {\n if (date === form.firstDay) return form;\n const days = Math.max(0, dayDifference(form.firstDay, form.lastDay));\n return followingStart(form, { ...form, firstDay: date, lastDay: addDays(date, days) });\n }\n const wall = startWall(form);\n if (date === wall.date) return form;\n const start = zonedTimeToInstant(date, wall.minutes, form.timeZone);\n return followingStart(form, startingAt(form, start, lengthMinutes(form)));\n}\n\n/** The start at another time of its day, the length kept. */\nexport function withStartTime(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n const start = zonedTimeToInstant(startWall(form).date, minutes, form.timeZone);\n return followingStart(form, startingAt(form, start, lengthMinutes(form)));\n}\n\n/**\n * The end picked in the end picker beside the start, whose times run on past midnight\n * (`nextDay`): on the start's day, or the day after.\n */\nexport function withEndTime(form: EventForm, minutes: number, nextDay: boolean): EventForm {\n if (form.allDay) return form;\n const day = startWall(form).date;\n return {\n ...form,\n end: zonedTimeToInstant(nextDay ? addDays(day, 1) : day, minutes, form.timeZone),\n };\n}\n\n/** The end's time on its own day (an event of more than a day has an end date of its own). */\nexport function withEndClock(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n return { ...form, end: zonedTimeToInstant(endWall(form).date, minutes, form.timeZone) };\n}\n\n/** The end's day (timed), or the last day (all-day). */\nexport function withEndDate(form: EventForm, date: DateValue): EventForm {\n if (form.allDay) return { ...form, lastDay: date };\n return { ...form, end: zonedTimeToInstant(date, endWall(form).minutes, form.timeZone) };\n}\n\n/** The Length chips: the end `minutes` real minutes after the start. */\nexport function withLength(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n return startingAt(form, form.start, minutes);\n}\n\n/**\n * All day on or off. On: the days the times touch (an end at midnight doesn't add its day).\n * Off: the times it had, on its first day.\n */\nexport function withAllDay(form: EventForm, allDay: boolean): EventForm {\n if (form.allDay === allDay) return form;\n if (allDay) {\n const first = startWall(form).date;\n const lastMoment = new Date(Math.max(form.start.getTime(), form.end.getTime() - 1));\n const last = instantToZoned(lastMoment, form.timeZone).date;\n return { ...form, allDay: true, firstDay: first, lastDay: last < first ? first : last };\n }\n const start = zonedTimeToInstant(form.firstDay, startWall(form).minutes, form.timeZone);\n return followingStart(form, startingAt({ ...form, allDay: false }, start, lengthMinutes(form)));\n}\n\n/** The time zone, keeping the clock times shown (a time the new zone skips moves past the gap). */\nexport function withTimeZone(form: EventForm, timeZone: string): EventForm {\n if (timeZone === form.timeZone) return form;\n const start = startWall(form);\n const end = endWall(form);\n return {\n ...form,\n timeZone,\n start: zonedTimeToInstant(start.date, start.minutes, timeZone),\n end: zonedTimeToInstant(end.date, end.minutes, timeZone),\n };\n}\n\n/** Where the event's start and end land on another clock (the calendar's: \"your time\"). */\nexport function wallIn(form: EventForm, timeZone: string): { start: WallTime; end: WallTime } {\n return {\n start: instantToZoned(startInstant(form), timeZone),\n end: instantToZoned(endInstant(form), timeZone),\n };\n}\n\n/** A time from Find a time: `start` minutes on `date` on `timeZone`'s clock, for `length`. */\nexport function withSlot(\n form: EventForm,\n slot: { date: DateValue; start: number; length: number; timeZone: string }\n): EventForm {\n const start = zonedTimeToInstant(slot.date, slot.start, slot.timeZone);\n return followingStart(form, startingAt({ ...form, allDay: false }, start, slot.length));\n}\n\n// ── Repeat ───────────────────────────────────────────────────────────────────\n\n/** What the form's repeat rule is tied to: its start on its own clock. */\nexport function anchorOf(form: EventForm): RuleAnchor {\n if (form.allDay) {\n return { start: form.firstDay, startMinutes: 0, timeZone: form.timeZone, allDay: true };\n }\n const wall = startWall(form);\n return { start: wall.date, startMinutes: wall.minutes, timeZone: form.timeZone, allDay: false };\n}\n\n/**\n * A repeat after the start moved: a preset stays that preset for the new start (the nearest one\n * when the new start doesn't offer it), a custom rule keeps the start an occurrence.\n */\nfunction repeatFollowingStart(\n repeat: RepeatState,\n before: RuleAnchor,\n after: RuleAnchor\n): RepeatState {\n if (repeat.kind === 'custom') {\n return { kind: 'custom', rule: followStart(repeat.rule, before, after) };\n }\n if (repeat.kind !== 'preset') return repeat;\n const offered = presetsFor(after);\n if (offered.includes(repeat.preset)) return repeat;\n if (repeat.preset === 'monthlyNth' && offered.includes('monthlyLast')) {\n return { kind: 'preset', preset: 'monthlyLast' };\n }\n if (repeat.preset === 'monthlyLast' && offered.includes('monthlyNth')) {\n return { kind: 'preset', preset: 'monthlyNth' };\n }\n // \"Every weekday\" from a weekend day: the weekdays and the new start's day.\n return { kind: 'custom', rule: followStart(presetRule(repeat.preset, before), before, after) };\n}\n\n/** The rule the form repeats by; null when it doesn't repeat or keeps a stored rule. */\nexport function repeatRuleOf(form: EventForm): RepeatRule | null {\n if (form.repeat.kind === 'preset') return presetRule(form.repeat.preset, anchorOf(form));\n if (form.repeat.kind === 'custom') return form.repeat.rule;\n return null;\n}\n\n/** The RRULE to store: null when the event doesn't repeat; a kept rule as it was. */\nexport function rruleOf(form: EventForm): string | null {\n if (form.repeat.kind === 'none') return null;\n if (form.repeat.kind === 'kept') return form.repeat.text;\n const rule = repeatRuleOf(form);\n return rule ? buildRRule(rule, anchorOf(form)) : null;\n}\n\n/** A stored rule as the form holds it: a preset when it is one. */\nexport function repeatStateOf(rrule: string | null, anchor: RuleAnchor): RepeatState {\n const parsed = parseRRule(rrule, anchor);\n if (parsed.kind === 'none') return { kind: 'none' };\n if (parsed.kind === 'kept') return { kind: 'kept', text: parsed.text };\n const preset = presetOf(parsed.rule, anchor);\n return preset ? { kind: 'preset', preset } : { kind: 'custom', rule: parsed.rule };\n}\n\n// ── People and reminders ─────────────────────────────────────────────────────\n\n/** A plain email address check: something@something.tld, no spaces. */\nexport function isEmailAddress(text: string): boolean {\n return /^[^\\s@,;<>]+@[^\\s@,;<>]+\\.[^\\s@,;<>.]{2,}$/.test(text.trim());\n}\n\nexport function guestKey(guest: { userId: string | null; email: string | null }): string {\n return guest.userId ? `u:${guest.userId}` : `e:${(guest.email ?? '').trim().toLowerCase()}`;\n}\n\nfunction addressOfGuest(email: string | null): string | null {\n return email?.trim().toLowerCase() || null;\n}\n\n/**\n * The form with these people added: each once, never the organiser. A member and their email\n * address are one guest: an address that is a member's isn't added again, and a member found\n * after their address was typed (before the workspace's people loaded, say) takes the place of\n * that address while it isn't saved yet; once saved, the address stays the guest.\n */\nexport function withGuests(\n form: EventForm,\n people: readonly { userId: string | null; email: string | null; name: string | null }[],\n organizerId: string | null\n): EventForm {\n const guests = [...form.guests];\n const keys = new Set(guests.map((guest) => guest.key));\n let changed = false;\n for (const person of people) {\n if (person.userId && person.userId === organizerId) continue;\n const email = person.email?.trim() || null;\n const key = guestKey({ userId: person.userId, email });\n if (key === 'e:' || keys.has(key)) continue;\n const address = addressOfGuest(email);\n const same = address\n ? guests.findIndex((guest) => addressOfGuest(guest.email) === address)\n : -1;\n const already = guests[same];\n if (already) {\n if (!person.userId || already.userId || already.attendeeId !== null) continue;\n guests.splice(same, 1);\n keys.delete(already.key);\n }\n keys.add(key);\n guests.push({\n key,\n userId: person.userId,\n email,\n name: person.name,\n optional: false,\n attendeeId: null,\n response: null,\n });\n changed = true;\n }\n return changed ? { ...form, guests } : form;\n}\n\nexport function withoutGuest(form: EventForm, key: string): EventForm {\n return { ...form, guests: form.guests.filter((guest) => guest.key !== key) };\n}\n\n/** The form with a reminder added, unless it has one at that time on that channel. */\nexport function withReminder(\n form: EventForm,\n minutesBefore: number,\n channel: ReminderChannelV2\n): EventForm {\n const same = (reminder: ReminderDraft) =>\n reminder.minutesBefore === minutesBefore && reminder.channel === channel;\n if (form.reminders.some(same)) return form;\n const key = `${channel}:${minutesBefore}`;\n const reminders = [...form.reminders, { key, minutesBefore, channel, reminderId: null }];\n reminders.sort((a, b) => a.minutesBefore - b.minutesBefore || a.channel.localeCompare(b.channel));\n return { ...form, reminders };\n}\n\nexport function withoutReminder(form: EventForm, key: string): EventForm {\n return { ...form, reminders: form.reminders.filter((reminder) => reminder.key !== key) };\n}\n\n// ── Place ────────────────────────────────────────────────────────────────────\n\n/** Which of the event's fields the video link lives in. */\nexport type VideoField = 'onlineMeetingUrl' | 'locationUrl';\n/** Which of the event's fields the address lives in. */\nexport type AddressField = 'location' | 'locationAddress';\n\n/**\n * An event's video link and the field it is in: the meeting link, else an online event's\n * location link (today's form wrote it there).\n */\nexport function videoOf(event: CalendarEventV2): { url: string; field: VideoField } {\n if (event.meeting?.url) return { url: event.meeting.url, field: 'onlineMeetingUrl' };\n if (event.locationType === 'ONLINE' && event.locationUrl) {\n return { url: event.locationUrl, field: 'locationUrl' };\n }\n return { url: '', field: 'onlineMeetingUrl' };\n}\n\n/**\n * An event's address and the field it is in: the location, unless it is a room's name or a\n * link; else the address field. A new address goes in the location, which every app reads.\n */\nexport function addressOf(event: CalendarEventV2): { text: string; field: AddressField } {\n const location = event.location?.trim() ?? '';\n if (location && !locationIsRoomName(event) && !/^https?:\\/\\//i.test(location)) {\n return { text: location, field: 'location' };\n }\n if (event.locationAddress?.trim())\n return { text: event.locationAddress, field: 'locationAddress' };\n return { text: '', field: 'location' };\n}\n\n/**\n * The time a person's availability is checked over: a timed event's instants; an all-day\n * event's days from midnight to midnight on the calendar's clock (its stored UTC midnights would\n * reach into the days either side, where time off is kept on that clock too).\n */\nexport function availabilitySpan(\n form: EventForm,\n calendarTimeZone: string\n): { start: Date; end: Date; allDay: boolean } {\n if (!form.allDay) return { start: startInstant(form), end: endInstant(form), allDay: false };\n return {\n start: startOfDayInZone(form.firstDay, calendarTimeZone),\n end: startOfDayInZone(addDays(form.lastDay, 1), calendarTimeZone),\n allDay: true,\n };\n}\n\n/** The event's location is only the name of its booked room (as other apps write it). */\nexport function locationIsRoomName(event: CalendarEventV2): boolean {\n const name = eventRoom(event)?.name?.trim();\n return Boolean(name) && event.location?.trim() === name;\n}\n\n// ── Building a form ──────────────────────────────────────────────────────────\n\nfunction defaultReminders(defaults: NewFormDefaults): ReminderDraft[] {\n if (defaults.defaultReminder === null) return [];\n return [\n {\n key: `IN_APP:${defaults.defaultReminder}`,\n minutesBefore: defaults.defaultReminder,\n channel: 'IN_APP',\n reminderId: null,\n },\n ];\n}\n\n/**\n * A draft's length in minutes. Its end is a time on the same clock as its start (an end of 1440\n * is the next midnight), so the length is the time between the two instants: on a day the clocks\n * change, the difference of the clock times would gain or lose the hour. Null without an end\n * after the start.\n */\nfunction draftLength(\n date: DateValue,\n start: number,\n end: number | undefined,\n timeZone: string\n): number | null {\n if (end === undefined || end <= start) return null;\n const from = zonedTimeToInstant(date, start, timeZone).getTime();\n const minutes = Math.round(\n (zonedTimeToInstant(date, end, timeZone).getTime() - from) / MINUTE_MS\n );\n return minutes > 0 ? minutes : null;\n}\n\n/**\n * A new event's form from what the view set (`CalendarV2EventDraft`): its day and times on the\n * calendar's clock (an end of 1440 is the next midnight), else 09:00 for the default length.\n */\nexport function newEventForm(\n draft: CalendarV2EventDraft | null,\n defaults: NewFormDefaults\n): EventForm {\n const date = draft?.date ?? defaults.today;\n const startMinutes = Math.max(0, Math.round(draft?.start ?? 9 * 60));\n const length =\n draftLength(date, startMinutes, draft?.end, defaults.timeZone) ?? defaults.defaultLength;\n const start = zonedTimeToInstant(date, startMinutes, defaults.timeZone);\n const form: EventForm = {\n title: draft?.title ?? '',\n allDay: false,\n start,\n end: new Date(start.getTime() + Math.max(1, length) * MINUTE_MS),\n firstDay: date,\n lastDay: date,\n timeZone: defaults.timeZone,\n repeat: { kind: 'none' },\n description: '',\n guests: [],\n roomId: draft?.resourceIds?.[0] ?? null,\n videoUrl: '',\n address: '',\n calendarId: draft?.calendarId ?? defaults.defaultCalendarId,\n visibility: 'PUBLIC',\n reminders: defaultReminders(defaults),\n };\n return draft?.allDay ? withAllDay(form, true) : form;\n}\n\n/**\n * An existing event's form: its instants on its own zone's clock (else the calendar's), its days\n * when all-day (with 09:00 for an hour on its first day to switch to), its guests but the\n * organiser, its room, link, address and reminders. `draft` may bring a new time on the\n * calendar's clock (Find a time's \"Use this time\" on a repeating event).\n */\nexport function formFromEvent(\n event: CalendarEventV2,\n calendarTimeZone: string,\n draft: CalendarV2EventDraft | null = null\n): EventForm {\n const timeZone = event.timeZone ?? calendarTimeZone;\n const room = eventRoom(event);\n const activeRoom =\n room && (room.status === 'APPROVED' || room.status === 'PENDING') ? room : null;\n const days = eventDays(event, calendarTimeZone);\n const start = event.allDay ? zonedTimeToInstant(days.start, 9 * 60, timeZone) : event.start;\n const end = event.allDay ? new Date(start.getTime() + 60 * MINUTE_MS) : event.end;\n let form: EventForm = {\n title: event.title,\n allDay: event.allDay,\n start,\n end,\n firstDay: days.start,\n lastDay: days.end,\n timeZone,\n repeat: { kind: 'none' },\n description: event.description ?? '',\n guests: event.guests\n .filter((guest) => !guest.organizer && guest.userId !== event.organizerId)\n .map((guest) => ({\n key: guestKey(guest),\n userId: guest.userId,\n email: guest.email,\n name: guest.name,\n optional: guest.optional,\n attendeeId: guest.id,\n response: guest.response,\n })),\n roomId: activeRoom?.resourceId ?? null,\n videoUrl: videoOf(event).url,\n address: addressOf(event).text,\n calendarId: event.calendarId,\n visibility: event.visibility,\n reminders: event.reminders.map((reminder) => ({\n key: `r:${reminder.id}`,\n minutesBefore: reminder.minutesBefore,\n channel: reminder.channel,\n reminderId: reminder.id,\n })),\n };\n if (event.isRecurring && event.rrule) {\n form = { ...form, repeat: repeatStateOf(event.rrule, anchorOf(form)) };\n } else if (event.rrule) {\n form = { ...form, repeat: { kind: 'kept', text: event.rrule } };\n }\n if (draft?.date !== undefined && draft.start !== undefined) {\n const length =\n draftLength(draft.date, draft.start, draft.end, calendarTimeZone) ?? lengthMinutes(form);\n form = withSlot(form, {\n date: draft.date,\n start: draft.start,\n length,\n timeZone: calendarTimeZone,\n });\n }\n return form;\n}\n\n// ── Checks ───────────────────────────────────────────────────────────────────\n\nexport interface FormIssues {\n title?: 'missing';\n when?: 'endBeforeStart';\n video?: 'notWebAddress';\n repeat?: RuleProblem;\n}\n\n/** What stops the form from being saved. */\nexport function formIssues(form: EventForm): FormIssues {\n const issues: FormIssues = {};\n if (form.title.trim() === '') issues.title = 'missing';\n const ends = form.allDay\n ? form.lastDay >= form.firstDay\n : form.end.getTime() > form.start.getTime();\n if (!ends) issues.when = 'endBeforeStart';\n if (form.videoUrl.trim() !== '' && !safeWebUrl(form.videoUrl)) issues.video = 'notWebAddress';\n if (form.repeat.kind === 'custom') {\n const problem = ruleProblem(form.repeat.rule, anchorOf(form));\n if (problem) issues.repeat = problem;\n }\n return issues;\n}\n\nexport function hasIssues(issues: FormIssues): boolean {\n return Object.keys(issues).length > 0;\n}\n\n/** The two forms hold the same event (the dialog asks before dropping changes). */\nexport function sameForm(a: EventForm, b: EventForm): boolean {\n const comparable = (form: EventForm) => JSON.stringify({ ...form, title: form.title.trim() });\n return comparable(a) === comparable(b);\n}\n"],"mappings":";;;;;AA6CA,IAAMA,IAAY,KAGLC,IAAkC;CAAC;CAAI;CAAI;CAAI;AAAE;AA2E9D,SAAgBC,EAAU,GAA2B;CACnD,OAAOC,EAAeC,EAAK,OAAOA,EAAK,QAAQ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AS,KAAK,MAAM,MAAM,CAAC0G,EAAW1G,EAAK,QAAQ,MAAG,EAAO,QAAQ,kBAC1EA,EAAK,OAAO,SAAS,UAAU;EACjC,IAAM2G,IAAUC,EAAY5G,EAAK,OAAO,MAAMe,EAASf,CAAI,CAAC;EAC5D,AAAI2G,MAAS,EAAO,SAASA;CAC/B;CACA,OAAOF;AACT;AAEA,SAAgBI,GAAU,GAA6B;CACrD,OAAO,OAAO,KAAKJ,CAAM,CAAC,CAAC,SAAS;AACtC;AAGA,SAAgBK,GAAS,GAAc,GAAuB;CAC5D,IAAMC,KAAc,MAAoB,KAAK,UAAU;EAAE,GAAG/G;EAAM,OAAOA,EAAK,MAAM,KAAK;CAAE,CAAC;CAC5F,OAAO+G,EAAW/B,CAAC,MAAM+B,EAAW9B,CAAC;AACvC"}
1
+ {"version":3,"file":"eventForm.js","names":["MINUTE_MS","LENGTH_CHIPS","startWall","instantToZoned","form","endWall","firstDayOf","startInstant","endInstant","addDays","lengthMinutes","lengthChip","length","startingAt","start","followingStart","after","repeatFollowingStart","before","anchorOf","withStartDate","date","days","dayDifference","wall","zonedTimeToInstant","withStartTime","minutes","withEndTime","day","nextDay","withEndClock","withEndDate","withLength","withAllDay","allDay","first","lastMoment","last","withTimeZone","timeZone","end","wallIn","withSlot","slot","repeat","followStart","offered","presetsFor","presetRule","repeatRuleOf","rruleOf","rule","buildRRule","repeatStateOf","parsed","parseRRule","rrule","anchor","preset","presetOf","isEmailAddress","text","guestKey","guest","addressOfGuest","email","withGuests","guests","keys","changed","person","people","organizerId","key","address","same","already","withoutGuest","withReminder","reminder","minutesBefore","channel","reminders","a","b","withoutReminder","videoOf","event","addressOf","location","locationIsRoomName","availabilitySpan","startOfDayInZone","calendarTimeZone","name","eventRoom","defaultReminders","defaults","draftLength","from","newEventForm","draft","startMinutes","formFromEvent","room","activeRoom","eventDays","sameTimes","detachedForm","seriesFormOf","own","series","timesKept","initial","repeatKept","roomId","shift","moved","times","movedCancellations","cancelled","formIssues","issues","safeWebUrl","problem","ruleProblem","hasIssues","sameForm","comparable"],"sources":["../../../src/v2/event/eventForm.ts"],"sourcesContent":["/**\n * The event dialog's form (BOFF-15698 A2): what the person sets, and the rules between the\n * fields. Pure.\n *\n * - A timed event is its start and end instants, shown on its own zone's clock (the Time zone\n * field). Instants, not clock times, so an event ending in the second 01:30 of 25 October in\n * London keeps its end: a clock time names only the first. Lengths are real time: \"1 h\" from\n * 00:30 on 29 March ends at 02:30; a clock time the clocks skip (01:30 then) becomes the time\n * after the gap (02:30), as the grid reads it.\n * - An all-day event is its first and last day, floating: it is written at UTC midnights (the\n * API's own rule, which the .ics export and free/busy read), the same days wherever it is read.\n * Its start and end instants are kept meanwhile: switching All day back off restores them.\n * - Changing the time zone keeps the clock times shown (\"09:00 in New York\") and moves the\n * instants; `wallIn` says where they land on the calendar's clock.\n * - Moving the start keeps the length. The end can't come before the start.\n */\nimport { addDays, type DateValue } from '@burdenoff/fe-libs/ui';\nimport { eventRoom, safeWebUrl } from '../events/eventModel';\nimport {\n dayDifference,\n eventDays,\n instantToZoned,\n startOfDayInZone,\n zonedTimeToInstant,\n} from '../time/calendarTime';\nimport type {\n CalendarEventV2,\n CalendarV2EventDraft,\n EventResponseV2,\n EventVisibilityV2,\n} from '../types';\nimport {\n buildRRule,\n followStart,\n parseRRule,\n presetOf,\n presetRule,\n presetsFor,\n ruleProblem,\n type RepeatPreset,\n type RepeatRule,\n type RuleAnchor,\n type RuleProblem,\n} from './rrule';\n\nconst MINUTE_MS = 60_000;\n\n/** The Length chips, in minutes. */\nexport const LENGTH_CHIPS: readonly number[] = [30, 45, 60, 90];\n\nexport interface GuestDraft {\n /** `u:<userId>` for a member, `e:<email>` for anyone else. */\n key: string;\n userId: string | null;\n email: string | null;\n name: string | null;\n optional: boolean;\n /** The guest's row, for someone the event already has. */\n attendeeId: string | null;\n response: EventResponseV2 | null;\n}\n\nexport type ReminderChannelV2 = 'IN_APP' | 'EMAIL' | 'SMS';\n\nexport interface ReminderDraft {\n /** `r:<id>` for a reminder the event has, `<channel>:<minutes>` for a new one. */\n key: string;\n minutesBefore: number;\n channel: ReminderChannelV2;\n /** The reminder's row, for one the event already has. */\n reminderId: string | null;\n}\n\nexport type RepeatState =\n | { kind: 'none' }\n /** A menu preset, worked out from the start whenever it moves. */\n | { kind: 'preset'; preset: RepeatPreset }\n | { kind: 'custom'; rule: RepeatRule }\n /** A stored rule the builder can't hold, kept as it is. */\n | { kind: 'kept'; text: string };\n\nexport interface EventForm {\n title: string;\n allDay: boolean;\n /** Timed: when it starts and ends. All-day: the times to go back to when it is switched off. */\n start: Date;\n end: Date;\n /** All-day: the first and last day, both included. */\n firstDay: DateValue;\n lastDay: DateValue;\n timeZone: string;\n repeat: RepeatState;\n description: string;\n guests: GuestDraft[];\n roomId: string | null;\n videoUrl: string;\n address: string;\n calendarId: string | null;\n visibility: EventVisibilityV2;\n /** \"Show me as\": busy (true), or free (the time stays open in free/busy and Find a time). */\n busy: boolean;\n reminders: ReminderDraft[];\n}\n\n/** What a new event starts with besides its draft. */\nexport interface NewFormDefaults {\n /** The calendar's zone. */\n timeZone: string;\n today: DateValue;\n /** Minutes. */\n defaultLength: number;\n /** Minutes before, or null for none. */\n defaultReminder: number | null;\n defaultCalendarId: string | null;\n}\n\n/** A day, and minutes after its midnight on a clock. */\nexport interface WallTime {\n date: DateValue;\n minutes: number;\n}\n\n// ── Times ────────────────────────────────────────────────────────────────────\n\n/** Where the start shows on the event's own clock. */\nexport function startWall(form: EventForm): WallTime {\n return instantToZoned(form.start, form.timeZone);\n}\n\n/** Where the end shows on the event's own clock. */\nexport function endWall(form: EventForm): WallTime {\n return instantToZoned(form.end, form.timeZone);\n}\n\n/** The event's first day: an all-day event's own, else its start's on its clock. */\nexport function firstDayOf(form: EventForm): DateValue {\n return form.allDay ? form.firstDay : startWall(form).date;\n}\n\n/** When the event starts: the instant, or the UTC midnight of an all-day event's first day. */\nexport function startInstant(form: EventForm): Date {\n return form.allDay ? new Date(`${form.firstDay}T00:00:00.000Z`) : form.start;\n}\n\n/** When it ends: the instant, or the UTC midnight after an all-day event's last day. */\nexport function endInstant(form: EventForm): Date {\n return form.allDay ? new Date(`${addDays(form.lastDay, 1)}T00:00:00.000Z`) : form.end;\n}\n\n/** How long a timed event lasts, in real minutes. */\nexport function lengthMinutes(form: EventForm): number {\n return Math.round((form.end.getTime() - form.start.getTime()) / MINUTE_MS);\n}\n\n/** The Length chip the event's length is, if it is one. */\nexport function lengthChip(form: EventForm): number | null {\n if (form.allDay) return null;\n const length = lengthMinutes(form);\n return LENGTH_CHIPS.includes(length) ? length : null;\n}\n\n/** A start, and an end `length` real minutes after it (the length never below a minute). */\nfunction startingAt(form: EventForm, start: Date, length: number): EventForm {\n return { ...form, start, end: new Date(start.getTime() + Math.max(1, length) * MINUTE_MS) };\n}\n\n/** The form after its start moved: its repeat follows, so the start stays an occurrence. */\nfunction followingStart(before: EventForm, after: EventForm): EventForm {\n return {\n ...after,\n repeat: repeatFollowingStart(before.repeat, anchorOf(before), anchorOf(after)),\n };\n}\n\n/** The start on another day, the length kept (all-day: the number of days kept). */\nexport function withStartDate(form: EventForm, date: DateValue): EventForm {\n if (form.allDay) {\n if (date === form.firstDay) return form;\n const days = Math.max(0, dayDifference(form.firstDay, form.lastDay));\n return followingStart(form, { ...form, firstDay: date, lastDay: addDays(date, days) });\n }\n const wall = startWall(form);\n if (date === wall.date) return form;\n const start = zonedTimeToInstant(date, wall.minutes, form.timeZone);\n return followingStart(form, startingAt(form, start, lengthMinutes(form)));\n}\n\n/** The start at another time of its day, the length kept. */\nexport function withStartTime(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n const start = zonedTimeToInstant(startWall(form).date, minutes, form.timeZone);\n return followingStart(form, startingAt(form, start, lengthMinutes(form)));\n}\n\n/**\n * The end picked in the end picker beside the start, whose times run on past midnight\n * (`nextDay`): on the start's day, or the day after.\n */\nexport function withEndTime(form: EventForm, minutes: number, nextDay: boolean): EventForm {\n if (form.allDay) return form;\n const day = startWall(form).date;\n return {\n ...form,\n end: zonedTimeToInstant(nextDay ? addDays(day, 1) : day, minutes, form.timeZone),\n };\n}\n\n/** The end's time on its own day (an event of more than a day has an end date of its own). */\nexport function withEndClock(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n return { ...form, end: zonedTimeToInstant(endWall(form).date, minutes, form.timeZone) };\n}\n\n/** The end's day (timed), or the last day (all-day). */\nexport function withEndDate(form: EventForm, date: DateValue): EventForm {\n if (form.allDay) return { ...form, lastDay: date };\n return { ...form, end: zonedTimeToInstant(date, endWall(form).minutes, form.timeZone) };\n}\n\n/** The Length chips: the end `minutes` real minutes after the start. */\nexport function withLength(form: EventForm, minutes: number): EventForm {\n if (form.allDay) return form;\n return startingAt(form, form.start, minutes);\n}\n\n/**\n * All day on or off. On: the days the times touch (an end at midnight doesn't add its day).\n * Off: the times it had, on its first day.\n */\nexport function withAllDay(form: EventForm, allDay: boolean): EventForm {\n if (form.allDay === allDay) return form;\n if (allDay) {\n const first = startWall(form).date;\n const lastMoment = new Date(Math.max(form.start.getTime(), form.end.getTime() - 1));\n const last = instantToZoned(lastMoment, form.timeZone).date;\n return { ...form, allDay: true, firstDay: first, lastDay: last < first ? first : last };\n }\n const start = zonedTimeToInstant(form.firstDay, startWall(form).minutes, form.timeZone);\n return followingStart(form, startingAt({ ...form, allDay: false }, start, lengthMinutes(form)));\n}\n\n/** The time zone, keeping the clock times shown (a time the new zone skips moves past the gap). */\nexport function withTimeZone(form: EventForm, timeZone: string): EventForm {\n if (timeZone === form.timeZone) return form;\n const start = startWall(form);\n const end = endWall(form);\n return {\n ...form,\n timeZone,\n start: zonedTimeToInstant(start.date, start.minutes, timeZone),\n end: zonedTimeToInstant(end.date, end.minutes, timeZone),\n };\n}\n\n/** Where the event's start and end land on another clock (the calendar's: \"your time\"). */\nexport function wallIn(form: EventForm, timeZone: string): { start: WallTime; end: WallTime } {\n return {\n start: instantToZoned(startInstant(form), timeZone),\n end: instantToZoned(endInstant(form), timeZone),\n };\n}\n\n/** A time from Find a time: `start` minutes on `date` on `timeZone`'s clock, for `length`. */\nexport function withSlot(\n form: EventForm,\n slot: { date: DateValue; start: number; length: number; timeZone: string }\n): EventForm {\n const start = zonedTimeToInstant(slot.date, slot.start, slot.timeZone);\n return followingStart(form, startingAt({ ...form, allDay: false }, start, slot.length));\n}\n\n// ── Repeat ───────────────────────────────────────────────────────────────────\n\n/** What the form's repeat rule is tied to: its start on its own clock. */\nexport function anchorOf(form: EventForm): RuleAnchor {\n if (form.allDay) {\n return { start: form.firstDay, startMinutes: 0, timeZone: form.timeZone, allDay: true };\n }\n const wall = startWall(form);\n return { start: wall.date, startMinutes: wall.minutes, timeZone: form.timeZone, allDay: false };\n}\n\n/**\n * A repeat after the start moved: a preset stays that preset for the new start (the nearest one\n * when the new start doesn't offer it), a custom rule keeps the start an occurrence.\n */\nfunction repeatFollowingStart(\n repeat: RepeatState,\n before: RuleAnchor,\n after: RuleAnchor\n): RepeatState {\n if (repeat.kind === 'custom') {\n return { kind: 'custom', rule: followStart(repeat.rule, before, after) };\n }\n if (repeat.kind !== 'preset') return repeat;\n const offered = presetsFor(after);\n if (offered.includes(repeat.preset)) return repeat;\n if (repeat.preset === 'monthlyNth' && offered.includes('monthlyLast')) {\n return { kind: 'preset', preset: 'monthlyLast' };\n }\n if (repeat.preset === 'monthlyLast' && offered.includes('monthlyNth')) {\n return { kind: 'preset', preset: 'monthlyNth' };\n }\n // \"Every weekday\" from a weekend day: the weekdays and the new start's day.\n return { kind: 'custom', rule: followStart(presetRule(repeat.preset, before), before, after) };\n}\n\n/** The rule the form repeats by; null when it doesn't repeat or keeps a stored rule. */\nexport function repeatRuleOf(form: EventForm): RepeatRule | null {\n if (form.repeat.kind === 'preset') return presetRule(form.repeat.preset, anchorOf(form));\n if (form.repeat.kind === 'custom') return form.repeat.rule;\n return null;\n}\n\n/** The RRULE to store: null when the event doesn't repeat; a kept rule as it was. */\nexport function rruleOf(form: EventForm): string | null {\n if (form.repeat.kind === 'none') return null;\n if (form.repeat.kind === 'kept') return form.repeat.text;\n const rule = repeatRuleOf(form);\n return rule ? buildRRule(rule, anchorOf(form)) : null;\n}\n\n/** A stored rule as the form holds it: a preset when it is one. */\nexport function repeatStateOf(rrule: string | null, anchor: RuleAnchor): RepeatState {\n const parsed = parseRRule(rrule, anchor);\n if (parsed.kind === 'none') return { kind: 'none' };\n if (parsed.kind === 'kept') return { kind: 'kept', text: parsed.text };\n const preset = presetOf(parsed.rule, anchor);\n return preset ? { kind: 'preset', preset } : { kind: 'custom', rule: parsed.rule };\n}\n\n// ── People and reminders ─────────────────────────────────────────────────────\n\n/** A plain email address check: something@something.tld, no spaces. */\nexport function isEmailAddress(text: string): boolean {\n return /^[^\\s@,;<>]+@[^\\s@,;<>]+\\.[^\\s@,;<>.]{2,}$/.test(text.trim());\n}\n\nexport function guestKey(guest: { userId: string | null; email: string | null }): string {\n return guest.userId ? `u:${guest.userId}` : `e:${(guest.email ?? '').trim().toLowerCase()}`;\n}\n\nfunction addressOfGuest(email: string | null): string | null {\n return email?.trim().toLowerCase() || null;\n}\n\n/**\n * The form with these people added: each once, never the organiser. A member and their email\n * address are one guest: an address that is a member's isn't added again, and a member found\n * after their address was typed (before the workspace's people loaded, say) takes the place of\n * that address while it isn't saved yet; once saved, the address stays the guest.\n */\nexport function withGuests(\n form: EventForm,\n people: readonly { userId: string | null; email: string | null; name: string | null }[],\n organizerId: string | null\n): EventForm {\n const guests = [...form.guests];\n const keys = new Set(guests.map((guest) => guest.key));\n let changed = false;\n for (const person of people) {\n if (person.userId && person.userId === organizerId) continue;\n const email = person.email?.trim() || null;\n const key = guestKey({ userId: person.userId, email });\n if (key === 'e:' || keys.has(key)) continue;\n const address = addressOfGuest(email);\n const same = address\n ? guests.findIndex((guest) => addressOfGuest(guest.email) === address)\n : -1;\n const already = guests[same];\n if (already) {\n if (!person.userId || already.userId || already.attendeeId !== null) continue;\n guests.splice(same, 1);\n keys.delete(already.key);\n }\n keys.add(key);\n guests.push({\n key,\n userId: person.userId,\n email,\n name: person.name,\n optional: false,\n attendeeId: null,\n response: null,\n });\n changed = true;\n }\n return changed ? { ...form, guests } : form;\n}\n\nexport function withoutGuest(form: EventForm, key: string): EventForm {\n return { ...form, guests: form.guests.filter((guest) => guest.key !== key) };\n}\n\n/** The form with a reminder added, unless it has one at that time on that channel. */\nexport function withReminder(\n form: EventForm,\n minutesBefore: number,\n channel: ReminderChannelV2\n): EventForm {\n const same = (reminder: ReminderDraft) =>\n reminder.minutesBefore === minutesBefore && reminder.channel === channel;\n if (form.reminders.some(same)) return form;\n const key = `${channel}:${minutesBefore}`;\n const reminders = [...form.reminders, { key, minutesBefore, channel, reminderId: null }];\n reminders.sort((a, b) => a.minutesBefore - b.minutesBefore || a.channel.localeCompare(b.channel));\n return { ...form, reminders };\n}\n\nexport function withoutReminder(form: EventForm, key: string): EventForm {\n return { ...form, reminders: form.reminders.filter((reminder) => reminder.key !== key) };\n}\n\n// ── Place ────────────────────────────────────────────────────────────────────\n\n/** Which of the event's fields the video link lives in. */\nexport type VideoField = 'onlineMeetingUrl' | 'locationUrl';\n/** Which of the event's fields the address lives in. */\nexport type AddressField = 'location' | 'locationAddress';\n\n/**\n * An event's video link and the field it is in: the meeting link, else an online event's\n * location link (today's form wrote it there).\n */\nexport function videoOf(event: CalendarEventV2): { url: string; field: VideoField } {\n if (event.meeting?.url) return { url: event.meeting.url, field: 'onlineMeetingUrl' };\n if (event.locationType === 'ONLINE' && event.locationUrl) {\n return { url: event.locationUrl, field: 'locationUrl' };\n }\n return { url: '', field: 'onlineMeetingUrl' };\n}\n\n/**\n * An event's address and the field it is in: the location, unless it is a room's name or a\n * link; else the address field. A new address goes in the location, which every app reads.\n */\nexport function addressOf(event: CalendarEventV2): { text: string; field: AddressField } {\n const location = event.location?.trim() ?? '';\n if (location && !locationIsRoomName(event) && !/^https?:\\/\\//i.test(location)) {\n return { text: location, field: 'location' };\n }\n if (event.locationAddress?.trim())\n return { text: event.locationAddress, field: 'locationAddress' };\n return { text: '', field: 'location' };\n}\n\n/**\n * The time a person's availability is checked over: a timed event's instants; an all-day\n * event's days from midnight to midnight on the calendar's clock (its stored UTC midnights would\n * reach into the days either side, where time off is kept on that clock too).\n */\nexport function availabilitySpan(\n form: EventForm,\n calendarTimeZone: string\n): { start: Date; end: Date; allDay: boolean } {\n if (!form.allDay) return { start: startInstant(form), end: endInstant(form), allDay: false };\n return {\n start: startOfDayInZone(form.firstDay, calendarTimeZone),\n end: startOfDayInZone(addDays(form.lastDay, 1), calendarTimeZone),\n allDay: true,\n };\n}\n\n/** The event's location is only the name of its booked room (as other apps write it). */\nexport function locationIsRoomName(event: CalendarEventV2): boolean {\n const name = eventRoom(event)?.name?.trim();\n return Boolean(name) && event.location?.trim() === name;\n}\n\n// ── Building a form ──────────────────────────────────────────────────────────\n\nfunction defaultReminders(defaults: NewFormDefaults): ReminderDraft[] {\n if (defaults.defaultReminder === null) return [];\n return [\n {\n key: `IN_APP:${defaults.defaultReminder}`,\n minutesBefore: defaults.defaultReminder,\n channel: 'IN_APP',\n reminderId: null,\n },\n ];\n}\n\n/**\n * A draft's length in minutes. Its end is a time on the same clock as its start (an end of 1440\n * is the next midnight), so the length is the time between the two instants: on a day the clocks\n * change, the difference of the clock times would gain or lose the hour. Null without an end\n * after the start.\n */\nfunction draftLength(\n date: DateValue,\n start: number,\n end: number | undefined,\n timeZone: string\n): number | null {\n if (end === undefined || end <= start) return null;\n const from = zonedTimeToInstant(date, start, timeZone).getTime();\n const minutes = Math.round(\n (zonedTimeToInstant(date, end, timeZone).getTime() - from) / MINUTE_MS\n );\n return minutes > 0 ? minutes : null;\n}\n\n/**\n * A new event's form from what the view set (`CalendarV2EventDraft`): its day and times on the\n * calendar's clock (an end of 1440 is the next midnight), else 09:00 for the default length.\n */\nexport function newEventForm(\n draft: CalendarV2EventDraft | null,\n defaults: NewFormDefaults\n): EventForm {\n const date = draft?.date ?? defaults.today;\n const startMinutes = Math.max(0, Math.round(draft?.start ?? 9 * 60));\n const length =\n draftLength(date, startMinutes, draft?.end, defaults.timeZone) ?? defaults.defaultLength;\n const start = zonedTimeToInstant(date, startMinutes, defaults.timeZone);\n const form: EventForm = {\n title: draft?.title ?? '',\n allDay: false,\n start,\n end: new Date(start.getTime() + Math.max(1, length) * MINUTE_MS),\n firstDay: date,\n lastDay: date,\n timeZone: defaults.timeZone,\n repeat: { kind: 'none' },\n description: '',\n guests: [],\n roomId: draft?.resourceIds?.[0] ?? null,\n videoUrl: '',\n address: '',\n calendarId: draft?.calendarId ?? defaults.defaultCalendarId,\n visibility: 'PUBLIC',\n busy: true,\n reminders: defaultReminders(defaults),\n };\n return draft?.allDay ? withAllDay(form, true) : form;\n}\n\n/**\n * An existing event's form: its instants on its own zone's clock (else the calendar's), its days\n * when all-day (with 09:00 for an hour on its first day to switch to), its guests but the\n * organiser, its room, link, address and reminders. `draft` may bring a new time on the\n * calendar's clock (Find a time's \"Use this time\" on a repeating event).\n */\nexport function formFromEvent(\n event: CalendarEventV2,\n calendarTimeZone: string,\n draft: CalendarV2EventDraft | null = null\n): EventForm {\n const timeZone = event.timeZone ?? calendarTimeZone;\n const room = eventRoom(event);\n const activeRoom =\n room && (room.status === 'APPROVED' || room.status === 'PENDING') ? room : null;\n const days = eventDays(event, calendarTimeZone);\n const start = event.allDay ? zonedTimeToInstant(days.start, 9 * 60, timeZone) : event.start;\n const end = event.allDay ? new Date(start.getTime() + 60 * MINUTE_MS) : event.end;\n let form: EventForm = {\n title: event.title,\n allDay: event.allDay,\n start,\n end,\n firstDay: days.start,\n lastDay: days.end,\n timeZone,\n repeat: { kind: 'none' },\n description: event.description ?? '',\n guests: event.guests\n .filter((guest) => !guest.organizer && guest.userId !== event.organizerId)\n .map((guest) => ({\n key: guestKey(guest),\n userId: guest.userId,\n email: guest.email,\n name: guest.name,\n optional: guest.optional,\n attendeeId: guest.id,\n response: guest.response,\n })),\n roomId: activeRoom?.resourceId ?? null,\n videoUrl: videoOf(event).url,\n address: addressOf(event).text,\n calendarId: event.calendarId,\n visibility: event.visibility,\n busy: event.isBusy,\n reminders: event.reminders.map((reminder) => ({\n key: `r:${reminder.id}`,\n minutesBefore: reminder.minutesBefore,\n channel: reminder.channel,\n reminderId: reminder.id,\n })),\n };\n if (event.isRecurring && event.rrule) {\n form = { ...form, repeat: repeatStateOf(event.rrule, anchorOf(form)) };\n } else if (event.rrule) {\n form = { ...form, repeat: { kind: 'kept', text: event.rrule } };\n }\n if (draft?.date !== undefined && draft.start !== undefined) {\n const length =\n draftLength(draft.date, draft.start, draft.end, calendarTimeZone) ?? lengthMinutes(form);\n form = withSlot(form, {\n date: draft.date,\n start: draft.start,\n length,\n timeZone: calendarTimeZone,\n });\n }\n return form;\n}\n\n// ── Dates of a series (A4) ───────────────────────────────────────────────────\n\n/** The two forms hold the same times: days, instants, zone and all day. */\nexport function sameTimes(a: EventForm, b: EventForm): boolean {\n if (a.allDay !== b.allDay || a.timeZone !== b.timeZone) return false;\n return a.allDay\n ? a.firstDay === b.firstDay && a.lastDay === b.lastDay\n : a.start.getTime() === b.start.getTime() && a.end.getTime() === b.end.getTime();\n}\n\n/**\n * The form for an event of its own made from it (a date of a series changed on its own, or the\n * later part of a split series): its guests and reminders are new to that event, so saving adds\n * each of them there rather than reading them as already its own.\n */\nexport function detachedForm(form: EventForm): EventForm {\n return {\n ...form,\n guests: form.guests.map((guest) => ({ ...guest, attendeeId: null, response: null })),\n reminders: form.reminders.map((reminder) => ({\n ...reminder,\n key: `${reminder.channel}:${reminder.minutesBefore}`,\n reminderId: null,\n })),\n };\n}\n\n/**\n * The form for a change to every event of a series, made on one of its dates (`initial` is the\n * form as that date opened): on the series' own first date (`series`, the series as stored).\n * What the person changed at the date (its time of day, length, zone, all day, a move of some\n * days, the repeat) moves the series the same way; what they didn't change keeps the series'\n * own, to the instant. Everything else (title, people, place …) is the form's.\n */\nexport function seriesFormOf(\n form: EventForm,\n initial: EventForm,\n series: CalendarEventV2,\n calendarTimeZone: string\n): EventForm {\n const own = formFromEvent(series, calendarTimeZone);\n const timesKept = sameTimes(form, initial);\n const repeatKept = rruleOf(form) === rruleOf(initial);\n // A series' room is booked for its first date: another date shows none, and leaving the room\n // alone there keeps the series' own.\n const roomId = form.roomId === initial.roomId ? own.roomId : form.roomId;\n if (timesKept && repeatKept) {\n return {\n ...form,\n roomId,\n allDay: own.allDay,\n start: own.start,\n end: own.end,\n firstDay: own.firstDay,\n lastDay: own.lastDay,\n timeZone: own.timeZone,\n repeat: own.repeat,\n };\n }\n // The days this date moved by move the series' first date too; its repeat follows.\n const shift = dayDifference(firstDayOf(initial), firstDayOf(form));\n const moved = withStartDate(form, addDays(firstDayOf(own), shift));\n const times = timesKept ? own : moved;\n return {\n ...form,\n roomId,\n allDay: times.allDay,\n start: times.start,\n end: times.end,\n firstDay: times.firstDay,\n lastDay: times.lastDay,\n timeZone: times.timeZone,\n repeat: moved.repeat,\n };\n}\n\n/**\n * Where a series' cancelled dates land once its times change (A4), as `before` → `after` (the\n * series' form before and after the change). The service keeps a cancelled date as the instant\n * it was cancelled at, and a series whose start moved would bring it back: each keeps its day\n * (moved by the days the series moved), at the series' new time of day, or as a whole day for\n * an all-day series. `from`: only the dates at or after this instant (a split's date).\n */\nexport function movedCancellations(\n cancelled: readonly Date[],\n before: EventForm,\n after: EventForm,\n from: Date | null = null\n): Date[] {\n const shift = dayDifference(firstDayOf(before), firstDayOf(after));\n const minutes = startWall(after).minutes;\n return cancelled\n .filter((date) => from === null || date.getTime() >= from.getTime())\n .map((date) => {\n const day = before.allDay\n ? date.toISOString().slice(0, 10)\n : instantToZoned(date, before.timeZone).date;\n const moved = addDays(day, shift);\n return after.allDay\n ? new Date(`${moved}T00:00:00.000Z`)\n : zonedTimeToInstant(moved, minutes, after.timeZone);\n });\n}\n\n// ── Checks ───────────────────────────────────────────────────────────────────\n\nexport interface FormIssues {\n title?: 'missing';\n when?: 'endBeforeStart';\n video?: 'notWebAddress';\n repeat?: RuleProblem;\n}\n\n/** What stops the form from being saved. */\nexport function formIssues(form: EventForm): FormIssues {\n const issues: FormIssues = {};\n if (form.title.trim() === '') issues.title = 'missing';\n const ends = form.allDay\n ? form.lastDay >= form.firstDay\n : form.end.getTime() > form.start.getTime();\n if (!ends) issues.when = 'endBeforeStart';\n if (form.videoUrl.trim() !== '' && !safeWebUrl(form.videoUrl)) issues.video = 'notWebAddress';\n if (form.repeat.kind === 'custom') {\n const problem = ruleProblem(form.repeat.rule, anchorOf(form));\n if (problem) issues.repeat = problem;\n }\n return issues;\n}\n\nexport function hasIssues(issues: FormIssues): boolean {\n return Object.keys(issues).length > 0;\n}\n\n/** The two forms hold the same event (the dialog asks before dropping changes). */\nexport function sameForm(a: EventForm, b: EventForm): boolean {\n const comparable = (form: EventForm) => JSON.stringify({ ...form, title: form.title.trim() });\n return comparable(a) === comparable(b);\n}\n"],"mappings":";;;;;AA6CA,IAAMA,IAAY,KAGLC,IAAkC;CAAC;CAAI;CAAI;CAAI;AAAE;AA6E9D,SAAgBC,EAAU,GAA2B;CACnD,OAAOC,EAAeC,EAAK,OAAOA,EAAK,QAAQ;AACjD;AAGA,SAAgBC,EAAQ,GAA2B;CACjD,OAAOF,EAAeC,EAAK,KAAKA,EAAK,QAAQ;AAC/C;AAGA,SAAgBE,EAAW,GAA4B;CACrD,OAAOF,EAAK,SAASA,EAAK,WAAWF,EAAUE,CAAI,CAAC,CAAC;AACvD;AAGA,SAAgBG,EAAa,GAAuB;CAClD,OAAOH,EAAK,yBAAS,IAAI,KAAK,GAAGA,EAAK,SAAS,eAAe,IAAIA,EAAK;AACzE;AAGA,SAAgBI,EAAW,GAAuB;CAChD,OAAOJ,EAAK,yBAAS,IAAI,KAAK,GAAGK,EAAQL,EAAK,SAAS,CAAC,EAAE,eAAe,IAAIA,EAAK;AACpF;AAGA,SAAgBM,EAAc,GAAyB;CACrD,OAAO,KAAK,OAAON,EAAK,IAAI,QAAQ,IAAIA,EAAK,MAAM,QAAQ,KAAKJ,CAAS;AAC3E;AAGA,SA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ChCA,EAAK,SACdA,EAAK,WAAWA,EAAK,WACrBA,EAAK,IAAI,QAAQ,IAAIA,EAAK,MAAM,QAAQ,OACjC,EAAO,OAAO,mBACrBA,EAAK,SAAS,KAAK,MAAM,MAAM,CAACwH,EAAWxH,EAAK,QAAQ,MAAG,EAAO,QAAQ,kBAC1EA,EAAK,OAAO,SAAS,UAAU;EACjC,IAAMyH,IAAUC,GAAY1H,EAAK,OAAO,MAAMe,EAASf,CAAI,CAAC;EAC5D,AAAIyH,MAAS,EAAO,SAASA;CAC/B;CACA,OAAOF;AACT;AAEA,SAAgBI,GAAU,GAA6B;CACrD,OAAO,OAAO,KAAKJ,CAAM,CAAC,CAAC,SAAS;AACtC;AAGA,SAAgBK,GAAS,GAAc,GAAuB;CAC5D,IAAMC,KAAc,MAAoB,KAAK,UAAU;EAAE,GAAG7H;EAAM,OAAOA,EAAK,MAAM,KAAK;CAAE,CAAC;CAC5F,OAAO6H,EAAW7C,CAAC,MAAM6C,EAAW5C,CAAC;AACvC"}
@@ -1,15 +1,15 @@
1
- import { eventRoom as e } from "../events/eventModel.js";
2
- import { dayDifference as t, eventDays as n, instantToZoned as r, zonedTimeToInstant as i } from "../time/calendarTime.js";
3
- import { lengthMinutes as a, startInstant as o, withSlot as s } from "./eventForm.js";
4
- import { movesDirectly as c, roomBusySpans as l } from "./findTime.js";
1
+ import { editDraftFor as e, eventRoom as t } from "../events/eventModel.js";
2
+ import { dayDifference as n, eventDays as r, instantToZoned as i, zonedTimeToInstant as a } from "../time/calendarTime.js";
3
+ import { lengthMinutes as o, startInstant as s, withSlot as c } from "./eventForm.js";
4
+ import { movesDirectly as l, roomBusySpans as u } from "./findTime.js";
5
5
  // src/v2/event/findTimeSource.ts
6
- function u(e) {
6
+ function d(e) {
7
7
  if (e.kind === "form") return e.form.guests;
8
8
  if (e.kind === "none") return [];
9
9
  let t = e.event;
10
10
  return t.guests.filter((e) => !e.organizer && e.userId !== t.organizerId);
11
11
  }
12
- function d(e, t, n) {
12
+ function f(e, t, n) {
13
13
  let r = t ? [{
14
14
  key: `u:${t}`,
15
15
  userId: t,
@@ -17,7 +17,7 @@ function d(e, t, n) {
17
17
  role: n.organiser,
18
18
  required: !0
19
19
  }] : [];
20
- for (let i of u(e)) i.userId && i.userId === t || r.push({
20
+ for (let i of d(e)) i.userId && i.userId === t || r.push({
21
21
  key: i.userId ? `u:${i.userId}` : `e:${i.email ?? ""}`,
22
22
  userId: i.userId,
23
23
  name: i.name ?? i.email ?? n.guest,
@@ -26,23 +26,23 @@ function d(e, t, n) {
26
26
  });
27
27
  return r;
28
28
  }
29
- function f(t) {
30
- if (t.kind === "form") return t.form.allDay ? null : t.form.roomId;
31
- if (t.kind === "none") return null;
32
- let n = e(t.event);
29
+ function p(e) {
30
+ if (e.kind === "form") return e.form.allDay ? null : e.form.roomId;
31
+ if (e.kind === "none") return null;
32
+ let n = t(e.event);
33
33
  return n && (n.status === "APPROVED" || n.status === "PENDING") ? n.resourceId : null;
34
34
  }
35
- function p(t) {
36
- let n = t.kind === "none" ? null : t.event, r = n ? e(n) : null;
37
- return r && r.resourceId === f(t) ? r.name : null;
35
+ function m(e) {
36
+ let n = e.kind === "none" ? null : e.event, r = n ? t(n) : null;
37
+ return r && r.resourceId === p(e) ? r.name : null;
38
38
  }
39
- function m(e, t, n, r, i) {
39
+ function h(e, t, n, r, i) {
40
40
  if (e === null) return null;
41
41
  let a = t.rooms.find((t) => t.id === e);
42
42
  if (a) return {
43
43
  id: `room:${a.id}`,
44
44
  name: a.name,
45
- busy: l(a, r.from, r.to, i)
45
+ busy: u(a, r.from, r.to, i)
46
46
  };
47
47
  if (t.status !== "ready") return null;
48
48
  let o = {
@@ -56,52 +56,52 @@ function m(e, t, n, r, i) {
56
56
  busy: [o]
57
57
  };
58
58
  }
59
- function h(e) {
59
+ function g(e) {
60
60
  let t = 60;
61
- return e.kind === "form" && !e.form.allDay && (t = a(e.form)), e.kind === "event" && !e.event.allDay && (t = Math.round((e.event.end.getTime() - e.event.start.getTime()) / 6e4)), t >= 15 && t <= 480 ? t : 60;
61
+ return e.kind === "form" && !e.form.allDay && (t = o(e.form)), e.kind === "event" && !e.event.allDay && (t = Math.round((e.event.end.getTime() - e.event.start.getTime()) / 6e4)), t >= 15 && t <= 480 ? t : 60;
62
62
  }
63
- function g(e, t, i) {
64
- let a = i;
65
- return e.kind === "form" ? a = e.form.allDay ? e.form.firstDay : r(o(e.form), t).date : e.kind === "event" && (a = e.event.allDay ? n(e.event, t).start : r(e.event.start, t).date), a < i ? i : a;
63
+ function _(e, t, n) {
64
+ let a = n;
65
+ return e.kind === "form" ? a = e.form.allDay ? e.form.firstDay : i(s(e.form), t).date : e.kind === "event" && (a = e.event.allDay ? r(e.event, t).start : i(e.event.start, t).date), a < n ? n : a;
66
66
  }
67
- function _(e, n) {
68
- let a = i(e.date, e.start, n), o = r(new Date(a.getTime() + e.length * 6e4), n);
69
- return t(e.date, o.date) * 1440 + o.minutes;
67
+ function v(e, t) {
68
+ let r = a(e.date, e.start, t), o = i(new Date(r.getTime() + e.length * 6e4), t);
69
+ return n(e.date, o.date) * 1440 + o.minutes;
70
70
  }
71
- function v(e, t, n, r, a) {
72
- if (t.kind === "form") return {
71
+ function y(t, n, r, i, o) {
72
+ if (n.kind === "form") return {
73
73
  kind: "fillForm",
74
- form: s(t.form, {
75
- ...e,
76
- timeZone: a
74
+ form: c(n.form, {
75
+ ...t,
76
+ timeZone: o
77
77
  })
78
78
  };
79
- let o = i(e.date, e.start, a), l = new Date(o.getTime() + e.length * 6e4), u = _(e, a);
80
- if (t.kind === "none") return {
79
+ let s = a(t.date, t.start, o), u = new Date(s.getTime() + t.length * 6e4), d = v(t, o);
80
+ if (n.kind === "none") return {
81
81
  kind: "openDialog",
82
82
  draft: {
83
- date: e.date,
84
- start: e.start,
85
- end: u,
83
+ date: t.date,
84
+ start: t.start,
85
+ end: d,
86
86
  allDay: !1
87
87
  }
88
88
  };
89
- let d = t.event;
90
- return c(d, n, r, a) ? {
89
+ let f = n.event;
90
+ return l(f, r, i, o) ? {
91
91
  kind: "move",
92
- event: d,
93
- start: o,
94
- end: l
92
+ event: f,
93
+ start: s,
94
+ end: u
95
95
  } : {
96
96
  kind: "openDialog",
97
97
  draft: {
98
- eventId: d.id,
99
- date: e.date,
100
- start: e.start,
101
- end: u
98
+ ...e(f),
99
+ date: t.date,
100
+ start: t.start,
101
+ end: d
102
102
  }
103
103
  };
104
104
  }
105
- export { p as bookedRoomNameOf, m as findTimeRoomOf, d as participantsOf, _ as pickEndClock, f as roomIdOf, g as startDayOf, h as startLengthOf, v as stepForPick };
105
+ export { m as bookedRoomNameOf, h as findTimeRoomOf, f as participantsOf, v as pickEndClock, p as roomIdOf, _ as startDayOf, g as startLengthOf, y as stepForPick };
106
106
 
107
107
  //# sourceMappingURL=findTimeSource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"findTimeSource.js","names":["guestsOf","basis","event","guest","participantsOf","list","me","words","roomIdOf","booking","eventRoom","bookedRoomNameOf","findTimeRoomOf","roomId","room","rooms","item","roomBusySpans","range","ownEventId","always","startLengthOf","length","lengthMinutes","startDayOf","day","today","instantToZoned","startInstant","timeZone","eventDays","pickEndClock","start","zonedTimeToInstant","time","end","dayDifference","stepForPick","withSlot","endAt","movesDirectly","calendar"],"sources":["../../../src/v2/event/findTimeSource.ts"],"sourcesContent":["/**\n * Who and what Find a time looks at (BOFF-15698 A2), from where it opened: the event dialog's\n * form, an event's peek, or the page's ⋯ menu. Pure.\n */\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport { eventRoom } from '../events/eventModel';\nimport { dayDifference, eventDays, instantToZoned, zonedTimeToInstant } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, CalendarV2EventDraft } from '../types';\nimport { lengthMinutes, startInstant, withSlot, type EventForm } from './eventForm';\nimport { movesDirectly, roomBusySpans, type BusySpan } from './findTime';\nimport type { RoomForEvent } from './place';\n\n/** A time picked: `start` minutes on the calendar's clock of `date`, lasting `length`. */\nexport interface PickedTime {\n date: DateValue;\n start: number;\n length: number;\n}\n\n/** Where it opened, once what it looks at is in hand. */\nexport type FindTimeBasis =\n | { kind: 'form'; form: EventForm; event: CalendarEventV2 | null }\n | { kind: 'event'; event: CalendarEventV2 }\n | { kind: 'none' };\n\nexport interface Participant {\n /** `u:<userId>`, or `e:<email>` for someone outside the workspace. */\n key: string;\n userId: string | null;\n name: string;\n /** \"Organiser\", \"Required\", \"Optional\". */\n role: string;\n required: boolean;\n}\n\n/** The words a participant list needs, already translated. */\nexport interface ParticipantWords {\n you: string;\n organiser: string;\n required: string;\n optional: string;\n guest: string;\n}\n\ninterface GuestLike {\n userId: string | null;\n email: string | null;\n name: string | null;\n optional: boolean;\n}\n\nfunction guestsOf(basis: FindTimeBasis): GuestLike[] {\n if (basis.kind === 'form') return basis.form.guests;\n if (basis.kind === 'none') return [];\n const event = basis.event;\n return event.guests.filter((guest) => !guest.organizer && guest.userId !== event.organizerId);\n}\n\n/** The person first (as organiser), then the guests: each once. */\nexport function participantsOf(\n basis: FindTimeBasis,\n me: string | null,\n words: ParticipantWords\n): Participant[] {\n const list: Participant[] = me\n ? [{ key: `u:${me}`, userId: me, name: words.you, role: words.organiser, required: true }]\n : [];\n for (const guest of guestsOf(basis)) {\n if (guest.userId && guest.userId === me) continue;\n list.push({\n key: guest.userId ? `u:${guest.userId}` : `e:${guest.email ?? ''}`,\n userId: guest.userId,\n name: guest.name ?? guest.email ?? words.guest,\n role: guest.optional ? words.optional : words.required,\n required: !guest.optional,\n });\n }\n return list;\n}\n\n/** The room the time is for: the form's (not for all day), or the event's booked one. */\nexport function roomIdOf(basis: FindTimeBasis): string | null {\n if (basis.kind === 'form') return basis.form.allDay ? null : basis.form.roomId;\n if (basis.kind === 'none') return null;\n const booking = eventRoom(basis.event);\n return booking && (booking.status === 'APPROVED' || booking.status === 'PENDING')\n ? booking.resourceId\n : null;\n}\n\n/** The booked room's name, from the event's booking (for a room the rooms list no longer has). */\nexport function bookedRoomNameOf(basis: FindTimeBasis): string | null {\n const event = basis.kind === 'none' ? null : basis.event;\n const booking = event ? eventRoom(event) : null;\n return booking && booking.resourceId === roomIdOf(basis) ? booking.name : null;\n}\n\n/** The room's row in Find a time. */\nexport interface FindTimeRoom {\n /** `room:<id>`, never a person's key. */\n id: string;\n name: string;\n busy: BusySpan[];\n}\n\n/**\n * The room the time is for, as Find a time weighs it: its bookings (its buffers counted, the\n * event's own left out); nothing while the rooms load; and one the rooms list no longer has\n * (deleted, or closed down) busy all along, so no time is called free with it.\n */\nexport function findTimeRoomOf(\n roomId: string | null,\n rooms: { rooms: readonly RoomForEvent[]; status: string },\n name: string,\n range: { from: Date; to: Date },\n ownEventId: string | null\n): FindTimeRoom | null {\n if (roomId === null) return null;\n const room = rooms.rooms.find((item) => item.id === roomId);\n if (room) {\n return {\n id: `room:${room.id}`,\n name: room.name,\n busy: roomBusySpans(room, range.from, range.to, ownEventId),\n };\n }\n if (rooms.status !== 'ready') return null;\n const always: BusySpan = { start: range.from.getTime(), end: range.to.getTime(), kind: 'closed' };\n return { id: `room:${roomId}`, name, busy: [always] };\n}\n\n/** The length to start with: the event's own (15 minutes to 8 hours), else an hour. */\nexport function startLengthOf(basis: FindTimeBasis): number {\n let length = 60;\n if (basis.kind === 'form' && !basis.form.allDay) length = lengthMinutes(basis.form);\n if (basis.kind === 'event' && !basis.event.allDay) {\n length = Math.round((basis.event.end.getTime() - basis.event.start.getTime()) / 60_000);\n }\n return length >= 15 && length <= 8 * 60 ? length : 60;\n}\n\n/**\n * The day to start on, on the calendar's clock: the event's (an all-day one's first day, not\n * its stored UTC midnight), never before today.\n */\nexport function startDayOf(basis: FindTimeBasis, timeZone: string, today: DateValue): DateValue {\n let day = today;\n if (basis.kind === 'form') {\n day = basis.form.allDay\n ? basis.form.firstDay\n : instantToZoned(startInstant(basis.form), timeZone).date;\n } else if (basis.kind === 'event') {\n day = basis.event.allDay\n ? eventDays(basis.event, timeZone).start\n : instantToZoned(basis.event.start, timeZone).date;\n }\n return day < today ? today : day;\n}\n\n/**\n * A pick's end on its day's clock (past 1440, the next day's): its start's instant plus its\n * length, so a time across a change of the clocks ends where the clock says.\n */\nexport function pickEndClock(time: PickedTime, timeZone: string): number {\n const start = zonedTimeToInstant(time.date, time.start, timeZone);\n const end = instantToZoned(new Date(start.getTime() + time.length * 60_000), timeZone);\n return dayDifference(time.date, end.date) * 1440 + end.minutes;\n}\n\n/** What \"Use this time\" does. */\nexport type PickStep =\n /** Back to the event dialog, its form at the time. */\n | { kind: 'fillForm'; form: EventForm }\n /** The event moves there (with Undo, as a drag does). */\n | { kind: 'move'; event: CalendarEventV2; start: Date; end: Date }\n /** The event dialog opens with the time: the event's, or a new one. */\n | { kind: 'openDialog'; draft: CalendarV2EventDraft };\n\n/**\n * What \"Use this time\" does, from where Find a time opened: from the event dialog the time fills\n * its form; from an event's peek the event moves there when a drag could move it (`movesDirectly`)\n * and otherwise the event dialog opens with the time, to ask what it must and move the room too;\n * from ⋯ a new event starts there. `calendar` is the event's.\n */\nexport function stepForPick(\n time: PickedTime,\n basis: FindTimeBasis,\n calendar: CalendarV2 | undefined,\n me: string | null,\n timeZone: string\n): PickStep {\n if (basis.kind === 'form') {\n return { kind: 'fillForm', form: withSlot(basis.form, { ...time, timeZone }) };\n }\n const start = zonedTimeToInstant(time.date, time.start, timeZone);\n const endAt = new Date(start.getTime() + time.length * 60_000);\n // A draft's end is a time on its day's clock, so a time across a change of the clocks keeps\n // its length.\n const end = pickEndClock(time, timeZone);\n if (basis.kind === 'none') {\n return {\n kind: 'openDialog',\n draft: { date: time.date, start: time.start, end, allDay: false },\n };\n }\n const event = basis.event;\n if (movesDirectly(event, calendar, me, timeZone)) {\n return { kind: 'move', event, start, end: endAt };\n }\n return {\n kind: 'openDialog',\n draft: { eventId: event.id, date: time.date, start: time.start, end },\n };\n}\n"],"mappings":";;;;;AAmDA,SAASA,EAAS,GAAmC;CACnD,IAAIC,EAAM,SAAS,QAAQ,OAAOA,EAAM,KAAK;CAC7C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AIE,EAAK,SAAS,GAAM,GAAGL,CAAQ;CACrF,OAAOO,EAAcF,EAAK,MAAMC,EAAI,IAAI,IAAI,OAAOA,EAAI;AACzD;AAiBA,SAAgBE,EACd,GACA,GACA,GACA,GACA,GACU;CACV,IAAIpC,EAAM,SAAS,QACjB,OAAO;EAAE,MAAM;EAAY,MAAMqC,EAASrC,EAAM,MAAM;GAAE,GAAGiC;GAAM;EAAS,CAAC;CAAE;CAE/E,IAAMF,IAAQC,EAAmBC,EAAK,MAAMA,EAAK,OAAOL,CAAQ,GAC1DU,IAAQ,IAAI,KAAKP,EAAM,QAAQ,IAAIE,EAAK,SAAS,GAAM,GAGvDC,IAAMJ,EAAaG,GAAML,CAAQ;CACvC,IAAI5B,EAAM,SAAS,QACjB,OAAO;EACL,MAAM;EACN,OAAO;GAAE,MAAMiC,EAAK;GAAM,OAAOA,EAAK;GAAO;GAAK,QAAQ;EAAM;CAClE;CAEF,IAAMhC,IAAQD,EAAM;CAIpB,OAHIuC,EAActC,GAAOuC,GAAUnC,GAAIuB,CAAQ,IACtC;EAAE,MAAM;EAAQ;EAAO;EAAO,KAAKU;CAAM,IAE3C;EACL,MAAM;EACN,OAAO;GAAE,SAASrC,EAAM;GAAI,MAAMgC,EAAK;GAAM,OAAOA,EAAK;GAAO;EAAI;CACtE;AACF"}
1
+ {"version":3,"file":"findTimeSource.js","names":["guestsOf","basis","event","guest","participantsOf","list","me","words","roomIdOf","booking","eventRoom","bookedRoomNameOf","findTimeRoomOf","roomId","room","rooms","item","roomBusySpans","range","ownEventId","always","startLengthOf","length","lengthMinutes","startDayOf","day","today","instantToZoned","startInstant","timeZone","eventDays","pickEndClock","start","zonedTimeToInstant","time","end","dayDifference","stepForPick","withSlot","endAt","movesDirectly","calendar","editDraftFor"],"sources":["../../../src/v2/event/findTimeSource.ts"],"sourcesContent":["/**\n * Who and what Find a time looks at (BOFF-15698 A2), from where it opened: the event dialog's\n * form, an event's peek, or the page's ⋯ menu. Pure.\n */\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport { editDraftFor, eventRoom } from '../events/eventModel';\nimport { dayDifference, eventDays, instantToZoned, zonedTimeToInstant } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, CalendarV2EventDraft } from '../types';\nimport { lengthMinutes, startInstant, withSlot, type EventForm } from './eventForm';\nimport { movesDirectly, roomBusySpans, type BusySpan } from './findTime';\nimport type { RoomForEvent } from './place';\n\n/** A time picked: `start` minutes on the calendar's clock of `date`, lasting `length`. */\nexport interface PickedTime {\n date: DateValue;\n start: number;\n length: number;\n}\n\n/** Where it opened, once what it looks at is in hand. */\nexport type FindTimeBasis =\n | { kind: 'form'; form: EventForm; event: CalendarEventV2 | null }\n | { kind: 'event'; event: CalendarEventV2 }\n | { kind: 'none' };\n\nexport interface Participant {\n /** `u:<userId>`, or `e:<email>` for someone outside the workspace. */\n key: string;\n userId: string | null;\n name: string;\n /** \"Organiser\", \"Required\", \"Optional\". */\n role: string;\n required: boolean;\n}\n\n/** The words a participant list needs, already translated. */\nexport interface ParticipantWords {\n you: string;\n organiser: string;\n required: string;\n optional: string;\n guest: string;\n}\n\ninterface GuestLike {\n userId: string | null;\n email: string | null;\n name: string | null;\n optional: boolean;\n}\n\nfunction guestsOf(basis: FindTimeBasis): GuestLike[] {\n if (basis.kind === 'form') return basis.form.guests;\n if (basis.kind === 'none') return [];\n const event = basis.event;\n return event.guests.filter((guest) => !guest.organizer && guest.userId !== event.organizerId);\n}\n\n/** The person first (as organiser), then the guests: each once. */\nexport function participantsOf(\n basis: FindTimeBasis,\n me: string | null,\n words: ParticipantWords\n): Participant[] {\n const list: Participant[] = me\n ? [{ key: `u:${me}`, userId: me, name: words.you, role: words.organiser, required: true }]\n : [];\n for (const guest of guestsOf(basis)) {\n if (guest.userId && guest.userId === me) continue;\n list.push({\n key: guest.userId ? `u:${guest.userId}` : `e:${guest.email ?? ''}`,\n userId: guest.userId,\n name: guest.name ?? guest.email ?? words.guest,\n role: guest.optional ? words.optional : words.required,\n required: !guest.optional,\n });\n }\n return list;\n}\n\n/** The room the time is for: the form's (not for all day), or the event's booked one. */\nexport function roomIdOf(basis: FindTimeBasis): string | null {\n if (basis.kind === 'form') return basis.form.allDay ? null : basis.form.roomId;\n if (basis.kind === 'none') return null;\n const booking = eventRoom(basis.event);\n return booking && (booking.status === 'APPROVED' || booking.status === 'PENDING')\n ? booking.resourceId\n : null;\n}\n\n/** The booked room's name, from the event's booking (for a room the rooms list no longer has). */\nexport function bookedRoomNameOf(basis: FindTimeBasis): string | null {\n const event = basis.kind === 'none' ? null : basis.event;\n const booking = event ? eventRoom(event) : null;\n return booking && booking.resourceId === roomIdOf(basis) ? booking.name : null;\n}\n\n/** The room's row in Find a time. */\nexport interface FindTimeRoom {\n /** `room:<id>`, never a person's key. */\n id: string;\n name: string;\n busy: BusySpan[];\n}\n\n/**\n * The room the time is for, as Find a time weighs it: its bookings (its buffers counted, the\n * event's own left out); nothing while the rooms load; and one the rooms list no longer has\n * (deleted, or closed down) busy all along, so no time is called free with it.\n */\nexport function findTimeRoomOf(\n roomId: string | null,\n rooms: { rooms: readonly RoomForEvent[]; status: string },\n name: string,\n range: { from: Date; to: Date },\n ownEventId: string | null\n): FindTimeRoom | null {\n if (roomId === null) return null;\n const room = rooms.rooms.find((item) => item.id === roomId);\n if (room) {\n return {\n id: `room:${room.id}`,\n name: room.name,\n busy: roomBusySpans(room, range.from, range.to, ownEventId),\n };\n }\n if (rooms.status !== 'ready') return null;\n const always: BusySpan = { start: range.from.getTime(), end: range.to.getTime(), kind: 'closed' };\n return { id: `room:${roomId}`, name, busy: [always] };\n}\n\n/** The length to start with: the event's own (15 minutes to 8 hours), else an hour. */\nexport function startLengthOf(basis: FindTimeBasis): number {\n let length = 60;\n if (basis.kind === 'form' && !basis.form.allDay) length = lengthMinutes(basis.form);\n if (basis.kind === 'event' && !basis.event.allDay) {\n length = Math.round((basis.event.end.getTime() - basis.event.start.getTime()) / 60_000);\n }\n return length >= 15 && length <= 8 * 60 ? length : 60;\n}\n\n/**\n * The day to start on, on the calendar's clock: the event's (an all-day one's first day, not\n * its stored UTC midnight), never before today.\n */\nexport function startDayOf(basis: FindTimeBasis, timeZone: string, today: DateValue): DateValue {\n let day = today;\n if (basis.kind === 'form') {\n day = basis.form.allDay\n ? basis.form.firstDay\n : instantToZoned(startInstant(basis.form), timeZone).date;\n } else if (basis.kind === 'event') {\n day = basis.event.allDay\n ? eventDays(basis.event, timeZone).start\n : instantToZoned(basis.event.start, timeZone).date;\n }\n return day < today ? today : day;\n}\n\n/**\n * A pick's end on its day's clock (past 1440, the next day's): its start's instant plus its\n * length, so a time across a change of the clocks ends where the clock says.\n */\nexport function pickEndClock(time: PickedTime, timeZone: string): number {\n const start = zonedTimeToInstant(time.date, time.start, timeZone);\n const end = instantToZoned(new Date(start.getTime() + time.length * 60_000), timeZone);\n return dayDifference(time.date, end.date) * 1440 + end.minutes;\n}\n\n/** What \"Use this time\" does. */\nexport type PickStep =\n /** Back to the event dialog, its form at the time. */\n | { kind: 'fillForm'; form: EventForm }\n /** The event moves there (with Undo, as a drag does). */\n | { kind: 'move'; event: CalendarEventV2; start: Date; end: Date }\n /** The event dialog opens with the time: the event's, or a new one. */\n | { kind: 'openDialog'; draft: CalendarV2EventDraft };\n\n/**\n * What \"Use this time\" does, from where Find a time opened: from the event dialog the time fills\n * its form; from an event's peek the event moves there when a drag could move it (`movesDirectly`)\n * and otherwise the event dialog opens with the time, to ask what it must and move the room too;\n * from ⋯ a new event starts there. `calendar` is the event's.\n */\nexport function stepForPick(\n time: PickedTime,\n basis: FindTimeBasis,\n calendar: CalendarV2 | undefined,\n me: string | null,\n timeZone: string\n): PickStep {\n if (basis.kind === 'form') {\n return { kind: 'fillForm', form: withSlot(basis.form, { ...time, timeZone }) };\n }\n const start = zonedTimeToInstant(time.date, time.start, timeZone);\n const endAt = new Date(start.getTime() + time.length * 60_000);\n // A draft's end is a time on its day's clock, so a time across a change of the clocks keeps\n // its length.\n const end = pickEndClock(time, timeZone);\n if (basis.kind === 'none') {\n return {\n kind: 'openDialog',\n draft: { date: time.date, start: time.start, end, allDay: false },\n };\n }\n const event = basis.event;\n if (movesDirectly(event, calendar, me, timeZone)) {\n return { kind: 'move', event, start, end: endAt };\n }\n return {\n kind: 'openDialog',\n draft: { ...editDraftFor(event), date: time.date, start: time.start, end },\n };\n}\n"],"mappings":";;;;;AAmDA,SAASA,EAAS,GAAmC;CACnD,IAAIC,EAAM,SAAS,QAAQ,OAAOA,EAAM,KAAK;CAC7C,IAAIA,EAAM,SAAS,QAAQ,OAAO,CAAC;CACnC,IAAMC,IAAQD,EAAM;CACpB,OAAOC,EAAM,OAAO,QAAQ,MAAU,CAACC,EAAM,aAAaA,EAAM,WAAWD,EAAM,WAAW;AAC9F;AAGA,SAAgBE,EACd,GACA,GACA,GACe;CACf,IAAMC,IAAsBC,IACxB,CAAC;EAAE,KAAK,KAAKA;EAAM,QAAQA;EAAI,MAAMC,EAAM;EAAK,MAAMA,EAAM;EAAW,UAAU;CAAK,CAAC,IACvF,CAAC;CACL,KAAK,IAAMJ,KAASH,EAASC,CAAK,GAChC,AAAIE,EAAM,UAAUA,EAAM,WAAWG,KACrCD,EAAK,KAAK;EACR,KAAKF,EAAM,SAAS,KAAKA,EAAM,WAAW,KAAKA,EAAM,SAAS;EAC9D,QAAQA,EAAM;EACd,MAAMA,EAAM,QAAQA,EAAM,SAASI,EAAM;EACzC,MAAMJ,EAAM,WAAWI,EAAM,WAAWA,EAAM;EAC9C,UAAU,CAACJ,EAAM;CACnB,CAAC;CAEH,OAAOE;AACT;AAGA,SAAgBG,EAAS,GAAqC;CAC5D,IAAIP,EAAM,SAAS,QAAQ,OAAOA,EAAM,KAAK,SAAS,OAAOA,EAAM,KAAK;CACxE,IAAIA,EAAM,SAAS,QAAQ,OAAO;CAClC,IAAMQ,IAAUC,EAAUT,EAAM,KAAK;CACrC,OAAOQ,MAAYA,EAAQ,WAAW,cAAcA,EAAQ,WAAW,aACnEA,EAAQ,a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","SECOND_MS","isWeekday","day","value","isFrequency","frequency","weekdayCode","weekdayOf","date","dayOfMonth","parseDateValue","daysInMonth","parts","nthOfMonth","isLastOfMonth","inWeekOrder","set","days","sameDays","left","a","right","b","index","presetsFor","presets","anchor","presetRule","never","start","preset","presetOf","candidate","rule","withFrequency","withWeekdayToggled","item","followStart","oldDay","before","newDay","after","kept","ruleProblem","utcStamp","instant","untilStamp","last","nextMidnight","zonedTimeToInstant","addDays","monthlyWeekday","pattern","buildRRule","onlyStart","ruleLine","rules","text","line","untilDate","match","year","month","hours","minutes","seconds","utc","zone","minute","instantToZoned","weekdayEntries","entries","raw","ordinal","monthlyPatternOf","entry","parseRRule","fields","part","at","name","interval","intervalText","weekStart","end","countText","untilText","count","byDayText","byDay","setPosText","monthDayText","monthText","startDay","base","named","monthly"],"sources":["../../../src/v2/event/rrule.ts"],"sourcesContent":["/**\n * Repeat rules for the event dialog (BOFF-15698 A2): the RRULE the Repeat menu and its Custom\n * builder write, and a stored one read back into them. Pure.\n *\n * - A rule is always tied to the event's start (`RuleAnchor`): the weekly days include the\n * start's weekday, and a monthly rule is on the start's day of the month, its nth weekday or\n * its last weekday. So the start is always an occurrence, as RFC 5545 asks.\n * - What follows from the start is left to DTSTART rather than written out: weekly on the\n * start's day alone has no BYDAY, monthly on its day no BYMONTHDAY, yearly nothing more. The\n * service expands series in UTC until B7, and a written-out weekday lands a day early or late\n * for an event whose UTC date isn't its own (01:00 in Tokyo is the day before in UTC).\n * - UNTIL is a UTC time: the end of the last day on the event's clock, or for an all-day event\n * (stored at UTC midnights) the end of that day in UTC. Read back, it is the last day an\n * occurrence can start on.\n * - A stored rule this can't hold (BYHOUR, BYWEEKNO, EXDATE lines, several rules, a monthly day\n * other than the start's …) is `kept`: the menu names it, and saving leaves it as it is\n * unless the person picks another.\n */\nimport { addDays, parseDateValue, type DateValue } from '@burdenoff/fe-libs/ui';\nimport { instantToZoned, weekdayOf, zonedTimeToInstant } from '../time/calendarTime';\n\nexport type Weekday = 'SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA';\n\n/** By JavaScript's day number: 0 Sunday to 6 Saturday. */\nexport const WEEKDAYS: readonly Weekday[] = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];\n\n/** Monday to Friday. */\nexport const WORKWEEK: readonly Weekday[] = ['MO', 'TU', 'WE', 'TH', 'FR'];\n\nexport type RepeatFrequency = 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';\n\n/** A monthly rule: on the start's day of the month, its nth weekday, or its last weekday. */\nexport type MonthlyPattern = 'monthDay' | 'nthWeekday' | 'lastWeekday';\n\nexport type RepeatEnd =\n | { kind: 'never' }\n | { kind: 'count'; count: number }\n /** The last day an occurrence may start on, on the event's clock. */\n | { kind: 'until'; date: DateValue };\n\nexport interface RepeatRule {\n frequency: RepeatFrequency;\n /** Every `interval` days, weeks, months or years. */\n interval: number;\n /** Weekly: the days, in week order from Monday, the start's among them. Otherwise empty. */\n weekdays: Weekday[];\n /** Monthly: which day of each month. Otherwise null. */\n monthly: MonthlyPattern | null;\n end: RepeatEnd;\n}\n\n/** What a rule is tied to: the event's start, on its own clock. */\nexport interface RuleAnchor {\n start: DateValue;\n /** Minutes after midnight on the event's clock (0 for an all-day event). */\n startMinutes: number;\n timeZone: string;\n allDay: boolean;\n}\n\nexport type ParsedRepeat =\n { kind: 'none' } | { kind: 'rule'; rule: RepeatRule } | { kind: 'kept'; text: string };\n\n/** The menu's ready-made rules. */\nexport type RepeatPreset =\n 'daily' | 'weekly' | 'monthlyNth' | 'monthlyLast' | 'yearly' | 'weekdays';\n\n/** The longest interval and count the builder offers. */\nexport const MAX_INTERVAL = 99;\nexport const MAX_COUNT = 999;\n\nconst WEEK_ORDER: readonly Weekday[] = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'];\nconst FREQUENCIES: readonly RepeatFrequency[] = ['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'];\nconst SECOND_MS = 1000;\n\nfunction isWeekday(value: string | undefined): value is Weekday {\n return WEEKDAYS.some((day) => day === value);\n}\n\nfunction isFrequency(value: string | undefined): value is RepeatFrequency {\n return FREQUENCIES.some((frequency) => frequency === value);\n}\n\n/** The start's weekday. */\nexport function weekdayCode(date: DateValue): Weekday {\n return WEEKDAYS[weekdayOf(date)] ?? 'MO';\n}\n\nfunction dayOfMonth(date: DateValue): number {\n return parseDateValue(date)?.day ?? 1;\n}\n\nfunction daysInMonth(date: DateValue): number {\n const parts = parseDateValue(date);\n if (!parts) return 31;\n return new Date(Date.UTC(parts.year, parts.month, 0)).getUTCDate();\n}\n\n/** Which of its weekday the date is in its month: 1 for the first … 5 for a fifth. */\nexport function nthOfMonth(date: DateValue): number {\n return Math.ceil(dayOfMonth(date) / 7);\n}\n\n/** The date is the last of its weekday in its month. */\nexport function isLastOfMonth(date: DateValue): boolean {\n return dayOfMonth(date) + 7 > daysInMonth(date);\n}\n\n/** Days in week order from Monday, each once. */\nfunction inWeekOrder(days: readonly Weekday[]): Weekday[] {\n const set = new Set(days);\n return WEEK_ORDER.filter((day) => set.has(day));\n}\n\nfunction sameDays(a: readonly Weekday[], b: readonly Weekday[]): boolean {\n const left = inWeekOrder(a);\n const right = inWeekOrder(b);\n return left.length === right.length && left.every((day, index) => day === right[index]);\n}\n\n// ── The menu's rules ─────────────────────────────────────────────────────────\n\n/**\n * The presets the menu offers for this start: \"on the last …\" only in a month's last week,\n * \"every weekday\" only from a weekday (the start is always an occurrence).\n */\nexport function presetsFor(anchor: RuleAnchor): RepeatPreset[] {\n const presets: RepeatPreset[] = ['daily', 'weekly'];\n if (nthOfMonth(anchor.start) <= 4) presets.push('monthlyNth');\n if (isLastOfMonth(anchor.start)) presets.push('monthlyLast');\n presets.push('yearly');\n if (WORKWEEK.includes(weekdayCode(anchor.start))) presets.push('weekdays');\n return presets;\n}\n\n/** A preset's rule for this start, repeating for ever. */\nexport function presetRule(preset: RepeatPreset, anchor: RuleAnchor): RepeatRule {\n const never: RepeatEnd = { kind: 'never' };\n const start = weekdayCode(anchor.start);\n switch (preset) {\n case 'daily':\n return { frequency: 'DAILY', interval: 1, weekdays: [], monthly: null, end: never };\n case 'weekly':\n return { frequency: 'WEEKLY', interval: 1, weekdays: [start], monthly: null, end: never };\n case 'monthlyNth':\n return { frequency: 'MONTHLY', interval: 1, weekdays: [], monthly: 'nthWeekday', end: never };\n case 'monthlyLast':\n return {\n frequency: 'MONTHLY',\n interval: 1,\n weekdays: [],\n monthly: 'lastWeekday',\n end: never,\n };\n case 'yearly':\n return { frequency: 'YEARLY', interval: 1, weekdays: [], monthly: null, end: never };\n case 'weekdays':\n return {\n frequency: 'WEEKLY',\n interval: 1,\n weekdays: [...WORKWEEK],\n monthly: null,\n end: never,\n };\n }\n}\n\n/** The preset a rule is, for this start; null for anything else (a custom rule). */\nexport function presetOf(rule: RepeatRule, anchor: RuleAnchor): RepeatPreset | null {\n for (const preset of presetsFor(anchor)) {\n const candidate = presetRule(preset, anchor);\n if (\n candidate.frequency === rule.frequency &&\n candidate.interval === rule.interval &&\n sameDays(candidate.weekdays, rule.weekdays) &&\n candidate.monthly === rule.monthly &&\n rule.end.kind === 'never'\n ) {\n return preset;\n }\n }\n return null;\n}\n\n// ── The Custom builder's changes ─────────────────────────────────────────────\n\n/** A new frequency: weekly starts on the start's day, monthly on its day of the month. */\nexport function withFrequency(\n rule: RepeatRule,\n frequency: RepeatFrequency,\n anchor: RuleAnchor\n): RepeatRule {\n if (rule.frequency === frequency) return rule;\n return {\n ...rule,\n frequency,\n weekdays: frequency === 'WEEKLY' ? [weekdayCode(anchor.start)] : [],\n monthly: frequency === 'MONTHLY' ? 'monthDay' : null,\n };\n}\n\n/** Turns a weekly day on or off; the start's own day stays on. */\nexport function withWeekdayToggled(rule: RepeatRule, day: Weekday, anchor: RuleAnchor): RepeatRule {\n if (rule.frequency !== 'WEEKLY' || day === weekdayCode(anchor.start)) return rule;\n const days = rule.weekdays.includes(day)\n ? rule.weekdays.filter((item) => item !== day)\n : [...rule.weekdays, day];\n return { ...rule, weekdays: inWeekOrder(days) };\n}\n\n/**\n * The rule after the event's start moved, so the start stays an occurrence: a weekly rule\n * takes the new start's day (the old start's day goes when it was the only one); a monthly\n * nth weekday past the fourth becomes the last, and a last weekday no longer last the nth.\n */\nexport function followStart(rule: RepeatRule, before: RuleAnchor, after: RuleAnchor): RepeatRule {\n if (rule.frequency === 'WEEKLY') {\n const oldDay = weekdayCode(before.start);\n const newDay = weekdayCode(after.start);\n if (oldDay === newDay) return rule;\n const kept = rule.weekdays.length === 1 && rule.weekdays[0] === oldDay ? [] : rule.weekdays;\n return { ...rule, weekdays: inWeekOrder([...kept, newDay]) };\n }\n if (rule.frequency === 'MONTHLY') {\n if (rule.monthly === 'nthWeekday' && nthOfMonth(after.start) > 4) {\n return { ...rule, monthly: 'lastWeekday' };\n }\n if (rule.monthly === 'lastWeekday' && !isLastOfMonth(after.start)) {\n return { ...rule, monthly: 'nthWeekday' };\n }\n }\n return rule;\n}\n\nexport type RuleProblem = 'interval' | 'count' | 'untilBeforeStart' | 'noWeekdays';\n\n/** What is wrong with a rule the builder holds; null when it can be saved. */\nexport function ruleProblem(rule: RepeatRule, anchor: RuleAnchor): RuleProblem | null {\n if (!Number.isInteger(rule.interval) || rule.interval < 1 || rule.interval > MAX_INTERVAL) {\n return 'interval';\n }\n if (rule.frequency === 'WEEKLY' && rule.weekdays.length === 0) return 'noWeekdays';\n if (\n rule.end.kind === 'count' &&\n (!Number.isInteger(rule.end.count) || rule.end.count < 1 || rule.end.count > MAX_COUNT)\n ) {\n return 'count';\n }\n if (rule.end.kind === 'until' && rule.end.date < anchor.start) return 'untilBeforeStart';\n return null;\n}\n\n// ── Writing ──────────────────────────────────────────────────────────────────\n\n/** `20261231T182959Z`: an instant as RFC 5545 writes a UTC time. */\nexport function utcStamp(instant: Date): string {\n return instant\n .toISOString()\n .replace(/\\.\\d{3}Z$/, 'Z')\n .replace(/[-:]/g, '');\n}\n\n/** The UNTIL of a last day: the end of that day on the event's clock, in UTC. */\nfunction untilStamp(last: DateValue, anchor: RuleAnchor): string {\n if (anchor.allDay) return `${last.replace(/-/g, '')}T235959Z`;\n const nextMidnight = zonedTimeToInstant(addDays(last, 1), 0, anchor.timeZone);\n return utcStamp(new Date(nextMidnight.getTime() - SECOND_MS));\n}\n\n/** `3TU`, `-1FR`: the start's nth or last weekday of the month. */\nfunction monthlyWeekday(pattern: 'nthWeekday' | 'lastWeekday', anchor: RuleAnchor): string {\n const day = weekdayCode(anchor.start);\n return pattern === 'lastWeekday' ? `-1${day}` : `${nthOfMonth(anchor.start)}${day}`;\n}\n\n/** The RRULE value of a rule (without the `RRULE:` prefix), tied to `anchor`. */\nexport function buildRRule(rule: RepeatRule, anchor: RuleAnchor): string {\n const parts = [`FREQ=${rule.frequency}`];\n if (rule.interval > 1) parts.push(`INTERVAL=${rule.interval}`);\n if (rule.frequency === 'WEEKLY') {\n const days = inWeekOrder(rule.weekdays);\n const onlyStart = days.length === 1 && days[0] === weekdayCode(anchor.start);\n if (days.length > 0 && !onlyStart) parts.push(`BYDAY=${days.join(',')}`);\n }\n if (rule.frequency === 'MONTHLY' && rule.monthly && rule.monthly !== 'monthDay') {\n parts.push(`BYDAY=${monthlyWeekday(rule.monthly, anchor)}`);\n }\n if (rule.end.kind === 'count') parts.push(`COUNT=${rule.end.count}`);\n if (rule.end.kind === 'until') parts.push(`UNTIL=${untilStamp(rule.end.date, anchor)}`);\n return parts.join(';');\n}\n\n// ── Reading ──────────────────────────────────────────────────────────────────\n\n/** The rule's line: one line, or the RRULE line among DTSTART lines; null for anything more. */\nfunction ruleLine(text: string): string | null {\n const lines = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '');\n const rules = lines.filter((line) => !/^DTSTART[:;]/i.test(line));\n if (rules.length !== 1) return null;\n const [line] = rules;\n if (!line) return null;\n if (/^RRULE:/i.test(line)) return line.slice('RRULE:'.length);\n // A one-line value with another property name (EXDATE:, RDATE:, EXRULE:) isn't a rule.\n return /^[A-Z-]+[:;]/i.test(line) && !/^[A-Z]+=/i.test(line) ? null : line;\n}\n\n/** The day an UNTIL names, on the event's clock: the last day an occurrence can start. */\nfunction untilDate(value: string, anchor: RuleAnchor): DateValue | null {\n const match = /^(\\d{4})(\\d{2})(\\d{2})(?:T(\\d{2})(\\d{2})(\\d{2})(Z)?)?$/.exec(value);\n if (!match) return null;\n const [, year, month, day, hours, minutes, seconds, utc] = match;\n const date: DateValue = `${year}-${month}-${day}`;\n if (!parseDateValue(date)) return null;\n // A date, or a floating time: the day as written.\n if (hours === undefined || !utc) return date;\n const instant = new Date(\n Date.UTC(\n Number(year),\n Number(month) - 1,\n Number(day),\n Number(hours),\n Number(minutes),\n Number(seconds)\n )\n );\n const zone = anchor.allDay ? 'UTC' : anchor.timeZone;\n const minute = anchor.allDay ? 0 : anchor.startMinutes;\n let last = instantToZoned(instant, zone).date;\n // An UNTIL before that day's occurrence (an end of day in UTC, read east of UTC) ends a day\n // earlier.\n if (zonedTimeToInstant(last, minute, zone).getTime() > instant.getTime())\n last = addDays(last, -1);\n return last;\n}\n\ninterface WeekdayEntry {\n ordinal: number | null;\n day: Weekday;\n}\n\nfunction weekdayEntries(value: string): WeekdayEntry[] | null {\n const entries: WeekdayEntry[] = [];\n for (const raw of value.split(',')) {\n const match = /^([+-]?\\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(raw.trim().toUpperCase());\n const day = match?.[2];\n if (!match || !isWeekday(day)) return null;\n const ordinal = match[1] === undefined ? null : Number(match[1]);\n entries.push({ ordinal, day });\n }\n return entries;\n}\n\n/** The monthly pattern a weekday entry names for this start; null when it isn't the start's. */\nfunction monthlyPatternOf(entry: WeekdayEntry, anchor: RuleAnchor): MonthlyPattern | null {\n if (entry.day !== weekdayCode(anchor.start)) return null;\n if (entry.ordinal === -1 && isLastOfMonth(anchor.start)) return 'lastWeekday';\n if (entry.ordinal === nthOfMonth(anchor.start) && entry.ordinal <= 4) return 'nthWeekday';\n return null;\n}\n\n/**\n * Reads a stored rule: one line, with or without `RRULE:`, with an inline `DTSTART=` (the\n * service writes one) or DTSTART lines around it. What the builder can't hold for this start is\n * `kept`, never changed or dropped.\n */\nexport function parseRRule(text: string | null | undefined, anchor: RuleAnchor): ParsedRepeat {\n const raw = (text ?? '').trim();\n if (raw === '') return { kind: 'none' };\n const kept: ParsedRepeat = { kind: 'kept', text: raw };\n const line = ruleLine(raw);\n if (line === null) return kept;\n\n const fields = new Map<string, string>();\n for (const part of line.split(';')) {\n if (part.trim() === '') continue;\n const at = part.indexOf('=');\n if (at <= 0) return kept;\n const name = part.slice(0, at).trim().toUpperCase();\n if (fields.has(name)) return kept;\n fields.set(name, part.slice(at + 1).trim());\n }\n // The service's inline start; the start is the event's own.\n fields.delete('DTSTART');\n\n const frequency = fields.get('FREQ')?.toUpperCase();\n if (!isFrequency(frequency)) return kept;\n fields.delete('FREQ');\n\n let interval = 1;\n const intervalText = fields.get('INTERVAL');\n if (intervalText !== undefined) {\n interval = Number(intervalText);\n if (!/^\\d+$/.test(intervalText) || interval < 1 || interval > MAX_INTERVAL) return kept;\n fields.delete('INTERVAL');\n }\n\n // A week starting on Monday is the default; another start only matters every 2+ weeks.\n const weekStart = fields.get('WKST');\n if (weekStart !== undefined) {\n if (weekStart.toUpperCase() !== 'MO' && frequency === 'WEEKLY' && interval > 1) return kept;\n fields.delete('WKST');\n }\n\n let end: RepeatEnd = { kind: 'never' };\n const countText = fields.get('COUNT');\n const untilText = fields.get('UNTIL');\n if (countText !== undefined && untilText !== undefined) return kept;\n if (countText !== undefined) {\n const count = Number(countText);\n if (!/^\\d+$/.test(countText) || count < 1 || count > MAX_COUNT) return kept;\n end = { kind: 'count', count };\n fields.delete('COUNT');\n }\n if (untilText !== undefined) {\n const date = untilDate(untilText.toUpperCase(), anchor);\n if (!date) return kept;\n end = { kind: 'until', date };\n fields.delete('UNTIL');\n }\n\n const byDayText = fields.get('BYDAY');\n const byDay = byDayText === undefined ? null : weekdayEntries(byDayText);\n if (byDayText !== undefined && byDay === null) return kept;\n fields.delete('BYDAY');\n const setPosText = fields.get('BYSETPOS');\n fields.delete('BYSETPOS');\n const monthDayText = fields.get('BYMONTHDAY');\n fields.delete('BYMONTHDAY');\n const monthText = fields.get('BYMONTH');\n fields.delete('BYMONTH');\n // Anything else (BYHOUR, BYWEEKNO, BYYEARDAY, TZID …) is beyond the builder.\n if (fields.size > 0) return kept;\n\n const startDay = weekdayCode(anchor.start);\n const base = { interval, end };\n switch (frequency) {\n case 'DAILY': {\n if (setPosText !== undefined || monthDayText !== undefined || monthText !== undefined) {\n return kept;\n }\n if (!byDay) {\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: null } };\n }\n // \"Daily on weekdays\", as some apps write every weekday: the same as weekly on those days.\n const days = byDay.map((entry) => entry.day);\n if (\n interval !== 1 ||\n byDay.some((entry) => entry.ordinal !== null) ||\n !days.includes(startDay)\n ) {\n return kept;\n }\n return {\n kind: 'rule',\n rule: { ...base, frequency: 'WEEKLY', weekdays: inWeekOrder(days), monthly: null },\n };\n }\n case 'WEEKLY': {\n if (setPosText !== undefined || monthDayText !== undefined || monthText !== undefined) {\n return kept;\n }\n const days = byDay ? byDay.map((entry) => entry.day) : [startDay];\n if (byDay?.some((entry) => entry.ordinal !== null) || !days.includes(startDay)) return kept;\n return {\n kind: 'rule',\n rule: { ...base, frequency, weekdays: inWeekOrder(days), monthly: null },\n };\n }\n case 'MONTHLY': {\n if (monthText !== undefined) return kept;\n if (monthDayText !== undefined) {\n if (\n byDay ||\n setPosText !== undefined ||\n Number(monthDayText) !== dayOfMonth(anchor.start)\n ) {\n return kept;\n }\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: 'monthDay' } };\n }\n if (!byDay) {\n if (setPosText !== undefined) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: 'monthDay' } };\n }\n const [entry] = byDay;\n if (byDay.length !== 1 || !entry) return kept;\n let named: WeekdayEntry = entry;\n if (setPosText !== undefined) {\n // BYDAY=TU;BYSETPOS=3 is the third Tuesday, as 3TU.\n if (entry.ordinal !== null || !/^-?\\d{1,2}$/.test(setPosText)) return kept;\n named = { ordinal: Number(setPosText), day: entry.day };\n }\n const monthly = monthlyPatternOf(named, anchor);\n if (!monthly) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly } };\n }\n case 'YEARLY': {\n if (byDay || setPosText !== undefined) return kept;\n const parts = parseDateValue(anchor.start);\n if (monthText !== undefined && Number(monthText) !== parts?.month) return kept;\n if (monthDayText !== undefined && Number(monthDayText) !== parts?.day) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: null } };\n }\n }\n}\n"],"mappings":";;;AAwBA,IAAaA,IAA+B;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI,GAGxEC,IAA+B;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI,GA4CnEC,IAAiC;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI,GAC1EC,IAA0C;CAAC;CAAS;CAAU;CAAW;AAAQ,GACjFC,IAAY;AAElB,SAASC,EAAU,GAA6C;CAC9D,OAAOL,EAAS,MAAM,MAAQM,MAAQC,CAAK;AAC7C;AAEA,SAASC,EAAY,GAAqD;CACxE,OAAOL,EAAY,MAAM,MAAcM,MAAcF,CAAK;AAC5D;AAGA,SAAgBG,EAAY,GAA0B;CACpD,OAAOV,EAASW,EAAUC,CAAI,MAAM;AACtC;AAEA,SAASC,EAAW,GAAyB;CAC3C,OAAOC,EAAeF,CAAI,CAAC,EAAE,OAAO;AACtC;AAEA,SAASG,EAAY,GAAyB;CAC5C,IAAMC,IAAQF,EAAeF,CAAI;CAEjC,OADKI,IACE,IAAI,KAAK,KAAK,IAAIA,EAAM,MAAMA,EAAM,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,IAD9C;AAErB;AAGA,SAAgBC,EAAW,GAAyB;CAClD,OAAO,KAAK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,CAACL,GAEH,OADIC,MAAe,KAAA,IACZ;IAAE,MAAM;IAAQ,MAAM;KAAE,GAAGI;KAAM;KAAW,UAAU,CAAC;KAAG,SAAS;IAAW;GAAE,IADlDpD;GAGvC,IAAM,CAACiC,KAASc;GAChB,IAAIA,EAAM,WAAW,KAAK,CAACd,GAAO,OAAOjC;GACzC,IAAIqD,IAAsBpB;GAC1B,IAAIe,MAAe,KAAA,GAAW;IAE5B,IAAIf,EAAM,YAAY,QAAQ,CAAC,cAAc,KAAKe,CAAU,GAAG,OAAOhD;IACtE,IAAQ;KAAE,SAAS,OAAOgD,CAAU;KAAG,KAAKf,EAAM;IAAI;GACxD;GACA,IAAMqB,IAAUtB,EAAiBqB,GAAOrE,CAAM;GAE9C,OADKsE,IACE;IAAE,MAAM;IAAQ,MAAM;KAAE,GAAGF;KAAM;KAAW,UAAU,CAAC;KAAG;IAAQ;GAAE,IADtDpD;EAEvB;EACA,KAAK,UAAU;GACb,IAAI+C,KAASC,MAAe,KAAA,GAAW,OAAOhD;GAC9C,IAAM9B,IAAQF,EAAegB,EAAO,KAAK;GAGzC,OAFIkE,MAAc,KAAA,KAAa,OAAOA,CAAS,MAAMhF,GAAO,SACxD+E,MAAiB,KAAA,KAAa,OAAOA,CAAY,MAAM/E,GAAO,MAAY8B,IACvE;IAAE,MAAM;IAAQ,MAAM;KAAE,GAAGoD;KAAM;KAAW,UAAU,CAAC;KAAG,SAAS;IAAK;GAAE;EACnF;CACF;AACF"}
1
+ {"version":3,"file":"rrule.js","names":["WEEKDAYS","WORKWEEK","WEEK_ORDER","FREQUENCIES","SECOND_MS","isWeekday","day","value","isFrequency","frequency","weekdayCode","weekdayOf","date","dayOfMonth","parseDateValue","daysInMonth","parts","nthOfMonth","isLastOfMonth","inWeekOrder","set","days","sameDays","left","a","right","b","index","presetsFor","presets","anchor","presetRule","never","start","preset","presetOf","candidate","rule","withFrequency","withWeekdayToggled","item","followStart","oldDay","before","newDay","after","kept","ruleProblem","utcStamp","instant","untilStamp","last","nextMidnight","zonedTimeToInstant","addDays","monthlyWeekday","pattern","buildRRule","onlyStart","ruleLine","rules","text","line","untilDate","match","year","month","hours","minutes","seconds","utc","zone","minute","instantToZoned","weekdayEntries","entries","raw","ordinal","monthlyPatternOf","entry","parseRRule","fields","part","at","name","interval","intervalText","weekStart","end","countText","untilText","count","byDayText","byDay","setPosText","monthDayText","monthText","startDay","base","named","monthly"],"sources":["../../../src/v2/event/rrule.ts"],"sourcesContent":["/**\n * Repeat rules for the event dialog (BOFF-15698 A2): the RRULE the Repeat menu and its Custom\n * builder write, and a stored one read back into them. Pure.\n *\n * - A rule is always tied to the event's start (`RuleAnchor`): the weekly days include the\n * start's weekday, and a monthly rule is on the start's day of the month, its nth weekday or\n * its last weekday. So the start is always an occurrence, as RFC 5545 asks.\n * - What follows from the start is left to DTSTART rather than written out: weekly on the\n * start's day alone has no BYDAY, monthly on its day no BYMONTHDAY, yearly nothing more. The\n * service expanded series in UTC before B7 (it now expands in the event's own zone), and a\n * reader that walks in UTC puts a written-out weekday a day early or late for an event whose\n * UTC date isn't its own (01:00 in Tokyo is the day before in UTC).\n * - UNTIL is a UTC time: the end of the last day on the event's clock, or for an all-day event\n * (stored at UTC midnights) the end of that day in UTC. Read back, it is the last day an\n * occurrence can start on.\n * - A stored rule this can't hold (BYHOUR, BYWEEKNO, EXDATE lines, several rules, a monthly day\n * other than the start's …) is `kept`: the menu names it, and saving leaves it as it is\n * unless the person picks another.\n */\nimport { addDays, parseDateValue, type DateValue } from '@burdenoff/fe-libs/ui';\nimport { instantToZoned, weekdayOf, zonedTimeToInstant } from '../time/calendarTime';\n\nexport type Weekday = 'SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA';\n\n/** By JavaScript's day number: 0 Sunday to 6 Saturday. */\nexport const WEEKDAYS: readonly Weekday[] = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];\n\n/** Monday to Friday. */\nexport const WORKWEEK: readonly Weekday[] = ['MO', 'TU', 'WE', 'TH', 'FR'];\n\nexport type RepeatFrequency = 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';\n\n/** A monthly rule: on the start's day of the month, its nth weekday, or its last weekday. */\nexport type MonthlyPattern = 'monthDay' | 'nthWeekday' | 'lastWeekday';\n\nexport type RepeatEnd =\n | { kind: 'never' }\n | { kind: 'count'; count: number }\n /** The last day an occurrence may start on, on the event's clock. */\n | { kind: 'until'; date: DateValue };\n\nexport interface RepeatRule {\n frequency: RepeatFrequency;\n /** Every `interval` days, weeks, months or years. */\n interval: number;\n /** Weekly: the days, in week order from Monday, the start's among them. Otherwise empty. */\n weekdays: Weekday[];\n /** Monthly: which day of each month. Otherwise null. */\n monthly: MonthlyPattern | null;\n end: RepeatEnd;\n}\n\n/** What a rule is tied to: the event's start, on its own clock. */\nexport interface RuleAnchor {\n start: DateValue;\n /** Minutes after midnight on the event's clock (0 for an all-day event). */\n startMinutes: number;\n timeZone: string;\n allDay: boolean;\n}\n\nexport type ParsedRepeat =\n { kind: 'none' } | { kind: 'rule'; rule: RepeatRule } | { kind: 'kept'; text: string };\n\n/** The menu's ready-made rules. */\nexport type RepeatPreset =\n 'daily' | 'weekly' | 'monthlyNth' | 'monthlyLast' | 'yearly' | 'weekdays';\n\n/** The longest interval and count the builder offers. */\nexport const MAX_INTERVAL = 99;\nexport const MAX_COUNT = 999;\n\nconst WEEK_ORDER: readonly Weekday[] = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'];\nconst FREQUENCIES: readonly RepeatFrequency[] = ['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'];\nconst SECOND_MS = 1000;\n\nfunction isWeekday(value: string | undefined): value is Weekday {\n return WEEKDAYS.some((day) => day === value);\n}\n\nfunction isFrequency(value: string | undefined): value is RepeatFrequency {\n return FREQUENCIES.some((frequency) => frequency === value);\n}\n\n/** The start's weekday. */\nexport function weekdayCode(date: DateValue): Weekday {\n return WEEKDAYS[weekdayOf(date)] ?? 'MO';\n}\n\nfunction dayOfMonth(date: DateValue): number {\n return parseDateValue(date)?.day ?? 1;\n}\n\nfunction daysInMonth(date: DateValue): number {\n const parts = parseDateValue(date);\n if (!parts) return 31;\n return new Date(Date.UTC(parts.year, parts.month, 0)).getUTCDate();\n}\n\n/** Which of its weekday the date is in its month: 1 for the first … 5 for a fifth. */\nexport function nthOfMonth(date: DateValue): number {\n return Math.ceil(dayOfMonth(date) / 7);\n}\n\n/** The date is the last of its weekday in its month. */\nexport function isLastOfMonth(date: DateValue): boolean {\n return dayOfMonth(date) + 7 > daysInMonth(date);\n}\n\n/** Days in week order from Monday, each once. */\nfunction inWeekOrder(days: readonly Weekday[]): Weekday[] {\n const set = new Set(days);\n return WEEK_ORDER.filter((day) => set.has(day));\n}\n\nfunction sameDays(a: readonly Weekday[], b: readonly Weekday[]): boolean {\n const left = inWeekOrder(a);\n const right = inWeekOrder(b);\n return left.length === right.length && left.every((day, index) => day === right[index]);\n}\n\n// ── The menu's rules ─────────────────────────────────────────────────────────\n\n/**\n * The presets the menu offers for this start: \"on the last …\" only in a month's last week,\n * \"every weekday\" only from a weekday (the start is always an occurrence).\n */\nexport function presetsFor(anchor: RuleAnchor): RepeatPreset[] {\n const presets: RepeatPreset[] = ['daily', 'weekly'];\n if (nthOfMonth(anchor.start) <= 4) presets.push('monthlyNth');\n if (isLastOfMonth(anchor.start)) presets.push('monthlyLast');\n presets.push('yearly');\n if (WORKWEEK.includes(weekdayCode(anchor.start))) presets.push('weekdays');\n return presets;\n}\n\n/** A preset's rule for this start, repeating for ever. */\nexport function presetRule(preset: RepeatPreset, anchor: RuleAnchor): RepeatRule {\n const never: RepeatEnd = { kind: 'never' };\n const start = weekdayCode(anchor.start);\n switch (preset) {\n case 'daily':\n return { frequency: 'DAILY', interval: 1, weekdays: [], monthly: null, end: never };\n case 'weekly':\n return { frequency: 'WEEKLY', interval: 1, weekdays: [start], monthly: null, end: never };\n case 'monthlyNth':\n return { frequency: 'MONTHLY', interval: 1, weekdays: [], monthly: 'nthWeekday', end: never };\n case 'monthlyLast':\n return {\n frequency: 'MONTHLY',\n interval: 1,\n weekdays: [],\n monthly: 'lastWeekday',\n end: never,\n };\n case 'yearly':\n return { frequency: 'YEARLY', interval: 1, weekdays: [], monthly: null, end: never };\n case 'weekdays':\n return {\n frequency: 'WEEKLY',\n interval: 1,\n weekdays: [...WORKWEEK],\n monthly: null,\n end: never,\n };\n }\n}\n\n/** The preset a rule is, for this start; null for anything else (a custom rule). */\nexport function presetOf(rule: RepeatRule, anchor: RuleAnchor): RepeatPreset | null {\n for (const preset of presetsFor(anchor)) {\n const candidate = presetRule(preset, anchor);\n if (\n candidate.frequency === rule.frequency &&\n candidate.interval === rule.interval &&\n sameDays(candidate.weekdays, rule.weekdays) &&\n candidate.monthly === rule.monthly &&\n rule.end.kind === 'never'\n ) {\n return preset;\n }\n }\n return null;\n}\n\n// ── The Custom builder's changes ─────────────────────────────────────────────\n\n/** A new frequency: weekly starts on the start's day, monthly on its day of the month. */\nexport function withFrequency(\n rule: RepeatRule,\n frequency: RepeatFrequency,\n anchor: RuleAnchor\n): RepeatRule {\n if (rule.frequency === frequency) return rule;\n return {\n ...rule,\n frequency,\n weekdays: frequency === 'WEEKLY' ? [weekdayCode(anchor.start)] : [],\n monthly: frequency === 'MONTHLY' ? 'monthDay' : null,\n };\n}\n\n/** Turns a weekly day on or off; the start's own day stays on. */\nexport function withWeekdayToggled(rule: RepeatRule, day: Weekday, anchor: RuleAnchor): RepeatRule {\n if (rule.frequency !== 'WEEKLY' || day === weekdayCode(anchor.start)) return rule;\n const days = rule.weekdays.includes(day)\n ? rule.weekdays.filter((item) => item !== day)\n : [...rule.weekdays, day];\n return { ...rule, weekdays: inWeekOrder(days) };\n}\n\n/**\n * The rule after the event's start moved, so the start stays an occurrence: a weekly rule\n * takes the new start's day (the old start's day goes when it was the only one); a monthly\n * nth weekday past the fourth becomes the last, and a last weekday no longer last the nth.\n */\nexport function followStart(rule: RepeatRule, before: RuleAnchor, after: RuleAnchor): RepeatRule {\n if (rule.frequency === 'WEEKLY') {\n const oldDay = weekdayCode(before.start);\n const newDay = weekdayCode(after.start);\n if (oldDay === newDay) return rule;\n const kept = rule.weekdays.length === 1 && rule.weekdays[0] === oldDay ? [] : rule.weekdays;\n return { ...rule, weekdays: inWeekOrder([...kept, newDay]) };\n }\n if (rule.frequency === 'MONTHLY') {\n if (rule.monthly === 'nthWeekday' && nthOfMonth(after.start) > 4) {\n return { ...rule, monthly: 'lastWeekday' };\n }\n if (rule.monthly === 'lastWeekday' && !isLastOfMonth(after.start)) {\n return { ...rule, monthly: 'nthWeekday' };\n }\n }\n return rule;\n}\n\nexport type RuleProblem = 'interval' | 'count' | 'untilBeforeStart' | 'noWeekdays';\n\n/** What is wrong with a rule the builder holds; null when it can be saved. */\nexport function ruleProblem(rule: RepeatRule, anchor: RuleAnchor): RuleProblem | null {\n if (!Number.isInteger(rule.interval) || rule.interval < 1 || rule.interval > MAX_INTERVAL) {\n return 'interval';\n }\n if (rule.frequency === 'WEEKLY' && rule.weekdays.length === 0) return 'noWeekdays';\n if (\n rule.end.kind === 'count' &&\n (!Number.isInteger(rule.end.count) || rule.end.count < 1 || rule.end.count > MAX_COUNT)\n ) {\n return 'count';\n }\n if (rule.end.kind === 'until' && rule.end.date < anchor.start) return 'untilBeforeStart';\n return null;\n}\n\n// ── Writing ──────────────────────────────────────────────────────────────────\n\n/** `20261231T182959Z`: an instant as RFC 5545 writes a UTC time. */\nexport function utcStamp(instant: Date): string {\n return instant\n .toISOString()\n .replace(/\\.\\d{3}Z$/, 'Z')\n .replace(/[-:]/g, '');\n}\n\n/** The UNTIL of a last day: the end of that day on the event's clock, in UTC. */\nfunction untilStamp(last: DateValue, anchor: RuleAnchor): string {\n if (anchor.allDay) return `${last.replace(/-/g, '')}T235959Z`;\n const nextMidnight = zonedTimeToInstant(addDays(last, 1), 0, anchor.timeZone);\n return utcStamp(new Date(nextMidnight.getTime() - SECOND_MS));\n}\n\n/** `3TU`, `-1FR`: the start's nth or last weekday of the month. */\nfunction monthlyWeekday(pattern: 'nthWeekday' | 'lastWeekday', anchor: RuleAnchor): string {\n const day = weekdayCode(anchor.start);\n return pattern === 'lastWeekday' ? `-1${day}` : `${nthOfMonth(anchor.start)}${day}`;\n}\n\n/** The RRULE value of a rule (without the `RRULE:` prefix), tied to `anchor`. */\nexport function buildRRule(rule: RepeatRule, anchor: RuleAnchor): string {\n const parts = [`FREQ=${rule.frequency}`];\n if (rule.interval > 1) parts.push(`INTERVAL=${rule.interval}`);\n if (rule.frequency === 'WEEKLY') {\n const days = inWeekOrder(rule.weekdays);\n const onlyStart = days.length === 1 && days[0] === weekdayCode(anchor.start);\n if (days.length > 0 && !onlyStart) parts.push(`BYDAY=${days.join(',')}`);\n }\n if (rule.frequency === 'MONTHLY' && rule.monthly && rule.monthly !== 'monthDay') {\n parts.push(`BYDAY=${monthlyWeekday(rule.monthly, anchor)}`);\n }\n if (rule.end.kind === 'count') parts.push(`COUNT=${rule.end.count}`);\n if (rule.end.kind === 'until') parts.push(`UNTIL=${untilStamp(rule.end.date, anchor)}`);\n return parts.join(';');\n}\n\n// ── Reading ──────────────────────────────────────────────────────────────────\n\n/** The rule's line: one line, or the RRULE line among DTSTART lines; null for anything more. */\nfunction ruleLine(text: string): string | null {\n const lines = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '');\n const rules = lines.filter((line) => !/^DTSTART[:;]/i.test(line));\n if (rules.length !== 1) return null;\n const [line] = rules;\n if (!line) return null;\n if (/^RRULE:/i.test(line)) return line.slice('RRULE:'.length);\n // A one-line value with another property name (EXDATE:, RDATE:, EXRULE:) isn't a rule.\n return /^[A-Z-]+[:;]/i.test(line) && !/^[A-Z]+=/i.test(line) ? null : line;\n}\n\n/** The day an UNTIL names, on the event's clock: the last day an occurrence can start. */\nfunction untilDate(value: string, anchor: RuleAnchor): DateValue | null {\n const match = /^(\\d{4})(\\d{2})(\\d{2})(?:T(\\d{2})(\\d{2})(\\d{2})(Z)?)?$/.exec(value);\n if (!match) return null;\n const [, year, month, day, hours, minutes, seconds, utc] = match;\n const date: DateValue = `${year}-${month}-${day}`;\n if (!parseDateValue(date)) return null;\n // A date, or a floating time: the day as written.\n if (hours === undefined || !utc) return date;\n const instant = new Date(\n Date.UTC(\n Number(year),\n Number(month) - 1,\n Number(day),\n Number(hours),\n Number(minutes),\n Number(seconds)\n )\n );\n const zone = anchor.allDay ? 'UTC' : anchor.timeZone;\n const minute = anchor.allDay ? 0 : anchor.startMinutes;\n let last = instantToZoned(instant, zone).date;\n // An UNTIL before that day's occurrence (an end of day in UTC, read east of UTC) ends a day\n // earlier.\n if (zonedTimeToInstant(last, minute, zone).getTime() > instant.getTime())\n last = addDays(last, -1);\n return last;\n}\n\ninterface WeekdayEntry {\n ordinal: number | null;\n day: Weekday;\n}\n\nfunction weekdayEntries(value: string): WeekdayEntry[] | null {\n const entries: WeekdayEntry[] = [];\n for (const raw of value.split(',')) {\n const match = /^([+-]?\\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(raw.trim().toUpperCase());\n const day = match?.[2];\n if (!match || !isWeekday(day)) return null;\n const ordinal = match[1] === undefined ? null : Number(match[1]);\n entries.push({ ordinal, day });\n }\n return entries;\n}\n\n/** The monthly pattern a weekday entry names for this start; null when it isn't the start's. */\nfunction monthlyPatternOf(entry: WeekdayEntry, anchor: RuleAnchor): MonthlyPattern | null {\n if (entry.day !== weekdayCode(anchor.start)) return null;\n if (entry.ordinal === -1 && isLastOfMonth(anchor.start)) return 'lastWeekday';\n if (entry.ordinal === nthOfMonth(anchor.start) && entry.ordinal <= 4) return 'nthWeekday';\n return null;\n}\n\n/**\n * Reads a stored rule: one line, with or without `RRULE:`, with an inline `DTSTART=` (the\n * service writes one) or DTSTART lines around it. What the builder can't hold for this start is\n * `kept`, never changed or dropped.\n */\nexport function parseRRule(text: string | null | undefined, anchor: RuleAnchor): ParsedRepeat {\n const raw = (text ?? '').trim();\n if (raw === '') return { kind: 'none' };\n const kept: ParsedRepeat = { kind: 'kept', text: raw };\n const line = ruleLine(raw);\n if (line === null) return kept;\n\n const fields = new Map<string, string>();\n for (const part of line.split(';')) {\n if (part.trim() === '') continue;\n const at = part.indexOf('=');\n if (at <= 0) return kept;\n const name = part.slice(0, at).trim().toUpperCase();\n if (fields.has(name)) return kept;\n fields.set(name, part.slice(at + 1).trim());\n }\n // The service's inline start; the start is the event's own.\n fields.delete('DTSTART');\n\n const frequency = fields.get('FREQ')?.toUpperCase();\n if (!isFrequency(frequency)) return kept;\n fields.delete('FREQ');\n\n let interval = 1;\n const intervalText = fields.get('INTERVAL');\n if (intervalText !== undefined) {\n interval = Number(intervalText);\n if (!/^\\d+$/.test(intervalText) || interval < 1 || interval > MAX_INTERVAL) return kept;\n fields.delete('INTERVAL');\n }\n\n // A week starting on Monday is the default; another start only matters every 2+ weeks.\n const weekStart = fields.get('WKST');\n if (weekStart !== undefined) {\n if (weekStart.toUpperCase() !== 'MO' && frequency === 'WEEKLY' && interval > 1) return kept;\n fields.delete('WKST');\n }\n\n let end: RepeatEnd = { kind: 'never' };\n const countText = fields.get('COUNT');\n const untilText = fields.get('UNTIL');\n if (countText !== undefined && untilText !== undefined) return kept;\n if (countText !== undefined) {\n const count = Number(countText);\n if (!/^\\d+$/.test(countText) || count < 1 || count > MAX_COUNT) return kept;\n end = { kind: 'count', count };\n fields.delete('COUNT');\n }\n if (untilText !== undefined) {\n const date = untilDate(untilText.toUpperCase(), anchor);\n if (!date) return kept;\n end = { kind: 'until', date };\n fields.delete('UNTIL');\n }\n\n const byDayText = fields.get('BYDAY');\n const byDay = byDayText === undefined ? null : weekdayEntries(byDayText);\n if (byDayText !== undefined && byDay === null) return kept;\n fields.delete('BYDAY');\n const setPosText = fields.get('BYSETPOS');\n fields.delete('BYSETPOS');\n const monthDayText = fields.get('BYMONTHDAY');\n fields.delete('BYMONTHDAY');\n const monthText = fields.get('BYMONTH');\n fields.delete('BYMONTH');\n // Anything else (BYHOUR, BYWEEKNO, BYYEARDAY, TZID …) is beyond the builder.\n if (fields.size > 0) return kept;\n\n const startDay = weekdayCode(anchor.start);\n const base = { interval, end };\n switch (frequency) {\n case 'DAILY': {\n if (setPosText !== undefined || monthDayText !== undefined || monthText !== undefined) {\n return kept;\n }\n if (!byDay) {\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: null } };\n }\n // \"Daily on weekdays\", as some apps write every weekday: the same as weekly on those days.\n const days = byDay.map((entry) => entry.day);\n if (\n interval !== 1 ||\n byDay.some((entry) => entry.ordinal !== null) ||\n !days.includes(startDay)\n ) {\n return kept;\n }\n return {\n kind: 'rule',\n rule: { ...base, frequency: 'WEEKLY', weekdays: inWeekOrder(days), monthly: null },\n };\n }\n case 'WEEKLY': {\n if (setPosText !== undefined || monthDayText !== undefined || monthText !== undefined) {\n return kept;\n }\n const days = byDay ? byDay.map((entry) => entry.day) : [startDay];\n if (byDay?.some((entry) => entry.ordinal !== null) || !days.includes(startDay)) return kept;\n return {\n kind: 'rule',\n rule: { ...base, frequency, weekdays: inWeekOrder(days), monthly: null },\n };\n }\n case 'MONTHLY': {\n if (monthText !== undefined) return kept;\n if (monthDayText !== undefined) {\n if (\n byDay ||\n setPosText !== undefined ||\n Number(monthDayText) !== dayOfMonth(anchor.start)\n ) {\n return kept;\n }\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: 'monthDay' } };\n }\n if (!byDay) {\n if (setPosText !== undefined) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: 'monthDay' } };\n }\n const [entry] = byDay;\n if (byDay.length !== 1 || !entry) return kept;\n let named: WeekdayEntry = entry;\n if (setPosText !== undefined) {\n // BYDAY=TU;BYSETPOS=3 is the third Tuesday, as 3TU.\n if (entry.ordinal !== null || !/^-?\\d{1,2}$/.test(setPosText)) return kept;\n named = { ordinal: Number(setPosText), day: entry.day };\n }\n const monthly = monthlyPatternOf(named, anchor);\n if (!monthly) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly } };\n }\n case 'YEARLY': {\n if (byDay || setPosText !== undefined) return kept;\n const parts = parseDateValue(anchor.start);\n if (monthText !== undefined && Number(monthText) !== parts?.month) return kept;\n if (monthDayText !== undefined && Number(monthDayText) !== parts?.day) return kept;\n return { kind: 'rule', rule: { ...base, frequency, weekdays: [], monthly: null } };\n }\n }\n}\n"],"mappings":";;;AAyBA,IAAaA,IAA+B;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI,GAGxEC,IAA+B;CAAC;CAAM;CAAM;CAAM;CAAM;AAAI,GA4CnEC,IAAiC;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI,GAC1EC,IAA0C;CAAC;CAAS;CAAU;CAAW;AAAQ,GACjFC,IAAY;AAElB,SAASC,EAAU,GAA6C;CAC9D,OAAOL,EAAS,MAAM,MAAQM,MAAQC,CAAK;AAC7C;AAEA,SAASC,EAAY,GAAqD;CACxE,OAAOL,EAAY,MAAM,MAAcM,MAAcF,CAAK;AAC5D;AAGA,SAAgBG,EAAY,GAA0B;CACpD,OAAOV,EAASW,EAAUC,CAAI,MAAM;AACtC;AAEA,SAASC,EAAW,GAAyB;CAC3C,OAAOC,EAAeF,CAAI,CAAC,EAAE,OAAO;AACtC;AAEA,SAASG,EAAY,GAAyB;CAC5C,IAAMC,IAAQF,EAAeF,CAAI;CAEjC,OADKI,IACE,IAAI,KAAK,KAAK,IAAIA,EAAM,MAAMA,EAAM,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,IAD9C;AAErB;AAGA,SAAgBC,EAAW,GAAyB;CAClD,OAAO,KAAK,KAAKJ,EAAWD,CAAI,IAAI,CAAC;AACvC;AAGA,SAAgBM,EAAc,GAA0B;CACtD,OAAOL,EAAWD,CAAI,IAAI,IAAIG,EAAYH,CAAI;AAChD;AAGA,SAASO,EAAY,GAAqC;CACxD,IAAMC,IAAM,IAAI,IAAIC,CAAI;CACxB,OAAOnB,EAAW,QA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