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