@rokoyfa/calendar 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/DEVELOPER_GUIDE.md +743 -0
  3. package/README.md +39 -108
  4. package/api/openapi.yaml +359 -3
  5. package/demo/calendar.config.jsonc +149 -0
  6. package/demo/calendar.config.yaml +146 -0
  7. package/dist-lib/cdn/browser-BSbYkIQu.js +130 -0
  8. package/dist-lib/cdn/browser-BSbYkIQu.js.map +1 -0
  9. package/dist-lib/cdn/calendar-widget.js +12 -7
  10. package/dist-lib/cdn/calendar-widget.js.map +1 -1
  11. package/dist-lib/cdn/de-CjkGEfiE.js +2 -0
  12. package/dist-lib/cdn/de-CjkGEfiE.js.map +1 -0
  13. package/dist-lib/cdn/es-BrMRh6bn.js +2 -0
  14. package/dist-lib/cdn/es-BrMRh6bn.js.map +1 -0
  15. package/dist-lib/cdn/fr-Ckr8Uxxd.js +2 -0
  16. package/dist-lib/cdn/fr-Ckr8Uxxd.js.map +1 -0
  17. package/dist-lib/cdn/it-_2BGklYa.js +2 -0
  18. package/dist-lib/cdn/it-_2BGklYa.js.map +1 -0
  19. package/dist-lib/cdn/nl-BykoYBK7.js +2 -0
  20. package/dist-lib/cdn/nl-BykoYBK7.js.map +1 -0
  21. package/dist-lib/cdn/pl-as7f_-F8.js +2 -0
  22. package/dist-lib/cdn/pl-as7f_-F8.js.map +1 -0
  23. package/dist-lib/cdn/pt-BWJIdrI6.js +2 -0
  24. package/dist-lib/cdn/pt-BWJIdrI6.js.map +1 -0
  25. package/dist-lib/cdn/rolldown-runtime-CrjiCqGf.js +1 -0
  26. package/dist-lib/cdn/src-l8Q4aJRr.js +12 -0
  27. package/dist-lib/cdn/src-l8Q4aJRr.js.map +1 -0
  28. package/dist-lib/npm/{de-CCzGjeTd.js → de-lDO0Tv9y.js} +135 -8
  29. package/dist-lib/npm/de-lDO0Tv9y.js.map +1 -0
  30. package/dist-lib/npm/{es-Ciaf66rH.js → es-Cy3Mmj9C.js} +135 -8
  31. package/dist-lib/npm/es-Cy3Mmj9C.js.map +1 -0
  32. package/dist-lib/npm/{fr-CAqNm10Z.js → fr-Ci0ZM0nG.js} +135 -8
  33. package/dist-lib/npm/fr-Ci0ZM0nG.js.map +1 -0
  34. package/dist-lib/npm/index.js +6012 -2564
  35. package/dist-lib/npm/index.js.map +1 -1
  36. package/dist-lib/npm/{it-Cqqdu2ua.js → it-BiTHjgzI.js} +135 -8
  37. package/dist-lib/npm/it-BiTHjgzI.js.map +1 -0
  38. package/dist-lib/npm/{nl-CkchSA8q.js → nl-DZTwpAwV.js} +135 -8
  39. package/dist-lib/npm/nl-DZTwpAwV.js.map +1 -0
  40. package/dist-lib/npm/{pl-CCBDUr8k.js → pl-DeWLtyMR.js} +135 -8
  41. package/dist-lib/npm/pl-DeWLtyMR.js.map +1 -0
  42. package/dist-lib/npm/{pt-DucaCaoY.js → pt-CaqSW5TJ.js} +135 -8
  43. package/dist-lib/npm/pt-CaqSW5TJ.js.map +1 -0
  44. package/dist-lib/npm/types/components/Button.d.ts +1 -1
  45. package/dist-lib/npm/types/components/Icons.d.ts +5 -0
  46. package/dist-lib/npm/types/components/SegmentedControl.d.ts +2 -2
  47. package/dist-lib/npm/types/components/SegmentedField.d.ts +2 -11
  48. package/dist-lib/npm/types/components/StatusMessage.d.ts +0 -1
  49. package/dist-lib/npm/types/components/Tabs.d.ts +3 -1
  50. package/dist-lib/npm/types/config/routes.d.ts +1 -1
  51. package/dist-lib/npm/types/context/HostContext.d.ts +26 -3
  52. package/dist-lib/npm/types/context/TimeZoneContext.d.ts +3 -0
  53. package/dist-lib/npm/types/data/restDataSource.d.ts +5 -1
  54. package/dist-lib/npm/types/data/tenantDataSource.d.ts +4 -1
  55. package/dist-lib/npm/types/data/types.d.ts +3 -1
  56. package/dist-lib/npm/types/features/authorization/hooks/useAuth.d.ts +2 -1
  57. package/dist-lib/npm/types/features/authorization/hooks/useRedirectTarget.d.ts +4 -0
  58. package/dist-lib/npm/types/features/authorization/index.d.ts +1 -1
  59. package/dist-lib/npm/types/features/authorization/repositories/HostTokenAuthRepository.d.ts +2 -0
  60. package/dist-lib/npm/types/features/authorization/repositories/RemoteAuthRepository.d.ts +2 -0
  61. package/dist-lib/npm/types/features/authorization/types/auth.d.ts +3 -0
  62. package/dist-lib/npm/types/features/calendar/components/Calendar.d.ts +14 -1
  63. package/dist-lib/npm/types/features/calendar/components/CalendarHeader.d.ts +2 -1
  64. package/dist-lib/npm/types/features/calendar/components/DayColumn.d.ts +2 -1
  65. package/dist-lib/npm/types/features/calendar/components/EventLinks.d.ts +7 -0
  66. package/dist-lib/npm/types/features/calendar/components/EventLocation.d.ts +3 -0
  67. package/dist-lib/npm/types/features/calendar/components/EventSearchModal.d.ts +9 -0
  68. package/dist-lib/npm/types/features/calendar/components/EventTitle.d.ts +2 -1
  69. package/dist-lib/npm/types/features/calendar/components/MiniMonth.d.ts +2 -1
  70. package/dist-lib/npm/types/features/calendar/components/UndoNotice.d.ts +7 -0
  71. package/dist-lib/npm/types/features/calendar/constants/views.d.ts +4 -1
  72. package/dist-lib/npm/types/features/calendar/context/CurrentUserContext.d.ts +3 -0
  73. package/dist-lib/npm/types/features/calendar/context/HolidaysContext.d.ts +4 -0
  74. package/dist-lib/npm/types/features/calendar/hooks/useAttendeeCandidates.d.ts +3 -0
  75. package/dist-lib/npm/types/features/calendar/hooks/useEventDrag.d.ts +1 -1
  76. package/dist-lib/npm/types/features/calendar/hooks/useEventSearch.d.ts +7 -0
  77. package/dist-lib/npm/types/features/calendar/hooks/useEventSource.d.ts +2 -1
  78. package/dist-lib/npm/types/features/calendar/hooks/usePressDrag.d.ts +23 -0
  79. package/dist-lib/npm/types/features/calendar/hooks/useSegmentAttributes.d.ts +15 -0
  80. package/dist-lib/npm/types/features/calendar/hooks/useSlotSelection.d.ts +1 -4
  81. package/dist-lib/npm/types/features/calendar/index.d.ts +1 -2
  82. package/dist-lib/npm/types/features/calendar/types/editor.d.ts +3 -0
  83. package/dist-lib/npm/types/features/calendar/types/view.d.ts +1 -1
  84. package/dist-lib/npm/types/features/calendar/utils/eventDrag.d.ts +0 -1
  85. package/dist-lib/npm/types/features/calendar/utils/eventLabels.d.ts +0 -3
  86. package/dist-lib/npm/types/features/calendar/utils/search.d.ts +11 -0
  87. package/dist-lib/npm/types/features/calendars/components/ShowInPersonalSwitch.d.ts +4 -0
  88. package/dist-lib/npm/types/features/calendars/components/settings/ExchangeSection.d.ts +4 -0
  89. package/dist-lib/npm/types/features/calendars/components/settings/SubscribeSection.d.ts +4 -0
  90. package/dist-lib/npm/types/features/calendars/context/CalendarsProvider.d.ts +2 -1
  91. package/dist-lib/npm/types/features/calendars/index.d.ts +2 -2
  92. package/dist-lib/npm/types/features/calendars/repositories/LocalCalendarRepository.d.ts +12 -1
  93. package/dist-lib/npm/types/features/calendars/repositories/RemoteCalendarRepository.d.ts +3 -0
  94. package/dist-lib/npm/types/features/calendars/types/calendar.d.ts +5 -1
  95. package/dist-lib/npm/types/features/calendars/utils/activeCalendarStorage.d.ts +2 -0
  96. package/dist-lib/npm/types/features/calendars/utils/permissions.d.ts +1 -2
  97. package/dist-lib/npm/types/features/chat/components/ChatPanel.d.ts +8 -0
  98. package/dist-lib/npm/types/features/chat/components/ChatProvider.d.ts +13 -0
  99. package/dist-lib/npm/types/features/chat/components/UnreadBadge.d.ts +4 -0
  100. package/dist-lib/npm/types/features/chat/context/ChatContext.d.ts +14 -0
  101. package/dist-lib/npm/types/features/chat/hooks/useChatMessages.d.ts +13 -0
  102. package/dist-lib/npm/types/features/chat/hooks/useChatUnread.d.ts +7 -0
  103. package/dist-lib/npm/types/features/chat/index.d.ts +4 -0
  104. package/dist-lib/npm/types/features/chat/utils/time.d.ts +2 -0
  105. package/dist-lib/npm/types/features/events/components/AttendeesField.d.ts +15 -0
  106. package/dist-lib/npm/types/features/events/components/EventModal.d.ts +19 -3
  107. package/dist-lib/npm/types/features/events/components/LinksField.d.ts +8 -0
  108. package/dist-lib/npm/types/features/events/components/ReminderField.d.ts +6 -0
  109. package/dist-lib/npm/types/features/events/hooks/useEvents.d.ts +6 -3
  110. package/dist-lib/npm/types/features/events/index.d.ts +3 -1
  111. package/dist-lib/npm/types/features/events/utils/icalExchange.d.ts +11 -0
  112. package/dist-lib/npm/types/features/events/utils/undo.d.ts +7 -0
  113. package/dist-lib/npm/types/features/holidays/components/HolidaySettings.d.ts +1 -0
  114. package/dist-lib/npm/types/features/holidays/hooks/useHolidays.d.ts +3 -0
  115. package/dist-lib/npm/types/features/holidays/index.d.ts +2 -0
  116. package/dist-lib/npm/types/features/holidays/utils/holidayLibrary.d.ts +8 -0
  117. package/dist-lib/npm/types/features/preferences/components/NotificationSettings.d.ts +3 -0
  118. package/dist-lib/npm/types/features/preferences/index.d.ts +1 -0
  119. package/dist-lib/npm/types/features/reminders/ReminderNotices.d.ts +1 -0
  120. package/dist-lib/npm/types/features/reminders/useReminders.d.ts +2 -0
  121. package/dist-lib/npm/types/features/storage/hooks/useStorage.d.ts +1 -2
  122. package/dist-lib/npm/types/features/storage/index.d.ts +4 -2
  123. package/dist-lib/npm/types/features/storage/repositories/LocalEventRepository.d.ts +2 -1
  124. package/dist-lib/npm/types/features/storage/repositories/RemoteChatRepository.d.ts +18 -0
  125. package/dist-lib/npm/types/features/storage/repositories/RemoteEventRepository.d.ts +5 -2
  126. package/dist-lib/npm/types/features/storage/repositories/RemoteHolidayRepository.d.ts +7 -0
  127. package/dist-lib/npm/types/features/storage/types/storage.d.ts +30 -2
  128. package/dist-lib/npm/types/hooks/useDebouncedValue.d.ts +1 -0
  129. package/dist-lib/npm/types/hooks/useForm.d.ts +5 -0
  130. package/dist-lib/npm/types/hooks/useFormState.d.ts +5 -0
  131. package/dist-lib/npm/types/hooks/useKeyboardShortcuts.d.ts +3 -0
  132. package/dist-lib/npm/types/hooks/useLocationUrl.d.ts +1 -0
  133. package/dist-lib/npm/types/i18n/format.d.ts +1 -0
  134. package/dist-lib/npm/types/i18n/index.d.ts +0 -1
  135. package/dist-lib/npm/types/i18n/locale.d.ts +0 -2
  136. package/dist-lib/npm/types/i18n/messages/en/calendar.d.ts +17 -0
  137. package/dist-lib/npm/types/i18n/messages/en/calendars.d.ts +25 -0
  138. package/dist-lib/npm/types/i18n/messages/en/core.d.ts +3 -0
  139. package/dist-lib/npm/types/i18n/messages/en/events.d.ts +64 -3
  140. package/dist-lib/npm/types/i18n/messages/en/index.d.ts +130 -3
  141. package/dist-lib/npm/types/i18n/messages/en/settings.d.ts +21 -0
  142. package/dist-lib/npm/types/i18n/messages/index.d.ts +130 -3
  143. package/dist-lib/npm/types/lib/CalendarWidget.d.ts +1 -1
  144. package/dist-lib/npm/types/lib/config.d.ts +9 -22
  145. package/dist-lib/npm/types/lib/configFile.d.ts +6 -0
  146. package/dist-lib/npm/types/lib/defaults.d.ts +25 -1
  147. package/dist-lib/npm/types/lib/element.d.ts +5 -1
  148. package/dist-lib/npm/types/lib/index.d.ts +6 -3
  149. package/dist-lib/npm/types/lib/options.d.ts +35 -0
  150. package/dist-lib/npm/types/lib/useCalendarOptions.d.ts +11 -0
  151. package/dist-lib/npm/types/pages/RespondPage.d.ts +1 -0
  152. package/dist-lib/npm/types/utils/api.d.ts +4 -5
  153. package/dist-lib/npm/types/utils/apiError.d.ts +0 -2
  154. package/dist-lib/npm/types/utils/appError.d.ts +2 -1
  155. package/dist-lib/npm/types/utils/calendarView.d.ts +1 -0
  156. package/dist-lib/npm/types/utils/chat.d.ts +44 -0
  157. package/dist-lib/npm/types/utils/color.d.ts +0 -1
  158. package/dist-lib/npm/types/utils/date.d.ts +0 -6
  159. package/dist-lib/npm/types/utils/event.d.ts +41 -5
  160. package/dist-lib/npm/types/utils/holidays.d.ts +18 -0
  161. package/dist-lib/npm/types/utils/ical.d.ts +11 -0
  162. package/dist-lib/npm/types/utils/location.d.ts +4 -0
  163. package/dist-lib/npm/types/utils/notifications.d.ts +3 -0
  164. package/dist-lib/npm/types/utils/preferences.d.ts +7 -1
  165. package/dist-lib/npm/types/utils/recurrence.d.ts +3 -4
  166. package/dist-lib/npm/types/utils/reminders.d.ts +13 -0
  167. package/dist-lib/npm/types/utils/timeZone.d.ts +1 -1
  168. package/package.json +10 -1
  169. package/schema/calendar-config.schema.json +232 -0
  170. package/dist-lib/cdn/de-BPZBZXaZ.js +0 -2
  171. package/dist-lib/cdn/de-BPZBZXaZ.js.map +0 -1
  172. package/dist-lib/cdn/es-DsIckdik.js +0 -2
  173. package/dist-lib/cdn/es-DsIckdik.js.map +0 -1
  174. package/dist-lib/cdn/fr-DWAs3O6J.js +0 -2
  175. package/dist-lib/cdn/fr-DWAs3O6J.js.map +0 -1
  176. package/dist-lib/cdn/it-CbhjxqIb.js +0 -2
  177. package/dist-lib/cdn/it-CbhjxqIb.js.map +0 -1
  178. package/dist-lib/cdn/nl-mjTHznX5.js +0 -2
  179. package/dist-lib/cdn/nl-mjTHznX5.js.map +0 -1
  180. package/dist-lib/cdn/pl-CXT0jb2D.js +0 -2
  181. package/dist-lib/cdn/pl-CXT0jb2D.js.map +0 -1
  182. package/dist-lib/cdn/pt-D0oXlVdU.js +0 -2
  183. package/dist-lib/cdn/pt-D0oXlVdU.js.map +0 -1
  184. package/dist-lib/npm/de-CCzGjeTd.js.map +0 -1
  185. package/dist-lib/npm/es-Ciaf66rH.js.map +0 -1
  186. package/dist-lib/npm/fr-CAqNm10Z.js.map +0 -1
  187. package/dist-lib/npm/it-Cqqdu2ua.js.map +0 -1
  188. package/dist-lib/npm/nl-CkchSA8q.js.map +0 -1
  189. package/dist-lib/npm/pl-CCBDUr8k.js.map +0 -1
  190. package/dist-lib/npm/pt-DucaCaoY.js.map +0 -1
  191. package/dist-lib/npm/types/hooks/useArrowKeyNavigation.d.ts +0 -6
