@vaadin/date-picker 24.0.0-alpha7 → 24.0.0-alpha9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/date-picker",
3
- "version": "24.0.0-alpha7",
3
+ "version": "24.0.0-alpha9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,14 +36,14 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.2.0",
39
- "@vaadin/button": "24.0.0-alpha7",
40
- "@vaadin/component-base": "24.0.0-alpha7",
41
- "@vaadin/field-base": "24.0.0-alpha7",
42
- "@vaadin/input-container": "24.0.0-alpha7",
43
- "@vaadin/overlay": "24.0.0-alpha7",
44
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha7",
45
- "@vaadin/vaadin-material-styles": "24.0.0-alpha7",
46
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha7"
39
+ "@vaadin/button": "24.0.0-alpha9",
40
+ "@vaadin/component-base": "24.0.0-alpha9",
41
+ "@vaadin/field-base": "24.0.0-alpha9",
42
+ "@vaadin/input-container": "24.0.0-alpha9",
43
+ "@vaadin/overlay": "24.0.0-alpha9",
44
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha9",
45
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha9",
46
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha9"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@esm-bundle/chai": "^4.3.4",
@@ -54,5 +54,5 @@
54
54
  "web-types.json",
55
55
  "web-types.lit.json"
56
56
  ],
