@sbb-esta/lyne-elements-dev 5.14.0-dev.1795683754 → 5.14.0-dev.1795700857
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/badge/_badge.global.scss +4 -0
- package/calendar.js +1 -1
- package/calendar.pure.js +98 -128
- package/core.js +13 -13
- package/custom-elements.json +1821 -398
- package/development/calendar/calendar/calendar.component.d.ts +55 -21
- package/development/calendar/calendar-select-all/calendar-select-all.component.d.ts +18 -0
- package/development/calendar/calendar-weeknumber/calendar-weeknumber.component.d.ts +0 -1
- package/development/calendar/common/calendar-cell-base-element.d.ts +2 -2
- package/development/calendar.js +2 -1
- package/development/calendar.pure.d.ts +1 -0
- package/development/calendar.pure.js +304 -354
- package/development/core/datetime/date-adapter.d.ts +10 -0
- package/development/core/datetime/temporal-date-adapter.d.ts +5 -0
- package/development/core/i18n/i18n.d.ts +7 -0
- package/development/core.js +91 -1
- package/development/menu.pure.js +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/lean-off-brand-theme.css +3 -0
- package/lean-safety-theme.css +3 -0
- package/lean-theme.css +3 -0
- package/menu.pure.js +1 -1
- package/off-brand-theme.css +3 -0
- package/package.json +2 -2
- package/safety-theme.css +3 -0
- package/standard-theme.css +3 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
2
|
import { html, isServer, nothing, unsafeCSS } from "lit";
|
|
3
3
|
import { property, state } from "lit/decorators.js";
|
|
4
|
-
import {
|
|
4
|
+
import { SbbButtonLikeBaseElement, SbbDisabledMixin, SbbElement, SbbFormAssociatedMixin, SbbLanguageController, SbbPropertyWatcherController, defaultDateAdapter, forceType, getNextElementIndex, handleDistinctChange, i18nCalendarDateSelection, i18nCalendarDeselectAll, i18nCalendarDeselectWeek, i18nCalendarDeselectWeekday, i18nCalendarHeaderNavigationHint, i18nCalendarSelectAll, i18nCalendarSelectWeek, i18nCalendarSelectWeekday, i18nCalendarWeekNumber, i18nNextMonth, i18nNextYear, i18nNextYearRange, i18nPreviousMonth, i18nPreviousYear, i18nPreviousYearRange, i18nYearMonthSelection, isArrowKeyOrPageKeysPressed, plainDate, readConfig, screenReaderOnlyStyles } from "./core.js";
|
|
5
|
+
import { ref } from "lit/directives/ref.js";
|
|
5
6
|
import { SbbSecondaryButtonElement } from "./button.pure.js";
|
|
6
|
-
import { SbbIconElement } from "./icon.pure.js";
|
|
7
|
+
import { SbbIconElement, SbbIconNameMixin } from "./icon.pure.js";
|
|
7
8
|
|
|
8
9
|
// src/elements/calendar/common/calendar-cell-base-element.scss?inline
|
|
9
|
-
var calendar_cell_base_element_default = ":host {\n --sbb-focus-outline-offset: 0.125rem;\n --sbb-calendar-cell-transition-duration: var(\n --sbb-disable-animation-duration,\n var(--sbb-animation-duration-2x)\n );\n display: block;\n font-size: var(--sbb-calendar-cell-font-size);\n letter-spacing: var(--sbb-letter-spacing-text);\n cursor: var(--sbb-calendar-cell-cursor);\n color: var(--sbb-calendar-cell-color);\n border-radius: calc(var(--sbb-border-radius-4x) + var(--sbb-calendar-cell-border-width));\n margin: var(--sbb-calendar-cell-margin);\n padding: var(--sbb-calendar-cell-border-width);\n background-clip: content-box;\n transition-duration: var(--sbb-calendar-cell-transition-duration);\n transition-timing-function: var(--sbb-calendar-cell-transition-easing-function);\n transition-property: background-color;\n}\n\n:host(:is(sbb-calendar-weekday, sbb-calendar-weeknumber)) {\n --sbb-calendar-cell-font-size: var(--sbb-text-font-size-xs);\n --sbb-calendar-day-height: var(--sbb-calendar-day-size);\n color: var(--sbb-calendar-header-color);\n margin-inline: auto;\n}\n\n:host(:is(sbb-calendar-day, sbb-calendar-weekday, sbb-calendar-weeknumber)) {\n height: var(--sbb-calendar-day-height);\n width: var(--sbb-calendar-day-width);\n}\n\n:host(:is(:state(current),[state--current])) {\n font-weight: bold;\n}\n\n:host(:is(:state(selected),[state--selected])) {\n border: var(--sbb-calendar-cell-border-width) solid var(--sbb-calendar-cell-border-color-selected);\n padding: 0;\n}\n\n:host(:disabled) {\n --sbb-calendar-cell-color: var(--sbb-calendar-cell-disabled-color);\n --sbb-calendar-cell-cursor: var(--sbb-cursor-default);\n}\n\n:host(:disabled:is(:state(crossed-out),[state--crossed-out])) {\n --sbb-calendar-cell-color: var(--sbb-calendar-cell-disabled-crossed-out-color);\n}\n\n:host(:focus-visible) {\n outline-offset: var(--sbb-focus-outline-offset);\n outline: var(--sbb-focus-outline-color) var(--sbb-focus-outline-style, solid) var(--sbb-focus-outline-width);\n}\n\n@media (any-hover: hover) {\n :host(:not(:disabled, :where(:is(:state(active),[state--active]), :active)):hover) {\n background-color: var(--sbb-calendar-cell-background-color-hover);\n }\n}\n\n@media (any-hover: hover) and (forced-colors: active) {\n :host(:not(:disabled):hover) {\n outline-offset: var(--sbb-focus-outline-offset);\n outline: var(--sbb-focus-outline-color) var(--sbb-focus-outline-style, solid) var(--sbb-focus-outline-width);\n --sbb-focus-outline-style: initial;\n }\n}\n\n:host(:not(:disabled):where(:is(:state(active),[state--active]), :active)) {\n background-color: var(--sbb-calendar-cell-background-color-active);\n}\n\n.sbb-action-base {\n display: flex;\n flex-direction: column;\n justify-content: center;\n height: 100%;\n width: 100%;\n}\n\n.sbb-calendar-year,\n.sbb-calendar-month {\n justify-content: center;\n height: var(--sbb-calendar-cell-year-month-height);\n min-width: var(--sbb-calendar-cell-year-month-width);\n width: 100%;\n}\n\n:host(:is(:state(crossed-out),[state--crossed-out])) :is(.sbb-calendar-year, .sbb-calendar-month, .sbb-calendar-day__value)::after {\n position: absolute;\n top: 50%;\n left: 50%;\n translate: -50% -50%;\n content: \"\";\n height: var(--sbb-calendar-cell-disabled-height);\n width: var(--sbb-calendar-cell-disabled-width);\n background-color: var(--sbb-calendar-cell-disabled-crossed-out-color);\n rotate: -45deg;\n}\n";
|
|
10
|
+
var calendar_cell_base_element_default = ":host {\n --sbb-focus-outline-offset: 0.125rem;\n --sbb-calendar-cell-transition-duration: var(\n --sbb-disable-animation-duration,\n var(--sbb-animation-duration-2x)\n );\n display: block;\n font-size: var(--sbb-calendar-cell-font-size);\n letter-spacing: var(--sbb-letter-spacing-text);\n cursor: var(--sbb-calendar-cell-cursor);\n color: var(--sbb-calendar-cell-color);\n border-radius: calc(var(--sbb-border-radius-4x) + var(--sbb-calendar-cell-border-width));\n margin: var(--sbb-calendar-cell-margin);\n padding: var(--sbb-calendar-cell-border-width);\n background-clip: content-box;\n transition-duration: var(--sbb-calendar-cell-transition-duration);\n transition-timing-function: var(--sbb-calendar-cell-transition-easing-function);\n transition-property: background-color;\n}\n\n:host(:is(sbb-calendar-weekday, sbb-calendar-weeknumber, sbb-calendar-select-all)) {\n --sbb-calendar-cell-font-size: var(--sbb-text-font-size-xs);\n --sbb-calendar-day-height: var(--sbb-calendar-day-size);\n color: var(--sbb-calendar-header-color);\n margin-inline: auto;\n}\n\n:host(:is(sbb-calendar-day, sbb-calendar-weekday, sbb-calendar-weeknumber, sbb-calendar-select-all)) {\n height: var(--sbb-calendar-day-height);\n width: var(--sbb-calendar-day-width);\n}\n\n:host(:is(:state(current),[state--current])) {\n font-weight: bold;\n}\n\n:host(:is(:state(selected),[state--selected])) {\n border: var(--sbb-calendar-cell-border-width) solid var(--sbb-calendar-cell-border-color-selected);\n padding: 0;\n}\n\n:host(:disabled) {\n --sbb-calendar-cell-color: var(--sbb-calendar-cell-disabled-color);\n --sbb-calendar-cell-cursor: var(--sbb-cursor-default);\n}\n\n:host(:disabled:is(:state(crossed-out),[state--crossed-out])) {\n --sbb-calendar-cell-color: var(--sbb-calendar-cell-disabled-crossed-out-color);\n}\n\n:host(:focus-visible) {\n outline-offset: var(--sbb-focus-outline-offset);\n outline: var(--sbb-focus-outline-color) var(--sbb-focus-outline-style, solid) var(--sbb-focus-outline-width);\n}\n\n@media (any-hover: hover) {\n :host(:not(:disabled, :where(:is(:state(active),[state--active]), :active)):hover) {\n background-color: var(--sbb-calendar-cell-background-color-hover);\n }\n}\n\n@media (any-hover: hover) and (forced-colors: active) {\n :host(:not(:disabled):hover) {\n outline-offset: var(--sbb-focus-outline-offset);\n outline: var(--sbb-focus-outline-color) var(--sbb-focus-outline-style, solid) var(--sbb-focus-outline-width);\n --sbb-focus-outline-style: initial;\n }\n}\n\n:host(:not(:disabled):where(:is(:state(active),[state--active]), :active)) {\n background-color: var(--sbb-calendar-cell-background-color-active);\n}\n\n.sbb-action-base {\n display: flex;\n flex-direction: column;\n justify-content: center;\n height: 100%;\n width: 100%;\n}\n\n.sbb-calendar-year,\n.sbb-calendar-month {\n justify-content: center;\n height: var(--sbb-calendar-cell-year-month-height);\n min-width: var(--sbb-calendar-cell-year-month-width);\n width: 100%;\n}\n\n:host(:is(:state(crossed-out),[state--crossed-out])) :is(.sbb-calendar-year, .sbb-calendar-month, .sbb-calendar-day__value)::after {\n position: absolute;\n top: 50%;\n left: 50%;\n translate: -50% -50%;\n content: \"\";\n height: var(--sbb-calendar-cell-disabled-height);\n width: var(--sbb-calendar-cell-disabled-width);\n background-color: var(--sbb-calendar-cell-disabled-crossed-out-color);\n rotate: -45deg;\n}\n";
|
|
10
11
|
|
|
11
12
|
// src/elements/calendar/common/calendar-cell-base-element.ts
|
|
12
13
|
var SbbCalendarCellBaseElement = class extends SbbDisabledMixin(SbbButtonLikeBaseElement) {
|
|
@@ -17,10 +18,10 @@ var SbbCalendarCellBaseElement = class extends SbbDisabledMixin(SbbButtonLikeBas
|
|
|
17
18
|
super();
|
|
18
19
|
this.dateAdapter = readConfig().datetime?.dateAdapter ?? defaultDateAdapter;
|
|
19
20
|
this.addController(new SbbPropertyWatcherController(this, () => this.getParent(), {
|
|
20
|
-
dateFilter: (component) => this.setDisabledFilteredState(component),
|
|
21
|
-
min: (component) => this.setDisabledFilteredState(component),
|
|
22
|
-
max: (component) => this.setDisabledFilteredState(component),
|
|
23
|
-
value: (component) => this.setSelectedState(component)
|
|
21
|
+
dateFilter: (component) => this.setDisabledFilteredState?.(component),
|
|
22
|
+
min: (component) => this.setDisabledFilteredState?.(component),
|
|
23
|
+
max: (component) => this.setDisabledFilteredState?.(component),
|
|
24
|
+
value: (component) => this.setSelectedState?.(component)
|
|
24
25
|
}));
|
|
25
26
|
}
|
|
26
27
|
getParent() {
|
|
@@ -406,7 +407,6 @@ let SbbCalendarWeekdayElement = (() => {
|
|
|
406
407
|
set value(value) {
|
|
407
408
|
if (!value) return;
|
|
408
409
|
this._value = value;
|
|
409
|
-
this.internals.ariaLabel = value.long;
|
|
410
410
|
}
|
|
411
411
|
get value() {
|
|
412
412
|
return this._value;
|
|
@@ -430,8 +430,7 @@ let SbbCalendarWeeknumberElement = (() => {
|
|
|
430
430
|
return class SbbCalendarWeeknumberElement extends _classSuper {
|
|
431
431
|
constructor() {
|
|
432
432
|
super(...arguments);
|
|
433
|
-
this.
|
|
434
|
-
this._value = null;
|
|
433
|
+
this._value = (__runInitializers(this, _instanceExtraInitializers), null);
|
|
435
434
|
}
|
|
436
435
|
static {
|
|
437
436
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
@@ -463,7 +462,6 @@ let SbbCalendarWeeknumberElement = (() => {
|
|
|
463
462
|
set value(value) {
|
|
464
463
|
if (!value) return;
|
|
465
464
|
this._value = String(value);
|
|
466
|
-
this.internals.ariaLabel = `${i18nCalendarWeekNumber[this._language.current]} ${value}`;
|
|
467
465
|
}
|
|
468
466
|
get value() {
|
|
469
467
|
return this._value;
|
|
@@ -476,6 +474,19 @@ let SbbCalendarWeeknumberElement = (() => {
|
|
|
476
474
|
};
|
|
477
475
|
})();
|
|
478
476
|
|
|
477
|
+
// src/elements/calendar/calendar-select-all/calendar-select-all.component.ts
|
|
478
|
+
/**
|
|
479
|
+
* It displays a toggle all button inside the `sbb-calendar` component.
|
|
480
|
+
*/
|
|
481
|
+
var SbbCalendarSelectAllElement = class extends SbbIconNameMixin(SbbCalendarCellBaseElement) {
|
|
482
|
+
static {
|
|
483
|
+
this.elementName = "sbb-calendar-select-all";
|
|
484
|
+
}
|
|
485
|
+
renderTemplate() {
|
|
486
|
+
return this.renderIconSlot();
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
479
490
|
// src/elements/calendar/calendar/calendar.scss?inline
|
|
480
491
|
var calendar_default = ":host {\n display: block;\n width: max-content;\n max-width: 100%;\n line-height: var(--sbb-typo-line-height-text);\n}\n\n:host(:is(:state(enhanced),[state--enhanced])) {\n --sbb-calendar-cell-padding-block-end: var(--sbb-spacing-fixed-3x);\n}\n\n.sbb-calendar__wrapper {\n width: 100%;\n display: flex;\n flex-wrap: wrap;\n gap: var(--sbb-calendar-tables-gap);\n position: relative;\n}\n\n:host(:is(:state(single-month),[state--single-month])) .sbb-calendar__table-wrapper {\n width: 100%;\n min-width: fit-content;\n}\n\n.sbb-calendar__table-data > slot {\n display: flex;\n justify-content: center;\n}\n\n:is(.sbb-calendar__year-view, .sbb-calendar__month-view) {\n position: absolute;\n inset-block-start: 0;\n inset-inline-start: 0;\n}\n\n:host(:not(:is(:state(view-day),[state--view-day]))) .sbb-calendar__day-view {\n visibility: hidden;\n}\n\n.sbb-calendar__table-header {\n display: flex;\n align-items: center;\n gap: var(--sbb-calendar-control-gap);\n height: var(--sbb-size-element-xs);\n margin-block-end: var(--sbb-spacing-fixed-4x);\n}\n\n.sbb-calendar__table-header span {\n flex: 1 1 auto;\n padding-inline-start: var(--sbb-spacing-fixed-3x);\n color: var(--sbb-calendar-control-view-change-color);\n}\n\n.sbb-calendar__control {\n -webkit-tap-highlight-color: transparent;\n}\n\n.sbb-calendar__table {\n width: 100%;\n border-collapse: collapse;\n height: max-content;\n flex: 0 0;\n}\n\n.sbb-calendar__table :is(thead, tbody) {\n text-align: center;\n}\n\n.sbb-calendar__table-header-cell,\n.sbb-calendar__table-header-cell-vertical {\n width: var(--sbb-calendar-cell-size);\n min-width: var(--sbb-calendar-cell-size);\n color: var(--sbb-calendar-header-color);\n padding: 0;\n font-size: var(--sbb-text-font-size-xs);\n font-weight: normal;\n letter-spacing: var(--sbb-letter-spacing-text);\n justify-content: center;\n}\n:host(:not([multiple])) .sbb-calendar__table-header-cell,\n:host(:not([multiple])) .sbb-calendar__table-header-cell-vertical {\n height: var(--sbb-calendar-cell-size);\n}\n\n.sbb-calendar__table-header-cell-vertical {\n padding-block-end: var(--sbb-calendar-cell-padding-block-end);\n}\n\n.sbb-calendar__table-data {\n position: relative;\n padding: 0;\n text-align: center;\n}\n\n.sbb-calendar__day-cell {\n padding-block-end: var(--sbb-calendar-cell-padding-block-end);\n}\n\n:host(:not(:is(:state(enhanced),[state--enhanced]))) sbb-calendar-day {\n --sbb-calendar-day-justify-content: center;\n --sbb-calendar-day-height: var(--sbb-calendar-day-size);\n --sbb-calendar-day-extra-display: none;\n --sbb-calendar-day-value-height: unset;\n}\n";
|
|
481
492
|
|
|
@@ -485,6 +496,8 @@ const MONTHS_PER_ROW = 4;
|
|
|
485
496
|
const YEARS_PER_ROW = 4;
|
|
486
497
|
const MONTHS_PER_PAGE = 12;
|
|
487
498
|
const YEARS_PER_PAGE = 24;
|
|
499
|
+
const WEEKDAY_HINT_ID = "sbb-calendar-weekday-hint";
|
|
500
|
+
const WEEK_NUMBER_HINT_ID = "sbb-calendar-week-number-hint";
|
|
488
501
|
var SbbMonthChangeEvent = class extends Event {
|
|
489
502
|
get range() {
|
|
490
503
|
return this._range;
|
|
@@ -802,6 +815,7 @@ let SbbCalendarElement = (() => {
|
|
|
802
815
|
this.elementDependencies = [
|
|
803
816
|
SbbCalendarDayElement,
|
|
804
817
|
SbbCalendarMonthElement,
|
|
818
|
+
SbbCalendarSelectAllElement,
|
|
805
819
|
SbbCalendarWeekdayElement,
|
|
806
820
|
SbbCalendarWeeknumberElement,
|
|
807
821
|
SbbCalendarYearElement,
|
|
@@ -810,11 +824,7 @@ let SbbCalendarElement = (() => {
|
|
|
810
824
|
];
|
|
811
825
|
}
|
|
812
826
|
static {
|
|
813
|
-
this.styles = [
|
|
814
|
-
buttonResetStyles,
|
|
815
|
-
screenReaderOnlyStyles,
|
|
816
|
-
unsafeCSS(calendar_default)
|
|
817
|
-
];
|
|
827
|
+
this.styles = [screenReaderOnlyStyles, unsafeCSS(calendar_default)];
|
|
818
828
|
}
|
|
819
829
|
static {
|
|
820
830
|
this.events = {
|
|
@@ -953,18 +963,6 @@ let SbbCalendarElement = (() => {
|
|
|
953
963
|
set _calendarView(value) {
|
|
954
964
|
this.#_calendarView_accessor_storage = value;
|
|
955
965
|
}
|
|
956
|
-
/** A list of calendar's cells corresponding to days, months or years depending on the view. */
|
|
957
|
-
get _cells() {
|
|
958
|
-
return Array.from((this._calendarView === "day" ? Array.from(this.shadowRoot.querySelectorAll("slot")).flatMap((e) => e.assignedElements({ flatten: true })) : this.shadowRoot?.querySelectorAll(`sbb-calendar-${this._calendarView}`)) ?? []);
|
|
959
|
-
}
|
|
960
|
-
/** A list of calendar's weekday cells. */
|
|
961
|
-
get _weekdayCells() {
|
|
962
|
-
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-weekday`) ?? []);
|
|
963
|
-
}
|
|
964
|
-
/** A list of calendar's weeknumber cells. */
|
|
965
|
-
get _weekNumberCells() {
|
|
966
|
-
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-weeknumber`) ?? []);
|
|
967
|
-
}
|
|
968
966
|
#_initialized_accessor_storage;
|
|
969
967
|
get _initialized() {
|
|
970
968
|
return this.#_initialized_accessor_storage;
|
|
@@ -972,29 +970,6 @@ let SbbCalendarElement = (() => {
|
|
|
972
970
|
set _initialized(value) {
|
|
973
971
|
this.#_initialized_accessor_storage = value;
|
|
974
972
|
}
|
|
975
|
-
get _tabbableGroups() {
|
|
976
|
-
const weekdays = {
|
|
977
|
-
key: "weekdays",
|
|
978
|
-
value: () => this._weekdayCells
|
|
979
|
-
};
|
|
980
|
-
const weekNumbers = {
|
|
981
|
-
key: "weekNumbers",
|
|
982
|
-
value: () => this._weekNumberCells
|
|
983
|
-
};
|
|
984
|
-
const days = {
|
|
985
|
-
key: "days",
|
|
986
|
-
value: () => this._cells
|
|
987
|
-
};
|
|
988
|
-
return this.orientation === "vertical" ? [
|
|
989
|
-
weekNumbers,
|
|
990
|
-
weekdays,
|
|
991
|
-
days
|
|
992
|
-
] : [
|
|
993
|
-
weekdays,
|
|
994
|
-
weekNumbers,
|
|
995
|
-
days
|
|
996
|
-
];
|
|
997
|
-
}
|
|
998
973
|
constructor() {
|
|
999
974
|
super();
|
|
1000
975
|
this.#amount_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _amount_initializers, 1));
|
|
@@ -1030,6 +1005,7 @@ let SbbCalendarElement = (() => {
|
|
|
1030
1005
|
this.#_initialized_accessor_storage = __runInitializers(this, __initialized_initializers, false);
|
|
1031
1006
|
this._language = (__runInitializers(this, __initialized_extraInitializers), new SbbLanguageController(this).withHandler(() => {
|
|
1032
1007
|
this._monthNames = this._dateAdapter.getMonthNames("long");
|
|
1008
|
+
this._setWeekdays();
|
|
1033
1009
|
this._createMonthRows();
|
|
1034
1010
|
}));
|
|
1035
1011
|
this._sortDate = (a, b) => this._dateAdapter.compareDate(a, b);
|
|
@@ -1042,37 +1018,99 @@ let SbbCalendarElement = (() => {
|
|
|
1042
1018
|
this._setWeekdays();
|
|
1043
1019
|
this.addEventListener("focusin", () => this._containingFocus = true);
|
|
1044
1020
|
this.addEventListener("focusout", () => this._containingFocus = false);
|
|
1045
|
-
const resolveDay = (event) => event.target.closest("sbb-calendar-day") ?? event.composedPath().find((e) => e.localName === "sbb-calendar-day") ?? null;
|
|
1046
|
-
const resolveWeekday = (event) => event.composedPath().find((e) => e.localName === "sbb-calendar-weekday") ?? null;
|
|
1047
|
-
const resolveWeekNumber = (event) => event.composedPath().find((e) => e.localName === "sbb-calendar-weeknumber") ?? null;
|
|
1048
1021
|
this.addEventListener("click", (event) => {
|
|
1049
|
-
const
|
|
1050
|
-
if (day) this._selectDate(
|
|
1051
|
-
});
|
|
1052
|
-
this.addEventListener("keydown", (event) => {
|
|
1053
|
-
const day = resolveDay(event);
|
|
1054
|
-
const weekday = resolveWeekday(event);
|
|
1055
|
-
const weekNumber = resolveWeekNumber(event);
|
|
1056
|
-
if (!(day || weekday || weekNumber)) return;
|
|
1057
|
-
if (event.key === "Tab") {
|
|
1058
|
-
const currentKey = weekday ? "weekdays" : weekNumber ? "weekNumbers" : "days";
|
|
1059
|
-
const availableGroups = this._tabbableGroups.filter((tg) => tg.value().length > 0);
|
|
1060
|
-
const groupId = availableGroups.findIndex((tg) => tg.key === currentKey);
|
|
1061
|
-
const nextIdx = event.shiftKey ? groupId - 1 : groupId + 1;
|
|
1062
|
-
if (groupId === -1 || nextIdx < 0 || nextIdx >= availableGroups.length) return;
|
|
1063
|
-
const next = availableGroups[nextIdx].value().find((e) => e.tabIndex === 0);
|
|
1064
|
-
if (!next) return;
|
|
1065
|
-
event.preventDefault();
|
|
1066
|
-
next.focus();
|
|
1067
|
-
}
|
|
1068
|
-
if (isArrowKeyOrPageKeysPressed(event)) {
|
|
1069
|
-
if (day) this._handleKeyboardEvent(event, day);
|
|
1070
|
-
else if (weekday) this._handleKeyboardEventWeek(event, weekday, this._weekdayCells);
|
|
1071
|
-
else if (weekNumber) this._handleKeyboardEventWeek(event, weekNumber, this._weekNumberCells);
|
|
1072
|
-
}
|
|
1022
|
+
const cell = this._resolveHeaderNavigationCell(event);
|
|
1023
|
+
if (cell?.localName === "sbb-calendar-day") this._selectDate(cell.value, event);
|
|
1073
1024
|
});
|
|
1025
|
+
this.addEventListener("keydown", (event) => this._handleCellKeydown(event));
|
|
1074
1026
|
this.addEventListener("blur", () => this._lastSelection = null);
|
|
1075
1027
|
}
|
|
1028
|
+
/** A list of calendar's cells corresponding to days, months or years depending on the view. */
|
|
1029
|
+
_cells() {
|
|
1030
|
+
switch (this._calendarView) {
|
|
1031
|
+
case "month": return this._monthCells();
|
|
1032
|
+
case "year": return this._yearCells();
|
|
1033
|
+
default: return this._dayCells();
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
/** A list of calendar's month cells. */
|
|
1037
|
+
_yearCells() {
|
|
1038
|
+
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-year`) ?? []);
|
|
1039
|
+
}
|
|
1040
|
+
/** A list of calendar's month cells. */
|
|
1041
|
+
_monthCells() {
|
|
1042
|
+
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-month`) ?? []);
|
|
1043
|
+
}
|
|
1044
|
+
/** Returns the rendered or slotted days within the given root. */
|
|
1045
|
+
_dayCells(root = this.shadowRoot) {
|
|
1046
|
+
return Array.from(root.querySelectorAll("slot")).flatMap((slot) => slot.assignedElements({ flatten: true })).filter((el) => el.localName === "sbb-calendar-day");
|
|
1047
|
+
}
|
|
1048
|
+
/** A list of calendar's weekday cells. */
|
|
1049
|
+
_weekdayCells() {
|
|
1050
|
+
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-weekday`) ?? []);
|
|
1051
|
+
}
|
|
1052
|
+
/** A list of calendar's weeknumber cells. */
|
|
1053
|
+
_weekNumberCells() {
|
|
1054
|
+
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-weeknumber`) ?? []);
|
|
1055
|
+
}
|
|
1056
|
+
_selectAllButtons() {
|
|
1057
|
+
return Array.from(this.shadowRoot?.querySelectorAll(`sbb-calendar-select-all`) ?? []);
|
|
1058
|
+
}
|
|
1059
|
+
/** Returns the day, weekday, week number or select-all cell the event originates from. */
|
|
1060
|
+
_resolveHeaderNavigationCell(event) {
|
|
1061
|
+
return event.composedPath().find((e) => e instanceof HTMLElement && [
|
|
1062
|
+
"sbb-calendar-day",
|
|
1063
|
+
"sbb-calendar-weekday",
|
|
1064
|
+
"sbb-calendar-weeknumber",
|
|
1065
|
+
"sbb-calendar-select-all"
|
|
1066
|
+
].includes(e.localName));
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Each table provides two tab stops: the header cells (select-all, weekdays and week numbers)
|
|
1070
|
+
* and the days. Arrow keys move within a tab stop, Tab moves between them.
|
|
1071
|
+
*/
|
|
1072
|
+
_handleCellKeydown(event) {
|
|
1073
|
+
const cell = this._resolveHeaderNavigationCell(event);
|
|
1074
|
+
const table = cell?.closest("table") ?? cell?.assignedSlot?.closest("table");
|
|
1075
|
+
if (!cell || !table) return;
|
|
1076
|
+
const isDay = cell.localName === "sbb-calendar-day";
|
|
1077
|
+
let toFocus;
|
|
1078
|
+
if (event.key === "Tab") {
|
|
1079
|
+
if (isDay && event.shiftKey) toFocus = table.querySelector("sbb-calendar-select-all") ?? table.querySelector("sbb-calendar-weekday");
|
|
1080
|
+
else if (!isDay && !event.shiftKey) toFocus = this._getDayTabStop(table);
|
|
1081
|
+
else this.shadowRoot.querySelectorAll("table [tabindex=\"0\"]").forEach((el) => el.tabIndex = -1);
|
|
1082
|
+
} else if (isArrowKeyOrPageKeysPressed(event)) {
|
|
1083
|
+
if (isDay) this._handleKeyboardEvent(event, cell);
|
|
1084
|
+
else toFocus = this._getNextNavigationHeaderCell(event, cell);
|
|
1085
|
+
}
|
|
1086
|
+
if (toFocus) {
|
|
1087
|
+
event.preventDefault();
|
|
1088
|
+
toFocus.focus();
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
/** Returns the day of the given table which should receive focus when tabbing into the days. */
|
|
1092
|
+
_getDayTabStop(table) {
|
|
1093
|
+
const days = this._dayCells(table);
|
|
1094
|
+
return days.find((day) => day.tabIndex === 0 && !day.disabled) ?? this._getFirstFocusableDay(days);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Weekdays are navigated along the orientation axis, week numbers along the other one.
|
|
1098
|
+
* The select-all buttons belong to both groups. Navigation spans over all tables.
|
|
1099
|
+
*/
|
|
1100
|
+
_getNextNavigationHeaderCell(event, cell) {
|
|
1101
|
+
const weekdayAxis = [
|
|
1102
|
+
"ArrowLeft",
|
|
1103
|
+
"ArrowRight",
|
|
1104
|
+
"Home",
|
|
1105
|
+
"End"
|
|
1106
|
+
].includes(event.key) === (this.orientation === "horizontal");
|
|
1107
|
+
const group = [...this._selectAllButtons(), ...weekdayAxis ? this._weekdayCells() : this._weekNumberCells()].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
1108
|
+
const index = group.indexOf(cell);
|
|
1109
|
+
if (index === -1) return;
|
|
1110
|
+
else if (event.key === "Home" || event.key === "PageUp") return group[0];
|
|
1111
|
+
else if (event.key === "End" || event.key === "PageDown") return group.at(-1);
|
|
1112
|
+
return group[getNextElementIndex(event, index, group.length)];
|
|
1113
|
+
}
|
|
1076
1114
|
_dateFilter(date) {
|
|
1077
1115
|
return this.dateFilter?.(date) ?? true;
|
|
1078
1116
|
}
|
|
@@ -1134,6 +1172,7 @@ let SbbCalendarElement = (() => {
|
|
|
1134
1172
|
willUpdate(changedProperties) {
|
|
1135
1173
|
super.willUpdate(changedProperties);
|
|
1136
1174
|
if (!this._initialized) return;
|
|
1175
|
+
if (changedProperties.has("orientation")) this._weeks = [];
|
|
1137
1176
|
if (changedProperties.has("amount") || changedProperties.has("orientation") || changedProperties.has("fixedMonth")) this.resetPosition();
|
|
1138
1177
|
if (changedProperties.has("view")) {
|
|
1139
1178
|
this._setChosenYear();
|
|
@@ -1257,34 +1296,19 @@ let SbbCalendarElement = (() => {
|
|
|
1257
1296
|
return weeks;
|
|
1258
1297
|
}
|
|
1259
1298
|
_mapDateToDay(date) {
|
|
1299
|
+
const isoDate = this._dateAdapter.toIso8601(date);
|
|
1300
|
+
const { week, year } = this._dateAdapter.getIsoWeek(date);
|
|
1260
1301
|
return {
|
|
1261
|
-
value:
|
|
1302
|
+
value: isoDate,
|
|
1262
1303
|
dateValue: date,
|
|
1263
1304
|
dayValue: String(this._dateAdapter.getDate(date)),
|
|
1264
1305
|
monthValue: String(this._dateAdapter.getMonth(date)),
|
|
1265
1306
|
yearValue: String(this._dateAdapter.getYear(date)),
|
|
1266
|
-
weekValue:
|
|
1307
|
+
weekValue: week,
|
|
1308
|
+
weekYearValue: year,
|
|
1267
1309
|
weekDayValue: this._dateAdapter.getDayOfWeek(date)
|
|
1268
1310
|
};
|
|
1269
1311
|
}
|
|
1270
|
-
_getWeek(date) {
|
|
1271
|
-
const firstDayOfYear = this._dateAdapter.createDate(this._dateAdapter.getYear(date), 1, 1);
|
|
1272
|
-
const weekday = this._dateAdapter.getDayOfWeek(firstDayOfYear);
|
|
1273
|
-
let weekIndex = [
|
|
1274
|
-
MONDAY,
|
|
1275
|
-
TUESDAY,
|
|
1276
|
-
WEDNESDAY,
|
|
1277
|
-
THURSDAY
|
|
1278
|
-
].includes(weekday) ? 1 : 0;
|
|
1279
|
-
let weekStart = this._dateAdapter.addCalendarDays(firstDayOfYear, this._dateAdapter.getFirstWeekOffset(firstDayOfYear) * -1);
|
|
1280
|
-
while (this._dateAdapter.compareDate(weekStart, date) <= 0) {
|
|
1281
|
-
const weekEnd = this._dateAdapter.addCalendarDays(weekStart, 6);
|
|
1282
|
-
if (this._dateAdapter.compareDate(date, weekEnd) <= 0) return weekIndex > 0 ? weekIndex : this._getWeek(this._dateAdapter.addCalendarDays(firstDayOfYear, -1));
|
|
1283
|
-
weekStart = this._dateAdapter.addCalendarDays(weekStart, DAYS_PER_ROW);
|
|
1284
|
-
weekIndex++;
|
|
1285
|
-
}
|
|
1286
|
-
throw new Error("The provided date is invalid");
|
|
1287
|
-
}
|
|
1288
1312
|
/** Force the conversion to ISO8601 formatted string. */
|
|
1289
1313
|
_mapValueToISODate(value) {
|
|
1290
1314
|
return typeof value === "string" ? value : this._dateAdapter.toIso8601(value);
|
|
@@ -1373,7 +1397,7 @@ let SbbCalendarElement = (() => {
|
|
|
1373
1397
|
}
|
|
1374
1398
|
_mergeDates(dates, selected) {
|
|
1375
1399
|
selected ??= this._value.map((s) => this._dateAdapter.toIso8601(s));
|
|
1376
|
-
const enabledDays = this._cells.filter((e) => !e.disabled).map((e) => this._mapValueToISODate(e.value));
|
|
1400
|
+
const enabledDays = this._cells().filter((e) => !e.disabled).map((e) => this._mapValueToISODate(e.value));
|
|
1377
1401
|
const daysToAdd = dates.filter((isoDate) => enabledDays.includes(isoDate));
|
|
1378
1402
|
if (daysToAdd.every((day) => selected.includes(day))) selected = selected.filter((day) => !daysToAdd.includes(day));
|
|
1379
1403
|
else selected = [...selected, ...daysToAdd].filter((v, i, a) => a.indexOf(v) === i);
|
|
@@ -1470,83 +1494,44 @@ let SbbCalendarElement = (() => {
|
|
|
1470
1494
|
return this._nextDisabled(nextYear);
|
|
1471
1495
|
}
|
|
1472
1496
|
_handleTableBlur(eventTarget) {
|
|
1473
|
-
if (eventTarget?.localName !== "sbb-calendar-day" && eventTarget?.localName !== "sbb-calendar-weeknumber" && eventTarget?.localName !== "sbb-calendar-weekday") this._setTabIndex();
|
|
1497
|
+
if (eventTarget?.localName !== "sbb-calendar-day" && eventTarget?.localName !== "sbb-calendar-weeknumber" && eventTarget?.localName !== "sbb-calendar-weekday" && eventTarget?.localName !== "sbb-calendar-select-all") this._setTabIndex();
|
|
1474
1498
|
}
|
|
1475
1499
|
_setTabIndex() {
|
|
1476
|
-
Array.from(this._cells.filter((e) => e.tabIndex === 0) ?? []).forEach((day) => day.tabIndex = -1);
|
|
1477
|
-
this.
|
|
1500
|
+
Array.from(this._cells().filter((e) => e.tabIndex === 0) ?? []).forEach((day) => day.tabIndex = -1);
|
|
1501
|
+
const setFocus = (e, i) => e.tabIndex = i === 0 && !this.weekNumbers ? 0 : -1;
|
|
1502
|
+
this._weekdayCells().forEach(setFocus);
|
|
1503
|
+
this._weekNumberCells().forEach(setFocus);
|
|
1504
|
+
this._selectAllButtons().forEach((e, i) => e.tabIndex = i === 0 ? 0 : -1);
|
|
1478
1505
|
const firstFocusable = this._getFirstFocusable();
|
|
1479
1506
|
if (firstFocusable) firstFocusable.tabIndex = 0;
|
|
1480
1507
|
}
|
|
1481
|
-
_setWeekFocus() {
|
|
1482
|
-
this._weekdayCells.forEach((e, i) => e.tabIndex = i === 0 ? 0 : -1);
|
|
1483
|
-
this._weekNumberCells.forEach((e, i) => e.tabIndex = i === 0 ? 0 : -1);
|
|
1484
|
-
}
|
|
1485
1508
|
/** Get the element in the calendar to assign focus. */
|
|
1486
1509
|
_getFirstFocusable() {
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
const selectedOrCurrent = this.shadowRoot?.querySelector(`sbb-calendar-${this._calendarView}:is(:state(selected),[state--selected])`) ?? this.shadowRoot?.querySelector(`sbb-calendar-${this._calendarView}:is(:state(current),[state--current])`);
|
|
1492
|
-
return selectedOrCurrent && !selectedOrCurrent.disabled ? selectedOrCurrent : this.shadowRoot.querySelector(`sbb-calendar-${this._calendarView}:not([disabled])`);
|
|
1493
|
-
}
|
|
1510
|
+
const cells = this._cells();
|
|
1511
|
+
const selectedOrCurrent = cells.find((e) => e.matches(":is(:state(selected),[state--selected])")) ?? cells.find((e) => e.matches(":is(:state(current),[state--current])"));
|
|
1512
|
+
if (selectedOrCurrent && !selectedOrCurrent.disabled) return selectedOrCurrent;
|
|
1513
|
+
return this._calendarView === "day" ? this._getFirstFocusableDay(cells) : cells.find((e) => !e.disabled) ?? null;
|
|
1494
1514
|
}
|
|
1495
1515
|
/**
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
* To solve this, the element with the lowest `value` is taken (ISO String are ordered).
|
|
1516
|
+
* Returns the enabled day with the earliest date.
|
|
1517
|
+
* In `vertical` orientation, the DOM order does not match the date order (e.g. if the first of
|
|
1518
|
+
* the month is not a Monday), so the days are compared by their slot name (ISO string).
|
|
1501
1519
|
*/
|
|
1502
|
-
_getFirstFocusableDay() {
|
|
1503
|
-
|
|
1504
|
-
const daysInView = cells.filter((e) => !e.disabled);
|
|
1505
|
-
if (!daysInView || daysInView.length === 0) return null;
|
|
1506
|
-
else {
|
|
1507
|
-
const firstElement = daysInView.map((e) => this._dateAdapter.toIso8601(e.value)).sort()[0];
|
|
1508
|
-
return cells.find((e) => e.matches(`[slot="${firstElement}"]`)) ?? null;
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
_handleKeyboardEventWeek(event, cell, cellArray) {
|
|
1512
|
-
event.preventDefault();
|
|
1513
|
-
let nextEl;
|
|
1514
|
-
switch (event.key) {
|
|
1515
|
-
case "ArrowUp":
|
|
1516
|
-
case "ArrowDown":
|
|
1517
|
-
case "ArrowLeft":
|
|
1518
|
-
case "ArrowRight":
|
|
1519
|
-
nextEl = cellArray[getNextElementIndex(event, cellArray.indexOf(cell), cellArray.length)];
|
|
1520
|
-
break;
|
|
1521
|
-
case "PageUp":
|
|
1522
|
-
case "Home":
|
|
1523
|
-
nextEl = cellArray[0];
|
|
1524
|
-
break;
|
|
1525
|
-
case "PageDown":
|
|
1526
|
-
case "End":
|
|
1527
|
-
nextEl = cellArray[cellArray.length - 1];
|
|
1528
|
-
break;
|
|
1529
|
-
default: nextEl = cell;
|
|
1530
|
-
}
|
|
1531
|
-
if (nextEl !== cell) {
|
|
1532
|
-
nextEl.tabIndex = 0;
|
|
1533
|
-
nextEl.focus();
|
|
1534
|
-
cell.tabIndex = -1;
|
|
1535
|
-
}
|
|
1520
|
+
_getFirstFocusableDay(days) {
|
|
1521
|
+
return days.filter((day) => !day.disabled).sort((a, b) => a.slot.localeCompare(b.slot))[0] ?? null;
|
|
1536
1522
|
}
|
|
1537
1523
|
_handleKeyboardEvent(event, day) {
|
|
1538
1524
|
if (isArrowKeyOrPageKeysPressed(event)) event.preventDefault();
|
|
1539
1525
|
const origin = day ?? event.target;
|
|
1540
|
-
const cells = this._cells;
|
|
1526
|
+
const cells = this._cells();
|
|
1541
1527
|
const index = cells.indexOf(origin);
|
|
1542
1528
|
let nextEl;
|
|
1543
1529
|
if (day) nextEl = this._navigateByKeyboardDayView(event, index, cells, this._mapDateToDay(day.value));
|
|
1544
1530
|
else nextEl = this._navigateByKeyboard(event, index, cells);
|
|
1545
|
-
|
|
1546
|
-
|
|
1531
|
+
if (nextEl !== origin) {
|
|
1532
|
+
origin.tabIndex = -1;
|
|
1547
1533
|
nextEl.tabIndex = 0;
|
|
1548
1534
|
nextEl.focus();
|
|
1549
|
-
if (cells.includes(activeEl)) activeEl.tabIndex = -1;
|
|
1550
1535
|
}
|
|
1551
1536
|
}
|
|
1552
1537
|
_navigateByKeyboardDayView(evt, index, cells, day) {
|
|
@@ -1557,71 +1542,44 @@ let SbbCalendarElement = (() => {
|
|
|
1557
1542
|
leftRight: DAYS_PER_ROW,
|
|
1558
1543
|
upDown: 1
|
|
1559
1544
|
};
|
|
1545
|
+
const current = cells[index];
|
|
1546
|
+
const findDay = (offset, step) => this._findEnabledDay(cells, this._dateAdapter.addCalendarDays(day.dateValue, offset), step, current);
|
|
1560
1547
|
switch (evt.key) {
|
|
1561
|
-
case "ArrowUp": return
|
|
1562
|
-
case "ArrowDown": return
|
|
1563
|
-
case "ArrowLeft": return
|
|
1564
|
-
case "ArrowRight": return
|
|
1565
|
-
case "PageUp": if (this.orientation === "horizontal")
|
|
1566
|
-
|
|
1567
|
-
return this._findDayPageUpDown(cells, index, day, delta, arrowsOffset.upDown);
|
|
1568
|
-
} else {
|
|
1548
|
+
case "ArrowUp": return findDay(-arrowsOffset.upDown, -arrowsOffset.upDown);
|
|
1549
|
+
case "ArrowDown": return findDay(arrowsOffset.upDown, arrowsOffset.upDown);
|
|
1550
|
+
case "ArrowLeft": return findDay(-arrowsOffset.leftRight, -arrowsOffset.leftRight);
|
|
1551
|
+
case "ArrowRight": return findDay(arrowsOffset.leftRight, arrowsOffset.leftRight);
|
|
1552
|
+
case "PageUp": if (this.orientation === "horizontal") return findDay((+day.dayValue % DAYS_PER_ROW || DAYS_PER_ROW) - +day.dayValue, arrowsOffset.upDown);
|
|
1553
|
+
else {
|
|
1569
1554
|
const offsetForVertical = this._dateAdapter.getFirstWeekOffset(day.dateValue);
|
|
1570
|
-
|
|
1571
|
-
return this._findDayPageUpDown(cells, index, day, delta, arrowsOffset.upDown);
|
|
1555
|
+
return findDay((Math.ceil((+day.dayValue + offsetForVertical) / DAYS_PER_ROW) - 1) * DAYS_PER_ROW - offsetForVertical + 1 - +day.dayValue, arrowsOffset.upDown);
|
|
1572
1556
|
}
|
|
1573
1557
|
case "PageDown": if (this.orientation === "horizontal") {
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
const firstNextMonth = this._dateAdapter.createDate(yearInBounds, monthInBounds, 1);
|
|
1577
|
-
const lastOfMonth = this._dateAdapter.getDate(this._dateAdapter.addCalendarDays(firstNextMonth, -1));
|
|
1578
|
-
const delta = Math.trunc((lastOfMonth - +day.dayValue) / DAYS_PER_ROW) * DAYS_PER_ROW;
|
|
1579
|
-
return this._findDayPageUpDown(cells, index, day, delta, -arrowsOffset.upDown);
|
|
1558
|
+
const lastOfMonth = this._dateAdapter.getNumDaysInMonth(day.dateValue);
|
|
1559
|
+
return findDay(Math.trunc((lastOfMonth - +day.dayValue) / DAYS_PER_ROW) * DAYS_PER_ROW, -arrowsOffset.upDown);
|
|
1580
1560
|
} else {
|
|
1581
1561
|
const offsetForVertical = this._dateAdapter.getFirstWeekOffset(day.dateValue);
|
|
1582
|
-
|
|
1583
|
-
return this._findDayPageUpDown(cells, index, day, delta, -arrowsOffset.upDown);
|
|
1584
|
-
}
|
|
1585
|
-
case "Home": return this._findDayFirst(cells, index, day, 1);
|
|
1586
|
-
case "End": {
|
|
1587
|
-
const monthInBounds = +day.monthValue + 1 > 12 ? 1 : +day.monthValue + 1;
|
|
1588
|
-
const yearInBounds = +day.monthValue + 1 > 12 ? +day.yearValue + 1 : +day.yearValue;
|
|
1589
|
-
const firstNextMonth = this._dateAdapter.createDate(yearInBounds, monthInBounds, 1);
|
|
1590
|
-
return this._findDayLast(cells, index, firstNextMonth);
|
|
1562
|
+
return findDay(Math.ceil((+day.dayValue + offsetForVertical) / DAYS_PER_ROW) * DAYS_PER_ROW - offsetForVertical - +day.dayValue, -arrowsOffset.upDown);
|
|
1591
1563
|
}
|
|
1592
|
-
|
|
1564
|
+
case "Home": return findDay(1 - +day.dayValue, 1);
|
|
1565
|
+
case "End": return findDay(this._dateAdapter.getNumDaysInMonth(day.dateValue) - +day.dayValue, -1);
|
|
1566
|
+
default: return current;
|
|
1593
1567
|
}
|
|
1594
1568
|
}
|
|
1595
1569
|
_isDayOutOfView(date) {
|
|
1596
1570
|
return date < this._firstVisibleDay || date > this._lastVisibleDay;
|
|
1597
1571
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
if (!nextCell || nextCell.disabled) return this._findDayPageUpDown(cells, index, day, delta + deltaIfDisabled, deltaIfDisabled);
|
|
1610
|
-
return nextCell;
|
|
1611
|
-
}
|
|
1612
|
-
_findDayFirst(cells, index, day, date) {
|
|
1613
|
-
const newDateValue = this._dateAdapter.toIso8601(this._dateAdapter.createDate(+day.yearValue, +day.monthValue, date));
|
|
1614
|
-
if (this._isDayOutOfView(newDateValue)) return cells[index];
|
|
1615
|
-
const nextCell = cells.find((e) => this._mapValueToISODate(e.value) === newDateValue);
|
|
1616
|
-
if (!nextCell || nextCell.disabled) return this._findDayFirst(cells, index, day, date + 1);
|
|
1617
|
-
return nextCell;
|
|
1618
|
-
}
|
|
1619
|
-
_findDayLast(cells, index, firstNextMonth) {
|
|
1620
|
-
const newDateValue = this._dateAdapter.toIso8601(this._dateAdapter.addCalendarDays(firstNextMonth, -1));
|
|
1621
|
-
if (this._isDayOutOfView(newDateValue)) return cells[index];
|
|
1622
|
-
const nextCell = cells.find((e) => this._mapValueToISODate(e.value) === newDateValue);
|
|
1623
|
-
if (!nextCell || nextCell.disabled) return this._findDayLast(cells, index, this._dateAdapter.deserialize(newDateValue));
|
|
1624
|
-
return nextCell;
|
|
1572
|
+
/**
|
|
1573
|
+
* Starting from `date`, moves by `step` days until an enabled day is found.
|
|
1574
|
+
* Returns `fallback` if the visible range is left before.
|
|
1575
|
+
*/
|
|
1576
|
+
_findEnabledDay(cells, date, step, fallback) {
|
|
1577
|
+
for (let current = date;; current = this._dateAdapter.addCalendarDays(current, step)) {
|
|
1578
|
+
const iso = this._dateAdapter.toIso8601(current);
|
|
1579
|
+
if (this._isDayOutOfView(iso)) return fallback;
|
|
1580
|
+
const cell = cells.find((e) => e.slot === iso);
|
|
1581
|
+
if (cell && !cell.disabled) return cell;
|
|
1582
|
+
}
|
|
1625
1583
|
}
|
|
1626
1584
|
/**
|
|
1627
1585
|
* Gets the index of the element to move to, based on a list of elements (which can be potentially disabled),
|
|
@@ -1702,161 +1660,79 @@ let SbbCalendarElement = (() => {
|
|
|
1702
1660
|
_createDayTable(weeks, weekNumbers, first) {
|
|
1703
1661
|
const firstDay = weeks[0][0].dateValue;
|
|
1704
1662
|
const monthLabel = `${this._monthNames[this._dateAdapter.getMonth(firstDay) - 1]} ${this._dateAdapter.getYear(firstDay)}`;
|
|
1705
|
-
const
|
|
1706
|
-
const weeksForSelectMultipleWeekDays = weeks.flat();
|
|
1663
|
+
const days = weeks.flat();
|
|
1707
1664
|
return html`
|
|
1708
1665
|
<div class="sbb-calendar__table-wrapper sbb-calendar__day-view">
|
|
1709
1666
|
<div class="sbb-calendar__table-header">
|
|
1710
|
-
<span>${monthLabel}</span>
|
|
1667
|
+
<span>${monthLabel}</span>
|
|
1668
|
+
${first ? this._createDayTableControls(monthLabel) : nothing}
|
|
1711
1669
|
</div>
|
|
1712
1670
|
<table
|
|
1713
1671
|
class="sbb-calendar__table"
|
|
1714
1672
|
@focusout=${(event) => this._handleTableBlur(event.relatedTarget)}
|
|
1715
1673
|
>
|
|
1716
|
-
|
|
1717
|
-
<tr>
|
|
1718
|
-
${this.weekNumbers ? html`<th class="sbb-calendar__table-header-cell"></th>` : nothing}
|
|
1719
|
-
${this._weekdays.map((weekDay, index) => html`
|
|
1720
|
-
<th class="sbb-calendar__table-header-cell">
|
|
1721
|
-
${this.multiple ? html`
|
|
1722
|
-
<sbb-calendar-weekday
|
|
1723
|
-
.value=${weekDay}
|
|
1724
|
-
@click=${() => {
|
|
1725
|
-
const days = weeksForSelectMultipleWeekDays.filter((day) => day.weekDayValue === (index + 1) % 7);
|
|
1726
|
-
this._selectMultipleDates(days);
|
|
1727
|
-
}}
|
|
1728
|
-
></sbb-calendar-weekday>
|
|
1729
|
-
` : html`
|
|
1730
|
-
<span class="sbb-screen-reader-only">${weekDay.long}</span>
|
|
1731
|
-
<span aria-hidden="true">${weekDay.narrow}</span>
|
|
1732
|
-
`}
|
|
1733
|
-
</th>
|
|
1734
|
-
`)}
|
|
1735
|
-
</tr>
|
|
1736
|
-
</thead>
|
|
1737
|
-
<tbody>
|
|
1738
|
-
${weeks.map((week, rowIndex) => {
|
|
1739
|
-
const firstRowOffset = DAYS_PER_ROW - week.length;
|
|
1740
|
-
if (rowIndex === 0 && firstRowOffset) return html`
|
|
1741
|
-
<tr>
|
|
1742
|
-
${this.weekNumbers ? html`
|
|
1743
|
-
<td class="sbb-calendar__table-header-cell-vertical">
|
|
1744
|
-
${this.multiple ? html`
|
|
1745
|
-
<sbb-calendar-weeknumber
|
|
1746
|
-
.value=${weekNumbers[0]}
|
|
1747
|
-
@click=${() => {
|
|
1748
|
-
const days = weeksForSelectMultipleWeekNumbers.filter((day) => day.weekValue === weekNumbers[0]);
|
|
1749
|
-
this._selectMultipleDates(days);
|
|
1750
|
-
}}
|
|
1751
|
-
></sbb-calendar-weeknumber>
|
|
1752
|
-
` : html`
|
|
1753
|
-
<span class="sbb-screen-reader-only"
|
|
1754
|
-
>${`${i18nCalendarWeekNumber[this._language.current]} ${weekNumbers[0]}`}</span
|
|
1755
|
-
>
|
|
1756
|
-
<span aria-hidden="true">${weekNumbers[0]}</span>
|
|
1757
|
-
`}
|
|
1758
|
-
</td>
|
|
1759
|
-
` : nothing}
|
|
1760
|
-
${[...Array(firstRowOffset).keys()].map(() => html`<td class="sbb-calendar__table-data"></td>`)}
|
|
1761
|
-
${this._createDayCells(week)}
|
|
1762
|
-
</tr>
|
|
1763
|
-
`;
|
|
1764
|
-
return html`
|
|
1765
|
-
<tr>
|
|
1766
|
-
${this.weekNumbers ? html`
|
|
1767
|
-
<td class="sbb-calendar__table-header-cell-vertical">
|
|
1768
|
-
${this.multiple ? html`
|
|
1769
|
-
<sbb-calendar-weeknumber
|
|
1770
|
-
.value=${weekNumbers[rowIndex]}
|
|
1771
|
-
@click=${() => {
|
|
1772
|
-
const days = weeksForSelectMultipleWeekNumbers.filter((day) => day.weekValue === weekNumbers[rowIndex]);
|
|
1773
|
-
this._selectMultipleDates(days);
|
|
1774
|
-
}}
|
|
1775
|
-
></sbb-calendar-weeknumber>
|
|
1776
|
-
` : html`
|
|
1777
|
-
<span class="sbb-screen-reader-only"
|
|
1778
|
-
>${`${i18nCalendarWeekNumber[this._language.current]} ${weekNumbers[rowIndex]}`}</span
|
|
1779
|
-
>
|
|
1780
|
-
<span aria-hidden="true">${weekNumbers[rowIndex]}</span>
|
|
1781
|
-
`}
|
|
1782
|
-
</td>
|
|
1783
|
-
` : nothing}
|
|
1784
|
-
${this._createDayCells(week)}
|
|
1785
|
-
</tr>
|
|
1786
|
-
`;
|
|
1787
|
-
})}
|
|
1788
|
-
</tbody>
|
|
1674
|
+
${this.orientation === "horizontal" ? this._createDayTableHorizontalContent(weeks, weekNumbers, monthLabel, days) : this._createDayTableVerticalContent(weeks, weekNumbers, monthLabel, days)}
|
|
1789
1675
|
</table>
|
|
1790
1676
|
</div>
|
|
1791
1677
|
`;
|
|
1792
1678
|
}
|
|
1793
|
-
/**
|
|
1794
|
-
|
|
1795
|
-
const firstDay = weeks[0][0].dateValue;
|
|
1796
|
-
const monthLabel = `${this._monthNames[this._dateAdapter.getMonth(firstDay) - 1]} ${this._dateAdapter.getYear(firstDay)}`;
|
|
1797
|
-
const activeDate = weeks[0][0].dateValue;
|
|
1798
|
-
const weekOffset = this._dateAdapter.getFirstWeekOffset(activeDate ?? this._activeDate);
|
|
1799
|
-
const weeksForSelectMultipleWeekNumbers = weeks.flat();
|
|
1679
|
+
/** Weekdays are rendered as columns, weeks as rows. */
|
|
1680
|
+
_createDayTableHorizontalContent(weeks, weekNumbers, monthLabel, days) {
|
|
1800
1681
|
return html`
|
|
1801
|
-
<
|
|
1802
|
-
<
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
</thead>
|
|
1833
|
-
` : nothing}
|
|
1834
|
-
<tbody>
|
|
1835
|
-
${weeks.map((week, rowIndex) => {
|
|
1836
|
-
const weekday = this._weekdays[rowIndex];
|
|
1837
|
-
return html`
|
|
1682
|
+
<thead>
|
|
1683
|
+
<tr>
|
|
1684
|
+
${this.weekNumbers ? html`<th class="sbb-calendar__table-header-cell">
|
|
1685
|
+
${this._selectAllButton(monthLabel, days)}
|
|
1686
|
+
</th>` : nothing}
|
|
1687
|
+
${this._weekdays.map((weekday, index) => html`
|
|
1688
|
+
<th class="sbb-calendar__table-header-cell">
|
|
1689
|
+
${this._weekdayCell(weekday, monthLabel, days.filter((day) => day.weekDayValue === (index + 1) % 7))}
|
|
1690
|
+
</th>
|
|
1691
|
+
`)}
|
|
1692
|
+
</tr>
|
|
1693
|
+
</thead>
|
|
1694
|
+
<tbody>
|
|
1695
|
+
${weeks.map((week, rowIndex) => html`
|
|
1696
|
+
<tr>
|
|
1697
|
+
${this.weekNumbers ? html`<td class="sbb-calendar__table-header-cell-vertical">
|
|
1698
|
+
${this._weekNumberCell(weekNumbers[rowIndex], days)}
|
|
1699
|
+
</td>` : nothing}
|
|
1700
|
+
${rowIndex === 0 ? Array.from({ length: DAYS_PER_ROW - week.length }, () => html`<td class="sbb-calendar__table-data"></td>`) : nothing}
|
|
1701
|
+
${this._createDayCells(week)}
|
|
1702
|
+
</tr>
|
|
1703
|
+
`)}
|
|
1704
|
+
</tbody>
|
|
1705
|
+
`;
|
|
1706
|
+
}
|
|
1707
|
+
/** Weekdays are rendered as rows, weeks as columns. */
|
|
1708
|
+
_createDayTableVerticalContent(weeks, weekNumbers, monthLabel, days) {
|
|
1709
|
+
const weekOffset = this._dateAdapter.getFirstWeekOffset(weeks[0][0].dateValue);
|
|
1710
|
+
return html`
|
|
1711
|
+
${this.weekNumbers ? html`
|
|
1712
|
+
<thead>
|
|
1838
1713
|
<tr>
|
|
1839
|
-
<
|
|
1840
|
-
${this.
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
` : html`
|
|
1848
|
-
<span class="sbb-screen-reader-only">${weekday.long}</span>
|
|
1849
|
-
<span aria-hidden="true">${weekday.narrow}</span>
|
|
1850
|
-
`}
|
|
1851
|
-
</td>
|
|
1852
|
-
${rowIndex < weekOffset ? html`<td class="sbb-calendar__table-data"></td>` : nothing}
|
|
1853
|
-
${this._createDayCells(week)}
|
|
1714
|
+
<th class="sbb-calendar__table-data">
|
|
1715
|
+
${this._selectAllButton(monthLabel, days)}
|
|
1716
|
+
</th>
|
|
1717
|
+
${weekNumbers.map((weekNumber) => html`
|
|
1718
|
+
<th class="sbb-calendar__table-header-cell">
|
|
1719
|
+
${this._weekNumberCell(weekNumber, days)}
|
|
1720
|
+
</th>
|
|
1721
|
+
`)}
|
|
1854
1722
|
</tr>
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1723
|
+
</thead>
|
|
1724
|
+
` : nothing}
|
|
1725
|
+
<tbody>
|
|
1726
|
+
${weeks.map((week, rowIndex) => html`
|
|
1727
|
+
<tr>
|
|
1728
|
+
<td class="sbb-calendar__table-header-cell-vertical">
|
|
1729
|
+
${this._weekdayCell(this._weekdays[rowIndex], monthLabel, week)}
|
|
1730
|
+
</td>
|
|
1731
|
+
${rowIndex < weekOffset ? html`<td class="sbb-calendar__table-data"></td>` : nothing}
|
|
1732
|
+
${this._createDayCells(week)}
|
|
1733
|
+
</tr>
|
|
1734
|
+
`)}
|
|
1735
|
+
</tbody>
|
|
1860
1736
|
`;
|
|
1861
1737
|
}
|
|
1862
1738
|
_createDayTableControls(monthLabel) {
|
|
@@ -1881,6 +1757,67 @@ let SbbCalendarElement = (() => {
|
|
|
1881
1757
|
`;
|
|
1882
1758
|
});
|
|
1883
1759
|
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Returns true if at least one of the given days, which can be selected
|
|
1762
|
+
* (within min/max and not filtered out), is not selected yet.
|
|
1763
|
+
*/
|
|
1764
|
+
_hasUnselectedDays(days) {
|
|
1765
|
+
if (!Array.isArray(this._value)) return false;
|
|
1766
|
+
const selected = new Set(this._value.map((d) => this._dateAdapter.toIso8601(d)));
|
|
1767
|
+
return days.some((d) => !selected.has(d.value) && this._isDayInRange(d.value) && this._dateFilter(d.dateValue));
|
|
1768
|
+
}
|
|
1769
|
+
/** Weekday header cell, which selects all given days if multiple selection is enabled. */
|
|
1770
|
+
_weekdayCell(weekday, monthLabel, days) {
|
|
1771
|
+
if (this.multiple) {
|
|
1772
|
+
const label = this._hasUnselectedDays(days) ? i18nCalendarSelectWeekday(weekday.long, monthLabel) : i18nCalendarDeselectWeekday(weekday.long, monthLabel);
|
|
1773
|
+
return html`
|
|
1774
|
+
<sbb-calendar-weekday
|
|
1775
|
+
.value=${weekday}
|
|
1776
|
+
aria-describedby=${WEEKDAY_HINT_ID}
|
|
1777
|
+
${ref((el) => this._applyElementInternalsAriaLabel(el, label[this._language.current]))}
|
|
1778
|
+
@click=${() => this._selectMultipleDates(days)}
|
|
1779
|
+
></sbb-calendar-weekday>
|
|
1780
|
+
`;
|
|
1781
|
+
} else return html`
|
|
1782
|
+
<span class="sbb-screen-reader-only">${weekday.long}</span>
|
|
1783
|
+
<span aria-hidden="true">${weekday.narrow}</span>
|
|
1784
|
+
`;
|
|
1785
|
+
}
|
|
1786
|
+
/** Week number header cell, which selects the days of the given week if multiple selection is enabled. */
|
|
1787
|
+
_weekNumberCell(weekNumber, daysOfMonth) {
|
|
1788
|
+
if (this.multiple) {
|
|
1789
|
+
const days = daysOfMonth.filter((day) => day.weekValue === weekNumber);
|
|
1790
|
+
const weekYear = days[0].weekYearValue;
|
|
1791
|
+
const label = this._hasUnselectedDays(days) ? i18nCalendarSelectWeek(weekNumber, weekYear) : i18nCalendarDeselectWeek(weekNumber, weekYear);
|
|
1792
|
+
return html`
|
|
1793
|
+
<sbb-calendar-weeknumber
|
|
1794
|
+
.value=${weekNumber}
|
|
1795
|
+
aria-describedby=${WEEK_NUMBER_HINT_ID}
|
|
1796
|
+
${ref((el) => this._applyElementInternalsAriaLabel(el, label[this._language.current]))}
|
|
1797
|
+
@click=${() => this._selectMultipleDates(days)}
|
|
1798
|
+
></sbb-calendar-weeknumber>
|
|
1799
|
+
`;
|
|
1800
|
+
} else return html`
|
|
1801
|
+
<span class="sbb-screen-reader-only">
|
|
1802
|
+
${`${i18nCalendarWeekNumber[this._language.current]} ${weekNumber}`}
|
|
1803
|
+
</span>
|
|
1804
|
+
<span aria-hidden="true">${weekNumber}</span>
|
|
1805
|
+
`;
|
|
1806
|
+
}
|
|
1807
|
+
_selectAllButton(monthLabel, daysOfMonth) {
|
|
1808
|
+
if (this.multiple) {
|
|
1809
|
+
const hints = this.orientation === "horizontal" ? `${WEEKDAY_HINT_ID} ${WEEK_NUMBER_HINT_ID}` : `${WEEK_NUMBER_HINT_ID} ${WEEKDAY_HINT_ID}`;
|
|
1810
|
+
const label = this._hasUnselectedDays(daysOfMonth) ? i18nCalendarSelectAll(monthLabel) : i18nCalendarDeselectAll(monthLabel);
|
|
1811
|
+
return html`
|
|
1812
|
+
<sbb-calendar-select-all
|
|
1813
|
+
icon-name="four-squares-small"
|
|
1814
|
+
${ref((el) => this._applyElementInternalsAriaLabel(el, label[this._language.current]))}
|
|
1815
|
+
aria-describedby=${hints}
|
|
1816
|
+
@click=${() => this._selectMultipleDates(daysOfMonth)}
|
|
1817
|
+
></sbb-calendar-select-all>
|
|
1818
|
+
`;
|
|
1819
|
+
} else return html`${nothing}`;
|
|
1820
|
+
}
|
|
1884
1821
|
/** Render the view for the month selection. */
|
|
1885
1822
|
_renderMonthView() {
|
|
1886
1823
|
return html`
|
|
@@ -1942,7 +1879,7 @@ let SbbCalendarElement = (() => {
|
|
|
1942
1879
|
</div>
|
|
1943
1880
|
<table class="sbb-calendar__table">
|
|
1944
1881
|
<tbody>
|
|
1945
|
-
${this._years.map((row) => html
|
|
1882
|
+
${this._years.map((row) => html`<tr>
|
|
1946
1883
|
${row.map((year) => {
|
|
1947
1884
|
return html`
|
|
1948
1885
|
<td class="sbb-calendar__table-data">
|
|
@@ -1973,7 +1910,7 @@ let SbbCalendarElement = (() => {
|
|
|
1973
1910
|
class="sbb-calendar__control"
|
|
1974
1911
|
size="s"
|
|
1975
1912
|
icon-name="chevron-small-${direction}-small"
|
|
1976
|
-
|
|
1913
|
+
${ref((el) => this._applyElementInternalsAriaLabel(el, ariaLabel))}
|
|
1977
1914
|
@click=${click}
|
|
1978
1915
|
?disabled=${disabled}
|
|
1979
1916
|
></sbb-secondary-button>`;
|
|
@@ -1985,14 +1922,27 @@ let SbbCalendarElement = (() => {
|
|
|
1985
1922
|
default: return nothing;
|
|
1986
1923
|
}
|
|
1987
1924
|
}
|
|
1925
|
+
_applyElementInternalsAriaLabel(el, label) {
|
|
1926
|
+
if (!el) return;
|
|
1927
|
+
const internals = el["internals"];
|
|
1928
|
+
if (internals) internals.ariaLabel = label;
|
|
1929
|
+
}
|
|
1930
|
+
/** Hidden descriptions referenced by the header cells via aria-describedby. */
|
|
1931
|
+
_navigationHints() {
|
|
1932
|
+
const hint = (id, cells) => html`<span id=${id} class="sbb-screen-reader-only" aria-hidden="true">
|
|
1933
|
+
${i18nCalendarHeaderNavigationHint(cells, this.orientation)[this._language.current]}
|
|
1934
|
+
</span>`;
|
|
1935
|
+
return html`${hint(WEEKDAY_HINT_ID, "weekdays")}
|
|
1936
|
+
${this.weekNumbers ? hint(WEEK_NUMBER_HINT_ID, "weekNumbers") : nothing}`;
|
|
1937
|
+
}
|
|
1988
1938
|
render() {
|
|
1989
1939
|
if (isServer || this.hydrationRequired) return html`${nothing}`;
|
|
1990
1940
|
return html`<div class="sbb-calendar__wrapper">
|
|
1991
|
-
${this.
|
|
1992
|
-
${this._getView()}
|
|
1941
|
+
${this._weeks.map((weeks, i) => this._createDayTable(weeks, this._weekNumbers[i], i === 0))}
|
|
1942
|
+
${this._getView()} ${this.multiple ? this._navigationHints() : nothing}
|
|
1993
1943
|
</div>`;
|
|
1994
1944
|
}
|
|
1995
1945
|
};
|
|
1996
1946
|
})();
|
|
1997
1947
|
|
|
1998
|
-
export { SbbCalendarCellBaseElement, SbbCalendarDayElement, SbbCalendarElement, SbbCalendarMonthElement, SbbCalendarWeekdayElement, SbbCalendarWeeknumberElement, SbbCalendarYearElement, SbbDateSelectedEvent, SbbMonthChangeEvent };
|
|
1948
|
+
export { SbbCalendarCellBaseElement, SbbCalendarDayElement, SbbCalendarElement, SbbCalendarMonthElement, SbbCalendarSelectAllElement, SbbCalendarWeekdayElement, SbbCalendarWeeknumberElement, SbbCalendarYearElement, SbbDateSelectedEvent, SbbMonthChangeEvent };
|