@burdenoff/microfe-calendar 2026.1124.2 → 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.
- package/dist/generated/wspace-operations.d.ts +811 -69
- package/dist/generated/wspace-operations.js +173 -19
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +405 -6
- package/dist/pages/ResourcesPage.js.map +1 -1
- package/dist/translations/en.d.ts +250 -1
- package/dist/v2/CalendarPageV2.js +45 -41
- package/dist/v2/CalendarPageV2.js.map +1 -1
- package/dist/v2/CalendarRoutesV2.js +64 -64
- package/dist/v2/CalendarRoutesV2.js.map +1 -1
- package/dist/v2/data/enums.d.ts +1 -0
- package/dist/v2/data/enums.js +6 -2
- package/dist/v2/data/enums.js.map +1 -1
- package/dist/v2/data/errors.d.ts +5 -0
- package/dist/v2/data/errors.js +6 -2
- package/dist/v2/data/errors.js.map +1 -1
- package/dist/v2/data/normalize.d.ts +31 -3
- package/dist/v2/data/normalize.js +57 -13
- package/dist/v2/data/normalize.js.map +1 -1
- package/dist/v2/data/seriesDateLookup.d.ts +9 -0
- package/dist/v2/data/seriesDateLookup.js +12 -0
- package/dist/v2/data/seriesDateLookup.js.map +1 -0
- package/dist/v2/data/useEventActions.d.ts +9 -3
- package/dist/v2/data/useEventActions.js +239 -186
- package/dist/v2/data/useEventActions.js.map +1 -1
- package/dist/v2/data/useEventForPeek.js +63 -21
- package/dist/v2/data/useEventForPeek.js.map +1 -1
- package/dist/v2/data/useEventsInRangeV2.d.ts +40 -2
- package/dist/v2/data/useEventsInRangeV2.js +76 -47
- package/dist/v2/data/useEventsInRangeV2.js.map +1 -1
- package/dist/v2/day/DayPanel.js +1 -1
- package/dist/v2/day/DayPanel.js.map +1 -1
- package/dist/v2/dialogs/CalendarDialogsV2.js +12 -9
- package/dist/v2/dialogs/CalendarDialogsV2.js.map +1 -1
- package/dist/v2/event/CustomRepeat.d.ts +5 -0
- package/dist/v2/event/CustomRepeat.js +246 -0
- package/dist/v2/event/CustomRepeat.js.map +1 -0
- package/dist/v2/event/EventDetailsTab.d.ts +6 -0
- package/dist/v2/event/EventDetailsTab.js +291 -0
- package/dist/v2/event/EventDetailsTab.js.map +1 -0
- package/dist/v2/event/EventDialog.d.ts +35 -0
- package/dist/v2/event/EventDialog.js +388 -0
- package/dist/v2/event/EventDialog.js.map +1 -0
- package/dist/v2/event/EventDialogs.d.ts +3 -0
- package/dist/v2/event/EventDialogs.js +118 -0
- package/dist/v2/event/EventDialogs.js.map +1 -0
- package/dist/v2/event/EventMoreTab.d.ts +4 -0
- package/dist/v2/event/EventMoreTab.js +215 -0
- package/dist/v2/event/EventMoreTab.js.map +1 -0
- package/dist/v2/event/EventPeopleTab.d.ts +8 -0
- package/dist/v2/event/EventPeopleTab.js +422 -0
- package/dist/v2/event/EventPeopleTab.js.map +1 -0
- package/dist/v2/event/EventPlaceTab.d.ts +6 -0
- package/dist/v2/event/EventPlaceTab.js +264 -0
- package/dist/v2/event/EventPlaceTab.js.map +1 -0
- package/dist/v2/event/FindTimeDialog.d.ts +26 -0
- package/dist/v2/event/FindTimeDialog.js +667 -0
- package/dist/v2/event/FindTimeDialog.js.map +1 -0
- package/dist/v2/event/RepeatField.d.ts +5 -0
- package/dist/v2/event/RepeatField.js +91 -0
- package/dist/v2/event/RepeatField.js.map +1 -0
- package/dist/v2/event/dialogLogic.d.ts +97 -0
- package/dist/v2/event/dialogLogic.js +120 -0
- package/dist/v2/event/dialogLogic.js.map +1 -0
- package/dist/v2/event/dialogModel.d.ts +51 -0
- package/dist/v2/event/dialogModel.js +13 -0
- package/dist/v2/event/dialogModel.js.map +1 -0
- package/dist/v2/event/eventForm.d.ts +235 -0
- package/dist/v2/event/eventForm.js +450 -0
- package/dist/v2/event/eventForm.js.map +1 -0
- package/dist/v2/event/findTime.d.ts +120 -0
- package/dist/v2/event/findTime.js +149 -0
- package/dist/v2/event/findTime.js.map +1 -0
- package/dist/v2/event/findTimeSource.d.ts +102 -0
- package/dist/v2/event/findTimeSource.js +107 -0
- package/dist/v2/event/findTimeSource.js.map +1 -0
- package/dist/v2/event/parts.d.ts +46 -0
- package/dist/v2/event/parts.js +124 -0
- package/dist/v2/event/parts.js.map +1 -0
- package/dist/v2/event/place.d.ts +64 -0
- package/dist/v2/event/place.js +48 -0
- package/dist/v2/event/place.js.map +1 -0
- package/dist/v2/event/repeatWords.d.ts +19 -0
- package/dist/v2/event/repeatWords.js +130 -0
- package/dist/v2/event/repeatWords.js.map +1 -0
- package/dist/v2/event/rrule.d.ts +90 -0
- package/dist/v2/event/rrule.js +368 -0
- package/dist/v2/event/rrule.js.map +1 -0
- package/dist/v2/event/savePlan.d.ts +160 -0
- package/dist/v2/event/savePlan.js +219 -0
- package/dist/v2/event/savePlan.js.map +1 -0
- package/dist/v2/event/useEventData.d.ts +96 -0
- package/dist/v2/event/useEventData.js +229 -0
- package/dist/v2/event/useEventData.js.map +1 -0
- package/dist/v2/event/useEventDialogModel.d.ts +50 -0
- package/dist/v2/event/useEventDialogModel.js +144 -0
- package/dist/v2/event/useEventDialogModel.js.map +1 -0
- package/dist/v2/event/useEventSave.d.ts +57 -0
- package/dist/v2/event/useEventSave.js +276 -0
- package/dist/v2/event/useEventSave.js.map +1 -0
- package/dist/v2/events/eventLook.js +16 -16
- package/dist/v2/events/eventLook.js.map +1 -1
- package/dist/v2/events/eventModel.d.ts +17 -4
- package/dist/v2/events/eventModel.js +46 -34
- package/dist/v2/events/eventModel.js.map +1 -1
- package/dist/v2/events/localChanges.d.ts +4 -1
- package/dist/v2/events/localChanges.js +4 -2
- package/dist/v2/events/localChanges.js.map +1 -1
- package/dist/v2/format.d.ts +2 -0
- package/dist/v2/format.js +4 -0
- package/dist/v2/format.js.map +1 -1
- package/dist/v2/page/CalendarPageContext.d.ts +2 -2
- package/dist/v2/page/CalendarPageContext.js.map +1 -1
- package/dist/v2/page/useCalendarPageModel.js +141 -139
- package/dist/v2/page/useCalendarPageModel.js.map +1 -1
- package/dist/v2/page/viewState.d.ts +9 -1
- package/dist/v2/page/viewState.js +5 -3
- package/dist/v2/page/viewState.js.map +1 -1
- package/dist/v2/peek/EventPeek.js.map +1 -1
- package/dist/v2/peek/PeekEvent.js +210 -204
- package/dist/v2/peek/PeekEvent.js.map +1 -1
- package/dist/v2/rail/CalendarRail.js.map +1 -1
- package/dist/v2/rail/useMonthEventDates.js +1 -1
- package/dist/v2/rail/useMonthEventDates.js.map +1 -1
- package/dist/v2/runs/RunPeek.js.map +1 -1
- package/dist/v2/states/CalendarStates.d.ts +15 -0
- package/dist/v2/states/CalendarStates.js +42 -11
- package/dist/v2/states/CalendarStates.js.map +1 -1
- package/dist/v2/types.d.ts +32 -2
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEventSave.js","names":["PARALLEL_WRITES","serviceMessage","CombinedGraphQLErrors","error","item","inTurns","next","worker","task","tasks","size","inOrder","items","index","stop","step","ALREADY_SO","alreadySo","key","graphQLErrorKey","reasonFor","tr","reminderWords","reminder","ctx","formatDuration","attempt","work","done","run","failed","modifyOccurrence","raw","client","CalendarV2ModifyOccurrenceDocument","made","toCalendarEventV2","me","splitSeries","CalendarV2SplitSeriesDocument","seriesId","createEvent","id","CalendarV2CreateEventDocument","applyUpdates","plan","CalendarV2UpdateEventDocument","update","madeNew","guestTasks","CalendarV2RemoveGuestDocument","guest","why","CalendarV2AddGuestDocument","reminderTasks","CalendarV2DeleteReminderDocument","CalendarV2CreateReminderDocument","REMINDER_CHANNEL","tagsTask","tags","write","leaveCancel","left","entry","date","cancelledDateTasks","dates","CalendarV2CancelOccurrenceDocument","formatDay","instantToZoned","roomTask","book","letGo","CalendarV2CancelRoomBookingDocument","cancelId","release","reserve","CalendarV2BookRoomDocument","seriesHeld","stillHeld","bookingId","savedWords","title","form","start","startInstant","day","route","row","when","formatInstantRange","endInstant","dateAfterSave","request","event","savedId","isSeriesDate","rruleOf","initial","useEventSave","useApolloClient","notify","useNotify","contextRef","useRef","context","useEffect","useCallback","saveRouteFor","creating","planOnNewEvent","carry","firstUpdate","invalidateCalendarEvents","carriesWork"],"sources":["../../../src/v2/event/useEventSave.ts"],"sourcesContent":["/**\n * Saving the event dialog (BOFF-15698 A2, A4): runs the plan (`savePlan.ts`) against the service\n * and says how it went in a themed toast.\n *\n * - The event itself first: `createEvent`, or the `updateEvent` calls. If that fails nothing\n * else is sent, the service's words are shown, and the dialog keeps everything typed.\n * - A date of a series changed on its own (\"This event\") is made an event of its own first\n * (`modifyRecurringInstance`, by the date's original start), and \"This and later\" splits the\n * series at the date (`updateEvent` with THIS_AND_FUTURE); the rest is then planned on what\n * the service made, which carries no guests, reminders or room of the series yet, nor (a\n * split) its cancelled dates. If that first step fails nothing changed; anything after it that\n * fails is a partial save.\n * - A series' cancelled dates are cancelled again where its new times put them\n * (`cancelRecurringInstance`), as the service keeps them by the instants they were at. The\n * service adds each to the series' list on its own, so a series' dates go one after another.\n * - Then its guests, reminders and room, a few at a time. Whatever of those fails is named with\n * the service's words, and the dialog stays open on the saved event (an edit from then on),\n * so saving again sends only what is still missing. What failed that the event read back\n * can't show (a series' booking still holding the room, tags, dates still to cancel) comes\n * back as the outcome's `carry`, for the next save to send.\n * - Letting go of a booking already let go, or cancelling a date already cancelled, is done:\n * saving again after a write whose answer was lost doesn't fail on it.\n * - After any write the views, free/busy and the dialog's own copy of the event reload\n * (`invalidateCalendarEvents`).\n */\nimport { useCallback, useEffect, useRef } from 'react';\nimport { CombinedGraphQLErrors } from '@apollo/client';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useNotify } from '@burdenoff/fe-libs/ui';\nimport {\n CalendarV2AddGuestDocument,\n CalendarV2BookRoomDocument,\n CalendarV2CancelOccurrenceDocument,\n CalendarV2CancelRoomBookingDocument,\n CalendarV2CreateEventDocument,\n CalendarV2CreateReminderDocument,\n CalendarV2DeleteReminderDocument,\n CalendarV2ModifyOccurrenceDocument,\n CalendarV2RemoveGuestDocument,\n CalendarV2SplitSeriesDocument,\n CalendarV2UpdateEventDocument,\n type CalendarV2AddGuestMutation,\n type CalendarV2AddGuestMutationVariables,\n type CalendarV2BookRoomMutation,\n type CalendarV2BookRoomMutationVariables,\n type CalendarV2CancelOccurrenceMutation,\n type CalendarV2CancelOccurrenceMutationVariables,\n type CalendarV2CancelRoomBookingMutation,\n type CalendarV2CancelRoomBookingMutationVariables,\n type CalendarV2CreateEventMutation,\n type CalendarV2CreateEventMutationVariables,\n type CalendarV2CreateReminderMutation,\n type CalendarV2CreateReminderMutationVariables,\n type CalendarV2DeleteReminderMutation,\n type CalendarV2DeleteReminderMutationVariables,\n type CalendarV2ModifyOccurrenceMutation,\n type CalendarV2ModifyOccurrenceMutationVariables,\n type CalendarV2RemoveGuestMutation,\n type CalendarV2RemoveGuestMutationVariables,\n type CalendarV2SplitSeriesMutation,\n type CalendarV2SplitSeriesMutationVariables,\n type CalendarV2UpdateEventMutation,\n type CalendarV2UpdateEventMutationVariables,\n} from '../../generated/wspace-operations';\nimport type {\n CreateEventInput,\n ModifyRecurringInstanceInput,\n UpdateEventInput,\n} from '../../generated/wspace-types';\nimport { REMINDER_CHANNEL } from '../data/enums';\nimport { graphQLErrorKey } from '../data/errors';\nimport { invalidateCalendarEvents } from '../data/invalidation';\nimport { toCalendarEventV2 } from '../data/normalize';\nimport { isSeriesDate } from '../events/eventModel';\nimport type { Tr } from '../data/useEventActions';\nimport {\n formatDay,\n formatDuration,\n formatInstantRange,\n type CalendarFormat,\n type DurationWords,\n} from '../format';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { CalendarEventV2 } from '../types';\nimport {\n startInstant,\n endInstant,\n rruleOf,\n type EventForm,\n type GuestDraft,\n type ReminderDraft,\n} from './eventForm';\nimport {\n carriesWork,\n planOnNewEvent,\n saveRouteFor,\n type SaveCarry,\n type SavePlan,\n type SaveRoute,\n type ScopeChoice,\n} from './savePlan';\n\nexport interface EventSaveContext {\n tr: Tr;\n format: CalendarFormat;\n durationWords: DurationWords;\n /** The calendar's zone: where the toast says the event is. */\n timeZone: string;\n /** A calendar's name, for \"Added … to Customer calls\". */\n calendarName: (calendarId: string) => string | null;\n /** A room's name, for \"Couldn't book Atlas\". */\n roomName: (roomId: string) => string | null;\n /** A guest's name, for \"Couldn't add Priya Raman\". */\n guestName: (guest: GuestDraft) => string;\n /** The signed-in person: whose answer an event read back carries. */\n me: string | null;\n}\n\nexport interface SaveRequest {\n form: EventForm;\n /** The form as the dialog opened (for a series' date, at that date). */\n initial: EventForm;\n /** The event as the service last returned it (a series' date at that date); null when new. */\n event: CalendarEventV2 | null;\n /** The stored event behind it: for a series' date, the series at its first date. */\n row: CalendarEventV2 | null;\n /** A series' date: the answer to \"Change …\". */\n scope: ScopeChoice;\n /** What a save before left undone and the event read back can't show; null when nothing. */\n carry: SaveCarry | null;\n}\n\nexport type SaveOutcome =\n | { kind: 'saved'; eventId: string }\n /**\n * The event saved but not all of it did. The dialog goes on with `eventId` (at\n * `instanceDate`, a series' date); `madeNew`: the service made that event from a series (a\n * date on its own, or the later part of a split), so the guests and reminders the form holds\n * are new to it. `carry`: what failed that the event read back won't show, for the next save.\n */\n | {\n kind: 'partial';\n eventId: string;\n instanceDate: Date | null;\n madeNew: boolean;\n carry: SaveCarry | null;\n }\n /** Nothing changed on the service. */\n | { kind: 'failed' };\n\n/** How many guest, reminder and room writes run at once. */\nconst PARALLEL_WRITES = 4;\n\ntype Client = ReturnType<typeof useApolloClient>;\n\n/** The service's own words for a failed write; null when it never answered. */\nexport function serviceMessage(error: unknown): string | null {\n if (CombinedGraphQLErrors.is(error)) {\n const message = error.errors.map((item) => item.message.trim()).find(Boolean);\n return message ?? null;\n }\n return null;\n}\n\n/** Runs `tasks`, at most `size` at a time, each as soon as one before it is done. */\nasync function inTurns(tasks: readonly (() => Promise<unknown>)[], size: number): Promise<void> {\n let next = 0;\n const worker = async (): Promise<void> => {\n const task = tasks[next];\n next += 1;\n if (!task) return;\n await task();\n await worker();\n };\n await Promise.all(Array.from({ length: Math.min(size, tasks.length) }, worker));\n}\n\n/**\n * Runs `step` on each item in order, the next only once the one before is done. A step that\n * returns something stops there, and that is returned; null when every step ran.\n */\nasync function inOrder<T, R>(\n items: readonly T[],\n step: (item: T, index: number) => Promise<R | null>,\n index = 0\n): Promise<R | null> {\n const item = items[index];\n if (item === undefined) return null;\n const stop = await step(item, index);\n return stop === null ? inOrder(items, step, index + 1) : stop;\n}\n\n/**\n * What a save has done so far: whether anything was written, what failed, and of that what the\n * next plan couldn't send again on its own (`left`).\n */\ninterface SaveRun {\n wrote: boolean;\n problems: string[];\n left: SaveCarry;\n}\n\n/**\n * The service's words for a booking already let go (gone, cancelled or over), and for a date\n * already cancelled (or its series gone, or no longer repeating): what the write was for is so.\n */\nconst ALREADY_SO = new Set([\n 'resource.errors.bookingNotFound',\n 'resource.errors.cannotCancelBooking',\n 'recurrence.errors.instanceAlreadyCancelled',\n 'recurrence.errors.notRecurringSeries',\n 'recurrence.errors.seriesNotFound',\n]);\n\nfunction alreadySo(error: unknown): boolean {\n const key = graphQLErrorKey(error);\n return key !== null && ALREADY_SO.has(key);\n}\n\n/** Why a write failed: the service's words, or that it never answered. */\nfunction reasonFor(error: unknown, tr: Tr): string {\n return (\n serviceMessage(error) ??\n tr('calendar.v2.eventSaveOffline', 'The calendar service didn’t answer. Check your connection.')\n );\n}\n\n/** \"10 min before\", \"When it starts\". */\nfunction reminderWords(reminder: ReminderDraft, ctx: EventSaveContext): string {\n return reminder.minutesBefore === 0\n ? ctx.tr('calendar.v2.reminderAtStart', 'When it starts')\n : ctx.tr('calendar.v2.reminderBefore', '{{time}} before', {\n time: formatDuration(reminder.minutesBefore, ctx.durationWords),\n });\n}\n\n/**\n * A write whose failure is noted (in the service's words) rather than thrown; it says whether\n * it went through. An error `done` accepts means what it was for is so already.\n */\nfunction attempt(\n run: SaveRun,\n ctx: EventSaveContext,\n work: () => Promise<unknown>,\n failed: (why: string) => string,\n done: (error: unknown) => boolean = () => false\n): () => Promise<boolean> {\n return async () => {\n try {\n await work();\n run.wrote = true;\n return true;\n } catch (error) {\n if (done(error)) return true;\n run.problems.push(failed(reasonFor(error, ctx.tr)));\n return false;\n }\n };\n}\n\n/** Makes a series' date an event of its own; that event, as the service has it. */\nasync function modifyOccurrence(\n client: Client,\n input: ModifyRecurringInstanceInput,\n me: string | null\n): Promise<CalendarEventV2> {\n const result = await client.mutate<\n CalendarV2ModifyOccurrenceMutation,\n CalendarV2ModifyOccurrenceMutationVariables\n >({ mutation: CalendarV2ModifyOccurrenceDocument, variables: { input } });\n const raw = result.data?.modifyRecurringInstance;\n const made = raw ? toCalendarEventV2(raw, me) : null;\n if (!made) throw new Error('No event came back');\n return made;\n}\n\n/** Splits a series at a date; the new series from that date, as the service has it. */\nasync function splitSeries(\n client: Client,\n seriesId: string,\n input: UpdateEventInput,\n me: string | null\n): Promise<CalendarEventV2> {\n const result = await client.mutate<\n CalendarV2SplitSeriesMutation,\n CalendarV2SplitSeriesMutationVariables\n >({ mutation: CalendarV2SplitSeriesDocument, variables: { id: seriesId, input } });\n const raw = result.data?.updateEvent;\n const made = raw ? toCalendarEventV2(raw, me) : null;\n if (!made) throw new Error('No event came back');\n return made;\n}\n\n/** Creates the event; its id. */\nasync function createEvent(client: Client, input: CreateEventInput): Promise<string> {\n const created = await client.mutate<\n CalendarV2CreateEventMutation,\n CalendarV2CreateEventMutationVariables\n >({\n mutation: CalendarV2CreateEventDocument,\n variables: { input },\n });\n const id = created.data?.createEvent.id;\n if (!id) throw new Error('No event came back');\n return id;\n}\n\n/**\n * The event's updates, one after the other (a new rule first, then the series' new start). If\n * the first fails, its error is returned: nothing has changed, unless the service already made\n * the event from a series (`madeNew`), when it is noted with the rest. A later one that fails is\n * noted.\n */\nasync function applyUpdates(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext,\n madeNew: boolean\n): Promise<{ error: unknown } | null> {\n return inOrder(plan.updates, async (update, index) => {\n try {\n await client.mutate<CalendarV2UpdateEventMutation, CalendarV2UpdateEventMutationVariables>({\n mutation: CalendarV2UpdateEventDocument,\n variables: { id, input: update.input, scope: update.scope },\n });\n run.wrote = true;\n return null;\n } catch (error) {\n if (index === 0 && !madeNew) return { error };\n run.problems.push(\n index === 0\n ? ctx.tr('calendar.v2.eventRestFailed', 'Its other changes didn’t save: {{reason}}', {\n reason: reasonFor(error, ctx.tr),\n })\n : ctx.tr('calendar.v2.eventRuleFailed', 'The new repeat didn’t save: {{reason}}', {\n reason: reasonFor(error, ctx.tr),\n })\n );\n return null;\n }\n });\n}\n\n/** Guests out and in. */\nfunction guestTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeGuests.map((guest) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2RemoveGuestMutation, CalendarV2RemoveGuestMutationVariables>({\n mutation: CalendarV2RemoveGuestDocument,\n variables: { attendeeId: guest.attendeeId ?? '' },\n }),\n (why) =>\n tr('calendar.v2.guestRemoveFailed', 'Couldn’t remove {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ...plan.addGuests.map((guest: GuestDraft) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2AddGuestMutation, CalendarV2AddGuestMutationVariables>({\n mutation: CalendarV2AddGuestDocument,\n variables: { eventId: id, userId: guest.userId, email: guest.email, name: guest.name },\n }),\n (why) =>\n tr('calendar.v2.guestAddFailed', 'Couldn’t invite {{name}}: {{reason}}', {\n name: ctx.guestName(guest),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/** Reminders out and in. */\nfunction reminderTasks(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<boolean>)[] {\n const { tr } = ctx;\n return [\n ...plan.removeReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2DeleteReminderMutation,\n CalendarV2DeleteReminderMutationVariables\n >({\n mutation: CalendarV2DeleteReminderDocument,\n variables: { id: reminder.reminderId ?? '' },\n }),\n (why) =>\n tr(\n 'calendar.v2.reminderRemoveFailed',\n 'Couldn’t remove the reminder {{when}}: {{reason}}',\n {\n when: reminderWords(reminder, ctx),\n reason: why,\n }\n )\n )\n ),\n ...plan.addReminders.map((reminder) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CreateReminderMutation,\n CalendarV2CreateReminderMutationVariables\n >({\n mutation: CalendarV2CreateReminderDocument,\n variables: {\n input: {\n eventId: id,\n minutesBefore: reminder.minutesBefore,\n channel: REMINDER_CHANNEL[reminder.channel],\n },\n },\n }),\n (why) =>\n tr('calendar.v2.reminderAddFailed', 'Couldn’t add the reminder {{when}}: {{reason}}', {\n when: reminderWords(reminder, ctx),\n reason: why,\n })\n )\n ),\n ];\n}\n\n/** The series' tags on the event made from it (A4); kept for the next save when it fails. */\nfunction tagsTask(\n client: Client,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n const tags = plan.tags;\n if (!tags) return [];\n const write = attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2UpdateEventMutation, CalendarV2UpdateEventMutationVariables>({\n mutation: CalendarV2UpdateEventDocument,\n variables: { id: tags.eventId, input: tags.input, scope: tags.scope },\n }),\n (why) =>\n ctx.tr('calendar.v2.eventTagsFailed', 'Its tags didn’t save: {{reason}}', { reason: why })\n );\n return [\n async () => {\n if (!(await write())) run.left.tags = tags;\n },\n ];\n}\n\n/** Notes a series' date still to cancel, for the next save. */\nfunction leaveCancel(left: SaveCarry, seriesId: string, date: Date): void {\n const item = left.cancels.find((entry) => entry.seriesId === seriesId);\n if (item) item.dates.push(date);\n else left.cancels.push({ seriesId, dates: [date] });\n}\n\n/**\n * Series' cancelled dates, cancelled again where their new times put them (A4): one task a\n * series, its dates one after another (the service adds each to the series' list on its own,\n * so two at once could leave one out). One that fails is kept for the next save.\n */\nfunction cancelledDateTasks(\n client: Client,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n return plan.cancels.map(({ seriesId, dates }) => async () => {\n await inOrder(dates, async (date) => {\n const cancelled = await attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CancelOccurrenceMutation,\n CalendarV2CancelOccurrenceMutationVariables\n >({\n mutation: CalendarV2CancelOccurrenceDocument,\n variables: { seriesId, instanceDate: date.toISOString() },\n }),\n (why) =>\n ctx.tr(\n 'calendar.v2.eventKeepCancelledFailed',\n 'Couldn’t keep {{day}} cancelled: {{reason}}',\n {\n day: formatDay(instantToZoned(date, ctx.timeZone).date, ctx.format, 'short'),\n reason: why,\n }\n ),\n alreadySo\n )();\n if (!cancelled) leaveCancel(run.left, seriesId, date);\n return null;\n });\n });\n}\n\n/**\n * The room, as one task: a room moving to a new time (or another room) is let go before it is\n * booked again, and booked only once it is let go; else the event would hold two bookings. The\n * old one then stands, and saving again tries both again. A booking a series held for the date\n * made an event of its own goes first; one that can't be let go is kept for the next save (the\n * event read back doesn't show it).\n */\nfunction roomTask(\n client: Client,\n id: string,\n plan: SavePlan,\n run: SaveRun,\n ctx: EventSaveContext\n): (() => Promise<void>)[] {\n const { tr } = ctx;\n const book = plan.bookRoom;\n const letGo = (bookingId: string) =>\n attempt(\n run,\n ctx,\n () =>\n client.mutate<\n CalendarV2CancelRoomBookingMutation,\n CalendarV2CancelRoomBookingMutationVariables\n >({\n mutation: CalendarV2CancelRoomBookingDocument,\n variables: { bookingId },\n }),\n (why) =>\n book\n ? tr(\n 'calendar.v2.roomMoveFailed',\n 'Couldn’t move the room booking, so it stays as it was: {{reason}}',\n { reason: why }\n )\n : tr(\n 'calendar.v2.roomReleaseFailed',\n 'Couldn’t let go of the room booked before: {{reason}}',\n { reason: why }\n ),\n alreadySo\n );\n const cancelId = plan.cancelBookingId;\n const release = cancelId ? letGo(cancelId) : null;\n const reserve = book\n ? attempt(\n run,\n ctx,\n () =>\n client.mutate<CalendarV2BookRoomMutation, CalendarV2BookRoomMutationVariables>({\n mutation: CalendarV2BookRoomDocument,\n variables: {\n input: {\n eventId: id,\n resourceId: book.resourceId,\n startTime: book.start.toISOString(),\n endTime: book.end.toISOString(),\n },\n },\n }),\n (why) =>\n tr('calendar.v2.roomBookFailed', 'Couldn’t book {{room}}: {{reason}}', {\n room: ctx.roomName(book.resourceId) ?? tr('calendar.v2.theRoom', 'The room'),\n reason: why,\n })\n )\n : null;\n const seriesHeld = plan.releaseBookingIds;\n if (seriesHeld.length === 0 && !release && !reserve) return [];\n return [\n async () => {\n const stillHeld: string[] = [];\n await inOrder(seriesHeld, async (bookingId) => {\n if (!(await letGo(bookingId)())) stillHeld.push(bookingId);\n return null;\n });\n if (stillHeld.length > 0) {\n run.left.releaseBookingIds.push(...stillHeld);\n return;\n }\n if (release && !(await release())) return;\n if (reserve) await reserve();\n },\n ];\n}\n\n/** The success toast's title: \"Added “Sync” to Customer calls, Fri 20 Nov 13:00 – 14:00.\" */\nfunction savedWords(\n form: EventForm,\n route: SaveRoute,\n row: CalendarEventV2 | null,\n ctx: EventSaveContext\n): string {\n const { tr } = ctx;\n const title = form.title.trim();\n const start = startInstant(form);\n const day = form.allDay ? form.firstDay : instantToZoned(start, ctx.timeZone).date;\n if (route.kind === 'thisDate') {\n return tr('calendar.v2.eventSavedDate', 'Saved “{{title}}” on {{day}}.', {\n title,\n day: formatDay(day, ctx.format, 'short'),\n });\n }\n if (route.kind === 'split') {\n return tr('calendar.v2.eventSavedLater', 'Saved “{{title}}” from {{day}} on.', {\n title,\n day: formatDay(day, ctx.format, 'short'),\n });\n }\n if (route.kind === 'edit') {\n return row?.isRecurring && route.eventId === row.eventId\n ? tr('calendar.v2.eventSavedSeries', 'Saved every event in “{{title}}”.', { title })\n : tr('calendar.v2.eventSaved', 'Saved “{{title}}”.', { title });\n }\n const when = form.allDay\n ? tr('calendar.v2.allDayLower', 'all day')\n : formatInstantRange(start, endInstant(form), ctx.timeZone, ctx.format);\n return tr('calendar.v2.eventAdded', 'Added “{{title}}” to {{calendar}}, {{day}} {{time}}.', {\n title,\n calendar: ctx.calendarName(form.calendarId ?? '') ?? tr('calendar.v2.aCalendar', 'a calendar'),\n day: formatDay(day, ctx.format, 'short'),\n time: when,\n });\n}\n\n/**\n * The date of a series the dialog goes on with after a partial save: the date edited, where the\n * save put it (every event moved as the form moved it). With no date when that may not be a\n * date of the series any more (its repeat changed: a new end, other days), and for a split's new\n * series and a date made its own event: the series read back is its first date (for a split, the\n * edited one, at whatever time its update left it), and the event made is one of its own.\n */\nfunction dateAfterSave(request: SaveRequest, route: SaveRoute, savedId: string): Date | null {\n const { form, initial, event } = request;\n if (route.kind !== 'edit' || !event || event.eventId !== savedId || !isSeriesDate(event)) {\n return null;\n }\n return rruleOf(form) === rruleOf(initial) ? startInstant(form) : null;\n}\n\nexport function useEventSave(\n context: EventSaveContext\n): (request: SaveRequest) => Promise<SaveOutcome> {\n const client = useApolloClient();\n const notify = useNotify();\n const contextRef = useRef(context);\n useEffect(() => {\n contextRef.current = context;\n });\n\n return useCallback(\n async (request: SaveRequest): Promise<SaveOutcome> => {\n const { form, initial, event, row, carry } = request;\n const ctx = contextRef.current;\n const { tr } = ctx;\n const title = form.title.trim();\n const route = saveRouteFor(request, ctx.timeZone);\n const creating = route.kind === 'create';\n const failed = (error: unknown): SaveOutcome => {\n notify({\n title: creating\n ? tr('calendar.v2.eventAddFailed', 'Couldn’t add “{{title}}”', { title })\n : tr('calendar.v2.eventSaveFailed', 'Couldn’t save “{{title}}”', { title }),\n description: reasonFor(error, tr),\n tone: 'error',\n urgent: true,\n });\n return { kind: 'failed' };\n };\n\n // ── The event itself ──\n let id: string;\n let plan: SavePlan;\n // The service made an event from the series (a date on its own, or a split's new series).\n let made: CalendarEventV2 | null = null;\n try {\n if (route.kind === 'create') {\n id = await createEvent(client, route.plan.create);\n plan = route.plan;\n } else if (route.kind === 'edit') {\n id = route.eventId;\n plan = route.plan;\n } else {\n made =\n route.kind === 'thisDate'\n ? await modifyOccurrence(client, route.input, ctx.me)\n : await splitSeries(client, route.seriesId, route.input, ctx.me);\n id = made.eventId;\n plan = planOnNewEvent(\n route.form,\n initial,\n made,\n event ?? made,\n row ?? made,\n ctx.timeZone,\n carry\n );\n }\n } catch (error) {\n return failed(error);\n }\n const madeNew = made !== null;\n const run: SaveRun = {\n wrote: creating || madeNew,\n problems: [],\n left: { releaseBookingIds: [], tags: null, cancels: [] },\n };\n const firstUpdate = await applyUpdates(client, id, plan, run, ctx, madeNew);\n if (firstUpdate) return failed(firstUpdate.error);\n\n // ── Its guests, reminders and room ──\n await inTurns(\n [\n ...guestTasks(client, id, plan, run, ctx),\n ...reminderTasks(client, id, plan, run, ctx),\n ...roomTask(client, id, plan, run, ctx),\n ...tagsTask(client, plan, run, ctx),\n ...cancelledDateTasks(client, plan, run, ctx),\n ],\n PARALLEL_WRITES\n );\n if (run.wrote) invalidateCalendarEvents();\n\n if (run.problems.length > 0) {\n notify({\n title: creating\n ? tr('calendar.v2.eventAddedPartly', 'Added “{{title}}”, but not all of it', { title })\n : tr('calendar.v2.eventSavedPartly', 'Saved “{{title}}”, but not all of it', { title }),\n description: `${run.problems.join(' ')} ${tr(\n 'calendar.v2.eventSaveAgain',\n 'Save again to try the rest.'\n )}`,\n tone: 'warning',\n urgent: true,\n });\n return {\n kind: 'partial',\n eventId: id,\n instanceDate: dateAfterSave(request, route, id),\n madeNew,\n carry: carriesWork(run.left) ? run.left : null,\n };\n }\n notify({ title: savedWords(form, route, row, ctx), tone: 'success' });\n return { kind: 'saved', eventId: id };\n },\n [client, notify]\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuJA,IAAMA,IAAkB;AAKxB,SAAgBC,EAAe,GAA+B;CAK5D,OAJIC,EAAsB,GAAGC,CAAK,IAChBA,EAAM,OAAO,KAAK,MAASC,EAAK,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK,O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QS,GAAIG,GAAMhB,GAAKL,GAAKwB,CAAO;EAqC1E,OApCIgE,IAAoBlF,EAAOkF,EAAY,KAAK,KAGhD,MAAM3G,EACJ;GACE,GAAG4C,EAAWhB,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GACxC,GAAG8B,EAAcrB,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GAC3C,GAAG8C,EAASrC,GAAQS,GAAIG,GAAMhB,GAAKL,CAAG;GACtC,GAAGkC,EAASzB,GAAQY,GAAMhB,GAAKL,CAAG;GAClC,GAAGyC,EAAmBhC,GAAQY,GAAMhB,GAAKL,CAAG;EAC9C,GACAxB,CACF,GACI6B,EAAI,SAAOoF,EAAyB,GAEpCpF,EAAI,SAAS,SAAS,KACxBwE,EAAO;GACL,OAAOQ,IACHxF,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC,IACpFA,EAAG,gCAAgC,wCAAwC,EAAE,SAAM,CAAC;GACxF,aAAa,GAAGQ,EAAI,SAAS,KAAK,GAAG,EAAE,GAAGR,EACxC,8BACA,6BACF;GACA,MAAM;GACN,QAAQ;EACV,CAAC,GACM;GACL,MAAM;GACN,SAASqB;GACT,cAAckD,EAAcC,GAASN,GAAO7C,CAAE;GAC9C;GACA,OAAOwE,EAAYrF,EAAI,IAAI,IAAIA,EAAI,OAAO;EAC5C,MAEFwE,EAAO;GAAE,OAAOpB,EAAWE,GAAMI,GAAOC,GAAKhE,CAAG;GAAG,MAAM;EAAU,CAAC,GAC7D;GAAE,MAAM;GAAS,SAASkB;EAAG;CACtC,GACA,CAACT,GAAQoE,CAAM,CACjB;AACF"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { formatDayTimeSpan as e, formatInstantRange as t } from "../format.js";
|
|
2
2
|
import { eventDays as n } from "../time/calendarTime.js";
|
|
3
|
-
import { canEditEvent as r, canMoveOnGrid as i, eventRoom as a,
|
|
3
|
+
import { canEditEvent as r, canMoveOnGrid as i, eventRoom as a, inSeries as o, isBusyOnly as s, isHappeningNow as c, isPastEvent as l, joinUrl as u, myPart as d } from "./eventModel.js";
|
|
4
4
|
// src/v2/events/eventLook.ts
|
|
5
|
-
function
|
|
6
|
-
let n =
|
|
5
|
+
function f(e, t) {
|
|
6
|
+
let n = s(e, t.calendar, t.me), f = d({
|
|
7
7
|
...e,
|
|
8
8
|
myResponse: t.answer ?? e.myResponse
|
|
9
|
-
}, t.me),
|
|
9
|
+
}, t.me), p = n ? null : a(e), m = !n && u(e) !== null, h = (e.location ?? e.locationAddress ?? "").split(",")[0]?.trim() ?? "";
|
|
10
10
|
return {
|
|
11
11
|
busyOnly: n,
|
|
12
|
-
invitation: !n &&
|
|
13
|
-
maybe: !n &&
|
|
14
|
-
declined: !n &&
|
|
15
|
-
faded: t.dimPast &&
|
|
16
|
-
happeningNow:
|
|
12
|
+
invitation: !n && f === "invited",
|
|
13
|
+
maybe: !n && f === "maybe",
|
|
14
|
+
declined: !n && f === "declined",
|
|
15
|
+
faded: t.dimPast && l(e, t.now, t.timeZone),
|
|
16
|
+
happeningNow: c(e, t.now),
|
|
17
17
|
editable: !n && r(e, t.calendar, t.me),
|
|
18
18
|
movable: !n && i(e, t.calendar, t.me, t.timeZone),
|
|
19
|
-
roomPending:
|
|
20
|
-
roomRefused:
|
|
21
|
-
repeating: !n && e
|
|
22
|
-
online:
|
|
19
|
+
roomPending: p?.status === "PENDING",
|
|
20
|
+
roomRefused: p?.status === "REJECTED",
|
|
21
|
+
repeating: !n && o(e),
|
|
22
|
+
online: m,
|
|
23
23
|
title: n ? t.tr("calendar.v2.busy", "Busy") : e.title || t.tr("calendar.v2.untitled", "(No title)"),
|
|
24
|
-
place: n ? null :
|
|
24
|
+
place: n ? null : p?.name ?? (m ? t.tr("calendar.v2.videoCall", "Video call") : h || null)
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function p(r, i, a) {
|
|
28
28
|
let { tr: o } = a, s = n(r, a.timeZone), c;
|
|
29
29
|
c = r.allDay ? o("calendar.v2.allDayLower", "all day") : s.start === s.end ? t(r.start, r.end, a.timeZone, a.format) : e(r.start, r.end, a.timeZone, a.format);
|
|
30
30
|
let l = [i.title, c];
|
|
31
31
|
return a.calendarName && l.push(a.calendarName), i.invitation && l.push(o("calendar.v2.markerInvitation", "waiting for your answer")), i.maybe && l.push(o("calendar.v2.markerMaybe", "you said maybe")), i.declined && l.push(o("calendar.v2.markerDeclined", "you declined")), i.roomPending && l.push(o("calendar.v2.markerRoomPending", "room waiting for approval")), i.roomRefused && l.push(o("calendar.v2.markerRoomRefused", "room not available")), i.repeating && l.push(o("calendar.v2.markerRepeats", "repeats")), i.happeningNow && l.push(o("calendar.v2.markerNow", "happening now")), l.join(", ");
|
|
32
32
|
}
|
|
33
|
-
export {
|
|
33
|
+
export { p as eventAriaLabel, f as eventLook };
|
|
34
34
|
|
|
35
35
|
//# sourceMappingURL=eventLook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventLook.js","names":["eventLook","busyOnly","isBusyOnly","event","context","part","myPart","room","eventRoom","online","joinUrl","address","isPastEvent","isHappeningNow","canEditEvent","canMoveOnGrid","eventAriaLabel","days","eventDays","when","tr","formatInstantRange","formatDayTimeSpan","parts","look"],"sources":["../../../src/v2/events/eventLook.ts"],"sourcesContent":["/**\n * How an event looks in every view (BOFF-15698 A1): the markers (invitation, maybe, private\n * \"Busy\", ended, on now, room waiting or refused, repeating) and the words a screen reader\n * hears for it. Pure apart from the translations it is given.\n */\nimport type { Tr } from '../data/useEventActions';\nimport type { CalendarFormat } from '../format';\nimport { formatDayTimeSpan, formatInstantRange } from '../format';\nimport { eventDays } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventResponseV2 } from '../types';\nimport {\n canEditEvent,\n canMoveOnGrid,\n eventRoom,\n isBusyOnly,\n isHappeningNow,\n isPastEvent,\n joinUrl,\n myPart,\n} from './eventModel';\n\nexport interface EventLook {\n /** Someone else's private time: only \"Busy\" shows. */\n busyOnly: boolean;\n /** Waiting for the person's answer. */\n invitation: boolean;\n maybe: boolean;\n declined: boolean;\n /** Ended, and \"Fade past events\" is on. */\n faded: boolean;\n happeningNow: boolean;\n editable: boolean;\n /** Can be dragged and moved with the keyboard on the grid. */\n movable: boolean;\n /** The room is waiting for approval. */\n roomPending: boolean;\n /** The room booking was turned down. */\n roomRefused: boolean;\n repeating: boolean;\n /** A video call to join. */\n online: boolean;\n /** \"Busy\" or the title. */\n title: string;\n /** Where: the room, \"Video call\", or the first part of the address. */\n place: string | null;\n}\n\nexport interface LookContext {\n tr: Tr;\n me: string | null;\n now: Date;\n timeZone: string;\n dimPast: boolean;\n calendar: CalendarV2 | undefined;\n /** The person's answer, with one given on this page first. */\n answer: EventResponseV2 | null;\n}\n\nexport function eventLook(event: CalendarEventV2, context: LookContext): EventLook {\n const busyOnly = isBusyOnly(event, context.calendar, context.me);\n const part = myPart({ ...event, myResponse: context.answer ?? event.myResponse }, context.me);\n // Someone else's private time shows nothing but \"Busy\": no room, call or repeat markers.\n const room = busyOnly ? null : eventRoom(event);\n const online = !busyOnly && joinUrl(event) !== null;\n const address = (event.location ?? event.locationAddress ?? '').split(',')[0]?.trim() ?? '';\n return {\n busyOnly,\n invitation: !busyOnly && part === 'invited',\n maybe: !busyOnly && part === 'maybe',\n declined: !busyOnly && part === 'declined',\n faded: context.dimPast && isPastEvent(event, context.now, context.timeZone),\n happeningNow: isHappeningNow(event, context.now),\n editable: !busyOnly && canEditEvent(event, context.calendar, context.me),\n movable: !busyOnly && canMoveOnGrid(event, context.calendar, context.me, context.timeZone),\n roomPending: room?.status === 'PENDING',\n roomRefused: room?.status === 'REJECTED',\n repeating: !busyOnly && event
|
|
1
|
+
{"version":3,"file":"eventLook.js","names":["eventLook","busyOnly","isBusyOnly","event","context","part","myPart","room","eventRoom","online","joinUrl","address","isPastEvent","isHappeningNow","canEditEvent","canMoveOnGrid","inSeries","eventAriaLabel","days","eventDays","when","tr","formatInstantRange","formatDayTimeSpan","parts","look"],"sources":["../../../src/v2/events/eventLook.ts"],"sourcesContent":["/**\n * How an event looks in every view (BOFF-15698 A1): the markers (invitation, maybe, private\n * \"Busy\", ended, on now, room waiting or refused, repeating) and the words a screen reader\n * hears for it. Pure apart from the translations it is given.\n */\nimport type { Tr } from '../data/useEventActions';\nimport type { CalendarFormat } from '../format';\nimport { formatDayTimeSpan, formatInstantRange } from '../format';\nimport { eventDays } from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventResponseV2 } from '../types';\nimport {\n canEditEvent,\n canMoveOnGrid,\n eventRoom,\n inSeries,\n isBusyOnly,\n isHappeningNow,\n isPastEvent,\n joinUrl,\n myPart,\n} from './eventModel';\n\nexport interface EventLook {\n /** Someone else's private time: only \"Busy\" shows. */\n busyOnly: boolean;\n /** Waiting for the person's answer. */\n invitation: boolean;\n maybe: boolean;\n declined: boolean;\n /** Ended, and \"Fade past events\" is on. */\n faded: boolean;\n happeningNow: boolean;\n editable: boolean;\n /** Can be dragged and moved with the keyboard on the grid. */\n movable: boolean;\n /** The room is waiting for approval. */\n roomPending: boolean;\n /** The room booking was turned down. */\n roomRefused: boolean;\n repeating: boolean;\n /** A video call to join. */\n online: boolean;\n /** \"Busy\" or the title. */\n title: string;\n /** Where: the room, \"Video call\", or the first part of the address. */\n place: string | null;\n}\n\nexport interface LookContext {\n tr: Tr;\n me: string | null;\n now: Date;\n timeZone: string;\n dimPast: boolean;\n calendar: CalendarV2 | undefined;\n /** The person's answer, with one given on this page first. */\n answer: EventResponseV2 | null;\n}\n\nexport function eventLook(event: CalendarEventV2, context: LookContext): EventLook {\n const busyOnly = isBusyOnly(event, context.calendar, context.me);\n const part = myPart({ ...event, myResponse: context.answer ?? event.myResponse }, context.me);\n // Someone else's private time shows nothing but \"Busy\": no room, call or repeat markers.\n const room = busyOnly ? null : eventRoom(event);\n const online = !busyOnly && joinUrl(event) !== null;\n const address = (event.location ?? event.locationAddress ?? '').split(',')[0]?.trim() ?? '';\n return {\n busyOnly,\n invitation: !busyOnly && part === 'invited',\n maybe: !busyOnly && part === 'maybe',\n declined: !busyOnly && part === 'declined',\n faded: context.dimPast && isPastEvent(event, context.now, context.timeZone),\n happeningNow: isHappeningNow(event, context.now),\n editable: !busyOnly && canEditEvent(event, context.calendar, context.me),\n movable: !busyOnly && canMoveOnGrid(event, context.calendar, context.me, context.timeZone),\n roomPending: room?.status === 'PENDING',\n roomRefused: room?.status === 'REJECTED',\n repeating: !busyOnly && inSeries(event),\n online,\n title: busyOnly\n ? context.tr('calendar.v2.busy', 'Busy')\n : event.title || context.tr('calendar.v2.untitled', '(No title)'),\n place: busyOnly\n ? null\n : (room?.name ??\n (online ? context.tr('calendar.v2.videoCall', 'Video call') : address || null)),\n };\n}\n\n/** What a screen reader hears for an event: title, when, calendar, and its markers. */\nexport function eventAriaLabel(\n event: CalendarEventV2,\n look: EventLook,\n context: { tr: Tr; format: CalendarFormat; timeZone: string; calendarName: string | null }\n): string {\n const { tr } = context;\n const days = eventDays(event, context.timeZone);\n let when: string;\n if (event.allDay) when = tr('calendar.v2.allDayLower', 'all day');\n else if (days.start === days.end) {\n when = formatInstantRange(event.start, event.end, context.timeZone, context.format);\n } else {\n // Over midnight, or a day or more: both ends with their days.\n when = formatDayTimeSpan(event.start, event.end, context.timeZone, context.format);\n }\n const parts = [look.title, when];\n if (context.calendarName) parts.push(context.calendarName);\n if (look.invitation) parts.push(tr('calendar.v2.markerInvitation', 'waiting for your answer'));\n if (look.maybe) parts.push(tr('calendar.v2.markerMaybe', 'you said maybe'));\n if (look.declined) parts.push(tr('calendar.v2.markerDeclined', 'you declined'));\n if (look.roomPending)\n parts.push(tr('calendar.v2.markerRoomPending', 'room waiting for approval'));\n if (look.roomRefused) parts.push(tr('calendar.v2.markerRoomRefused', 'room not available'));\n if (look.repeating) parts.push(tr('calendar.v2.markerRepeats', 'repeats'));\n if (look.happeningNow) parts.push(tr('calendar.v2.markerNow', 'happening now'));\n return parts.join(', ');\n}\n"],"mappings":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AAUA,EAAK,MACpBI,EAAmBnB,EAAM,OAAOA,EAAM,KAAKC,EAAQ,UAAUA,EAAQ,MAAM,IAG3EmB,EAAkBpB,EAAM,OAAOA,EAAM,KAAKC,EAAQ,UAAUA,EAAQ,MAAM;CAEnF,IAAMoB,IAAQ,CAACC,EAAK,OAAOL,CAAI;CAU/B,OATIhB,EAAQ,gBAAcoB,EAAM,KAAKpB,EAAQ,YAAY,GACrDqB,EAAK,cAAYD,EAAM,KAAKH,EAAG,gCAAgC,yBAAyB,CAAC,GACzFI,EAAK,SAAOD,EAAM,KAAKH,EAAG,2BAA2B,gBAAgB,CAAC,GACtEI,EAAK,YAAUD,EAAM,KAAKH,EAAG,8BAA8B,cAAc,CAAC,GAC1EI,EAAK,eACPD,EAAM,KAAKH,EAAG,iCAAiC,2BAA2B,CAAC,GACzEI,EAAK,eAAaD,EAAM,KAAKH,EAAG,iCAAiC,oBAAoB,CAAC,GACtFI,EAAK,aAAWD,EAAM,KAAKH,EAAG,6BAA6B,SAAS,CAAC,GACrEI,EAAK,gBAAcD,EAAM,KAAKH,EAAG,yBAAyB,eAAe,CAAC,GACvEG,EAAM,KAAK,IAAI;AACxB"}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { DateValue } from '@burdenoff/fe-libs/ui';
|
|
2
|
-
import { CalendarEventV2, CalendarV2, EventBookingV2, TimedSegment } from '../types';
|
|
2
|
+
import { CalendarEventV2, CalendarV2, CalendarV2EventDraft, EventBookingV2, TimedSegment } from '../types';
|
|
3
3
|
/** The person's part in an event. */
|
|
4
4
|
export type MyPart = 'organizer' | 'invited' | 'going' | 'maybe' | 'declined' | 'none';
|
|
5
|
+
/**
|
|
6
|
+
* A regular date of a repeating event (A4): the series stands behind it, and "This event"
|
|
7
|
+
* names the date by its original start. A date moved on its own is an event of its own.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isSeriesDate(event: Pick<CalendarEventV2, 'isRecurring' | 'seriesId' | 'instanceDate' | 'isModified'>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* What the event dialog and Find a time open with to change an event: the stored event, and for
|
|
12
|
+
* a regular date of a series the date ("This event" names it).
|
|
13
|
+
*/
|
|
14
|
+
export declare function editDraftFor(event: CalendarEventV2): CalendarV2EventDraft;
|
|
15
|
+
/** A date of a repeating event, as it stands or moved on its own: it shows "Repeats". */
|
|
16
|
+
export declare function inSeries(event: Pick<CalendarEventV2, 'isRecurring' | 'seriesId'>): boolean;
|
|
5
17
|
export declare function isOrganizer(event: CalendarEventV2, me: string | null): boolean;
|
|
6
18
|
export declare function myPart(event: CalendarEventV2, me: string | null): MyPart;
|
|
7
19
|
/**
|
|
@@ -16,9 +28,10 @@ export declare function isBusyOnly(event: CalendarEventV2, calendar: CalendarV2
|
|
|
16
28
|
export declare function canEditEvent(event: CalendarEventV2, calendar: CalendarV2 | undefined, me: string | null): boolean;
|
|
17
29
|
/**
|
|
18
30
|
* Drag and keyboard moves, which keep an event inside one day of the grid. Not for:
|
|
19
|
-
* - a repeating event:
|
|
20
|
-
*
|
|
21
|
-
* to change
|
|
31
|
+
* - a date of a repeating event: a move would change the series' own time (every date), and a
|
|
32
|
+
* date changed on its own is an event of its own that the event dialog makes, carrying its
|
|
33
|
+
* guests, reminders and room; so the dialog asks which events to change. A date already
|
|
34
|
+
* moved on its own is its own event and moves like one;
|
|
22
35
|
* - one that runs past midnight on the calendar's clock (23:00–01:00): kept inside one day it
|
|
23
36
|
* would lose its times, so it changes in the event dialog;
|
|
24
37
|
* - one that starts or ends in the second pass of an hour the clocks repeat (01:30 GMT on 25
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { dayDifference as e, eventDays as t, instantToZoned as n, timedSegments as r, zonedTimeToInstant as i } from "../time/calendarTime.js";
|
|
2
2
|
// src/v2/events/eventModel.ts
|
|
3
3
|
var a = 864e5;
|
|
4
|
-
function o(e
|
|
4
|
+
function o(e) {
|
|
5
|
+
return e.isRecurring && !e.isModified && e.seriesId !== null && e.instanceDate !== null;
|
|
6
|
+
}
|
|
7
|
+
function s(e) {
|
|
8
|
+
return o(e) && e.instanceDate ? {
|
|
9
|
+
eventId: e.eventId,
|
|
10
|
+
instanceDate: e.instanceDate
|
|
11
|
+
} : { eventId: e.eventId };
|
|
12
|
+
}
|
|
13
|
+
function c(e) {
|
|
14
|
+
return e.isRecurring || e.seriesId !== null;
|
|
15
|
+
}
|
|
16
|
+
function l(e, t) {
|
|
5
17
|
return t ? e.organizerId === t || e.guests.some((e) => e.organizer && e.userId === t) : !1;
|
|
6
18
|
}
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
19
|
+
function u(e, t) {
|
|
20
|
+
if (l(e, t)) return "organizer";
|
|
9
21
|
switch (e.myResponse) {
|
|
10
22
|
case "NO_RESPONSE": return "invited";
|
|
11
23
|
case "ACCEPTED": return "going";
|
|
@@ -14,53 +26,53 @@ function s(e, t) {
|
|
|
14
26
|
default: return "none";
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
|
-
function
|
|
29
|
+
function d(e, t) {
|
|
18
30
|
return !e || !t || e.kind !== "PERSONAL" ? !1 : (e.ownerUserId ?? e.createdBy) === t;
|
|
19
31
|
}
|
|
20
|
-
function
|
|
21
|
-
return e.visibility !== "PUBLIC" &&
|
|
32
|
+
function f(e, t, n) {
|
|
33
|
+
return e.visibility !== "PUBLIC" && u(e, n) === "none" && !d(t, n);
|
|
22
34
|
}
|
|
23
|
-
function
|
|
24
|
-
return !t || t.isReadOnly || e.status === "CANCELLED" ? !1 :
|
|
35
|
+
function p(e, t, n) {
|
|
36
|
+
return !t || t.isReadOnly || e.status === "CANCELLED" ? !1 : l(e, n);
|
|
25
37
|
}
|
|
26
|
-
function
|
|
27
|
-
if (!
|
|
38
|
+
function m(e, n, r, i) {
|
|
39
|
+
if (!p(e, n, r) || e.isRecurring || g(e)) return !1;
|
|
28
40
|
let a = t(e, i);
|
|
29
|
-
return a.start === a.end &&
|
|
41
|
+
return a.start === a.end && h(e.start, i) && h(e.end, i);
|
|
30
42
|
}
|
|
31
|
-
function
|
|
43
|
+
function h(e, t) {
|
|
32
44
|
let r = n(e, t), a = Math.floor(e.getTime() / 6e4) * 6e4;
|
|
33
45
|
return i(r.date, r.minutes, t).getTime() === a;
|
|
34
46
|
}
|
|
35
|
-
function
|
|
47
|
+
function g(e) {
|
|
36
48
|
return e.allDay || e.end.getTime() - e.start.getTime() >= a;
|
|
37
49
|
}
|
|
38
|
-
function
|
|
50
|
+
function _(e, r, i) {
|
|
39
51
|
if (e.allDay) {
|
|
40
52
|
let a = n(r, i).date;
|
|
41
53
|
return t(e, i).end < a;
|
|
42
54
|
}
|
|
43
55
|
return e.end.getTime() <= r.getTime();
|
|
44
56
|
}
|
|
45
|
-
function
|
|
57
|
+
function v(e, t) {
|
|
46
58
|
if (e.allDay) return !1;
|
|
47
59
|
let n = t.getTime();
|
|
48
60
|
return e.start.getTime() <= n && e.end.getTime() > n;
|
|
49
61
|
}
|
|
50
|
-
function
|
|
51
|
-
return e.filter((e) => !t.hiddenCalendarIds.has(e.calendarId) && e.status !== "CANCELLED" && (t.showDeclined ||
|
|
62
|
+
function y(e, t) {
|
|
63
|
+
return e.filter((e) => !t.hiddenCalendarIds.has(e.calendarId) && e.status !== "CANCELLED" && (t.showDeclined || u(e, t.me) !== "declined"));
|
|
52
64
|
}
|
|
53
|
-
function
|
|
54
|
-
return e.filter((e) =>
|
|
65
|
+
function b(e, t, n) {
|
|
66
|
+
return e.filter((e) => u(e, n) === "invited" && e.end.getTime() > t.getTime()).sort((e, t) => e.start.getTime() - t.start.getTime());
|
|
55
67
|
}
|
|
56
|
-
function
|
|
68
|
+
function x(e) {
|
|
57
69
|
return e.resourceType === "ROOM" || e.resourceType === null;
|
|
58
70
|
}
|
|
59
|
-
function
|
|
60
|
-
let t = e.bookings.filter(
|
|
71
|
+
function S(e) {
|
|
72
|
+
let t = e.bookings.filter(x);
|
|
61
73
|
return t.find((e) => e.status === "PENDING" || e.status === "APPROVED") ?? t.find((e) => e.status === "COMPLETED") ?? t.find((e) => e.status === "REJECTED") ?? null;
|
|
62
74
|
}
|
|
63
|
-
function
|
|
75
|
+
function C(e) {
|
|
64
76
|
let t = e?.trim();
|
|
65
77
|
if (!t) return null;
|
|
66
78
|
let n = /^[a-z][a-z0-9+.-]*:/i.test(t) ? t : `https://${t}`;
|
|
@@ -71,22 +83,22 @@ function b(e) {
|
|
|
71
83
|
return null;
|
|
72
84
|
}
|
|
73
85
|
}
|
|
74
|
-
function
|
|
75
|
-
return
|
|
86
|
+
function w(e) {
|
|
87
|
+
return C(e.meeting?.url) ?? (e.locationType === "ONLINE" ? C(e.locationUrl) : null);
|
|
76
88
|
}
|
|
77
|
-
function
|
|
89
|
+
function T(e, t, n, i = {}) {
|
|
78
90
|
let a = new Map(t.map((e) => [e, []])), o = t[0], s = t[t.length - 1];
|
|
79
91
|
if (!o || !s) return a;
|
|
80
|
-
for (let t of e) if (!(t.allDay || !i.includeLong &&
|
|
92
|
+
for (let t of e) if (!(t.allDay || !i.includeLong && g(t))) for (let e of r(t.start, t.end, n, o, s)) a.get(e.date)?.push({
|
|
81
93
|
...e,
|
|
82
94
|
event: t
|
|
83
95
|
});
|
|
84
96
|
return a;
|
|
85
97
|
}
|
|
86
|
-
function
|
|
98
|
+
function E(e, n, r, i) {
|
|
87
99
|
let a = [];
|
|
88
100
|
for (let o of e) {
|
|
89
|
-
if (!
|
|
101
|
+
if (!g(o)) continue;
|
|
90
102
|
let e = t(o, i);
|
|
91
103
|
e.end < n || e.start > r || a.push({
|
|
92
104
|
event: o,
|
|
@@ -96,21 +108,21 @@ function C(e, n, r, i) {
|
|
|
96
108
|
}
|
|
97
109
|
return a;
|
|
98
110
|
}
|
|
99
|
-
function
|
|
111
|
+
function D(e, n, r) {
|
|
100
112
|
return e.filter((e) => {
|
|
101
113
|
let i = t(e, r);
|
|
102
114
|
return i.start <= n && i.end >= n;
|
|
103
|
-
}).sort((e, t) => Number(
|
|
115
|
+
}).sort((e, t) => Number(g(t)) - Number(g(e)) || e.start.getTime() - t.start.getTime() || e.title.localeCompare(t.title));
|
|
104
116
|
}
|
|
105
|
-
function
|
|
117
|
+
function O(t, n) {
|
|
106
118
|
return e(t.first, n) + 1;
|
|
107
119
|
}
|
|
108
|
-
function
|
|
120
|
+
function k(e, n, r, i, a) {
|
|
109
121
|
let o = t(e, a);
|
|
110
122
|
if (o.end < r || o.start > i) return !1;
|
|
111
123
|
for (let e of n) if (e >= o.start && e <= o.end) return !0;
|
|
112
124
|
return !1;
|
|
113
125
|
}
|
|
114
|
-
export {
|
|
126
|
+
export { E as allDayItems, p as canEditEvent, m as canMoveOnGrid, O as dayOfSpan, s as editDraftFor, S as eventRoom, D as eventsOnDay, c as inSeries, g as isAllDayRow, f as isBusyOnly, v as isHappeningNow, l as isOrganizer, _ as isPastEvent, o as isSeriesDate, w as joinUrl, u as myPart, h as readsBackOnClock, C as safeWebUrl, y as shownEvents, T as timedSegmentsByDay, k as touchesDays, b as waitingInvitations };
|
|
115
127
|
|
|
116
128
|
//# sourceMappingURL=eventModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventModel.js","names":["DAY_MS","isOrganizer","me","event","guest","myPart","isOwnCalendar","calendar","isBusyOnly","canEditEvent","canMoveOnGrid","isAllDayRow","days","eventDays","timeZone","readsBackOnClock","zoned","instantToZoned","instant","minute","zonedTimeToInstant","isPastEvent","today","now","isHappeningNow","at","shownEvents","events","options","waitingInvitations","a","b","isRoomBooking","booking","eventRoom","rooms","safeWebUrl","value","raw","withScheme","url","joinUrl","timedSegmentsByDay","byDay","day","first","last","segment","timedSegments","allDayItems","items","span","eventsOnDay","dayOfSpan","dayDifference","item","touchesDays"],"sources":["../../../src/v2/events/eventModel.ts"],"sourcesContent":["/**\n * What an event is to the person looking at it (BOFF-15698 A1): whose it is, their answer,\n * whether they may change it, whether only \"Busy\" may be shown, and which views and days it\n * belongs to. Pure, so the views and their tests share one reading.\n */\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport {\n dayDifference,\n eventDays,\n instantToZoned,\n timedSegments,\n zonedTimeToInstant,\n} from '../time/calendarTime';\nimport type { CalendarEventV2, CalendarV2, EventBookingV2, TimedSegment } from '../types';\n\nconst DAY_MS = 86_400_000;\n\n/** The person's part in an event. */\nexport type MyPart = 'organizer' | 'invited' | 'going' | 'maybe' | 'declined' | 'none';\n\nexport function isOrganizer(event: CalendarEventV2, me: string | null): boolean {\n if (!me) return false;\n return (\n event.organizerId === me || event.guests.some((guest) => guest.organizer && guest.userId === me)\n );\n}\n\nexport function myPart(event: CalendarEventV2, me: string | null): MyPart {\n if (isOrganizer(event, me)) return 'organizer';\n switch (event.myResponse) {\n case 'NO_RESPONSE':\n return 'invited';\n case 'ACCEPTED':\n return 'going';\n case 'TENTATIVE':\n return 'maybe';\n case 'DECLINED':\n return 'declined';\n default:\n return 'none';\n }\n}\n\n/** The person's own calendar: one only they hold. */\nfunction isOwnCalendar(calendar: CalendarV2 | undefined, me: string | null): boolean {\n if (!calendar || !me || calendar.kind !== 'PERSONAL') return false;\n return (calendar.ownerUserId ?? calendar.createdBy) === me;\n}\n\n/**\n * A private or confidential event of someone else's that the person is not invited to: the\n * views show only that the time is taken (\"Busy\"), never its title, place or guests.\n */\nexport function isBusyOnly(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null\n): boolean {\n if (event.visibility === 'PUBLIC') return false;\n return myPart(event, me) === 'none' && !isOwnCalendar(calendar, me);\n}\n\n/**\n * The person may move, resize, edit and delete it: they organise it, its calendar takes\n * changes (not a calendar followed by link), and it is not someone else's private time.\n */\nexport function canEditEvent(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null\n): boolean {\n if (!calendar || calendar.isReadOnly) return false;\n if (event.status === 'CANCELLED') return false;\n return isOrganizer(event, me);\n}\n\n/**\n * Drag and keyboard moves, which keep an event inside one day of the grid. Not for:\n * - a repeating event: it shows only its first occurrence until the series is expanded on the\n * server (B7), so moving it would move the whole series; the event dialog asks which events\n * to change;\n * - one that runs past midnight on the calendar's clock (23:00–01:00): kept inside one day it\n * would lose its times, so it changes in the event dialog;\n * - one that starts or ends in the second pass of an hour the clocks repeat (01:30 GMT on 25\n * October 2026 in London): the grid reads a clock time as its first pass, so a move would\n * shift it by the hour.\n */\nexport function canMoveOnGrid(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null,\n timeZone: string\n): boolean {\n if (!canEditEvent(event, calendar, me) || event.isRecurring || isAllDayRow(event)) return false;\n const days = eventDays(event, timeZone);\n if (days.start !== days.end) return false;\n return readsBackOnClock(event.start, timeZone) && readsBackOnClock(event.end, timeZone);\n}\n\n/**\n * Whether an instant's clock time on `timeZone` stands for that instant again (to the minute):\n * false in the second pass of a repeated hour, which the clock time reads as the first.\n */\nexport function readsBackOnClock(instant: Date, timeZone: string): boolean {\n const zoned = instantToZoned(instant, timeZone);\n const minute = Math.floor(instant.getTime() / 60_000) * 60_000;\n return zonedTimeToInstant(zoned.date, zoned.minutes, timeZone).getTime() === minute;\n}\n\n/** Shown in the all-day row: an all-day event, or one that lasts a day or more. */\nexport function isAllDayRow(event: CalendarEventV2): boolean {\n return event.allDay || event.end.getTime() - event.start.getTime() >= DAY_MS;\n}\n\n/** The event has ended (an all-day event: its last day is before today). */\nexport function isPastEvent(event: CalendarEventV2, now: Date, timeZone: string): boolean {\n if (event.allDay) {\n const today = instantToZoned(now, timeZone).date;\n return eventDays(event, timeZone).end < today;\n }\n return event.end.getTime() <= now.getTime();\n}\n\nexport function isHappeningNow(event: CalendarEventV2, now: Date): boolean {\n if (event.allDay) return false;\n const at = now.getTime();\n return event.start.getTime() <= at && event.end.getTime() > at;\n}\n\nexport interface ShownEventsOptions {\n hiddenCalendarIds: ReadonlySet<string>;\n showDeclined: boolean;\n me: string | null;\n}\n\n/**\n * The events the views show: on a shown calendar, not cancelled, and not declined unless the\n * person asked to see those.\n */\nexport function shownEvents(\n events: readonly CalendarEventV2[],\n options: ShownEventsOptions\n): CalendarEventV2[] {\n return events.filter(\n (event) =>\n !options.hiddenCalendarIds.has(event.calendarId) &&\n event.status !== 'CANCELLED' &&\n (options.showDeclined || myPart(event, options.me) !== 'declined')\n );\n}\n\n/** Invitations still waiting for the person's answer that haven't ended, soonest first. */\nexport function waitingInvitations(\n events: readonly CalendarEventV2[],\n now: Date,\n me: string | null\n): CalendarEventV2[] {\n return events\n .filter((event) => myPart(event, me) === 'invited' && event.end.getTime() > now.getTime())\n .sort((a, b) => a.start.getTime() - b.start.getTime());\n}\n\n/** A room booking: a room, or a resource of unknown type (rooms are what events book most). */\nfunction isRoomBooking(booking: EventBookingV2): boolean {\n return booking.resourceType === 'ROOM' || booking.resourceType === null;\n}\n\n/**\n * The room an event is in: its first room booking that wasn't cancelled or turned down, else a\n * turned-down one to warn about. Other resources (equipment) never stand in for the room, so a\n * refused room still shows next to approved equipment.\n */\nexport function eventRoom(event: CalendarEventV2): EventBookingV2 | null {\n const rooms = event.bookings.filter(isRoomBooking);\n return (\n rooms.find((booking) => booking.status === 'PENDING' || booking.status === 'APPROVED') ??\n rooms.find((booking) => booking.status === 'COMPLETED') ??\n rooms.find((booking) => booking.status === 'REJECTED') ??\n null\n );\n}\n\n/** A web address that is safe to open: http or https only. */\nexport function safeWebUrl(raw: string | null | undefined): string | null {\n const value = raw?.trim();\n if (!value) return null;\n const withScheme = /^[a-z][a-z0-9+.-]*:/i.test(value) ? value : `https://${value}`;\n try {\n const url = new URL(withScheme);\n return url.protocol === 'https:' || url.protocol === 'http:' ? url.toString() : null;\n } catch {\n return null;\n }\n}\n\n/** The video call to join: the meeting link, else a location that is a web address. */\nexport function joinUrl(event: CalendarEventV2): string | null {\n return (\n safeWebUrl(event.meeting?.url) ??\n (event.locationType === 'ONLINE' ? safeWebUrl(event.locationUrl) : null)\n );\n}\n\n/** A timed event's piece on one day. */\nexport interface DaySegment<T = CalendarEventV2> extends TimedSegment {\n event: T;\n}\n\n/**\n * Timed events' pieces on each of `days`, on the clock of `timeZone`. Events shown in the\n * all-day row (`isAllDayRow`) are left out, as the grid draws them there; `includeLong` keeps\n * the timed ones of a day or more, for what is busy (all-day events never are).\n */\nexport function timedSegmentsByDay(\n events: readonly CalendarEventV2[],\n days: readonly DateValue[],\n timeZone: string,\n options: { includeLong?: boolean } = {}\n): Map<DateValue, DaySegment[]> {\n const byDay = new Map<DateValue, DaySegment[]>(days.map((day) => [day, []]));\n const first = days[0];\n const last = days[days.length - 1];\n if (!first || !last) return byDay;\n for (const event of events) {\n if (event.allDay || (!options.includeLong && isAllDayRow(event))) continue;\n for (const segment of timedSegments(event.start, event.end, timeZone, first, last)) {\n byDay.get(segment.date)?.push({ ...segment, event });\n }\n }\n return byDay;\n}\n\n/** An event in the all-day row, from its first to its last day. */\nexport interface AllDayItem<T = CalendarEventV2> {\n event: T;\n first: DateValue;\n last: DateValue;\n}\n\n/** The all-day row's events that touch `first`..`last`. */\nexport function allDayItems(\n events: readonly CalendarEventV2[],\n first: DateValue,\n last: DateValue,\n timeZone: string\n): AllDayItem[] {\n const items: AllDayItem[] = [];\n for (const event of events) {\n if (!isAllDayRow(event)) continue;\n const span = eventDays(event, timeZone);\n if (span.end < first || span.start > last) continue;\n items.push({ event, first: span.start, last: span.end });\n }\n return items;\n}\n\n/**\n * The events on one day, for a day's list (Month's \"+N more\", phones' Month, the List view):\n * every event that touches the day (one over midnight on both its days, as the grid shows\n * it), all-day ones first, then by start.\n */\nexport function eventsOnDay(\n events: readonly CalendarEventV2[],\n day: DateValue,\n timeZone: string\n): CalendarEventV2[] {\n return events\n .filter((event) => {\n const span = eventDays(event, timeZone);\n return span.start <= day && span.end >= day;\n })\n .sort(\n (a, b) =>\n Number(isAllDayRow(b)) - Number(isAllDayRow(a)) ||\n a.start.getTime() - b.start.getTime() ||\n a.title.localeCompare(b.title)\n );\n}\n\n/** Which of an all-day item's days `day` is: 1 for its first. */\nexport function dayOfSpan(item: { first: DateValue }, day: DateValue): number {\n return dayDifference(item.first, day) + 1;\n}\n\n/** Whether an event falls on any of `days` (sorted), on the clock of `timeZone`. */\nexport function touchesDays(\n event: CalendarEventV2,\n days: ReadonlySet<DateValue>,\n first: DateValue,\n last: DateValue,\n timeZone: string\n): boolean {\n const span = eventDays(event, timeZone);\n if (span.end < first || span.start > last) return false;\n for (const day of days) if (day >= span.start && day <= span.end) return true;\n return false;\n}\n"],"mappings":";;AAeA,IAAMA,IAAS;AAKf,SAAgBC,EAAY,GAAwB,GAA4B;CAE9E,OADKC,IAEHC,EAAM,gBAAgBD,KAAMC,EAAM,OAAO,MAAM,MAAUC,EAAM,aAAaA,EAAM,WAAWF,CAAE,IAFjF;AAIlB;AAEA,SAAgBG,EAAO,GAAwB,GAA2B;CACxE,IAAIJ,EAAYE,GAAOD,CAAE,GAAG,OAAO;CACnC,QAAQC,EAAM,YAAd;EACE,KAAK,eACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAGA,SAASG,EAAc,GAAkC,GAA4B;CAEnF,OADI,CAACC,KAAY,CAACL,KAAMK,EAAS,SAAS,aAAmB,MACrDA,EAAS,eAAeA,EAAS,eAAeL;AAC1D;AAMA,SAAgBM,EACd,GACA,GACA,GACS;CAET,OADIL,EAAM,eAAe,YAClBE,EAAOF,GAAOD,CAAE,MAAM,UAAU,CAACI,EAAcC,GAAUL,CAAE;AACpE;AAMA,SAAgBO,EACd,GACA,GACA,GACS;CAGT,OAFI,CAACF,KAAYA,EAAS,cACtBJ,EAAM,WAAW,cAAoB,KAClCF,EAAYE,GAAOD,CAAE;AAC9B;AAaA,SAAgBQ,EACd,GACA,GACA,GACA,GACS;CACT,IAAI,CAACD,EAAaN,GAAOI,GAAUL,CAAE,KAAKC,EAAM,eAAeQ,EAAYR,CAAK,GAAG,OAAO;CAC1F,IAAMS,IAAOC,EAAUV,GAAOW,CAAQ;CAEtC,OADIF,EAAK,UAAUA,EAAK,OACjBG,EAAiBZ,EAAM,OA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C/E,EAAM,IAAIC,EAAQ,IAAI,CAAC,EAAE,KAAK;EAAE,GAAGA;EAAS;CAAM,CAAC;CAGvD,OAAOJ;AACT;AAUA,SAAgBM,EACd,GACA,GACA,GACA,GACc;CACd,IAAMC,IAAsB,CAAC;CAC7B,KAAK,IAAM/C,KAASwB,GAAQ;EAC1B,IAAI,CAAChB,EAAYR,CAAK,GAAG;EACzB,IAAMgD,IAAOtC,EAAUV,GAAOW,CAAQ;EACtC,AAAIqC,EAAK,MAAMN,KAASM,EAAK,QAAQL,KACrCI,EAAM,KAAK;GAAE;GAAO,OAAOC,EAAK;GAAO,MAAMA,EAAK;EAAI,CAAC;CACzD;CACA,OAAOD;AACT;AAOA,SAAgBE,EACd,GACA,GACA,GACmB;CACnB,OAAOzB,EACJ,QAAQ,MAAU;EACjB,IAAMwB,IAAOtC,EAAUV,GAAOW,CAAQ;EACtC,OAAOqC,EAAK,SAASP,KAAOO,EAAK,OAAOP;CAC1C,CAAC,CAAC,CACD,MACE,GAAG,MACF,OAAOjC,EAAYoB,CAAC,CAAC,IAAI,OAAOpB,EAAYmB,CAAC,CAAC,KAC9CA,EAAE,MAAM,QAAQ,IAAIC,EAAE,MAAM,QAAQ,KACpCD,EAAE,MAAM,cAAcC,EAAE,KAAK,CACjC;AACJ;AAGA,SAAgBsB,EAAU,GAA4B,GAAwB;CAC5E,OAAOC,EAAcC,EAAK,OAAOX,CAAG,IAAI;AAC1C;AAGA,SAAgBY,EACd,GACA,GACA,GACA,GACA,GACS;CACT,IAAML,IAAOtC,EAAUV,GAAOW,CAAQ;CACtC,IAAIqC,EAAK,MAAMN,KAASM,EAAK,QAAQL,GAAM,OAAO;CAClD,KAAK,IAAMF,KAAOhC,GAAM,IAAIgC,KAAOO,EAAK,SAASP,KAAOO,EAAK,KAAK,OAAO;CACzE,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"eventModel.js","names":["DAY_MS","isSeriesDate","event","editDraftFor","inSeries","isOrganizer","me","guest","myPart","isOwnCalendar","calendar","isBusyOnly","canEditEvent","canMoveOnGrid","isAllDayRow","days","eventDays","timeZone","readsBackOnClock","zoned","instantToZoned","instant","minute","zonedTimeToInstant","isPastEvent","today","now","isHappeningNow","at","shownEvents","events","options","waitingInvitations","a","b","isRoomBooking","booking","eventRoom","rooms","safeWebUrl","value","raw","withScheme","url","joinUrl","timedSegmentsByDay","byDay","day","first","last","segment","timedSegments","allDayItems","items","span","eventsOnDay","dayOfSpan","dayDifference","item","touchesDays"],"sources":["../../../src/v2/events/eventModel.ts"],"sourcesContent":["/**\n * What an event is to the person looking at it (BOFF-15698 A1): whose it is, their answer,\n * whether they may change it, whether only \"Busy\" may be shown, and which views and days it\n * belongs to. Pure, so the views and their tests share one reading.\n */\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport {\n dayDifference,\n eventDays,\n instantToZoned,\n timedSegments,\n zonedTimeToInstant,\n} from '../time/calendarTime';\nimport type {\n CalendarEventV2,\n CalendarV2,\n CalendarV2EventDraft,\n EventBookingV2,\n TimedSegment,\n} from '../types';\n\nconst DAY_MS = 86_400_000;\n\n/** The person's part in an event. */\nexport type MyPart = 'organizer' | 'invited' | 'going' | 'maybe' | 'declined' | 'none';\n\n/**\n * A regular date of a repeating event (A4): the series stands behind it, and \"This event\"\n * names the date by its original start. A date moved on its own is an event of its own.\n */\nexport function isSeriesDate(\n event: Pick<CalendarEventV2, 'isRecurring' | 'seriesId' | 'instanceDate' | 'isModified'>\n): boolean {\n return (\n event.isRecurring && !event.isModified && event.seriesId !== null && event.instanceDate !== null\n );\n}\n\n/**\n * What the event dialog and Find a time open with to change an event: the stored event, and for\n * a regular date of a series the date (\"This event\" names it).\n */\nexport function editDraftFor(event: CalendarEventV2): CalendarV2EventDraft {\n return isSeriesDate(event) && event.instanceDate\n ? { eventId: event.eventId, instanceDate: event.instanceDate }\n : { eventId: event.eventId };\n}\n\n/** A date of a repeating event, as it stands or moved on its own: it shows \"Repeats\". */\nexport function inSeries(event: Pick<CalendarEventV2, 'isRecurring' | 'seriesId'>): boolean {\n return event.isRecurring || event.seriesId !== null;\n}\n\nexport function isOrganizer(event: CalendarEventV2, me: string | null): boolean {\n if (!me) return false;\n return (\n event.organizerId === me || event.guests.some((guest) => guest.organizer && guest.userId === me)\n );\n}\n\nexport function myPart(event: CalendarEventV2, me: string | null): MyPart {\n if (isOrganizer(event, me)) return 'organizer';\n switch (event.myResponse) {\n case 'NO_RESPONSE':\n return 'invited';\n case 'ACCEPTED':\n return 'going';\n case 'TENTATIVE':\n return 'maybe';\n case 'DECLINED':\n return 'declined';\n default:\n return 'none';\n }\n}\n\n/** The person's own calendar: one only they hold. */\nfunction isOwnCalendar(calendar: CalendarV2 | undefined, me: string | null): boolean {\n if (!calendar || !me || calendar.kind !== 'PERSONAL') return false;\n return (calendar.ownerUserId ?? calendar.createdBy) === me;\n}\n\n/**\n * A private or confidential event of someone else's that the person is not invited to: the\n * views show only that the time is taken (\"Busy\"), never its title, place or guests.\n */\nexport function isBusyOnly(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null\n): boolean {\n if (event.visibility === 'PUBLIC') return false;\n return myPart(event, me) === 'none' && !isOwnCalendar(calendar, me);\n}\n\n/**\n * The person may move, resize, edit and delete it: they organise it, its calendar takes\n * changes (not a calendar followed by link), and it is not someone else's private time.\n */\nexport function canEditEvent(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null\n): boolean {\n if (!calendar || calendar.isReadOnly) return false;\n if (event.status === 'CANCELLED') return false;\n return isOrganizer(event, me);\n}\n\n/**\n * Drag and keyboard moves, which keep an event inside one day of the grid. Not for:\n * - a date of a repeating event: a move would change the series' own time (every date), and a\n * date changed on its own is an event of its own that the event dialog makes, carrying its\n * guests, reminders and room; so the dialog asks which events to change. A date already\n * moved on its own is its own event and moves like one;\n * - one that runs past midnight on the calendar's clock (23:00–01:00): kept inside one day it\n * would lose its times, so it changes in the event dialog;\n * - one that starts or ends in the second pass of an hour the clocks repeat (01:30 GMT on 25\n * October 2026 in London): the grid reads a clock time as its first pass, so a move would\n * shift it by the hour.\n */\nexport function canMoveOnGrid(\n event: CalendarEventV2,\n calendar: CalendarV2 | undefined,\n me: string | null,\n timeZone: string\n): boolean {\n if (!canEditEvent(event, calendar, me) || event.isRecurring || isAllDayRow(event)) return false;\n const days = eventDays(event, timeZone);\n if (days.start !== days.end) return false;\n return readsBackOnClock(event.start, timeZone) && readsBackOnClock(event.end, timeZone);\n}\n\n/**\n * Whether an instant's clock time on `timeZone` stands for that instant again (to the minute):\n * false in the second pass of a repeated hour, which the clock time reads as the first.\n */\nexport function readsBackOnClock(instant: Date, timeZone: string): boolean {\n const zoned = instantToZoned(instant, timeZone);\n const minute = Math.floor(instant.getTime() / 60_000) * 60_000;\n return zonedTimeToInstant(zoned.date, zoned.minutes, timeZone).getTime() === minute;\n}\n\n/** Shown in the all-day row: an all-day event, or one that lasts a day or more. */\nexport function isAllDayRow(event: CalendarEventV2): boolean {\n return event.allDay || event.end.getTime() - event.start.getTime() >= DAY_MS;\n}\n\n/** The event has ended (an all-day event: its last day is before today). */\nexport function isPastEvent(event: CalendarEventV2, now: Date, timeZone: string): boolean {\n if (event.allDay) {\n const today = instantToZoned(now, timeZone).date;\n return eventDays(event, timeZone).end < today;\n }\n return event.end.getTime() <= now.getTime();\n}\n\nexport function isHappeningNow(event: CalendarEventV2, now: Date): boolean {\n if (event.allDay) return false;\n const at = now.getTime();\n return event.start.getTime() <= at && event.end.getTime() > at;\n}\n\nexport interface ShownEventsOptions {\n hiddenCalendarIds: ReadonlySet<string>;\n showDeclined: boolean;\n me: string | null;\n}\n\n/**\n * The events the views show: on a shown calendar, not cancelled, and not declined unless the\n * person asked to see those.\n */\nexport function shownEvents(\n events: readonly CalendarEventV2[],\n options: ShownEventsOptions\n): CalendarEventV2[] {\n return events.filter(\n (event) =>\n !options.hiddenCalendarIds.has(event.calendarId) &&\n event.status !== 'CANCELLED' &&\n (options.showDeclined || myPart(event, options.me) !== 'declined')\n );\n}\n\n/** Invitations still waiting for the person's answer that haven't ended, soonest first. */\nexport function waitingInvitations(\n events: readonly CalendarEventV2[],\n now: Date,\n me: string | null\n): CalendarEventV2[] {\n return events\n .filter((event) => myPart(event, me) === 'invited' && event.end.getTime() > now.getTime())\n .sort((a, b) => a.start.getTime() - b.start.getTime());\n}\n\n/** A room booking: a room, or a resource of unknown type (rooms are what events book most). */\nfunction isRoomBooking(booking: EventBookingV2): boolean {\n return booking.resourceType === 'ROOM' || booking.resourceType === null;\n}\n\n/**\n * The room an event is in: its first room booking that wasn't cancelled or turned down, else a\n * turned-down one to warn about. Other resources (equipment) never stand in for the room, so a\n * refused room still shows next to approved equipment.\n */\nexport function eventRoom(event: CalendarEventV2): EventBookingV2 | null {\n const rooms = event.bookings.filter(isRoomBooking);\n return (\n rooms.find((booking) => booking.status === 'PENDING' || booking.status === 'APPROVED') ??\n rooms.find((booking) => booking.status === 'COMPLETED') ??\n rooms.find((booking) => booking.status === 'REJECTED') ??\n null\n );\n}\n\n/** A web address that is safe to open: http or https only. */\nexport function safeWebUrl(raw: string | null | undefined): string | null {\n const value = raw?.trim();\n if (!value) return null;\n const withScheme = /^[a-z][a-z0-9+.-]*:/i.test(value) ? value : `https://${value}`;\n try {\n const url = new URL(withScheme);\n return url.protocol === 'https:' || url.protocol === 'http:' ? url.toString() : null;\n } catch {\n return null;\n }\n}\n\n/** The video call to join: the meeting link, else a location that is a web address. */\nexport function joinUrl(event: CalendarEventV2): string | null {\n return (\n safeWebUrl(event.meeting?.url) ??\n (event.locationType === 'ONLINE' ? safeWebUrl(event.locationUrl) : null)\n );\n}\n\n/** A timed event's piece on one day. */\nexport interface DaySegment<T = CalendarEventV2> extends TimedSegment {\n event: T;\n}\n\n/**\n * Timed events' pieces on each of `days`, on the clock of `timeZone`. Events shown in the\n * all-day row (`isAllDayRow`) are left out, as the grid draws them there; `includeLong` keeps\n * the timed ones of a day or more, for what is busy (all-day events never are).\n */\nexport function timedSegmentsByDay(\n events: readonly CalendarEventV2[],\n days: readonly DateValue[],\n timeZone: string,\n options: { includeLong?: boolean } = {}\n): Map<DateValue, DaySegment[]> {\n const byDay = new Map<DateValue, DaySegment[]>(days.map((day) => [day, []]));\n const first = days[0];\n const last = days[days.length - 1];\n if (!first || !last) return byDay;\n for (const event of events) {\n if (event.allDay || (!options.includeLong && isAllDayRow(event))) continue;\n for (const segment of timedSegments(event.start, event.end, timeZone, first, last)) {\n byDay.get(segment.date)?.push({ ...segment, event });\n }\n }\n return byDay;\n}\n\n/** An event in the all-day row, from its first to its last day. */\nexport interface AllDayItem<T = CalendarEventV2> {\n event: T;\n first: DateValue;\n last: DateValue;\n}\n\n/** The all-day row's events that touch `first`..`last`. */\nexport function allDayItems(\n events: readonly CalendarEventV2[],\n first: DateValue,\n last: DateValue,\n timeZone: string\n): AllDayItem[] {\n const items: AllDayItem[] = [];\n for (const event of events) {\n if (!isAllDayRow(event)) continue;\n const span = eventDays(event, timeZone);\n if (span.end < first || span.start > last) continue;\n items.push({ event, first: span.start, last: span.end });\n }\n return items;\n}\n\n/**\n * The events on one day, for a day's list (Month's \"+N more\", phones' Month, the List view):\n * every event that touches the day (one over midnight on both its days, as the grid shows\n * it), all-day ones first, then by start.\n */\nexport function eventsOnDay(\n events: readonly CalendarEventV2[],\n day: DateValue,\n timeZone: string\n): CalendarEventV2[] {\n return events\n .filter((event) => {\n const span = eventDays(event, timeZone);\n return span.start <= day && span.end >= day;\n })\n .sort(\n (a, b) =>\n Number(isAllDayRow(b)) - Number(isAllDayRow(a)) ||\n a.start.getTime() - b.start.getTime() ||\n a.title.localeCompare(b.title)\n );\n}\n\n/** Which of an all-day item's days `day` is: 1 for its first. */\nexport function dayOfSpan(item: { first: DateValue }, day: DateValue): number {\n return dayDifference(item.first, day) + 1;\n}\n\n/** Whether an event falls on any of `days` (sorted), on the clock of `timeZone`. */\nexport function touchesDays(\n event: CalendarEventV2,\n days: ReadonlySet<DateValue>,\n first: DateValue,\n last: DateValue,\n timeZone: string\n): boolean {\n const span = eventDays(event, timeZone);\n if (span.end < first || span.start > last) return false;\n for (const day of days) if (day >= span.start && day <= span.end) return true;\n return false;\n}\n"],"mappings":";;AAqBA,IAAMA,IAAS;AASf,SAAgBC,EACd,GACS;CACT,OACEC,EAAM,eAAe,CAACA,EAAM,cAAcA,EAAM,aAAa,QAAQA,EAAM,iBAAiB;AAEhG;AAMA,SAAgBC,EAAa,GAA8C;CACzE,OAAOF,EAAaC,CAAK,KAAKA,EAAM,eAChC;EAAE,SAASA,EAAM;EAAS,cAAcA,EAAM;CAAa,IAC3D,EAAE,SAASA,EAAM,QAAQ;AAC/B;AAGA,SAAgBE,EAAS,GAAmE;CAC1F,OAAOF,EAAM,eAAeA,EAAM,aAAa;AACjD;AAEA,SAAgBG,EAAY,GAAwB,GAA4B;CAE9E,OADKC,IAEHJ,EAAM,gBAAgBI,KAAMJ,EAAM,OAAO,MAAM,MAAUK,EAAM,aAAaA,EAAM,WAAWD,CAAE,IAFjF;AAIlB;AAEA,SAAgBE,EAAO,GAAwB,GAA2B;CACxE,IAAIH,EAAYH,GAAOI,CAAE,GAAG,OAAO;CACnC,QAAQJ,EAAM,YAAd;EACE,KAAK,eACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAGA,SAASO,EAAc,GAAkC,GAA4B;CAEnF,OADI,CAACC,KAAY,CAACJ,KAAMI,EAAS,SAAS,aAAmB,MACrDA,EAAS,eAAeA,EAAS,eAAeJ;AAC1D;AAMA,SAAgBK,EACd,GACA,GACA,GACS;CAET,OADIT,EAAM,eAAe,YAClBM,EAAON,GAAOI,CAAE,MAAM,UAAU,CAACG,EAAcC,GAAUJ,CAAE;AACpE;AAMA,SAAgBM,EACd,GACA,GACA,GACS;CAGT,OAFI,CAACF,KAAYA,EAAS,cACtBR,EAAM,WAAW,cAAoB,KAClCG,EAAYH,GAAOI,CAAE;AAC9B;AAcA,SAA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AASM,EAAK,QAAQL,GAAM,OAAO;CAClD,KAAK,IAAMF,KAAOhC,GAAM,IAAIgC,KAAOO,EAAK,SAASP,KAAOO,EAAK,KAAK,OAAO;CACzE,OAAO;AACT"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { EventActions } from '../data/useEventActions';
|
|
2
2
|
import { CalendarEventV2 } from '../types';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Events with the changes made here laid over them: moved, answered, or deleted (one date, or a
|
|
5
|
+
* whole series by its id). An answer is the event's, so every date of a series shows it.
|
|
6
|
+
*/
|
|
4
7
|
export declare function withLocalChanges(events: readonly CalendarEventV2[], actions: Pick<EventActions, 'overrides' | 'removedIds' | 'answers'>, me: string | null): CalendarEventV2[];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/v2/events/localChanges.ts
|
|
2
2
|
function e(e, t, n) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
if (t.overrides.size === 0 && t.removedIds.size === 0 && t.answers.size === 0) return [...e];
|
|
4
|
+
let r = t.removedIds;
|
|
5
|
+
return e.filter((e) => !r.has(e.id) && !(e.seriesId !== null && r.has(e.seriesId))).map((e) => {
|
|
6
|
+
let r = t.overrides.get(e.id), i = t.answers.get(e.eventId);
|
|
5
7
|
return !r && !i ? e : {
|
|
6
8
|
...e,
|
|
7
9
|
...r ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localChanges.js","names":["withLocalChanges","actions","events","event","times","answer","guest","me"],"sources":["../../../src/v2/events/localChanges.ts"],"sourcesContent":["/**\n * The changes made on this page that the service hasn't sent back yet (BOFF-15698 A1): moved\n * events show at their new times, answers as given, deleted events not at all. The views and\n * search lay them over what they loaded, so both agree until the next reload.\n */\nimport type { EventActions } from '../data/useEventActions';\nimport type { CalendarEventV2 } from '../types';\n\n
|
|
1
|
+
{"version":3,"file":"localChanges.js","names":["withLocalChanges","actions","events","removed","event","times","answer","guest","me"],"sources":["../../../src/v2/events/localChanges.ts"],"sourcesContent":["/**\n * The changes made on this page that the service hasn't sent back yet (BOFF-15698 A1): moved\n * events show at their new times, answers as given, deleted events not at all. The views and\n * search lay them over what they loaded, so both agree until the next reload.\n */\nimport type { EventActions } from '../data/useEventActions';\nimport type { CalendarEventV2 } from '../types';\n\n/**\n * Events with the changes made here laid over them: moved, answered, or deleted (one date, or a\n * whole series by its id). An answer is the event's, so every date of a series shows it.\n */\nexport function withLocalChanges(\n events: readonly CalendarEventV2[],\n actions: Pick<EventActions, 'overrides' | 'removedIds' | 'answers'>,\n me: string | null\n): CalendarEventV2[] {\n if (actions.overrides.size === 0 && actions.removedIds.size === 0 && actions.answers.size === 0) {\n return [...events];\n }\n const removed = actions.removedIds;\n return events\n .filter(\n (event) => !removed.has(event.id) && !(event.seriesId !== null && removed.has(event.seriesId))\n )\n .map((event) => {\n const times = actions.overrides.get(event.id);\n const answer = actions.answers.get(event.eventId);\n if (!times && !answer) return event;\n return {\n ...event,\n ...(times ? { start: times.start, end: times.end } : {}),\n ...(answer\n ? {\n myResponse: answer,\n guests: event.guests.map((guest) =>\n guest.userId === me ? { ...guest, response: answer } : guest\n ),\n }\n : {}),\n };\n });\n}\n"],"mappings":";AAYA,SAAgBA,EACd,GACA,GACA,GACmB;CACnB,IAAIC,EAAQ,UAAU,SAAS,KAAKA,EAAQ,WAAW,SAAS,KAAKA,EAAQ,QAAQ,SAAS,GAC5F,OAAO,CAAC,GAAGC,CAAM;CAEnB,IAAMC,IAAUF,EAAQ;CACxB,OAAOC,EACJ,QACE,MAAU,CAACC,EAAQ,IAAIC,EAAM,EAAE,KAAK,EAAEA,EAAM,aAAa,QAAQD,EAAQ,IAAIC,EAAM,QAAQ,EAC9F,CAAC,CACA,KAAK,MAAU;EACd,IAAMC,IAAQJ,EAAQ,UAAU,IAAIG,EAAM,EAAE,GACtCE,IAASL,EAAQ,QAAQ,IAAIG,EAAM,OAAO;EAEhD,OADI,CAACC,KAAS,CAACC,IAAeF,IACvB;GACL,GAAGA;GACH,GAAIC,IAAQ;IAAE,OAAOA,EAAM;IAAO,KAAKA,EAAM;GAAI,IAAI,CAAC;GACtD,GAAIC,IACA;IACE,YAAYA;IACZ,QAAQF,EAAM,OAAO,KAAK,MACxBG,EAAM,WAAWC,IAAK;KAAE,GAAGD;KAAO,UAAUD;IAAO,IAAIC,CACzD;GACF,IACA,CAAC;EACP;CACF,CAAC;AACL"}
|
package/dist/v2/format.d.ts
CHANGED
package/dist/v2/format.js
CHANGED
package/dist/v2/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":["resolveCalendarLocale","appLocale","deviceLanguages","language","tag","formats","dayFormat","key","locale","options","format","utcMidnight","parts","parseDateValue","date","DAY_STYLES","formatDay","style","formatDaySpan","withYear","formatter","first","last","formatMinutes","wrapped","minutes","formatTimeOfDay","formatMinuteRange","start","end","formatInstantTime","instantToZoned","instant","timeZone","formatInstantRange","formatDayTimeSpan","at","zoned","formatDuration","rounded","totalMinutes","hours","template","words"],"sources":["../../src/v2/format.ts"],"sourcesContent":["/**\n * How the redesigned calendar writes days and times (BOFF-15698 A1): in the person's locale,\n * on their clock (24-hour unless they pick 12-hour in Calendar settings).\n *\n * - The locale is the app's language with this device's region when the device speaks that\n * language (\"en\" in a British browser writes \"Fri 20 Nov\", in an American one \"Fri, Nov 20\").\n * - A day is a floating `YYYY-MM-DD`, written at its UTC midnight with `timeZone: 'UTC'`, so it\n * never reads as the day before or after.\n * - A time is minutes after midnight on the calendar's clock (`instantToZoned`), written with\n * fe-libs' `formatTimeOfDay`.\n */\nimport {\n formatTimeOfDay,\n parseDateValue,\n type DateValue,\n type HourCycle,\n} from '@burdenoff/fe-libs/ui';\nimport { instantToZoned } from './time/calendarTime';\n\nexport interface CalendarFormat {\n /** A BCP 47 tag (\"en-GB\"), or undefined for the runtime's. */\n locale: string | undefined;\n hourCycle: HourCycle;\n}\n\n/**\n * The locale the calendar writes in: the first of the device's languages that is the app's\n * language (so its region decides the order of day and month), else the app's language.\n */\nexport function resolveCalendarLocale(\n appLocale: string | undefined,\n deviceLanguages: readonly string[]\n): string | undefined {\n if (!appLocale) return deviceLanguages[0];\n const language = appLocale.toLowerCase().split(/[-_]/)[0];\n const regional = deviceLanguages.find(\n (tag) => tag.toLowerCase().split(/[-_]/)[0] === language && tag.includes('-')\n );\n return regional ?? appLocale;\n}\n\nconst formats = new Map<string, Intl.DateTimeFormat>();\n\nfunction dayFormat(\n locale: string | undefined,\n options: Intl.DateTimeFormatOptions\n): Intl.DateTimeFormat {\n const key = `${locale ?? ''}|${JSON.stringify(options)}`;\n let format = formats.get(key);\n if (!format) {\n try {\n format = new Intl.DateTimeFormat(locale, { ...options, timeZone: 'UTC' });\n } catch {\n format = new Intl.DateTimeFormat(undefined, { ...options, timeZone: 'UTC' });\n }\n formats.set(key, format);\n }\n return format;\n}\n\n/** The UTC midnight of a day, for `Intl` with `timeZone: 'UTC'`. */\nexport function utcMidnight(date: DateValue): Date {\n const parts = parseDateValue(date);\n if (!parts) return new Date(Number.NaN);\n return new Date(Date.UTC(parts.year, parts.month - 1, parts.day));\n}\n\nexport type DayStyle =\n /** \"Fri 20 Nov\" */\n | 'short'\n /** \"Friday 20 Nov\" */\n | 'mid'\n /** \"Friday 20 November\" */\n | 'long'\n /** \"Friday 20 November 2026\" */\n | 'full'\n /** \"20 Nov 2026\" */\n | 'date'\n /** \"Fri\" */\n | 'weekday'\n /** \"Friday\" */\n | 'weekdayLong'\n /** \"20\" */\n | 'dayNumber'\n /** \"Nov\" */\n | 'monthShort'\n /** \"November 2026\" */\n | 'monthYear'\n /** \"Nov 2026\" */\n | 'monthYearShort';\n\nconst DAY_STYLES: Readonly<Record<DayStyle, Intl.DateTimeFormatOptions>> = {\n short: { weekday: 'short', day: 'numeric', month: 'short' },\n mid: { weekday: 'long', day: 'numeric', month: 'short' },\n long: { weekday: 'long', day: 'numeric', month: 'long' },\n full: { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' },\n date: { day: 'numeric', month: 'short', year: 'numeric' },\n weekday: { weekday: 'short' },\n weekdayLong: { weekday: 'long' },\n dayNumber: { day: 'numeric' },\n monthShort: { month: 'short' },\n monthYear: { month: 'long', year: 'numeric' },\n monthYearShort: { month: 'short', year: 'numeric' },\n};\n\n/** A day in the locale; commas the locale puts between weekday and day are kept. */\nexport function formatDay(date: DateValue, format: CalendarFormat, style: DayStyle): string {\n return dayFormat(format.locale, DAY_STYLES[style]).format(utcMidnight(date));\n}\n\n/**\n * Two days as the locale writes a range: \"16–22 Nov 2026\", \"30 Nov – 6 Dec 2026\",\n * \"28 Dec 2026 – 3 Jan 2027\". `withYear: false` leaves the year out (phones).\n */\nexport function formatDaySpan(\n first: DateValue,\n last: DateValue,\n format: CalendarFormat,\n withYear = true\n): string {\n const options: Intl.DateTimeFormatOptions = withYear\n ? { day: 'numeric', month: 'short', year: 'numeric' }\n : { day: 'numeric', month: 'short' };\n const formatter = dayFormat(format.locale, options);\n if (first === last) return formatter.format(utcMidnight(first));\n return formatter.formatRange(utcMidnight(first), utcMidnight(last));\n}\n\n/** A time of day, `minutes` after midnight (1440 reads as midnight). */\nexport function formatMinutes(minutes: number, format: CalendarFormat): string {\n const wrapped = ((Math.round(minutes) % 1440) + 1440) % 1440;\n return formatTimeOfDay(wrapped, format.locale, format.hourCycle);\n}\n\n/** \"10:15 – 11:15\". */\nexport function formatMinuteRange(start: number, end: number, format: CalendarFormat): string {\n return `${formatMinutes(start, format)} – ${formatMinutes(end, format)}`;\n}\n\n/** The time an instant shows on the clock of `timeZone`. */\nexport function formatInstantTime(instant: Date, timeZone: string, format: CalendarFormat): string {\n return formatMinutes(instantToZoned(instant, timeZone).minutes, format);\n}\n\n/** \"10:15 – 11:15\", both ends on the clock of `timeZone`. */\nexport function formatInstantRange(\n start: Date,\n end: Date,\n timeZone: string,\n format: CalendarFormat\n): string {\n return `${formatInstantTime(start, timeZone, format)} – ${formatInstantTime(end, timeZone, format)}`;\n}\n\n/**\n * A timed span over more than one day, with its days: \"Mon 16 Nov, 10:00 – Tue 17 Nov, 10:00\",\n * both ends on the clock of `timeZone`.\n */\nexport function formatDayTimeSpan(\n start: Date,\n end: Date,\n timeZone: string,\n format: CalendarFormat\n): string {\n const at = (instant: Date) => {\n const zoned = instantToZoned(instant, timeZone);\n return `${formatDay(zoned.date, format, 'short')}, ${formatMinutes(zoned.minutes, format)}`;\n };\n return `${at(start)} – ${at(end)}`;\n}\n\n/** The words of a length of time, already translated by the caller. */\nexport interface DurationWords {\n /** \"{{minutes}} min\" */\n minutes: string;\n /** \"{{hours}} h\" */\n hours: string;\n /** \"{{hours}} h {{minutes}} min\" */\n hoursMinutes: string;\n}\n\n/** \"45 min\", \"1 h\", \"2 h 30 min\". */\nexport function formatDuration(totalMinutes: number, words: DurationWords): string {\n const rounded = Math.max(0, Math.round(totalMinutes));\n const hours = Math.floor(rounded / 60);\n const minutes = rounded % 60;\n const fill = (template: string) =>\n template.replace('{{hours}}', String(hours)).replace('{{minutes}}', String(minutes));\n if (hours === 0) return fill(words.minutes);\n return minutes === 0 ? fill(words.hours) : fill(words.hoursMinutes);\n}\n"],"mappings":";;;AA6BA,SAAgBA,EACd,GACA,GACoB;CACpB,IAAI,CAACC,GAAW,OAAOC,EAAgB;CACvC,IAAMC,IAAWF,EAAU,YAAY,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC;CAIvD,OAHiBC,EAAgB,MAC9B,MAAQE,EAAI,YAAY,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,OAAOD,KAAYC,EAAI,SAAS,GAAG,CAEvE,KAAYH;AACrB;AAEA,IAAMI,oBAAU,IAAI,IAAiC;AAErD,SAASC,EACP,GACA,GACqB;CACrB,IAAMC,IAAM,GAAGC,KAAU,GAAG,GAAG,KAAK,UAAUC,CAAO,KACjDC,IAASL,EAAQ,IAAIE,CAAG;CAC5B,IAAI,CAACG,GAAQ;EACX,IAAI;GACF,IAAS,IAAI,KAAK,eAAeF,GAAQ;I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,MAAU,IAAeE,EAAM,UAC5BlB,MAAY,IAASkB,EAAM,QAAcA,EAAM,YADZ;AAE5C"}
|
|
1
|
+
{"version":3,"file":"format.js","names":["resolveCalendarLocale","appLocale","deviceLanguages","language","tag","formats","dayFormat","key","locale","options","format","utcMidnight","parts","parseDateValue","date","DAY_STYLES","formatDay","style","formatDaySpan","withYear","formatter","first","last","formatMinutes","wrapped","minutes","formatTimeOfDay","formatMinuteRange","start","end","formatInstantTime","instantToZoned","instant","timeZone","formatInstantRange","formatDayTimeSpan","at","zoned","formatDuration","rounded","totalMinutes","hours","template","words"],"sources":["../../src/v2/format.ts"],"sourcesContent":["/**\n * How the redesigned calendar writes days and times (BOFF-15698 A1): in the person's locale,\n * on their clock (24-hour unless they pick 12-hour in Calendar settings).\n *\n * - The locale is the app's language with this device's region when the device speaks that\n * language (\"en\" in a British browser writes \"Fri 20 Nov\", in an American one \"Fri, Nov 20\").\n * - A day is a floating `YYYY-MM-DD`, written at its UTC midnight with `timeZone: 'UTC'`, so it\n * never reads as the day before or after.\n * - A time is minutes after midnight on the calendar's clock (`instantToZoned`), written with\n * fe-libs' `formatTimeOfDay`.\n */\nimport {\n formatTimeOfDay,\n parseDateValue,\n type DateValue,\n type HourCycle,\n} from '@burdenoff/fe-libs/ui';\nimport { instantToZoned } from './time/calendarTime';\n\nexport interface CalendarFormat {\n /** A BCP 47 tag (\"en-GB\"), or undefined for the runtime's. */\n locale: string | undefined;\n hourCycle: HourCycle;\n}\n\n/**\n * The locale the calendar writes in: the first of the device's languages that is the app's\n * language (so its region decides the order of day and month), else the app's language.\n */\nexport function resolveCalendarLocale(\n appLocale: string | undefined,\n deviceLanguages: readonly string[]\n): string | undefined {\n if (!appLocale) return deviceLanguages[0];\n const language = appLocale.toLowerCase().split(/[-_]/)[0];\n const regional = deviceLanguages.find(\n (tag) => tag.toLowerCase().split(/[-_]/)[0] === language && tag.includes('-')\n );\n return regional ?? appLocale;\n}\n\nconst formats = new Map<string, Intl.DateTimeFormat>();\n\nfunction dayFormat(\n locale: string | undefined,\n options: Intl.DateTimeFormatOptions\n): Intl.DateTimeFormat {\n const key = `${locale ?? ''}|${JSON.stringify(options)}`;\n let format = formats.get(key);\n if (!format) {\n try {\n format = new Intl.DateTimeFormat(locale, { ...options, timeZone: 'UTC' });\n } catch {\n format = new Intl.DateTimeFormat(undefined, { ...options, timeZone: 'UTC' });\n }\n formats.set(key, format);\n }\n return format;\n}\n\n/** The UTC midnight of a day, for `Intl` with `timeZone: 'UTC'`. */\nexport function utcMidnight(date: DateValue): Date {\n const parts = parseDateValue(date);\n if (!parts) return new Date(Number.NaN);\n return new Date(Date.UTC(parts.year, parts.month - 1, parts.day));\n}\n\nexport type DayStyle =\n /** \"Fri 20 Nov\" */\n | 'short'\n /** \"Friday 20 Nov\" */\n | 'mid'\n /** \"Friday 20 November\" */\n | 'long'\n /** \"Friday 20 November 2026\" */\n | 'full'\n /** \"20 Nov 2026\" */\n | 'date'\n /** \"20 November\" */\n | 'dayMonth'\n /** \"Fri\" */\n | 'weekday'\n /** \"Friday\" */\n | 'weekdayLong'\n /** \"20\" */\n | 'dayNumber'\n /** \"Nov\" */\n | 'monthShort'\n /** \"November 2026\" */\n | 'monthYear'\n /** \"Nov 2026\" */\n | 'monthYearShort';\n\nconst DAY_STYLES: Readonly<Record<DayStyle, Intl.DateTimeFormatOptions>> = {\n short: { weekday: 'short', day: 'numeric', month: 'short' },\n mid: { weekday: 'long', day: 'numeric', month: 'short' },\n long: { weekday: 'long', day: 'numeric', month: 'long' },\n full: { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' },\n date: { day: 'numeric', month: 'short', year: 'numeric' },\n dayMonth: { day: 'numeric', month: 'long' },\n weekday: { weekday: 'short' },\n weekdayLong: { weekday: 'long' },\n dayNumber: { day: 'numeric' },\n monthShort: { month: 'short' },\n monthYear: { month: 'long', year: 'numeric' },\n monthYearShort: { month: 'short', year: 'numeric' },\n};\n\n/** A day in the locale; commas the locale puts between weekday and day are kept. */\nexport function formatDay(date: DateValue, format: CalendarFormat, style: DayStyle): string {\n return dayFormat(format.locale, DAY_STYLES[style]).format(utcMidnight(date));\n}\n\n/**\n * Two days as the locale writes a range: \"16–22 Nov 2026\", \"30 Nov – 6 Dec 2026\",\n * \"28 Dec 2026 – 3 Jan 2027\". `withYear: false` leaves the year out (phones).\n */\nexport function formatDaySpan(\n first: DateValue,\n last: DateValue,\n format: CalendarFormat,\n withYear = true\n): string {\n const options: Intl.DateTimeFormatOptions = withYear\n ? { day: 'numeric', month: 'short', year: 'numeric' }\n : { day: 'numeric', month: 'short' };\n const formatter = dayFormat(format.locale, options);\n if (first === last) return formatter.format(utcMidnight(first));\n return formatter.formatRange(utcMidnight(first), utcMidnight(last));\n}\n\n/** A time of day, `minutes` after midnight (1440 reads as midnight). */\nexport function formatMinutes(minutes: number, format: CalendarFormat): string {\n const wrapped = ((Math.round(minutes) % 1440) + 1440) % 1440;\n return formatTimeOfDay(wrapped, format.locale, format.hourCycle);\n}\n\n/** \"10:15 – 11:15\". */\nexport function formatMinuteRange(start: number, end: number, format: CalendarFormat): string {\n return `${formatMinutes(start, format)} – ${formatMinutes(end, format)}`;\n}\n\n/** The time an instant shows on the clock of `timeZone`. */\nexport function formatInstantTime(instant: Date, timeZone: string, format: CalendarFormat): string {\n return formatMinutes(instantToZoned(instant, timeZone).minutes, format);\n}\n\n/** \"10:15 – 11:15\", both ends on the clock of `timeZone`. */\nexport function formatInstantRange(\n start: Date,\n end: Date,\n timeZone: string,\n format: CalendarFormat\n): string {\n return `${formatInstantTime(start, timeZone, format)} – ${formatInstantTime(end, timeZone, format)}`;\n}\n\n/**\n * A timed span over more than one day, with its days: \"Mon 16 Nov, 10:00 – Tue 17 Nov, 10:00\",\n * both ends on the clock of `timeZone`.\n */\nexport function formatDayTimeSpan(\n start: Date,\n end: Date,\n timeZone: string,\n format: CalendarFormat\n): string {\n const at = (instant: Date) => {\n const zoned = instantToZoned(instant, timeZone);\n return `${formatDay(zoned.date, format, 'short')}, ${formatMinutes(zoned.minutes, format)}`;\n };\n return `${at(start)} – ${at(end)}`;\n}\n\n/** The words of a length of time, already translated by the caller. */\nexport interface DurationWords {\n /** \"{{minutes}} min\" */\n minutes: string;\n /** \"{{hours}} h\" */\n hours: string;\n /** \"{{hours}} h {{minutes}} min\" */\n hoursMinutes: string;\n}\n\n/** \"45 min\", \"1 h\", \"2 h 30 min\". */\nexport function formatDuration(totalMinutes: number, words: DurationWords): string {\n const rounded = Math.max(0, Math.round(totalMinutes));\n const hours = Math.floor(rounded / 60);\n const minutes = rounded % 60;\n const fill = (template: string) =>\n template.replace('{{hours}}', String(hours)).replace('{{minutes}}', String(minutes));\n if (hours === 0) return fill(words.minutes);\n return minutes === 0 ? fill(words.hours) : fill(words.hoursMinutes);\n}\n"],"mappings":";;;AA6BA,SAAgBA,EACd,GACA,GACoB;CACpB,IAAI,CAACC,GAAW,OAAOC,EAAgB;CACvC,IAAMC,IAAWF,EAAU,YAAY,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC;CAIvD,OAHiBC,EAAgB,MAC9B,MAAQE,EAAI,YAAY,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,OAAOD,KAAYC,EAAI,SAAS,GAAG,CAEvE,KAAYH;AACrB;AAEA,IAAMI,oBAAU,IAAI,IAAiC;AAErD,SAASC,EACP,GACA,GACqB;CACrB,IAAMC,IAAM,GAAGC,KAAU,GAAG,GAAG,KAAK,UAAUC,CAAO,KACjDC,IAASL,EAAQ,IAAIE,CAAG;CAC5B,IAAI,CAACG,GAAQ;EACX,IAAI;GACF,IAAS,IAAI,KAAK,eAAeF,GAAQ;IAAE,GAAGC;IAAS,UAAU;GAAM,CAAC;EAC1E,QAAQ;GACN,IAAS,IAAI,KAAK,eAAe,KAAA,GAAW;IAAE,GAAGA;IAAS,UAAU;GAAM,CAAC;EAC7E;EACA,EAAQ,IAAIF,GAAKG,CAAM;CACzB;CACA,OAAOA;AACT;AAGA,SAAgBC,EAAY,GAAuB;CACj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what it should show. */
|
|
82
82
|
openEventDialog: (draft: CalendarV2EventDraft) => void;
|
|
83
|
-
/** Opens Find a time (A2), for an event when given (moving it). */
|
|
84
|
-
openFindTime: (
|
|
83
|
+
/** Opens Find a time (A2), for an event when given (moving it: one date of a series, A4). */
|
|
84
|
+
openFindTime: (event?: CalendarEventV2) => void;
|
|
85
85
|
railSheetOpen: boolean;
|
|
86
86
|
setRailSheetOpen: (open: boolean) => void;
|
|
87
87
|
/** Phones: the search field shows under the toolbar. */
|