@@ -0,0 +1,743 @@
1
+ # Developer Guide
2
+
3
+ Everything you need to put `@rokoyfa/calendar` on your page: embedding, all options, the configuration file, the types the package exports, and what a backend has to provide. For a first look see the [README](README.md).
4
+
5
+ **Contents**
6
+
7
+ 1. [Embedding](#1-embedding)
8
+ 2. [Options](#2-options)
9
+ 3. [Features](#3-features)
10
+ 4. [Configuration file](#4-configuration-file)
11
+ 5. [Languages and texts](#5-languages-and-texts)
12
+ 6. [Reacting to changes](#6-reacting-to-changes)
13
+ 7. [Sign-in and tenants](#7-sign-in-and-tenants)
14
+ 8. [Data adapters](#8-data-adapters)
15
+ 9. [Exported types](#9-exported-types)
16
+ 10. [Backend](#10-backend)
17
+ 11. [Event chat](#11-event-chat)
18
+ 12. [Calendar subscriptions](#12-calendar-subscriptions)
19
+
20
+ ## 1. Embedding
21
+
22
+ There are two ways to embed the calendar. Both render the same component and take the same options.
23
+
24
+ ### Web component, for any website
25
+
26
+ One script, no build step. React is bundled.
27
+
28
+ ```html
29
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@rokoyfa/calendar@1/dist-lib/cdn/calendar-widget.js"></script>
30
+
31
+ <calendar-widget style="height: 700px"></calendar-widget>
32
+ ```
33
+
34
+ The script registers `<calendar-widget>`. Options are attributes in kebab-case (`initial-view="month"`). Values that are not text (functions, objects) are set as properties on the element, before or after the script has loaded:
35
+
36
+ ```js
37
+ const calendar = document.querySelector('calendar-widget')
38
+ calendar.getUserToken = async () => (await fetch('/calendar-token')).text()
39
+ calendar.config = { features: { chat: false } }
40
+ ```
41
+
42
+ When hosting the script yourself, copy the whole `dist-lib/cdn` folder. Languages other than English, the holiday data and the YAML parser are separate files next to `calendar-widget.js` that are loaded on demand.
43
+
44
+ To register the element under another name, or to control when it is registered, use the npm package:
45
+
46
+ ```js
47
+ import { defineCalendarElement, CalendarElement } from '@rokoyfa/calendar'
48
+
49
+ defineCalendarElement('team-calendar')
50
+ console.log(CalendarElement.version)
51
+ ```
52
+
53
+ ### React component
54
+
55
+ Needs React 19.
56
+
57
+ ```bash
58
+ npm install @rokoyfa/calendar
59
+ ```
60
+
61
+ ```tsx
62
+ import { Calendar } from '@rokoyfa/calendar'
63
+
64
+ <Calendar style={{ height: 700 }} />
65
+ ```
66
+
67
+ ### What the host page should know
68
+
69
+ - **Height.** Give the calendar a height, it fills its box and scrolls inside. Without one it grows with its content.
70
+ - **Styles.** The calendar renders into a Shadow DOM. Your CSS does not reach in, its CSS does not leak out, and no stylesheet has to be imported.
71
+ - **Responsive.** The layout follows the width of the calendar, not of the window. A narrow calendar on a wide screen shows the phone layout.
72
+ - **Several calendars** on one page are independent, each with its own view and dialogs. In local mode they share the browser's storage.
73
+ - **Address bar.** By default (`routing: memory`) the calendar never touches the address of your page.
74
+
75
+ ## 2. Options
76
+
77
+ Every option can be given in three ways: as a React prop, as an attribute of the web component, or in a [configuration file](#4-configuration-file).
78
+
79
+ ### Data
80
+
81
+ | Prop | Attribute | Default | |
82
+ | --- | --- | --- | --- |
83
+ | `storageMode` | `storage-mode` | `local` | `local` keeps events in the visitor's browser, `remote` in your backend. With the `auth` feature the sign-in decides: signed-in users use the backend, guests the browser |
84
+ | `apiBaseUrl` | `api-base-url` | `/api` | Base URL of your backend, relative or absolute |
85
+ | `apiTimeoutMs` | `api-timeout-ms` | `10000` | Time limit per request in milliseconds |
86
+ | `tenant` | `tenant` | – | Tenant of a multi-tenant backend, see [Sign-in and tenants](#7-sign-in-and-tenants) |
87
+ | `getUserToken` | property `getUserToken` | – | Sign-in through your own page, see [Sign-in and tenants](#7-sign-in-and-tenants) |
88
+ | `dataSource` | property `dataSource` | – | Your own data adapter, see [Data adapters](#8-data-adapters). Replaces the five options above |
89
+
90
+ ### Features and views
91
+
92
+ | Prop | Attribute | Default | |
93
+ | --- | --- | --- | --- |
94
+ | `features` | `feature-*` | see [Features](#3-features) | Switches for every optional feature |
95
+ | `views` | `views` | all four | Views the user can switch between: `day`, `week`, `month`, `year`. Attribute: separated by spaces or commas, `views="week month"`. With one view the switch disappears |
96
+ | `initialView` | `initial-view` | user's start view | View shown first. Wins over the user's setting |
97
+
98
+ ### Appearance
99
+
100
+ | Prop | Attribute | Default | |
101
+ | --- | --- | --- | --- |
102
+ | `locale` | `locale` | browser | Language and region: `en-US`, `de-DE`, `fr-FR`, `pt-BR`, … See [Languages and texts](#5-languages-and-texts) |
103
+ | `messages` | property `messages` | – | Own texts or languages |
104
+ | `theme` | `theme` | follows the device | `light` or `dark`. Applies while the user has chosen "system" in the settings |
105
+ | `timeZone` | `time-zone` | browser | IANA zone the calendar is shown in, e.g. `Europe/Berlin`. New events start in it. A zone the user picks in the settings wins |
106
+ | `holidays` | `holidays` | from `locale` | Region for public holidays: `DE`, `DE-NW`, `AT`, `US-CA`, or `off`. Users can override it in the settings |
107
+ | `holidaySource` | `holiday-source` | `library` | `library` computes holidays in the browser, `backend` asks your backend (`GET /holidays`) and falls back to the library |
108
+ | `mapUrl` | `map-url` | Google Maps | Map service for locations, with `{query}` for the place: `https://www.openstreetmap.org/search?query={query}`, `https://maps.apple.com/?q={query}` |
109
+ | `className`, `style` | `class`, `style` | – | Size and place on your page |
110
+
111
+ ### Navigation
112
+
113
+ | Prop | Attribute | Default | |
114
+ | --- | --- | --- | --- |
115
+ | `routing` | – | `memory` | `memory`: the calendar's pages (settings, sign-in, …) change inside the widget only. `browser`: they get addresses in the address bar, for when the calendar is the whole page. The web component always uses `memory` |
116
+ | `basename` | – | – | Path prefix for `routing="browser"` |
117
+ | `initialPath` | `initial-path` | `/` | Page the widget opens on, e.g. `/settings` |
118
+ | `linkParam` | `link-param` | `calendarPath` | Query parameter of your page that links from e-mails use to open a page of the widget, e.g. `?calendarPath=%2Freset-password%3Ftoken%3D…`. `false` turns it off |
119
+
120
+ ### Configuration and callbacks
121
+
122
+ | Prop | Attribute | Default | |
123
+ | --- | --- | --- | --- |
124
+ | `config` | `config`, property `config` | – | URL of a JSON or YAML file, or an object with options. See [Configuration file](#4-configuration-file) |
125
+ | `onEventCreate`, `onEventUpdate`, `onEventDelete` | events `event-create`, `event-update`, `event-delete` | – | After every stored change, see [Reacting to changes](#6-reacting-to-changes) |
126
+
127
+ ### Which setting wins
128
+
129
+ Several places can set the same thing. From strongest to weakest:
130
+
131
+ 1. What the user chose in the calendar's settings (language, theme, time zone, holidays, start view). Exception: `initialView` wins over the user's start view.
132
+ 2. Props and attributes.
133
+ 3. The configuration file.
134
+ 4. The browser or device (language, time zone, light or dark).
135
+ 5. The defaults in the tables above.
136
+
137
+ ## 3. Features
138
+
139
+ Everything beyond the core calendar (views, creating, editing, moving and deleting events, colors, all-day events) can be switched off. A feature that is off disappears from the interface and the component makes no calls for it, so your backend does not have to provide it.
140
+
141
+ ```jsx
142
+ <Calendar storageMode="remote" features={{ auth: true, chat: false, subscriptions: false }} views={['week', 'month']} />
143
+ ```
144
+
145
+ ```html
146
+ <calendar-widget storage-mode="remote" feature-auth feature-chat="false" feature-subscriptions="false" views="week month"></calendar-widget>
147
+ ```
148
+
149
+ | Feature | Attribute | Default | What it covers | Your backend needs |
150
+ | --- | --- | --- | --- | --- |
151
+ | `auth` | `feature-auth` | off | Sign-in, registration, accounts | `/auth/*` |
152
+ | `teams` | `feature-teams` | on | Team calendars, members, roles, invitations | `/calendars`, `/teams/*`, `/invitations` |
153
+ | `chat` | `feature-chat` | on | Chat per event in team calendars | Chat endpoints and the WebSocket, see [Event chat](#11-event-chat) |
154
+ | `attendees` | `feature-attendees` | on | Inviting members to events, replies | `POST /events/:id/response` |
155
+ | `recurrence` | `feature-recurrence` | on | Creating and editing recurring events | – |
156
+ | `reminders` | `feature-reminders` | on | Reminders and their notifications | `PUT /events/:id/reminders` for members without edit rights |
157
+ | `links` | `feature-links` | on | Website and other links on events | – |
158
+ | `mapLinks` | `feature-map-links` | on | Opening a location in a map service | – |
159
+ | `holidays` | `feature-holidays` | on | Public holidays and their setting | `GET /holidays` only with `holidaySource="backend"` |
160
+ | `search` | `feature-search` | on | Event search | `GET /events/search` |
161
+ | `undo` | `feature-undo` | on | Undo after moving or deleting | – |
162
+ | `duplicate` | `feature-duplicate` | on | Duplicating events | – |
163
+ | `shortcuts` | `feature-shortcuts` | on | Keyboard shortcuts | – |
164
+ | `subscriptions` | `feature-subscriptions` | on | Subscription links in the calendar settings | `/calendars/:id/feed`, `/feeds/:token.ics` |
165
+ | `importExport` | `feature-import-export` | on | iCalendar import and export | – |
166
+ | `emailNotifications` | `feature-email-notifications` | on | E-mail settings of a signed-in user | Sending the e-mails |
167
+ | `timeZones` | `feature-time-zones` | on | Time zone per event and in the settings | – |
168
+ | `customColors` | `feature-custom-colors` | on | Own event colors | `/colors` |
169
+
170
+ Good to know:
171
+
172
+ - `chat` and `attendees` need `teams`. Without teams they are off, whatever you set.
173
+ - With `undo` off, deleting an event asks for confirmation first.
174
+ - With `recurrence`, `links` or `reminders` off, existing data is kept when an event is saved. It is only no longer shown or editable.
175
+ - With `timeZones` off, the calendar always uses the automatic zone (your `timeZone`, otherwise the browser's).
176
+ - With a single entry in `views`, the view switch disappears.
177
+ - The attributes `auth` and `teams` still work as short forms of `feature-auth` and `feature-teams`.
178
+
179
+ ## 4. Configuration file
180
+
181
+ Instead of props or attributes you can keep the options in a file, or pass them as an object. This keeps the embedding code the same on every page and the settings in one place.
182
+
183
+ ```html
184
+ <calendar-widget config="/calendar.config.yaml"></calendar-widget>
185
+ ```
186
+
187
+ ```tsx
188
+ <Calendar config="/calendar.config.json" />
189
+ <Calendar config={{ storageMode: 'remote', features: { auth: true, chat: false } }} />
190
+ ```
191
+
192
+ ```js
193
+ document.querySelector('calendar-widget').config = { features: { chat: false } }
194
+ ```
195
+
196
+ ### Example files
197
+
198
+ Two complete, commented examples list every option with its default. Copy one and delete what you do not need:
199
+
200
+ - [`demo/calendar.config.yaml`](demo/calendar.config.yaml)
201
+ - [`demo/calendar.config.jsonc`](demo/calendar.config.jsonc), the same as JSON
202
+
203
+ A short file is enough, everything left out keeps its default:
204
+
205
+ ```yaml
206
+ storageMode: remote
207
+ apiBaseUrl: https://api.example.com
208
+ locale: de-DE
209
+ views: [week, month]
210
+ features:
211
+ auth: true
212
+ chat: false
213
+ subscriptions: false
214
+ ```
215
+
216
+ ```jsonc
217
+ {
218
+ // comments are allowed
219
+ "storageMode": "remote",
220
+ "apiBaseUrl": "https://api.example.com",
221
+ "locale": "de-DE",
222
+ "views": ["week", "month"],
223
+ "features": { "auth": true, "chat": false, "subscriptions": false }
224
+ }
225
+ ```
226
+
227
+ ### What can be in the file
228
+
229
+ All options from [Options](#2-options) under their prop names, except those that cannot be written as data: `dataSource`, `getUserToken`, the event callbacks, `className`, `style`, and `config` itself.
230
+
231
+ | Field | Type | Default |
232
+ | --- | --- | --- |
233
+ | `storageMode` | `"local"` or `"remote"` | `"local"` |
234
+ | `apiBaseUrl` | text | `"/api"` |
235
+ | `apiTimeoutMs` | whole number above 0 | `10000` |
236
+ | `tenant` | text | – |
237
+ | `features` | object of feature names and `true` / `false` | see [Features](#3-features) |
238
+ | `views` | list of `day`, `week`, `month`, `year` | all four |
239
+ | `initialView` | `day`, `week`, `month` or `year` | user's start view |
240
+ | `locale` | text | browser |
241
+ | `messages` | object: language → texts | – |
242
+ | `theme` | `"light"` or `"dark"` | follows the device |
243
+ | `timeZone` | text (IANA zone) | browser |
244
+ | `holidays` | text (region or `"off"`) | from `locale` |
245
+ | `holidaySource` | `"library"` or `"backend"` | `"library"` |
246
+ | `mapUrl` | text with `{query}` | Google Maps |
247
+ | `routing` | `"memory"` or `"browser"` | `"memory"` |
248
+ | `basename` | text | – |
249
+ | `initialPath` | text | `/` |
250
+ | `linkParam` | text or `false` | `"calendarPath"` |
251
+
252
+ ### How the file is read
253
+
254
+ - **Format.** Files ending in `.yaml` or `.yml` are read as YAML, files ending in `.json` or `.jsonc` as JSON. For other addresses the `Content-Type` of the answer decides. JSON files may contain `//` and `/* */` comments.
255
+ - **YAML parser.** It is only loaded when a YAML file is used. With the script tag it is a separate file next to `calendar-widget.js`, with the npm package it comes from the `yaml` dependency.
256
+ - **Precedence.** Props and attributes win over the file, for features one switch at a time. So one shared file can be adjusted per page: `<calendar-widget config="/calendar.config.yaml" feature-search="false">`.
257
+ - **Mistakes in the file.** Unknown or invalid entries are skipped, the rest is used. Every skipped entry is listed as a warning in the browser console, starting with `[calendar]`.
258
+ - **File not reachable or not parseable.** The calendar shows a message and does not start. It never falls back to defaults silently, because that could mean storing events in the wrong place.
259
+ - **Loading.** The file is fetched once when the calendar starts and again when the `config` address changes. Cache it like any other static file.
260
+ - **Texts.** `messages` in a file can override plain texts. Texts that are functions need the `messages` prop or property, see [Languages and texts](#5-languages-and-texts).
261
+ - **Security.** The file is public, like everything a browser loads. Never put secrets in it.
262
+
263
+ ### Editor support
264
+
265
+ A JSON Schema ships with the package as `@rokoyfa/calendar/config.schema.json`. With it, editors complete field names and flag wrong values.
266
+
267
+ ```json
268
+ { "$schema": "https://unpkg.com/@rokoyfa/calendar/schema/calendar-config.schema.json" }
269
+ ```
270
+
271
+ ```yaml
272
+ # yaml-language-server: $schema=https://unpkg.com/@rokoyfa/calendar/schema/calendar-config.schema.json
273
+ ```
274
+
275
+ ### Checking a configuration yourself
276
+
277
+ `parseCalendarOptions` is the function the calendar uses. It returns the valid options and a list of problems, useful in a build step or an admin page:
278
+
279
+ ```ts
280
+ import { parseCalendarOptions } from '@rokoyfa/calendar'
281
+
282
+ const { options, issues } = parseCalendarOptions(JSON.parse(text))
283
+ if (issues.length > 0) console.warn(issues)
284
+ ```
285
+
286
+ ## 5. Languages and texts
287
+
288
+ English, German, French, Spanish, Italian, Dutch, Polish and Portuguese are built in. Which language is used, in this order:
289
+
290
+ 1. The user's choice in the settings.
291
+ 2. Your `locale`.
292
+ 3. The browser's languages.
293
+ 4. `en-US`.
294
+
295
+ Formats follow the region, not the language: `en-US` starts the week on Sunday and shows `1:00 PM`, `en-GB` starts on Monday and shows `13:00`. A language that is not available falls back to English with the user's region.
296
+
297
+ **Own texts and languages.** `messages` overrides single texts or adds a language. Missing texts fall back to the built-in language, or to English for a new one. The full list of keys is the `Messages` type.
298
+
299
+ ```js
300
+ document.querySelector('calendar-widget').messages = {
301
+ de: { calendar: { newEvent: 'Neuer Eintrag' } },
302
+ sv: { calendar: { today: 'Idag', newEvent: 'Ny händelse' }, views: { weekNumber: (week) => `V. ${week}` } },
303
+ }
304
+ ```
305
+
306
+ Texts with values in them are functions, like `weekNumber` above. An override of the wrong kind (a text where a function is expected, or the other way round) is ignored.
307
+
308
+ ## 6. Reacting to changes
309
+
310
+ After every stored change the calendar tells your page.
311
+
312
+ ```tsx
313
+ <Calendar
314
+ onEventCreate={(event) => console.log('created', event)}
315
+ onEventUpdate={(event) => console.log('updated', event)}
316
+ onEventDelete={({ id }) => console.log('deleted', id)}
317
+ />
318
+ ```
319
+
320
+ ```js
321
+ const calendar = document.querySelector('calendar-widget')
322
+ calendar.addEventListener('event-create', (e) => console.log(e.detail))
323
+ calendar.addEventListener('event-update', (e) => console.log(e.detail))
324
+ calendar.addEventListener('event-delete', (e) => console.log(e.detail.id))
325
+ ```
326
+
327
+ - Create and update carry the stored `CalendarEvent`, delete carries `{ id }`.
328
+ - The DOM events bubble and cross the Shadow DOM, so you can listen on a parent element.
329
+ - One action on a recurring event can cause several calls. Changing "only this occurrence" updates the series and creates a detached event.
330
+ - An undo causes the reverse calls.
331
+
332
+ ## 7. Sign-in and tenants
333
+
334
+ There are three ways to handle users.
335
+
336
+ **No sign-in** (default). Everything stays in the visitor's browser. With `storageMode="remote"` all requests go to your backend without the calendar asking anyone to sign in. Who the visitor is, is then up to your backend, for example through a session cookie of your own site or a token from `getAccessToken` (see [Data adapters](#8-data-adapters)).
337
+
338
+ **The calendar's own accounts.** Turn on the `auth` feature. The calendar then has pages for sign-in, registration, password reset and e-mail confirmation. Guests keep working in the browser, and after signing in they are asked whether to move their local events into the account.
339
+
340
+ ```html
341
+ <calendar-widget storage-mode="remote" feature-auth api-base-url="https://api.example.com"></calendar-widget>
342
+ ```
343
+
344
+ **Sign-in through your page.** If your visitors are already signed in on your site, pass `getUserToken`. It returns a short-lived token signed by your server, or `null` when nobody is signed in.
345
+
346
+ ```tsx
347
+ <Calendar
348
+ tenant="acme"
349
+ apiBaseUrl="https://api.example.com"
350
+ getUserToken={() => fetch('/calendar-token').then((r) => r.text())}
351
+ />
352
+ ```
353
+
354
+ - The calendar first asks `GET /auth/me`. On `401` it calls `getUserToken` and exchanges the token at `POST /auth/token` for a session. When the session runs out later, this happens again by itself.
355
+ - In this mode there are no sign-in, registration or password pages, no sign-out button and no account tab. The account belongs to your site.
356
+ - With `null` the calendar works like for guests, in the browser.
357
+
358
+ **Tenants.** `tenant` is for a backend that serves several host pages. Every request then carries the header `X-Calendar-Tenant`, and sign-in is on. What the backend has to check is described in the OpenAPI file.
359
+
360
+ ## 8. Data adapters
361
+
362
+ Where the data comes from is decided by a `CalendarDataSource`. Without the `dataSource` option the calendar picks a built-in one from `storageMode`, `apiBaseUrl`, `tenant` and the `auth` feature.
363
+
364
+ ```tsx
365
+ import { Calendar, localDataSource, restDataSource, tenantDataSource } from '@rokoyfa/calendar'
366
+
367
+ <Calendar dataSource={localDataSource()} />
368
+ <Calendar dataSource={restDataSource({ baseUrl: 'https://api.example.com' })} />
369
+ <Calendar dataSource={restDataSource({ baseUrl: '/api', auth: false, getAccessToken: () => myToken })} />
370
+ <Calendar dataSource={tenantDataSource({ tenant: 'acme', baseUrl: 'https://api.example.com', getUserToken })} />
371
+ ```
372
+
373
+ | Adapter | Behaviour |
374
+ | --- | --- |
375
+ | `localDataSource()` | Everything in the browser (localStorage), no sign-in |
376
+ | `restDataSource(options)` | Talks to the [REST API](api/openapi.yaml) |
377
+ | `tenantDataSource(options)` | `restDataSource` with the tenant header and sign-in |
378
+
379
+ `restDataSource` options:
380
+
381
+ | Option | Default | |
382
+ | --- | --- | --- |
383
+ | `baseUrl` | required | Base URL of the backend |
384
+ | `timeoutMs` | `10000` | Time limit per request |
385
+ | `auth` | `true` | With sign-in in the widget: guests work in the browser, signed-in users on the backend. `false`: always the backend |
386
+ | `headers` | – | Extra headers for every request |
387
+ | `getAccessToken` | – | Returns a bearer token for the `Authorization` header |
388
+ | `getUserToken` | – | Sign-in through your page, see above |
389
+ | `holidaySource` | `library` | `backend` asks `GET /holidays` |
390
+ | `chat` | `true` | `false` creates no chat connection |
391
+ | `chatSocketUrl` | from `baseUrl` | Address of the chat WebSocket |
392
+
393
+ Note that `restDataSource` defaults to `auth: true`, while the `auth` feature of the component defaults to off.
394
+
395
+ ### Your own adapter
396
+
397
+ For any other data source, implement the interfaces yourself. All types are exported.
398
+
399
+ ```ts
400
+ import type { CalendarDataSource } from '@rokoyfa/calendar'
401
+
402
+ const myDataSource: CalendarDataSource = {
403
+ createAuthRepository: ({ getLanguage }) => myAuth,
404
+ connect: ({ isAuthenticated }, { getLanguage, onUnauthorized }) => ({
405
+ mode: 'remote',
406
+ events: myEvents,
407
+ calendars: myCalendars,
408
+ colors: myColors,
409
+ preferences: myPreferences,
410
+ holidays: myHolidays,
411
+ chat: myChat,
412
+ }),
413
+ }
414
+ ```
415
+
416
+ - `connect` returns the repositories for the current state. It is called again on sign-in and sign-out.
417
+ - `createAuthRepository` is optional. Without it there is no sign-in in the widget.
418
+ - `holidays` and `chat` are optional. Without `chat` there is no chat, without `holidays` they are computed in the browser.
419
+ - `mode: 'remote'` makes the calendar offer to move local events into the account after sign-in.
420
+ - Optional methods switch their feature on: `events.search`, `events.respond`, `events.setReminders`, `calendars.getFeed` / `createFeed` / `deleteFeed`. Without `search` the calendar searches the last and next year itself.
421
+ - Call `onUnauthorized` when a session has run out. `getLanguage` returns the current language for your requests.
422
+ - Errors with a known `code` are shown translated, others with their `message`.
423
+
424
+ A simple start is to take most repositories from `localDataSource()` and replace only `events`:
425
+
426
+ ```ts
427
+ const local = localDataSource()
428
+
429
+ const myDataSource: CalendarDataSource = {
430
+ connect: (session, context) => ({ ...local.connect(session, context), events: myEvents }),
431
+ }
432
+ ```
433
+
434
+ ## 9. Exported types
435
+
436
+ Everything below is exported from `@rokoyfa/calendar`.
437
+
438
+ ### Component and configuration
439
+
440
+ | Export | Kind | |
441
+ | --- | --- | --- |
442
+ | `Calendar` | component | The React component |
443
+ | `CalendarElement`, `defineCalendarElement`, `DEFAULT_ELEMENT_NAME` | class, function, text | The web component, registering it, and its default name `calendar-widget` |
444
+ | `VERSION` | text | Version of the package |
445
+ | `CalendarProps` | type | All props of `Calendar` |
446
+ | `CalendarOptions` | type | The options that can be written as data, the shape of a configuration file |
447
+ | `CalendarConfigSource` | type | `string | CalendarOptions`, the type of `config` |
448
+ | `CalendarFeatures`, `CalendarFeature` | types | All feature switches, and the name of one |
449
+ | `DEFAULT_FEATURES`, `FEATURE_NAMES` | values | Defaults and names of the features |
450
+ | `parseCalendarOptions`, `ParsedOptions` | function, type | Checks a configuration and returns `{ options, issues }` |
451
+ | `CalendarView` | type | `'day' | 'week' | 'month' | 'year'` |
452
+ | `CalendarRouting`, `StorageMode`, `HolidaySource`, `HostTheme` | types | The values of `routing`, `storageMode`, `holidaySource`, `theme` |
453
+ | `EventCallbacks`, `DeletedEvent` | types | The three callbacks, and `{ id }` |
454
+ | `Messages`, `PartialMessages`, `MessageOverrides`, `DeepPartial` | types | All texts, a part of them, and the type of `messages` |
455
+
456
+ ```ts
457
+ type CalendarOptions = {
458
+ tenant?: string
459
+ storageMode?: 'local' | 'remote'
460
+ apiBaseUrl?: string
461
+ apiTimeoutMs?: number
462
+ features?: Partial<CalendarFeatures>
463
+ views?: readonly CalendarView[]
464
+ routing?: 'memory' | 'browser'
465
+ basename?: string
466
+ initialPath?: string
467
+ linkParam?: string | false
468
+ locale?: string
469
+ messages?: MessageOverrides
470
+ theme?: 'light' | 'dark'
471
+ initialView?: CalendarView
472
+ timeZone?: string
473
+ holidays?: string
474
+ holidaySource?: 'library' | 'backend'
475
+ mapUrl?: string
476
+ }
477
+
478
+ type CalendarProps = CalendarOptions &
479
+ EventCallbacks & {
480
+ config?: string | CalendarOptions
481
+ dataSource?: CalendarDataSource
482
+ getUserToken?: UserTokenProvider
483
+ className?: string
484
+ style?: CSSProperties
485
+ }
486
+
487
+ type CalendarFeatures = {
488
+ auth: boolean
489
+ teams: boolean
490
+ chat: boolean
491
+ attendees: boolean
492
+ recurrence: boolean
493
+ reminders: boolean
494
+ links: boolean
495
+ mapLinks: boolean
496
+ holidays: boolean
497
+ search: boolean
498
+ undo: boolean
499
+ duplicate: boolean
500
+ shortcuts: boolean
501
+ subscriptions: boolean
502
+ importExport: boolean
503
+ emailNotifications: boolean
504
+ timeZones: boolean
505
+ customColors: boolean
506
+ }
507
+ ```
508
+
509
+ ### Data
510
+
511
+ | Export | |
512
+ | --- | --- |
513
+ | `CalendarEvent`, `EventInput`, `EventLink`, `Attendee`, `AttendeeStatus`, `Recurrence`, `HexColor` | Events, see [Data types](#data-types) |
514
+ | `CalendarSummary`, `CalendarDraft`, `CalendarChanges`, `TeamChanges`, `TeamMember`, `TeamRole`, `Invitation`, `PendingInvitation`, `TeamInvitation` | Calendars, teams and invitations |
515
+ | `User`, `AuthMethod`, `UserTokenProvider` | The signed-in user, `'password' | 'hostToken'`, and the type of `getUserToken` |
516
+ | `Preferences` | A user's settings |
517
+ | `PublicHoliday` | `{ date, name }` |
518
+ | `ChatMessage`, `ChatKey`, `ChatPage`, `ChatUnread`, `ChatEvent` | Chat, see [Event chat](#11-event-chat) |
519
+
520
+ ### Data adapters
521
+
522
+ | Export | |
523
+ | --- | --- |
524
+ | `localDataSource`, `restDataSource`, `tenantDataSource`, `TENANT_HEADER` | The built-in adapters and the name of the tenant header |
525
+ | `RestDataSourceOptions`, `TenantDataSourceOptions` | Their options |
526
+ | `CalendarDataSource`, `DataRepositories`, `DataSession`, `DataSourceContext` | The adapter interface |
527
+ | `EventRepository`, `EventQuery`, `EventSearchQuery` | Events |
528
+ | `CalendarRepository` | Calendars, teams, invitations, subscription links |
529
+ | `AuthRepository` | Sign-in and account |
530
+ | `ColorRepository`, `PreferencesRepository` | Own colors, settings |
531
+ | `HolidayRepository`, `HolidayQuery` | Public holidays |
532
+ | `ChatRepository` | Chat |
533
+
534
+ ```ts
535
+ interface CalendarDataSource {
536
+ createAuthRepository?: (context: { getLanguage: () => string | null }) => AuthRepository
537
+ connect: (session: { isAuthenticated: boolean }, context: DataSourceContext) => DataRepositories
538
+ }
539
+
540
+ type DataSourceContext = { getLanguage: () => string | null; onUnauthorized: () => void }
541
+
542
+ type DataRepositories = {
543
+ mode: 'local' | 'remote'
544
+ events: EventRepository
545
+ calendars: CalendarRepository
546
+ colors: ColorRepository
547
+ preferences: PreferencesRepository
548
+ holidays?: HolidayRepository
549
+ chat?: ChatRepository
550
+ }
551
+
552
+ interface EventRepository {
553
+ list(query: { from: string; to: string; calendarIds: readonly string[] }): Promise<CalendarEvent[]>
554
+ listSeries(seriesId: string): Promise<CalendarEvent[]>
555
+ create(calendarId: string, input: EventInput): Promise<CalendarEvent>
556
+ update(id: string, input: EventInput): Promise<CalendarEvent>
557
+ remove(id: string): Promise<void>
558
+ search?(query: { text: string; calendarIds: readonly string[] }): Promise<CalendarEvent[]>
559
+ respond?(id: string, status: AttendeeStatus): Promise<CalendarEvent>
560
+ setReminders?(id: string, reminders: number[]): Promise<CalendarEvent>
561
+ }
562
+
563
+ interface ChatRepository {
564
+ list(key: ChatKey, options?: { before?: string }): Promise<ChatPage>
565
+ send(key: ChatKey, text: string): Promise<ChatMessage>
566
+ edit(id: string, text: string): Promise<ChatMessage>
567
+ remove(id: string): Promise<void>
568
+ markRead(key: ChatKey): Promise<void>
569
+ unread(calendarIds: readonly string[]): Promise<ChatUnread[]>
570
+ subscribe(listener: (event: ChatEvent) => void): () => void
571
+ }
572
+
573
+ type ChatKey = { eventId: string; occurrenceDate: string | null }
574
+ type ChatMessage = ChatKey & {
575
+ id: string
576
+ calendarId: string
577
+ author: { id: string; name: string } | null
578
+ text: string
579
+ createdAt: string
580
+ editedAt: string | null
581
+ }
582
+ type ChatPage = { messages: ChatMessage[]; hasMore: boolean }
583
+ type ChatUnread = ChatKey & { count: number }
584
+ ```
585
+
586
+ The other interfaces (`CalendarRepository`, `AuthRepository`, `ColorRepository`, `PreferencesRepository`, `HolidayRepository`) are best read in your editor from the package's type definitions.
587
+
588
+ ## 10. Backend
589
+
590
+ The full contract is [`api/openapi.yaml`](api/openapi.yaml) (OpenAPI 3.1, also shipped as `@rokoyfa/calendar/openapi.yaml`). The essentials:
591
+
592
+ ### Data types
593
+
594
+ ```ts
595
+ type CalendarEvent = EventInput & {
596
+ id: string
597
+ calendarId: string
598
+ createdAt: string // ISO date-time
599
+ updatedAt: string
600
+ }
601
+
602
+ type EventInput = {
603
+ uid: string // stable id for iCalendar, shared by a series and its detached events
604
+ title: string // 1–100 chars
605
+ location: string // max 200 chars, '' if none
606
+ links: EventLink[] // up to 10 http(s) links
607
+ startDate: string // 'YYYY-MM-DD'
608
+ start: string // 'HH:mm' in timeZone
609
+ endDate: string // inclusive for all-day events
610
+ end: string
611
+ allDay: boolean // start and end are '00:00'
612
+ timeZone: string | null // IANA zone, null = same local time everywhere (always null for all-day)
613
+ description: string // max 2000 chars
614
+ color: 'blue' | 'red' | 'green' | 'yellow' | `#${string}`
615
+ recurrence: Recurrence | null
616
+ excludedDates: string[] // occurrences removed from a series
617
+ seriesId: string | null // set on an occurrence detached from a series
618
+ originalDate: string | null // its original date in that series
619
+ reminders: number[] // minutes before the start, per user (see below)
620
+ attendees: Attendee[]
621
+ }
622
+
623
+ type Attendee = { email: string; name: string; status: 'needsAction' | 'accepted' | 'tentative' | 'declined' }
624
+
625
+ type EventLink = { url: string; label: string } // url max 2000 chars, label max 100 chars, '' if none
626
+
627
+ type Recurrence = {
628
+ frequency: 'daily' | 'weekly' | 'monthly' | 'yearly'
629
+ interval: number // 1–99
630
+ weekdays: number[] // 0 = Monday … 6 = Sunday
631
+ monthlyMode: 'dayOfMonth' | 'weekdayOfMonth' | 'lastWeekdayOfMonth'
632
+ until: string | null // either until or count, or neither
633
+ count: number | null
634
+ }
635
+
636
+ type CalendarSummary = {
637
+ id: string; teamId: string; name: string; color: string
638
+ kind: 'personal' | 'team'; teamName: string | null; description: string
639
+ role: 'owner' | 'admin' | 'manager' | 'editor' | 'member' | 'contributor' | 'viewer'
640
+ showInPersonal: boolean; permissions: string[]
641
+ }
642
+
643
+ type User = { id: string; email: string; name: string; emailVerified: boolean }
644
+ type Preferences = {
645
+ theme: 'system' | 'light' | 'dark'; defaultView: View; mobileDefaultView: View; locale: string
646
+ timeZone: string // 'auto' or IANA zone
647
+ holidays: string // 'auto', 'off' or a region such as 'DE-NW'
648
+ }
649
+ type PublicHoliday = { date: string; name: string } // GET /holidays, only with holiday-source="backend"
650
+ // Preferences also carry emailInvites, emailChanges, emailReminders, emailChat: booleans for the emails below
651
+ type Problem = { code: string; message: string } // every error response
652
+ ```
653
+
654
+ The backend stores series as one event. The component expands occurrences itself.
655
+
656
+ **Reminders are personal.** Store them per user and event, return only the caller's own `reminders`, and keep other members' reminders when someone saves the event. The component shows reminders while it is open (browser notification or a notice in the calendar). Emails or push messages when it is closed are up to your backend.
657
+
658
+ ### When the component calls your backend
659
+
660
+ | Moment | Requests |
661
+ | --- | --- |
662
+ | Widget loads | `GET /auth/me` (only with `auth`), then `GET /preferences`, `GET /colors`, `GET /calendars`, `GET /invitations` |
663
+ | Visible range changes | `GET /events?from=…&to=…&calendarId=…` with the calendars shown. The range is two days wider than the view to cover time zone shifts. Return every event in the range **and** every series that can occur in it. |
664
+ | Create event | `POST /events` with `EventInput` + `calendarId` |
665
+ | Edit event / whole series | `PUT /events/:id` with the full `EventInput` |
666
+ | Edit only this occurrence | `PUT` the series with the date added to `excludedDates`, then `POST` a detached event with `seriesId` and `originalDate` |
667
+ | Edit this and following | `PUT` the series with `until` set to the day before (and `count: null`), `POST` a new series, `PUT` later detached events to relink them |
668
+ | Delete | single: `PUT` with `excludedDates` · following: `PUT` with `until`, `DELETE` its later detached events · all: `DELETE` detached events, then the series · plain: `DELETE /events/:id` |
669
+ | Search | `GET /events/search?q=…&calendarId=…` (optional: without it the component searches the last and next year via `GET /events`) |
670
+ | Answer as attendee | `POST /events/:id/response` with `{ status }` |
671
+ | Change only own reminders | `PUT /events/:id/reminders` with `{ reminders }` (also for members without edit rights) |
672
+ | Answer from an email link | `POST /events/respond` with `{ token, status }`, no session needed |
673
+ | Event chat | `GET`/`POST /events/:id/chat?date=…`, `POST /events/:id/chat/read`, `PATCH`/`DELETE /chat/messages/:id`, `GET /chat/unread?calendarId=…`, WebSocket `/chat/socket` |
674
+ | Subscription link | `GET`, `POST` (new link), `DELETE /calendars/:id/feed`. The link points at your `GET /feeds/:token.ics` |
675
+ | Reminders | `GET /events` for the next four weeks of all calendars, every five minutes while the widget is open |
676
+ | Import .ics | `GET /events` for the whole calendar, then `PUT` for known `uid`s and `POST` for new ones |
677
+ | Settings, colors | `PATCH /preferences`, `POST /colors`, `DELETE /colors/:rrggbb` |
678
+ | Holidays (only with `holiday-source="backend"`) | `GET /holidays?from=…&to=…&region=DE-NW&lang=de`, answer `PublicHoliday[]` |
679
+ | Sign-in, teams, invitations | `/auth/*`, `/calendars`, `/teams/*`, `/invitations/*`, see the OpenAPI file |
680
+
681
+ Before editing "following" or "all" of a series, the component loads its detached events with `GET /events?seriesId=…`.
682
+
683
+ ### Rules for the backend
684
+
685
+ - **Sessions:** requests use `credentials: 'include'`. Set an `HttpOnly` cookie on sign-in. If the widget runs on another domain: CORS for that origin with `Access-Control-Allow-Credentials: true`, allowed headers `Content-Type`, `Accept`, `Accept-Language`, `Authorization`, `X-Calendar-Tenant`, and the cookie as `SameSite=None; Secure`. Answer `401` when the session is gone.
686
+ - **Errors:** always `{ code, message }`. Known codes such as `invalidCredentials`, `emailTaken`, `forbidden`, `lastOwner` are shown translated, others with `message`.
687
+ - **Language:** every request carries `Accept-Language`. Use it, or the stored `locale`, for emails.
688
+ - **Emails about events** (your backend sends them, the component only stores the user's choice): an invitation with yes / maybe / no links to `/respond?status=accepted&token=…` when someone is added as attendee (`emailInvites`), a notice when title, time, place or repetition change or the event is cancelled (`emailChanges`), and reminders at the user's own reminder times even while the calendar is closed (`emailReminders`, off by default). Only to verified addresses, never to the person who made the change.
689
+ - **Subscriptions:** `GET /feeds/:token.ics` answers without a session with the calendar as iCalendar (RFC 5545) and the subscriber's own reminders. Keep one secret token per user and calendar, a new one replaces the old. Stop serving it when the user leaves the calendar.
690
+ - **Email links:** point them at the host page with the screen as parameter, e.g. `https://host.example/calendar?calendarPath=%2Freset-password%3Ftoken%3D…`.
691
+
692
+ ## 11. Event chat
693
+
694
+ Events in team calendars have a **Chat** tab: every member can read and write, edit and delete their own messages, and owners, admins and managers (`manage_calendars`) can delete any message. Recurring events have one chat per occurrence. A detached occurrence keeps the chat of its original date. The calendar shows unread messages as a red badge on the event and in the tab title, and attendees can get an email about new messages (`emailChat`, on by default, at most one email per chat every few minutes).
695
+
696
+ Messages go over REST (see the OpenAPI file, tag *Chat*). New, edited and deleted messages arrive live over a WebSocket:
697
+
698
+ - **Address:** `{apiBaseUrl}/chat/socket` with `ws://` or `wss://`, derived from `apiBaseUrl` (relative addresses use the page's host). With `tenant` the tenant is added as `?tenant=…`, because browsers cannot set headers on WebSockets. `restDataSource` takes another address as `chatSocketUrl`.
699
+ - **Sign-in:** the session cookie is sent with the handshake. Check the `Origin` header against the allowed origins and answer `401` without a session.
700
+ - **Server → client** (JSON text frames): `{ "type": "message.created" | "message.updated", "message": ChatMessage }` and `{ "type": "message.deleted", "id", "calendarId", "eventId", "occurrenceDate" }`, sent to every connected member of the calendar's team.
701
+ - **Client → server:** only `{ "type": "ping" }` every 25 seconds, answer with `{ "type": "pong" }` or ignore it.
702
+ - The component reconnects with growing pauses (1 to 30 seconds) and reloads the open chat and the unread counts after reconnecting, so a lost connection only delays messages.
703
+
704
+ Emails link to the host page with `?calendar=…&event=…&date=…&tab=chat`, which opens the event with the chat.
705
+
706
+ Without a WebSocket on your backend, turn the feature off: `features: { chat: false }`. The calendar then opens no connection and shows no chat.
707
+
708
+ ## 12. Calendar subscriptions
709
+
710
+ With a backend that serves `/calendars/:id/feed` and `/feeds/:token.ics`, every signed-in user can subscribe to a calendar in another calendar app and see its events there, for example on the phone. Users get the link in the calendar settings: **Import & export** tab for team calendars, on the settings page for the personal calendar → **Subscribe** → **Create subscription link**. They can copy the link or open it in their calendar app.
711
+
712
+ - The subscription is **read-only**. Changes made in the other app do not come back.
713
+ - The link is **personal and secret**: it contains the user's own reminders, and anyone who has it can see all events of the calendar. **Create new link** turns the old one off, **End subscription** removes it.
714
+ - It stops working when the user leaves the calendar.
715
+
716
+ ### Adding the link in calendar apps
717
+
718
+ | App | Steps |
719
+ | --- | --- |
720
+ | **Apple Calendar on Mac** | **Open in calendar app** in the settings, or *File → New Calendar Subscription…*, paste the link, **Subscribe**. Set *Auto-refresh* and choose *iCloud* as location so the calendar also appears on iPhone and iPad. |
721
+ | **Apple Calendar on iPhone / iPad** | **Open in calendar app** in the settings, or *Settings → Apps → Calendar → Calendar Accounts → Add Account → Other → Add Subscribed Calendar* (older iOS: *Settings → Calendar → Accounts*), paste the link as server, **Next**, **Save**. |
722
+ | **Google Calendar** | Only in the browser at calendar.google.com: next to *Other calendars* click **+** → **From URL**, paste the link, **Add calendar**. It then also shows in the Google Calendar apps on Android and iPhone. |
723
+ | **Outlook.com / Outlook on the web / new Outlook** | *Calendar → Add calendar → Subscribe from web*, paste the link, give it a name, **Import**. |
724
+ | **Classic Outlook for Windows** | *Home → Add Calendar → From Internet…* (in some versions *Open Calendar → From Internet*), paste the link, **OK**, confirm with **Yes**. |
725
+ | **Thunderbird** | *New Calendar → On the Network*, paste the link, choose the iCalendar (ICS) format. |
726
+
727
+ Menu names change between app versions. If a path does not match, look for “subscribe”, “from URL” or “from internet”.
728
+
729
+ ### How quickly changes show up
730
+
731
+ A subscription is not live: the app downloads the whole calendar again at intervals that the app decides. Changes made in this calendar therefore appear with a delay:
732
+
733
+ | App | Refresh |
734
+ | --- | --- |
735
+ | Apple Calendar on Mac | Adjustable per subscription, from every 5 minutes to weekly (right-click the calendar → *Get Info* → *Auto-refresh*). *View → Refresh Calendars* (⌘R) refreshes right away. |
736
+ | Apple Calendar on iPhone / iPad | Follows *Fetch New Data* (*Settings → Apps → Calendar → Calendar Accounts → Fetch New Data*). Choose *Every 15 Minutes* or *Hourly*. Subscriptions have no push. A subscription added on the Mac with location *iCloud* is refreshed by iCloud. |
737
+ | Google Calendar | Google's own schedule, usually several hours, sometimes up to a day. Cannot be changed. |
738
+ | Outlook.com / web / new Outlook | Microsoft's own schedule, roughly every 3 hours, sometimes more than 24 hours. Cannot be changed. |
739
+ | Classic Outlook for Windows | Follows the update limit in the feed (one hour here) and Outlook's send/receive settings. |
740
+
741
+ The feed asks clients to reload every hour (`REFRESH-INTERVAL` and `X-PUBLISHED-TTL`), but most apps follow their own settings. For changes that must show up immediately, users should open this calendar directly. Two-way sync with near-instant updates would need a CalDAV server, which this component does not cover.
742
+
743
+ Without the feed endpoints, turn the feature off: `features: { subscriptions: false }`.