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