@vaadin/vaadin-date-picker 4.4.2 → 4.4.4

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
@@ -10,7 +10,7 @@
10
10
  "repository": "vaadin/vaadin-date-picker",
11
11
  "homepage": "https://vaadin.com/components",
12
12
  "name": "@vaadin/vaadin-date-picker",
13
- "version": "4.4.2",
13
+ "version": "4.4.4",
14
14
  "main": "vaadin-date-picker.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -25,8 +25,6 @@
25
25
  "theme"
26
26
  ],
27
27
  "resolutions": {
28
- "es-abstract": "1.17.6",
29
- "@types/doctrine": "0.0.3",
30
28
  "inherits": "2.0.3",
31
29
  "samsam": "1.1.3",
32
30
  "supports-color": "3.1.2",
@@ -47,10 +45,9 @@
47
45
  "@vaadin/vaadin-material-styles": "^1.3.2",
48
46
  "@vaadin/vaadin-element-mixin": "^2.4.1"
49
47
  },
50
- "scripts": {
51
- "generate-typings": "gen-typescript-declarations --outDir . --verify"
52
- },
53
- "devDependencies": {
48
+ "devDependencies": {
49
+ "@web-padawan/gen-typescript-declarations": "^1.6.2",
50
+ "web-component-tester": "6.9.2",
54
51
  "@polymer/iron-component-page": "^4.0.0",
55
52
  "@polymer/iron-form": "^3.0.0",
56
53
  "@polymer/iron-icon": "^3.0.0",
@@ -62,5 +59,9 @@
62
59
  "@vaadin/vaadin-demo-helpers": "^3.1.0",
63
60
  "@vaadin/vaadin-custom-field": "^1.0.0",
64
61
  "@vaadin/vaadin-dialog": "^2.2.1"
62
+ },
63
+ "scripts": {
64
+ "generate-typings": "gen-typescript-declarations --outDir . --verify",
65
+ "test": "wct --npm"
65
66
  }
66
67
  }
@@ -295,6 +295,18 @@ class DatePickerOverlayContentElement extends
295
295
  return this.getAttribute('dir') === 'rtl';
296
296
  }
297
297
 
