@redvars/peacock 4.4.0 → 4.5.0

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 (236) hide show
  1. package/dist/{BaseField-Cj2rNVeC.js → BaseField-BbOj212R.js} +3 -3
  2. package/dist/{BaseField-Cj2rNVeC.js.map → BaseField-BbOj212R.js.map} +1 -1
  3. package/dist/{BaseInput-CSOLv2-i.js → BaseInput-Cv03GZLu.js} +2 -2
  4. package/dist/{BaseInput-CSOLv2-i.js.map → BaseInput-Cv03GZLu.js.map} +1 -1
  5. package/dist/ai-badge.js +2 -2
  6. package/dist/ai-summary.js +2 -2
  7. package/dist/alert.js +2 -2
  8. package/dist/anchor-nav.js +2 -2
  9. package/dist/app-shell.js +2 -2
  10. package/dist/assistant-panel.js +2 -2
  11. package/dist/assistant-step.js +2 -2
  12. package/dist/assistant-steps.js +2 -2
  13. package/dist/avatar-group.js +2 -2
  14. package/dist/banner.js +2 -2
  15. package/dist/{base-progress-DduJjUeq.js → base-progress-CqsyiVOV.js} +2 -2
  16. package/dist/{base-progress-DduJjUeq.js.map → base-progress-CqsyiVOV.js.map} +1 -1
  17. package/dist/bottom-sheet.js +2 -2
  18. package/dist/breadcrumb.js +2 -2
  19. package/dist/calendar-column-view.js +648 -30
  20. package/dist/calendar-column-view.js.map +1 -1
  21. package/dist/calendar-drag-IXMPZrTN.js +344 -0
  22. package/dist/calendar-drag-IXMPZrTN.js.map +1 -0
  23. package/dist/{calendar-event-_OYdAT3c.js → calendar-event-BQChlMXy.js} +15 -4
  24. package/dist/calendar-event-BQChlMXy.js.map +1 -0
  25. package/dist/calendar-header-DVrfThwr.js +59 -0
  26. package/dist/calendar-header-DVrfThwr.js.map +1 -0
  27. package/dist/calendar-month-view.js +311 -21
  28. package/dist/calendar-month-view.js.map +1 -1
  29. package/dist/calendar-timeline.js +1877 -0
  30. package/dist/calendar-timeline.js.map +1 -0
  31. package/dist/calendar.js +224 -62
  32. package/dist/calendar.js.map +1 -1
  33. package/dist/{canvas-base-Bfpv5_HJ.js → canvas-base-BjiU3Ecl.js} +2 -2
  34. package/dist/{canvas-base-Bfpv5_HJ.js.map → canvas-base-BjiU3Ecl.js.map} +1 -1
  35. package/dist/carousel.js +2 -2
  36. package/dist/{cartesian-chart-SnqFbbXV.js → cartesian-chart-iE3cmeGF.js} +2 -2
  37. package/dist/{cartesian-chart-SnqFbbXV.js.map → cartesian-chart-iE3cmeGF.js.map} +1 -1
  38. package/dist/{cb-group-base-DZIzMlen.js → cb-group-base-CWctDJvy.js} +2 -2
  39. package/dist/{cb-group-base-DZIzMlen.js.map → cb-group-base-CWctDJvy.js.map} +1 -1
  40. package/dist/cb-group.js +3 -3
  41. package/dist/cb-rule.js +3 -3
  42. package/dist/chart-area.js +4 -4
  43. package/dist/chart-bar.js +4 -4
  44. package/dist/{chart-base-C2N0WQLI.js → chart-base-CDyVDmz7.js} +2 -2
  45. package/dist/{chart-base-C2N0WQLI.js.map → chart-base-CDyVDmz7.js.map} +1 -1
  46. package/dist/chart-doughnut.js +3 -3
  47. package/dist/chart-line.js +4 -4
  48. package/dist/chart-pie.js +3 -3
  49. package/dist/chat-event.js +2 -2
  50. package/dist/chat-message.js +2 -2
  51. package/dist/chat-thread.js +2 -2
  52. package/dist/checkbox-group.js +3 -3
  53. package/dist/checkbox.js +3 -3
  54. package/dist/chip-set.js +2 -2
  55. package/dist/chip.js +2 -2
  56. package/dist/circular-progress.js +3 -3
  57. package/dist/citation.js +2 -2
  58. package/dist/code-editor.js +3 -3
  59. package/dist/code-highlighter.js +2 -2
  60. package/dist/color-field.js +4 -4
  61. package/dist/color-picker.js +2 -2
  62. package/dist/command-palette.js +2 -2
  63. package/dist/comment-composer.js +4 -4
  64. package/dist/condition-builder.js +3 -3
  65. package/dist/confirm-dialog.js +2 -2
  66. package/dist/copy-button.js +2 -2
  67. package/dist/currency-field.js +4 -4
  68. package/dist/custom-elements-jsdocs.json +52 -129
  69. package/dist/custom-elements.json +3109 -5
  70. package/dist/{date-vFrYT1S9.js → date-cfPx3alz.js} +20 -3
  71. package/dist/date-cfPx3alz.js.map +1 -0
  72. package/dist/date-field.js +8 -8
  73. package/dist/date-picker.js +4 -4
  74. package/dist/date-range-field.js +8 -8
  75. package/dist/datetime-field.js +7 -7
  76. package/dist/dependency-map.js +3 -3
  77. package/dist/description-item.js +2 -2
  78. package/dist/description-list.js +2 -2
  79. package/dist/{diagram-W_Kddt7I.js → diagram-D2aM93kf.js} +2 -2
  80. package/dist/{diagram-W_Kddt7I.js.map → diagram-D2aM93kf.js.map} +1 -1
  81. package/dist/diagram-controls.js +2 -2
  82. package/dist/diagram-minimap.js +2 -2
  83. package/dist/diagram.js +4 -4
  84. package/dist/diff-viewer.js +2 -2
  85. package/dist/discussion-activity.js +2 -2
  86. package/dist/discussion-comment.js +2 -2
  87. package/dist/discussion.js +4 -4
  88. package/dist/{document-editor-dBgmcyUW.js → document-editor-BS6al7Hq.js} +2 -2
  89. package/dist/{document-editor-dBgmcyUW.js.map → document-editor-BS6al7Hq.js.map} +1 -1
  90. package/dist/document-editor.js +3 -3
  91. package/dist/draft-card.js +2 -2
  92. package/dist/erd.js +3 -3
  93. package/dist/{event-manager-CWAWPOUE.js → event-manager-KGMT2x2Q.js} +10 -8
  94. package/dist/event-manager-KGMT2x2Q.js.map +1 -0
  95. package/dist/file-upload.js +3 -3
  96. package/dist/filter-bar.js +4 -4
  97. package/dist/flow.js +4 -4
  98. package/dist/form.js +2 -2
  99. package/dist/{generative-view-CfW6yMpY.js → generative-view-DsSOPf26.js} +2 -2
  100. package/dist/{generative-view-CfW6yMpY.js.map → generative-view-DsSOPf26.js.map} +1 -1
  101. package/dist/generative-view.js +3 -3
  102. package/dist/html-editor.js +4 -4
  103. package/dist/{i18n-controller-DNAjVSIP.js → i18n-controller-BTeChxE0.js} +2 -2
  104. package/dist/{i18n-controller-DNAjVSIP.js.map → i18n-controller-BTeChxE0.js.map} +1 -1
  105. package/dist/image.js +2 -2
  106. package/dist/index.js +26 -23
  107. package/dist/index.js.map +1 -1
  108. package/dist/inline-edit.js +2 -2
  109. package/dist/input.js +3 -3
  110. package/dist/json-viewer.js +2 -2
  111. package/dist/kanban.js +2 -2
  112. package/dist/kbd.js +2 -2
  113. package/dist/linear-progress.js +3 -3
  114. package/dist/listbox.js +2 -2
  115. package/dist/loader-full.js +13 -13
  116. package/dist/loader.js +17 -13
  117. package/dist/loader.js.map +1 -1
  118. package/dist/markdown-editor.js +4 -4
  119. package/dist/mention-input.js +4 -4
  120. package/dist/modal.js +2 -2
  121. package/dist/navigation-bar.js +2 -2
  122. package/dist/navigation-drawer.js +2 -2
  123. package/dist/navigation-rail.js +2 -2
  124. package/dist/notification-center.js +2 -2
  125. package/dist/number-field.js +4 -4
  126. package/dist/page-header.js +2 -2
  127. package/dist/pagination.js +2 -2
  128. package/dist/password-field.js +4 -4
  129. package/dist/password-rules.js +2 -2
  130. package/dist/phone-field.js +4 -4
  131. package/dist/{picker-field-Mi7_hbo8.js → picker-field-DmXYPvbF.js} +3 -3
  132. package/dist/{picker-field-Mi7_hbo8.js.map → picker-field-DmXYPvbF.js.map} +1 -1
  133. package/dist/pin-input.js +4 -4
  134. package/dist/presence-indicator.js +2 -2
  135. package/dist/prompt-input.js +4 -4
  136. package/dist/radio.js +3 -3
  137. package/dist/{range-utils-BoKOhxVX.js → range-utils-DZe96GnO.js} +2 -2
  138. package/dist/{range-utils-BoKOhxVX.js.map → range-utils-DZe96GnO.js.map} +1 -1
  139. package/dist/rating.js +3 -3
  140. package/dist/redvars-loader.js +2 -2
  141. package/dist/relative-time.js +2 -2
  142. package/dist/resizable-panels.js +2 -2
  143. package/dist/{rich-text-input-O1ku1q-J.js → rich-text-input-BCZ46UF8.js} +3 -3
  144. package/dist/{rich-text-input-O1ku1q-J.js.map → rich-text-input-BCZ46UF8.js.map} +1 -1
  145. package/dist/{schema-BWH1ANdE.js → schema-D0PCeIEA.js} +2 -2
  146. package/dist/{schema-BWH1ANdE.js.map → schema-D0PCeIEA.js.map} +1 -1
  147. package/dist/search.js +3 -3
  148. package/dist/select.js +4 -4
  149. package/dist/side-sheet.js +2 -2
  150. package/dist/signature-pad.js +3 -3
  151. package/dist/site-header.js +2 -2
  152. package/dist/slider.js +3 -3
  153. package/dist/snackbar.js +2 -2
  154. package/dist/sparkline.js +2 -2
  155. package/dist/split-button.js +2 -2
  156. package/dist/src/__internal/i18n/strings.d.ts +16 -0
  157. package/dist/src/__internal/utils/date.d.ts +5 -0
  158. package/dist/src/calendar/base-event.d.ts +5 -0
  159. package/dist/src/calendar/calendar-column-view.d.ts +65 -1
  160. package/dist/src/calendar/calendar-drag.d.ts +91 -0
  161. package/dist/src/calendar/calendar-header.d.ts +28 -0
  162. package/dist/src/calendar/calendar-month-view.d.ts +39 -1
  163. package/dist/src/calendar/calendar.d.ts +83 -6
  164. package/dist/src/calendar/index.d.ts +2 -2
  165. package/dist/src/calendar/types.d.ts +32 -0
  166. package/dist/src/calendar/utils.d.ts +53 -0
  167. package/dist/src/calendar-timeline/calendar-timeline.d.ts +287 -0
  168. package/dist/src/calendar-timeline/index.d.ts +3 -0
  169. package/dist/src/calendar-timeline/layout.d.ts +39 -0
  170. package/dist/src/calendar-timeline/types.d.ts +60 -0
  171. package/dist/src/index.d.ts +4 -2
  172. package/dist/stat.js +2 -2
  173. package/dist/status-indicator.js +2 -2
  174. package/dist/step.js +2 -2
  175. package/dist/stepper.js +2 -2
  176. package/dist/{strings-BpCoUL0V.js → strings-DeiQWMd9.js} +18 -1
  177. package/dist/strings-DeiQWMd9.js.map +1 -0
  178. package/dist/svg.js +2 -2
  179. package/dist/switch.js +3 -3
  180. package/dist/table.js +2 -2
  181. package/dist/test/calendar-timeline.test.d.ts +1 -0
  182. package/dist/textarea.js +4 -4
  183. package/dist/time-field.js +7 -7
  184. package/dist/time-picker.js +4 -4
  185. package/dist/timeline-item.js +2 -2
  186. package/dist/timeline.js +2 -2
  187. package/dist/{toggle-base-BRNNka2o.js → toggle-base-BtjRAZ5z.js} +2 -2
  188. package/dist/{toggle-base-BRNNka2o.js.map → toggle-base-BtjRAZ5z.js.map} +1 -1
  189. package/dist/tour.js +2 -2
  190. package/dist/transfer-list.js +3 -3
  191. package/dist/tree-chart.js +3 -3
  192. package/dist/tree-item.js +2 -2
  193. package/dist/tree.js +2 -2
  194. package/dist/tsconfig.tsbuildinfo +1 -1
  195. package/dist/typing-indicator.js +2 -2
  196. package/dist/url-field.js +4 -4
  197. package/dist/user-menu.js +2 -2
  198. package/dist/{utils-D92ldd1V.js → utils-DcvLgexs.js} +116 -19
  199. package/dist/utils-DcvLgexs.js.map +1 -0
  200. package/dist/{video-DBdRuyh4.js → video-DPjOBk6I.js} +2 -2
  201. package/dist/{video-DBdRuyh4.js.map → video-DPjOBk6I.js.map} +1 -1
  202. package/dist/video.js +3 -3
  203. package/dist/virtual-list.js +2 -2
  204. package/dist/workflow-timeline.js +2 -2
  205. package/dist/workflow.js +3 -3
  206. package/dist/workspace-switcher.js +2 -2
  207. package/package.json +1 -1
  208. package/readme.md +1 -0
  209. package/src/__internal/i18n/strings.ts +25 -0
  210. package/src/__internal/utils/date.ts +19 -0
  211. package/src/calendar/_calendar-header.scss +33 -0
  212. package/src/calendar/base-event.ts +19 -2
  213. package/src/calendar/calendar-column-view.scss +174 -2
  214. package/src/calendar/calendar-column-view.ts +665 -37
  215. package/src/calendar/calendar-drag.ts +403 -0
  216. package/src/calendar/calendar-header.ts +78 -0
  217. package/src/calendar/calendar-month-view.scss +89 -0
  218. package/src/calendar/calendar-month-view.ts +289 -23
  219. package/src/calendar/calendar.scss +2 -27
  220. package/src/calendar/calendar.ts +264 -62
  221. package/src/calendar/event-manager.ts +11 -7
  222. package/src/calendar/index.ts +8 -2
  223. package/src/calendar/types.ts +35 -0
  224. package/src/calendar/utils.ts +160 -20
  225. package/src/calendar-timeline/calendar-timeline.scss +554 -0
  226. package/src/calendar-timeline/calendar-timeline.ts +1528 -0
  227. package/src/calendar-timeline/index.ts +14 -0
  228. package/src/calendar-timeline/layout.ts +129 -0
  229. package/src/calendar-timeline/types.ts +65 -0
  230. package/src/index.ts +18 -0
  231. package/src/loader.ts +4 -0
  232. package/dist/calendar-event-_OYdAT3c.js.map +0 -1
  233. package/dist/date-vFrYT1S9.js.map +0 -1
  234. package/dist/event-manager-CWAWPOUE.js.map +0 -1
  235. package/dist/strings-BpCoUL0V.js.map +0 -1
  236. package/dist/utils-D92ldd1V.js.map +0 -1