57
- "gitHead": "aeb4535336813636736759e0a5de148b26bfc3b6"
57
+ "gitHead": "cc3f747164041566b300bde4b105d2475649e93f"
58
58
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -153,7 +153,7 @@ export function getAdjustedYear(referenceDate, year, month = 0, day = 1) {
153
153
  */
154
154
  export function parseDate(str) {
155
155
  // Parsing with RegExp to ensure correct format
156
- const parts = /^([-+]\d{1}|\d{2,4}|[-+]\d{6})-(\d{1,2})-(\d{1,2})$/.exec(str);
156
+ const parts = /^([-+]\d{1}|\d{2,4}|[-+]\d{6})-(\d{1,2})-(\d{1,2})$/u.exec(str);
157
157
  if (!parts) {
158
158
  return undefined;
159
159
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ValidateMixin } from '@vaadin/field-base/src/validate-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-date-picker-overlay.js';
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
7
8
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
9
  import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
10
  import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
10
- import type { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js';
11
+ import type { OverlayClassMixinClass } from '@vaadin/component-base/src/overlay-class-mixin.js';
11
12
  import type { InputConstraintsMixinClass } from '@vaadin/field-base/src/input-constraints-mixin.js';
12
13
  import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
13
14
 
@@ -93,6 +94,7 @@ export declare function DatePickerMixin<T extends Constructor<HTMLElement>>(
93
94
  Constructor<InputConstraintsMixinClass> &
94
95
  Constructor<InputMixinClass> &
95
96
  Constructor<KeyboardMixinClass> &
97
+ Constructor<OverlayClassMixinClass> &
96
98
  T;
97
99
 
98
100
  export declare class DatePickerMixinClass {
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
7
7
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import { DelegateFocusMixin } from '@vaadin/component-base/src/delegate-focus-mixin.js';
8
9
  import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
9
10
  import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
10
- import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js';
11
+ import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
11
12
  import { InputConstraintsMixin } from '@vaadin/field-base/src/input-constraints-mixin.js';
12
13
  import { VirtualKeyboardController } from '@vaadin/field-base/src/virtual-keyboard-controller.js';
13
14
  import {
@@ -21,11 +22,16 @@ import {
21
22
 
22
23
  /**
23
24
  * @polymerMixin
25
+ * @mixes ControllerMixin
26
+ * @mixes DelegateFocusMixin
27
+ * @mixes InputConstraintsMixin
28
+ * @mixes KeyboardMixin
29
+ * @mixes OverlayClassMixin
24
30
  * @param {function(new:HTMLElement)} subclass
25
31
  */
26
32
  export const DatePickerMixin = (subclass) =>
27
- class VaadinDatePickerMixin extends ControllerMixin(
28
- DelegateFocusMixin(InputConstraintsMixin(KeyboardMixin(subclass))),
33
+ class DatePickerMixinClass extends OverlayClassMixin(
34
+ ControllerMixin(DelegateFocusMixin(InputConstraintsMixin(KeyboardMixin(subclass)))),
29
35
  ) {
30
36
  static get properties() {
31
37
  return {
@@ -222,7 +228,7 @@ export const DatePickerMixin = (subclass) =>
222
228
  cancel: 'Cancel',
223
229
  referenceDate: '',
224
230
  formatDate(d) {
225
- const yearStr = String(d.year).replace(/\d+/, (y) => '0000'.substr(y.length) + y);
231
+ const yearStr = String(d.year).replace(/\d+/u, (y) => '0000'.substr(y.length) + y);
226
232
  return [d.month + 1, d.day, yearStr].join('/');
227
233
  },
228
234
  parseDate(text) {
@@ -424,7 +430,10 @@ export const DatePickerMixin = (subclass) =>
424
430
 
425
431
  this.addController(new VirtualKeyboardController(this));
426
432
 
427
- this.$.overlay.renderer = this._boundOverlayRenderer;
433
+ const overlay = this.$.overlay;
434
+ this._overlayElement = overlay;
435
+
436
+ overlay.renderer = this._boundOverlayRenderer;
428
437
 
429
438
  this.addEventListener('mousedown', () => this.__bringToFront());
430
439
  this.addEventListener('touchstart', () => this.__bringToFront());
@@ -791,21 +800,17 @@ export const DatePickerMixin = (subclass) =>
791
800
 
792
801
  /** @protected */
793
802
  _onOverlayOpened() {
794
- const parsedInitialPosition = parseDate(this.initialPosition);
795
-
796
- const initialPosition =
797
- this._selectedDate || this._overlayContent.initialPosition || parsedInitialPosition || new Date();
803
+ // Detect which date to show
804
+ const initialPosition = this._getInitialPosition();
805
+ this._overlayContent.initialPosition = initialPosition;
798
806
 
799
- if (parsedInitialPosition || dateAllowed(initialPosition, this._minDate, this._maxDate)) {
800
- this._overlayContent.initialPosition = initialPosition;
801
- } else {
802
- this._overlayContent.initialPosition = getClosestDate(initialPosition, [this._minDate, this._maxDate]);
803
- }
807
+ // Scroll the date into view
808
+ const scrollFocusDate = this._overlayContent.focusedDate || initialPosition;
809
+ this._overlayContent.scrollToDate(scrollFocusDate);
804
810
 
805
- this._overlayContent.scrollToDate(this._overlayContent.focusedDate || this._overlayContent.initialPosition);
806
- // Have a default focused date
811
+ // Ensure the date is focused
807
812
  this._ignoreFocusedDateChange = true;
808
- this._overlayContent.focusedDate ||= this._overlayContent.initialPosition;
813
+ this._overlayContent.focusedDate = scrollFocusDate;
809
814
  this._ignoreFocusedDateChange = false;
810
815
 
811
816
  window.addEventListener('scroll', this._boundOnScroll, true);
@@ -823,6 +828,18 @@ export const DatePickerMixin = (subclass) =>
823
828
  }
824
829
  }
825
830
 
831
+ /** @private */
832
+ _getInitialPosition() {
833
+ const parsedInitialPosition = parseDate(this.initialPosition);
834
+
835
+ const initialPosition =
836
+ this._selectedDate || this._overlayContent.initialPosition || parsedInitialPosition || new Date();
837
+
838
+ return parsedInitialPosition || dateAllowed(initialPosition, this._minDate, this._maxDate)
839
+ ? initialPosition
840
+ : getClosestDate(initialPosition, [this._minDate, this._maxDate]);
841
+ }
842
+
826
843
  /** @private */
827
844
  _selectParsedOrFocusedDate() {
828
845
  // Select the parsed input or focused date
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html } from '@polymer/polymer/lib/utils/html-tag.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/button/src/vaadin-button.js';
@@ -644,7 +644,10 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
644
644
  const initialPosition = this._monthScroller.position;
645
645
 
646
646
  const smoothScroll = (timestamp) => {
647
- start ||= timestamp;
647
+ if (!start) {
648
+ start = timestamp;
649
+ }
650
+
648
651
  const currentTime = timestamp - start;
649
652
 
650
653
  if (currentTime < this.scrollDuration) {
@@ -972,58 +975,55 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
972
975
  this.focusDate(getClosestDate(focus, [this.minDate, this.maxDate]));
973
976
  }
974
977
 
975
- _moveFocusByDays(days) {
976
- const focus = this.focusedDate;
977
- const dateToFocus = new Date(0, 0);
978
- dateToFocus.setFullYear(focus.getFullYear());
979
- dateToFocus.setMonth(focus.getMonth());
980
- dateToFocus.setDate(focus.getDate() + days);
981
-
982
- if (this._dateAllowed(dateToFocus, this.minDate, this.maxDate)) {
983
- this.focusDate(dateToFocus);
984
- } else if (this._dateAllowed(focus, this.minDate, this.maxDate)) {
978
+ _focusAllowedDate(dateToFocus, diff, keepMonth) {
979
+ if (this._dateAllowed(dateToFocus)) {
980
+ this.focusDate(dateToFocus, keepMonth);
981
+ } else if (this._dateAllowed(this.focusedDate)) {
985
982
  // Move to min or max date
986
- if (days > 0) {
987
- // Down or right
983
+ if (diff > 0) {
984
+ // Down, Right or Page Down key
988
985
  this.focusDate(this.maxDate);
989
986
  } else {
990
- // Up or left
987
+ // Up, Left or Page Up key
991
988
  this.focusDate(this.minDate);
992
989
  }
993
990
  } else {
994
991
  // Move to closest allowed date
995
- this._focusClosestDate(focus);
992
+ this._focusClosestDate(this.focusedDate);
996
993
  }
997
994
  }
998
995
 
999
- _moveFocusByMonths(months) {
1000
- const focus = this.focusedDate;
1001
- const dateToFocus = new Date(0, 0);
1002
- dateToFocus.setFullYear(focus.getFullYear());
1003
- dateToFocus.setMonth(focus.getMonth() + months);
996
+ _getDateDiff(months, days) {
997
+ const date = new Date(0, 0);
998
+ date.setFullYear(this.focusedDate.getFullYear());
999
+ date.setMonth(this.focusedDate.getMonth() + months);
1000
+ if (days) {
1001
+ date.setDate(this.focusedDate.getDate() + days);
1002
+ }
1003
+ return date;
1004
+ }
1005
+
1006
+ _moveFocusByDays(days) {
1007
+ const dateToFocus = this._getDateDiff(0, days);
1008
+
1009
+ this._focusAllowedDate(dateToFocus, days, false);
1010
+ }
1004
1011
 
1012
+ _moveFocusByMonths(months) {
1013
+ const dateToFocus = this._getDateDiff(months);
1005
1014
  const targetMonth = dateToFocus.getMonth();
1006
1015
 
1007
- dateToFocus.setDate((this._focusedMonthDate ||= focus.getDate()));
1016
+ if (!this._focusedMonthDate) {
1017
+ this._focusedMonthDate = this.focusedDate.getDate();
1018
+ }
1019
+
1020
+ dateToFocus.setDate(this._focusedMonthDate);
1021
+
1008
1022
  if (dateToFocus.getMonth() !== targetMonth) {
1009
1023
  dateToFocus.setDate(0);
1010
1024
  }
1011
1025
 
1012
- if (this._dateAllowed(dateToFocus, this.minDate, this.maxDate)) {
1013
- this.focusDate(dateToFocus, true);
1014
- } else if (this._dateAllowed(focus, this.minDate, this.maxDate)) {
1015
- // Move to min or max date
1016
- if (months > 0) {
1017
- // Pagedown
1018
- this.focusDate(this.maxDate);
1019
- } else {
1020
- // Pageup
1021
- this.focusDate(this.minDate);
1022
- }
1023
- } else {
1024
- // Move to closest allowed date
1025
- this._focusClosestDate(focus);
1026
- }
1026
+ this._focusAllowedDate(dateToFocus, months, true);
1027
1027
  }
1028
1028
 
1029
1029
  _moveFocusInsideMonth(focusedDate, property) {
@@ -1038,9 +1038,9 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
1038
1038
  dateToFocus.setDate(0);
1039
1039
  }
1040
1040
 
1041
- if (this._dateAllowed(dateToFocus, this.minDate, this.maxDate)) {
1041
+ if (this._dateAllowed(dateToFocus)) {
1042
1042
  this.focusDate(dateToFocus);
1043
- } else if (this._dateAllowed(focusedDate, this.minDate, this.maxDate)) {
1043
+ } else if (this._dateAllowed(focusedDate)) {
1044
1044
  // Move to minDate or maxDate
1045
1045
  this.focusDate(this[property]);
1046
1046
  } else {
@@ -1049,7 +1049,7 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
1049
1049
  }
1050
1050
  }
1051
1051
 
1052
- _dateAllowed(date, min, max) {
1052
+ _dateAllowed(date, min = this.minDate, max = this.maxDate) {
1053
1053
  return (!min || date >= min) && (!max || date <= max);
1054
1054
  }
1055
1055
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { Overlay } from '@vaadin/overlay/src/vaadin-overlay.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html } from '@polymer/polymer/lib/utils/html-tag.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/input-container/src/vaadin-input-container.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js';
@@ -8,6 +8,7 @@ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
8
  import { timeOut } from '@vaadin/component-base/src/async.js';
9
9
  import { isFirefox } from '@vaadin/component-base/src/browser-utils.js';
10
10
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
11
+ import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
11
12
 
12
13
  /**
13
14
  * @extends HTMLElement
@@ -329,8 +330,7 @@ export class InfiniteScroller extends PolymerElement {
329
330
  itemWrapper.style.height = `${this.itemHeight}px`;
330
331
  itemWrapper.instance = {};
331
332
 
332
- const contentId = (InfiniteScroller._contentIndex = InfiniteScroller._contentIndex + 1 || 0);
333
- const slotName = `vaadin-infinite-scroller-item-content-${contentId}`;
333
+ const slotName = `vaadin-infinite-scroller-item-content-${generateUniqueId()}`;
334
334
 
335
335
  const slot = document.createElement('slot');
336
336
  slot.setAttribute('name', slotName);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@polymer/polymer/lib/elements/dom-repeat.js';