@redvars/peacock 4.4.0 → 4.5.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 (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 +564 -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
@@ -1,8 +1,22 @@
1
- import { LitElement, html, nothing, PropertyValues } from 'lit';
1
+ import { LitElement, html, nothing, PropertyValues } from 'lit';
2
2
  import { property, state } from 'lit/decorators.js';
3
- import { addDays, addMonths, formatDate, toZonedWallClock } from './utils.js';
3
+ import {
4
+ addDays,
5
+ addMonths,
6
+ formatDate,
7
+ formatEventLabel,
8
+ formatEventWhen,
9
+ isAllDayRange,
10
+ toZonedWallClock,
11
+ } from './utils.js';
4
12
  import { CalendarEvent } from './calendar-event.js';
5
- import type { CalendarViewType, EventType } from './types.js';
13
+ import { renderCalendarHeader } from './calendar-header.js';
14
+ import type {
15
+ CalendarEventAddDetail,
16
+ CalendarEventChangeDetail,
17
+ CalendarViewType,
18
+ EventType,
19
+ } from './types.js';
6
20
  import IndividualComponent from '@/IndividualComponent.js';
7
21
  import { I18nController } from '@/__internal/i18n/i18n-controller.js';
8
22
  import type { PeacockStrings } from '@/__internal/i18n/strings.js';
@@ -14,6 +28,12 @@ import {
14
28
  } from '@/__internal/utils/date.js';
15
29
  import styles from './calendar.scss';
16
30
 
31
+ export type {
32
+ CalendarEventAddDetail,
33
+ CalendarEventChangeAction,
34
+ CalendarEventChangeDetail,
35
+ } from './types.js';
36
+
17
37
  /** Detail of `date-change`. */
18
38
  export type CalendarDateChangeDetail = {
19
39
  /** The new context date. */
@@ -22,6 +42,27 @@ export type CalendarDateChangeDetail = {
22
42
  value: string;
23
43
  };
24
44
 
45
+ /**
46
+ * Applies an `event-change` to an `events` array the way the calendar does, returning a new array
47
+ * in which the event is replaced by a copy with the new `start` and `end`. The event is found by
48
+ * identity, else by `id`. The copy is made with object spread, so give the calendar plain objects,
49
+ * not class instances. Use it to apply a change you canceled, for example once the server has
50
+ * accepted it.
51
+ */
52
+ export function applyCalendarChange<T extends EventType>(
53
+ events: readonly T[],
54
+ change: Pick<CalendarEventChangeDetail, 'event' | 'start' | 'end'>,
55
+ ): T[] {
56
+ const { id } = change.event;
57
+ let index = events.indexOf(change.event as T);
58
+ if (index < 0 && id !== undefined && id !== null) {
59
+ index = events.findIndex(event => event.id === id);
60
+ }
61
+ return events.map((event, i) =>
62
+ i === index ? { ...event, start: change.start, end: change.end } : event,
63
+ );
64
+ }
65
+
25
66
  /**
26
67
  * @label Calendar
27
68
  * @tag wc-calendar
@@ -30,10 +71,11 @@ export type CalendarDateChangeDetail = {
30
71
  *
31
72
  * @overview
32
73
  * <p>Pass events as the <code>events</code> property; each has a <code>start</code>,
33
- * <code>end</code>, <code>title</code> and optional palette <code>color</code>. The day and week
34
- * views lay timed events out in a column per day, with events lasting a day or more in a row
35
- * above; the month view shows six weeks. <code>available-views</code> sets the views offered in
36
- * the header's segmented buttons, and <code>view</code> the one shown.</p>
74
+ * <code>end</code>, <code>title</code> and optional palette <code>color</code>. <code>end</code> is
75
+ * exclusive: an all-day event on November 4 runs from midnight on the 4th to midnight on the 5th.
76
+ * The day and week views lay timed events out in a column per day, with events lasting a day or
77
+ * more in a row above; the month view shows six weeks. <code>available-views</code> sets the views
78
+ * offered in the header's segmented buttons, and <code>view</code> the one shown.</p>
37
79
  * <p>The header has a Today button, previous and next buttons and the current date, which is a
38
80
  * polite live region. <code>previous()</code>, <code>next()</code> and <code>today()</code> do the
39
81
  * same from code; each fires <code>date-change</code>. The date shown is <code>date</code> (an ISO
@@ -45,6 +87,22 @@ export type CalendarDateChangeDetail = {
45
87
  * <code>loading</code> shows a progress bar and marks the calendar busy. <code>first-day</code>
46
88
  * sets the week start (else the locale's), <code>timezone</code> the zone the current time is
47
89
  * shown in, and <code>locale</code> the language of names and times.</p>
90
+ * <p>With <code>editable</code>, people drag events to move them and drag their edges to change
91
+ * when they start or end: timed events in steps of <code>minute-step</code> minutes, all-day events
92
+ * and every event in the month view by whole days. Each drop fires the cancelable
93
+ * <code>event-change</code>; unless it is canceled, the calendar replaces <code>events</code> with
94
+ * a new array holding a copy of the event with its new times. To confirm a change with a server
95
+ * first, cancel the event and apply it later with <code>applyCalendarChange()</code>. An event with
96
+ * <code>editable: false</code> stays put, and <code>events-readonly</code> turns editing off. On
97
+ * touch screens, hold an event briefly before dragging it. Escape cancels a drag.</p>
98
+ * <p>With <code>addable</code>, dragging across empty time, or clicking it, fires
99
+ * <code>event-add</code> with the range: a click gives <code>default-duration</code> minutes, and
100
+ * the all-day row and the month view give whole days. The calendar does not add the event itself.
101
+ * It marks the range as a new event until <code>events</code> changes, the person presses Escape
102
+ * or starts another drag, or <code>clearPlaceholder()</code> is called, for example when a dialog
103
+ * asking for the event's title is canceled. Each change is announced to screen readers. Dragging
104
+ * needs a pointer, so offer another way to change an event's time too, such as the dialog that
105
+ * <code>event-click</code> opens.</p>
48
106
  *
49
107
  * @cssprop --calendar-border-color - Border color used throughout the calendar grid.
50
108
  * @cssprop --calendar-event-bg-color - Background color for calendar events.
@@ -53,11 +111,28 @@ export type CalendarDateChangeDetail = {
53
111
  * @fires {CustomEvent<{event: EventType}>} event-click - An event was clicked, or chosen with Enter or Space. Detail contains `{ event }`. Not fired with `events-readonly`.
54
112
  * @fires {CustomEvent<{view: string}>} view-change - The view changed. Detail contains `{ view }`.
55
113
  * @fires {CustomEvent<{date: Date, value: string}>} date-change - The context date changed. Detail contains `{ date, value }`: the `Date` and its ISO string.
114
+ * @fires {CustomEvent<CalendarEventChangeDetail>} event-change - An event was dragged to a new time (`action: 'move'`) or had its start or end dragged (`action: 'resize'`). Detail contains `{ event, start, end, action }`, where `event` is the object from `events` as it was. Cancelable: cancel it to keep the event where it was. Only with `editable`.
115
+ * @fires {CustomEvent<CalendarEventAddDetail>} event-add - Empty time was dragged across or clicked. Detail contains `{ start, end, allDay }`. Only with `addable`.
56
116
  *
57
117
  * @example
58
118
  * ```html
59
119
  * <wc-calendar view="week" date="2026-11-06" style="height: 600px"></wc-calendar>
60
120
  * ```
121
+ *
122
+ * @example
123
+ * ```html
124
+ * <wc-calendar id="planner" view="week" editable addable style="height: 600px"></wc-calendar>
125
+ * <script>
126
+ * const planner = document.getElementById('planner');
127
+ * planner.events = [
128
+ * { id: 1, title: 'Standup', start: new Date(2026, 10, 4, 9), end: new Date(2026, 10, 4, 9, 30) },
129
+ * ];
130
+ * planner.addEventListener('event-change', event => console.log(event.detail));
131
+ * planner.addEventListener('event-add', ({ detail }) => {
132
+ * planner.events = [...planner.events, { id: Date.now(), title: 'New event', ...detail }];
133
+ * });
134
+ * </script>
135
+ * ```
61
136
  */
62
137
  @IndividualComponent
63
138
  export class Calendar extends LitElement {
@@ -109,6 +184,28 @@ export class Calendar extends LitElement {
109
184
  @property({ type: Boolean, attribute: 'events-readonly' })
110
185
  eventsReadonly: boolean = false;
111
186
 
187
+ /**
188
+ * People can drag events to move them and drag their edges to resize them. Each drop fires the
189
+ * cancelable `event-change`. An event with `editable: false` stays put.
190
+ */
191
+ @property({ type: Boolean, reflect: true })
192
+ editable: boolean = false;
193
+
194
+ /**
195
+ * Dragging across empty time, or clicking it, fires `event-add` with the range and marks it as a
196
+ * new event until `events` changes.
197
+ */
198
+ @property({ type: Boolean, reflect: true })
199
+ addable: boolean = false;
200
+
201
+ /** Minutes that dragging moves, resizes and draws timed events by. Defaults to 15. */
202
+ @property({ type: Number, attribute: 'minute-step' })
203
+ minuteStep: number = 15;
204
+
205
+ /** Length in minutes of an event added by clicking empty time in the day or week view. Defaults to 60. */
206
+ @property({ type: Number, attribute: 'default-duration' })
207
+ defaultDuration: number = 60;
208
+
112
209
  /** Shows a progress bar and marks the calendar busy while events load. */
113
210
  @property({ type: Boolean, reflect: true })
114
211
  loading: boolean = false;
@@ -137,6 +234,10 @@ export class Calendar extends LitElement {
137
234
  @state()
138
235
  private _currentView: CalendarViewType | undefined;
139
236
 
237
+ /** The range of the last `event-add`, marked as a new event until the app adds it. */
238
+ @state()
239
+ private _placeholder: CalendarEventAddDetail | null = null;
240
+
140
241
  // ── Private fields
141
242
 
142
243
  /** Peacock's strings and the resolved locale. */
@@ -150,6 +251,18 @@ export class Calendar extends LitElement {
150
251
  if (!this.contextDate && !isoToDate(this.date)) {
151
252
  this.contextDate = this._currentTime;
152
253
  }
254
+ // Capture, so a press clears the placeholder before it starts a drag of its own.
255
+ this.addEventListener('pointerdown', this._handlePointerDown, true);
256
+ this.addEventListener('keydown', this._handleKeyDown);
257
+ // Clicking empty time leaves focus on the page, so Escape is also heard there.
258
+ window.addEventListener('keydown', this._handleWindowKeyDown);
259
+ }
260
+
261
+ override disconnectedCallback() {
262
+ super.disconnectedCallback();
263
+ this.removeEventListener('pointerdown', this._handlePointerDown, true);
264
+ this.removeEventListener('keydown', this._handleKeyDown);
265
+ window.removeEventListener('keydown', this._handleWindowKeyDown);
153
266
  }
154
267
 
155
268
  override willUpdate(changed: PropertyValues<this>) {
@@ -160,6 +273,17 @@ export class Calendar extends LitElement {
160
273
  if (changed.has('timezone')) {
161
274
  this._currentTime = this._now();
162
275
  }
276
+ // The new event has been added, or the person has moved on.
277
+ if (
278
+ this._placeholder &&
279
+ (changed.has('events') ||
280
+ changed.has('view') ||
281
+ changed.has('date') ||
282
+ changed.has('contextDate') ||
283
+ (changed.has('addable') && !this.addable))
284
+ ) {
285
+ this._placeholder = null;
286
+ }
163
287
  this._syncDate(changed);
164
288
  }
165
289
 
@@ -181,6 +305,14 @@ export class Calendar extends LitElement {
181
305
  this._setContextDate(this._currentTime);
182
306
  }
183
307
 
308
+ /**
309
+ * Removes the new event marked after `event-add`, for when adding it is canceled. It also goes
310
+ * when `events` changes.
311
+ */
312
+ clearPlaceholder() {
313
+ this._placeholder = null;
314
+ }
315
+
184
316
  // ── Private methods
185
317
 
186
318
  /** Now, as wall-clock time in `timezone`. */
@@ -222,6 +354,11 @@ export class Calendar extends LitElement {
222
354
  return !this.eventsReadonly;
223
355
  }
224
356
 
357
+ /** Whether events can be dragged: `editable` and not `events-readonly`. */
358
+ private _eventsEditable(): boolean {
359
+ return this.editable && this._eventsInteractive();
360
+ }
361
+
225
362
  private _step(direction: 1 | -1) {
226
363
  if (!this._currentView || !this.contextDate) return;
227
364
  if (this._currentView.days) {
@@ -245,6 +382,35 @@ export class Calendar extends LitElement {
245
382
  );
246
383
  }
247
384
 
385
+ /**
386
+ * Reads `message` in the live region. Its text is set directly, so an announcement does not
387
+ * render the calendar, and its views, again.
388
+ */
389
+ private _announce(message: string) {
390
+ const region = this.renderRoot.querySelector('[role="status"]');
391
+ if (!region) return;
392
+ // Clear first, so the same message twice in a row is read again.
393
+ region.textContent = '';
394
+ setTimeout(() => {
395
+ region.textContent = message;
396
+ });
397
+ }
398
+
399
+ private readonly _handlePointerDown = () => {
400
+ if (this._placeholder) this._placeholder = null;
401
+ };
402
+
403
+ private readonly _handleKeyDown = (event: KeyboardEvent) => {
404
+ if (event.key !== 'Escape' || !this._placeholder) return;
405
+ // Keep an enclosing dialog open.
406
+ event.stopPropagation();
407
+ this._placeholder = null;
408
+ };
409
+
410
+ private readonly _handleWindowKeyDown = (event: KeyboardEvent) => {
411
+ if (event.key === 'Escape' && this._placeholder) this._placeholder = null;
412
+ };
413
+
248
414
  private _onViewDateClick(evt: CustomEvent<{ date: Date }>) {
249
415
  evt.stopPropagation();
250
416
  this.view = 'day';
@@ -270,9 +436,58 @@ export class Calendar extends LitElement {
270
436
  );
271
437
  }
272
438
 
273
- private _onViewSegmentChange(evt: CustomEvent<{ value: string | null }>) {
274
- if (!evt.detail.value) return;
275
- this.view = evt.detail.value;
439
+ private _onViewEventChange(evt: CustomEvent<CalendarEventChangeDetail>) {
440
+ evt.stopPropagation();
441
+ if (!this._eventsEditable()) return;
442
+ const detail = { ...evt.detail };
443
+ const change = new CustomEvent<CalendarEventChangeDetail>('event-change', {
444
+ detail,
445
+ bubbles: true,
446
+ composed: true,
447
+ cancelable: true,
448
+ });
449
+ if (!this.dispatchEvent(change)) return;
450
+ this.events = applyCalendarChange(this.events, detail);
451
+ const { event, start, end, action } = detail;
452
+ const title = event.title || this._i18n.t('calendarUntitled');
453
+ const when = formatEventWhen(
454
+ start,
455
+ end,
456
+ this._i18n.locale,
457
+ isAllDayRange(start, end),
458
+ );
459
+ this._announce(
460
+ this._i18n.t(
461
+ action === 'move' ? 'calendarEventMoved' : 'calendarEventResized',
462
+ )(title, when),
463
+ );
464
+ }
465
+
466
+ private _onViewEventAdd(evt: CustomEvent<CalendarEventAddDetail>) {
467
+ evt.stopPropagation();
468
+ if (!this.addable) return;
469
+ const detail = { ...evt.detail };
470
+ this._placeholder = detail;
471
+ this.dispatchEvent(
472
+ new CustomEvent<CalendarEventAddDetail>('event-add', {
473
+ detail,
474
+ bubbles: true,
475
+ composed: true,
476
+ }),
477
+ );
478
+ this._announce(
479
+ formatEventLabel(
480
+ this._i18n.t('calendarNewEvent'),
481
+ detail.start,
482
+ detail.end,
483
+ this._i18n.locale,
484
+ detail.allDay,
485
+ ),
486
+ );
487
+ }
488
+
489
+ private _changeView(value: string) {
490
+ this.view = value;
276
491
  this.dispatchEvent(
277
492
  new CustomEvent('view-change', {
278
493
  detail: { view: this.view },
@@ -298,56 +513,25 @@ export class Calendar extends LitElement {
298
513
  // ── Render helpers
299
514
 
300
515
  private _renderHeader() {
301
- return html`
302
- <div class="calendar-header-classic">
303
- <div class="header-left">
304
- <wc-button
305
- variant="outlined"
306
- size="sm"
307
- class="color-secondary"
308
- @click=${() => this.today()}
309
- >
310
- ${this._i18n.t('today')}
311
- </wc-button>
312
- <wc-icon-button
313
- variant="text"
314
- size="sm"
315
- class="color-secondary"
316
- aria-label=${this._i18n.t('previousPeriod')}
317
- @click=${() => this.previous()}
318
- >
319
- <wc-icon name="chevron_left"></wc-icon>
320
- </wc-icon-button>
321
- <wc-icon-button
322
- variant="text"
323
- size="sm"
324
- class="color-secondary"
325
- aria-label=${this._i18n.t('nextPeriod')}
326
- @click=${() => this.next()}
327
- >
328
- <wc-icon name="chevron_right"></wc-icon>
329
- </wc-icon-button>
330
- <div class="title" aria-live="polite">
331
- ${this.contextDate
332
- ? formatDate(this.contextDate, 'MMMM d, yyyy', this._i18n.locale)
333
- : ''}
334
- </div>
335
- </div>
336
- <div class="header-right">
337
- <wc-segmented-button-group @change=${this._onViewSegmentChange}>
338
- ${this.availableViews.map(
339
- v =>
340
- html`<wc-segmented-button
341
- .value=${v.value}
342
- ?selected=${this.view === v.value}
343
- >
344
- ${this._viewLabel(v)}
345
- </wc-segmented-button>`,
346
- )}
347
- </wc-segmented-button-group>
348
- </div>
349
- </div>
350
- `;
516
+ return renderCalendarHeader({
517
+ title: this.contextDate
518
+ ? formatDate(this.contextDate, 'MMMM d, yyyy', this._i18n.locale)
519
+ : '',
520
+ views: this.availableViews.map(view => ({
521
+ value: view.value,
522
+ label: this._viewLabel(view),
523
+ })),
524
+ view: this.view,
525
+ labels: {
526
+ today: this._i18n.t('today'),
527
+ previous: this._i18n.t('previousPeriod'),
528
+ next: this._i18n.t('nextPeriod'),
529
+ },
530
+ onToday: () => this.today(),
531
+ onPrevious: () => this.previous(),
532
+ onNext: () => this.next(),
533
+ onViewChange: value => this._changeView(value),
534
+ });
351
535
  }
352
536
 
353
537
  private _renderCalendarView() {
@@ -356,10 +540,12 @@ export class Calendar extends LitElement {
356
540
  }
357
541
  const { locale } = this._i18n;
358
542
  const readonly = !this._eventsInteractive();
543
+ const editable = this._eventsEditable();
359
544
  const weekStartsOn = this._weekStart();
360
545
  const contextDate = this.contextDate ?? this._currentTime;
361
-
362
- const calEvents = this.events.map(
546
+ const untitled = this._i18n.t('calendarUntitled');
547
+ // Wrapped on every render, so events changed in place show after `requestUpdate()`.
548
+ const calEvents = (this.events ?? []).map(
363
549
  event =>
364
550
  new CalendarEvent(
365
551
  event.start,
@@ -380,9 +566,18 @@ export class Calendar extends LitElement {
380
566
  .contextDate=${contextDate}
381
567
  .weekStartsOn=${weekStartsOn}
382
568
  .locale=${locale}
569
+ .editable=${editable}
570
+ .addable=${this.addable}
571
+ .minuteStep=${this.minuteStep}
572
+ .defaultDuration=${this.defaultDuration}
573
+ .placeholder=${this._placeholder}
574
+ .untitledLabel=${untitled}
575
+ .newEventLabel=${this._i18n.t('calendarNewEvent')}
383
576
  ?events-readonly=${readonly}
384
577
  @date-click=${this._onViewDateClick}
385
578
  @event-click=${this._onViewEventClick}
579
+ @event-change=${this._onViewEventChange}
580
+ @event-add=${this._onViewEventAdd}
386
581
  ></wc-calendar-column-view>
387
582
  `;
388
583
  }
@@ -394,8 +589,14 @@ export class Calendar extends LitElement {
394
589
  .contextDate=${contextDate}
395
590
  .weekStartsOn=${weekStartsOn}
396
591
  .locale=${locale}
592
+ .editable=${editable}
593
+ .addable=${this.addable}
594
+ .placeholder=${this._placeholder}
595
+ .untitledLabel=${untitled}
397
596
  ?events-readonly=${readonly}
398
597
  @event-click=${this._onViewEventClick}
598
+ @event-change=${this._onViewEventChange}
599
+ @event-add=${this._onViewEventAdd}
399
600
  ></wc-calendar-month-view>
400
601
  `;
401
602
  }
@@ -419,6 +620,7 @@ export class Calendar extends LitElement {
419
620
  <div class="calendar-body" aria-busy=${busy ? 'true' : 'false'}>
420
621
  <div class="view-container">${this._renderCalendarView()}</div>
421
622
  </div>
623
+ <div class="screen-reader-only" role="status" aria-live="polite"></div>
422
624
  </div>
423
625
  `;
424
626
  }
@@ -1,4 +1,5 @@
1
1
  import { CalendarEvent } from './calendar-event.js';
2
+ import { endOfDay, startOfDay } from './utils.js';
2
3
 
3
4
  export class ColumnEvent extends CalendarEvent {
4
5
  width: number = 1;
@@ -38,12 +39,15 @@ export class EventManager {
38
39
  for (let i = 0; i < events.length; i++) {
39
40
  if (i === 0) {
40
41
  column.push(events[i]);
41
- } else if (events[i].start.valueOf() >= column[column.length - 1].end.valueOf()) {
42
+ } else if (
43
+ events[i].start.valueOf() >= column[column.length - 1].end.valueOf()
44
+ ) {
42
45
  column.push(events[i]);
43
46
  }
44
47
  }
45
48
  this.columns.push(column);
46
- events = events.filter(e => !column.find(ce => ce.gid === e.gid));
49
+ const placed = new Set(column);
50
+ events = events.filter(e => !placed.has(e));
47
51
  }
48
52
 
49
53
  /* Calculate widths for events that span multiple columns */
@@ -90,17 +94,17 @@ export class MonthEventManager {
90
94
  if (i === 0) {
91
95
  column.push(events[i]);
92
96
  } else {
93
- const lastEnd = new Date(column[column.length - 1].end);
94
- lastEnd.setHours(23, 59, 59, 999);
95
- const nextStart = new Date(events[i].start);
96
- nextStart.setHours(0, 0, 0, 0);
97
+ // `end` is exclusive: an event ending at midnight leaves that day free.
98
+ const lastEnd = endOfDay(column[column.length - 1].lastDay());
99
+ const nextStart = startOfDay(events[i].start);
97
100
  if (nextStart.valueOf() > lastEnd.valueOf()) {
98
101
  column.push(events[i]);
99
102
  }
100
103
  }
101
104
  }
102
105
  this.columns.push(column);
103
- events = events.filter(e => !column.find(ce => ce.gid === e.gid));
106
+ const placed = new Set(column);
107
+ events = events.filter(e => !placed.has(e));
104
108
  }
105
109
 
106
110
  for (let i = 0; i < this.columns.length - 1; i++) {
@@ -1,5 +1,11 @@
1
- export { Calendar } from './calendar.js';
1
+ export { Calendar, applyCalendarChange } from './calendar.js';
2
2
  export type { CalendarDateChangeDetail } from './calendar.js';
3
3
  export { CalendarColumnView } from './calendar-column-view.js';
4
4
  export { CalendarMonthView } from './calendar-month-view.js';
5
- export type { CalendarViewType, EventType } from './types.js';
5
+ export type {
6
+ CalendarViewType,
7
+ EventType,
8
+ CalendarEventAddDetail,
9
+ CalendarEventChangeAction,
10
+ CalendarEventChangeDetail,
11
+ } from './types.js';
@@ -7,9 +7,44 @@ export type CalendarViewType = {
7
7
  };
8
8
 
9
9
  export type EventType = {
10
+ /**
11
+ * When the event starts. An event lasting a day or more, or running from one midnight to
12
+ * another, is shown in the all-day row.
13
+ */
10
14
  start: Date;
15
+ /** When the event ends, exclusive: an all-day event on November 4 ends at midnight on November 5. */
11
16
  end: Date;
12
17
  title: string;
18
+ /** A palette color name, such as `blue` or `green`. */
13
19
  color?: string;
20
+ /** Identifies the event, so `applyCalendarChange()` finds it after the array was replaced. */
21
+ id?: string | number;
22
+ /** `false` keeps this event in place when the calendar is `editable`. */
23
+ editable?: boolean;
14
24
  [key: string]: any;
15
25
  };
26
+
27
+ /** How an `event-change` changed the event. */
28
+ export type CalendarEventChangeAction = 'move' | 'resize';
29
+
30
+ /** Detail of `event-change`. */
31
+ export type CalendarEventChangeDetail = {
32
+ /** The event as it was, the object from `events`. */
33
+ event: EventType;
34
+ /** The new start. */
35
+ start: Date;
36
+ /** The new end. */
37
+ end: Date;
38
+ /** `move` when the event was dragged, `resize` when its start or end was. */
39
+ action: CalendarEventChangeAction;
40
+ };
41
+
42
+ /** Detail of `event-add`. */
43
+ export type CalendarEventAddDetail = {
44
+ /** Start of the range the person drew or clicked. */
45
+ start: Date;
46
+ /** End of the range, exclusive: midnight after the last day of an all-day range. */
47
+ end: Date;
48
+ /** Whether the range is whole days, drawn in the all-day row or the month view. */
49
+ allDay: boolean;
50
+ };