@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,403 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import {
3
+ addDays,
4
+ differenceInDays,
5
+ lastDayOf,
6
+ nextDay,
7
+ startOfDay,
8
+ } from './utils.js';
9
+
10
+ /** What a drag in a calendar view does. */
11
+ export type CalendarDragAction = 'add' | 'move' | 'resize-start' | 'resize-end';
12
+
13
+ /** Pixels a mouse or pen moves before a press becomes a drag. */
14
+ const DRAG_DISTANCE = 5;
15
+ /** Milliseconds a finger holds still before a press becomes a drag; moving sooner scrolls. */
16
+ const TOUCH_HOLD_MS = 300;
17
+ /** Pixels a finger may move during the hold. */
18
+ const TOUCH_SLOP = 8;
19
+ /** Distance from a scroller's edge, in pixels, at which a drag scrolls it. */
20
+ const SCROLL_EDGE = 40;
21
+ /** Fastest auto-scroll, in pixels per frame. */
22
+ const SCROLL_MAX = 24;
23
+
24
+ /** Where the pointer is, in viewport pixels. */
25
+ export interface DragPoint {
26
+ x: number;
27
+ y: number;
28
+ }
29
+
30
+ /** What a view does at each step of a press. `T` is what the view knows about the press. */
31
+ export interface DragHandlers<T> {
32
+ /** The press became a drag. `move` follows at once. */
33
+ lift(data: T, point: DragPoint): void;
34
+ /** The pointer moved during the drag, or a scroller scrolled under it. */
35
+ move(data: T, point: DragPoint): void;
36
+ /** The pointer was released after a drag. */
37
+ drop(data: T, point: DragPoint): void;
38
+ /** The drag ended without a drop: Escape, a canceled pointer, or the view left the page. */
39
+ cancel(data: T): void;
40
+ /** The pointer was released before the press became a drag. */
41
+ tap?(data: T, point: DragPoint): void;
42
+ /** Elements to scroll while the pointer is near their edges, along each axis they overflow. */
43
+ scrollers?(data: T): (HTMLElement | null)[];
44
+ }
45
+
46
+ interface Press<T> {
47
+ data: T;
48
+ pointerId: number;
49
+ pointerType: string;
50
+ startX: number;
51
+ startY: number;
52
+ x: number;
53
+ y: number;
54
+ lifted: boolean;
55
+ holdTimer?: ReturnType<typeof setTimeout>;
56
+ frame?: number;
57
+ }
58
+
59
+ /**
60
+ * The index of the element whose box holds the point, else of the nearest one; -1 when there are
61
+ * none. Without `y`, only the horizontal distance counts.
62
+ */
63
+ export function nearestIndex(elements: Element[], x: number, y?: number) {
64
+ let best = -1;
65
+ let bestDistance = Infinity;
66
+ elements.forEach((element, index) => {
67
+ const rect = element.getBoundingClientRect();
68
+ const dx = Math.max(0, rect.left - x, x - rect.right);
69
+ const dy = y === undefined ? 0 : Math.max(0, rect.top - y, y - rect.bottom);
70
+ const distance = Math.hypot(dx, dy);
71
+ if (distance < bestDistance) {
72
+ bestDistance = distance;
73
+ best = index;
74
+ }
75
+ });
76
+ return best;
77
+ }
78
+
79
+ /**
80
+ * Where a drag by whole days puts an event, or the days it adds: `from` is the day pressed and
81
+ * `to` the day under the pointer. Moves keep the event's times of day. Resizes keep the time of
82
+ * the edge that moves and never let the event end before it starts; an event that ends up shorter
83
+ * than a day is drawn in the hours from then on. An added range runs from midnight to the
84
+ * midnight after its last day.
85
+ */
86
+ export function dragByDays(
87
+ action: CalendarDragAction,
88
+ from: Date,
89
+ to: Date,
90
+ event?: { start: Date; end: Date },
91
+ ): { start: Date; end: Date } | null {
92
+ const fromDay = startOfDay(from);
93
+ const toDay = startOfDay(to);
94
+ if (action === 'add') {
95
+ const [first, last] =
96
+ fromDay.valueOf() <= toDay.valueOf()
97
+ ? [fromDay, toDay]
98
+ : [toDay, fromDay];
99
+ return { start: first, end: nextDay(last) };
100
+ }
101
+ if (!event) return null;
102
+ const { start, end } = event;
103
+ const firstDay = startOfDay(start);
104
+ const lastDay = lastDayOf(start, end);
105
+ if (action === 'move') {
106
+ const days = differenceInDays(toDay, fromDay);
107
+ return { start: addDays(start, days), end: addDays(end, days) };
108
+ }
109
+ if (action === 'resize-end') {
110
+ const target = toDay.valueOf() < firstDay.valueOf() ? firstDay : toDay;
111
+ let newEnd = addDays(end, differenceInDays(target, lastDay));
112
+ // An end earlier in the day than the start would make the event negative.
113
+ if (newEnd.valueOf() <= start.valueOf()) newEnd = addDays(newEnd, 1);
114
+ return { start, end: newEnd };
115
+ }
116
+ const target = toDay.valueOf() > lastDay.valueOf() ? lastDay : toDay;
117
+ let newStart = addDays(start, differenceInDays(target, firstDay));
118
+ if (newStart.valueOf() >= end.valueOf()) newStart = addDays(newStart, -1);
119
+ return { start: newStart, end };
120
+ }
121
+
122
+ /** Auto-scroll speed for a pointer at `position` along a scroller from `start` to `end`. */
123
+ function edgeSpeed(position: number, start: number, end: number): number {
124
+ let overshoot = 0;
125
+ if (position < start + SCROLL_EDGE)
126
+ overshoot = position - (start + SCROLL_EDGE);
127
+ else if (position > end - SCROLL_EDGE)
128
+ overshoot = position - (end - SCROLL_EDGE);
129
+ if (!overshoot) return 0;
130
+ return (
131
+ Math.sign(overshoot) *
132
+ Math.min(SCROLL_MAX, Math.ceil(Math.abs(overshoot) / 4))
133
+ );
134
+ }
135
+
136
+ /** Stops the next click from reaching anything, when it comes before the next task. */
137
+ function swallowNextClick() {
138
+ const swallow = (click: Event) => {
139
+ click.stopPropagation();
140
+ click.preventDefault();
141
+ };
142
+ window.addEventListener('click', swallow, { capture: true, once: true });
143
+ setTimeout(() => window.removeEventListener('click', swallow, true));
144
+ }
145
+
146
+ /**
147
+ * Turns presses in a calendar view into drags, the way `wc-kanban` does: a mouse or pen drags once
148
+ * it moves a few pixels, a finger once it has held still briefly (moving sooner scrolls). During a
149
+ * drag the pointer is captured by the view, the view's scrollers scroll near their edges, the page
150
+ * does not scroll under a finger, and Escape cancels. The click that ends a drag, dropped or
151
+ * canceled, is swallowed, so it does not also open an event.
152
+ *
153
+ * Set `enabled` while the view can be dragged in: the touch listener that keeps the page still is
154
+ * not passive, so read-only views do without it.
155
+ */
156
+ export class CalendarDragController<T> implements ReactiveController {
157
+ private press: Press<T> | null = null;
158
+
159
+ private readonly host: ReactiveControllerHost & HTMLElement;
160
+
161
+ private readonly handlers: DragHandlers<T>;
162
+
163
+ private _enabled = false;
164
+
165
+ private connected = false;
166
+
167
+ constructor(
168
+ host: ReactiveControllerHost & HTMLElement,
169
+ handlers: DragHandlers<T>,
170
+ ) {
171
+ this.host = host;
172
+ this.handlers = handlers;
173
+ host.addController(this);
174
+ }
175
+
176
+ /** Whether presses can become drags; turning it off cancels a drag in progress. */
177
+ get enabled(): boolean {
178
+ return this._enabled;
179
+ }
180
+
181
+ set enabled(value: boolean) {
182
+ if (value === this._enabled) return;
183
+ this._enabled = value;
184
+ if (!value) this.abort();
185
+ this.listen();
186
+ }
187
+
188
+ /** Whether a press is being followed, dragging or not yet. */
189
+ get pressing(): boolean {
190
+ return this.press !== null;
191
+ }
192
+
193
+ /** Whether a drag is in progress. */
194
+ get dragging(): boolean {
195
+ return this.press?.lifted ?? false;
196
+ }
197
+
198
+ hostConnected() {
199
+ this.connected = true;
200
+ this.listen();
201
+ }
202
+
203
+ hostDisconnected() {
204
+ this.connected = false;
205
+ this.listen();
206
+ this.abort();
207
+ }
208
+
209
+ /**
210
+ * Follows a press from its `pointerdown`. Returns `false`, ignoring it, when not `enabled`, for
211
+ * a secondary button or pointer, or while another press is followed.
212
+ */
213
+ start(event: PointerEvent, data: T): boolean {
214
+ if (!this._enabled || !event.isPrimary || event.button !== 0) return false;
215
+ if (this.press) return false;
216
+ const press: Press<T> = {
217
+ data,
218
+ pointerId: event.pointerId,
219
+ pointerType: event.pointerType,
220
+ startX: event.clientX,
221
+ startY: event.clientY,
222
+ x: event.clientX,
223
+ y: event.clientY,
224
+ lifted: false,
225
+ };
226
+ this.press = press;
227
+ if (press.pointerType === 'touch') {
228
+ press.holdTimer = setTimeout(() => this.lift(), TOUCH_HOLD_MS);
229
+ }
230
+ window.addEventListener('pointermove', this.handlePointerMove);
231
+ window.addEventListener('pointerup', this.handlePointerUp);
232
+ window.addEventListener('pointercancel', this.handlePointerCancel);
233
+ window.addEventListener('keydown', this.handleKeyDown, true);
234
+ return true;
235
+ }
236
+
237
+ /** Stops following the press; a drag in progress is canceled. */
238
+ abort() {
239
+ const { press } = this;
240
+ if (!press) return;
241
+ this.end();
242
+ if (press.lifted) this.handlers.cancel(press.data);
243
+ }
244
+
245
+ /** Adds the host's listeners while it is connected and enabled, and removes them otherwise. */
246
+ private listen() {
247
+ const { host } = this;
248
+ host.removeEventListener('touchmove', this.handleTouchMove);
249
+ host.removeEventListener('contextmenu', this.handleContextMenu);
250
+ host.removeEventListener('lostpointercapture', this.handleLostCapture);
251
+ if (!this.connected || !this._enabled) return;
252
+ host.addEventListener('touchmove', this.handleTouchMove, {
253
+ passive: false,
254
+ });
255
+ host.addEventListener('contextmenu', this.handleContextMenu);
256
+ host.addEventListener('lostpointercapture', this.handleLostCapture);
257
+ }
258
+
259
+ private lift() {
260
+ const { press } = this;
261
+ if (!press || press.lifted) return;
262
+ press.lifted = true;
263
+ // The element pressed may be drawn again during the drag; the host stays.
264
+ try {
265
+ this.host.setPointerCapture(press.pointerId);
266
+ } catch {
267
+ // Not an active pointer, as for events made by scripts.
268
+ }
269
+ const point = { x: press.x, y: press.y };
270
+ this.handlers.lift(press.data, point);
271
+ if (this.press !== press) return;
272
+ this.handlers.move(press.data, point);
273
+ const tick = () => {
274
+ if (this.press !== press) return;
275
+ this.autoScroll(press);
276
+ press.frame = requestAnimationFrame(tick);
277
+ };
278
+ press.frame = requestAnimationFrame(tick);
279
+ }
280
+
281
+ private autoScroll(press: Press<T>) {
282
+ let scrolled = false;
283
+ (this.handlers.scrollers?.(press.data) ?? []).forEach(scroller => {
284
+ if (!scroller) return;
285
+ const rect = scroller.getBoundingClientRect();
286
+ const top =
287
+ scroller.scrollHeight > scroller.clientHeight
288
+ ? edgeSpeed(press.y, rect.top, rect.bottom)
289
+ : 0;
290
+ const left =
291
+ scroller.scrollWidth > scroller.clientWidth
292
+ ? edgeSpeed(press.x, rect.left, rect.right)
293
+ : 0;
294
+ if (!top && !left) return;
295
+ const { scrollTop, scrollLeft } = scroller;
296
+ scroller.scrollBy({ top, left });
297
+ scrolled ||=
298
+ scroller.scrollTop !== scrollTop || scroller.scrollLeft !== scrollLeft;
299
+ });
300
+ if (scrolled) this.handlers.move(press.data, { x: press.x, y: press.y });
301
+ }
302
+
303
+ /** Stops following the press without telling the view. */
304
+ private end() {
305
+ const { press } = this;
306
+ if (!press) return;
307
+ this.press = null;
308
+ if (press.holdTimer) clearTimeout(press.holdTimer);
309
+ if (press.frame !== undefined) cancelAnimationFrame(press.frame);
310
+ window.removeEventListener('pointermove', this.handlePointerMove);
311
+ window.removeEventListener('pointerup', this.handlePointerUp);
312
+ window.removeEventListener('pointercancel', this.handlePointerCancel);
313
+ window.removeEventListener('keydown', this.handleKeyDown, true);
314
+ }
315
+
316
+ /** After a drag canceled with the button still down, swallows the click its release makes. */
317
+ private swallowClickAfterRelease(pointerId: number) {
318
+ const release = (event: PointerEvent) => {
319
+ if (event.pointerId !== pointerId) return;
320
+ window.removeEventListener('pointerup', release, true);
321
+ window.removeEventListener('pointercancel', release, true);
322
+ if (event.type === 'pointerup') swallowNextClick();
323
+ };
324
+ window.addEventListener('pointerup', release, true);
325
+ window.addEventListener('pointercancel', release, true);
326
+ }
327
+
328
+ private readonly handlePointerMove = (event: PointerEvent) => {
329
+ const { press } = this;
330
+ if (!press || event.pointerId !== press.pointerId) return;
331
+ press.x = event.clientX;
332
+ press.y = event.clientY;
333
+ if (!press.lifted) {
334
+ const distance = Math.hypot(
335
+ press.x - press.startX,
336
+ press.y - press.startY,
337
+ );
338
+ if (press.pointerType === 'touch') {
339
+ // Moving before the hold ends is a scroll, not a drag.
340
+ if (distance > TOUCH_SLOP) this.end();
341
+ return;
342
+ }
343
+ if (distance >= DRAG_DISTANCE) this.lift();
344
+ return;
345
+ }
346
+ // A mouse whose release never arrived, for example outside the window, no longer drags.
347
+ if (press.pointerType === 'mouse' && event.buttons === 0) {
348
+ this.abort();
349
+ return;
350
+ }
351
+ event.preventDefault();
352
+ this.handlers.move(press.data, { x: press.x, y: press.y });
353
+ };
354
+
355
+ private readonly handlePointerUp = (event: PointerEvent) => {
356
+ const { press } = this;
357
+ if (!press || event.pointerId !== press.pointerId) return;
358
+ press.x = event.clientX;
359
+ press.y = event.clientY;
360
+ this.end();
361
+ const point = { x: press.x, y: press.y };
362
+ if (!press.lifted) {
363
+ this.handlers.tap?.(press.data, point);
364
+ return;
365
+ }
366
+ // The click that follows a drag is not a click on what was dragged.
367
+ swallowNextClick();
368
+ this.handlers.drop(press.data, point);
369
+ };
370
+
371
+ private readonly handlePointerCancel = (event: PointerEvent) => {
372
+ if (!this.press || event.pointerId !== this.press.pointerId) return;
373
+ this.abort();
374
+ };
375
+
376
+ private readonly handleLostCapture = (event: PointerEvent) => {
377
+ // Capture ends with the release, after `pointerup` has ended the press; losing it any other
378
+ // way would leave a drag no event can end.
379
+ if (this.press?.lifted && event.pointerId === this.press.pointerId) {
380
+ this.abort();
381
+ }
382
+ };
383
+
384
+ private readonly handleKeyDown = (event: KeyboardEvent) => {
385
+ const { press } = this;
386
+ if (event.key !== 'Escape' || !press?.lifted) return;
387
+ // Keep an enclosing dialog open.
388
+ event.preventDefault();
389
+ event.stopPropagation();
390
+ this.abort();
391
+ this.swallowClickAfterRelease(press.pointerId);
392
+ };
393
+
394
+ private readonly handleTouchMove = (event: TouchEvent) => {
395
+ // Keep the page from scrolling under a drag.
396
+ if (this.press?.lifted && event.cancelable) event.preventDefault();
397
+ };
398
+
399
+ private readonly handleContextMenu = (event: Event) => {
400
+ // A long press on touch screens opens the context menu.
401
+ if (this.press) event.preventDefault();
402
+ };
403
+ }
@@ -0,0 +1,78 @@
1
+ import { html } from 'lit';
2
+
3
+ /** One button of the header's view switcher. */
4
+ export interface CalendarHeaderView {
5
+ value: string;
6
+ label: string;
7
+ }
8
+
9
+ /** What the header shows, and what its controls do. */
10
+ export interface CalendarHeaderOptions {
11
+ /** The period shown, read out when it changes. */
12
+ title: string;
13
+ views: CalendarHeaderView[];
14
+ /** The `value` of the selected view. */
15
+ view: string;
16
+ labels: { today: string; previous: string; next: string };
17
+ onToday: () => void;
18
+ onPrevious: () => void;
19
+ onNext: () => void;
20
+ onViewChange: (value: string) => void;
21
+ }
22
+
23
+ /**
24
+ * The header `wc-calendar` and `wc-calendar-timeline` share: a Today button, Previous and Next, the
25
+ * period shown (a polite live region) and the views as segmented buttons. Its styles are the
26
+ * `styles` mixin of `_calendar-header.scss`.
27
+ */
28
+ export function renderCalendarHeader(options: CalendarHeaderOptions) {
29
+ const onChange = (event: CustomEvent<{ value: string | null }>) => {
30
+ if (event.detail.value) options.onViewChange(event.detail.value);
31
+ };
32
+ return html`
33
+ <div class="calendar-header-classic">
34
+ <div class="header-left">
35
+ <wc-button
36
+ variant="outlined"
37
+ size="sm"
38
+ class="color-secondary"
39
+ @click=${options.onToday}
40
+ >
41
+ ${options.labels.today}
42
+ </wc-button>
43
+ <wc-icon-button
44
+ variant="text"
45
+ size="sm"
46
+ class="color-secondary"
47
+ aria-label=${options.labels.previous}
48
+ @click=${options.onPrevious}
49
+ >
50
+ <wc-icon name="chevron_left"></wc-icon>
51
+ </wc-icon-button>
52
+ <wc-icon-button
53
+ variant="text"
54
+ size="sm"
55
+ class="color-secondary"
56
+ aria-label=${options.labels.next}
57
+ @click=${options.onNext}
58
+ >
59
+ <wc-icon name="chevron_right"></wc-icon>
60
+ </wc-icon-button>
61
+ <div class="title" aria-live="polite">${options.title}</div>
62
+ </div>
63
+ <div class="header-right">
64
+ <wc-segmented-button-group @change=${onChange}>
65
+ ${options.views.map(
66
+ view =>
67
+ html`<wc-segmented-button
68
+ .value=${view.value}
69
+ ?selected=${options.view === view.value}
70
+ >
71
+ ${view.label}
72
+ </wc-segmented-button>`,
73
+ )}
74
+ </wc-segmented-button-group>
75
+ </div>
76
+ </div>
77
+ `;
78
+ }
@@ -194,4 +194,93 @@
194
194
  border-top-color: var(--color-primary);
