@sebgroup/green-core 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +961 -72
- 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 +425 -4
- 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 = "-c7f30b";
|
|
143
143
|
var elementLookupTable = /* @__PURE__ */ new Map();
|
|
144
144
|
var gdsCustomElement = (tagName) => {
|
|
145
145
|
if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
|
|
@@ -192,7 +192,7 @@ import { property } from "lit/decorators.js";
|
|
|
192
192
|
import { createRef, ref } from "lit/directives/ref.js";
|
|
193
193
|
|
|
194
194
|
// libs/core/src/utils/helpers/transitional-styles.ts
|
|
195
|
-
var TransitionalStyles = class
|
|
195
|
+
var TransitionalStyles = class {
|
|
196
196
|
constructor() {
|
|
197
197
|
this.sheets = /* @__PURE__ */ new Map();
|
|
198
198
|
this.elements = /* @__PURE__ */ new Map();
|
|
@@ -200,7 +200,8 @@ var TransitionalStyles = class _TransitionalStyles {
|
|
|
200
200
|
static get instance() {
|
|
201
201
|
if (!globalThis.__gdsTransitionalStyles?.[VER_SUFFIX])
|
|
202
202
|
globalThis.__gdsTransitionalStyles = {
|
|
203
|
-
|
|
203
|
+
...globalThis.__gdsTransitionalStyles,
|
|
204
|
+
[VER_SUFFIX]: new TransitionalStyles()
|
|
204
205
|
};
|
|
205
206
|
return globalThis.__gdsTransitionalStyles[VER_SUFFIX];
|
|
206
207
|
}
|
|
@@ -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);
|
|
@@ -1017,54 +1028,53 @@ GdsPopover = __decorateClass([
|
|
|
1017
1028
|
// libs/core/src/components/form-control.ts
|
|
1018
1029
|
import { LitElement as LitElement4 } from "lit";
|
|
1019
1030
|
import { property as property4 } from "lit/decorators.js";
|
|
1031
|
+
var _internals;
|
|
1020
1032
|
var GdsFormControlElement = class extends LitElement4 {
|
|
1021
1033
|
constructor() {
|
|
1022
1034
|
super();
|
|
1035
|
+
__privateAdd(this, _internals, void 0);
|
|
1023
1036
|
this.invalid = false;
|
|
1024
1037
|
this.name = "";
|
|
1025
1038
|
/**
|
|
1026
1039
|
* Event handler for the form reset event.
|
|
1040
|
+
* Can be overridden by subclasses to rcustomize the reset value.
|
|
1027
1041
|
*/
|
|
1028
|
-
this
|
|
1042
|
+
this._handleFormReset = () => {
|
|
1029
1043
|
this.value = void 0;
|
|
1030
1044
|
};
|
|
1031
|
-
this
|
|
1032
|
-
}
|
|
1033
|
-
#internals;
|
|
1034
|
-
static {
|
|
1035
|
-
this.formAssociated = true;
|
|
1045
|
+
__privateSet(this, _internals, this.attachInternals());
|
|
1036
1046
|
}
|
|
1037
1047
|
get form() {
|
|
1038
|
-
return this
|
|
1048
|
+
return __privateGet(this, _internals).form;
|
|
1039
1049
|
}
|
|
1040
1050
|
get type() {
|
|
1041
1051
|
return getUnscopedTagName(this.localName) || "gds-form-control";
|
|
1042
1052
|
}
|
|
1043
1053
|
get validity() {
|
|
1044
|
-
return this
|
|
1054
|
+
return __privateGet(this, _internals).validity;
|
|
1045
1055
|
}
|
|
1046
1056
|
get validationMessage() {
|
|
1047
|
-
return this
|
|
1057
|
+
return __privateGet(this, _internals).validationMessage;
|
|
1048
1058
|
}
|
|
1049
1059
|
get willValidate() {
|
|
1050
|
-
return this
|
|
1060
|
+
return __privateGet(this, _internals).willValidate;
|
|
1051
1061
|
}
|
|
1052
1062
|
checkValidity() {
|
|
1053
|
-
return this
|
|
1063
|
+
return __privateGet(this, _internals).checkValidity();
|
|
1054
1064
|
}
|
|
1055
1065
|
reportValidity() {
|
|
1056
|
-
return this
|
|
1066
|
+
return __privateGet(this, _internals).reportValidity();
|
|
1057
1067
|
}
|
|
1058
1068
|
connectedCallback() {
|
|
1059
1069
|
super.connectedCallback();
|
|
1060
|
-
this
|
|
1070
|
+
__privateGet(this, _internals).form?.addEventListener("reset", this._handleFormReset);
|
|
1061
1071
|
}
|
|
1062
1072
|
disconnectedCallback() {
|
|
1063
1073
|
super.disconnectedCallback();
|
|
1064
|
-
this
|
|
1074
|
+
__privateGet(this, _internals).form?.removeEventListener("reset", this._handleFormReset);
|
|
1065
1075
|
}
|
|
1066
1076
|
__handleValidityChange() {
|
|
1067
|
-
this
|
|
1077
|
+
__privateGet(this, _internals).setValidity(
|
|
1068
1078
|
{
|
|
1069
1079
|
badInput: false,
|
|
1070
1080
|
customError: this.invalid,
|
|
@@ -1081,10 +1091,11 @@ var GdsFormControlElement = class extends LitElement4 {
|
|
|
1081
1091
|
);
|
|
1082
1092
|
}
|
|
1083
1093
|
__handleValueChange() {
|
|
1084
|
-
this
|
|
1094
|
+
__privateGet(this, _internals).setFormValue(this.value);
|
|
1085
1095
|
}
|
|
1086
|
-
#handleFormReset;
|
|
1087
1096
|
};
|
|
1097
|
+
_internals = new WeakMap();
|
|
1098
|
+
GdsFormControlElement.formAssociated = true;
|
|
1088
1099
|
__decorateClass([
|
|
1089
1100
|
property4({
|
|
1090
1101
|
type: Boolean,
|
|
@@ -1451,11 +1462,10 @@ import { property as property6, queryAsync as queryAsync2 } from "lit/decorators
|
|
|
1451
1462
|
// libs/core/src/primitives/menu/menu.ts
|
|
1452
1463
|
import { LitElement as LitElement5 } from "lit";
|
|
1453
1464
|
import { createRef as createRef3, ref as ref3 } from "lit/directives/ref.js";
|
|
1454
|
-
var _slotRef2;
|
|
1455
1465
|
var GdsMenu = class extends LitElement5 {
|
|
1466
|
+
#slotRef = createRef3();
|
|
1456
1467
|
constructor() {
|
|
1457
1468
|
super();
|
|
1458
|
-
__privateAdd(this, _slotRef2, createRef3());
|
|
1459
1469
|
new ListboxKbNavController(this);
|
|
1460
1470
|
}
|
|
1461
1471
|
connectedCallback() {
|
|
@@ -1464,9 +1474,9 @@ var GdsMenu = class extends LitElement5 {
|
|
|
1464
1474
|
TransitionalStyles.instance.apply(this, "gds-listbox");
|
|
1465
1475
|
}
|
|
1466
1476
|
get navigableItems() {
|
|
1467
|
-
if (!
|
|
1477
|
+
if (!this.#slotRef.value)
|
|
1468
1478
|
return [];
|
|
1469
|
-
return unwrap(
|
|
1479
|
+
return unwrap(this.#slotRef.value).assignedElements().filter(
|
|
1470
1480
|
(o) => !o.hasAttribute("isplaceholder")
|
|
1471
1481
|
) || [];
|
|
1472
1482
|
}
|
|
@@ -1477,10 +1487,9 @@ var GdsMenu = class extends LitElement5 {
|
|
|
1477
1487
|
this.navigableItems[0]?.focus();
|
|
1478
1488
|
}
|
|
1479
1489
|
render() {
|
|
1480
|
-
return html`<slot ${ref3(
|
|
1490
|
+
return html`<slot ${ref3(this.#slotRef)}></slot>`;
|
|
1481
1491
|
}
|
|
1482
1492
|
};
|
|
1483
|
-
_slotRef2 = new WeakMap();
|
|
1484
1493
|
GdsMenu = __decorateClass([
|
|
1485
1494
|
gdsCustomElement("gds-menu")
|
|
1486
1495
|
], GdsMenu);
|
|
@@ -1568,19 +1577,7 @@ GdsContextMenu = __decorateClass([
|
|
|
1568
1577
|
|
|
1569
1578
|
// libs/core/src/primitives/menu/menu-item.ts
|
|
1570
1579
|
import { LitElement as LitElement7 } from "lit";
|
|
1571
|
-
var _handleOnClick;
|
|
1572
1580
|
var GdsMenuItem = class extends Focusable(LitElement7) {
|
|
1573
|
-
constructor() {
|
|
1574
|
-
super(...arguments);
|
|
1575
|
-
__privateAdd(this, _handleOnClick, () => {
|
|
1576
|
-
this.dispatchEvent(
|
|
1577
|
-
new CustomEvent("gds-menu-item-click", {
|
|
1578
|
-
bubbles: true,
|
|
1579
|
-
composed: true
|
|
1580
|
-
})
|
|
1581
|
-
);
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
1581
|
connectedCallback() {
|
|
1585
1582
|
super.connectedCallback();
|
|
1586
1583
|
this.setAttribute("role", "menuitem");
|
|
@@ -1590,19 +1587,911 @@ var GdsMenuItem = class extends Focusable(LitElement7) {
|
|
|
1590
1587
|
e.preventDefault();
|
|
1591
1588
|
this.click();
|
|
1592
1589
|
});
|
|
1593
|
-
this.addEventListener("click",
|
|
1590
|
+
this.addEventListener("click", this.#handleOnClick);
|
|
1594
1591
|
TransitionalStyles.instance.apply(this, "gds-option");
|
|
1595
1592
|
}
|
|
1593
|
+
#handleOnClick = () => {
|
|
1594
|
+
this.dispatchEvent(
|
|
1595
|
+
new CustomEvent("gds-menu-item-click", {
|
|
1596
|
+
bubbles: true,
|
|
1597
|
+
composed: true
|
|
1598
|
+
})
|
|
1599
|
+
);
|
|
1600
|
+
};
|
|
1596
1601
|
render() {
|
|
1597
1602
|
return html`<slot></slot>`;
|
|
1598
1603
|
}
|
|
1599
1604
|
};
|
|
1600
|
-
_handleOnClick = new WeakMap();
|
|
1601
1605
|
GdsMenuItem = __decorateClass([
|
|
1602
1606
|
gdsCustomElement("gds-menu-item")
|
|
1603
1607
|
], GdsMenuItem);
|
|
1608
|
+
|
|
1609
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
1610
|
+
import { property as property9, queryAll, queryAsync as queryAsync3, state as state3 } from "lit/decorators.js";
|
|
1611
|
+
import { join } from "lit/directives/join.js";
|
|
1612
|
+
import { when as when4 } from "lit/directives/when.js";
|
|
1613
|
+
import { until } from "lit/directives/until.js";
|
|
1614
|
+
import { map } from "lit/directives/map.js";
|
|
1615
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
1616
|
+
import { msg as msg5 } from "@lit/localize";
|
|
1617
|
+
import { eachYearOfInterval } from "date-fns";
|
|
1618
|
+
|
|
1619
|
+
// libs/core/src/primitives/calendar/calendar.ts
|
|
1620
|
+
import { LitElement as LitElement8, html as html5 } from "lit";
|
|
1621
|
+
import { classMap as classMap4 } from "lit/directives/class-map.js";
|
|
1622
|
+
import { when as when3 } from "lit/directives/when.js";
|
|
1623
|
+
import { property as property7, query as query2 } from "lit/decorators.js";
|
|
1624
|
+
import { msg as msg4 } from "@lit/localize";
|
|
1625
|
+
import {
|
|
1626
|
+
addDays as addDays2,
|
|
1627
|
+
isSameDay,
|
|
1628
|
+
isSameMonth,
|
|
1629
|
+
getWeek,
|
|
1630
|
+
subMonths,
|
|
1631
|
+
addMonths
|
|
1632
|
+
} from "date-fns";
|
|
1633
|
+
|
|
1634
|
+
// libs/core/src/primitives/calendar/functions.ts
|
|
1635
|
+
import {
|
|
1636
|
+
startOfMonth,
|
|
1637
|
+
endOfMonth,
|
|
1638
|
+
addDays,
|
|
1639
|
+
eachWeekOfInterval,
|
|
1640
|
+
eachDayOfInterval
|
|
1641
|
+
} from "date-fns";
|
|
1642
|
+
import { html as html4 } from "lit-html";
|
|
1643
|
+
function renderMonthGridView(date, template) {
|
|
1644
|
+
const monthStart = startOfMonth(date);
|
|
1645
|
+
const monthEnd = endOfMonth(date);
|
|
1646
|
+
const weeks = eachWeekOfInterval(
|
|
1647
|
+
{ start: monthStart, end: monthEnd },
|
|
1648
|
+
{ weekStartsOn: 1 }
|
|
1649
|
+
);
|
|
1650
|
+
return html4`${template(
|
|
1651
|
+
weeks.map((weekStartDay) => ({
|
|
1652
|
+
days: eachDayOfInterval({
|
|
1653
|
+
start: weekStartDay,
|
|
1654
|
+
end: addDays(weekStartDay, 6)
|
|
1655
|
+
})
|
|
1656
|
+
}))
|
|
1657
|
+
)}`;
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
// libs/core/src/primitives/calendar/calendar.styles.ts
|
|
1661
|
+
import { css as css5 } from "lit";
|
|
1662
|
+
var style5 = css5`
|
|
1663
|
+
td.disabled {
|
|
1664
|
+
color: #999;
|
|
1665
|
+
cursor: default;
|
|
1666
|
+
}
|
|
1667
|
+
td.today {
|
|
1668
|
+
background-color: #eee;
|
|
1669
|
+
}
|
|
1670
|
+
`;
|
|
1671
|
+
var calendar_styles_default = style5;
|
|
1672
|
+
|
|
1673
|
+
// libs/core/src/primitives/calendar/calendar.ts
|
|
1674
|
+
var _setSelectedDate, setSelectedDate_fn, _handleKeyDown, handleKeyDown_fn;
|
|
1675
|
+
var GdsCalendar = class extends LitElement8 {
|
|
1676
|
+
constructor() {
|
|
1677
|
+
super(...arguments);
|
|
1678
|
+
__privateAdd(this, _setSelectedDate);
|
|
1679
|
+
__privateAdd(this, _handleKeyDown);
|
|
1680
|
+
this.value = /* @__PURE__ */ new Date();
|
|
1681
|
+
this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
|
|
1682
|
+
this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
|
|
1683
|
+
this.focusedDate = /* @__PURE__ */ new Date();
|
|
1684
|
+
this.showWeekNumbers = false;
|
|
1685
|
+
}
|
|
1686
|
+
get focusedMonth() {
|
|
1687
|
+
return this.focusedDate.getMonth();
|
|
1688
|
+
}
|
|
1689
|
+
set focusedMonth(month) {
|
|
1690
|
+
this.focusedDate = new Date(this.focusedDate.setMonth(month));
|
|
1691
|
+
}
|
|
1692
|
+
get focusedYear() {
|
|
1693
|
+
return this.focusedDate.getFullYear();
|
|
1694
|
+
}
|
|
1695
|
+
set focusedYear(year) {
|
|
1696
|
+
this.focusedDate = new Date(this.focusedDate.setFullYear(year));
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Returns the date cell element for the given day number.
|
|
1700
|
+
*/
|
|
1701
|
+
getDateCell(dayNumber) {
|
|
1702
|
+
return this.shadowRoot?.querySelector(`#dateCell-${dayNumber}`);
|
|
1703
|
+
}
|
|
1704
|
+
connectedCallback() {
|
|
1705
|
+
super.connectedCallback();
|
|
1706
|
+
TransitionalStyles.instance.apply(this, "gds-calendar");
|
|
1707
|
+
this.addEventListener("keydown", __privateMethod(this, _handleKeyDown, handleKeyDown_fn));
|
|
1708
|
+
}
|
|
1709
|
+
focus() {
|
|
1710
|
+
super.focus();
|
|
1711
|
+
this._elFocusedCell?.focus();
|
|
1712
|
+
}
|
|
1713
|
+
render() {
|
|
1714
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
1715
|
+
return html5`<table>
|
|
1716
|
+
<thead>
|
|
1717
|
+
<tr>
|
|
1718
|
+
${when3(this.showWeekNumbers, () => html5`<th></th>`)}
|
|
1719
|
+
<th>${msg4("Mon")}</th>
|
|
1720
|
+
<th>${msg4("Tue")}</th>
|
|
1721
|
+
<th>${msg4("Wed")}</th>
|
|
1722
|
+
<th>${msg4("Thu")}</th>
|
|
1723
|
+
<th>${msg4("Fri")}</th>
|
|
1724
|
+
<th>${msg4("Sat")}</th>
|
|
1725
|
+
<th>${msg4("Sun")}</th>
|
|
1726
|
+
</tr>
|
|
1727
|
+
</thead>
|
|
1728
|
+
<tbody>
|
|
1729
|
+
${renderMonthGridView(
|
|
1730
|
+
this.focusedDate,
|
|
1731
|
+
(weeks) => html5`
|
|
1732
|
+
${weeks.map(
|
|
1733
|
+
(week) => html5`
|
|
1734
|
+
<tr>
|
|
1735
|
+
${when3(
|
|
1736
|
+
this.showWeekNumbers,
|
|
1737
|
+
() => html5`<td class="week-number">
|
|
1738
|
+
${getWeek(week.days[0])}
|
|
1739
|
+
</td>`
|
|
1740
|
+
)}
|
|
1741
|
+
${week.days.map((day) => {
|
|
1742
|
+
const isDisabled = !isSameMonth(this.focusedDate, day) || day < this.min || day > this.max;
|
|
1743
|
+
return html5`
|
|
1744
|
+
<td
|
|
1745
|
+
class="${classMap4({
|
|
1746
|
+
disabled: isDisabled,
|
|
1747
|
+
today: isSameDay(currentDate, day)
|
|
1748
|
+
})}"
|
|
1749
|
+
?disabled=${isDisabled}
|
|
1750
|
+
tabindex="${isSameDay(this.focusedDate, day) ? 0 : -1}"
|
|
1751
|
+
aria-selected="${isSameDay(this.value, day)}"
|
|
1752
|
+
aria-label="${day.toDateString()}"
|
|
1753
|
+
@click=${() => isDisabled ? null : __privateMethod(this, _setSelectedDate, setSelectedDate_fn).call(this, day)}
|
|
1754
|
+
id="dateCell-${day.getDate()}"
|
|
1755
|
+
>
|
|
1756
|
+
${day.getDate()}
|
|
1757
|
+
</td>
|
|
1758
|
+
`;
|
|
1759
|
+
})}
|
|
1760
|
+
</tr>
|
|
1761
|
+
`
|
|
1762
|
+
)}
|
|
1763
|
+
`
|
|
1764
|
+
)}
|
|
1765
|
+
</tbody>
|
|
1766
|
+
</table>`;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
_setSelectedDate = new WeakSet();
|
|
1770
|
+
setSelectedDate_fn = function(date) {
|
|
1771
|
+
this.value = date;
|
|
1772
|
+
this.dispatchEvent(
|
|
1773
|
+
new CustomEvent("change", {
|
|
1774
|
+
detail: date,
|
|
1775
|
+
bubbles: false,
|
|
1776
|
+
composed: false
|
|
1777
|
+
})
|
|
1778
|
+
);
|
|
1779
|
+
};
|
|
1780
|
+
_handleKeyDown = new WeakSet();
|
|
1781
|
+
handleKeyDown_fn = function(e) {
|
|
1782
|
+
let handled = false;
|
|
1783
|
+
let newFocusedDate = new Date(this.focusedDate);
|
|
1784
|
+
if (e.key === "ArrowLeft") {
|
|
1785
|
+
newFocusedDate = addDays2(this.focusedDate, -1);
|
|
1786
|
+
handled = true;
|
|
1787
|
+
} else if (e.key === "ArrowRight") {
|
|
1788
|
+
newFocusedDate = addDays2(this.focusedDate, 1);
|
|
1789
|
+
handled = true;
|
|
1790
|
+
} else if (e.key === "ArrowUp") {
|
|
1791
|
+
newFocusedDate = addDays2(this.focusedDate, -7);
|
|
1792
|
+
handled = true;
|
|
1793
|
+
} else if (e.key === "ArrowDown") {
|
|
1794
|
+
newFocusedDate = addDays2(this.focusedDate, 7);
|
|
1795
|
+
handled = true;
|
|
1796
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
1797
|
+
if (!this._elFocusedCell?.hasAttribute("disabled")) {
|
|
1798
|
+
__privateMethod(this, _setSelectedDate, setSelectedDate_fn).call(this, this.focusedDate);
|
|
1799
|
+
}
|
|
1800
|
+
handled = true;
|
|
1801
|
+
} else if (e.key === "Home") {
|
|
1802
|
+
newFocusedDate = new Date(this.focusedYear, this.focusedMonth, 1);
|
|
1803
|
+
handled = true;
|
|
1804
|
+
} else if (e.key === "End") {
|
|
1805
|
+
newFocusedDate = new Date(this.focusedYear, this.focusedMonth + 1, 0);
|
|
1806
|
+
handled = true;
|
|
1807
|
+
} else if (e.key === "PageUp") {
|
|
1808
|
+
newFocusedDate = subMonths(this.focusedDate, 1);
|
|
1809
|
+
handled = true;
|
|
1810
|
+
} else if (e.key === "PageDown") {
|
|
1811
|
+
newFocusedDate = addMonths(this.focusedDate, 1);
|
|
1812
|
+
handled = true;
|
|
1813
|
+
}
|
|
1814
|
+
if (newFocusedDate.getFullYear() >= this.min.getFullYear() && newFocusedDate.getFullYear() <= this.max.getFullYear()) {
|
|
1815
|
+
this.focusedDate = newFocusedDate;
|
|
1816
|
+
}
|
|
1817
|
+
if (handled) {
|
|
1818
|
+
e.preventDefault();
|
|
1819
|
+
e.stopPropagation();
|
|
1820
|
+
this.updateComplete.then(() => {
|
|
1821
|
+
this._elFocusedCell?.focus();
|
|
1822
|
+
this.dispatchEvent(
|
|
1823
|
+
new CustomEvent("gds-date-focused", {
|
|
1824
|
+
detail: this.focusedDate,
|
|
1825
|
+
bubbles: false,
|
|
1826
|
+
composed: false
|
|
1827
|
+
})
|
|
1828
|
+
);
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
GdsCalendar.styles = [calendar_styles_default];
|
|
1833
|
+
GdsCalendar.shadowRootOptions = {
|
|
1834
|
+
mode: "open",
|
|
1835
|
+
delegatesFocus: true
|
|
1836
|
+
};
|
|
1837
|
+
__decorateClass([
|
|
1838
|
+
property7()
|
|
1839
|
+
], GdsCalendar.prototype, "value", 2);
|
|
1840
|
+
__decorateClass([
|
|
1841
|
+
property7({ type: Date })
|
|
1842
|
+
], GdsCalendar.prototype, "min", 2);
|
|
1843
|
+
__decorateClass([
|
|
1844
|
+
property7({ type: Date })
|
|
1845
|
+
], GdsCalendar.prototype, "max", 2);
|
|
1846
|
+
__decorateClass([
|
|
1847
|
+
property7()
|
|
1848
|
+
], GdsCalendar.prototype, "focusedDate", 2);
|
|
1849
|
+
__decorateClass([
|
|
1850
|
+
property7({ type: Number })
|
|
1851
|
+
], GdsCalendar.prototype, "focusedMonth", 1);
|
|
1852
|
+
__decorateClass([
|
|
1853
|
+
property7({ type: Number })
|
|
1854
|
+
], GdsCalendar.prototype, "focusedYear", 1);
|
|
1855
|
+
__decorateClass([
|
|
1856
|
+
property7({ type: Boolean })
|
|
1857
|
+
], GdsCalendar.prototype, "showWeekNumbers", 2);
|
|
1858
|
+
__decorateClass([
|
|
1859
|
+
query2('td[tabindex="0"]')
|
|
1860
|
+
], GdsCalendar.prototype, "_elFocusedCell", 2);
|
|
1861
|
+
GdsCalendar = __decorateClass([
|
|
1862
|
+
gdsCustomElement("gds-calendar")
|
|
1863
|
+
], GdsCalendar);
|
|
1864
|
+
|
|
1865
|
+
// libs/core/src/components/datepicker/date-part-spinner.ts
|
|
1866
|
+
import { LitElement as LitElement9 } from "lit";
|
|
1867
|
+
import { property as property8, state as state2 } from "lit/decorators.js";
|
|
1868
|
+
var _inputBuffer, _increment, _decrement, _handleClick, _handleFocus, _handleBlur, _handleWheel, _handleKeyDown2, _focusNextSpinner, focusNextSpinner_fn, _dispatchChangeEvent, dispatchChangeEvent_fn, _formatNumber, formatNumber_fn, _clamp, clamp_fn, _clearInputBuffer, clearInputBuffer_fn;
|
|
1869
|
+
var GdsDatePartSpinner = class extends LitElement9 {
|
|
1870
|
+
constructor() {
|
|
1871
|
+
super(...arguments);
|
|
1872
|
+
__privateAdd(this, _focusNextSpinner);
|
|
1873
|
+
__privateAdd(this, _dispatchChangeEvent);
|
|
1874
|
+
__privateAdd(this, _formatNumber);
|
|
1875
|
+
__privateAdd(this, _clamp);
|
|
1876
|
+
__privateAdd(this, _clearInputBuffer);
|
|
1877
|
+
this.value = 0;
|
|
1878
|
+
this.length = 2;
|
|
1879
|
+
this.min = 0;
|
|
1880
|
+
this.max = Number.MAX_SAFE_INTEGER;
|
|
1881
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
1882
|
+
__privateAdd(this, _inputBuffer, "");
|
|
1883
|
+
__privateAdd(this, _increment, () => {
|
|
1884
|
+
let current = parseInt(this.value.toString());
|
|
1885
|
+
if (Number.isNaN(current))
|
|
1886
|
+
current = this.length === 2 ? this.min : (/* @__PURE__ */ new Date()).getFullYear() - 1;
|
|
1887
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, current + 1);
|
|
1888
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1889
|
+
});
|
|
1890
|
+
__privateAdd(this, _decrement, () => {
|
|
1891
|
+
let current = parseInt(this.value.toString());
|
|
1892
|
+
if (Number.isNaN(current))
|
|
1893
|
+
current = this.length === 2 ? this.max : (/* @__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, _handleClick, (e) => {
|
|
1898
|
+
e.stopPropagation();
|
|
1899
|
+
e.preventDefault();
|
|
1900
|
+
this.focus();
|
|
1901
|
+
});
|
|
1902
|
+
__privateAdd(this, _handleFocus, () => {
|
|
1903
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
1904
|
+
});
|
|
1905
|
+
__privateAdd(this, _handleBlur, () => {
|
|
1906
|
+
if (__privateGet(this, _inputBuffer) === "")
|
|
1907
|
+
return;
|
|
1908
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
1909
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, parseInt(this.value.toString()));
|
|
1910
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1911
|
+
document.getSelection()?.removeAllRanges();
|
|
1912
|
+
});
|
|
1913
|
+
__privateAdd(this, _handleWheel, (e) => {
|
|
1914
|
+
e.stopPropagation();
|
|
1915
|
+
e.preventDefault();
|
|
1916
|
+
if (e.deltaY > 0) {
|
|
1917
|
+
__privateGet(this, _decrement).call(this);
|
|
1918
|
+
} else {
|
|
1919
|
+
__privateGet(this, _increment).call(this);
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
__privateAdd(this, _handleKeyDown2, (e) => {
|
|
1923
|
+
let handled = false;
|
|
1924
|
+
if (e.key === "ArrowUp") {
|
|
1925
|
+
__privateGet(this, _increment).call(this);
|
|
1926
|
+
handled = true;
|
|
1927
|
+
} else if (e.key === "ArrowDown") {
|
|
1928
|
+
__privateGet(this, _decrement).call(this);
|
|
1929
|
+
handled = true;
|
|
1930
|
+
} else {
|
|
1931
|
+
const key = parseInt(e.key);
|
|
1932
|
+
if (!isNaN(key)) {
|
|
1933
|
+
__privateSet(this, _inputBuffer, __privateGet(this, _inputBuffer) + key.toString());
|
|
1934
|
+
this.value = parseInt(__privateGet(this, _inputBuffer));
|
|
1935
|
+
if (__privateGet(this, _inputBuffer).length == this.length) {
|
|
1936
|
+
__privateMethod(this, _focusNextSpinner, focusNextSpinner_fn).call(this);
|
|
1937
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
1938
|
+
}
|
|
1939
|
+
handled = true;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
if (handled) {
|
|
1943
|
+
e.preventDefault();
|
|
1944
|
+
e.stopPropagation();
|
|
1945
|
+
}
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
// No need for a shadow root here
|
|
1949
|
+
createRenderRoot() {
|
|
1950
|
+
return this;
|
|
1951
|
+
}
|
|
1952
|
+
connectedCallback() {
|
|
1953
|
+
super.connectedCallback();
|
|
1954
|
+
this.setAttribute("role", "spinbutton");
|
|
1955
|
+
this.setAttribute("tabindex", "0");
|
|
1956
|
+
this.addEventListener("wheel", __privateGet(this, _handleWheel));
|
|
1957
|
+
this.addEventListener("keydown", __privateGet(this, _handleKeyDown2));
|
|
1958
|
+
this.addEventListener("blur", __privateGet(this, _handleBlur));
|
|
1959
|
+
this.addEventListener("focus", __privateGet(this, _handleFocus));
|
|
1960
|
+
this.addEventListener("click", __privateGet(this, _handleClick));
|
|
1961
|
+
this.addEventListener("mousedown", __privateGet(this, _handleClick));
|
|
1962
|
+
}
|
|
1963
|
+
focus(options) {
|
|
1964
|
+
super.focus(options);
|
|
1965
|
+
__privateGet(this, _handleFocus).call(this);
|
|
1966
|
+
}
|
|
1967
|
+
render() {
|
|
1968
|
+
return html`${this.displayValue}`;
|
|
1969
|
+
}
|
|
1970
|
+
_refreshDisplayValue() {
|
|
1971
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
1972
|
+
this.setAttribute("aria-valuetext", this.value.toString());
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
_inputBuffer = new WeakMap();
|
|
1976
|
+
_increment = new WeakMap();
|
|
1977
|
+
_decrement = new WeakMap();
|
|
1978
|
+
_handleClick = new WeakMap();
|
|
1979
|
+
_handleFocus = new WeakMap();
|
|
1980
|
+
_handleBlur = new WeakMap();
|
|
1981
|
+
_handleWheel = new WeakMap();
|
|
1982
|
+
_handleKeyDown2 = new WeakMap();
|
|
1983
|
+
_focusNextSpinner = new WeakSet();
|
|
1984
|
+
focusNextSpinner_fn = function() {
|
|
1985
|
+
let nextSpinner = this.nextElementSibling;
|
|
1986
|
+
while (nextSpinner) {
|
|
1987
|
+
if (nextSpinner instanceof GdsDatePartSpinner) {
|
|
1988
|
+
nextSpinner.focus();
|
|
1989
|
+
break;
|
|
1990
|
+
}
|
|
1991
|
+
nextSpinner = nextSpinner.nextElementSibling;
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
_dispatchChangeEvent = new WeakSet();
|
|
1995
|
+
dispatchChangeEvent_fn = function() {
|
|
1996
|
+
this.dispatchEvent(
|
|
1997
|
+
new CustomEvent("change", {
|
|
1998
|
+
detail: { value: this.value.toString() }
|
|
1999
|
+
})
|
|
2000
|
+
);
|
|
2001
|
+
};
|
|
2002
|
+
_formatNumber = new WeakSet();
|
|
2003
|
+
formatNumber_fn = function(num, padZeros) {
|
|
2004
|
+
return String(num).padStart(padZeros, "0");
|
|
2005
|
+
};
|
|
2006
|
+
_clamp = new WeakSet();
|
|
2007
|
+
clamp_fn = function(value) {
|
|
2008
|
+
return Math.max(this.min, Math.min(this.max, value));
|
|
2009
|
+
};
|
|
2010
|
+
_clearInputBuffer = new WeakSet();
|
|
2011
|
+
clearInputBuffer_fn = function() {
|
|
2012
|
+
__privateSet(this, _inputBuffer, "");
|
|
2013
|
+
};
|
|
2014
|
+
GdsDatePartSpinner.formAssociated = true;
|
|
2015
|
+
__decorateClass([
|
|
2016
|
+
property8({ type: Number })
|
|
2017
|
+
], GdsDatePartSpinner.prototype, "value", 2);
|
|
2018
|
+
__decorateClass([
|
|
2019
|
+
property8({ type: Number })
|
|
2020
|
+
], GdsDatePartSpinner.prototype, "length", 2);
|
|
2021
|
+
__decorateClass([
|
|
2022
|
+
property8({ type: Number, attribute: "aria-valuemin" })
|
|
2023
|
+
], GdsDatePartSpinner.prototype, "min", 2);
|
|
2024
|
+
__decorateClass([
|
|
2025
|
+
property8({ type: Number, attribute: "aria-valuemax" })
|
|
2026
|
+
], GdsDatePartSpinner.prototype, "max", 2);
|
|
2027
|
+
__decorateClass([
|
|
2028
|
+
state2()
|
|
2029
|
+
], GdsDatePartSpinner.prototype, "displayValue", 2);
|
|
2030
|
+
__decorateClass([
|
|
2031
|
+
watch("value")
|
|
2032
|
+
], GdsDatePartSpinner.prototype, "_refreshDisplayValue", 1);
|
|
2033
|
+
GdsDatePartSpinner = __decorateClass([
|
|
2034
|
+
gdsCustomElement("gds-date-part-spinner")
|
|
2035
|
+
], GdsDatePartSpinner);
|
|
2036
|
+
|
|
2037
|
+
// libs/core/src/components/datepicker/datepicker.styles.ts
|
|
2038
|
+
import { css as css6 } from "lit";
|
|
2039
|
+
var styles = css6`
|
|
2040
|
+
label {
|
|
2041
|
+
display: block;
|
|
2042
|
+
}
|
|
2043
|
+
`;
|
|
2044
|
+
|
|
2045
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
2046
|
+
import { nothing } from "lit";
|
|
2047
|
+
var dateConverter = {
|
|
2048
|
+
fromAttribute(value) {
|
|
2049
|
+
return new Date(value);
|
|
2050
|
+
},
|
|
2051
|
+
toAttribute(value) {
|
|
2052
|
+
return value.toISOString();
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
var _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get;
|
|
2056
|
+
var GdsDatepicker = class extends GdsFormControlElement {
|
|
2057
|
+
constructor() {
|
|
2058
|
+
super(...arguments);
|
|
2059
|
+
__privateAdd(this, _renderBackToValidRangeButton);
|
|
2060
|
+
__privateAdd(this, _focusDate);
|
|
2061
|
+
__privateAdd(this, _getSpinnerLabel);
|
|
2062
|
+
__privateAdd(this, _getMinSpinnerValue);
|
|
2063
|
+
__privateAdd(this, _getMaxSpinnerValue);
|
|
2064
|
+
__privateAdd(this, _dispatchChangeEvent2);
|
|
2065
|
+
/**
|
|
2066
|
+
* Takes a dateformat string from the dateformat attribute and turnes it to a DateFormatLayout object used in rendering the template.
|
|
2067
|
+
*/
|
|
2068
|
+
__privateAdd(this, _parseDateFormat);
|
|
2069
|
+
/**
|
|
2070
|
+
* Returns an array of years between the min and max dates for use in the year dropdown.
|
|
2071
|
+
* If the value is set to a year outside the range, it will be added to the array until the value is changed.
|
|
2072
|
+
*/
|
|
2073
|
+
__privateAdd(this, _years);
|
|
2074
|
+
this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
|
|
2075
|
+
this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
|
|
2076
|
+
this.open = false;
|
|
2077
|
+
this.label = "";
|
|
2078
|
+
this.showWeekNumbers = false;
|
|
2079
|
+
this._focusedMonth = (/* @__PURE__ */ new Date()).getMonth();
|
|
2080
|
+
this._focusedYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
2081
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, "y-m-d");
|
|
2082
|
+
__privateAdd(this, _handleCalendarChange, (e) => {
|
|
2083
|
+
e.stopPropagation();
|
|
2084
|
+
this.value = e.detail;
|
|
2085
|
+
this.open = false;
|
|
2086
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2087
|
+
});
|
|
2088
|
+
__privateAdd(this, _handleMonthChange, (e) => {
|
|
2089
|
+
e.stopPropagation();
|
|
2090
|
+
this._focusedMonth = e.target?.value;
|
|
2091
|
+
});
|
|
2092
|
+
__privateAdd(this, _handleYearChange, (e) => {
|
|
2093
|
+
e.stopPropagation();
|
|
2094
|
+
this._focusedYear = e.target?.value;
|
|
2095
|
+
});
|
|
2096
|
+
__privateAdd(this, _handleIncrementFocusedMonth, (_e) => {
|
|
2097
|
+
this._focusedMonth++;
|
|
2098
|
+
if (this._focusedMonth > 11) {
|
|
2099
|
+
this._focusedMonth = 0;
|
|
2100
|
+
this._focusedYear++;
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
__privateAdd(this, _handleDecrementFocusedMonth, (_e) => {
|
|
2104
|
+
this._focusedMonth--;
|
|
2105
|
+
if (this._focusedMonth < 0) {
|
|
2106
|
+
this._focusedMonth = 11;
|
|
2107
|
+
this._focusedYear--;
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
__privateAdd(this, _handleFocusChange, async () => {
|
|
2111
|
+
this._focusedMonth = (await this._elCalendar).focusedMonth;
|
|
2112
|
+
this._focusedYear = (await this._elCalendar).focusedYear;
|
|
2113
|
+
this.requestUpdate();
|
|
2114
|
+
});
|
|
2115
|
+
__privateAdd(this, _handlePopoverStateChange, (e) => {
|
|
2116
|
+
if (e.target !== e.currentTarget)
|
|
2117
|
+
return;
|
|
2118
|
+
this.open = e.detail.open;
|
|
2119
|
+
});
|
|
2120
|
+
__privateAdd(this, _handleSpinnerKeydown, (e) => {
|
|
2121
|
+
const index = Array.from(this._elSpinners).findIndex(
|
|
2122
|
+
(spinner) => spinner === e.target
|
|
2123
|
+
);
|
|
2124
|
+
if (e.key === "ArrowRight") {
|
|
2125
|
+
const next = this._elSpinners[index + 1];
|
|
2126
|
+
if (next)
|
|
2127
|
+
next.focus();
|
|
2128
|
+
}
|
|
2129
|
+
if (e.key === "ArrowLeft") {
|
|
2130
|
+
const prev = this._elSpinners[index - 1];
|
|
2131
|
+
if (prev)
|
|
2132
|
+
prev.focus();
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2135
|
+
__privateAdd(this, _handleSpinnerChange, (val, name) => {
|
|
2136
|
+
__privateGet(this, _spinnerState)[name] = val;
|
|
2137
|
+
const newDate = /* @__PURE__ */ new Date();
|
|
2138
|
+
newDate.setFullYear(parseInt(__privateGet(this, _spinnerState).year));
|
|
2139
|
+
newDate.setMonth(parseInt(__privateGet(this, _spinnerState).month) - 1);
|
|
2140
|
+
newDate.setDate(parseInt(__privateGet(this, _spinnerState).day));
|
|
2141
|
+
if (newDate.toString() === "Invalid Date")
|
|
2142
|
+
return;
|
|
2143
|
+
this.value = newDate;
|
|
2144
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2145
|
+
});
|
|
2146
|
+
/**
|
|
2147
|
+
* The spinner state keeps track of the spinner values regardless of wheter a complete date has been enter yet.
|
|
2148
|
+
*/
|
|
2149
|
+
__privateAdd(this, _spinnerState, {
|
|
2150
|
+
year: "yyyy",
|
|
2151
|
+
month: "mm",
|
|
2152
|
+
day: "dd"
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
get dateformat() {
|
|
2156
|
+
return this._dateFormatLayout.layout.map((f) => f.token).join(this._dateFormatLayout.delimiter);
|
|
2157
|
+
}
|
|
2158
|
+
set dateformat(dateformat) {
|
|
2159
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, dateformat);
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Get the currently focused date in the calendar popover. If no date is focused, or the calendar popover
|
|
2163
|
+
* is closed, the value will be undefined.
|
|
2164
|
+
*/
|
|
2165
|
+
async getFocusedDate() {
|
|
2166
|
+
if (this.open)
|
|
2167
|
+
return this._elCalendar.then((el) => el.focusedDate);
|
|
2168
|
+
else
|
|
2169
|
+
return void 0;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* A reference to a date cell element (<td>) inside the shadow root of the calendar primitive.
|
|
2173
|
+
* Inteded for use in integration tests.
|
|
2174
|
+
*/
|
|
2175
|
+
async test_getDateCell(dayNumber) {
|
|
2176
|
+
return this._elCalendar.then((el) => el.getDateCell(dayNumber));
|
|
2177
|
+
}
|
|
2178
|
+
connectedCallback() {
|
|
2179
|
+
super.connectedCallback();
|
|
2180
|
+
TransitionalStyles.instance.apply(this, "gds-datepicker");
|
|
2181
|
+
}
|
|
2182
|
+
render() {
|
|
2183
|
+
return html`
|
|
2184
|
+
<label for="spinner-0" id="label">${this.label}</label>
|
|
2185
|
+
|
|
2186
|
+
<div class="form-info"><slot name="sub-label"></slot></div>
|
|
2187
|
+
|
|
2188
|
+
<div class="field" id="trigger">
|
|
2189
|
+
<div class="input">
|
|
2190
|
+
${join(
|
|
2191
|
+
map(
|
|
2192
|
+
this._dateFormatLayout.layout,
|
|
2193
|
+
(f, i) => html`<gds-date-part-spinner
|
|
2194
|
+
id="spinner-${i}"
|
|
2195
|
+
.length=${f.token === "y" ? 4 : 2}
|
|
2196
|
+
.value=${__privateGet(this, _spinnerState)[f.name]}
|
|
2197
|
+
aria-valuemin=${__privateMethod(this, _getMinSpinnerValue, getMinSpinnerValue_fn).call(this, f.name)}
|
|
2198
|
+
aria-valuemax=${__privateMethod(this, _getMaxSpinnerValue, getMaxSpinnerValue_fn).call(this, f.name)}
|
|
2199
|
+
aria-label=${__privateMethod(this, _getSpinnerLabel, getSpinnerLabel_fn).call(this, f.name)}
|
|
2200
|
+
aria-describedby="label"
|
|
2201
|
+
@keydown=${__privateGet(this, _handleSpinnerKeydown)}
|
|
2202
|
+
@change=${(e) => __privateGet(this, _handleSpinnerChange).call(this, e.detail.value, f.name)}
|
|
2203
|
+
></gds-date-part-spinner>`
|
|
2204
|
+
),
|
|
2205
|
+
html`<span>${this._dateFormatLayout.delimiter}</span>`
|
|
2206
|
+
)}
|
|
2207
|
+
</div>
|
|
2208
|
+
<button
|
|
2209
|
+
id="calendar-button"
|
|
2210
|
+
aria-label="${msg5("Open calendar modal")}"
|
|
2211
|
+
aria-haspopup="menu"
|
|
2212
|
+
aria-expanded=${this.open}
|
|
2213
|
+
aria-controls="calendar-popover"
|
|
2214
|
+
aria-describedby="label"
|
|
2215
|
+
@click=${() => this.open = !this.open}
|
|
2216
|
+
>
|
|
2217
|
+
<svg
|
|
2218
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
2219
|
+
viewBox="0 0 448 512"
|
|
2220
|
+
style="width:100%;height:100%"
|
|
2221
|
+
>
|
|
2222
|
+
<path
|
|
2223
|
+
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 "
|
|
2224
|
+
/>
|
|
2225
|
+
</svg>
|
|
2226
|
+
</button>
|
|
2227
|
+
</div>
|
|
2228
|
+
|
|
2229
|
+
<div class="form-info"><slot name="message"></slot></div>
|
|
2230
|
+
|
|
2231
|
+
<gds-popover
|
|
2232
|
+
.triggerRef=${this._elTrigger}
|
|
2233
|
+
.open=${this.open}
|
|
2234
|
+
@gds-ui-state=${__privateGet(this, _handlePopoverStateChange)}
|
|
2235
|
+
id="calendar-popover"
|
|
2236
|
+
.placement=${"bottom-end"}
|
|
2237
|
+
.calcMinWidth=${() => "390px"}
|
|
2238
|
+
@focusin=${async (e) => {
|
|
2239
|
+
const isPopover = e.target?.id === "calendar-popover";
|
|
2240
|
+
if (!isPopover)
|
|
2241
|
+
return;
|
|
2242
|
+
this._elCalendar.then((cal) => cal.focus());
|
|
2243
|
+
}}
|
|
2244
|
+
>
|
|
2245
|
+
<div class="header">
|
|
2246
|
+
<button @click=${__privateGet(this, _handleDecrementFocusedMonth)}>
|
|
2247
|
+
<i class="icon prev"></i>
|
|
2248
|
+
</button>
|
|
2249
|
+
<gds-dropdown
|
|
2250
|
+
.value=${this._focusedMonth.toString()}
|
|
2251
|
+
@change=${__privateGet(this, _handleMonthChange)}
|
|
2252
|
+
aria-label="${msg5("Month")}"
|
|
2253
|
+
>
|
|
2254
|
+
<gds-option value="0">${msg5("January")}</gds-option>
|
|
2255
|
+
<gds-option value="1">${msg5("February")}</gds-option>
|
|
2256
|
+
<gds-option value="2">${msg5("March")}</gds-option>
|
|
2257
|
+
<gds-option value="3">${msg5("April")}</gds-option>
|
|
2258
|
+
<gds-option value="4">${msg5("May")}</gds-option>
|
|
2259
|
+
<gds-option value="5">${msg5("June")}</gds-option>
|
|
2260
|
+
<gds-option value="6">${msg5("July")}</gds-option>
|
|
2261
|
+
<gds-option value="7">${msg5("August")}</gds-option>
|
|
2262
|
+
<gds-option value="8">${msg5("September")}</gds-option>
|
|
2263
|
+
<gds-option value="9">${msg5("October")}</gds-option>
|
|
2264
|
+
<gds-option value="10">${msg5("November")}</gds-option>
|
|
2265
|
+
<gds-option value="11">${msg5("December")}</gds-option>
|
|
2266
|
+
</gds-dropdown>
|
|
2267
|
+
<gds-dropdown
|
|
2268
|
+
.value=${this._focusedYear.toString()}
|
|
2269
|
+
@change=${__privateGet(this, _handleYearChange)}
|
|
2270
|
+
aria-label="${msg5("Year")}"
|
|
2271
|
+
>
|
|
2272
|
+
${repeat(
|
|
2273
|
+
__privateGet(this, _years, years_get),
|
|
2274
|
+
(year) => year,
|
|
2275
|
+
(year) => html`<gds-option value=${year}>${year}</gds-option>`
|
|
2276
|
+
)}
|
|
2277
|
+
</gds-dropdown>
|
|
2278
|
+
<button @click=${__privateGet(this, _handleIncrementFocusedMonth)}>
|
|
2279
|
+
<i class="icon next"></i>
|
|
2280
|
+
</button>
|
|
2281
|
+
</div>
|
|
2282
|
+
|
|
2283
|
+
<gds-calendar
|
|
2284
|
+
id="calendar"
|
|
2285
|
+
@change=${__privateGet(this, _handleCalendarChange)}
|
|
2286
|
+
@gds-date-focused=${__privateGet(this, _handleFocusChange)}
|
|
2287
|
+
.focusedMonth=${this._focusedMonth}
|
|
2288
|
+
.focusedYear=${this._focusedYear}
|
|
2289
|
+
.value=${this.value}
|
|
2290
|
+
.min=${this.min}
|
|
2291
|
+
.max=${this.max}
|
|
2292
|
+
.showWeekNumbers=${this.showWeekNumbers}
|
|
2293
|
+
></gds-calendar>
|
|
2294
|
+
|
|
2295
|
+
<div class="footer">
|
|
2296
|
+
<button
|
|
2297
|
+
class="tertiary clear"
|
|
2298
|
+
@click=${() => {
|
|
2299
|
+
this.value = void 0;
|
|
2300
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2301
|
+
}}
|
|
2302
|
+
>
|
|
2303
|
+
${msg5("Clear")}
|
|
2304
|
+
</button>
|
|
2305
|
+
${until(__privateMethod(this, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn).call(this), nothing)}
|
|
2306
|
+
<button
|
|
2307
|
+
class="tertiary today"
|
|
2308
|
+
@click=${() => {
|
|
2309
|
+
this.value = /* @__PURE__ */ new Date();
|
|
2310
|
+
__privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
|
|
2311
|
+
}}
|
|
2312
|
+
>
|
|
2313
|
+
${msg5("Today")}
|
|
2314
|
+
</button>
|
|
2315
|
+
</div>
|
|
2316
|
+
</gds-popover>
|
|
2317
|
+
`;
|
|
2318
|
+
}
|
|
2319
|
+
_handleValueChange() {
|
|
2320
|
+
if (!this.value) {
|
|
2321
|
+
__privateSet(this, _spinnerState, {
|
|
2322
|
+
year: "yyyy",
|
|
2323
|
+
month: "mm",
|
|
2324
|
+
day: "dd"
|
|
2325
|
+
});
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
const date = this.value;
|
|
2329
|
+
this._focusedMonth = date.getMonth();
|
|
2330
|
+
this._focusedYear = date.getFullYear();
|
|
2331
|
+
const year = date.getFullYear().toString();
|
|
2332
|
+
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
2333
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
2334
|
+
__privateSet(this, _spinnerState, { year, month, day });
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
_renderBackToValidRangeButton = new WeakSet();
|
|
2338
|
+
renderBackToValidRangeButton_fn = async function() {
|
|
2339
|
+
const focusedDate = await this.getFocusedDate();
|
|
2340
|
+
let buttonTxt = "";
|
|
2341
|
+
let buttonAction;
|
|
2342
|
+
if (focusedDate && focusedDate > this.max) {
|
|
2343
|
+
buttonTxt = msg5("Last available date");
|
|
2344
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.max);
|
|
2345
|
+
} else if (focusedDate && focusedDate < this.min) {
|
|
2346
|
+
buttonTxt = msg5("First available date");
|
|
2347
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.min);
|
|
2348
|
+
}
|
|
2349
|
+
return html`${when4(
|
|
2350
|
+
buttonTxt.length > 0,
|
|
2351
|
+
() => html`<button class="tertiary back-to-range" @click=${buttonAction}>
|
|
2352
|
+
${buttonTxt}
|
|
2353
|
+
</button>`,
|
|
2354
|
+
() => nothing
|
|
2355
|
+
)}`;
|
|
2356
|
+
};
|
|
2357
|
+
_focusDate = new WeakSet();
|
|
2358
|
+
focusDate_fn = function(d) {
|
|
2359
|
+
const firstValidDate = new Date(d);
|
|
2360
|
+
this._elCalendar.then((el) => el.focusedDate = firstValidDate).then(__privateGet(this, _handleFocusChange));
|
|
2361
|
+
};
|
|
2362
|
+
_getSpinnerLabel = new WeakSet();
|
|
2363
|
+
getSpinnerLabel_fn = function(name) {
|
|
2364
|
+
const labels = {
|
|
2365
|
+
year: msg5("Year"),
|
|
2366
|
+
month: msg5("Month"),
|
|
2367
|
+
day: msg5("Day")
|
|
2368
|
+
};
|
|
2369
|
+
return labels[name];
|
|
2370
|
+
};
|
|
2371
|
+
_getMinSpinnerValue = new WeakSet();
|
|
2372
|
+
getMinSpinnerValue_fn = function(name) {
|
|
2373
|
+
const min = {
|
|
2374
|
+
year: this.min.getFullYear(),
|
|
2375
|
+
month: 1,
|
|
2376
|
+
day: 1
|
|
2377
|
+
};
|
|
2378
|
+
return min[name];
|
|
2379
|
+
};
|
|
2380
|
+
_getMaxSpinnerValue = new WeakSet();
|
|
2381
|
+
getMaxSpinnerValue_fn = function(name) {
|
|
2382
|
+
const max = {
|
|
2383
|
+
year: this.max.getFullYear(),
|
|
2384
|
+
month: 12,
|
|
2385
|
+
day: 31
|
|
2386
|
+
};
|
|
2387
|
+
return max[name];
|
|
2388
|
+
};
|
|
2389
|
+
_dispatchChangeEvent2 = new WeakSet();
|
|
2390
|
+
dispatchChangeEvent_fn2 = function() {
|
|
2391
|
+
this.dispatchEvent(
|
|
2392
|
+
new CustomEvent("change", {
|
|
2393
|
+
detail: { value: this.value }
|
|
2394
|
+
})
|
|
2395
|
+
);
|
|
2396
|
+
};
|
|
2397
|
+
_handleCalendarChange = new WeakMap();
|
|
2398
|
+
_handleMonthChange = new WeakMap();
|
|
2399
|
+
_handleYearChange = new WeakMap();
|
|
2400
|
+
_handleIncrementFocusedMonth = new WeakMap();
|
|
2401
|
+
_handleDecrementFocusedMonth = new WeakMap();
|
|
2402
|
+
_handleFocusChange = new WeakMap();
|
|
2403
|
+
_handlePopoverStateChange = new WeakMap();
|
|
2404
|
+
_handleSpinnerKeydown = new WeakMap();
|
|
2405
|
+
_parseDateFormat = new WeakSet();
|
|
2406
|
+
parseDateFormat_fn = function(dateformat) {
|
|
2407
|
+
const delimiter = dateformat.replace(/[a-z0-9]/gi, "")[0];
|
|
2408
|
+
const format = dateformat.split(delimiter);
|
|
2409
|
+
const year = format.findIndex((f) => f === "y");
|
|
2410
|
+
const month = format.findIndex((f) => f === "m");
|
|
2411
|
+
const day = format.findIndex((f) => f === "d");
|
|
2412
|
+
if (year === -1 || month === -1 || day === -1)
|
|
2413
|
+
throw new Error("Invalid date format for <gds-datepicker>");
|
|
2414
|
+
const ordered = [year, month, day].sort((a, b) => a - b);
|
|
2415
|
+
const orderedFormat = ordered.map((i) => format[i]).map((f) => ({
|
|
2416
|
+
token: f,
|
|
2417
|
+
name: f === "y" ? "year" : f === "m" ? "month" : "day"
|
|
2418
|
+
}));
|
|
2419
|
+
return { delimiter, layout: orderedFormat };
|
|
2420
|
+
};
|
|
2421
|
+
_handleSpinnerChange = new WeakMap();
|
|
2422
|
+
_spinnerState = new WeakMap();
|
|
2423
|
+
_years = new WeakSet();
|
|
2424
|
+
years_get = function() {
|
|
2425
|
+
const years = eachYearOfInterval({
|
|
2426
|
+
start: this.min,
|
|
2427
|
+
end: this.max
|
|
2428
|
+
}).map((date) => date.getFullYear());
|
|
2429
|
+
if (!this.value)
|
|
2430
|
+
return years;
|
|
2431
|
+
const selectedYear = this.value.getFullYear();
|
|
2432
|
+
const valueIsInrage = years[0] <= selectedYear && years[years.length - 1] >= selectedYear;
|
|
2433
|
+
if (!valueIsInrage) {
|
|
2434
|
+
years.push(selectedYear);
|
|
2435
|
+
years.sort((a, b) => a - b);
|
|
2436
|
+
}
|
|
2437
|
+
return years;
|
|
2438
|
+
};
|
|
2439
|
+
GdsDatepicker.styles = [styles];
|
|
2440
|
+
GdsDatepicker.shadowRootOptions = {
|
|
2441
|
+
mode: "open",
|
|
2442
|
+
delegatesFocus: true
|
|
2443
|
+
};
|
|
2444
|
+
__decorateClass([
|
|
2445
|
+
property9({ converter: dateConverter })
|
|
2446
|
+
], GdsDatepicker.prototype, "value", 2);
|
|
2447
|
+
__decorateClass([
|
|
2448
|
+
property9({ converter: dateConverter })
|
|
2449
|
+
], GdsDatepicker.prototype, "min", 2);
|
|
2450
|
+
__decorateClass([
|
|
2451
|
+
property9({ converter: dateConverter })
|
|
2452
|
+
], GdsDatepicker.prototype, "max", 2);
|
|
2453
|
+
__decorateClass([
|
|
2454
|
+
property9({ type: Boolean })
|
|
2455
|
+
], GdsDatepicker.prototype, "open", 2);
|
|
2456
|
+
__decorateClass([
|
|
2457
|
+
property9()
|
|
2458
|
+
], GdsDatepicker.prototype, "label", 2);
|
|
2459
|
+
__decorateClass([
|
|
2460
|
+
property9({ type: Boolean })
|
|
2461
|
+
], GdsDatepicker.prototype, "showWeekNumbers", 2);
|
|
2462
|
+
__decorateClass([
|
|
2463
|
+
property9()
|
|
2464
|
+
], GdsDatepicker.prototype, "dateformat", 1);
|
|
2465
|
+
__decorateClass([
|
|
2466
|
+
queryAsync3("#calendar-button")
|
|
2467
|
+
], GdsDatepicker.prototype, "test_calendarButton", 2);
|
|
2468
|
+
__decorateClass([
|
|
2469
|
+
state3()
|
|
2470
|
+
], GdsDatepicker.prototype, "_focusedMonth", 2);
|
|
2471
|
+
__decorateClass([
|
|
2472
|
+
state3()
|
|
2473
|
+
], GdsDatepicker.prototype, "_focusedYear", 2);
|
|
2474
|
+
__decorateClass([
|
|
2475
|
+
state3()
|
|
2476
|
+
], GdsDatepicker.prototype, "_dateFormatLayout", 2);
|
|
2477
|
+
__decorateClass([
|
|
2478
|
+
queryAsync3("#calendar")
|
|
2479
|
+
], GdsDatepicker.prototype, "_elCalendar", 2);
|
|
2480
|
+
__decorateClass([
|
|
2481
|
+
queryAsync3("#trigger")
|
|
2482
|
+
], GdsDatepicker.prototype, "_elTrigger", 2);
|
|
2483
|
+
__decorateClass([
|
|
2484
|
+
queryAll(getScopedTagName("gds-date-part-spinner"))
|
|
2485
|
+
], GdsDatepicker.prototype, "_elSpinners", 2);
|
|
2486
|
+
__decorateClass([
|
|
2487
|
+
watch("value")
|
|
2488
|
+
], GdsDatepicker.prototype, "_handleValueChange", 1);
|
|
2489
|
+
GdsDatepicker = __decorateClass([
|
|
2490
|
+
gdsCustomElement("gds-datepicker")
|
|
2491
|
+
], GdsDatepicker);
|
|
1604
2492
|
export {
|
|
1605
2493
|
GdsContextMenu,
|
|
2494
|
+
GdsDatepicker,
|
|
1606
2495
|
GdsDropdown,
|
|
1607
2496
|
GdsMenuItem,
|
|
1608
2497
|
GdsOption,
|