@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.
- package/dist/{BaseField-Cj2rNVeC.js → BaseField-BbOj212R.js} +3 -3
- package/dist/{BaseField-Cj2rNVeC.js.map → BaseField-BbOj212R.js.map} +1 -1
- package/dist/{BaseInput-CSOLv2-i.js → BaseInput-Cv03GZLu.js} +2 -2
- package/dist/{BaseInput-CSOLv2-i.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-DduJjUeq.js → base-progress-CqsyiVOV.js} +2 -2
- package/dist/{base-progress-DduJjUeq.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-Bfpv5_HJ.js → canvas-base-BjiU3Ecl.js} +2 -2
- package/dist/{canvas-base-Bfpv5_HJ.js.map → canvas-base-BjiU3Ecl.js.map} +1 -1
- package/dist/carousel.js +2 -2
- package/dist/{cartesian-chart-SnqFbbXV.js → cartesian-chart-iE3cmeGF.js} +2 -2
- package/dist/{cartesian-chart-SnqFbbXV.js.map → cartesian-chart-iE3cmeGF.js.map} +1 -1
- package/dist/{cb-group-base-DZIzMlen.js → cb-group-base-CWctDJvy.js} +2 -2
- package/dist/{cb-group-base-DZIzMlen.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-C2N0WQLI.js → chart-base-CDyVDmz7.js} +2 -2
- package/dist/{chart-base-C2N0WQLI.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-W_Kddt7I.js → diagram-D2aM93kf.js} +2 -2
- package/dist/{diagram-W_Kddt7I.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-dBgmcyUW.js → document-editor-BS6al7Hq.js} +2 -2
- package/dist/{document-editor-dBgmcyUW.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-CfW6yMpY.js → generative-view-DsSOPf26.js} +2 -2
- package/dist/{generative-view-CfW6yMpY.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-DNAjVSIP.js → i18n-controller-BTeChxE0.js} +2 -2
- package/dist/{i18n-controller-DNAjVSIP.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-Mi7_hbo8.js → picker-field-DmXYPvbF.js} +3 -3
- package/dist/{picker-field-Mi7_hbo8.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-O1ku1q-J.js → rich-text-input-BCZ46UF8.js} +3 -3
- package/dist/{rich-text-input-O1ku1q-J.js.map → rich-text-input-BCZ46UF8.js.map} +1 -1
- package/dist/{schema-BWH1ANdE.js → schema-D0PCeIEA.js} +2 -2
- package/dist/{schema-BWH1ANdE.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 +16 -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/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-BpCoUL0V.js → strings-DeiQWMd9.js} +18 -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-BRNNka2o.js → toggle-base-BtjRAZ5z.js} +2 -2
- package/dist/{toggle-base-BRNNka2o.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-DBdRuyh4.js → video-DPjOBk6I.js} +2 -2
- package/dist/{video-DBdRuyh4.js.map → video-DPjOBk6I.js.map} +1 -1
- package/dist/video.js +3 -3
- package/dist/virtual-list.js +2 -2
- package/dist/workflow-timeline.js +2 -2
- package/dist/workflow.js +3 -3
- package/dist/workspace-switcher.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/__internal/i18n/strings.ts +25 -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/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-BpCoUL0V.js.map +0 -1
- package/dist/utils-D92ldd1V.js.map +0 -1
|
@@ -1,27 +1,82 @@
|
|
|
1
1
|
import { LitElement, html, nothing, PropertyValues, TemplateResult } from 'lit';
|
|
2
2
|
import { property, state } from 'lit/decorators.js';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
3
4
|
import {
|
|
4
5
|
addDays,
|
|
5
6
|
addHours,
|
|
7
|
+
clamp,
|
|
6
8
|
differenceInDays,
|
|
7
9
|
startOfDay,
|
|
8
|
-
endOfDay,
|
|
9
10
|
calculateDateRange,
|
|
10
11
|
formatDate,
|
|
11
12
|
formatEventLabel,
|
|
13
|
+
formatTimeRange,
|
|
12
14
|
getTimePercent,
|
|
15
|
+
lastDayOf,
|
|
16
|
+
nextDay,
|
|
17
|
+
rangesOverlap,
|
|
18
|
+
snapTime,
|
|
19
|
+
timeAtFraction,
|
|
13
20
|
LONG_EVENT_PADDING,
|
|
21
|
+
MINUTE_MS,
|
|
14
22
|
onActivateKey,
|
|
15
23
|
} from './utils.js';
|
|
16
|
-
import { BaseEvent } from './base-event.js';
|
|
17
24
|
import { CalendarEvent } from './calendar-event.js';
|
|
25
|
+
import {
|
|
26
|
+
CalendarDragController,
|
|
27
|
+
dragByDays,
|
|
28
|
+
nearestIndex,
|
|
29
|
+
type CalendarDragAction,
|
|
30
|
+
type DragPoint,
|
|
31
|
+
} from './calendar-drag.js';
|
|
18
32
|
import { EventManager } from './event-manager.js';
|
|
19
33
|
import type { ColumnEvent } from './event-manager.js';
|
|
34
|
+
import type {
|
|
35
|
+
CalendarEventAddDetail,
|
|
36
|
+
CalendarEventChangeDetail,
|
|
37
|
+
EventType,
|
|
38
|
+
} from './types.js';
|
|
20
39
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
21
40
|
import { resolveLocale } from '@/__internal/i18n/locale.js';
|
|
22
41
|
import type { WeekDay } from '@/__internal/utils/date.js';
|
|
23
42
|
import styles from './calendar-column-view.scss';
|
|
24
43
|
|
|
44
|
+
/** The part of the view a drag happens in: the hours, or the all-day row above them. */
|
|
45
|
+
type Section = 'timed' | 'all-day';
|
|
46
|
+
|
|
47
|
+
/** A press that may become a drag. */
|
|
48
|
+
interface ColumnPress {
|
|
49
|
+
action: CalendarDragAction;
|
|
50
|
+
section: Section;
|
|
51
|
+
/** The event pressed; none when adding. */
|
|
52
|
+
event?: ColumnEvent;
|
|
53
|
+
/** The day under the press. */
|
|
54
|
+
day: Date;
|
|
55
|
+
/** The time under the press; midnight in the all-day row. */
|
|
56
|
+
time: Date;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Where a drag would put an event, or the range it would add. */
|
|
60
|
+
interface ColumnPreview {
|
|
61
|
+
action: CalendarDragAction;
|
|
62
|
+
section: Section;
|
|
63
|
+
/** The dragged event's object from `events`; none when adding. */
|
|
64
|
+
data?: EventType;
|
|
65
|
+
title: string;
|
|
66
|
+
color?: string;
|
|
67
|
+
start: Date;
|
|
68
|
+
end: Date;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** How an event block takes part in a drag. */
|
|
72
|
+
type DragRole = 'source' | 'lifted' | null;
|
|
73
|
+
|
|
74
|
+
/** Events shorter than this have no handle at their start, so there is room to grab them. */
|
|
75
|
+
const START_HANDLE_MIN_MS = 30 * MINUTE_MS;
|
|
76
|
+
|
|
77
|
+
/** Previews shorter than this show their title and times on one line. */
|
|
78
|
+
const COMPACT_PREVIEW_MS = 45 * MINUTE_MS;
|
|
79
|
+
|
|
25
80
|
/**
|
|
26
81
|
* @internal
|
|
27
82
|
*
|
|
@@ -36,9 +91,13 @@ import styles from './calendar-column-view.scss';
|
|
|
36
91
|
* that open the day; events are buttons labelled with their title and time, or notes that cannot
|
|
37
92
|
* be focused when <code>events-readonly</code> is set. Events lasting a day or more are shown in a
|
|
38
93
|
* row above the hours.</p>
|
|
94
|
+
* <p>With <code>editable</code>, events are dragged to move them and their edges to resize them;
|
|
95
|
+
* with <code>addable</code>, dragging across empty time or clicking it asks for a new event.</p>
|
|
39
96
|
*
|
|
40
97
|
* @fires date-click - Internal, does not bubble; a day number was chosen. Detail contains `{ date }`.
|
|
41
98
|
* @fires event-click - Internal, does not bubble; `wc-calendar` re-fires it. Detail contains `{ event }`.
|
|
99
|
+
* @fires event-change - Internal, does not bubble; an event was dropped at a new time. `wc-calendar` re-fires it.
|
|
100
|
+
* @fires event-add - Internal, does not bubble; a range of empty time was drawn or clicked. `wc-calendar` re-fires it.
|
|
42
101
|
*/
|
|
43
102
|
@IndividualComponent
|
|
44
103
|
export class CalendarColumnView extends LitElement {
|
|
@@ -64,6 +123,34 @@ export class CalendarColumnView extends LitElement {
|
|
|
64
123
|
@property({ type: Boolean, attribute: 'events-readonly' })
|
|
65
124
|
eventsReadonly: boolean = false;
|
|
66
125
|
|
|
126
|
+
/** Events can be moved and resized by dragging. */
|
|
127
|
+
@property({ type: Boolean })
|
|
128
|
+
editable: boolean = false;
|
|
129
|
+
|
|
130
|
+
/** Dragging across empty time, or clicking it, asks for a new event. */
|
|
131
|
+
@property({ type: Boolean })
|
|
132
|
+
addable: boolean = false;
|
|
133
|
+
|
|
134
|
+
/** Minutes that drags move timed events and their edges by. */
|
|
135
|
+
@property({ type: Number, attribute: false })
|
|
136
|
+
minuteStep: number = 15;
|
|
137
|
+
|
|
138
|
+
/** Minutes an event added by a click lasts. */
|
|
139
|
+
@property({ type: Number, attribute: false })
|
|
140
|
+
defaultDuration: number = 60;
|
|
141
|
+
|
|
142
|
+
/** A range waiting for its new event, drawn as one. */
|
|
143
|
+
@property({ attribute: false })
|
|
144
|
+
placeholder: CalendarEventAddDetail | null = null;
|
|
145
|
+
|
|
146
|
+
/** Title shown for an event without one. */
|
|
147
|
+
@property({ attribute: false })
|
|
148
|
+
untitledLabel: string = '(no title)';
|
|
149
|
+
|
|
150
|
+
/** Title of the block that marks a new event. */
|
|
151
|
+
@property({ attribute: false })
|
|
152
|
+
newEventLabel: string = 'New event';
|
|
153
|
+
|
|
67
154
|
/** Now, which places the current-time line and marks today. */
|
|
68
155
|
@property({ type: Object, attribute: false })
|
|
69
156
|
currentTime: Date = new Date();
|
|
@@ -98,6 +185,27 @@ export class CalendarColumnView extends LitElement {
|
|
|
98
185
|
@state()
|
|
99
186
|
private multiDayEvents: ColumnEvent[][] = [];
|
|
100
187
|
|
|
188
|
+
/** The drag in progress, where it would put its event. */
|
|
189
|
+
@state()
|
|
190
|
+
private _preview: ColumnPreview | null = null;
|
|
191
|
+
|
|
192
|
+
// ── Private fields
|
|
193
|
+
|
|
194
|
+
private readonly _drag = new CalendarDragController<ColumnPress>(this, {
|
|
195
|
+
lift: () => this._blurFocused(),
|
|
196
|
+
move: (press, point) => this._follow(press, point),
|
|
197
|
+
drop: (press, point) => this._drop(press, point),
|
|
198
|
+
cancel: () => {
|
|
199
|
+
this._preview = null;
|
|
200
|
+
},
|
|
201
|
+
tap: press => this._tap(press),
|
|
202
|
+
scrollers: press => [
|
|
203
|
+
this.renderRoot.querySelector<HTMLElement>(
|
|
204
|
+
press.section === 'timed' ? '.view-body' : '.multi-day-section-scroll',
|
|
205
|
+
),
|
|
206
|
+
],
|
|
207
|
+
});
|
|
208
|
+
|
|
101
209
|
// ── Lifecycle
|
|
102
210
|
|
|
103
211
|
override connectedCallback() {
|
|
@@ -117,6 +225,7 @@ export class CalendarColumnView extends LitElement {
|
|
|
117
225
|
|
|
118
226
|
override willUpdate(changed: PropertyValues<this>) {
|
|
119
227
|
super.willUpdate(changed);
|
|
228
|
+
this._drag.enabled = this.addable || (this.editable && this._interactive);
|
|
120
229
|
if (
|
|
121
230
|
changed.has('events') ||
|
|
122
231
|
changed.has('contextDate') ||
|
|
@@ -126,6 +235,19 @@ export class CalendarColumnView extends LitElement {
|
|
|
126
235
|
) {
|
|
127
236
|
this._processEvents();
|
|
128
237
|
}
|
|
238
|
+
// A drag cannot outlive the days it started on, or editing being turned off.
|
|
239
|
+
if (
|
|
240
|
+
this._drag.pressing &&
|
|
241
|
+
(changed.has('contextDate') ||
|
|
242
|
+
changed.has('view') ||
|
|
243
|
+
changed.has('days') ||
|
|
244
|
+
changed.has('weekStartsOn') ||
|
|
245
|
+
changed.has('editable') ||
|
|
246
|
+
changed.has('addable') ||
|
|
247
|
+
changed.has('eventsReadonly'))
|
|
248
|
+
) {
|
|
249
|
+
this._drag.abort();
|
|
250
|
+
}
|
|
129
251
|
}
|
|
130
252
|
|
|
131
253
|
// ── Private methods
|
|
@@ -139,6 +261,24 @@ export class CalendarColumnView extends LitElement {
|
|
|
139
261
|
return resolveLocale(this.locale, this);
|
|
140
262
|
}
|
|
141
263
|
|
|
264
|
+
/** `minuteStep` when it is a whole number of minutes in a day, else 15. */
|
|
265
|
+
private get _step(): number {
|
|
266
|
+
const step = Math.round(this.minuteStep);
|
|
267
|
+
return Number.isFinite(step) && step >= 1 ? Math.min(step, 1440) : 15;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** `defaultDuration` when it is a positive number of minutes, else 60. */
|
|
271
|
+
private get _duration(): number {
|
|
272
|
+
const minutes = Math.round(this.defaultDuration);
|
|
273
|
+
return Number.isFinite(minutes) && minutes >= 1 ? minutes : 60;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Whether an event can be dragged: the view is editable and the event did not opt out. */
|
|
277
|
+
private _canEdit(node: CalendarEvent): boolean {
|
|
278
|
+
const data = node.data as EventType | undefined;
|
|
279
|
+
return this.editable && this._interactive && data?.editable !== false;
|
|
280
|
+
}
|
|
281
|
+
|
|
142
282
|
private _processEvents() {
|
|
143
283
|
this.dateRange = calculateDateRange(
|
|
144
284
|
this.view,
|
|
@@ -149,25 +289,32 @@ export class CalendarColumnView extends LitElement {
|
|
|
149
289
|
this.singleDayEvents = {};
|
|
150
290
|
|
|
151
291
|
this._forEachDayInRange(i => {
|
|
292
|
+
const dayStart = startOfDay(i);
|
|
293
|
+
const dayEnd = nextDay(dayStart);
|
|
152
294
|
const manager = new EventManager();
|
|
153
295
|
manager.addEvents(
|
|
154
296
|
this.events.filter(
|
|
155
297
|
event =>
|
|
156
|
-
event.
|
|
157
|
-
event.
|
|
298
|
+
!event.isAllDay() &&
|
|
299
|
+
rangesOverlap(event.start, event.end, dayStart, dayEnd),
|
|
158
300
|
),
|
|
159
301
|
);
|
|
160
302
|
manager.process();
|
|
161
303
|
this.singleDayEvents[this._getDateOnly(i)] = manager.columns;
|
|
162
304
|
});
|
|
163
305
|
|
|
306
|
+
const rangeEnd = nextDay(this.dateRange.endDate);
|
|
164
307
|
const multiManager = new EventManager();
|
|
165
308
|
multiManager.addEvents(
|
|
166
309
|
this.events.filter(
|
|
167
310
|
event =>
|
|
168
|
-
event.
|
|
169
|
-
|
|
170
|
-
|
|
311
|
+
event.isAllDay() &&
|
|
312
|
+
rangesOverlap(
|
|
313
|
+
event.start,
|
|
314
|
+
event.end,
|
|
315
|
+
this.dateRange.startDate,
|
|
316
|
+
rangeEnd,
|
|
317
|
+
),
|
|
171
318
|
),
|
|
172
319
|
);
|
|
173
320
|
multiManager.process();
|
|
@@ -228,6 +375,18 @@ export class CalendarColumnView extends LitElement {
|
|
|
228
375
|
this.dispatchEvent(new CustomEvent('event-click', { detail: { event } }));
|
|
229
376
|
}
|
|
230
377
|
|
|
378
|
+
private _emitChange(detail: CalendarEventChangeDetail) {
|
|
379
|
+
this.dispatchEvent(
|
|
380
|
+
new CustomEvent<CalendarEventChangeDetail>('event-change', { detail }),
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private _emitAdd(detail: CalendarEventAddDetail) {
|
|
385
|
+
this.dispatchEvent(
|
|
386
|
+
new CustomEvent<CalendarEventAddDetail>('event-add', { detail }),
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
231
390
|
/** Accessible name of the view: the dates it shows. */
|
|
232
391
|
private _rangeLabel(): string {
|
|
233
392
|
const { startDate, endDate } = this.dateRange;
|
|
@@ -247,6 +406,282 @@ export class CalendarColumnView extends LitElement {
|
|
|
247
406
|
.join(';');
|
|
248
407
|
}
|
|
249
408
|
|
|
409
|
+
// ── Drag and drop
|
|
410
|
+
|
|
411
|
+
/** The day columns of a section. */
|
|
412
|
+
private _columnsOf(section: Section): HTMLElement[] {
|
|
413
|
+
return [
|
|
414
|
+
...this.renderRoot.querySelectorAll<HTMLElement>(
|
|
415
|
+
section === 'timed'
|
|
416
|
+
? '.events-container > .column'
|
|
417
|
+
: '.multi-day-background .columns > .column',
|
|
418
|
+
),
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** The day of the column nearest `x`; with `within`, only a column that spans `x`. */
|
|
423
|
+
private _dayAt(section: Section, x: number, within = false): Date | null {
|
|
424
|
+
const columns = this._columnsOf(section);
|
|
425
|
+
const index = nearestIndex(columns, x);
|
|
426
|
+
if (index < 0) return null;
|
|
427
|
+
if (within) {
|
|
428
|
+
const rect = columns[index].getBoundingClientRect();
|
|
429
|
+
if (x < rect.left || x > rect.right) return null;
|
|
430
|
+
}
|
|
431
|
+
return startOfDay(addDays(this.dateRange.startDate, index));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** The time at `y` in `day`'s column of the hours. */
|
|
435
|
+
private _timeAt(day: Date, y: number): Date {
|
|
436
|
+
const rect = this.renderRoot
|
|
437
|
+
.querySelector('.events-container')
|
|
438
|
+
?.getBoundingClientRect();
|
|
439
|
+
if (!rect || rect.height <= 0) return startOfDay(day);
|
|
440
|
+
return timeAtFraction(day, (y - rect.top) / rect.height);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
private _onEventPointerDown(
|
|
444
|
+
event: PointerEvent,
|
|
445
|
+
node: ColumnEvent,
|
|
446
|
+
section: Section,
|
|
447
|
+
) {
|
|
448
|
+
if (!this._canEdit(node)) return;
|
|
449
|
+
const handle =
|
|
450
|
+
event.target instanceof Element
|
|
451
|
+
? event.target.closest<HTMLElement>('[data-handle]')?.dataset.handle
|
|
452
|
+
: undefined;
|
|
453
|
+
let action: CalendarDragAction = 'move';
|
|
454
|
+
if (handle === 'start') action = 'resize-start';
|
|
455
|
+
else if (handle === 'end') action = 'resize-end';
|
|
456
|
+
const day = this._dayAt(section, event.clientX) ?? startOfDay(node.start);
|
|
457
|
+
this._drag.start(event, {
|
|
458
|
+
action,
|
|
459
|
+
section,
|
|
460
|
+
event: node,
|
|
461
|
+
day,
|
|
462
|
+
time: section === 'timed' ? this._timeAt(day, event.clientY) : day,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private _onSectionPointerDown(event: PointerEvent, section: Section) {
|
|
467
|
+
if (!this.addable || this._drag.pressing) return;
|
|
468
|
+
// Presses on events are theirs, even on events that cannot be dragged.
|
|
469
|
+
const onEvent = event
|
|
470
|
+
.composedPath()
|
|
471
|
+
.some(
|
|
472
|
+
target =>
|
|
473
|
+
target instanceof HTMLElement && target.classList.contains('event'),
|
|
474
|
+
);
|
|
475
|
+
if (onEvent) return;
|
|
476
|
+
const day = this._dayAt(section, event.clientX, true);
|
|
477
|
+
if (!day) return;
|
|
478
|
+
this._drag.start(event, {
|
|
479
|
+
action: 'add',
|
|
480
|
+
section,
|
|
481
|
+
day,
|
|
482
|
+
time: section === 'timed' ? this._timeAt(day, event.clientY) : day,
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Where the drag of `press` would put its event with the pointer at `point`. */
|
|
487
|
+
private _previewFor(
|
|
488
|
+
press: ColumnPress,
|
|
489
|
+
point: DragPoint,
|
|
490
|
+
): ColumnPreview | null {
|
|
491
|
+
const { event } = press;
|
|
492
|
+
const range =
|
|
493
|
+
press.section === 'timed'
|
|
494
|
+
? this._timedRange(press, point)
|
|
495
|
+
: dragByDays(
|
|
496
|
+
press.action,
|
|
497
|
+
press.day,
|
|
498
|
+
this._dayAt('all-day', point.x) ?? press.day,
|
|
499
|
+
event,
|
|
500
|
+
);
|
|
501
|
+
if (!range) return null;
|
|
502
|
+
return {
|
|
503
|
+
action: press.action,
|
|
504
|
+
section: press.section,
|
|
505
|
+
data: event?.data as EventType | undefined,
|
|
506
|
+
title: event ? event.title || this.untitledLabel : this.newEventLabel,
|
|
507
|
+
color: event?.color,
|
|
508
|
+
...range,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** The range a drag in the hours gives, snapped to `minuteStep`. */
|
|
513
|
+
private _timedRange(
|
|
514
|
+
press: ColumnPress,
|
|
515
|
+
point: DragPoint,
|
|
516
|
+
): { start: Date; end: Date } | null {
|
|
517
|
+
const step = this._step;
|
|
518
|
+
const stepMs = step * MINUTE_MS;
|
|
519
|
+
const { event } = press;
|
|
520
|
+
|
|
521
|
+
if (press.action === 'add') {
|
|
522
|
+
// The slot pressed is always part of the range; the drag stays in its day.
|
|
523
|
+
const time = this._timeAt(press.day, point.y);
|
|
524
|
+
const anchor = snapTime(press.time, step, 'floor');
|
|
525
|
+
const dayEnd = nextDay(press.day).valueOf();
|
|
526
|
+
if (time.valueOf() >= anchor.valueOf()) {
|
|
527
|
+
const end = Math.max(
|
|
528
|
+
snapTime(time, step, 'ceil', press.day).valueOf(),
|
|
529
|
+
anchor.valueOf() + stepMs,
|
|
530
|
+
);
|
|
531
|
+
return { start: anchor, end: new Date(Math.min(end, dayEnd)) };
|
|
532
|
+
}
|
|
533
|
+
return {
|
|
534
|
+
start: snapTime(time, step, 'floor', press.day),
|
|
535
|
+
end: new Date(Math.min(anchor.valueOf() + stepMs, dayEnd)),
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (!event) return null;
|
|
539
|
+
|
|
540
|
+
if (press.action === 'move') {
|
|
541
|
+
// The point the event was grabbed by follows the pointer, so the event keeps its length and
|
|
542
|
+
// may run past midnight; at least a step of it stays in the column under the pointer.
|
|
543
|
+
const day = this._dayAt('timed', point.x) ?? press.day;
|
|
544
|
+
const length = event.length();
|
|
545
|
+
const visible = Math.min(stepMs, length);
|
|
546
|
+
const grab = press.time.valueOf() - event.start.valueOf();
|
|
547
|
+
const raw = new Date(this._timeAt(day, point.y).valueOf() - grab);
|
|
548
|
+
const start = clamp(
|
|
549
|
+
snapTime(raw, step, 'round').valueOf(),
|
|
550
|
+
startOfDay(day).valueOf() + visible - length,
|
|
551
|
+
nextDay(day).valueOf() - visible,
|
|
552
|
+
);
|
|
553
|
+
return { start: new Date(start), end: new Date(start + length) };
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (press.action === 'resize-end') {
|
|
557
|
+
// The end stays on the day it is drawn on, at least one step after the start.
|
|
558
|
+
const endDay = event.lastDay();
|
|
559
|
+
const end = snapTime(
|
|
560
|
+
this._timeAt(endDay, point.y),
|
|
561
|
+
step,
|
|
562
|
+
'round',
|
|
563
|
+
endDay,
|
|
564
|
+
).valueOf();
|
|
565
|
+
const min = event.start.valueOf() + stepMs;
|
|
566
|
+
const max = Math.max(nextDay(endDay).valueOf(), min);
|
|
567
|
+
return { start: event.start, end: new Date(clamp(end, min, max)) };
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// resize-start: the start stays on its day, at least one step before the end.
|
|
571
|
+
const startDay = startOfDay(event.start);
|
|
572
|
+
const start = snapTime(
|
|
573
|
+
this._timeAt(startDay, point.y),
|
|
574
|
+
step,
|
|
575
|
+
'round',
|
|
576
|
+
startDay,
|
|
577
|
+
).valueOf();
|
|
578
|
+
const max = event.end.valueOf() - stepMs;
|
|
579
|
+
return {
|
|
580
|
+
start: new Date(clamp(start, Math.min(startDay.valueOf(), max), max)),
|
|
581
|
+
end: event.end,
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
private _follow(press: ColumnPress, point: DragPoint) {
|
|
586
|
+
const preview = this._previewFor(press, point);
|
|
587
|
+
if (!preview) return;
|
|
588
|
+
const current = this._preview;
|
|
589
|
+
if (
|
|
590
|
+
current &&
|
|
591
|
+
current.start.valueOf() === preview.start.valueOf() &&
|
|
592
|
+
current.end.valueOf() === preview.end.valueOf()
|
|
593
|
+
) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
this._preview = preview;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
private _drop(press: ColumnPress, point: DragPoint) {
|
|
600
|
+
const preview = this._previewFor(press, point) ?? this._preview;
|
|
601
|
+
this._preview = null;
|
|
602
|
+
if (!preview) return;
|
|
603
|
+
const { start, end } = preview;
|
|
604
|
+
if (press.action === 'add') {
|
|
605
|
+
this._emitAdd({ start, end, allDay: press.section === 'all-day' });
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const { event } = press;
|
|
609
|
+
if (!event || !preview.data) return;
|
|
610
|
+
if (
|
|
611
|
+
start.valueOf() === event.start.valueOf() &&
|
|
612
|
+
end.valueOf() === event.end.valueOf()
|
|
613
|
+
) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
this._emitChange({
|
|
617
|
+
event: preview.data,
|
|
618
|
+
start,
|
|
619
|
+
end,
|
|
620
|
+
action: press.action === 'move' ? 'move' : 'resize',
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** A click on empty time adds an event there: `defaultDuration` long, or the whole day. */
|
|
625
|
+
private _tap(press: ColumnPress) {
|
|
626
|
+
if (press.action !== 'add') return;
|
|
627
|
+
if (press.section === 'all-day') {
|
|
628
|
+
this._emitAdd({
|
|
629
|
+
start: press.day,
|
|
630
|
+
end: nextDay(press.day),
|
|
631
|
+
allDay: true,
|
|
632
|
+
});
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
// Starts at the half hour clicked, the rows the grid draws.
|
|
636
|
+
const start = snapTime(press.time, Math.max(30, this._step), 'floor');
|
|
637
|
+
const dayEnd = nextDay(press.day).valueOf();
|
|
638
|
+
const end = new Date(
|
|
639
|
+
Math.min(start.valueOf() + this._duration * MINUTE_MS, dayEnd),
|
|
640
|
+
);
|
|
641
|
+
this._emitAdd({ start, end, allDay: false });
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Blurs the focused event when a drag starts. The drop redraws the events, and the element that
|
|
646
|
+
* held focus could then show another event, which Enter would open.
|
|
647
|
+
*/
|
|
648
|
+
private _blurFocused() {
|
|
649
|
+
const active = (this.renderRoot as ShadowRoot).activeElement;
|
|
650
|
+
if (active instanceof HTMLElement) active.blur();
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** How `node`'s blocks take part in the drag in progress. */
|
|
654
|
+
private _dragRole(node: CalendarEvent, section: Section): DragRole {
|
|
655
|
+
const preview = this._preview;
|
|
656
|
+
if (!preview?.data || preview.data !== node.data) return null;
|
|
657
|
+
// A timed event moving between columns is drawn again where it lands.
|
|
658
|
+
return section === 'timed' && preview.action === 'move'
|
|
659
|
+
? 'source'
|
|
660
|
+
: 'lifted';
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** The days the drag in progress, or the placeholder, covers in the all-day row. */
|
|
664
|
+
private _allDayTarget(): { start: Date; end: Date } | null {
|
|
665
|
+
const preview = this._preview;
|
|
666
|
+
if (preview) return preview.section === 'all-day' ? preview : null;
|
|
667
|
+
return this.placeholder?.allDay ? this.placeholder : null;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** Classes of the view while a drag is in progress, which set the cursor. */
|
|
671
|
+
private _rootClasses() {
|
|
672
|
+
const action = this._preview?.action;
|
|
673
|
+
const section = this._preview?.section;
|
|
674
|
+
const resizing = action === 'resize-start' || action === 'resize-end';
|
|
675
|
+
return {
|
|
676
|
+
'calendar-column-view': true,
|
|
677
|
+
addable: this.addable,
|
|
678
|
+
dragging: !!action,
|
|
679
|
+
'drag-move': action === 'move',
|
|
680
|
+
'drag-resize-y': resizing && section === 'timed',
|
|
681
|
+
'drag-resize-x': resizing && section === 'all-day',
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
250
685
|
// ── Render helpers
|
|
251
686
|
|
|
252
687
|
private _renderHeader() {
|
|
@@ -281,9 +716,18 @@ export class CalendarColumnView extends LitElement {
|
|
|
281
716
|
}
|
|
282
717
|
|
|
283
718
|
private _renderMultiDayBackground() {
|
|
719
|
+
const target = this._allDayTarget();
|
|
720
|
+
const first = target ? startOfDay(target.start).valueOf() : 0;
|
|
721
|
+
const last = target ? lastDayOf(target.start, target.end).valueOf() : -1;
|
|
284
722
|
const columns: TemplateResult[] = [];
|
|
285
723
|
this._forEachDayInRange(i => {
|
|
286
|
-
|
|
724
|
+
const day = startOfDay(i).valueOf();
|
|
725
|
+
const covered = day >= first && day <= last;
|
|
726
|
+
columns.push(
|
|
727
|
+
html`<div
|
|
728
|
+
class="${this._getDayClass(i)}${covered ? ' drop-target' : ''}"
|
|
729
|
+
></div>`,
|
|
730
|
+
);
|
|
287
731
|
});
|
|
288
732
|
return columns;
|
|
289
733
|
}
|
|
@@ -320,20 +764,42 @@ export class CalendarColumnView extends LitElement {
|
|
|
320
764
|
return html`<div class="background" aria-hidden="true">${rows}</div>`;
|
|
321
765
|
}
|
|
322
766
|
|
|
323
|
-
/** One event block
|
|
767
|
+
/** One event block. `start` and `end` are where it is drawn, which a resize changes. */
|
|
324
768
|
private _renderEvent(
|
|
325
769
|
node: ColumnEvent,
|
|
770
|
+
section: Section,
|
|
326
771
|
position: Record<string, string>,
|
|
327
|
-
|
|
772
|
+
range: { start: Date; end: Date },
|
|
773
|
+
handles: ('start' | 'end')[],
|
|
328
774
|
) {
|
|
329
775
|
const interactive = this._interactive;
|
|
776
|
+
const editable = this._canEdit(node);
|
|
777
|
+
const role = this._dragRole(node, section);
|
|
778
|
+
const resizing =
|
|
779
|
+
role === 'lifted' &&
|
|
780
|
+
section === 'timed' &&
|
|
781
|
+
this._preview?.action !== 'move';
|
|
330
782
|
const declarations = node.color
|
|
331
783
|
? { ...position, ...this._colorVars(node.color) }
|
|
332
784
|
: position;
|
|
333
785
|
const activate = () => this._emitEventClick(node.data);
|
|
786
|
+
const handle = (edge: 'start' | 'end') =>
|
|
787
|
+
editable && handles.includes(edge)
|
|
788
|
+
? html`<div
|
|
789
|
+
class="resize-handle ${edge}"
|
|
790
|
+
data-handle=${edge}
|
|
791
|
+
aria-hidden="true"
|
|
792
|
+
></div>`
|
|
793
|
+
: nothing;
|
|
334
794
|
return html`
|
|
335
795
|
<div
|
|
336
|
-
class=${
|
|
796
|
+
class=${classMap({
|
|
797
|
+
event: true,
|
|
798
|
+
clickable: interactive,
|
|
799
|
+
editable,
|
|
800
|
+
'drag-source': role === 'source',
|
|
801
|
+
lifted: role === 'lifted',
|
|
802
|
+
})}
|
|
337
803
|
style=${this._styleMap(declarations)}
|
|
338
804
|
role=${interactive ? 'button' : 'note'}
|
|
339
805
|
tabindex=${interactive ? '0' : nothing}
|
|
@@ -342,16 +808,115 @@ export class CalendarColumnView extends LitElement {
|
|
|
342
808
|
node.start,
|
|
343
809
|
node.end,
|
|
344
810
|
this._locale,
|
|
345
|
-
|
|
811
|
+
section === 'all-day',
|
|
346
812
|
)}
|
|
347
813
|
@click=${() => {
|
|
348
814
|
if (interactive) activate();
|
|
349
815
|
}}
|
|
350
816
|
@keydown=${interactive ? onActivateKey(activate) : nothing}
|
|
817
|
+
@pointerdown=${editable
|
|
818
|
+
? (event: PointerEvent) =>
|
|
819
|
+
this._onEventPointerDown(event, node, section)
|
|
820
|
+
: nothing}
|
|
351
821
|
>
|
|
822
|
+
${handle('start')}
|
|
352
823
|
<div class="event-title" aria-hidden="true">
|
|
353
|
-
${node.title ||
|
|
824
|
+
${node.title || this.untitledLabel}
|
|
354
825
|
</div>
|
|
826
|
+
${resizing
|
|
827
|
+
? html`<div class="event-time" aria-hidden="true">
|
|
828
|
+
${formatTimeRange(range.start, range.end, this._locale)}
|
|
829
|
+
</div>`
|
|
830
|
+
: nothing}
|
|
831
|
+
${handle('end')}
|
|
832
|
+
</div>
|
|
833
|
+
`;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/** A timed event's block in one day column, at its own times or those of its resize. */
|
|
837
|
+
private _renderTimedEvent(
|
|
838
|
+
node: ColumnEvent,
|
|
839
|
+
dayStart: Date,
|
|
840
|
+
dayEnd: Date,
|
|
841
|
+
columnIndex: number,
|
|
842
|
+
columnCount: number,
|
|
843
|
+
) {
|
|
844
|
+
const preview = this._preview;
|
|
845
|
+
const resized =
|
|
846
|
+
this._dragRole(node, 'timed') === 'lifted' && preview ? preview : null;
|
|
847
|
+
const start = resized ? resized.start : node.start;
|
|
848
|
+
const end = resized ? resized.end : node.end;
|
|
849
|
+
const top = getTimePercent(start, dayStart);
|
|
850
|
+
const bottom = getTimePercent(end, dayStart);
|
|
851
|
+
// A block shows the handle of an edge only on the day that edge falls on. The event's own
|
|
852
|
+
// times decide, not the resize's: removing the handle being dragged would strand a touch drag.
|
|
853
|
+
const handles: ('start' | 'end')[] = [];
|
|
854
|
+
if (
|
|
855
|
+
node.start.valueOf() >= dayStart.valueOf() &&
|
|
856
|
+
node.length() >= START_HANDLE_MIN_MS
|
|
857
|
+
) {
|
|
858
|
+
handles.push('start');
|
|
859
|
+
}
|
|
860
|
+
if (node.end.valueOf() <= dayEnd.valueOf()) handles.push('end');
|
|
861
|
+
return this._renderEvent(
|
|
862
|
+
node,
|
|
863
|
+
'timed',
|
|
864
|
+
{
|
|
865
|
+
top: `${top}%`,
|
|
866
|
+
height: `${bottom - top}%`,
|
|
867
|
+
'inset-inline-start': `${(columnIndex / columnCount) * 100}%`,
|
|
868
|
+
width: `calc(${(node.width / columnCount) * 100}% - 1px)`,
|
|
869
|
+
},
|
|
870
|
+
{ start, end },
|
|
871
|
+
handles,
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** A new or moved timed event where the drag would put it, or the placeholder. */
|
|
876
|
+
private _renderTimedPreview(dayStart: Date, dayEnd: Date) {
|
|
877
|
+
const preview = this._preview;
|
|
878
|
+
let item: { start: Date; end: Date; title: string; color?: string } | null =
|
|
879
|
+
null;
|
|
880
|
+
let placeholder = false;
|
|
881
|
+
if (preview) {
|
|
882
|
+
if (
|
|
883
|
+
preview.section === 'timed' &&
|
|
884
|
+
(preview.action === 'add' || preview.action === 'move')
|
|
885
|
+
) {
|
|
886
|
+
item = preview;
|
|
887
|
+
}
|
|
888
|
+
} else if (this.placeholder && !this.placeholder.allDay) {
|
|
889
|
+
item = { ...this.placeholder, title: this.newEventLabel };
|
|
890
|
+
placeholder = true;
|
|
891
|
+
}
|
|
892
|
+
if (!item || !rangesOverlap(item.start, item.end, dayStart, dayEnd)) {
|
|
893
|
+
return nothing;
|
|
894
|
+
}
|
|
895
|
+
const top = getTimePercent(item.start, dayStart);
|
|
896
|
+
const bottom = getTimePercent(item.end, dayStart);
|
|
897
|
+
const position = {
|
|
898
|
+
top: `${top}%`,
|
|
899
|
+
height: `${bottom - top}%`,
|
|
900
|
+
'inset-inline-start': '0',
|
|
901
|
+
width: 'calc(100% - 1px)',
|
|
902
|
+
};
|
|
903
|
+
const time = formatTimeRange(item.start, item.end, this._locale);
|
|
904
|
+
const compact =
|
|
905
|
+
item.end.valueOf() - item.start.valueOf() < COMPACT_PREVIEW_MS;
|
|
906
|
+
return html`
|
|
907
|
+
<div
|
|
908
|
+
class=${classMap({ event: true, preview: true, placeholder })}
|
|
909
|
+
style=${this._styleMap(
|
|
910
|
+
item.color
|
|
911
|
+
? { ...position, ...this._colorVars(item.color) }
|
|
912
|
+
: position,
|
|
913
|
+
)}
|
|
914
|
+
aria-hidden="true"
|
|
915
|
+
>
|
|
916
|
+
${compact
|
|
917
|
+
? html`<div class="event-title">${item.title}, ${time}</div>`
|
|
918
|
+
: html`<div class="event-title">${item.title}</div>
|
|
919
|
+
<div class="event-time">${time}</div>`}
|
|
355
920
|
</div>
|
|
356
921
|
`;
|
|
357
922
|
}
|
|
@@ -359,27 +924,26 @@ export class CalendarColumnView extends LitElement {
|
|
|
359
924
|
private _renderEvents() {
|
|
360
925
|
const columns: TemplateResult[] = [];
|
|
361
926
|
this._forEachDayInRange(i => {
|
|
362
|
-
const
|
|
927
|
+
const dayStart = startOfDay(i);
|
|
928
|
+
const dayEnd = nextDay(dayStart);
|
|
363
929
|
const eventDay = this.singleDayEvents[this._getDateOnly(i)];
|
|
364
930
|
columns.push(html`
|
|
365
|
-
<div class=${
|
|
931
|
+
<div class=${this._getDayClass(i)}>
|
|
366
932
|
<div class="column-content">
|
|
367
933
|
${eventDay
|
|
368
934
|
? eventDay.map((nodes, columnIndex) =>
|
|
369
935
|
nodes.map(node =>
|
|
370
|
-
this.
|
|
936
|
+
this._renderTimedEvent(
|
|
371
937
|
node,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
width: `calc(${((1 * node.width) / eventDay.length) * 100}% - 1px)`,
|
|
377
|
-
},
|
|
378
|
-
false,
|
|
938
|
+
dayStart,
|
|
939
|
+
dayEnd,
|
|
940
|
+
columnIndex,
|
|
941
|
+
eventDay.length,
|
|
379
942
|
),
|
|
380
943
|
),
|
|
381
944
|
)
|
|
382
945
|
: nothing}
|
|
946
|
+
${this._renderTimedPreview(dayStart, dayEnd)}
|
|
383
947
|
</div>
|
|
384
948
|
</div>
|
|
385
949
|
`);
|
|
@@ -387,26 +951,82 @@ export class CalendarColumnView extends LitElement {
|
|
|
387
951
|
return html`<div class="events-container">${columns}</div>`;
|
|
388
952
|
}
|
|
389
953
|
|
|
954
|
+
/** Position of a bar in the all-day row covering the days of `start`–`end`. */
|
|
955
|
+
private _allDayPosition(start: Date, end: Date): Record<string, string> {
|
|
956
|
+
const from = this._getDatePercent(start);
|
|
957
|
+
const to = this._getDatePercent(nextDay(lastDayOf(start, end)));
|
|
958
|
+
return {
|
|
959
|
+
'inset-inline-start': `${from + LONG_EVENT_PADDING}%`,
|
|
960
|
+
width: `${to - from - 2 * LONG_EVENT_PADDING}%`,
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
private _renderAllDayEvent(node: ColumnEvent) {
|
|
965
|
+
const preview = this._preview;
|
|
966
|
+
const dragged =
|
|
967
|
+
this._dragRole(node, 'all-day') === 'lifted' && preview ? preview : null;
|
|
968
|
+
const start = dragged ? dragged.start : node.start;
|
|
969
|
+
const end = dragged ? dragged.end : node.end;
|
|
970
|
+
// Edges outside the days shown cannot be dragged. The event's own days decide, so the handle
|
|
971
|
+
// being dragged stays while the bar moves.
|
|
972
|
+
const handles: ('start' | 'end')[] = [];
|
|
973
|
+
if (
|
|
974
|
+
startOfDay(node.start).valueOf() >=
|
|
975
|
+
startOfDay(this.dateRange.startDate).valueOf()
|
|
976
|
+
) {
|
|
977
|
+
handles.push('start');
|
|
978
|
+
}
|
|
979
|
+
if (
|
|
980
|
+
node.lastDay().valueOf() <= startOfDay(this.dateRange.endDate).valueOf()
|
|
981
|
+
) {
|
|
982
|
+
handles.push('end');
|
|
983
|
+
}
|
|
984
|
+
return this._renderEvent(
|
|
985
|
+
node,
|
|
986
|
+
'all-day',
|
|
987
|
+
this._allDayPosition(start, end),
|
|
988
|
+
{ start, end },
|
|
989
|
+
handles,
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
|
|
390
993
|
private _renderMultiDayEvents() {
|
|
391
|
-
|
|
994
|
+
const preview = this._preview;
|
|
995
|
+
let adding: { start: Date; end: Date; placeholder: boolean } | null = null;
|
|
996
|
+
if (preview) {
|
|
997
|
+
if (preview.section === 'all-day' && preview.action === 'add') {
|
|
998
|
+
adding = { start: preview.start, end: preview.end, placeholder: false };
|
|
999
|
+
}
|
|
1000
|
+
} else if (this.placeholder?.allDay) {
|
|
1001
|
+
adding = { ...this.placeholder, placeholder: true };
|
|
1002
|
+
}
|
|
1003
|
+
if (!this.multiDayEvents.length && !adding) return nothing;
|
|
392
1004
|
return html`
|
|
393
1005
|
<div class="row-content">
|
|
394
1006
|
${this.multiDayEvents.map(
|
|
395
1007
|
nodes => html`
|
|
396
1008
|
<div class="row">
|
|
397
|
-
${nodes.map(node =>
|
|
398
|
-
this._renderEvent(
|
|
399
|
-
node,
|
|
400
|
-
{
|
|
401
|
-
left: `${this._getDatePercent(node.start) + LONG_EVENT_PADDING}%`,
|
|
402
|
-
width: `${this._getDatePercent(addDays(node.end, 1)) - this._getDatePercent(node.start) - 2 * LONG_EVENT_PADDING}%`,
|
|
403
|
-
},
|
|
404
|
-
true,
|
|
405
|
-
),
|
|
406
|
-
)}
|
|
1009
|
+
${nodes.map(node => this._renderAllDayEvent(node))}
|
|
407
1010
|
</div>
|
|
408
1011
|
`,
|
|
409
1012
|
)}
|
|
1013
|
+
${adding
|
|
1014
|
+
? html`<div class="row">
|
|
1015
|
+
<div
|
|
1016
|
+
class=${classMap({
|
|
1017
|
+
event: true,
|
|
1018
|
+
preview: true,
|
|
1019
|
+
placeholder: adding.placeholder,
|
|
1020
|
+
})}
|
|
1021
|
+
style=${this._styleMap(
|
|
1022
|
+
this._allDayPosition(adding.start, adding.end),
|
|
1023
|
+
)}
|
|
1024
|
+
aria-hidden="true"
|
|
1025
|
+
>
|
|
1026
|
+
<div class="event-title">${this.newEventLabel}</div>
|
|
1027
|
+
</div>
|
|
1028
|
+
</div>`
|
|
1029
|
+
: nothing}
|
|
410
1030
|
<div class="row-spacer"></div>
|
|
411
1031
|
</div>
|
|
412
1032
|
`;
|
|
@@ -453,7 +1073,7 @@ export class CalendarColumnView extends LitElement {
|
|
|
453
1073
|
render() {
|
|
454
1074
|
return html`
|
|
455
1075
|
<div
|
|
456
|
-
class
|
|
1076
|
+
class=${classMap(this._rootClasses())}
|
|
457
1077
|
role="region"
|
|
458
1078
|
aria-label=${this._rangeLabel()}
|
|
459
1079
|
>
|
|
@@ -464,7 +1084,11 @@ export class CalendarColumnView extends LitElement {
|
|
|
464
1084
|
</div>
|
|
465
1085
|
<div class="multi-day-section-wrapper">
|
|
466
1086
|
<div class="multi-day-section-scroll">
|
|
467
|
-
<div
|
|
1087
|
+
<div
|
|
1088
|
+
class="multi-day-section"
|
|
1089
|
+
@pointerdown=${(event: PointerEvent) =>
|
|
1090
|
+
this._onSectionPointerDown(event, 'all-day')}
|
|
1091
|
+
>
|
|
468
1092
|
<div class="multi-day-background" aria-hidden="true">
|
|
469
1093
|
<div class="scale"></div>
|
|
470
1094
|
<div class="columns">${this._renderMultiDayBackground()}</div>
|
|
@@ -476,7 +1100,11 @@ export class CalendarColumnView extends LitElement {
|
|
|
476
1100
|
<div class="view-body">
|
|
477
1101
|
<div class="view-body-scroll">
|
|
478
1102
|
<div class="scale">${this._renderScale()}</div>
|
|
479
|
-
<div
|
|
1103
|
+
<div
|
|
1104
|
+
class="drawing-area"
|
|
1105
|
+
@pointerdown=${(event: PointerEvent) =>
|
|
1106
|
+
this._onSectionPointerDown(event, 'timed')}
|
|
1107
|
+
>
|
|
480
1108
|
${this._renderBackgroundGrid()} ${this._renderEvents()}
|
|
481
1109
|
</div>
|
|
482
1110
|
${this._renderCurrentTime()}
|