195
195
  }
196
196
  }
197
+
198
+ // The days a drag would give an event, or that a new event waits on.
199
+ &.drop-target {
200
+ background: color-mix(in srgb, var(--color-primary) 14%, transparent);
201
+ box-shadow: inset 0 0 0 1px var(--color-primary);
202
+ }
203
+ }
204
+
205
+ /* ── Editing ── */
206
+
207
+ // Days take presses that add events, so they must not start a text selection or a long-press
208
+ // callout.
209
+ .calendar-month-view.addable .drawing-area {
210
+ user-select: none;
211
+ -webkit-touch-callout: none;
212
+ }
213
+
214
+ .calendar-month-view.dragging {
215
+ user-select: none;
216
+
217
+ // Other events let the pointer through, so they neither flicker on hover nor set the cursor.
218
+ .event {
219
+ pointer-events: none;
220
+ }
221
+ }
222
+
223
+ .calendar-month-view.drag-move {
224
+ cursor: grabbing;
225
+ }
226
+
227
+ .calendar-month-view.drag-resize-x {
228
+ cursor: ew-resize;
229
+ }
230
+
231
+ .event {
232
+ &.editable {
233
+ cursor: grab;
234
+ user-select: none;
235
+ -webkit-touch-callout: none;
236
+ }
237
+
238
+ // The event being dragged stays in place, faded, while its new days are highlighted.
239
+ &.drag-source {
240
+ opacity: 0.4;
241
+ }
242
+ }
243
+
244
+ // A grip at each edge an all-day event can be resized by; the line in it shows on hover and focus.
245
+ .resize-handle {
246
+ position: absolute;
247
+ z-index: 1;
248
+ inset-block: 0;
249
+ inline-size: 0.375rem;
250
+ cursor: ew-resize;
251
+
252
+ &.start {
253
+ inset-inline-start: 0;
254
+ }
255
+
256
+ &.end {
257
+ inset-inline-end: 0;
258
+ }
259
+
260
+ &::after {
261
+ content: '';
262
+ position: absolute;
263
+ inset: 0;
264
+ margin: auto;
265
+ inline-size: 0.125rem;
266
+ block-size: 0.875rem;
267
+ border-radius: var(--shape-corner-full);
268
+ background: currentColor;
269
+ opacity: 0;
270
+ transition: opacity 150ms ease;
271
+ }
272
+ }
273
+
274
+ .event.editable:hover,
275
+ .event.editable:focus-visible {
276
+ .resize-handle::after {
277
+ opacity: 0.6;
278
+ }
279
+ }
280
+
281
+ @media (forced-colors: active) {
282
+ .column.drop-target {
283
+ outline: 2px solid Highlight;
284
+ outline-offset: -2px;
285
+ }
197
286
  }