@@ -0,0 +1,1528 @@
1
+ import { LitElement, html, nothing, type PropertyValues } from 'lit';
2
+ import { property, state } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import {
5
+ addDays,
6
+ addMonths,
7
+ atWallMinutes,
8
+ clamp,
9
+ formatEventWhen,
10
+ formatTimeRange,
11
+ isAllDayRange,
12
+ MINUTE_MS,
13
+ nextDay,
14
+ onActivateKey,
15
+ rangesOverlap,
16
+ snapTime,
17
+ startOfDay,
18
+ toZonedWallClock,
19
+ } from '@/calendar/utils.js';
20
+ import {
21
+ CalendarDragController,
22
+ dragByDays,
23
+ type CalendarDragAction,
24
+ type DragPoint,
25
+ } from '@/calendar/calendar-drag.js';
26
+ import { renderCalendarHeader } from '@/calendar/calendar-header.js';
27
+ import IndividualComponent from '@/IndividualComponent.js';
28
+ import { I18nController } from '@/__internal/i18n/i18n-controller.js';
29
+ import { isRtl } from '@/__internal/i18n/locale.js';
30
+ import type { PeacockStrings } from '@/__internal/i18n/strings.js';
31
+ import {
32
+ dateToIso,
33
+ isoToDate,
34
+ weekStart,
35
+ weekendDays,
36
+ type WeekDay,
37
+ } from '@/__internal/utils/date.js';
38
+ import {
39
+ DAY_MINUTES,
40
+ assignLanes,
41
+ axisLength,
42
+ axisMinutes,
43
+ dateAtAxis,
44
+ dayOfRange,
45
+ eventSpan,
46
+ rangeEnd,
47
+ viewRange,
48
+ type AxisSpan,
49
+ type TimelineRange,
50
+ } from './layout.js';
51
+ import type {
52
+ CalendarTimelineEvent,
53
+ CalendarTimelineEventAddDetail,
54
+ CalendarTimelineEventChangeDetail,
55
+ CalendarTimelineGroupToggleDetail,
56
+ CalendarTimelineResource,
57
+ CalendarTimelineViewType,
58
+ } from './types.js';
59
+ import styles from './calendar-timeline.scss';
60
+
61
+ export type {
62
+ CalendarTimelineEvent,
63
+ CalendarTimelineEventAddDetail,
64
+ CalendarTimelineEventChangeAction,
65
+ CalendarTimelineEventChangeDetail,
66
+ CalendarTimelineGroupToggleDetail,
67
+ CalendarTimelineResource,
68
+ CalendarTimelineViewType,
69
+ } from './types.js';
70
+
71
+ /** Detail of `date-change`. */
72
+ export type CalendarTimelineDateChangeDetail = {
73
+ /** The new context date. */
74
+ date: Date;
75
+ /** The same date as an ISO string, `YYYY-MM-DD`. */
76
+ value: string;
77
+ };
78
+
79
+ /** An event laid out in its row. */
80
+ interface PlacedEvent extends AxisSpan {
81
+ data: CalendarTimelineEvent;
82
+ start: Date;
83
+ end: Date;
84
+ lane: number;
85
+ }
86
+
87
+ /** A resource's row, laid out. */
88
+ interface LaidOutRow {
89
+ resource: CalendarTimelineResource;
90
+ events: PlacedEvent[];
91
+ lanes: number;
92
+ }
93
+
94
+ /** The rows of one `group-by` value: indices into the laid-out rows, in order. */
95
+ interface RowGroup {
96
+ key: string;
97
+ rows: number[];
98
+ }
99
+
100
+ /** A press that may become a drag. */
101
+ interface GridPress {
102
+ action: CalendarDragAction;
103
+ /** The event pressed; none when adding. */
104
+ event?: PlacedEvent;
105
+ /** The index of the row pressed. */
106
+ row: number;
107
+ /** The time under the press: the day in day views. */
108
+ time: Date;
109
+ }
110
+
111
+ /** Where a drag would put an event, or the range it would add. */
112
+ interface GridPreview {
113
+ action: CalendarDragAction;
114
+ /** The dragged event's object from `events`; none when adding. */
115
+ data?: CalendarTimelineEvent;
116
+ /** The index of the row it would land in. */
117
+ row: number;
118
+ title: string;
119
+ color?: string;
120
+ start: Date;
121
+ end: Date;
122
+ }
123
+
124
+ /** Events shorter than this have no handle at their start in hour views, so there is room to grab them. */
125
+ const START_HANDLE_MIN_MS = 30 * MINUTE_MS;
126
+
127
+ /**
128
+ * Applies an `event-change` to an `events` array the way the timeline does, returning a new array in
129
+ * which the event is replaced by a copy with the new `start`, `end` and `resourceId`. The event is
130
+ * found by identity, else by `id`. The copy is made with object spread, so give the timeline plain
131
+ * objects. Use it to apply a change you canceled, for example once the server has accepted it.
132
+ */
133
+ export function applyCalendarTimelineChange<T extends CalendarTimelineEvent>(
134
+ events: readonly T[],
135
+ change: Pick<
136
+ CalendarTimelineEventChangeDetail,
137
+ 'event' | 'start' | 'end' | 'resourceId'
138
+ >,
139
+ ): T[] {
140
+ const { id } = change.event;
141
+ let index = events.indexOf(change.event as T);
142
+ if (index < 0 && id !== undefined && id !== null) {
143
+ index = events.findIndex(event => event.id === id);
144
+ }
145
+ return events.map((event, i) =>
146
+ i === index
147
+ ? {
148
+ ...event,
149
+ start: change.start,
150
+ end: change.end,
151
+ resourceId: change.resourceId,
152
+ }
153
+ : event,
154
+ );
155
+ }
156
+
157
+ /**
158
+ * @label Calendar Timeline
159
+ * @tag wc-calendar-timeline
160
+ * @rawTag calendar-timeline
161
+ * @summary Resources such as people, rooms or machines as rows against a horizontal time axis, with events that can be dragged between times and rows.
162
+ *
163
+ * @overview
164
+ * <p>Pass the rows as <code>resources</code> (<code>{ id, title, supportingText? }</code>) and the
165
+ * events as <code>events</code>: the calendar's event objects with a <code>resourceId</code>. An
166
+ * event whose <code>resourceId</code> matches no resource is not shown, and <code>end</code> is
167
+ * exclusive, as in <code>wc-calendar</code>.</p>
168
+ * <p>Each entry of <code>available-views</code> is <code>{ value, label?, slot, days? }</code>:
169
+ * <code>slot</code> is what a column stands for, <code>hour</code> or <code>day</code>, and without
170
+ * <code>days</code> the view is a calendar month. The defaults are <code>day</code> (24 hour
171
+ * columns), <code>week</code> (7 day columns from the week's first day) and <code>month</code>. In
172
+ * hour views an event is drawn from its start to its end; in day views it covers the days it
173
+ * touches. Events that overlap in a row stack in lanes. Columns share the width, never narrower
174
+ * than <code>--calendar-timeline-hour-width</code> or <code>--calendar-timeline-day-width</code>, and a
175
+ * range that does not fit scrolls sideways under a header and a resource column that stay in
176
+ * place. A line marks the current time.</p>
177
+ * <p>The header, <code>date</code>, <code>contextDate</code>, <code>view</code>,
178
+ * <code>first-day</code>, <code>timezone</code>, <code>locale</code>, <code>previous()</code>,
179
+ * <code>next()</code> and <code>today()</code> work as in <code>wc-calendar</code>, so the two can
180
+ * share a view switcher and a date.</p>
181
+ * <p>With <code>editable</code>, people drag an event to another time or another resource's row,
182
+ * and drag its edges to resize it: in steps of <code>minute-step</code> minutes in hour views, by
183
+ * whole days in day views. Each drop fires the cancelable <code>event-change</code>, with the new
184
+ * <code>resourceId</code>; unless it is canceled, the timeline replaces <code>events</code> with a new
185
+ * array holding a copy of the event. To confirm a change with a server first, cancel the event and
186
+ * apply it later with <code>applyCalendarTimelineChange()</code>. With <code>addable</code>, dragging
187
+ * across empty time in a row, or clicking it, fires <code>event-add</code>; the range stays marked
188
+ * as a new event until <code>events</code> changes or <code>clearPlaceholder()</code> is called.
189
+ * An event with <code>editable: false</code> stays put, and <code>events-readonly</code> turns
190
+ * editing off.</p>
191
+ * <p><code>group-by</code> names a resource field, such as <code>team</code>, to group the rows by.
192
+ * Groups keep the order they first appear in, and resources without the field form an
193
+ * "(Empty)" group. Each group has a header row whose button collapses or expands it and fires
194
+ * <code>group-toggle</code>; <code>collapsed-groups</code> holds the keys of the collapsed groups,
195
+ * their values as strings. A collapsed group's header shows its events as thin bars, so its busy
196
+ * times stay in sight. Events can be dragged between rows of different groups.</p>
197
+ * <p>The timeline is a table: a row per resource, with the resource's title as its row header and its
198
+ * events in its cell. Events are buttons, named with their title, resource and time, that fire
199
+ * <code>event-click</code>. Changes are announced to screen readers. Dragging needs a pointer, so
200
+ * offer another way to change an event too, such as the dialog <code>event-click</code> opens.</p>
201
+ *
202
+ * @cssprop --calendar-timeline-resource-width - Width of the resource column. Defaults to `12rem`.
203
+ * @cssprop --calendar-timeline-hour-width - Narrowest an hour column gets before the timeline scrolls. Defaults to `4rem`.
204
+ * @cssprop --calendar-timeline-day-width - Narrowest a day column gets before the timeline scrolls. Defaults to `3rem`.
205
+ * @cssprop --calendar-timeline-lane-height - Height of each lane of events in a row. Defaults to `2rem`.
206
+ * @cssprop --calendar-timeline-border-color - Color of the grid lines.
207
+ * @cssprop --calendar-timeline-event-bg-color - Background color of events without a `color`.
208
+ * @cssprop --calendar-timeline-event-border-color - Start border color of events without a `color`.
209
+ *
210
+ * @fires {CustomEvent<{event: CalendarTimelineEvent}>} event-click - An event was clicked, or chosen with Enter or Space. Detail contains `{ event }`. Not fired with `events-readonly`.
211
+ * @fires {CustomEvent<{view: string}>} view-change - The view changed. Detail contains `{ view }`.
212
+ * @fires {CustomEvent<CalendarTimelineDateChangeDetail>} date-change - The context date changed. Detail contains `{ date, value }`: the `Date` and its ISO string.
213
+ * @fires {CustomEvent<CalendarTimelineEventChangeDetail>} event-change - An event was dragged to a new time or row (`action: 'move'`), or had its start or end dragged (`action: 'resize'`). Detail contains `{ event, start, end, resourceId, action }`, where `event` is the object from `events` as it was. Cancelable: cancel it to keep the event where it was. Only with `editable`.
214
+ * @fires {CustomEvent<CalendarTimelineEventAddDetail>} event-add - Empty time in a row was dragged across or clicked. Detail contains `{ start, end, allDay, resourceId }`. Only with `addable`.
215
+ * @fires {CustomEvent<CalendarTimelineGroupToggleDetail>} group-toggle - A group was collapsed or expanded with its header's button. Detail contains `{ group, expanded }`.
216
+ *
217
+ * @example
218
+ * ```html
219
+ * <wc-calendar-timeline id="rooms" view="day" resource-label="Rooms" editable addable style="height: 24rem"></wc-calendar-timeline>
220
+ * <script>
221
+ * const rooms = document.getElementById('rooms');
222
+ * rooms.resources = [
223
+ * { id: 'aspen', title: 'Aspen', supportingText: '8 seats' },
224
+ * { id: 'birch', title: 'Birch', supportingText: '4 seats' },
225
+ * ];
226
+ * rooms.events = [
227
+ * { id: 1, resourceId: 'aspen', title: 'Design review', start: new Date(2026, 10, 4, 9), end: new Date(2026, 10, 4, 10) },
228
+ * ];
229
+ * rooms.addEventListener('event-change', event => console.log(event.detail));
230
+ * </script>
231
+ * ```
232
+ */
233
+ @IndividualComponent
234
+ export class CalendarTimeline extends LitElement {
235
+ // ── Static
236
+
237
+ static styles = [styles];
238
+
239
+ // ── Properties
240
+
241
+ /** The rows, in order. */
242
+ @property({ attribute: false })
243
+ resources: CalendarTimelineResource[] = [];
244
+
245
+ /** The events. Each one is shown in the row of the resource its `resourceId` names. */
246
+ @property({ attribute: false })
247
+ events: CalendarTimelineEvent[] = [];
248
+
249
+ /**
250
+ * The views offered in the header. A view without a `label` shows Peacock's `day`, `week` or
251
+ * `month` string for those values, else its `value`.
252
+ */
253
+ @property({ type: Array, attribute: 'available-views' })
254
+ availableViews: CalendarTimelineViewType[] = [
255
+ { value: 'day', slot: 'hour', days: 1 },
256
+ { value: 'week', slot: 'day', days: 7 },
257
+ { value: 'month', slot: 'day' },
258
+ ];
259
+
260
+ /** The view shown: the `value` of one of `availableViews`. */
261
+ @property({ type: String, reflect: true })
262
+ view: string = 'day';
263
+
264
+ /**
265
+ * The date the view shows, as an ISO string (`YYYY-MM-DD`). Kept in step with `contextDate`.
266
+ * Defaults to today.
267
+ */
268
+ @property({ type: String })
269
+ date: string = '';
270
+
271
+ /** The date the view shows, as a `Date`. Kept in step with `date`. */
272
+ @property({ type: Object, attribute: false })
273
+ contextDate: Date | null = null;
274
+
275
+ /** First day of the week, `0` (Sunday) to `6` (Saturday). Defaults to the locale's week start. */
276
+ @property({ type: Number, attribute: 'first-day' })
277
+ firstDay?: number;
278
+
279
+ /** Header of the resource column, such as "Rooms" or "People". Defaults to "Resources". */
280
+ @property({ type: String, attribute: 'resource-label' })
281
+ resourceLabel: string = '';
282
+
283
+ /**
284
+ * A resource field to group the rows by, such as `team`. Each group gets a header row that
285
+ * collapses it. Groups keep the order they first appear in.
286
+ */
287
+ @property({ type: String, attribute: 'group-by' })
288
+ groupBy: string = '';
289
+
290
+ /** Keys of the collapsed groups: their `group-by` values as strings (`""` for resources without one). */
291
+ @property({ type: Array, attribute: 'collapsed-groups' })
292
+ collapsedGroups: string[] = [];
293
+
294
+ /** Events are shown but cannot be clicked or focused, and `event-click` does not fire. */
295
+ @property({ type: Boolean, attribute: 'events-readonly' })
296
+ eventsReadonly: boolean = false;
297
+
298
+ /**
299
+ * People can drag events to other times and rows, and drag their edges to resize them. Each drop
300
+ * fires the cancelable `event-change`. An event with `editable: false` stays put.
301
+ */
302
+ @property({ type: Boolean, reflect: true })
303
+ editable: boolean = false;
304
+
305
+ /**
306
+ * Dragging across empty time in a row, or clicking it, fires `event-add` with the range and
307
+ * marks it as a new event until `events` changes.
308
+ */
309
+ @property({ type: Boolean, reflect: true })
310
+ addable: boolean = false;
311
+
312
+ /** Minutes that dragging moves, resizes and draws events by in hour views. Defaults to 15. */
313
+ @property({ type: Number, attribute: 'minute-step' })
314
+ minuteStep: number = 15;
315
+
316
+ /** Length in minutes of an event added by clicking empty time in an hour view. Defaults to 60. */
317
+ @property({ type: Number, attribute: 'default-duration' })
318
+ defaultDuration: number = 60;
319
+
320
+ /** Shows a progress bar and marks the timeline busy while events load. */
321
+ @property({ type: Boolean, reflect: true })
322
+ loading: boolean = false;
323
+
324
+ /** IANA time zone the current time is shown in, for example `America/New_York`. Defaults to the browser's. */
325
+ @property({ type: String })
326
+ timezone: string = '';
327
+
328
+ /**
329
+ * Locale for day names and times. Defaults to the nearest `lang`, then the browser language.
330
+ */
331
+ @property({ type: String })
332
+ locale: string = '';
333
+
334
+ /** Overrides Peacock's strings for this instance only. */
335
+ @property({ attribute: false }) strings?: Partial<PeacockStrings>;
336
+
337
+ // ── State
338
+
339
+ /** Now, as wall-clock time in `timezone`. */
340
+ @state()
341
+ private _currentTime: Date = new Date();
342
+
343
+ /** The drag in progress, where it would put its event. */
344
+ @state()
345
+ private _preview: GridPreview | null = null;
346
+
347
+ /** The range of the last `event-add`, marked as a new event until the app adds it. */
348
+ @state()
349
+ private _placeholder: CalendarTimelineEventAddDetail | null = null;
350
+
351
+ // ── Private fields
352
+
353
+ /** Peacock's strings and the resolved locale. */
354
+ private readonly _i18n = new I18nController(this);
355
+
356
+ /** The days shown. */
357
+ private _range: TimelineRange = { start: startOfDay(new Date()), days: 1 };
358
+
359
+ /** The rows, laid out before each render, in the order of `resources`. */
360
+ private _rows: LaidOutRow[] = [];
361
+
362
+ /** The rows by `group-by` value, when grouped. */
363
+ private _groups: RowGroup[] | null = null;
364
+
365
+ /** Whether to scroll the axis to now, or to the morning, after the next render. */
366
+ private _scrollPending = true;
367
+
368
+ private readonly _drag = new CalendarDragController<GridPress>(this, {
369
+ lift: () => this._blurFocused(),
370
+ move: (press, point) => this._follow(press, point),
371
+ drop: (press, point) => this._drop(press, point),
372
+ cancel: () => {
373
+ this._preview = null;
374
+ },
375
+ tap: press => this._tap(press),
376
+ scrollers: () => [this.renderRoot.querySelector<HTMLElement>('.scroller')],
377
+ });
378
+
379
+ // ── Lifecycle
380
+
381
+ override connectedCallback() {
382
+ super.connectedCallback();
383
+ this._currentTime = this._now();
384
+ if (!this.contextDate && !isoToDate(this.date)) {
385
+ this.contextDate = this._currentTime;
386
+ }
387
+ // Capture, so a press clears the placeholder before it starts a drag of its own.
388
+ this.addEventListener('pointerdown', this._handlePointerDown, true);
389
+ this.addEventListener('keydown', this._handleKeyDown);
390
+ // Clicking empty time leaves focus on the page, so Escape is also heard there.
391
+ window.addEventListener('keydown', this._handleWindowKeyDown);
392
+ }
393
+
394
+ override disconnectedCallback() {
395
+ super.disconnectedCallback();
396
+ this.removeEventListener('pointerdown', this._handlePointerDown, true);
397
+ this.removeEventListener('keydown', this._handleKeyDown);
398
+ window.removeEventListener('keydown', this._handleWindowKeyDown);
399
+ }
400
+
401
+ override willUpdate(changed: PropertyValues<this>) {
402
+ super.willUpdate(changed);
403
+ if (changed.has('timezone')) this._currentTime = this._now();
404
+ this._syncDate(changed);
405
+
406
+ const view = this._view;
407
+ const previous = this._range;
408
+ if (view) {
409
+ this._range = viewRange(
410
+ view,
411
+ this.contextDate ?? this._currentTime,
412
+ this._weekStart(),
413
+ );
414
+ }
415
+ const rangeChanged =
416
+ this._range.start.valueOf() !== previous.start.valueOf() ||
417
+ this._range.days !== previous.days;
418
+ if (rangeChanged || changed.has('view') || changed.has('availableViews')) {
419
+ this._scrollPending = true;
420
+ }
421
+ this._rows = this._layout();
422
+ this._groups = this.groupBy ? this._groupsOf(this._rows) : null;
423
+
424
+ this._drag.enabled = this.addable || this._eventsEditable();
425
+ // A drag cannot outlive the days or rows it started on, or editing being turned off.
426
+ if (
427
+ this._drag.pressing &&
428
+ (rangeChanged ||
429
+ changed.has('view') ||
430
+ changed.has('resources') ||
431
+ changed.has('groupBy') ||
432
+ changed.has('collapsedGroups') ||
433
+ changed.has('editable') ||
434
+ changed.has('addable') ||
435
+ changed.has('eventsReadonly'))
436
+ ) {
437
+ this._drag.abort();
438
+ }
439
+ // The new event has been added, or the person has moved on.
440
+ if (
441
+ this._placeholder &&
442
+ (changed.has('events') ||
443
+ changed.has('resources') ||
444
+ changed.has('view') ||
445
+ changed.has('date') ||
446
+ changed.has('contextDate') ||
447
+ (changed.has('addable') && !this.addable))
448
+ ) {
449
+ this._placeholder = null;
450
+ }
451
+ }
452
+
453
+ override updated() {
454
+ if (this._scrollPending) {
455
+ this._scrollPending = false;
456
+ this._scrollAxis();
457
+ }
458
+ }
459
+
460
+ // ── Public methods
461
+
462
+ /** Moves back one period: the view's number of days, or a month. */
463
+ previous() {
464
+ this._shift(-1);
465
+ }
466
+
467
+ /** Moves forward one period: the view's number of days, or a month. */
468
+ next() {
469
+ this._shift(1);
470
+ }
471
+
472
+ /** Moves the view to today, in `timezone`. */
473
+ today() {
474
+ this._currentTime = this._now();
475
+ this._setContextDate(this._currentTime);
476
+ }
477
+
478
+ /**
479
+ * Removes the new event marked after `event-add`, for when adding it is canceled. It also goes
480
+ * when `events` changes.
481
+ */
482
+ clearPlaceholder() {
483
+ this._placeholder = null;
484
+ }
485
+
486
+ // ── Private methods
487
+
488
+ /** The entry of `availableViews` matching `view`. */
489
+ private get _view(): CalendarTimelineViewType | undefined {
490
+ return this.availableViews.find(view => view.value === this.view);
491
+ }
492
+
493
+ /** What a column of the current view stands for. */
494
+ private get _slot(): CalendarTimelineViewType['slot'] {
495
+ return this._view?.slot === 'day' ? 'day' : 'hour';
496
+ }
497
+
498
+ /** `minuteStep` when it is a whole number of minutes in a day, else 15. */
499
+ private get _step(): number {
500
+ const step = Math.round(this.minuteStep);
501
+ return Number.isFinite(step) && step >= 1 ? Math.min(step, 1440) : 15;
502
+ }
503
+
504
+ /** `defaultDuration` when it is a positive number of minutes, else 60. */
505
+ private get _duration(): number {
506
+ const minutes = Math.round(this.defaultDuration);
507
+ return Number.isFinite(minutes) && minutes >= 1 ? minutes : 60;
508
+ }
509
+
510
+ /** Now, as wall-clock time in `timezone`. */
511
+ private _now(): Date {
512
+ return toZonedWallClock(new Date(), this.timezone);
513
+ }
514
+
515
+ /** Keeps `date` and `contextDate` in step; `date` wins when both changed. */
516
+ private _syncDate(changed: PropertyValues<this>) {
517
+ const current = this.contextDate ? dateToIso(this.contextDate) : '';
518
+ if (changed.has('date') && this.date && this.date !== current) {
519
+ const parsed = isoToDate(this.date);
520
+ if (parsed) {
521
+ this.contextDate = parsed;
522
+ return;
523
+ }
524
+ }
525
+ if (current && this.date !== current) {
526
+ this.date = current;
527
+ }
528
+ }
529
+
530
+ /** The week start in effect: `firstDay` when valid, else the locale's. */
531
+ private _weekStart(): WeekDay {
532
+ const day = this.firstDay;
533
+ if (
534
+ typeof day === 'number' &&
535
+ Number.isInteger(day) &&
536
+ day >= 0 &&
537
+ day <= 6
538
+ ) {
539
+ return day as WeekDay;
540
+ }
541
+ return weekStart(this._i18n.locale);
542
+ }
543
+
544
+ /** Whether events can be dragged: `editable` and not `events-readonly`. */
545
+ private _eventsEditable(): boolean {
546
+ return this.editable && !this.eventsReadonly;
547
+ }
548
+
549
+ /** Whether an event can be dragged: the timeline is editable and the event did not opt out. */
550
+ private _canEdit(event: CalendarTimelineEvent): boolean {
551
+ return this._eventsEditable() && event.editable !== false;
552
+ }
553
+
554
+ /** Each resource's events within the range, in lanes. */
555
+ private _layout(): LaidOutRow[] {
556
+ const view = this._view;
557
+ if (!view) return [];
558
+ const range = this._range;
559
+ const end = rangeEnd(range);
560
+ const byResource = new Map<string | number, CalendarTimelineEvent[]>();
561
+ (this.events ?? []).forEach(event => {
562
+ if (!rangesOverlap(event.start, event.end, range.start, end)) return;
563
+ const list = byResource.get(event.resourceId);
564
+ if (list) list.push(event);
565
+ else byResource.set(event.resourceId, [event]);
566
+ });
567
+ return (this.resources ?? []).map(resource => {
568
+ const spans = (byResource.get(resource.id) ?? []).map(data => ({
569
+ data,
570
+ start: data.start,
571
+ end: data.end,
572
+ ...eventSpan(range, view.slot, data.start, data.end),
573
+ }));
574
+ const { lanes, laneOf } = assignLanes(spans);
575
+ const events: PlacedEvent[] = spans.map(span => ({
576
+ ...span,
577
+ lane: laneOf.get(span) ?? 0,
578
+ }));
579
+ return { resource, events, lanes };
580
+ });
581
+ }
582
+
583
+ /** The rows by their `group-by` value, in the order each value first appears. */
584
+ private _groupsOf(rows: LaidOutRow[]): RowGroup[] {
585
+ const groups = new Map<string, RowGroup>();
586
+ rows.forEach((row, index) => {
587
+ const value = row.resource[this.groupBy];
588
+ const key = value === undefined || value === null ? '' : String(value);
589
+ const group = groups.get(key);
590
+ if (group) group.rows.push(index);
591
+ else groups.set(key, { key, rows: [index] });
592
+ });
593
+ return [...groups.values()];
594
+ }
595
+
596
+ /** `collapsedGroups` as strings. */
597
+ private _collapsedKeys(): string[] {
598
+ return (
599
+ Array.isArray(this.collapsedGroups) ? this.collapsedGroups : []
600
+ ).map(key => String(key));
601
+ }
602
+
603
+ /** Collapses or expands a group, and fires `group-toggle`. */
604
+ private _toggleGroup(key: string) {
605
+ const keys = this._collapsedKeys();
606
+ const expanded = keys.includes(key);
607
+ this.collapsedGroups = expanded
608
+ ? keys.filter(entry => entry !== key)
609
+ : [...keys, key];
610
+ this.dispatchEvent(
611
+ new CustomEvent<CalendarTimelineGroupToggleDetail>('group-toggle', {
612
+ detail: { group: key, expanded },
613
+ bubbles: true,
614
+ composed: true,
615
+ }),
616
+ );
617
+ }
618
+
619
+ private _shift(direction: 1 | -1) {
620
+ const view = this._view;
621
+ if (!view || !this.contextDate) return;
622
+ if (view.days) {
623
+ this._setContextDate(
624
+ addDays(this.contextDate, direction * Math.round(view.days)),
625
+ );
626
+ } else {
627
+ this._setContextDate(addMonths(this.contextDate, direction));
628
+ }
629
+ }
630
+
631
+ private _setContextDate(date: Date) {
632
+ this.contextDate = date;
633
+ this.date = dateToIso(date);
634
+ this.dispatchEvent(
635
+ new CustomEvent<CalendarTimelineDateChangeDetail>('date-change', {
636
+ detail: { date, value: this.date },
637
+ bubbles: true,
638
+ composed: true,
639
+ }),
640
+ );
641
+ }
642
+
643
+ private _changeView(value: string) {
644
+ this.view = value;
645
+ this.dispatchEvent(
646
+ new CustomEvent('view-change', {
647
+ detail: { view: value },
648
+ bubbles: true,
649
+ composed: true,
650
+ }),
651
+ );
652
+ }
653
+
654
+ /** The view's own label, else Peacock's string for the built-in views, else its value. */
655
+ private _viewLabel(view: CalendarTimelineViewType): string {
656
+ if (view.label) return view.label;
657
+ if (
658
+ view.value === 'day' ||
659
+ view.value === 'week' ||
660
+ view.value === 'month'
661
+ ) {
662
+ return this._i18n.t(view.value);
663
+ }
664
+ return view.value;
665
+ }
666
+
667
+ /** The days shown, for the header and the table's name. */
668
+ private _rangeLabel(): string {
669
+ const { locale } = this._i18n;
670
+ const { start, days } = this._range;
671
+ if (!this._view?.days) {
672
+ return new Intl.DateTimeFormat(locale, {
673
+ month: 'long',
674
+ year: 'numeric',
675
+ }).format(start);
676
+ }
677
+ if (days === 1) {
678
+ return new Intl.DateTimeFormat(locale, { dateStyle: 'full' }).format(
679
+ start,
680
+ );
681
+ }
682
+ const last = dayOfRange(this._range, days - 1);
683
+ const format = new Intl.DateTimeFormat(locale, { dateStyle: 'medium' });
684
+ try {
685
+ return format.formatRange(start, last);
686
+ } catch {
687
+ return `${format.format(start)} – ${format.format(last)}`;
688
+ }
689
+ }
690
+
691
+ /** Custom properties that colour an event with a palette `color`. */
692
+ private _colorVars(color: string | undefined): Record<string, string> {
693
+ if (!color) return {};
694
+ return {
695
+ '--calendar-timeline-event-bg-color': `var(--color-${color}-container)`,
696
+ '--calendar-timeline-event-bg-color--hover': `var(--color-inverse-${color})`,
697
+ '--calendar-timeline-event-border-color': `var(--color-${color})`,
698
+ '--calendar-timeline-event-text-color': `var(--color-on-${color}-container)`,
699
+ '--calendar-timeline-event-text-color--hover': `var(--color-on-${color})`,
700
+ };
701
+ }
702
+
703
+ private _styleMap(declarations: Record<string, string>): string {
704
+ return Object.entries(declarations)
705
+ .map(([k, v]) => `${k}:${v}`)
706
+ .join(';');
707
+ }
708
+
709
+ /** The `inset-inline-start` and `width` of something spanning `span` of the axis. */
710
+ private _position(span: AxisSpan): Record<string, string> {
711
+ const total = axisLength(this._range);
712
+ return {
713
+ 'inset-inline-start': `${(span.from / total) * 100}%`,
714
+ width: `${(Math.max(0, span.to - span.from) / total) * 100}%`,
715
+ };
716
+ }
717
+
718
+ /** When an event happens, for its accessible name and the live region. */
719
+ private _when(start: Date, end: Date): string {
720
+ return formatEventWhen(
721
+ start,
722
+ end,
723
+ this._i18n.locale,
724
+ isAllDayRange(start, end),
725
+ );
726
+ }
727
+
728
+ /** The time an event shows after its title: its times in hour views, its start in day views. */
729
+ private _timeText(start: Date, end: Date): string {
730
+ const { locale } = this._i18n;
731
+ if (this._slot === 'hour') return formatTimeRange(start, end, locale);
732
+ if (isAllDayRange(start, end)) return '';
733
+ return new Intl.DateTimeFormat(locale, { timeStyle: 'short' }).format(
734
+ start,
735
+ );
736
+ }
737
+
738
+ /**
739
+ * Reads `message` in the live region. Its text is set directly, so an announcement does not
740
+ * render the timeline again.
741
+ */
742
+ private _announce(message: string) {
743
+ const region = this.renderRoot.querySelector('[role="status"]');
744
+ if (!region) return;
745
+ // Clear first, so the same message twice in a row is read again.
746
+ region.textContent = '';
747
+ setTimeout(() => {
748
+ region.textContent = message;
749
+ });
750
+ }
751
+
752
+ /** Scrolls the axis to just before now when it is in range, else to the morning or the start. */
753
+ private _scrollAxis() {
754
+ const scroller = this.renderRoot.querySelector<HTMLElement>('.scroller');
755
+ const header = this.renderRoot.querySelector<HTMLElement>('.time-header');
756
+ if (!scroller || !header || scroller.scrollWidth <= scroller.clientWidth) {
757
+ return;
758
+ }
759
+ const range = this._range;
760
+ const total = axisLength(range);
761
+ const now = this._currentTime;
762
+ let minutes = 0;
763
+ if (rangesOverlap(now, now, range.start, rangeEnd(range))) {
764
+ minutes =
765
+ axisMinutes(range, now) - (this._slot === 'hour' ? 60 : DAY_MINUTES);
766
+ } else if (this._slot === 'hour') {
767
+ minutes = 8 * 60;
768
+ }
769
+ const left = (clamp(minutes, 0, total) / total) * header.offsetWidth;
770
+ scroller.scrollTo({ left: isRtl(this) ? -left : left });
771
+ }
772
+
773
+ // ── Drag and drop
774
+
775
+ /** Minutes along the axis at viewport `x`; the axis runs from the inline start. */
776
+ private _axisAt(x: number): number {
777
+ const rect = this.renderRoot
778
+ .querySelector('.time-header')
779
+ ?.getBoundingClientRect();
780
+ if (!rect || rect.width <= 0) return 0;
781
+ const fraction = isRtl(this)
782
+ ? (rect.right - x) / rect.width
783
+ : (x - rect.left) / rect.width;
784
+ return clamp(fraction, 0, 1) * axisLength(this._range);
785
+ }
786
+
787
+ /** The time at viewport `x`. */
788
+ private _timeAt(x: number): Date {
789
+ return dateAtAxis(this._range, this._axisAt(x));
790
+ }
791
+
792
+ /** The day at viewport `x`, at midnight. */
793
+ private _dayAt(x: number): Date {
794
+ const index = Math.min(
795
+ Math.floor(this._axisAt(x) / DAY_MINUTES),
796
+ this._range.days - 1,
797
+ );
798
+ return dayOfRange(this._range, index);
799
+ }
800
+
801
+ /**
802
+ * The index of the row at viewport `y`, or of the nearest shown; -1 without rows. Rows of
803
+ * collapsed groups are not shown, so each track names its row.
804
+ */
805
+ private _rowAt(y: number): number {
806
+ let best = -1;
807
+ let bestDistance = Infinity;
808
+ this.renderRoot
809
+ .querySelectorAll<HTMLElement>('.track[data-row]')
810
+ .forEach(track => {
811
+ const rect = track.getBoundingClientRect();
812
+ const distance = Math.max(0, rect.top - y, y - rect.bottom);
813
+ if (distance < bestDistance) {
814
+ bestDistance = distance;
815
+ best = Number(track.dataset.row);
816
+ }
817
+ });
818
+ return best;
819
+ }
820
+
821
+ /** The time a press at `x` starts from: the day in day views. */
822
+ private _pressTime(x: number): Date {
823
+ return this._slot === 'day' ? this._dayAt(x) : this._timeAt(x);
824
+ }
825
+
826
+ private _onEventPointerDown(
827
+ event: PointerEvent,
828
+ placed: PlacedEvent,
829
+ row: number,
830
+ ) {
831
+ if (!this._canEdit(placed.data)) return;
832
+ const handle =
833
+ event.target instanceof Element
834
+ ? event.target.closest<HTMLElement>('[data-handle]')?.dataset.handle
835
+ : undefined;
836
+ let action: CalendarDragAction = 'move';
837
+ if (handle === 'start') action = 'resize-start';
838
+ else if (handle === 'end') action = 'resize-end';
839
+ this._drag.start(event, {
840
+ action,
841
+ event: placed,
842
+ row,
843
+ time: this._pressTime(event.clientX),
844
+ });
845
+ }
846
+
847
+ private _onTrackPointerDown(event: PointerEvent, row: number) {
848
+ if (!this.addable || this._drag.pressing) return;
849
+ // Presses on events are theirs, even on events that cannot be dragged.
850
+ const onEvent = event
851
+ .composedPath()
852
+ .some(
853
+ target =>
854
+ target instanceof HTMLElement && target.classList.contains('event'),
855
+ );
856
+ if (onEvent) return;
857
+ this._drag.start(event, {
858
+ action: 'add',
859
+ row,
860
+ time: this._pressTime(event.clientX),
861
+ });
862
+ }
863
+
864
+ /** Where the drag of `press` would put its event with the pointer at `point`. */
865
+ private _previewFor(press: GridPress, point: DragPoint): GridPreview | null {
866
+ const { event } = press;
867
+ const range =
868
+ this._slot === 'day'
869
+ ? dragByDays(press.action, press.time, this._dayAt(point.x), event)
870
+ : this._hourRange(press, point);
871
+ if (!range) return null;
872
+ // Only a move changes rows.
873
+ const row =
874
+ press.action === 'move' ? Math.max(0, this._rowAt(point.y)) : press.row;
875
+ return {
876
+ action: press.action,
877
+ data: event?.data,
878
+ row,
879
+ title: event
880
+ ? event.data.title || this._i18n.t('calendarUntitled')
881
+ : this._i18n.t('calendarNewEvent'),
882
+ color: event?.data.color,
883
+ ...range,
884
+ };
885
+ }
886
+
887
+ /** The range a drag in an hour view gives, snapped to `minuteStep` and kept in the range. */
888
+ private _hourRange(
889
+ press: GridPress,
890
+ point: DragPoint,
891
+ ): { start: Date; end: Date } | null {
892
+ const step = this._step;
893
+ const stepMs = step * MINUTE_MS;
894
+ const first = this._range.start.valueOf();
895
+ const last = rangeEnd(this._range).valueOf();
896
+ const time = this._timeAt(point.x);
897
+ const { event } = press;
898
+
899
+ if (press.action === 'add') {
900
+ // The slot pressed is always part of the range.
901
+ const anchor = Math.min(
902
+ snapTime(press.time, step, 'floor').valueOf(),
903
+ last - stepMs,
904
+ );
905
+ if (time.valueOf() >= anchor) {
906
+ const end = Math.max(
907
+ snapTime(time, step, 'ceil').valueOf(),
908
+ anchor + stepMs,
909
+ );
910
+ return { start: new Date(anchor), end: new Date(Math.min(end, last)) };
911
+ }
912
+ return {
913
+ start: snapTime(time, step, 'floor'),
914
+ end: new Date(Math.min(anchor + stepMs, last)),
915
+ };
916
+ }
917
+ if (!event) return null;
918
+
919
+ const length = event.end.valueOf() - event.start.valueOf();
920
+ if (press.action === 'move') {
921
+ // The point the event was grabbed by follows the pointer; at least a step of it stays in range.
922
+ const visible = Math.min(stepMs, length);
923
+ const grab = press.time.valueOf() - event.start.valueOf();
924
+ const start = clamp(
925
+ snapTime(new Date(time.valueOf() - grab), step, 'round').valueOf(),
926
+ first + visible - length,
927
+ last - visible,
928
+ );
929
+ return { start: new Date(start), end: new Date(start + length) };
930
+ }
931
+ if (press.action === 'resize-end') {
932
+ const end = snapTime(time, step, 'round').valueOf();
933
+ const min = event.start.valueOf() + stepMs;
934
+ return {
935
+ start: event.start,
936
+ end: new Date(clamp(end, min, Math.max(last, min))),
937
+ };
938
+ }
939
+ const start = snapTime(time, step, 'round').valueOf();
940
+ const max = event.end.valueOf() - stepMs;
941
+ return {
942
+ start: new Date(clamp(start, Math.min(first, max), max)),
943
+ end: event.end,
944
+ };
945
+ }
946
+
947
+ private _follow(press: GridPress, point: DragPoint) {
948
+ const preview = this._previewFor(press, point);
949
+ if (!preview) return;
950
+ const current = this._preview;
951
+ if (
952
+ current &&
953
+ current.row === preview.row &&
954
+ current.start.valueOf() === preview.start.valueOf() &&
955
+ current.end.valueOf() === preview.end.valueOf()
956
+ ) {
957
+ return;
958
+ }
959
+ this._preview = preview;
960
+ }
961
+
962
+ private _drop(press: GridPress, point: DragPoint) {
963
+ const preview = this._previewFor(press, point) ?? this._preview;
964
+ this._preview = null;
965
+ if (!preview) return;
966
+ const resource = this._rows[preview.row]?.resource;
967
+ if (!resource) return;
968
+ const { start, end } = preview;
969
+ if (press.action === 'add') {
970
+ this._add({
971
+ start,
972
+ end,
973
+ allDay: this._slot === 'day',
974
+ resourceId: resource.id,
975
+ });
976
+ return;
977
+ }
978
+ const { event } = press;
979
+ if (!event) return;
980
+ if (
981
+ start.valueOf() === event.start.valueOf() &&
982
+ end.valueOf() === event.end.valueOf() &&
983
+ resource.id === event.data.resourceId
984
+ ) {
985
+ return;
986
+ }
987
+ this._change({
988
+ event: event.data,
989
+ start,
990
+ end,
991
+ resourceId: resource.id,
992
+ action: press.action === 'move' ? 'move' : 'resize',
993
+ });
994
+ }
995
+
996
+ /** A click on empty time adds an event there: `defaultDuration` long, or the whole day. */
997
+ private _tap(press: GridPress) {
998
+ if (press.action !== 'add') return;
999
+ const resource = this._rows[press.row]?.resource;
1000
+ if (!resource) return;
1001
+ if (this._slot === 'day') {
1002
+ this._add({
1003
+ start: press.time,
1004
+ end: nextDay(press.time),
1005
+ allDay: true,
1006
+ resourceId: resource.id,
1007
+ });
1008
+ return;
1009
+ }
1010
+ // Starts at the half hour clicked.
1011
+ const grain = Math.max(30, this._step);
1012
+ const last = rangeEnd(this._range).valueOf();
1013
+ const start = Math.min(
1014
+ snapTime(press.time, grain, 'floor').valueOf(),
1015
+ last - grain * MINUTE_MS,
1016
+ );
1017
+ this._add({
1018
+ start: new Date(start),
1019
+ end: new Date(Math.min(start + this._duration * MINUTE_MS, last)),
1020
+ allDay: false,
1021
+ resourceId: resource.id,
1022
+ });
1023
+ }
1024
+
1025
+ /** Fires `event-change` and, unless it is canceled, applies and announces it. */
1026
+ private _change(detail: CalendarTimelineEventChangeDetail) {
1027
+ if (!this._eventsEditable()) return;
1028
+ const change = new CustomEvent<CalendarTimelineEventChangeDetail>(
1029
+ 'event-change',
1030
+ { detail, bubbles: true, composed: true, cancelable: true },
1031
+ );
1032
+ if (!this.dispatchEvent(change)) return;
1033
+ this.events = applyCalendarTimelineChange(this.events, detail);
1034
+ const title = detail.event.title || this._i18n.t('calendarUntitled');
1035
+ const when = this._when(detail.start, detail.end);
1036
+ if (detail.resourceId !== detail.event.resourceId) {
1037
+ const resource =
1038
+ this.resources.find(item => item.id === detail.resourceId)?.title ?? '';
1039
+ this._announce(
1040
+ this._i18n.t('calendarTimelineEventMoved')(title, resource, when),
1041
+ );
1042
+ return;
1043
+ }
1044
+ this._announce(
1045
+ this._i18n.t(
1046
+ detail.action === 'move'
1047
+ ? 'calendarEventMoved'
1048
+ : 'calendarEventResized',
1049
+ )(title, when),
1050
+ );
1051
+ }
1052
+
1053
+ /** Marks the range as a new event, fires `event-add` and announces it. */
1054
+ private _add(detail: CalendarTimelineEventAddDetail) {
1055
+ if (!this.addable) return;
1056
+ this._placeholder = detail;
1057
+ this.dispatchEvent(
1058
+ new CustomEvent<CalendarTimelineEventAddDetail>('event-add', {
1059
+ detail,
1060
+ bubbles: true,
1061
+ composed: true,
1062
+ }),
1063
+ );
1064
+ const resource =
1065
+ this.resources.find(item => item.id === detail.resourceId)?.title ?? '';
1066
+ this._announce(
1067
+ [
1068
+ this._i18n.t('calendarNewEvent'),
1069
+ resource,
1070
+ formatEventWhen(
1071
+ detail.start,
1072
+ detail.end,
1073
+ this._i18n.locale,
1074
+ detail.allDay,
1075
+ ),
1076
+ ]
1077
+ .filter(Boolean)
1078
+ .join(', '),
1079
+ );
1080
+ }
1081
+
1082
+ /**
1083
+ * Blurs the focused event when a drag starts. The drop redraws the events, and the element that
1084
+ * held focus could then show another event, which Enter would open.
1085
+ */
1086
+ private _blurFocused() {
1087
+ const active = (this.renderRoot as ShadowRoot).activeElement;
1088
+ if (active instanceof HTMLElement) active.blur();
1089
+ }
1090
+
1091
+ private readonly _handlePointerDown = () => {
1092
+ if (this._placeholder) this._placeholder = null;
1093
+ };
1094
+
1095
+ private readonly _handleKeyDown = (event: KeyboardEvent) => {
1096
+ if (event.key !== 'Escape' || !this._placeholder) return;
1097
+ // Keep an enclosing dialog open.
1098
+ event.stopPropagation();
1099
+ this._placeholder = null;
1100
+ };
1101
+
1102
+ private readonly _handleWindowKeyDown = (event: KeyboardEvent) => {
1103
+ if (event.key === 'Escape' && this._placeholder) this._placeholder = null;
1104
+ };
1105
+
1106
+ /** Classes of the scroller, which set the cursor during a drag. */
1107
+ private _scrollerClasses() {
1108
+ const action = this._preview?.action;
1109
+ return {
1110
+ scroller: true,
1111
+ addable: this.addable,
1112
+ dragging: !!action,
1113
+ 'drag-move': action === 'move',
1114
+ 'drag-resize': action === 'resize-start' || action === 'resize-end',
1115
+ };
1116
+ }
1117
+
1118
+ // ── Render helpers
1119
+
1120
+ private _renderHeader() {
1121
+ return renderCalendarHeader({
1122
+ title: this._rangeLabel(),
1123
+ views: this.availableViews.map(view => ({
1124
+ value: view.value,
1125
+ label: this._viewLabel(view),
1126
+ })),
1127
+ view: this.view,
1128
+ labels: {
1129
+ today: this._i18n.t('today'),
1130
+ previous: this._i18n.t('previousPeriod'),
1131
+ next: this._i18n.t('nextPeriod'),
1132
+ },
1133
+ onToday: () => this.today(),
1134
+ onPrevious: () => this.previous(),
1135
+ onNext: () => this.next(),
1136
+ onViewChange: value => this._changeView(value),
1137
+ });
1138
+ }
1139
+
1140
+ /** The column labels: hours (under their days when there are several), or days. */
1141
+ private _renderTimeHeader(view: CalendarTimelineViewType) {
1142
+ const { locale } = this._i18n;
1143
+ const range = this._range;
1144
+ const today = startOfDay(this._currentTime).valueOf();
1145
+ const days = Array.from({ length: range.days }, (_, i) =>
1146
+ dayOfRange(range, i),
1147
+ );
1148
+ if (view.slot === 'day') {
1149
+ const weekday = new Intl.DateTimeFormat(locale, {
1150
+ weekday: range.days > 7 ? 'narrow' : 'short',
1151
+ });
1152
+ const number = new Intl.DateTimeFormat(locale, { day: 'numeric' });
1153
+ return days.map(
1154
+ day =>
1155
+ html`<div
1156
+ class=${classMap({
1157
+ 'slot-label': true,
1158
+ 'day-label': true,
1159
+ today: day.valueOf() === today,
1160
+ })}
1161
+ >
1162
+ <span class="weekday">${weekday.format(day)}</span>
1163
+ <span class="day-number">${number.format(day)}</span>
1164
+ </div>`,
1165
+ );
1166
+ }
1167
+ const hour = new Intl.DateTimeFormat(locale, { hour: 'numeric' });
1168
+ const dayName = new Intl.DateTimeFormat(locale, {
1169
+ weekday: 'short',
1170
+ day: 'numeric',
1171
+ });
1172
+ return html`
1173
+ ${range.days > 1
1174
+ ? days.map(
1175
+ day =>
1176
+ html`<div
1177
+ class=${classMap({
1178
+ 'slot-label': true,
1179
+ 'day-span': true,
1180
+ today: day.valueOf() === today,
1181
+ })}
1182
+ >
1183
+ ${dayName.format(day)}
1184
+ </div>`,
1185
+ )
1186
+ : nothing}
1187
+ ${days.map(day =>
1188
+ Array.from(
1189
+ { length: 24 },
1190
+ (_, h) =>
1191
+ html`<div class="slot-label hour-label">
1192
+ ${hour.format(atWallMinutes(day, h * 60))}
1193
+ </div>`,
1194
+ ),
1195
+ )}
1196
+ `;
1197
+ }
1198
+
1199
+ /** Today, weekends and day boundaries behind every row, and the current-time line. */
1200
+ private _renderOverlay(view: CalendarTimelineViewType) {
1201
+ const range = this._range;
1202
+ const today = startOfDay(this._currentTime).valueOf();
1203
+ const weekend = weekendDays(this._i18n.locale);
1204
+ const stripes = Array.from({ length: range.days }, (_, i) => {
1205
+ const day = dayOfRange(range, i);
1206
+ const classes = {
1207
+ stripe: true,
1208
+ today: view.slot === 'day' && day.valueOf() === today,
1209
+ weekend:
1210
+ view.slot === 'day' && weekend.includes(day.getDay() as WeekDay),
1211
+ 'day-start': view.slot === 'hour' && i > 0,
1212
+ };
1213
+ if (!classes.today && !classes.weekend && !classes['day-start']) {
1214
+ return nothing;
1215
+ }
1216
+ return html`<div
1217
+ class=${classMap(classes)}
1218
+ style=${this._styleMap(
1219
+ this._position({
1220
+ from: i * DAY_MINUTES,
1221
+ to: (i + 1) * DAY_MINUTES,
1222
+ }),
1223
+ )}
1224
+ ></div>`;
1225
+ });
1226
+ const now = this._currentTime;
1227
+ const showNow = rangesOverlap(now, now, range.start, rangeEnd(range));
1228
+ return html`<div class="overlay" aria-hidden="true">
1229
+ ${stripes}
1230
+ ${showNow
1231
+ ? html`<div
1232
+ class="now"
1233
+ style="inset-inline-start: ${(axisMinutes(range, now) /
1234
+ axisLength(range)) *
1235
+ 100}%"
1236
+ ></div>`
1237
+ : nothing}
1238
+ </div>`;
1239
+ }
1240
+
1241
+ private _renderEvent(placed: PlacedEvent, row: number, slot: string) {
1242
+ const { data } = placed;
1243
+ const interactive = !this.eventsReadonly;
1244
+ const editable = this._canEdit(data);
1245
+ const preview = this._preview;
1246
+ const dragged = !!preview?.data && preview.data === data;
1247
+ const resized =
1248
+ dragged && preview && preview.action !== 'move' ? preview : null;
1249
+ // A resize is drawn in place; a move leaves the event faded where it was.
1250
+ const start = resized ? resized.start : data.start;
1251
+ const end = resized ? resized.end : data.end;
1252
+ const span = resized
1253
+ ? eventSpan(this._range, this._slot, start, end)
1254
+ : placed;
1255
+ const title = data.title || this._i18n.t('calendarUntitled');
1256
+ const resource = this._rows[row]?.resource.title ?? '';
1257
+ const time = this._timeText(start, end);
1258
+ const activate = () =>
1259
+ this.dispatchEvent(
1260
+ new CustomEvent('event-click', {
1261
+ detail: { event: data },
1262
+ bubbles: true,
1263
+ composed: true,
1264
+ }),
1265
+ );
1266
+ // The event's own times decide its handles, so the one being dragged stays.
1267
+ const handles = {
1268
+ start:
1269
+ data.start.valueOf() >= this._range.start.valueOf() &&
1270
+ (slot === 'day' ||
1271
+ data.end.valueOf() - data.start.valueOf() >= START_HANDLE_MIN_MS),
1272
+ end: data.end.valueOf() <= rangeEnd(this._range).valueOf(),
1273
+ };
1274
+ const handle = (edge: 'start' | 'end') =>
1275
+ editable && handles[edge]
1276
+ ? html`<span
1277
+ class="resize-handle ${edge}"
1278
+ data-handle=${edge}
1279
+ aria-hidden="true"
1280
+ ></span>`
1281
+ : nothing;
1282
+ return html`
1283
+ <div
1284
+ class=${classMap({
1285
+ event: true,
1286
+ clickable: interactive,
1287
+ editable,
1288
+ 'drag-source': dragged && !resized,
1289
+ lifted: !!resized,
1290
+ })}
1291
+ style=${this._styleMap({
1292
+ ...this._position(span),
1293
+ '--_lane-index': String(placed.lane),
1294
+ ...this._colorVars(data.color),
1295
+ })}
1296
+ role=${interactive ? 'button' : 'note'}
1297
+ tabindex=${interactive ? '0' : nothing}
1298
+ aria-label=${[title, resource, this._when(data.start, data.end)]
1299
+ .filter(Boolean)
1300
+ .join(', ')}
1301
+ @click=${() => {
1302
+ if (interactive) activate();
1303
+ }}
1304
+ @keydown=${interactive ? onActivateKey(activate) : nothing}
1305
+ @pointerdown=${editable
1306
+ ? (event: PointerEvent) =>
1307
+ this._onEventPointerDown(event, placed, row)
1308
+ : nothing}
1309
+ >
1310
+ ${handle('start')}
1311
+ <span class="event-title" aria-hidden="true">${title}</span>
1312
+ ${time
1313
+ ? html`<span class="event-time" aria-hidden="true">${time}</span>`
1314
+ : nothing}
1315
+ ${handle('end')}
1316
+ </div>
1317
+ `;
1318
+ }
1319
+
1320
+ /** A new or moved event where the drag would put it in this row, or the placeholder. */
1321
+ private _renderRowPreview(row: number) {
1322
+ const preview = this._preview;
1323
+ let item: { start: Date; end: Date; title: string; color?: string } | null =
1324
+ null;
1325
+ let placeholder = false;
1326
+ if (preview) {
1327
+ if (
1328
+ (preview.action === 'add' || preview.action === 'move') &&
1329
+ preview.row === row
1330
+ ) {
1331
+ item = preview;
1332
+ }
1333
+ } else if (
1334
+ this._placeholder &&
1335
+ this._rows[row]?.resource.id === this._placeholder.resourceId
1336
+ ) {
1337
+ item = {
1338
+ ...this._placeholder,
1339
+ title: this._i18n.t('calendarNewEvent'),
1340
+ };
1341
+ placeholder = true;
1342
+ }
1343
+ if (!item) return nothing;
1344
+ const time = this._timeText(item.start, item.end);
1345
+ return html`<div
1346
+ class=${classMap({ event: true, preview: true, placeholder })}
1347
+ style=${this._styleMap({
1348
+ ...this._position(
1349
+ eventSpan(this._range, this._slot, item.start, item.end),
1350
+ ),
1351
+ '--_lane-index': '0',
1352
+ ...this._colorVars(item.color),
1353
+ })}
1354
+ aria-hidden="true"
1355
+ >
1356
+ <span class="event-title">${item.title}</span>
1357
+ ${time ? html`<span class="event-time">${time}</span>` : nothing}
1358
+ </div>`;
1359
+ }
1360
+
1361
+ private _renderRow(row: LaidOutRow, index: number, slot: string) {
1362
+ const { resource } = row;
1363
+ return html`
1364
+ <div class="row" role="row">
1365
+ <div class="resource" role="rowheader">
1366
+ <span class="resource-title">${resource.title}</span>
1367
+ ${resource.supportingText
1368
+ ? html`<span class="resource-supporting"
1369
+ >${resource.supportingText}</span
1370
+ >`
1371
+ : nothing}
1372
+ </div>
1373
+ <div
1374
+ class="track"
1375
+ role="cell"
1376
+ data-row=${index}
1377
+ style="--_lanes: ${row.lanes}"
1378
+ @pointerdown=${(event: PointerEvent) =>
1379
+ this._onTrackPointerDown(event, index)}
1380
+ >
1381
+ ${row.events.map(placed => this._renderEvent(placed, index, slot))}
1382
+ ${this._renderRowPreview(index)}
1383
+ </div>
1384
+ </div>
1385
+ `;
1386
+ }
1387
+
1388
+ /** A collapsed group's events as thin bars, so its busy times stay in sight. */
1389
+ private _renderGroupSummary(group: RowGroup) {
1390
+ return html`<div class="summary" aria-hidden="true">
1391
+ ${group.rows.map(index =>
1392
+ (this._rows[index]?.events ?? []).map(
1393
+ event =>
1394
+ html`<span
1395
+ class="summary-bar"
1396
+ style=${this._styleMap({
1397
+ ...this._position(event),
1398
+ ...this._colorVars(event.data.color),
1399
+ })}
1400
+ ></span>`,
1401
+ ),
1402
+ )}
1403
+ </div>`;
1404
+ }
1405
+
1406
+ /** A group's header row, then its rows unless it is collapsed. */
1407
+ private _renderGroup(group: RowGroup, collapsed: boolean, slot: string) {
1408
+ const name = group.key === '' ? this._i18n.t('emptyGroup') : group.key;
1409
+ const count = group.rows.length;
1410
+ return html`
1411
+ <div
1412
+ class=${classMap({ row: true, 'group-row': true, collapsed })}
1413
+ role="row"
1414
+ >
1415
+ <div class="group-header" role="rowheader">
1416
+ <button
1417
+ type="button"
1418
+ class="group-toggle"
1419
+ aria-expanded=${collapsed ? 'false' : 'true'}
1420
+ aria-label=${collapsed
1421
+ ? this._i18n.t('expandGroup')(name)
1422
+ : this._i18n.t('collapseGroup')(name)}
1423
+ @click=${() => this._toggleGroup(group.key)}
1424
+ >
1425
+ <wc-icon name="chevron_right" aria-hidden="true"></wc-icon>
1426
+ </button>
1427
+ <span class="group-label">${name}</span>
1428
+ <span class="group-count"
1429
+ >${this._i18n.t('calendarTimelineGroupCount')(
1430
+ new Intl.NumberFormat(this._i18n.locale).format(count),
1431
+ count,
1432
+ )}</span
1433
+ >
1434
+ </div>
1435
+ <div class="group-track" role="cell">
1436
+ ${collapsed ? this._renderGroupSummary(group) : nothing}
1437
+ </div>
1438
+ </div>
1439
+ ${collapsed
1440
+ ? nothing
1441
+ : group.rows.map(index =>
1442
+ this._renderRow(this._rows[index], index, slot),
1443
+ )}
1444
+ `;
1445
+ }
1446
+
1447
+ /** The rows, under their groups' headers when grouped. */
1448
+ private _renderRows(slot: string) {
1449
+ if (!this._rows.length) {
1450
+ return html`<div class="row" role="row">
1451
+ <div class="empty" role="cell">
1452
+ ${this._i18n.t('calendarTimelineEmpty')}
1453
+ </div>
1454
+ </div>`;
1455
+ }
1456
+ if (!this._groups) {
1457
+ return this._rows.map((row, index) => this._renderRow(row, index, slot));
1458
+ }
1459
+ const collapsed = new Set(this._collapsedKeys());
1460
+ return this._groups.map(group =>
1461
+ this._renderGroup(group, collapsed.has(group.key), slot),
1462
+ );
1463
+ }
1464
+
1465
+ private _renderGrid() {
1466
+ const view = this._view;
1467
+ if (!view) {
1468
+ return html`<div class="message">${this._i18n.t('invalidView')}</div>`;
1469
+ }
1470
+ const range = this._range;
1471
+ const slots = view.slot === 'day' ? range.days : range.days * 24;
1472
+ const label = this._rangeLabel();
1473
+ return html`
1474
+ <div
1475
+ class=${classMap(this._scrollerClasses())}
1476
+ style="--_slots: ${slots}; --_days: ${range.days}; --_slot-min: var(${view.slot ===
1477
+ 'day'
1478
+ ? '--calendar-timeline-day-width'
1479
+ : '--calendar-timeline-hour-width'})"
1480
+ >
1481
+ <div class="table" role="table" aria-label=${label}>
1482
+ <div class="row header-row" role="row">
1483
+ <div class="corner" role="columnheader">
1484
+ ${this.resourceLabel || this._i18n.t('calendarTimelineResources')}
1485
+ </div>
1486
+ <div
1487
+ class=${classMap({
1488
+ 'time-header': true,
1489
+ 'two-tier': view.slot === 'hour' && range.days > 1,
1490
+ })}
1491
+ role="columnheader"
1492
+ aria-label=${label}
1493
+ >
1494
+ <div class="slot-labels" aria-hidden="true">
1495
+ ${this._renderTimeHeader(view)}
1496
+ </div>
1497
+ </div>
1498
+ </div>
1499
+ <div class="rows" role="rowgroup">
1500
+ ${this._renderOverlay(view)} ${this._renderRows(view.slot)}
1501
+ </div>
1502
+ </div>
1503
+ </div>
1504
+ `;
1505
+ }
1506
+
1507
+ // ── Render
1508
+
1509
+ render() {
1510
+ const busy = this.loading;
1511
+ return html`
1512
+ <div class="calendar-timeline">
1513
+ <div class="calendar-header">${this._renderHeader()}</div>
1514
+ ${busy
1515
+ ? html`<wc-linear-progress
1516
+ class="loader"
1517
+ indeterminate
1518
+ label=${this._i18n.t('loading')}
1519
+ ></wc-linear-progress>`
1520
+ : nothing}
1521
+ <div class="body" aria-busy=${busy ? 'true' : 'false'}>
1522
+ ${this._renderGrid()}
1523
+ </div>
1524
+ <div class="screen-reader-only" role="status" aria-live="polite"></div>
1525
+ </div>
1526
+ `;
1527
+ }
1528
+ }