298
+ /**
299
+ * Whether to scroll to a sub-month position when scrolling to a date.
300
+ * This is active if the month scroller is not large enough to fit a
301
+ * full month. In that case we want to scroll to a position between
302
+ * two months in order to have the focused date in the visible area.
303
+ * @returns {boolean} whether to use sub-month scrolling
304
+ * @private
305
+ */
306
+ get __useSubMonthScrolling() {
307
+ return this.$.monthScroller.clientHeight < this.$.monthScroller.itemHeight + this.$.monthScroller.bufferOffset;
308
+ }
309
+
298
310
  ready() {
299
311
  super.ready();
300
312
  this.setAttribute('tabindex', 0);
@@ -356,7 +368,9 @@ class DatePickerOverlayContentElement extends
356
368
  * Scrolls the list to the given Date.
357
369
  */
358
370
  scrollToDate(date, animate) {
359
- this._scrollToPosition(this._differenceInMonths(date, this._originDate), animate);
371
+ const offset = this.__useSubMonthScrolling ? this._calculateWeekScrollOffset(date) : 0;
372
+ this._scrollToPosition(this._differenceInMonths(date, this._originDate) + offset, animate);
373
+ this.$.monthScroller.forceUpdate();
360
374
  }
361
375
 
362
376
  _focusedDateChanged(focusedDate) {
@@ -376,20 +390,64 @@ class DatePickerOverlayContentElement extends
376
390
  /**
377
391
  * Scrolls the month and year scrollers enough to reveal the given date.
378
392
  */
379
- revealDate(date) {
380
- if (date) {
381
- var diff = this._differenceInMonths(date, this._originDate);
382
- var scrolledAboveViewport = this.$.monthScroller.position > diff;
393
+ revealDate(date, animate = true) {
394
+ if (!date) {
395
+ return;
396
+ }
397
+ const diff = this._differenceInMonths(date, this._originDate);
398
+ // If scroll area does not fit the full month, then always scroll with an offset to
399
+ // approximately display the week of the date
400
+ if (this.__useSubMonthScrolling) {
401
+ const offset = this._calculateWeekScrollOffset(date);
402
+ this._scrollToPosition(diff + offset, animate);
403
+ return;
404
+ }
405
+
406
+ // Otherwise determine if we need to scroll to make the month of the date visible
407
+ const scrolledAboveViewport = this.$.monthScroller.position > diff;
383
408
 
384
- var visibleItems = this.$.monthScroller.clientHeight / this.$.monthScroller.itemHeight;
385
- var scrolledBelowViewport = this.$.monthScroller.position + visibleItems - 1 < diff;
409
+ const visibleArea = Math.max(
410
+ this.$.monthScroller.itemHeight,
411
+ this.$.monthScroller.clientHeight - this.$.monthScroller.bufferOffset * 2
412
+ );
413
+ const visibleItems = visibleArea / this.$.monthScroller.itemHeight;
414
+ const scrolledBelowViewport = this.$.monthScroller.position + visibleItems - 1 < diff;
386
415
 
387
- if (scrolledAboveViewport) {
388
- this._scrollToPosition(diff, true);
389
- } else if (scrolledBelowViewport) {
390
- this._scrollToPosition(diff - visibleItems + 1, true);
416
+ if (scrolledAboveViewport) {
417
+ this._scrollToPosition(diff, animate);
418
+ } else if (scrolledBelowViewport) {
419
+ this._scrollToPosition(diff - visibleItems + 1, animate);
420
+ }
421
+ }
422
+
423
+ /**
424
+ * Calculates an offset to be added to the month scroll position
425
+ * when using sub-month scrolling, in order ensure that the week
426
+ * that the date is in is visible even for small scroll areas.
427
+ * As the month scroller uses a month as minimal scroll unit
428
+ * (a value of `1` equals one month), we can not exactly identify
429
+ * the position of a specific week. This is a best effort
430
+ * implementation based on manual testing.
431
+ * @param date the date for which to calculate the offset
432
+ * @returns {number} the offset
433
+ * @private
434
+ */
435
+ _calculateWeekScrollOffset(date) {
436
+ // Get first day of month
437
+ const temp = new Date(0, 0);
438
+ temp.setFullYear(date.getFullYear());
439
+ temp.setMonth(date.getMonth());
440
+ temp.setDate(1);
441
+ // Determine week (=row index) of date within the month
442
+ let week = 0;
443
+ while (temp.getDate() < date.getDate()) {
444
+ temp.setDate(temp.getDate() + 1);
445
+ if (temp.getDay() === this.i18n.firstDayOfWeek) {
446
+ week += 1;
391
447
  }
392
448
  }
449
+ // Calculate magic number that approximately keeps the week visible
450
+ return week / 6;
393
451
  }
394
452
 
395
453
  _onOverlayFocus() {
@@ -147,7 +147,7 @@ class DatePickerElement extends
147
147
  }
148
148
 
149
149
  static get version() {
150
- return '4.4.2';
150
+ return '4.4.4';
151
151
  }
152
152
 
153
153
  static get properties() {
@@ -143,6 +143,18 @@ class InfiniteScrollerElement extends PolymerElement {
143
143
  }
144
144
  }
145
145
 
146
+ /**
147
+ * Force the scroller to update clones after a reset, without
148
+ * waiting for the debouncer to resolve.
149
+ */
150
+ forceUpdate() {
151
+ if (this._debouncerUpdateClones) {
152
+ this._buffers[0].updated = this._buffers[1].updated = false;
153
+ this._updateClones();
154
+ this._debouncerUpdateClones.cancel();
155
+ }
156
+ }
157
+
146
158
  _activated(active) {
147
159
  if (active && !this._initialized) {
148
160
  this._createPool();
@@ -187,9 +199,9 @@ class InfiniteScrollerElement extends PolymerElement {
187
199
  }
188
200
 
189
201
  // Check if we scrolled enough to translate the buffer positions.
190
- var bufferOffset = this.root.querySelector('.buffer').offsetTop;
191
- var upperThresholdReached = scrollTop > this._buffers[1].translateY + this.itemHeight + bufferOffset;
192
- var lowerThresholdReached = scrollTop < this._buffers[0].translateY + this.itemHeight + bufferOffset;
202
+ const offset = this.itemHeight + this.bufferOffset;
203
+ const upperThresholdReached = scrollTop > this._buffers[1].translateY + offset;
204
+ const lowerThresholdReached = scrollTop < this._buffers[0].translateY + offset;
193
205
 
194
206
  if (upperThresholdReached || lowerThresholdReached) {
195
207
  this._translateBuffer(lowerThresholdReached);
@@ -241,6 +253,13 @@ class InfiniteScrollerElement extends PolymerElement {
241
253
 
242
254
  }
243
255
 
256
+ /**
257
+ * @return {number}
258
+ */
259
+ get bufferOffset() {
260
+ return this._buffers[0].offsetTop;
261
+ }
262
+
244
263
  /**
245
264
  * @private
246
265
  */
@@ -36,7 +36,7 @@ const $_documentContainer = html`<dom-module id="lumo-date-picker-overlay-conten
36
36
  + var(--lumo-size-m) * 6
37
37
  + var(--lumo-space-s)
38
38
  );
39
- --vaadin-infinite-scroller-buffer-offset: 20%;
39
+ --vaadin-infinite-scroller-buffer-offset: 10%;
40
40
  -webkit-mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
41
41
  mask-image: linear-gradient(transparent, #000 10%, #000 85%, transparent);
42
42
  position: relative;