@sebgroup/green-core 1.3.0 → 1.4.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/components/datepicker/date-part-spinner.d.ts +21 -0
- package/components/datepicker/datepicker.d.ts +80 -0
- package/components/datepicker/datepicker.styles.d.ts +1 -0
- package/components/datepicker/datepicker.trans.styles.d.ts +2 -0
- package/components/form-control.d.ts +6 -1
- package/components/index.d.ts +1 -0
- package/generated/locales/sv.d.ts +26 -0
- package/index.js +921 -37
- package/localization.js +27 -1
- package/package.json +2 -2
- package/primitives/calendar/calendar.d.ts +53 -0
- package/primitives/calendar/calendar.styles.d.ts +2 -0
- package/primitives/calendar/calendar.trans.styles.d.ts +2 -0
- package/primitives/calendar/functions.d.ts +5 -0
- package/primitives/listbox/option.d.ts +1 -1
- package/primitives/popover/popover.d.ts +5 -0
- package/transitional-styles.js +423 -2
- package/utils/testing/index.d.ts +9 -0
package/index.js
CHANGED
|
@@ -9,9 +9,9 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
9
|
__defProp(target, key, result);
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
|
-
var __accessCheck = (obj, member,
|
|
12
|
+
var __accessCheck = (obj, member, msg6) => {
|
|
13
13
|
if (!member.has(obj))
|
|
14
|
-
throw TypeError("Cannot " +
|
|
14
|
+
throw TypeError("Cannot " + msg6);
|
|
15
15
|
};
|
|
16
16
|
var __privateGet = (obj, member, getter) => {
|
|
17
17
|
__accessCheck(obj, member, "read from private field");
|
|
@@ -76,8 +76,8 @@ function watch(propertyName, options) {
|
|
|
76
76
|
const { update } = proto;
|
|
77
77
|
const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
|
|
78
78
|
proto.update = function(changedProps) {
|
|
79
|
-
watchedProperties.forEach((
|
|
80
|
-
const key =
|
|
79
|
+
watchedProperties.forEach((property10) => {
|
|
80
|
+
const key = property10;
|
|
81
81
|
if (changedProps.has(key)) {
|
|
82
82
|
const oldValue = changedProps.get(key);
|
|
83
83
|
const newValue = this[key];
|
|
@@ -139,7 +139,7 @@ function watchMediaQuery(q) {
|
|
|
139
139
|
// libs/core/src/utils/helpers/custom-element-scoping.ts
|
|
140
140
|
import { html as litHtml } from "lit";
|
|
141
141
|
import { customElement } from "lit/decorators.js";
|
|
142
|
-
var VER_SUFFIX = "-
|
|
142
|
+
var VER_SUFFIX = "-98c004";
|
|
143
143
|
var elementLookupTable = /* @__PURE__ */ new Map();
|
|
144
144
|
var gdsCustomElement = (tagName) => {
|
|
145
145
|
if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
|
|
@@ -200,6 +200,7 @@ var TransitionalStyles = class _TransitionalStyles {
|
|
|
200
200
|
static get instance() {
|
|
201
201
|
if (!globalThis.__gdsTransitionalStyles?.[VER_SUFFIX])
|
|
202
202
|
globalThis.__gdsTransitionalStyles = {
|
|
203
|
+
...globalThis.__gdsTransitionalStyles,
|
|
203
204
|
[VER_SUFFIX]: new _TransitionalStyles()
|
|
204
205
|
};
|
|
205
206
|
return globalThis.__gdsTransitionalStyles[VER_SUFFIX];
|
|
@@ -217,9 +218,9 @@ var TransitionalStyles = class _TransitionalStyles {
|
|
|
217
218
|
return;
|
|
218
219
|
element.shadowRoot.adoptedStyleSheets = [sheet];
|
|
219
220
|
}
|
|
220
|
-
register(name,
|
|
221
|
+
register(name, styles2) {
|
|
221
222
|
const sheet = new CSSStyleSheet();
|
|
222
|
-
sheet.replaceSync(
|
|
223
|
+
sheet.replaceSync(styles2);
|
|
223
224
|
this.sheets.set(name, sheet);
|
|
224
225
|
this.applyToElement(name, sheet);
|
|
225
226
|
}
|
|
@@ -468,13 +469,6 @@ var Focusable = (superClass) => {
|
|
|
468
469
|
focus(options) {
|
|
469
470
|
this.setAttribute("tabindex", "0");
|
|
470
471
|
super.focus(options);
|
|
471
|
-
if (document.activeElement !== this) {
|
|
472
|
-
const iv = setInterval(() => {
|
|
473
|
-
if (document.activeElement === this)
|
|
474
|
-
clearInterval(iv);
|
|
475
|
-
super.focus(options);
|
|
476
|
-
}, 10);
|
|
477
|
-
}
|
|
478
472
|
}
|
|
479
473
|
}
|
|
480
474
|
return HighlightableElement;
|
|
@@ -494,7 +488,7 @@ var GdsOption = class extends Focusable(LitElement2) {
|
|
|
494
488
|
if (e.key !== "Enter" && e.key !== " ")
|
|
495
489
|
return;
|
|
496
490
|
e.preventDefault();
|
|
497
|
-
__privateMethod(this, _emitSelect, emitSelect_fn).call(this);
|
|
491
|
+
__privateMethod(this, _emitSelect, emitSelect_fn).call(this, e);
|
|
498
492
|
});
|
|
499
493
|
}
|
|
500
494
|
get hidden() {
|
|
@@ -520,7 +514,7 @@ var GdsOption = class extends Focusable(LitElement2) {
|
|
|
520
514
|
get parentElement() {
|
|
521
515
|
return super.parentElement;
|
|
522
516
|
}
|
|
523
|
-
|
|
517
|
+
_handlePlaceholderStatusChange() {
|
|
524
518
|
if (this.isPlaceholder) {
|
|
525
519
|
__privateSet(this, _hidden, true);
|
|
526
520
|
this.setAttribute("aria-hidden", "true");
|
|
@@ -545,7 +539,8 @@ var GdsOption = class extends Focusable(LitElement2) {
|
|
|
545
539
|
};
|
|
546
540
|
_hidden = new WeakMap();
|
|
547
541
|
_emitSelect = new WeakSet();
|
|
548
|
-
emitSelect_fn = function() {
|
|
542
|
+
emitSelect_fn = function(e) {
|
|
543
|
+
e.stopPropagation();
|
|
549
544
|
this.dispatchEvent(
|
|
550
545
|
new CustomEvent("gds-select", {
|
|
551
546
|
bubbles: true,
|
|
@@ -577,7 +572,7 @@ __decorateClass([
|
|
|
577
572
|
], GdsOption.prototype, "isPlaceholder", 2);
|
|
578
573
|
__decorateClass([
|
|
579
574
|
watch("isplaceholder")
|
|
580
|
-
], GdsOption.prototype, "
|
|
575
|
+
], GdsOption.prototype, "_handlePlaceholderStatusChange", 1);
|
|
581
576
|
GdsOption = __decorateClass([
|
|
582
577
|
gdsCustomElement("gds-option")
|
|
583
578
|
], GdsOption);
|
|
@@ -696,8 +691,8 @@ function isContainingBlock(element) {
|
|
|
696
691
|
if (element.tagName === "dialog") {
|
|
697
692
|
return true;
|
|
698
693
|
}
|
|
699
|
-
const
|
|
700
|
-
return
|
|
694
|
+
const css7 = getComputedStyle(element);
|
|
695
|
+
return css7.transform !== "none" || css7.perspective !== "none" || css7.contain === "paint" || ["transform", "perspective"].includes(css7.willChange) || isFirefox && css7.willChange === "filter" || isFirefox && (css7.filter ? css7.filter !== "none" : false);
|
|
701
696
|
}
|
|
702
697
|
function getUAString() {
|
|
703
698
|
const uaData = navigator.userAgentData;
|
|
@@ -774,7 +769,7 @@ var style3 = css3`
|
|
|
774
769
|
var popover_styles_default = style3;
|
|
775
770
|
|
|
776
771
|
// libs/core/src/primitives/popover/popover.ts
|
|
777
|
-
var _dialogElementRef, _autoPositionCleanupFn, _isMobileViewport, _handleCloseButton, _registerTriggerEvents, registerTriggerEvents_fn, _unregisterTriggerEvents, unregisterTriggerEvents_fn, _registerAutoPositioning, registerAutoPositioning_fn, _triggerKeyDownListener, _focusFirstSlottedChild, _clickOutsideListener;
|
|
772
|
+
var _dialogElementRef, _autoPositionCleanupFn, _isMobileViewport, _dispatchUiStateEvent, _handleCloseButton, _registerTriggerEvents, registerTriggerEvents_fn, _unregisterTriggerEvents, unregisterTriggerEvents_fn, _registerAutoPositioning, registerAutoPositioning_fn, _triggerKeyDownListener, _focusFirstSlottedChild, _clickOutsideListener;
|
|
778
773
|
var GdsPopover = class extends LitElement3 {
|
|
779
774
|
constructor() {
|
|
780
775
|
super(...arguments);
|
|
@@ -785,6 +780,7 @@ var GdsPopover = class extends LitElement3 {
|
|
|
785
780
|
this.triggerRef = Promise.resolve(void 0);
|
|
786
781
|
this.label = void 0;
|
|
787
782
|
this.placement = "bottom-start";
|
|
783
|
+
this.calcMinWidth = (referenceEl) => `${referenceEl.offsetWidth}px`;
|
|
788
784
|
this.calcMaxWidth = (_referenceEl) => `auto`;
|
|
789
785
|
this._trigger = void 0;
|
|
790
786
|
this._isVirtKbVisible = false;
|
|
@@ -793,10 +789,20 @@ var GdsPopover = class extends LitElement3 {
|
|
|
793
789
|
// A function that removes the Floating UI auto positioning. This gets called when we switch to mobile view layout.
|
|
794
790
|
__privateAdd(this, _autoPositionCleanupFn, void 0);
|
|
795
791
|
__privateAdd(this, _isMobileViewport, false);
|
|
792
|
+
__privateAdd(this, _dispatchUiStateEvent, () => {
|
|
793
|
+
this.dispatchEvent(
|
|
794
|
+
new CustomEvent("gds-ui-state", {
|
|
795
|
+
detail: { open: this.open },
|
|
796
|
+
bubbles: false,
|
|
797
|
+
composed: false
|
|
798
|
+
})
|
|
799
|
+
);
|
|
800
|
+
});
|
|
796
801
|
__privateAdd(this, _handleCloseButton, (e) => {
|
|
797
802
|
e.stopPropagation();
|
|
798
803
|
e.preventDefault();
|
|
799
804
|
this.open = false;
|
|
805
|
+
__privateGet(this, _dispatchUiStateEvent).call(this);
|
|
800
806
|
setTimeout(() => this._trigger?.focus(), 250);
|
|
801
807
|
});
|
|
802
808
|
/**
|
|
@@ -806,9 +812,11 @@ var GdsPopover = class extends LitElement3 {
|
|
|
806
812
|
if (e.key === "ArrowDown") {
|
|
807
813
|
e.preventDefault();
|
|
808
814
|
this.open = true;
|
|
815
|
+
__privateGet(this, _dispatchUiStateEvent).call(this);
|
|
809
816
|
}
|
|
810
817
|
if (e.key === "Escape") {
|
|
811
818
|
this.open = false;
|
|
819
|
+
__privateGet(this, _dispatchUiStateEvent).call(this);
|
|
812
820
|
}
|
|
813
821
|
});
|
|
814
822
|
/**
|
|
@@ -820,13 +828,17 @@ var GdsPopover = class extends LitElement3 {
|
|
|
820
828
|
firstSlottedChild?.focus();
|
|
821
829
|
});
|
|
822
830
|
});
|
|
823
|
-
__privateAdd(this, _clickOutsideListener, (
|
|
831
|
+
__privateAdd(this, _clickOutsideListener, (evt) => {
|
|
832
|
+
const e = evt;
|
|
824
833
|
const dialog = __privateGet(this, _dialogElementRef).value;
|
|
825
|
-
|
|
834
|
+
const isNotEnterKey = e.clientX > 0 || e.clientY > 0;
|
|
835
|
+
if (isNotEnterKey && dialog && this.open) {
|
|
826
836
|
const rect = dialog.getBoundingClientRect();
|
|
827
837
|
const isInDialog = rect.top <= e.clientY && e.clientY <= rect.top + rect.height && rect.left <= e.clientX && e.clientX <= rect.left + rect.width;
|
|
828
838
|
if (!isInDialog) {
|
|
839
|
+
e.stopPropagation();
|
|
829
840
|
this.open = false;
|
|
841
|
+
__privateGet(this, _dispatchUiStateEvent).call(this);
|
|
830
842
|
}
|
|
831
843
|
}
|
|
832
844
|
});
|
|
@@ -849,7 +861,9 @@ var GdsPopover = class extends LitElement3 {
|
|
|
849
861
|
this.addEventListener("keydown", (e) => {
|
|
850
862
|
if (e.key === "Escape") {
|
|
851
863
|
this.open = false;
|
|
852
|
-
|
|
864
|
+
__privateGet(this, _dispatchUiStateEvent).call(this);
|
|
865
|
+
e.stopPropagation();
|
|
866
|
+
e.preventDefault();
|
|
853
867
|
}
|
|
854
868
|
});
|
|
855
869
|
this.addEventListener("focusin", (e) => {
|
|
@@ -908,13 +922,6 @@ var GdsPopover = class extends LitElement3 {
|
|
|
908
922
|
);
|
|
909
923
|
}
|
|
910
924
|
});
|
|
911
|
-
this.dispatchEvent(
|
|
912
|
-
new CustomEvent("gds-ui-state", {
|
|
913
|
-
detail: { open: this.open },
|
|
914
|
-
bubbles: true,
|
|
915
|
-
composed: false
|
|
916
|
-
})
|
|
917
|
-
);
|
|
918
925
|
}
|
|
919
926
|
_handleMobileLayout(matches) {
|
|
920
927
|
var _a;
|
|
@@ -938,6 +945,7 @@ var GdsPopover = class extends LitElement3 {
|
|
|
938
945
|
_dialogElementRef = new WeakMap();
|
|
939
946
|
_autoPositionCleanupFn = new WeakMap();
|
|
940
947
|
_isMobileViewport = new WeakMap();
|
|
948
|
+
_dispatchUiStateEvent = new WeakMap();
|
|
941
949
|
_handleCloseButton = new WeakMap();
|
|
942
950
|
_registerTriggerEvents = new WeakSet();
|
|
943
951
|
registerTriggerEvents_fn = function() {
|
|
@@ -967,8 +975,8 @@ registerAutoPositioning_fn = function() {
|
|
|
967
975
|
({ x, y }) => Object.assign(floatingEl.style, {
|
|
968
976
|
left: `${x}px`,
|
|
969
977
|
top: `${y}px`,
|
|
970
|
-
minWidth:
|
|
971
|
-
maxWidth:
|
|
978
|
+
minWidth: this.calcMinWidth(referenceEl),
|
|
979
|
+
maxWidth: this.calcMaxWidth(referenceEl)
|
|
972
980
|
})
|
|
973
981
|
);
|
|
974
982
|
}));
|
|
@@ -989,6 +997,9 @@ __decorateClass([
|
|
|
989
997
|
__decorateClass([
|
|
990
998
|
property3()
|
|
991
999
|
], GdsPopover.prototype, "placement", 2);
|
|
1000
|
+
__decorateClass([
|
|
1001
|
+
property3()
|
|
1002
|
+
], GdsPopover.prototype, "calcMinWidth", 2);
|
|
992
1003
|
__decorateClass([
|
|
993
1004
|
property3()
|
|
994
1005
|
], GdsPopover.prototype, "calcMaxWidth", 2);
|
|
@@ -1024,8 +1035,9 @@ var GdsFormControlElement = class extends LitElement4 {
|
|
|
1024
1035
|
this.name = "";
|
|
1025
1036
|
/**
|
|
1026
1037
|
* Event handler for the form reset event.
|
|
1038
|
+
* Can be overridden by subclasses to rcustomize the reset value.
|
|
1027
1039
|
*/
|
|
1028
|
-
this
|
|
1040
|
+
this._handleFormReset = () => {
|
|
1029
1041
|
this.value = void 0;
|
|
1030
1042
|
};
|
|
1031
1043
|
this.#internals = this.attachInternals();
|
|
@@ -1057,11 +1069,11 @@ var GdsFormControlElement = class extends LitElement4 {
|
|
|
1057
1069
|
}
|
|
1058
1070
|
connectedCallback() {
|
|
1059
1071
|
super.connectedCallback();
|
|
1060
|
-
this.#internals.form?.addEventListener("reset", this
|
|
1072
|
+
this.#internals.form?.addEventListener("reset", this._handleFormReset);
|
|
1061
1073
|
}
|
|
1062
1074
|
disconnectedCallback() {
|
|
1063
1075
|
super.disconnectedCallback();
|
|
1064
|
-
this.#internals.form?.removeEventListener("reset", this
|
|
1076
|
+
this.#internals.form?.removeEventListener("reset", this._handleFormReset);
|
|
1065
1077
|
}
|
|
1066
1078
|
__handleValidityChange() {
|
|
1067
1079
|
this.#internals.setValidity(
|
|
@@ -1083,7 +1095,6 @@ var GdsFormControlElement = class extends LitElement4 {
|
|
|
1083
1095
|
__handleValueChange() {
|
|
1084
1096
|
this.#internals.setFormValue(this.value);
|
|
1085
1097
|
}
|
|
1086
|
-
#handleFormReset;
|
|
1087
1098
|
};
|
|
1088
1099
|
__decorateClass([
|
|
1089
1100
|
property4({
|
|
@@ -1601,8 +1612,881 @@ _handleOnClick = new WeakMap();
|
|
|
1601
1612
|
GdsMenuItem = __decorateClass([
|
|
1602
1613
|
gdsCustomElement("gds-menu-item")
|
|
1603
1614
|
], GdsMenuItem);
|
|
1615
|
+
|
|
1616
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
1617
|
+
import { property as property9, queryAll, queryAsync as queryAsync3, state as state3 } from "lit/decorators.js";
|
|
1618
|
+
import { join } from "lit/directives/join.js";
|
|
1619
|
+
import { when as when4 } from "lit/directives/when.js";
|
|
1620
|
+
import { until } from "lit/directives/until.js";
|
|
1621
|
+
import { map } from "lit/directives/map.js";
|
|
1622
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
1623
|
+
import { msg as msg5 } from "@lit/localize";
|
|
1624
|
+
import { eachYearOfInterval } from "date-fns";
|
|
1625
|
+
|
|
1626
|
+
// libs/core/src/primitives/calendar/calendar.ts
|
|
1627
|
+
import { LitElement as LitElement8, html as html5 } from "lit";
|
|
1628
|
+
import { classMap as classMap4 } from "lit/directives/class-map.js";
|
|
1629
|
+
import { when as when3 } from "lit/directives/when.js";
|
|
1630
|
+
import { property as property7, query as query2 } from "lit/decorators.js";
|
|
1631
|
+
import { msg as msg4 } from "@lit/localize";
|
|
1632
|
+
import {
|
|
1633
|
+
addDays as addDays2,
|
|
1634
|
+
isSameDay,
|
|
1635
|
+
isSameMonth,
|
|
1636
|
+
getWeek,
|
|
1637
|
+
subMonths,
|
|
1638
|
+
addMonths
|
|
1639
|
+
} from "date-fns";
|
|
1640
|
+
|
|
1641
|
+
// libs/core/src/primitives/calendar/functions.ts
|
|
1642
|
+
import {
|
|
1643
|
+
startOfMonth,
|
|
1644
|
+
endOfMonth,
|
|
1645
|
+
addDays,
|
|
1646
|
+
eachWeekOfInterval,
|
|
1647
|
+
eachDayOfInterval
|
|
1648
|
+
} from "date-fns";
|
|
1649
|
+
import { html as html4 } from "lit-html";
|
|
1650
|
+
function renderMonthGridView(date, template) {
|
|
1651
|
+
const monthStart = startOfMonth(date);
|
|
1652
|
+
const monthEnd = endOfMonth(date);
|
|
1653
|
+
const weeks = eachWeekOfInterval(
|
|
1654
|
+
{ start: monthStart, end: monthEnd },
|
|
1655
|
+
{ weekStartsOn: 1 }
|
|
1656
|
+
);
|
|
1657
|
+
return html4`${template(
|
|
1658
|
+
weeks.map((weekStartDay) => ({
|
|
1659
|
+
days: eachDayOfInterval({
|
|
1660
|
+
start: weekStartDay,
|
|
1661
|
+
end: addDays(weekStartDay, 6)
|
|
1662
|
+
})
|
|
1663
|
+
}))
|
|
1664
|
+
)}`;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// libs/core/src/primitives/calendar/calendar.styles.ts
|
|
1668
|
+
import { css as css5 } from "lit";
|
|
1669
|
+
var style5 = css5`
|
|
1670
|
+
td.disabled {
|
|
1671
|
+
color: #999;
|
|
1672
|
+
cursor: default;
|
|
1673
|
+
}
|
|
1674
|
+
td.today {
|
|
1675
|
+
background-color: #eee;
|
|
1676
|
+
}
|
|
1677
|
+
`;
|
|
1678
|
+
var calendar_styles_default = style5;
|
|
1679
|
+
|
|
1680
|
+
// libs/core/src/primitives/calendar/calendar.ts
|
|
1681
|
+
var _setSelectedDate, setSelectedDate_fn, _handleKeyDown, handleKeyDown_fn;
|
|
1682
|
+
var GdsCalendar = class extends LitElement8 {
|
|
1683
|
+
constructor() {
|
|
1684
|
+
super(...arguments);
|
|
1685
|
+
__privateAdd(this, _setSelectedDate);
|
|
1686
|
+
__privateAdd(this, _handleKeyDown);
|
|
1687
|
+
this.value = /* @__PURE__ */ new Date();
|
|
1688
|
+
this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
|
|
1689
|
+
this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
|
|
1690
|
+
this.focusedDate = /* @__PURE__ */ new Date();
|
|
1691
|
+
this.showWeekNumbers = false;
|
|
1692
|
+
}
|
|
1693
|
+
get focusedMonth() {
|
|
1694
|
+
return this.focusedDate.getMonth();
|
|
1695
|
+
}
|
|
1696
|
+
set focusedMonth(month) {
|
|
1697
|
+
this.focusedDate = new Date(this.focusedDate.setMonth(month));
|
|
1698
|
+
}
|
|
1699
|
+
get focusedYear() {
|
|
1700
|
+
return this.focusedDate.getFullYear();
|
|
1701
|
+
}
|
|
1702
|
+
set focusedYear(year) {
|
|
1703
|
+
this.focusedDate = new Date(this.focusedDate.setFullYear(year));
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Returns the date cell element for the given day number.
|
|
1707
|
+
*/
|
|
1708
|
+
getDateCell(dayNumber) {
|
|
1709
|
+
return this.shadowRoot?.querySelector(`#dateCell-${dayNumber}`);
|
|
1710
|
+
}
|
|
1711
|
+
connectedCallback() {
|
|
1712
|
+
super.connectedCallback();
|
|
1713
|
+
TransitionalStyles.instance.apply(this, "gds-calendar");
|
|
1714
|
+
this.addEventListener("keydown", __privateMethod(this, _handleKeyDown, handleKeyDown_fn));
|
|
1715
|
+
}
|
|
1716
|
+
focus() {
|
|
1717
|
+
super.focus();
|
|
1718
|
+
this._elFocusedCell?.focus();
|
|
1719
|
+
}
|
|
1720
|
+
render() {
|
|
1721
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
1722
|
+
return html5`<table>
|
|
1723
|
+
<thead>
|
|
1724
|
+
<tr>
|
|
1725
|
+
${when3(this.showWeekNumbers, () => html5`<th></th>`)}
|
|
1726
|
+
<th>${msg4("Mon")}</th>
|
|
1727
|
+
<th>${msg4("Tue")}</th>
|
|
1728
|
+
<th>${msg4("Wed")}</th>
|
|
1729
|
+
<th>${msg4("Thu")}</th>
|
|
1730
|
+
<th>${msg4("Fri")}</th>
|
|
1731
|
+
<th>${msg4("Sat")}</th>
|
|
1732
|
+
<th>${msg4("Sun")}</th>
|
|
1733
|
+
</tr>
|
|
1734
|
+
</thead>
|
|
1735
|
+
<tbody>
|
|
1736
|
+
${renderMonthGridView(
|
|
1737
|
+
this.focusedDate,
|
|
1738
|
+
(weeks) => html5`
|
|
1739
|
+
${weeks.map(
|
|
1740
|
+
(week) => html5`
|
|
1741
|
+
<tr>
|
|
1742
|
+
${when3(
|
|
1743
|
+
this.showWeekNumbers,
|
|
1744
|
+
() => html5`<td class="week-number">
|
|
1745
|
+
${getWeek(week.days[0])}
|
|
1746
|
+
</td>`
|
|
1747
|
+
)}
|
|
1748
|
+
${week.days.map((day) => {
|
|
1749
|
+
const isDisabled = !isSameMonth(this.focusedDate, day) || day < this.min || day > this.max;
|
|
1750
|
+
return html5`
|
|
1751
|
+
<td
|
|
1752
|
+
class="${classMap4({
|
|
1753
|
+
disabled: isDisabled,
|
|
1754
|
+
today: isSameDay(currentDate, day)
|
|
1755
|
+
})}"
|
|
1756
|
+
?disabled=${isDisabled}
|
|
1757
|
+
tabindex="${isSameDay(this.focusedDate, day) ? 0 : -1}"
|
|
1758
|
+
aria-selected="${isSameDay(this.value, day)}"
|
|
1759
|
+
aria-label="${day.toDateString()}"
|
|
1760
|
+
@click=${() => isDisabled ? null : __privateMethod(this, _setSelectedDate, setSelectedDate_fn).call(this, day)}
|
|
1761
|
+
id="dateCell-${day.getDate()}"
|
|
1762
|
+
>
|
|
1763
|
+
${day.getDate()}
|
|
1764
|
+
</td>
|
|
1765
|
+
`;
|
|
1766
|
+
})}
|
|
1767
|
+
</tr>
|
|
1768
|
+
`
|
|
1769
|
+
)}
|
|
1770
|
+
`
|
|
1771
|
+
)}
|
|
1772
|
+
</tbody>
|
|
1773
|
+
</table>`;
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
_setSelectedDate = new WeakSet();
|
|
1777
|
+
setSelectedDate_fn = function(date) {
|
|
1778
|
+
this.value = date;
|
|
1779
|
+
this.dispatchEvent(
|
|
1780
|
+
new CustomEvent("change", {
|
|
1781
|
+
detail: date,
|
|
1782
|
+
bubbles: false,
|
|
1783
|
+
composed: false
|
|
1784
|
+
})
|
|
1785
|
+
);
|
|
1786
|
+
};
|
|
1787
|
+
_handleKeyDown = new WeakSet();
|
|
1788
|
+
handleKeyDown_fn = function(e) {
|
|
1789
|
+
let handled = false;
|
|
1790
|
+
let newFocusedDate = new Date(this.focusedDate);
|
|
1791
|
+
if (e.key === "ArrowLeft") {
|
|
1792
|
+
newFocusedDate = addDays2(this.focusedDate, -1);
|
|
1793
|
+
handled = true;
|
|
1794
|
+
} else if (e.key === "ArrowRight") {
|
|
1795
|
+
newFocusedDate = addDays2(this.focusedDate, 1);
|
|
1796
|
+
handled = true;
|
|
1797
|
+
} else if (e.key === "ArrowUp") {
|
|
1798
|
+
newFocusedDate = addDays2(this.focusedDate, -7);
|
|
1799
|
+
handled = true;
|
|
1800
|
+
} else if (e.key === "ArrowDown") {
|
|
1801
|
+
newFocusedDate = addDays2(this.focusedDate, 7);
|
|
1802
|
+
handled = true;
|
|
1803
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
1804
|
+
if (!this._elFocusedCell?.hasAttribute("disabled")) {
|
|
1805
|
+
__privateMethod(this, _setSelectedDate, setSelectedDate_fn).call(this, this.focusedDate);
|
|
1806
|
+
}
|
|
1807
|
+
handled = true;
|
|
1808
|
+
} else if (e.key === "Home") {
|
|
1809
|
+
newFocusedDate = new Date(this.focusedYear, this.focusedMonth, 1);
|
|
1810
|
+
handled = true;
|
|
1811
|
+
} else if (e.key === "End") {
|
|
1812
|
+
newFocusedDate = new Date(this.focusedYear, this.focusedMonth + 1, 0);
|
|
1813
|
+
handled = true;
|
|
1814
|
+
} else if (e.key === "PageUp") {
|
|
1815
|
+
newFocusedDate = subMonths(this.focusedDate, 1);
|
|
1816
|
+
handled = true;
|
|
1817
|
+
} else if (e.key === "PageDown") {
|
|
1818
|
+
newFocusedDate = addMonths(this.focusedDate, 1);
|
|
1819
|
+
handled = true;
|
|
1820
|
+
}
|
|
1821
|
+
if (newFocusedDate.getFullYear() >= this.min.getFullYear() && newFocusedDate.getFullYear() <= this.max.getFullYear()) {
|
|
1822
|
+
this.focusedDate = newFocusedDate;
|
|
1823
|
+
}
|
|
1824
|
+
if (handled) {
|
|
1825
|
+
e.preventDefault();
|
|
1826
|
+
e.stopPropagation();
|
|
1827
|
+
this.updateComplete.then(() => {
|
|
1828
|
+
this._elFocusedCell?.focus();
|
|
1829
|
+
this.dispatchEvent(
|
|
1830
|
+
new CustomEvent("gds-date-focused", {
|
|
1831
|
+
detail: this.focusedDate,
|
|
1832
|
+
bubbles: false,
|
|
1833
|
+
composed: false
|
|
1834
|
+
})
|
|
1835
|
+
);
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
GdsCalendar.styles = [calendar_styles_default];
|
|
1840
|
+
GdsCalendar.shadowRootOptions = {
|
|
1841
|
+
mode: "open",
|
|
1842
|
+
delegatesFocus: true
|
|
1843
|
+
};
|
|
1844
|
+
__decorateClass([
|
|
1845
|
+
property7()
|
|
1846
|
+
], GdsCalendar.prototype, "value", 2);
|
|
1847
|
+
__decorateClass([
|
|
1848
|
+
property7({ type: Date })
|
|
1849
|
+
], GdsCalendar.prototype, "min", 2);
|
|
1850
|
+
__decorateClass([
|
|
1851
|
+
property7({ type: Date })
|
|
1852
|
+
], GdsCalendar.prototype, "max", 2);
|
|
1853
|
+
__decorateClass([
|
|
1854
|
+
property7()
|
|
1855
|
+
], GdsCalendar.prototype, "focusedDate", 2);
|
|
1856
|
+
__decorateClass([
|
|
1857
|
+
property7({ type: Number })
|
|
1858
|
+
], GdsCalendar.prototype, "focusedMonth", 1);
|
|
1859
|
+
__decorateClass([
|
|
1860
|
+
property7({ type: Number })
|
|
1861
|
+
], GdsCalendar.prototype, "focusedYear", 1);
|
|
1862
|
+
__decorateClass([
|
|
1863
|
+
property7({ type: Boolean })
|
|
1864
|
+
], GdsCalendar.prototype, "showWeekNumbers", 2);
|
|
1865
|
+
__decorateClass([
|
|
1866
|
+
query2('td[tabindex="0"]')
|
|
1867
|
+
], GdsCalendar.prototype, "_elFocusedCell", 2);
|
|
1868
|
+
GdsCalendar = __decorateClass([
|
|
1869
|
+
gdsCustomElement("gds-calendar")
|
|
1870
|
+
], GdsCalendar);
|
|
1871
|
+
|
|
1872
|
+
// libs/core/src/components/datepicker/date-part-spinner.ts
|
|
1873
|
+
import { LitElement as LitElement9 } from "lit";
|
|
1874
|
+
import { property as property8, state as state2 } from "lit/decorators.js";
|
|
1875
|
+
var _inputBuffer, _increment, _decrement, _handleClick, _handleFocus, _handleBlur, _handleWheel, _handleKeyDown2, _focusNextSpinner, focusNextSpinner_fn, _dispatchChangeEvent, dispatchChangeEvent_fn, _formatNumber, formatNumber_fn, _clamp, clamp_fn, _clearInputBuffer, clearInputBuffer_fn;
|
|
1876
|
+
var GdsDatePartSpinner = class extends LitElement9 {
|
|
1877
|
+
constructor() {
|
|
1878
|
+
super(...arguments);
|
|
1879
|
+
__privateAdd(this, _focusNextSpinner);
|
|
1880
|
+
__privateAdd(this, _dispatchChangeEvent);
|
|
1881
|
+
__privateAdd(this, _formatNumber);
|
|
1882
|
+
__privateAdd(this, _clamp);
|
|
1883
|
+
__privateAdd(this, _clearInputBuffer);
|
|
1884
|
+
this.value = 0;
|
|
1885
|
+
this.length = 2;
|
|
1886
|
+
this.min = 0;
|
|
1887
|
+
this.max = Number.MAX_SAFE_INTEGER;
|
|
1888
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
1889
|
+
__privateAdd(this, _inputBuffer, "");
|
|
1890
|
+
__privateAdd(this, _increment, () => {
|
|
1891
|
+
let current = parseInt(this.value.toString());
|
|
1892
|
+
if (Number.isNaN(current))
|
|
1893
|
+
current = this.length === 2 ? this.min : (/* @__PURE__ */ new Date()).getFullYear() - 1;
|
|
1894
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, current + 1);
|
|
1895
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1896
|
+
});
|
|
1897
|
+
__privateAdd(this, _decrement, () => {
|
|
1898
|
+
let current = parseInt(this.value.toString());
|
|
1899
|
+
if (Number.isNaN(current))
|
|
1900
|
+
current = this.length === 2 ? this.max : (/* @__PURE__ */ new Date()).getFullYear() + 1;
|
|
1901
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, current - 1);
|
|
1902
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1903
|
+
});
|
|
1904
|
+
__privateAdd(this, _handleClick, (e) => {
|
|
1905
|
+
e.stopPropagation();
|
|
1906
|
+
e.preventDefault();
|
|
1907
|
+
this.focus();
|
|
1908
|
+
});
|
|
1909
|
+
__privateAdd(this, _handleFocus, () => {
|
|
1910
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
1911
|
+
});
|
|
1912
|
+
__privateAdd(this, _handleBlur, () => {
|
|
1913
|
+
if (__privateGet(this, _inputBuffer) === "")
|
|
1914
|
+
return;
|
|
1915
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
1916
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, parseInt(this.value.toString()));
|
|
1917
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1918
|
+
document.getSelection()?.removeAllRanges();
|
|
1919
|
+
});
|
|
1920
|
+
__privateAdd(this, _handleWheel, (e) => {
|
|
1921
|
+
e.stopPropagation();
|
|
1922
|
+
e.preventDefault();
|
|
1923
|
+
if (e.deltaY > 0) {
|
|
1924
|
+
__privateGet(this, _decrement).call(this);
|
|
1925
|
+
} else {
|
|
1926
|
+
__privateGet(this, _increment).call(this);
|
|
1927
|
+
}
|
|
1928
|
+
});
|
|
1929
|
+
__privateAdd(this, _handleKeyDown2, (e) => {
|
|
1930
|
+
let handled = false;
|
|
1931
|
+
if (e.key === "ArrowUp") {
|
|
1932
|
+
__privateGet(this, _increment).call(this);
|
|
1933
|
+
handled = true;
|
|
1934
|
+
} else if (e.key === "ArrowDown") {
|
|
1935
|
+
__privateGet(this, _decrement).call(this);
|
|
1936
|
+
handled = true;
|
|
1937
|
+
} else {
|
|
1938
|
+
const key = parseInt(e.key);
|
|
1939
|
+
if (!isNaN(key)) {
|
|
1940
|
+
__privateSet(this, _inputBuffer, __privateGet(this, _inputBuffer) + key.toString());
|
|
1941
|
+
this.value = parseInt(__privateGet(this, _inputBuffer));
|
|
1942
|
+
if (__privateGet(this, _inputBuffer).length == this.length) {
|
|
1943
|
+
__privateMethod(this, _focusNextSpinner, focusNextSpinner_fn).call(this);
|
|
1944
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1945
|
+
}
|
|
1946
|
+
handled = true;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
if (handled) {
|
|
1950
|
+
e.preventDefault();
|
|
1951
|
+
e.stopPropagation();
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
// No need for a shadow root here
|
|
1956
|
+
createRenderRoot() {
|
|
1957
|
+
return this;
|
|
1958
|
+
}
|
|
1959
|
+
connectedCallback() {
|
|
1960
|
+
super.connectedCallback();
|
|
1961
|
+
this.setAttribute("role", "spinbutton");
|
|
1962
|
+
this.setAttribute("tabindex", "0");
|
|
1963
|
+
this.addEventListener("wheel", __privateGet(this, _handleWheel));
|
|
1964
|
+
this.addEventListener("keydown", __privateGet(this, _handleKeyDown2));
|
|
1965
|
+
this.addEventListener("blur", __privateGet(this, _handleBlur));
|
|
1966
|
+
this.addEventListener("focus", __privateGet(this, _handleFocus));
|
|
1967
|
+
this.addEventListener("click", __privateGet(this, _handleClick));
|
|
1968
|
+
this.addEventListener("mousedown", __privateGet(this, _handleClick));
|
|
1969
|
+
}
|
|
1970
|
+
focus(options) {
|
|
1971
|
+
super.focus(options);
|
|
1972
|
+
__privateGet(this, _handleFocus).call(this);
|
|
1973
|
+
}
|
|
1974
|
+
render() {
|
|
1975
|
+
return html`${this.displayValue}`;
|
|
1976
|
+
}
|
|
1977
|
+
_refreshDisplayValue() {
|
|
1978
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
1979
|
+
this.setAttribute("aria-valuetext", this.value.toString());
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
_inputBuffer = new WeakMap();
|
|
1983
|
+
_increment = new WeakMap();
|
|
1984
|
+
_decrement = new WeakMap();
|
|
1985
|
+
_handleClick = new WeakMap();
|
|
1986
|
+
_handleFocus = new WeakMap();
|
|
1987
|
+
_handleBlur = new WeakMap();
|
|
1988
|
+
_handleWheel = new WeakMap();
|
|
1989
|
+
_handleKeyDown2 = new WeakMap();
|
|
1990
|
+
_focusNextSpinner = new WeakSet();
|
|
1991
|
+
focusNextSpinner_fn = function() {
|
|
1992
|
+
let nextSpinner = this.nextElementSibling;
|
|
1993
|
+
while (nextSpinner) {
|
|
1994
|
+
if (nextSpinner instanceof GdsDatePartSpinner) {
|
|
1995
|
+
nextSpinner.focus();
|
|
1996
|
+
break;
|
|
1997
|
+
}
|
|
1998
|
+
nextSpinner = nextSpinner.nextElementSibling;
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
_dispatchChangeEvent = new WeakSet();
|
|
2002
|
+
dispatchChangeEvent_fn = function() {
|
|
2003
|
+
this.dispatchEvent(
|
|
2004
|
+
new CustomEvent("change", {
|
|
2005
|
+
detail: { value: this.value.toString() }
|
|
2006
|
+
})
|
|
2007
|
+
);
|
|
2008
|
+
};
|
|
2009
|
+
_formatNumber = new WeakSet();
|
|
2010
|
+
formatNumber_fn = function(num, padZeros) {
|
|
2011
|
+
return String(num).padStart(padZeros, "0");
|
|
2012
|
+
};
|
|
2013
|
+
_clamp = new WeakSet();
|
|
2014
|
+
clamp_fn = function(value) {
|
|
2015
|
+
return Math.max(this.min, Math.min(this.max, value));
|
|
2016
|
+
};
|
|
2017
|
+
_clearInputBuffer = new WeakSet();
|
|
2018
|
+
clearInputBuffer_fn = function() {
|
|
2019
|
+
__privateSet(this, _inputBuffer, "");
|
|
2020
|
+
};
|
|
2021
|
+
GdsDatePartSpinner.formAssociated = true;
|
|
2022
|
+
__decorateClass([
|
|
2023
|
+
property8({ type: Number })
|
|
2024
|
+
], GdsDatePartSpinner.prototype, "value", 2);
|
|
2025
|
+
__decorateClass([
|
|
2026
|
+
property8({ type: Number })
|
|
2027
|
+
], GdsDatePartSpinner.prototype, "length", 2);
|
|
2028
|
+
__decorateClass([
|
|
2029
|
+
property8({ type: Number, attribute: "aria-valuemin" })
|
|
2030
|
+
], GdsDatePartSpinner.prototype, "min", 2);
|
|
2031
|
+
__decorateClass([
|
|
2032
|
+
property8({ type: Number, attribute: "aria-valuemax" })
|
|
2033
|
+
], GdsDatePartSpinner.prototype, "max", 2);
|
|
2034
|
+
__decorateClass([
|
|
2035
|
+
state2()
|
|
2036
|
+
], GdsDatePartSpinner.prototype, "displayValue", 2);
|
|
2037
|
+
__decorateClass([
|
|
2038
|
+
watch("value")
|
|
2039
|
+
], GdsDatePartSpinner.prototype, "_refreshDisplayValue", 1);
|
|
2040
|
+
GdsDatePartSpinner = __decorateClass([
|
|
2041
|
+
gdsCustomElement("gds-date-part-spinner")
|
|
2042
|
+
], GdsDatePartSpinner);
|
|
2043
|
+
|
|
2044
|
+
// libs/core/src/components/datepicker/datepicker.styles.ts
|
|
2045
|
+
import { css as css6 } from "lit";
|
|
2046
|
+
var styles = css6`
|
|
2047
|
+
label {
|
|
2048
|
+
display: block;
|
|
2049
|
+
}
|
|
2050
|
+
`;
|
|
2051
|
+
|
|
2052
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
2053
|
+
import { nothing } from "lit";
|
|
2054
|
+
var dateConverter = {
|
|
2055
|
+
fromAttribute(value) {
|
|
2056
|
+
return new Date(value);
|
|
2057
|
+
},
|
|
2058
|
+
toAttribute(value) {
|
|
2059
|
+
return value.toISOString();
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
var _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get;
|
|
2063
|
+
var GdsDatepicker = class extends GdsFormControlElement {
|
|
2064
|
+
constructor() {
|
|
2065
|
+
super(...arguments);
|
|
2066
|
+
__privateAdd(this, _renderBackToValidRangeButton);
|
|
2067
|
+
__privateAdd(this, _focusDate);
|
|
2068
|
+
__privateAdd(this, _getSpinnerLabel);
|
|
2069
|
+
__privateAdd(this, _getMinSpinnerValue);
|
|
2070
|
+
__privateAdd(this, _getMaxSpinnerValue);
|
|
2071
|
+
__privateAdd(this, _dispatchChangeEvent2);
|
|
2072
|
+
/**
|
|
2073
|
+
* Takes a dateformat string from the dateformat attribute and turnes it to a DateFormatLayout object used in rendering the template.
|
|
2074
|
+
*/
|
|
2075
|
+
__privateAdd(this, _parseDateFormat);
|
|
2076
|
+
/**
|
|
2077
|
+
* Returns an array of years between the min and max dates for use in the year dropdown.
|
|
2078
|
+
* If the value is set to a year outside the range, it will be added to the array until the value is changed.
|
|
2079
|
+
*/
|
|
2080
|
+
__privateAdd(this, _years);
|
|
2081
|
+
this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
|
|
2082
|
+
this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
|
|
2083
|
+
this.open = false;
|
|
2084
|
+
this.label = "";
|
|
2085
|
+
this.showWeekNumbers = false;
|
|
2086
|
+
this._focusedMonth = (/* @__PURE__ */ new Date()).getMonth();
|
|
2087
|
+
this._focusedYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
2088
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, "y-m-d");
|
|
2089
|
+
__privateAdd(this, _handleIncrementFocusedMonth, (_e) => {
|
|
2090
|
+
this._focusedMonth++;
|
|
2091
|
+
if (this._focusedMonth > 11) {
|
|
2092
|
+
this._focusedMonth = 0;
|
|
2093
|
+
this._focusedYear++;
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
2096
|
+
__privateAdd(this, _handleDecrementFocusedMonth, (_e) => {
|
|
2097
|
+
this._focusedMonth--;
|
|
2098
|
+
if (this._focusedMonth < 0) {
|
|
2099
|
+
this._focusedMonth = 11;
|
|
2100
|
+
this._focusedYear--;
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
__privateAdd(this, _handleFocusChange, async () => {
|
|
2104
|
+
this._focusedMonth = (await this._elCalendar).focusedMonth;
|
|
2105
|
+
this._focusedYear = (await this._elCalendar).focusedYear;
|
|
2106
|
+
this.requestUpdate();
|
|
2107
|
+
});
|
|
2108
|
+
__privateAdd(this, _handlePopoverStateChange, (e) => {
|
|
2109
|
+
if (e.target !== e.currentTarget)
|
|
2110
|
+
return;
|
|
2111
|
+
this.open = e.detail.open;
|
|
2112
|
+
});
|
|
2113
|
+
__privateAdd(this, _handleSpinnerKeydown, (e) => {
|
|
2114
|
+
const index = Array.from(this._elSpinners).findIndex(
|
|
2115
|
+
(spinner) => spinner === e.target
|
|
2116
|
+
);
|
|
2117
|
+
if (e.key === "ArrowRight") {
|
|
2118
|
+
const next = this._elSpinners[index + 1];
|
|
2119
|
+
if (next)
|
|
2120
|
+
next.focus();
|
|
2121
|
+
}
|
|
2122
|
+
if (e.key === "ArrowLeft") {
|
|
2123
|
+
const prev = this._elSpinners[index - 1];
|
|
2124
|
+
if (prev)
|
|
2125
|
+
prev.focus();
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
__privateAdd(this, _handleSpinnerChange, (val, name) => {
|
|
2129
|
+
__privateGet(this, _spinnerState)[name] = val;
|
|
2130
|
+
const newDate = /* @__PURE__ */ new Date();
|
|
2131
|
+
newDate.setFullYear(parseInt(__privateGet(this, _spinnerState).year));
|
|
2132
|
+
newDate.setMonth(parseInt(__privateGet(this, _spinnerState).month) - 1);
|
|
2133
|
+
newDate.setDate(parseInt(__privateGet(this, _spinnerState).day));
|
|
2134
|
+
if (newDate.toString() === "Invalid Date")
|
|
2135
|
+
return;
|
|
2136
|
+
this.value = newDate;
|
|
2137
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2138
|
+
});
|
|
2139
|
+
/**
|
|
2140
|
+
* The spinner state keeps track of the spinner values regardless of wheter a complete date has been enter yet.
|
|
2141
|
+
*/
|
|
2142
|
+
__privateAdd(this, _spinnerState, {
|
|
2143
|
+
year: "yyyy",
|
|
2144
|
+
month: "mm",
|
|
2145
|
+
day: "dd"
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
get dateformat() {
|
|
2149
|
+
return this._dateFormatLayout.layout.map((f) => f.token).join(this._dateFormatLayout.delimiter);
|
|
2150
|
+
}
|
|
2151
|
+
set dateformat(dateformat) {
|
|
2152
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, dateformat);
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Get the currently focused date in the calendar popover. If no date is focused, or the calendar popover
|
|
2156
|
+
* is closed, the value will be undefined.
|
|
2157
|
+
*/
|
|
2158
|
+
async getFocusedDate() {
|
|
2159
|
+
if (this.open)
|
|
2160
|
+
return this._elCalendar.then((el) => el.focusedDate);
|
|
2161
|
+
else
|
|
2162
|
+
return void 0;
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* A reference to a date cell element (<td>) inside the shadow root of the calendar primitive.
|
|
2166
|
+
* Inteded for use in integration tests.
|
|
2167
|
+
*/
|
|
2168
|
+
async test_getDateCell(dayNumber) {
|
|
2169
|
+
return this._elCalendar.then((el) => el.getDateCell(dayNumber));
|
|
2170
|
+
}
|
|
2171
|
+
connectedCallback() {
|
|
2172
|
+
super.connectedCallback();
|
|
2173
|
+
TransitionalStyles.instance.apply(this, "gds-datepicker");
|
|
2174
|
+
}
|
|
2175
|
+
render() {
|
|
2176
|
+
return html`
|
|
2177
|
+
<label for="spinner-0" id="label">${this.label}</label>
|
|
2178
|
+
|
|
2179
|
+
<div class="form-info"><slot name="sub-label"></slot></div>
|
|
2180
|
+
|
|
2181
|
+
<div class="field" id="trigger">
|
|
2182
|
+
<div class="input">
|
|
2183
|
+
${join(
|
|
2184
|
+
map(
|
|
2185
|
+
this._dateFormatLayout.layout,
|
|
2186
|
+
(f, i) => html`<gds-date-part-spinner
|
|
2187
|
+
id="spinner-${i}"
|
|
2188
|
+
.length=${f.token === "y" ? 4 : 2}
|
|
2189
|
+
.value=${__privateGet(this, _spinnerState)[f.name]}
|
|
2190
|
+
aria-valuemin=${__privateMethod(this, _getMinSpinnerValue, getMinSpinnerValue_fn).call(this, f.name)}
|
|
2191
|
+
aria-valuemax=${__privateMethod(this, _getMaxSpinnerValue, getMaxSpinnerValue_fn).call(this, f.name)}
|
|
2192
|
+
aria-label=${__privateMethod(this, _getSpinnerLabel, getSpinnerLabel_fn).call(this, f.name)}
|
|
2193
|
+
aria-describedby="label"
|
|
2194
|
+
@keydown=${__privateGet(this, _handleSpinnerKeydown)}
|
|
2195
|
+
@change=${(e) => __privateGet(this, _handleSpinnerChange).call(this, e.detail.value, f.name)}
|
|
2196
|
+
></gds-date-part-spinner>`
|
|
2197
|
+
),
|
|
2198
|
+
html`<span>${this._dateFormatLayout.delimiter}</span>`
|
|
2199
|
+
)}
|
|
2200
|
+
</div>
|
|
2201
|
+
<button
|
|
2202
|
+
id="calendar-button"
|
|
2203
|
+
aria-label="${msg5("Open calendar modal")}"
|
|
2204
|
+
aria-haspopup="menu"
|
|
2205
|
+
aria-expanded=${this.open}
|
|
2206
|
+
aria-controls="calendar-popover"
|
|
2207
|
+
aria-describedby="label"
|
|
2208
|
+
@click=${() => this.open = !this.open}
|
|
2209
|
+
>
|
|
2210
|
+
<svg
|
|
2211
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
2212
|
+
viewBox="0 0 448 512"
|
|
2213
|
+
style="width:100%;height:100%"
|
|
2214
|
+
>
|
|
2215
|
+
<path
|
|
2216
|
+
d="M152 64h144V24c0-13.25 10.7-24 24-24s24 10.75 24 24v40h40c35.3 0 64 28.65 64 64v320c0 35.3-28.7 64-64 64H64c-35.35 0-64-28.7-64-64V128c0-35.35 28.65-64 64-64h40V24c0-13.25 10.7-24 24-24s24 10.75 24 24v40zM48 248h80v-56H48v56zm0 48v64h80v-64H48zm128 0v64h96v-64h-96zm144 0v64h80v-64h-80zm80-104h-80v56h80v-56zm0 216h-80v56h64c8.8 0 16-7.2 16-16v-40zm-128 0h-96v56h96v-56zm-144 0H48v40c0 8.8 7.16 16 16 16h64v-56zm144-216h-96v56h96v-56z "
|
|
2217
|
+
/>
|
|
2218
|
+
</svg>
|
|
2219
|
+
</button>
|
|
2220
|
+
</div>
|
|
2221
|
+
|
|
2222
|
+
<div class="form-info"><slot name="message"></slot></div>
|
|
2223
|
+
|
|
2224
|
+
<gds-popover
|
|
2225
|
+
.triggerRef=${this._elTrigger}
|
|
2226
|
+
.open=${this.open}
|
|
2227
|
+
@gds-ui-state=${__privateGet(this, _handlePopoverStateChange)}
|
|
2228
|
+
id="calendar-popover"
|
|
2229
|
+
.placement=${"bottom-end"}
|
|
2230
|
+
.calcMinWidth=${() => "390px"}
|
|
2231
|
+
@focusin=${async (e) => {
|
|
2232
|
+
const isPopover = e.target?.id === "calendar-popover";
|
|
2233
|
+
if (!isPopover)
|
|
2234
|
+
return;
|
|
2235
|
+
this._elCalendar.then((cal) => cal.focus());
|
|
2236
|
+
}}
|
|
2237
|
+
>
|
|
2238
|
+
<div class="header">
|
|
2239
|
+
<button @click=${__privateGet(this, _handleDecrementFocusedMonth)}>
|
|
2240
|
+
<i class="icon prev"></i>
|
|
2241
|
+
</button>
|
|
2242
|
+
<gds-dropdown
|
|
2243
|
+
.value=${this._focusedMonth.toString()}
|
|
2244
|
+
@change=${(e) => this._focusedMonth = e.target?.value}
|
|
2245
|
+
aria-label="${msg5("Month")}"
|
|
2246
|
+
>
|
|
2247
|
+
<gds-option value="0">${msg5("January")}</gds-option>
|
|
2248
|
+
<gds-option value="1">${msg5("February")}</gds-option>
|
|
2249
|
+
<gds-option value="2">${msg5("March")}</gds-option>
|
|
2250
|
+
<gds-option value="3">${msg5("April")}</gds-option>
|
|
2251
|
+
<gds-option value="4">${msg5("May")}</gds-option>
|
|
2252
|
+
<gds-option value="5">${msg5("June")}</gds-option>
|
|
2253
|
+
<gds-option value="6">${msg5("July")}</gds-option>
|
|
2254
|
+
<gds-option value="7">${msg5("August")}</gds-option>
|
|
2255
|
+
<gds-option value="8">${msg5("September")}</gds-option>
|
|
2256
|
+
<gds-option value="9">${msg5("October")}</gds-option>
|
|
2257
|
+
<gds-option value="10">${msg5("November")}</gds-option>
|
|
2258
|
+
<gds-option value="11">${msg5("December")}</gds-option>
|
|
2259
|
+
</gds-dropdown>
|
|
2260
|
+
<gds-dropdown
|
|
2261
|
+
.value=${this._focusedYear.toString()}
|
|
2262
|
+
@change=${(e) => this._focusedYear = e.target?.value}
|
|
2263
|
+
aria-label="${msg5("Year")}"
|
|
2264
|
+
>
|
|
2265
|
+
${repeat(
|
|
2266
|
+
__privateGet(this, _years, years_get),
|
|
2267
|
+
(year) => year,
|
|
2268
|
+
(year) => html`<gds-option value=${year}>${year}</gds-option>`
|
|
2269
|
+
)}
|
|
2270
|
+
</gds-dropdown>
|
|
2271
|
+
<button @click=${__privateGet(this, _handleIncrementFocusedMonth)}>
|
|
2272
|
+
<i class="icon next"></i>
|
|
2273
|
+
</button>
|
|
2274
|
+
</div>
|
|
2275
|
+
|
|
2276
|
+
<gds-calendar
|
|
2277
|
+
id="calendar"
|
|
2278
|
+
@change=${(e) => {
|
|
2279
|
+
e.stopPropagation();
|
|
2280
|
+
this.value = e.detail;
|
|
2281
|
+
this.open = false;
|
|
2282
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2283
|
+
}}
|
|
2284
|
+
@gds-date-focused=${__privateGet(this, _handleFocusChange)}
|
|
2285
|
+
.focusedMonth=${this._focusedMonth}
|
|
2286
|
+
.focusedYear=${this._focusedYear}
|
|
2287
|
+
.value=${this.value}
|
|
2288
|
+
.min=${this.min}
|
|
2289
|
+
.max=${this.max}
|
|
2290
|
+
.showWeekNumbers=${this.showWeekNumbers}
|
|
2291
|
+
></gds-calendar>
|
|
2292
|
+
|
|
2293
|
+
<div class="footer">
|
|
2294
|
+
<button
|
|
2295
|
+
class="tertiary clear"
|
|
2296
|
+
@click=${() => {
|
|
2297
|
+
this.value = void 0;
|
|
2298
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2299
|
+
}}
|
|
2300
|
+
>
|
|
2301
|
+
${msg5("Clear")}
|
|
2302
|
+
</button>
|
|
2303
|
+
${until(__privateMethod(this, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn).call(this), nothing)}
|
|
2304
|
+
<button
|
|
2305
|
+
class="tertiary today"
|
|
2306
|
+
@click=${() => {
|
|
2307
|
+
this.value = /* @__PURE__ */ new Date();
|
|
2308
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2309
|
+
}}
|
|
2310
|
+
>
|
|
2311
|
+
${msg5("Today")}
|
|
2312
|
+
</button>
|
|
2313
|
+
</div>
|
|
2314
|
+
</gds-popover>
|
|
2315
|
+
`;
|
|
2316
|
+
}
|
|
2317
|
+
_handleValueChange() {
|
|
2318
|
+
if (!this.value) {
|
|
2319
|
+
__privateSet(this, _spinnerState, {
|
|
2320
|
+
year: "yyyy",
|
|
2321
|
+
month: "mm",
|
|
2322
|
+
day: "dd"
|
|
2323
|
+
});
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
const date = this.value;
|
|
2327
|
+
this._focusedMonth = date.getMonth();
|
|
2328
|
+
this._focusedYear = date.getFullYear();
|
|
2329
|
+
const year = date.getFullYear().toString();
|
|
2330
|
+
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
2331
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
2332
|
+
__privateSet(this, _spinnerState, { year, month, day });
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
_renderBackToValidRangeButton = new WeakSet();
|
|
2336
|
+
renderBackToValidRangeButton_fn = async function() {
|
|
2337
|
+
const focusedDate = await this.getFocusedDate();
|
|
2338
|
+
let buttonTxt = "";
|
|
2339
|
+
let buttonAction;
|
|
2340
|
+
if (focusedDate && focusedDate > this.max) {
|
|
2341
|
+
buttonTxt = msg5("Last available date");
|
|
2342
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.max);
|
|
2343
|
+
} else if (focusedDate && focusedDate < this.min) {
|
|
2344
|
+
buttonTxt = msg5("First available date");
|
|
2345
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.min);
|
|
2346
|
+
}
|
|
2347
|
+
return html`${when4(
|
|
2348
|
+
buttonTxt.length > 0,
|
|
2349
|
+
() => html`<button class="tertiary back-to-range" @click=${buttonAction}>
|
|
2350
|
+
${buttonTxt}
|
|
2351
|
+
</button>`,
|
|
2352
|
+
() => nothing
|
|
2353
|
+
)}`;
|
|
2354
|
+
};
|
|
2355
|
+
_focusDate = new WeakSet();
|
|
2356
|
+
focusDate_fn = function(d) {
|
|
2357
|
+
const firstValidDate = new Date(d);
|
|
2358
|
+
this._elCalendar.then((el) => el.focusedDate = firstValidDate).then(__privateGet(this, _handleFocusChange));
|
|
2359
|
+
};
|
|
2360
|
+
_getSpinnerLabel = new WeakSet();
|
|
2361
|
+
getSpinnerLabel_fn = function(name) {
|
|
2362
|
+
const labels = {
|
|
2363
|
+
year: msg5("Year"),
|
|
2364
|
+
month: msg5("Month"),
|
|
2365
|
+
day: msg5("Day")
|
|
2366
|
+
};
|
|
2367
|
+
return labels[name];
|
|
2368
|
+
};
|
|
2369
|
+
_getMinSpinnerValue = new WeakSet();
|
|
2370
|
+
getMinSpinnerValue_fn = function(name) {
|
|
2371
|
+
const min = {
|
|
2372
|
+
year: this.min.getFullYear(),
|
|
2373
|
+
month: 1,
|
|
2374
|
+
day: 1
|
|
2375
|
+
};
|
|
2376
|
+
return min[name];
|
|
2377
|
+
};
|
|
2378
|
+
_getMaxSpinnerValue = new WeakSet();
|
|
2379
|
+
getMaxSpinnerValue_fn = function(name) {
|
|
2380
|
+
const max = {
|
|
2381
|
+
year: this.max.getFullYear(),
|
|
2382
|
+
month: 12,
|
|
2383
|
+
day: 31
|
|
2384
|
+
};
|
|
2385
|
+
return max[name];
|
|
2386
|
+
};
|
|
2387
|
+
_dispatchChangeEvent2 = new WeakSet();
|
|
2388
|
+
dispatchChangeEvent_fn2 = function() {
|
|
2389
|
+
this.dispatchEvent(
|
|
2390
|
+
new CustomEvent("change", {
|
|
2391
|
+
detail: { value: this.value }
|
|
2392
|
+
})
|
|
2393
|
+
);
|
|
2394
|
+
};
|
|
2395
|
+
_handleIncrementFocusedMonth = new WeakMap();
|
|
2396
|
+
_handleDecrementFocusedMonth = new WeakMap();
|
|
2397
|
+
_handleFocusChange = new WeakMap();
|
|
2398
|
+
_handlePopoverStateChange = new WeakMap();
|
|
2399
|
+
_handleSpinnerKeydown = new WeakMap();
|
|
2400
|
+
_parseDateFormat = new WeakSet();
|
|
2401
|
+
parseDateFormat_fn = function(dateformat) {
|
|
2402
|
+
const delimiter = dateformat.replace(/[a-z0-9]/gi, "")[0];
|
|
2403
|
+
const format = dateformat.split(delimiter);
|
|
2404
|
+
const year = format.findIndex((f) => f === "y");
|
|
2405
|
+
const month = format.findIndex((f) => f === "m");
|
|
2406
|
+
const day = format.findIndex((f) => f === "d");
|
|
2407
|
+
if (year === -1 || month === -1 || day === -1)
|
|
2408
|
+
throw new Error("Invalid date format for <gds-datepicker>");
|
|
2409
|
+
const ordered = [year, month, day].sort((a, b) => a - b);
|
|
2410
|
+
const orderedFormat = ordered.map((i) => format[i]).map((f) => ({
|
|
2411
|
+
token: f,
|
|
2412
|
+
name: f === "y" ? "year" : f === "m" ? "month" : "day"
|
|
2413
|
+
}));
|
|
2414
|
+
return { delimiter, layout: orderedFormat };
|
|
2415
|
+
};
|
|
2416
|
+
_handleSpinnerChange = new WeakMap();
|
|
2417
|
+
_spinnerState = new WeakMap();
|
|
2418
|
+
_years = new WeakSet();
|
|
2419
|
+
years_get = function() {
|
|
2420
|
+
const years = eachYearOfInterval({
|
|
2421
|
+
start: this.min,
|
|
2422
|
+
end: this.max
|
|
2423
|
+
}).map((date) => date.getFullYear());
|
|
2424
|
+
if (!this.value)
|
|
2425
|
+
return years;
|
|
2426
|
+
const selectedYear = this.value.getFullYear();
|
|
2427
|
+
const valueIsInrage = years[0] <= selectedYear && years[years.length - 1] >= selectedYear;
|
|
2428
|
+
if (!valueIsInrage) {
|
|
2429
|
+
years.push(selectedYear);
|
|
2430
|
+
years.sort((a, b) => a - b);
|
|
2431
|
+
}
|
|
2432
|
+
return years;
|
|
2433
|
+
};
|
|
2434
|
+
GdsDatepicker.styles = [styles];
|
|
2435
|
+
GdsDatepicker.shadowRootOptions = {
|
|
2436
|
+
mode: "open",
|
|
2437
|
+
delegatesFocus: true
|
|
2438
|
+
};
|
|
2439
|
+
__decorateClass([
|
|
2440
|
+
property9({ converter: dateConverter })
|
|
2441
|
+
], GdsDatepicker.prototype, "value", 2);
|
|
2442
|
+
__decorateClass([
|
|
2443
|
+
property9({ converter: dateConverter })
|
|
2444
|
+
], GdsDatepicker.prototype, "min", 2);
|
|
2445
|
+
__decorateClass([
|
|
2446
|
+
property9({ converter: dateConverter })
|
|
2447
|
+
], GdsDatepicker.prototype, "max", 2);
|
|
2448
|
+
__decorateClass([
|
|
2449
|
+
property9({ type: Boolean })
|
|
2450
|
+
], GdsDatepicker.prototype, "open", 2);
|
|
2451
|
+
__decorateClass([
|
|
2452
|
+
property9()
|
|
2453
|
+
], GdsDatepicker.prototype, "label", 2);
|
|
2454
|
+
__decorateClass([
|
|
2455
|
+
property9({ type: Boolean })
|
|
2456
|
+
], GdsDatepicker.prototype, "showWeekNumbers", 2);
|
|
2457
|
+
__decorateClass([
|
|
2458
|
+
property9()
|
|
2459
|
+
], GdsDatepicker.prototype, "dateformat", 1);
|
|
2460
|
+
__decorateClass([
|
|
2461
|
+
queryAsync3("#calendar-button")
|
|
2462
|
+
], GdsDatepicker.prototype, "test_calendarButton", 2);
|
|
2463
|
+
__decorateClass([
|
|
2464
|
+
state3()
|
|
2465
|
+
], GdsDatepicker.prototype, "_focusedMonth", 2);
|
|
2466
|
+
__decorateClass([
|
|
2467
|
+
state3()
|
|
2468
|
+
], GdsDatepicker.prototype, "_focusedYear", 2);
|
|
2469
|
+
__decorateClass([
|
|
2470
|
+
state3()
|
|
2471
|
+
], GdsDatepicker.prototype, "_dateFormatLayout", 2);
|
|
2472
|
+
__decorateClass([
|
|
2473
|
+
queryAsync3("#calendar")
|
|
2474
|
+
], GdsDatepicker.prototype, "_elCalendar", 2);
|
|
2475
|
+
__decorateClass([
|
|
2476
|
+
queryAsync3("#trigger")
|
|
2477
|
+
], GdsDatepicker.prototype, "_elTrigger", 2);
|
|
2478
|
+
__decorateClass([
|
|
2479
|
+
queryAll(getScopedTagName("gds-date-part-spinner"))
|
|
2480
|
+
], GdsDatepicker.prototype, "_elSpinners", 2);
|
|
2481
|
+
__decorateClass([
|
|
2482
|
+
watch("value")
|
|
2483
|
+
], GdsDatepicker.prototype, "_handleValueChange", 1);
|
|
2484
|
+
GdsDatepicker = __decorateClass([
|
|
2485
|
+
gdsCustomElement("gds-datepicker")
|
|
2486
|
+
], GdsDatepicker);
|
|
1604
2487
|
export {
|
|
1605
2488
|
GdsContextMenu,
|
|
2489
|
+
GdsDatepicker,
|
|
1606
2490
|
GdsDropdown,
|
|
1607
2491
|
GdsMenuItem,
|
|
1608
2492
|
GdsOption,
|