@redvars/peacock 4.4.0 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +564 -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,21 +1,34 @@
|
|
|
1
1
|
import { LitElement, html, nothing, PropertyValues } 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
|
differenceInDays,
|
|
6
7
|
startOfDay,
|
|
7
|
-
endOfDay,
|
|
8
8
|
calculateMonthRange,
|
|
9
9
|
formatDate,
|
|
10
10
|
formatEventLabel,
|
|
11
|
-
|
|
11
|
+
lastDayOf,
|
|
12
|
+
nextDay,
|
|
13
|
+
rangesOverlap,
|
|
12
14
|
LONG_EVENT_PADDING,
|
|
13
15
|
onActivateKey,
|
|
14
16
|
} from './utils.js';
|
|
15
|
-
import { BaseEvent } from './base-event.js';
|
|
16
17
|
import { CalendarEvent } from './calendar-event.js';
|
|
18
|
+
import {
|
|
19
|
+
CalendarDragController,
|
|
20
|
+
dragByDays,
|
|
21
|
+
nearestIndex,
|
|
22
|
+
type CalendarDragAction,
|
|
23
|
+
type DragPoint,
|
|
24
|
+
} from './calendar-drag.js';
|
|
17
25
|
import { MonthEventManager } from './event-manager.js';
|
|
18
26
|
import type { ColumnEvent } from './event-manager.js';
|
|
27
|
+
import type {
|
|
28
|
+
CalendarEventAddDetail,
|
|
29
|
+
CalendarEventChangeDetail,
|
|
30
|
+
EventType,
|
|
31
|
+
} from './types.js';
|
|
19
32
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
20
33
|
import { resolveLocale } from '@/__internal/i18n/locale.js';
|
|
21
34
|
import type { WeekDay } from '@/__internal/utils/date.js';
|
|
@@ -24,6 +37,24 @@ import styles from './calendar-month-view.scss';
|
|
|
24
37
|
/** An event laid out in one week row, with the id its day cell owns it by. */
|
|
25
38
|
type PlacedEvent = { node: ColumnEvent; id: string; dayIndex: number };
|
|
26
39
|
|
|
40
|
+
/** A press that may become a drag. */
|
|
41
|
+
interface MonthPress {
|
|
42
|
+
action: CalendarDragAction;
|
|
43
|
+
/** The event pressed; none when adding. */
|
|
44
|
+
event?: ColumnEvent;
|
|
45
|
+
/** The day under the press. */
|
|
46
|
+
day: Date;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Where a drag would put an event, or the days it would add. */
|
|
50
|
+
interface MonthPreview {
|
|
51
|
+
action: CalendarDragAction;
|
|
52
|
+
/** The dragged event's object from `events`; none when adding. */
|
|
53
|
+
data?: EventType;
|
|
54
|
+
start: Date;
|
|
55
|
+
end: Date;
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
/**
|
|
28
59
|
* @internal
|
|
29
60
|
*
|
|
@@ -38,8 +69,13 @@ type PlacedEvent = { node: ColumnEvent; id: string; dayIndex: number };
|
|
|
38
69
|
* gridcell per day labelled with its full date. Each event is owned (<code>aria-owns</code>) by the
|
|
39
70
|
* cell of the day it starts on in that week. Events are buttons labelled with their title and
|
|
40
71
|
* time, or notes that cannot be focused when <code>events-readonly</code> is set.</p>
|
|
72
|
+
* <p>With <code>editable</code>, events are dragged to other days and all-day events resized by
|
|
73
|
+
* their edges; with <code>addable</code>, dragging across days or clicking one asks for an
|
|
74
|
+
* all-day event. The days a drag covers are highlighted.</p>
|
|
41
75
|
*
|
|
42
76
|
* @fires event-click - Internal, does not bubble; `wc-calendar` re-fires it. Detail contains `{ event }`.
|
|
77
|
+
* @fires event-change - Internal, does not bubble; an event was dropped on new days. `wc-calendar` re-fires it.
|
|
78
|
+
* @fires event-add - Internal, does not bubble; days were drawn across or a day clicked. `wc-calendar` re-fires it.
|
|
43
79
|
*/
|
|
44
80
|
@IndividualComponent
|
|
45
81
|
export class CalendarMonthView extends LitElement {
|
|
@@ -57,6 +93,22 @@ export class CalendarMonthView extends LitElement {
|
|
|
57
93
|
@property({ type: Boolean, attribute: 'events-readonly' })
|
|
58
94
|
eventsReadonly: boolean = false;
|
|
59
95
|
|
|
96
|
+
/** Events can be moved to other days, and all-day events resized, by dragging. */
|
|
97
|
+
@property({ type: Boolean })
|
|
98
|
+
editable: boolean = false;
|
|
99
|
+
|
|
100
|
+
/** Dragging across days, or clicking one, asks for a new all-day event. */
|
|
101
|
+
@property({ type: Boolean })
|
|
102
|
+
addable: boolean = false;
|
|
103
|
+
|
|
104
|
+
/** A range waiting for its new event; its days are highlighted. */
|
|
105
|
+
@property({ attribute: false })
|
|
106
|
+
placeholder: CalendarEventAddDetail | null = null;
|
|
107
|
+
|
|
108
|
+
/** Title shown for an event without one. */
|
|
109
|
+
@property({ attribute: false })
|
|
110
|
+
untitledLabel: string = '(no title)';
|
|
111
|
+
|
|
60
112
|
/** Now, which marks today. */
|
|
61
113
|
@property({ type: Object, attribute: false })
|
|
62
114
|
currentTime: Date = new Date();
|
|
@@ -87,6 +139,23 @@ export class CalendarMonthView extends LitElement {
|
|
|
87
139
|
@state()
|
|
88
140
|
private weekDayEvents: ColumnEvent[][][] = [];
|
|
89
141
|
|
|
142
|
+
/** The drag in progress, where it would put its event. */
|
|
143
|
+
@state()
|
|
144
|
+
private _preview: MonthPreview | null = null;
|
|
145
|
+
|
|
146
|
+
// ── Private fields
|
|
147
|
+
|
|
148
|
+
private readonly _drag = new CalendarDragController<MonthPress>(this, {
|
|
149
|
+
lift: () => this._blurFocused(),
|
|
150
|
+
move: (press, point) => this._follow(press, point),
|
|
151
|
+
drop: (press, point) => this._drop(press, point),
|
|
152
|
+
cancel: () => {
|
|
153
|
+
this._preview = null;
|
|
154
|
+
},
|
|
155
|
+
tap: press => this._tap(press),
|
|
156
|
+
scrollers: () => [this.renderRoot.querySelector<HTMLElement>('.view-body')],
|
|
157
|
+
});
|
|
158
|
+
|
|
90
159
|
// ── Lifecycle
|
|
91
160
|
|
|
92
161
|
override connectedCallback() {
|
|
@@ -94,18 +163,9 @@ export class CalendarMonthView extends LitElement {
|
|
|
94
163
|
this._processEvents();
|
|
95
164
|
}
|
|
96
165
|
|
|
97
|
-
override firstUpdated() {
|
|
98
|
-
const viewBody = this.renderRoot.querySelector('.view-body');
|
|
99
|
-
if (viewBody) {
|
|
100
|
-
const viewBodyHeight = viewBody.scrollHeight;
|
|
101
|
-
viewBody.scrollTo({
|
|
102
|
-
top: (getTimePercent(this.currentTime) / 100) * viewBodyHeight - 150,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
166
|
override willUpdate(changed: PropertyValues<this>) {
|
|
108
167
|
super.willUpdate(changed);
|
|
168
|
+
this._drag.enabled = this.addable || (this.editable && this._interactive);
|
|
109
169
|
if (
|
|
110
170
|
changed.has('events') ||
|
|
111
171
|
changed.has('contextDate') ||
|
|
@@ -113,6 +173,17 @@ export class CalendarMonthView extends LitElement {
|
|
|
113
173
|
) {
|
|
114
174
|
this._processEvents();
|
|
115
175
|
}
|
|
176
|
+
// A drag cannot outlive the month it started in, or editing being turned off.
|
|
177
|
+
if (
|
|
178
|
+
this._drag.pressing &&
|
|
179
|
+
(changed.has('contextDate') ||
|
|
180
|
+
changed.has('weekStartsOn') ||
|
|
181
|
+
changed.has('editable') ||
|
|
182
|
+
changed.has('addable') ||
|
|
183
|
+
changed.has('eventsReadonly'))
|
|
184
|
+
) {
|
|
185
|
+
this._drag.abort();
|
|
186
|
+
}
|
|
116
187
|
}
|
|
117
188
|
|
|
118
189
|
// ── Private methods
|
|
@@ -121,6 +192,12 @@ export class CalendarMonthView extends LitElement {
|
|
|
121
192
|
return !this.eventsReadonly;
|
|
122
193
|
}
|
|
123
194
|
|
|
195
|
+
/** Whether an event can be dragged: the view is editable and the event did not opt out. */
|
|
196
|
+
private _canEdit(node: CalendarEvent): boolean {
|
|
197
|
+
const data = node.data as EventType | undefined;
|
|
198
|
+
return this.editable && this._interactive && data?.editable !== false;
|
|
199
|
+
}
|
|
200
|
+
|
|
124
201
|
private _processEvents() {
|
|
125
202
|
this.dateRange = calculateMonthRange(this.contextDate, this.weekStartsOn);
|
|
126
203
|
this.weekDayEvents = [];
|
|
@@ -130,11 +207,15 @@ export class CalendarMonthView extends LitElement {
|
|
|
130
207
|
j < 6;
|
|
131
208
|
i = addDays(i, 7), j += 1
|
|
132
209
|
) {
|
|
210
|
+
const weekStart = startOfDay(i);
|
|
133
211
|
const manager = new MonthEventManager();
|
|
134
212
|
manager.addEvents(
|
|
135
213
|
this.events.filter(event =>
|
|
136
|
-
|
|
137
|
-
|
|
214
|
+
rangesOverlap(
|
|
215
|
+
event.start,
|
|
216
|
+
event.end,
|
|
217
|
+
weekStart,
|
|
218
|
+
startOfDay(addDays(weekStart, 7)),
|
|
138
219
|
),
|
|
139
220
|
),
|
|
140
221
|
);
|
|
@@ -176,6 +257,18 @@ export class CalendarMonthView extends LitElement {
|
|
|
176
257
|
this.dispatchEvent(new CustomEvent('event-click', { detail: { event } }));
|
|
177
258
|
}
|
|
178
259
|
|
|
260
|
+
private _emitChange(detail: CalendarEventChangeDetail) {
|
|
261
|
+
this.dispatchEvent(
|
|
262
|
+
new CustomEvent<CalendarEventChangeDetail>('event-change', { detail }),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private _emitAdd(detail: CalendarEventAddDetail) {
|
|
267
|
+
this.dispatchEvent(
|
|
268
|
+
new CustomEvent<CalendarEventAddDetail>('event-add', { detail }),
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
179
272
|
/** The locale day names and numbers are formatted in. */
|
|
180
273
|
private get _locale(): string {
|
|
181
274
|
return resolveLocale(this.locale, this);
|
|
@@ -203,6 +296,137 @@ export class CalendarMonthView extends LitElement {
|
|
|
203
296
|
.join(';');
|
|
204
297
|
}
|
|
205
298
|
|
|
299
|
+
// ── Drag and drop
|
|
300
|
+
|
|
301
|
+
/** The day of the cell under, or nearest, a point. */
|
|
302
|
+
private _dayAt(x: number, y: number): Date | null {
|
|
303
|
+
const cells = [
|
|
304
|
+
...this.renderRoot.querySelectorAll<HTMLElement>('[role="gridcell"]'),
|
|
305
|
+
];
|
|
306
|
+
const index = nearestIndex(cells, x, y);
|
|
307
|
+
return index < 0
|
|
308
|
+
? null
|
|
309
|
+
: startOfDay(addDays(this.dateRange.startDate, index));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private _onEventPointerDown(event: PointerEvent, node: ColumnEvent) {
|
|
313
|
+
if (!this._canEdit(node)) return;
|
|
314
|
+
const handle =
|
|
315
|
+
event.target instanceof Element
|
|
316
|
+
? event.target.closest<HTMLElement>('[data-handle]')?.dataset.handle
|
|
317
|
+
: undefined;
|
|
318
|
+
let action: CalendarDragAction = 'move';
|
|
319
|
+
if (handle === 'start') action = 'resize-start';
|
|
320
|
+
else if (handle === 'end') action = 'resize-end';
|
|
321
|
+
const day =
|
|
322
|
+
this._dayAt(event.clientX, event.clientY) ?? startOfDay(node.start);
|
|
323
|
+
this._drag.start(event, { action, event: node, day });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private _onAreaPointerDown(event: PointerEvent) {
|
|
327
|
+
if (!this.addable || this._drag.pressing) return;
|
|
328
|
+
// Presses on events are theirs, even on events that cannot be dragged.
|
|
329
|
+
const onEvent = event
|
|
330
|
+
.composedPath()
|
|
331
|
+
.some(
|
|
332
|
+
target =>
|
|
333
|
+
target instanceof HTMLElement && target.classList.contains('event'),
|
|
334
|
+
);
|
|
335
|
+
if (onEvent) return;
|
|
336
|
+
const day = this._dayAt(event.clientX, event.clientY);
|
|
337
|
+
if (!day) return;
|
|
338
|
+
this._drag.start(event, { action: 'add', day });
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private _previewFor(
|
|
342
|
+
press: MonthPress,
|
|
343
|
+
point: DragPoint,
|
|
344
|
+
): MonthPreview | null {
|
|
345
|
+
const day = this._dayAt(point.x, point.y) ?? press.day;
|
|
346
|
+
const range = dragByDays(press.action, press.day, day, press.event);
|
|
347
|
+
if (!range) return null;
|
|
348
|
+
return {
|
|
349
|
+
action: press.action,
|
|
350
|
+
data: press.event?.data as EventType | undefined,
|
|
351
|
+
...range,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
private _follow(press: MonthPress, point: DragPoint) {
|
|
356
|
+
const preview = this._previewFor(press, point);
|
|
357
|
+
if (!preview) return;
|
|
358
|
+
const current = this._preview;
|
|
359
|
+
if (
|
|
360
|
+
current &&
|
|
361
|
+
current.start.valueOf() === preview.start.valueOf() &&
|
|
362
|
+
current.end.valueOf() === preview.end.valueOf()
|
|
363
|
+
) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this._preview = preview;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private _drop(press: MonthPress, point: DragPoint) {
|
|
370
|
+
const preview = this._previewFor(press, point) ?? this._preview;
|
|
371
|
+
this._preview = null;
|
|
372
|
+
if (!preview) return;
|
|
373
|
+
const { start, end } = preview;
|
|
374
|
+
if (press.action === 'add') {
|
|
375
|
+
this._emitAdd({ start, end, allDay: true });
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const { event } = press;
|
|
379
|
+
if (!event || !preview.data) return;
|
|
380
|
+
if (
|
|
381
|
+
start.valueOf() === event.start.valueOf() &&
|
|
382
|
+
end.valueOf() === event.end.valueOf()
|
|
383
|
+
) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
this._emitChange({
|
|
387
|
+
event: preview.data,
|
|
388
|
+
start,
|
|
389
|
+
end,
|
|
390
|
+
action: press.action === 'move' ? 'move' : 'resize',
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** A click on a day adds an all-day event on it. */
|
|
395
|
+
private _tap(press: MonthPress) {
|
|
396
|
+
if (press.action !== 'add') return;
|
|
397
|
+
this._emitAdd({
|
|
398
|
+
start: press.day,
|
|
399
|
+
end: nextDay(press.day),
|
|
400
|
+
allDay: true,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Blurs the focused event when a drag starts. The drop redraws the events, and the element that
|
|
406
|
+
* held focus could then show another event, which Enter would open.
|
|
407
|
+
*/
|
|
408
|
+
private _blurFocused() {
|
|
409
|
+
const active = (this.renderRoot as ShadowRoot).activeElement;
|
|
410
|
+
if (active instanceof HTMLElement) active.blur();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** The days the drag in progress, or the placeholder, covers. */
|
|
414
|
+
private _target(): { start: Date; end: Date } | null {
|
|
415
|
+
return this._preview ?? this.placeholder;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Classes of the view while a drag is in progress, which set the cursor. */
|
|
419
|
+
private _rootClasses() {
|
|
420
|
+
const action = this._preview?.action;
|
|
421
|
+
return {
|
|
422
|
+
'calendar-month-view': true,
|
|
423
|
+
addable: this.addable,
|
|
424
|
+
dragging: !!action,
|
|
425
|
+
'drag-move': action === 'move',
|
|
426
|
+
'drag-resize-x': action === 'resize-start' || action === 'resize-end',
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
206
430
|
// ── Render helpers
|
|
207
431
|
|
|
208
432
|
private _renderHeader() {
|
|
@@ -227,6 +451,9 @@ export class CalendarMonthView extends LitElement {
|
|
|
227
451
|
private _renderDayCells(sd: Date, placed: PlacedEvent[]) {
|
|
228
452
|
const locale = this._locale;
|
|
229
453
|
const long = new Intl.DateTimeFormat(locale, { dateStyle: 'full' });
|
|
454
|
+
const target = this._target();
|
|
455
|
+
const first = target ? startOfDay(target.start).valueOf() : 0;
|
|
456
|
+
const last = target ? lastDayOf(target.start, target.end).valueOf() : -1;
|
|
230
457
|
const columns = [];
|
|
231
458
|
for (let i = new Date(sd), j = 0; j < 7; i = addDays(i, 1), j += 1) {
|
|
232
459
|
const owned = placed
|
|
@@ -234,9 +461,11 @@ export class CalendarMonthView extends LitElement {
|
|
|
234
461
|
.map(p => p.id)
|
|
235
462
|
.join(' ');
|
|
236
463
|
const today = this._getDayClass(i).includes('today');
|
|
464
|
+
const day = startOfDay(i).valueOf();
|
|
465
|
+
const covered = day >= first && day <= last;
|
|
237
466
|
columns.push(html`
|
|
238
467
|
<div
|
|
239
|
-
class
|
|
468
|
+
class="${this._getDayClass(i)}${covered ? ' drop-target' : ''}"
|
|
240
469
|
role="gridcell"
|
|
241
470
|
aria-label=${long.format(i)}
|
|
242
471
|
aria-current=${today ? 'date' : nothing}
|
|
@@ -256,16 +485,42 @@ export class CalendarMonthView extends LitElement {
|
|
|
256
485
|
private _renderEvent(placed: PlacedEvent, weekStartDate: Date) {
|
|
257
486
|
const { node, id } = placed;
|
|
258
487
|
const interactive = this._interactive;
|
|
488
|
+
const editable = this._canEdit(node);
|
|
489
|
+
const allDay = node.isAllDay();
|
|
490
|
+
const lastDay = node.lastDay();
|
|
491
|
+
const dragged = !!this._preview?.data && this._preview.data === node.data;
|
|
259
492
|
const evtStyles: Record<string, string> = {
|
|
260
|
-
|
|
261
|
-
width: `${this._getDatePercent(
|
|
493
|
+
'inset-inline-start': `${this._getDatePercent(node.start, weekStartDate) + LONG_EVENT_PADDING}%`,
|
|
494
|
+
width: `${this._getDatePercent(nextDay(lastDay), weekStartDate) - this._getDatePercent(node.start, weekStartDate) - 2 * LONG_EVENT_PADDING}%`,
|
|
262
495
|
...(node.color ? this._colorVars(node.color) : {}),
|
|
263
496
|
};
|
|
264
497
|
const activate = () => this._emitEventClick(node.data);
|
|
498
|
+
// All-day events resize by whichever of their edges falls in this week.
|
|
499
|
+
const weekEnd = startOfDay(addDays(weekStartDate, 6)).valueOf();
|
|
500
|
+
const handle = (edge: 'start' | 'end') => {
|
|
501
|
+
if (!editable || !allDay) return nothing;
|
|
502
|
+
const shown =
|
|
503
|
+
edge === 'start'
|
|
504
|
+
? startOfDay(node.start).valueOf() >=
|
|
505
|
+
startOfDay(weekStartDate).valueOf()
|
|
506
|
+
: lastDay.valueOf() <= weekEnd;
|
|
507
|
+
return shown
|
|
508
|
+
? html`<div
|
|
509
|
+
class="resize-handle ${edge}"
|
|
510
|
+
data-handle=${edge}
|
|
511
|
+
aria-hidden="true"
|
|
512
|
+
></div>`
|
|
513
|
+
: nothing;
|
|
514
|
+
};
|
|
265
515
|
return html`
|
|
266
516
|
<div
|
|
267
517
|
id=${id}
|
|
268
|
-
class=${
|
|
518
|
+
class=${classMap({
|
|
519
|
+
event: true,
|
|
520
|
+
clickable: interactive,
|
|
521
|
+
editable,
|
|
522
|
+
'drag-source': dragged,
|
|
523
|
+
})}
|
|
269
524
|
style=${this._styleMap(evtStyles)}
|
|
270
525
|
role=${interactive ? 'button' : 'note'}
|
|
271
526
|
tabindex=${interactive ? '0' : nothing}
|
|
@@ -274,16 +529,21 @@ export class CalendarMonthView extends LitElement {
|
|
|
274
529
|
node.start,
|
|
275
530
|
node.end,
|
|
276
531
|
this._locale,
|
|
277
|
-
|
|
532
|
+
allDay,
|
|
278
533
|
)}
|
|
279
534
|
@click=${() => {
|
|
280
535
|
if (interactive) activate();
|
|
281
536
|
}}
|
|
282
537
|
@keydown=${interactive ? onActivateKey(activate) : nothing}
|
|
538
|
+
@pointerdown=${editable
|
|
539
|
+
? (event: PointerEvent) => this._onEventPointerDown(event, node)
|
|
540
|
+
: nothing}
|
|
283
541
|
>
|
|
542
|
+
${handle('start')}
|
|
284
543
|
<div class="event-title" aria-hidden="true">
|
|
285
|
-
${node.title ||
|
|
544
|
+
${node.title || this.untitledLabel}
|
|
286
545
|
</div>
|
|
546
|
+
${handle('end')}
|
|
287
547
|
</div>
|
|
288
548
|
`;
|
|
289
549
|
}
|
|
@@ -334,7 +594,7 @@ export class CalendarMonthView extends LitElement {
|
|
|
334
594
|
}).format(context);
|
|
335
595
|
return html`
|
|
336
596
|
<div
|
|
337
|
-
class
|
|
597
|
+
class=${classMap(this._rootClasses())}
|
|
338
598
|
role="grid"
|
|
339
599
|
aria-label=${label}
|
|
340
600
|
aria-readonly="true"
|
|
@@ -345,7 +605,13 @@ export class CalendarMonthView extends LitElement {
|
|
|
345
605
|
</div>
|
|
346
606
|
<div class="view-body">
|
|
347
607
|
<div class="view-body-scroll">
|
|
348
|
-
<div
|
|
608
|
+
<div
|
|
609
|
+
class="drawing-area"
|
|
610
|
+
@pointerdown=${(event: PointerEvent) =>
|
|
611
|
+
this._onAreaPointerDown(event)}
|
|
612
|
+
>
|
|
613
|
+
${this._renderWeeks()}
|
|
614
|
+
</div>
|
|
349
615
|
</div>
|
|
350
616
|
</div>
|
|
351
617
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use '../../scss/mixin';
|
|
2
|
+
@use './calendar-header';
|
|
2
3
|
|
|
3
4
|
@include mixin.base-styles;
|
|
4
5
|
|
|
@@ -32,33 +33,7 @@
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
.calendar-header {
|
|
35
|
-
|
|
36
|
-
display: flex;
|
|
37
|
-
align-items: center;
|
|
38
|
-
padding: 0.75rem 1rem;
|
|
39
|
-
gap: 0.5rem;
|
|
40
|
-
|
|
41
|
-
.header-left {
|
|
42
|
-
display: flex;
|
|
43
|
-
gap: 0.5rem;
|
|
44
|
-
align-items: center;
|
|
45
|
-
flex: 1;
|
|
46
|
-
|
|
47
|
-
.title {
|
|
48
|
-
display: flex;
|
|
49
|
-
align-items: center;
|
|
50
|
-
font-weight: 500;
|
|
51
|
-
font-size: 1rem;
|
|
52
|
-
color: var(--calendar-on-surface);
|
|
53
|
-
padding-inline-start: 0.5rem;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.header-right {
|
|
58
|
-
display: flex;
|
|
59
|
-
align-items: center;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
36
|
+
@include calendar-header.styles;
|
|
62
37
|
}
|
|
63
38
|
|
|
64
39
|
.loader {
|