@everymatrix/helper-filters 0.1.2 → 0.1.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-979fa60b.js');
5
+ const index = require('./index-d16cebbc.js');
6
6
 
7
7
  const DEFAULT_LANGUAGE = 'en';
8
8
  const SUPPORTED_LANGUAGES = ['ro', 'en'];
@@ -17,7 +17,8 @@ const TRANSLATIONS = {
17
17
  filterDateRangePlaceholder: 'Date Range',
18
18
  filterModalButton: 'Search',
19
19
  filterFromCalendar: 'From',
20
- filterToCalendar: 'To'
20
+ filterToCalendar: 'To',
21
+ filterOrDate: 'or search by date'
21
22
  },
22
23
  ro: {
23
24
  filterOpen: 'Filtrare',
@@ -27,7 +28,8 @@ const TRANSLATIONS = {
27
28
  filterTicketPlaceholder: 'Cauta ID bilet',
28
29
  filterDrawPlaceholder: 'Cauta ID draw',
29
30
  filterDateRangePlaceholder: 'Perioada',
30
- filterModalButton: 'Cauta'
31
+ filterModalButton: 'Cauta',
32
+ filterOrDate: 'sau cauta dupa data'
31
33
  },
32
34
  };
33
35
  const translate$1 = (key, customLang) => {
@@ -42,7 +44,7 @@ const translate$1 = (key, customLang) => {
42
44
  */
43
45
  class Lumo extends HTMLElement {
44
46
  static get version() {
45
- return '23.1.5';
47
+ return '23.2.0';
46
48
  }
47
49
  }
48
50
 
@@ -98,7 +100,7 @@ const ThemePropertyMixin = (superClass) =>
98
100
  * **NOTE:** Extending the mixin only provides the property for binding,
99
101
  * and does not make the propagation alone.
100
102
  *
101
- * See [Styling Components: Sub-components](https://vaadin.com/docs/latest/ds/customization/styling-components/#sub-components).
103
+ * See [Styling Components: Sub-components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components/#sub-components).
102
104
  * page for more information.
103
105
  *
104
106
  * @deprecated The `theme` property is not supposed for public use and will be dropped in Vaadin 24.
@@ -123,7 +125,7 @@ const ThemePropertyMixin = (superClass) =>
123
125
  * **NOTE:** Extending the mixin only provides the property for binding,
124
126
  * and does not make the propagation alone.
125
127
  *
126
- * See [Styling Components: Sub-components](https://vaadin.com/docs/latest/ds/customization/styling-components/#sub-components).
128
+ * See [Styling Components: Sub-components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components/#sub-components).
127
129
  * page for more information.
128
130
  *
129
131
  * @protected
@@ -228,9 +230,9 @@ function matchesThemeFor(themeFor, tagName) {
228
230
  */
229
231
  function getIncludePriority(moduleName = '') {
230
232
  let includePriority = 0;
231
- if (moduleName.indexOf('lumo-') === 0 || moduleName.indexOf('material-') === 0) {
233
+ if (moduleName.startsWith('lumo-') || moduleName.startsWith('material-')) {
232
234
  includePriority = 1;
233
- } else if (moduleName.indexOf('vaadin-') === 0) {
235
+ } else if (moduleName.startsWith('vaadin-')) {
234
236
  includePriority = 2;
235
237
  }
236
238
  return includePriority;
@@ -10115,6 +10117,38 @@ const ControllerMixin = dedupingMixin(
10115
10117
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
10116
10118
  */
10117
10119
 
10120
+ // We consider the keyboard to be active if the window has received a keydown
10121
+ // event since the last mousedown event.
10122
+ let keyboardActive = false;
10123
+
10124
+ // Listen for top-level keydown and mousedown events.
10125
+ // Use capture phase so we detect events even if they're handled.
10126
+ window.addEventListener(
10127
+ 'keydown',
10128
+ () => {
10129
+ keyboardActive = true;
10130
+ },
10131
+ { capture: true },
10132
+ );
10133
+
10134
+ window.addEventListener(
10135
+ 'mousedown',
10136
+ () => {
10137
+ keyboardActive = false;
10138
+ },
10139
+ { capture: true },
10140
+ );
10141
+
10142
+ /**
10143
+ * Returns true if the window has received a keydown
10144
+ * event since the last mousedown event.
10145
+ *
10146
+ * @return {boolean}
10147
+ */
10148
+ function isKeyboardActive() {
10149
+ return keyboardActive;
10150
+ }
10151
+
10118
10152
  /**
10119
10153
  * Returns true if the element is hidden directly with `display: none` or `visibility: hidden`,
10120
10154
  * false otherwise.
@@ -10555,7 +10589,7 @@ class FocusTrapController {
10555
10589
  * ---|---|---
10556
10590
  * `--vaadin-overlay-viewport-bottom` | Bottom offset of the visible viewport area | `0` or detected offset
10557
10591
  *
10558
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
10592
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
10559
10593
  *
10560
10594
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
10561
10595
  * @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
@@ -12825,7 +12859,7 @@ const registered = new Set();
12825
12859
  const ElementMixin = (superClass) =>
12826
12860
  class VaadinElementMixin extends DirMixin(superClass) {
12827
12861
  static get version() {
12828
- return '23.1.5';
12862
+ return '23.2.0';
12829
12863
  }
12830
12864
 
12831
12865
  /** @protected */
@@ -13123,7 +13157,7 @@ function _handleNative(ev) {
13123
13157
  }
13124
13158
  if (!ev[HANDLED_OBJ]) {
13125
13159
  ev[HANDLED_OBJ] = {};
13126
- if (type.slice(0, 5) === 'touch') {
13160
+ if (type.startsWith('touch')) {
13127
13161
  const t = ev.changedTouches[0];
13128
13162
  if (type === 'touchstart') {
13129
13163
  // Only handle the first finger
@@ -13982,28 +14016,6 @@ const ActiveMixin = (superclass) =>
13982
14016
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
13983
14017
  */
13984
14018
 
13985
- // We consider the keyboard to be active if the window has received a keydown
13986
- // event since the last mousedown event.
13987
- let keyboardActive = false;
13988
-
13989
- // Listen for top-level keydown and mousedown events.
13990
- // Use capture phase so we detect events even if they're handled.
13991
- window.addEventListener(
13992
- 'keydown',
13993
- () => {
13994
- keyboardActive = true;
13995
- },
13996
- { capture: true },
13997
- );
13998
-
13999
- window.addEventListener(
14000
- 'mousedown',
14001
- () => {
14002
- keyboardActive = false;
14003
- },
14004
- { capture: true },
14005
- );
14006
-
14007
14019
  /**
14008
14020
  * A mixin to handle `focused` and `focus-ring` attributes based on focus.
14009
14021
  *
@@ -14017,7 +14029,7 @@ const FocusMixin = dedupingMixin(
14017
14029
  * @return {boolean}
14018
14030
  */
14019
14031
  get _keyboardActive() {
14020
- return keyboardActive;
14032
+ return isKeyboardActive();
14021
14033
  }
14022
14034
 
14023
14035
  /** @protected */
@@ -14281,7 +14293,7 @@ const ButtonMixin = (superClass) =>
14281
14293
  * `focus-ring` | Set when the button is focused using the keyboard.
14282
14294
  * `focused` | Set when the button is focused.
14283
14295
  *
14284
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
14296
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
14285
14297
  *
14286
14298
  * @extends HTMLElement
14287
14299
  * @mixes ButtonMixin
@@ -14363,7 +14375,6 @@ registerStyles(
14363
14375
  i$1`
14364
14376
  :host {
14365
14377
  position: relative;
14366
- background-color: transparent;
14367
14378
  /* Background for the year scroller, placed here as we are using a mask image on the actual years part */
14368
14379
  background-image: linear-gradient(var(--lumo-shade-5pct), var(--lumo-shade-5pct));
14369
14380
  background-size: 57px 100%;
@@ -14471,17 +14482,10 @@ registerStyles(
14471
14482
 
14472
14483
  [part='toolbar'] {
14473
14484
  padding: var(--lumo-space-s);
14474
- box-shadow: 0 -1px 0 0 var(--lumo-contrast-10pct);
14475
14485
  border-bottom-left-radius: var(--lumo-border-radius-l);
14476
14486
  margin-right: 57px;
14477
14487
  }
14478
14488
 
14479
- @supports (mask-image: linear-gradient(#000, #000)) or (-webkit-mask-image: linear-gradient(#000, #000)) {
14480
- [part='toolbar'] {
14481
- box-shadow: none;
14482
- }
14483
- }
14484
-
14485
14489
  /* Today and Cancel buttons */
14486
14490
 
14487
14491
  [part='toolbar'] [part\$='button'] {
@@ -14514,8 +14518,6 @@ registerStyles(
14514
14518
  /* Very narrow screen (year scroller initially hidden) */
14515
14519
 
14516
14520
  [part='years-toggle-button'] {
14517
- position: relative;
14518
- right: auto;
14519
14521
  display: flex;
14520
14522
  align-items: center;
14521
14523
  height: var(--lumo-size-s);
@@ -14533,10 +14535,6 @@ registerStyles(
14533
14535
  color: var(--lumo-primary-contrast-color);
14534
14536
  }
14535
14537
 
14536
- [part='years-toggle-button']::before {
14537
- content: none;
14538
- }
14539
-
14540
14538
  /* TODO magic number (same as used for iron-media-query in vaadin-date-picker-overlay-content) */
14541
14539
  @media screen and (max-width: 374px) {
14542
14540
  :host {
@@ -14712,9 +14710,9 @@ registerStyles(
14712
14710
  { moduleId: 'lumo-month-calendar' },
14713
14711
  );
14714
14712
 
14715
- const $_documentContainer$1 = document.createElement('template');
14713
+ const template$1 = document.createElement('template');
14716
14714
 
14717
- $_documentContainer$1.innerHTML = `
14715
+ template$1.innerHTML = `
14718
14716
  <style>
14719
14717
  @keyframes vaadin-date-picker-month-calendar-focus-date {
14720
14718
  50% {
@@ -14724,7 +14722,7 @@ $_documentContainer$1.innerHTML = `
14724
14722
  </style>
14725
14723
  `;
14726
14724
 
14727
- document.head.appendChild($_documentContainer$1.content);
14725
+ document.head.appendChild(template$1.content);
14728
14726
 
14729
14727
  /**
14730
14728
  * @license
@@ -14732,9 +14730,9 @@ document.head.appendChild($_documentContainer$1.content);
14732
14730
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
14733
14731
  */
14734
14732
 
14735
- const $_documentContainer = document.createElement('template');
14733
+ const template = document.createElement('template');
14736
14734
 
14737
- $_documentContainer.innerHTML = `
14735
+ template.innerHTML = `
14738
14736
  <style>
14739
14737
  @font-face {
14740
14738
  font-family: 'lumo-icons';
@@ -14790,7 +14788,7 @@ $_documentContainer.innerHTML = `
14790
14788
  </style>
14791
14789
  `;
14792
14790
 
14793
- document.head.appendChild($_documentContainer.content);
14791
+ document.head.appendChild(template.content);
14794
14792
 
14795
14793
  /**
14796
14794
  * @license
@@ -15357,6 +15355,57 @@ function getAncestorRootNodes(node) {
15357
15355
  return result;
15358
15356
  }
15359
15357
 
15358
+ /**
15359
+ * @param {string} value
15360
+ * @return {Set<string>}
15361
+ */
15362
+ function deserializeAttributeValue(value) {
15363
+ if (!value) {
15364
+ return new Set();
15365
+ }
15366
+
15367
+ return new Set(value.split(' '));
15368
+ }
15369
+
15370
+ /**
15371
+ * @param {Set<string>} values
15372
+ * @return {string}
15373
+ */
15374
+ function serializeAttributeValue(values) {
15375
+ return [...values].join(' ');
15376
+ }
15377
+
15378
+ /**
15379
+ * Adds a value to an attribute containing space-delimited values.
15380
+ *
15381
+ * @param {HTMLElement} element
15382
+ * @param {string} attr
15383
+ * @param {string} value
15384
+ */
15385
+ function addValueToAttribute(element, attr, value) {
15386
+ const values = deserializeAttributeValue(element.getAttribute(attr));
15387
+ values.add(value);
15388
+ element.setAttribute(attr, serializeAttributeValue(values));
15389
+ }
15390
+
15391
+ /**
15392
+ * Removes a value from an attribute containing space-delimited values.
15393
+ * If the value is the last one, the whole attribute is removed.
15394
+ *
15395
+ * @param {HTMLElement} element
15396
+ * @param {string} attr
15397
+ * @param {string} value
15398
+ */
15399
+ function removeValueFromAttribute(element, attr, value) {
15400
+ const values = deserializeAttributeValue(element.getAttribute(attr));
15401
+ values.delete(value);
15402
+ if (values.size === 0) {
15403
+ element.removeAttribute(attr);
15404
+ return;
15405
+ }
15406
+ element.setAttribute(attr, serializeAttributeValue(values));
15407
+ }
15408
+
15360
15409
  /**
15361
15410
  * @license
15362
15411
  * Copyright (c) 2017 - 2022 Vaadin Ltd.
@@ -17081,7 +17130,9 @@ class MonthCalendar extends FocusMixin(ThemableMixin(PolymerElement)) {
17081
17130
 
17082
17131
  _onMonthGridTouchStart() {
17083
17132
  this._notTapping = false;
17084
- setTimeout(() => (this._notTapping = true), 300);
17133
+ setTimeout(() => {
17134
+ this._notTapping = true;
17135
+ }, 300);
17085
17136
  }
17086
17137
 
17087
17138
  _dateAdd(date, delta) {
@@ -17416,7 +17467,7 @@ class InfiniteScroller extends PolymerElement {
17416
17467
  // Once the first set of items start fading in, stamp the rest
17417
17468
  this._buffers.forEach((buffer) => {
17418
17469
  [].forEach.call(buffer.children, (insertionPoint) => this._ensureStampedInstance(insertionPoint._itemWrapper));
17419
- }, this);
17470
+ });
17420
17471
 
17421
17472
  if (!this._buffers[0].translateY) {
17422
17473
  this._reset();
@@ -17579,7 +17630,7 @@ class InfiniteScroller extends PolymerElement {
17579
17630
  }
17580
17631
  }, 1); // Wait for first reset
17581
17632
  }
17582
- }, this);
17633
+ });
17583
17634
 
17584
17635
  setTimeout(() => {
17585
17636
  afterNextRender(this, this._finishInit.bind(this));
@@ -17617,7 +17668,7 @@ class InfiniteScroller extends PolymerElement {
17617
17668
  });
17618
17669
  buffer.updated = true;
17619
17670
  }
17620
- }, this);
17671
+ });
17621
17672
  }
17622
17673
 
17623
17674
  _isVisible(element, container) {
@@ -17716,7 +17767,6 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
17716
17767
  height: 100%;
17717
17768
  width: 100%;
17718
17769
  outline: none;
17719
- background: #fff;
17720
17770
  }
17721
17771
 
17722
17772
  [part='overlay-header'] {
@@ -17734,22 +17784,14 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
17734
17784
  flex-grow: 1;
17735
17785
  }
17736
17786
 
17737
- [part='clear-button']:not([showclear]) {
17738
- display: none;
17787
+ [hidden] {
17788
+ display: none !important;
17739
17789
  }
17740
17790
 
17741
17791
  [part='years-toggle-button'] {
17742
17792
  display: flex;
17743
17793
  }
17744
17794
 
17745
- [part='years-toggle-button'][desktop] {
17746
- display: none;
17747
- }
17748
-
17749
- :host(:not([years-visible])) [part='years-toggle-button']::before {
17750
- transform: rotate(180deg);
17751
- }
17752
-
17753
17795
  #scrollers {
17754
17796
  display: flex;
17755
17797
  height: 100%;
@@ -17823,27 +17865,14 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
17823
17865
  z-index: 2;
17824
17866
  flex-shrink: 0;
17825
17867
  }
17826
-
17827
- [part~='overlay-header']:not([desktop]) {
17828
- padding-bottom: 40px;
17829
- }
17830
-
17831
- [part~='years-toggle-button'] {
17832
- position: absolute;
17833
- top: auto;
17834
- right: 8px;
17835
- bottom: 0;
17836
- z-index: 1;
17837
- padding: 8px;
17838
- }
17839
17868
  </style>
17840
17869
 
17841
17870
  <div part="overlay-header" on-touchend="_preventDefault" desktop$="[[_desktopMode]]" aria-hidden="true">
17842
17871
  <div part="label">[[_formatDisplayed(selectedDate, i18n.formatDate, label)]]</div>
17843
- <div part="clear-button" showclear$="[[_showClear(selectedDate)]]"></div>
17872
+ <div part="clear-button" hidden$="[[!selectedDate]]"></div>
17844
17873
  <div part="toggle-button"></div>
17845
17874
 
17846
- <div part="years-toggle-button" desktop$="[[_desktopMode]]" aria-hidden="true">
17875
+ <div part="years-toggle-button" hidden$="[[_desktopMode]]" aria-hidden="true">
17847
17876
  [[_yearAfterXMonths(_visibleMonthIndex)]]
17848
17877
  </div>
17849
17878
  </div>
@@ -17929,6 +17958,7 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
17929
17958
  */
17930
17959
  selectedDate: {
17931
17960
  type: Date,
17961
+ value: null,
17932
17962
  },
17933
17963
 
17934
17964
  /**
@@ -18004,10 +18034,12 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18004
18034
  return this.getAttribute('dir') === 'rtl';
18005
18035
  }
18006
18036
 
18037
+ get calendars() {
18038
+ return [...this.shadowRoot.querySelectorAll('vaadin-month-calendar')];
18039
+ }
18040
+
18007
18041
  get focusableDateElement() {
18008
- return [...this.shadowRoot.querySelectorAll('vaadin-month-calendar')]
18009
- .map((calendar) => calendar.focusableDateElement)
18010
- .find(Boolean);
18042
+ return this.calendars.map((calendar) => calendar.focusableDateElement).find(Boolean);
18011
18043
  }
18012
18044
 
18013
18045
  ready() {
@@ -18015,7 +18047,6 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18015
18047
 
18016
18048
  this.setAttribute('role', 'dialog');
18017
18049
 
18018
- addListener(this, 'tap', this._stopPropagation);
18019
18050
  addListener(this.$.scrollers, 'track', this._track.bind(this));
18020
18051
  addListener(this.shadowRoot.querySelector('[part="clear-button"]'), 'tap', this._clear.bind(this));
18021
18052
  addListener(this.shadowRoot.querySelector('[part="today-button"]'), 'tap', this._onTodayTap.bind(this));
@@ -18137,7 +18168,9 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18137
18168
 
18138
18169
  _onYearScrollTouchStart() {
18139
18170
  this._notTapping = false;
18140
- setTimeout(() => (this._notTapping = true), 300);
18171
+ setTimeout(() => {
18172
+ this._notTapping = true;
18173
+ }, 300);
18141
18174
 
18142
18175
  this._repositionMonthScroller();
18143
18176
  }
@@ -18148,7 +18181,9 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18148
18181
 
18149
18182
  _doIgnoreTaps() {
18150
18183
  this._ignoreTaps = true;
18151
- this._debouncer = Debouncer$1.debounce(this._debouncer, timeOut.after(300), () => (this._ignoreTaps = false));
18184
+ this._debouncer = Debouncer$1.debounce(this._debouncer, timeOut.after(300), () => {
18185
+ this._ignoreTaps = false;
18186
+ });
18152
18187
  }
18153
18188
 
18154
18189
  _formatDisplayed(date, formatDate, label) {
@@ -18179,10 +18214,6 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18179
18214
  this.scrollToDate(new Date(), true);
18180
18215
  }
18181
18216
 
18182
- _showClear(selectedDate) {
18183
- return !!selectedDate;
18184
- }
18185
-
18186
18217
  _onYearTap(e) {
18187
18218
  if (!this._ignoreTaps && !this._notTapping) {
18188
18219
  const scrollDelta =
@@ -18208,6 +18239,11 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18208
18239
 
18209
18240
  this._targetPosition = targetPosition;
18210
18241
 
18242
+ let revealResolve;
18243
+ this._revealPromise = new Promise((resolve) => {
18244
+ revealResolve = resolve;
18245
+ });
18246
+
18211
18247
  // http://gizma.com/easing/
18212
18248
  const easingFunction = (t, b, c, d) => {
18213
18249
  t /= d / 2;
@@ -18248,7 +18284,9 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18248
18284
 
18249
18285
  this.$.monthScroller.position = this._targetPosition;
18250
18286
  this._targetPosition = undefined;
18251
- this.__tryFocusDate();
18287
+
18288
+ revealResolve();
18289
+ this._revealPromise = undefined;
18252
18290
  }
18253
18291
 
18254
18292
  setTimeout(this._repositionYearScroller.bind(this), 1);
@@ -18458,51 +18496,44 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18458
18496
  switch (section) {
18459
18497
  case 'calendar':
18460
18498
  if (event.shiftKey) {
18461
- // Return focus back to the input field.
18462
18499
  event.preventDefault();
18463
- this.__focusInput();
18500
+
18501
+ if (this.hasAttribute('fullscreen')) {
18502
+ // Trap focus in the overlay
18503
+ this.$.cancelButton.focus();
18504
+ } else {
18505
+ this.__focusInput();
18506
+ }
18464
18507
  }
18465
18508
  break;
18466
18509
  case 'today':
18467
18510
  if (event.shiftKey) {
18468
- // Browser returns focus back to the calendar.
18469
- // We need to move the scroll to focused date.
18470
- setTimeout(() => this.revealDate(this.focusedDate), 1);
18511
+ event.preventDefault();
18512
+ this.focusDateElement();
18471
18513
  }
18472
18514
  break;
18473
18515
  case 'cancel':
18474
18516
  if (!event.shiftKey) {
18475
- // Return focus back to the input field.
18476
18517
  event.preventDefault();
18477
- this.__focusInput();
18518
+
18519
+ if (this.hasAttribute('fullscreen')) {
18520
+ // Trap focus in the overlay
18521
+ this.focusDateElement();
18522
+ } else {
18523
+ this.__focusInput();
18524
+ }
18478
18525
  }
18479
18526
  break;
18480
18527
  }
18481
18528
  }
18482
18529
 
18483
18530
  __onTodayButtonKeyDown(event) {
18484
- if (this.hasAttribute('fullscreen')) {
18485
- // Do not prevent closing on Esc
18486
- if (event.key !== 'Escape') {
18487
- event.stopPropagation();
18488
- }
18489
- return;
18490
- }
18491
-
18492
18531
  if (event.key === 'Tab') {
18493
18532
  this._onTabKeyDown(event, 'today');
18494
18533
  }
18495
18534
  }
18496
18535
 
18497
18536
  __onCancelButtonKeyDown(event) {
18498
- if (this.hasAttribute('fullscreen')) {
18499
- // Do not prevent closing on Esc
18500
- if (event.key !== 'Escape') {
18501
- event.stopPropagation();
18502
- }
18503
- return;
18504
- }
18505
-
18506
18537
  if (event.key === 'Tab') {
18507
18538
  this._onTabKeyDown(event, 'cancel');
18508
18539
  }
@@ -18531,15 +18562,29 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18531
18562
  if (!keepMonth) {
18532
18563
  this._focusedMonthDate = dateToFocus.getDate();
18533
18564
  }
18534
- await this.focusDateElement();
18565
+ await this.focusDateElement(false);
18535
18566
  }
18536
18567
 
18537
- async focusDateElement() {
18568
+ async focusDateElement(reveal = true) {
18538
18569
  this.__pendingDateFocus = this.focusedDate;
18539
18570
 
18540
- await new Promise((resolve) => {
18541
- requestAnimationFrame(resolve);
18542
- });
18571
+ // Wait for `vaadin-month-calendar` elements to be rendered
18572
+ if (!this.calendars.length) {
18573
+ await new Promise((resolve) => {
18574
+ setTimeout(resolve);
18575
+ });
18576
+ }
18577
+
18578
+ // Reveal focused date unless it has been just set,
18579
+ // which triggers `revealDate()` in the observer.
18580
+ if (reveal) {
18581
+ this.revealDate(this.focusedDate);
18582
+ }
18583
+
18584
+ if (this._revealPromise) {
18585
+ // Wait for focused date to be scrolled into view.
18586
+ await this._revealPromise;
18587
+ }
18543
18588
 
18544
18589
  this.__tryFocusDate();
18545
18590
  }
@@ -18637,10 +18682,6 @@ class DatePickerOverlayContent extends ControllerMixin(ThemableMixin(DirMixin(Po
18637
18682
  todayMidnight.setDate(today.getDate());
18638
18683
  return this._dateAllowed(todayMidnight, min, max);
18639
18684
  }
18640
-
18641
- _stopPropagation(e) {
18642
- e.stopPropagation();
18643
- }
18644
18685
  }
18645
18686
 
18646
18687
  customElements.define(DatePickerOverlayContent.is, DatePickerOverlayContent);
@@ -18871,6 +18912,24 @@ const DelegateFocusMixin = dedupingMixin(
18871
18912
  },
18872
18913
  );
18873
18914
 
18915
+ /**
18916
+ * @license
18917
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
18918
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
18919
+ */
18920
+
18921
+ let uniqueId = 0;
18922
+
18923
+ /**
18924
+ * Returns a unique integer id.
18925
+ *
18926
+ * @return {number}
18927
+ */
18928
+ function generateUniqueId() {
18929
+ // eslint-disable-next-line no-plusplus
18930
+ return uniqueId++;
18931
+ }
18932
+
18874
18933
  /**
18875
18934
  * @license
18876
18935
  * Copyright (c) 2021 - 2022 Vaadin Ltd.
@@ -18891,24 +18950,21 @@ class SlotController extends EventTarget {
18891
18950
  */
18892
18951
  static generateId(slotName, host) {
18893
18952
  const prefix = slotName || 'default';
18894
-
18895
- // Support dash-case slot names e.g. "error-message"
18896
- const field = `${dashToCamelCase(prefix)}Id`;
18897
-
18898
- // Maintain the unique ID counter for a given prefix.
18899
- this[field] = 1 + this[field] || 0;
18900
-
18901
- return `${prefix}-${host.localName}-${this[field]}`;
18953
+ return `${prefix}-${host.localName}-${generateUniqueId()}`;
18902
18954
  }
18903
18955
 
18904
- constructor(host, slotName, slotFactory, slotInitializer) {
18956
+ constructor(host, slotName, slotFactory, slotInitializer, useUniqueId) {
18905
18957
  super();
18906
18958
 
18907
18959
  this.host = host;
18908
18960
  this.slotName = slotName;
18909
18961
  this.slotFactory = slotFactory;
18910
18962
  this.slotInitializer = slotInitializer;
18911
- this.defaultId = SlotController.generateId(slotName, host);
18963
+
18964
+ // Only generate the default ID if requested by the controller.
18965
+ if (useUniqueId) {
18966
+ this.defaultId = SlotController.generateId(slotName, host);
18967
+ }
18912
18968
  }
18913
18969
 
18914
18970
  hostConnected() {
@@ -19063,6 +19119,7 @@ class ErrorController extends SlotController {
19063
19119
 
19064
19120
  this.__updateHasError();
19065
19121
  },
19122
+ true,
19066
19123
  );
19067
19124
  }
19068
19125
 
@@ -19177,63 +19234,6 @@ class ErrorController extends SlotController {
19177
19234
  }
19178
19235
  }
19179
19236
 
19180
- /**
19181
- * @license
19182
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
19183
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
19184
- */
19185
-
19186
- /**
19187
- * @param {string} value
19188
- * @return {Set<string>}
19189
- */
19190
- function deserializeAttributeValue(value) {
19191
- if (!value) {
19192
- return new Set();
19193
- }
19194
-
19195
- return new Set(value.split(' '));
19196
- }
19197
-
19198
- /**
19199
- * @param {Set<string>} values
19200
- * @return {string}
19201
- */
19202
- function serializeAttributeValue(values) {
19203
- return [...values].join(' ');
19204
- }
19205
-
19206
- /**
19207
- * Adds a value to an attribute containing space-delimited values.
19208
- *
19209
- * @param {HTMLElement} element
19210
- * @param {string} attr
19211
- * @param {string} value
19212
- */
19213
- function addValueToAttribute(element, attr, value) {
19214
- const values = deserializeAttributeValue(element.getAttribute(attr));
19215
- values.add(value);
19216
- element.setAttribute(attr, serializeAttributeValue(values));
19217
- }
19218
-
19219
- /**
19220
- * Removes a value from an attribute containing space-delimited values.
19221
- * If the value is the last one, the whole attribute is removed.
19222
- *
19223
- * @param {HTMLElement} element
19224
- * @param {string} attr
19225
- * @param {string} value
19226
- */
19227
- function removeValueFromAttribute(element, attr, value) {
19228
- const values = deserializeAttributeValue(element.getAttribute(attr));
19229
- values.delete(value);
19230
- if (values.size === 0) {
19231
- element.removeAttribute(attr);
19232
- return;
19233
- }
19234
- element.setAttribute(attr, serializeAttributeValue(values));
19235
- }
19236
-
19237
19237
  /**
19238
19238
  * @license
19239
19239
  * Copyright (c) 2021 - 2022 Vaadin Ltd.
@@ -19408,7 +19408,7 @@ class FieldAriaController {
19408
19408
 
19409
19409
  /**
19410
19410
  * @license
19411
- * Copyright (c) 2021 Vaadin Ltd.
19411
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
19412
19412
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
19413
19413
  */
19414
19414
 
@@ -19418,7 +19418,7 @@ class FieldAriaController {
19418
19418
  class HelperController extends SlotController {
19419
19419
  constructor(host) {
19420
19420
  // Do not provide slot factory, as only create helper lazily.
19421
- super(host, 'helper');
19421
+ super(host, 'helper', null, null, true);
19422
19422
  }
19423
19423
 
19424
19424
  get helperId() {
@@ -19615,6 +19615,7 @@ class LabelController extends SlotController {
19615
19615
 
19616
19616
  this.__observeLabel(node);
19617
19617
  },
19618
+ true,
19618
19619
  );
19619
19620
  }
19620
19621
 
@@ -19821,6 +19822,12 @@ const LabelMixin = dedupingMixin(
19821
19822
  super();
19822
19823
 
19823
19824
  this._labelController = new LabelController(this);
19825
+ }
19826
+
19827
+ /** @protected */
19828
+ ready() {
19829
+ super.ready();
19830
+
19824
19831
  this.addController(this._labelController);
19825
19832
  }
19826
19833
 
@@ -19868,12 +19875,17 @@ const ValidateMixin = dedupingMixin(
19868
19875
  }
19869
19876
 
19870
19877
  /**
19871
- * Returns true if field is valid, and sets `invalid` based on the field validity.
19878
+ * Validates the field and sets the `invalid` property based on the result.
19879
+ *
19880
+ * The method fires a `validated` event with the result of the validation.
19872
19881
  *
19873
19882
  * @return {boolean} True if the value is valid.
19874
19883
  */
19875
19884
  validate() {
19876
- return !(this.invalid = !this.checkValidity());
19885
+ const isValid = this.checkValidity();
19886
+ this._setInvalid(!isValid);
19887
+ this.dispatchEvent(new CustomEvent('validated', { detail: { valid: isValid } }));
19888
+ return isValid;
19877
19889
  }
19878
19890
 
19879
19891
  /**
@@ -19884,6 +19896,35 @@ const ValidateMixin = dedupingMixin(
19884
19896
  checkValidity() {
19885
19897
  return !this.required || !!this.value;
19886
19898
  }
19899
+
19900
+ /**
19901
+ * @param {boolean} invalid
19902
+ * @protected
19903
+ */
19904
+ _setInvalid(invalid) {
19905
+ if (this._shouldSetInvalid(invalid)) {
19906
+ this.invalid = invalid;
19907
+ }
19908
+ }
19909
+
19910
+ /**
19911
+ * Override this method to define whether the given `invalid` state should be set.
19912
+ *
19913
+ * @param {boolean} _invalid
19914
+ * @return {boolean}
19915
+ * @protected
19916
+ */
19917
+ _shouldSetInvalid(_invalid) {
19918
+ return true;
19919
+ }
19920
+
19921
+ /**
19922
+ * Fired whenever the field is validated.
19923
+ *
19924
+ * @event validated
19925
+ * @param {Object} detail
19926
+ * @param {boolean} detail.valid the result of the validation.
19927
+ */
19887
19928
  },
19888
19929
  );
19889
19930
 
@@ -19972,10 +20013,6 @@ const FieldMixin = (superclass) =>
19972
20013
  this._helperController = new HelperController(this);
19973
20014
  this._errorController = new ErrorController(this);
19974
20015
 
19975
- this.addController(this._fieldAriaController);
19976
- this.addController(this._helperController);
19977
- this.addController(this._errorController);
19978
-
19979
20016
  this._labelController.addEventListener('label-changed', (event) => {
19980
20017
  const { hasLabel, node } = event.detail;
19981
20018
  this.__labelChanged(hasLabel, node);
@@ -19987,6 +20024,15 @@ const FieldMixin = (superclass) =>
19987
20024
  });
19988
20025
  }
19989
20026
 
20027
+ /** @protected */
20028
+ ready() {
20029
+ super.ready();
20030
+
20031
+ this.addController(this._fieldAriaController);
20032
+ this.addController(this._helperController);
20033
+ this.addController(this._errorController);
20034
+ }
20035
+
19990
20036
  /** @private */
19991
20037
  __helperChanged(hasHelper, helperNode) {
19992
20038
  if (hasHelper) {
@@ -20042,7 +20088,7 @@ const FieldMixin = (superclass) =>
20042
20088
  }
20043
20089
 
20044
20090
  /**
20045
- * @param {boolean} required
20091
+ * @param {boolean} invalid
20046
20092
  * @protected
20047
20093
  */
20048
20094
  _invalidChanged(invalid) {
@@ -20242,13 +20288,23 @@ const InputMixin = dedupingMixin(
20242
20288
  observer: '_valueChanged',
20243
20289
  notify: true,
20244
20290
  },
20291
+
20292
+ /**
20293
+ * When true, the input element has a non-empty value entered by the user.
20294
+ * @protected
20295
+ */
20296
+ _hasInputValue: {
20297
+ type: Boolean,
20298
+ value: false,
20299
+ observer: '_hasInputValueChanged',
20300
+ },
20245
20301
  };
20246
20302
  }
20247
20303
 
20248
20304
  constructor() {
20249
20305
  super();
20250
20306
 
20251
- this._boundOnInput = this._onInput.bind(this);
20307
+ this._boundOnInput = this.__onInput.bind(this);
20252
20308
  this._boundOnChange = this._onChange.bind(this);
20253
20309
  }
20254
20310
 
@@ -20263,6 +20319,7 @@ const InputMixin = dedupingMixin(
20263
20319
  * Add event listeners to the input element instance.
20264
20320
  * Override this method to add custom listeners.
20265
20321
  * @param {!HTMLElement} input
20322
+ * @protected
20266
20323
  */
20267
20324
  _addInputListeners(input) {
20268
20325
  input.addEventListener('input', this._boundOnInput);
@@ -20272,6 +20329,7 @@ const InputMixin = dedupingMixin(
20272
20329
  /**
20273
20330
  * Remove event listeners from the input element instance.
20274
20331
  * @param {!HTMLElement} input
20332
+ * @protected
20275
20333
  */
20276
20334
  _removeInputListeners(input) {
20277
20335
  input.removeEventListener('input', this._boundOnInput);
@@ -20285,7 +20343,6 @@ const InputMixin = dedupingMixin(
20285
20343
  * for example to skip this in certain conditions.
20286
20344
  * @param {string} value
20287
20345
  * @protected
20288
- * @override
20289
20346
  */
20290
20347
  _forwardInputValue(value) {
20291
20348
  // Value might be set before an input element is initialized.
@@ -20302,7 +20359,11 @@ const InputMixin = dedupingMixin(
20302
20359
  }
20303
20360
  }
20304
20361
 
20305
- /** @protected */
20362
+ /**
20363
+ * @param {HTMLElement | undefined} input
20364
+ * @param {HTMLElement | undefined} oldInput
20365
+ * @protected
20366
+ */
20306
20367
  _inputElementChanged(input, oldInput) {
20307
20368
  if (input) {
20308
20369
  this._addInputListeners(input);
@@ -20311,17 +20372,47 @@ const InputMixin = dedupingMixin(
20311
20372
  }
20312
20373
  }
20313
20374
 
20375
+ /**
20376
+ * Observer to notify about the change of private property.
20377
+ *
20378
+ * @private
20379
+ */
20380
+ _hasInputValueChanged(hasValue, oldHasValue) {
20381
+ if (hasValue || oldHasValue) {
20382
+ this.dispatchEvent(new CustomEvent('has-input-value-changed'));
20383
+ }
20384
+ }
20385
+
20386
+ /**
20387
+ * An input event listener used to update `_hasInputValue` property.
20388
+ * Do not override this method.
20389
+ *
20390
+ * @param {Event} event
20391
+ * @private
20392
+ */
20393
+ __onInput(event) {
20394
+ // In the case a custom web component is passed as `inputElement`,
20395
+ // the actual native input element, on which the event occurred,
20396
+ // can be inside shadow trees.
20397
+ const target = event.composedPath()[0];
20398
+ this._hasInputValue = target.value.length > 0;
20399
+ this._onInput(event);
20400
+ }
20401
+
20314
20402
  /**
20315
20403
  * An input event listener used to update the field value.
20316
- * Override this method with an actual implementation.
20317
- * @param {Event} _event
20404
+ *
20405
+ * @param {Event} event
20318
20406
  * @protected
20319
- * @override
20320
20407
  */
20321
20408
  _onInput(event) {
20409
+ // In the case a custom web component is passed as `inputElement`,
20410
+ // the actual native input element, on which the event occurred,
20411
+ // can be inside shadow trees.
20412
+ const target = event.composedPath()[0];
20322
20413
  // Ignore fake input events e.g. used by clear button.
20323
20414
  this.__userInput = event.isTrusted;
20324
- this.value = event.target.value;
20415
+ this.value = target.value;
20325
20416
  this.__userInput = false;
20326
20417
  }
20327
20418
 
@@ -20330,12 +20421,12 @@ const InputMixin = dedupingMixin(
20330
20421
  * Override this method with an actual implementation.
20331
20422
  * @param {Event} _event
20332
20423
  * @protected
20333
- * @override
20334
20424
  */
20335
20425
  _onChange(_event) {}
20336
20426
 
20337
20427
  /**
20338
20428
  * Toggle the has-value attribute based on the value property.
20429
+ *
20339
20430
  * @param {boolean} hasValue
20340
20431
  * @protected
20341
20432
  */
@@ -20348,10 +20439,9 @@ const InputMixin = dedupingMixin(
20348
20439
  * @param {string | undefined} newVal
20349
20440
  * @param {string | undefined} oldVal
20350
20441
  * @protected
20351
- * @override
20352
20442
  */
20353
20443
  _valueChanged(newVal, oldVal) {
20354
- this._toggleHasValue(newVal !== '' && newVal != null);
20444
+ this._toggleHasValue(this._hasValue);
20355
20445
 
20356
20446
  // Setting initial value to empty string, do nothing.
20357
20447
  if (newVal === '' && oldVal === undefined) {
@@ -20366,6 +20456,16 @@ const InputMixin = dedupingMixin(
20366
20456
  // Setting a value programmatically, sync it to input element.
20367
20457
  this._forwardInputValue(newVal);
20368
20458
  }
20459
+
20460
+ /**
20461
+ * Indicates whether the value is different from the default one.
20462
+ * Override if the `value` property has a type other than `string`.
20463
+ *
20464
+ * @protected
20465
+ */
20466
+ get _hasValue() {
20467
+ return this.value != null && this.value !== '';
20468
+ }
20369
20469
  },
20370
20470
  );
20371
20471
 
@@ -20437,26 +20537,32 @@ const InputConstraintsMixin = dedupingMixin(
20437
20537
  _createConstraintsObserver() {
20438
20538
  // This complex observer needs to be added dynamically instead of using `static get observers()`
20439
20539
  // to make it possible to tweak this behavior in classes that apply this mixin.
20440
- this._createMethodObserver(`_constraintsChanged(${this.constructor.constraints.join(', ')})`);
20540
+ this._createMethodObserver(`_constraintsChanged(stateTarget, ${this.constructor.constraints.join(', ')})`);
20441
20541
  }
20442
20542
 
20443
20543
  /**
20444
20544
  * Override this method to implement custom validation constraints.
20545
+ * @param {HTMLElement | undefined} stateTarget
20445
20546
  * @param {unknown[]} constraints
20446
20547
  * @protected
20447
20548
  */
20448
- _constraintsChanged(...constraints) {
20449
- // Prevent marking field as invalid when setting required state
20450
- // or any other constraint before a user has entered the value.
20451
- if (!this.invalid) {
20549
+ _constraintsChanged(stateTarget, ...constraints) {
20550
+ // The input element's validity cannot be determined until
20551
+ // all the necessary constraint attributes aren't set on it.
20552
+ if (!stateTarget) {
20452
20553
  return;
20453
20554
  }
20454
20555
 
20455
- if (this._hasValidConstraints(constraints)) {
20556
+ const hasConstraints = this._hasValidConstraints(constraints);
20557
+ const isLastConstraintRemoved = this.__previousHasConstraints && !hasConstraints;
20558
+
20559
+ if ((this._hasValue || this.invalid) && hasConstraints) {
20456
20560
  this.validate();
20457
- } else {
20458
- this.invalid = false;
20561
+ } else if (isLastConstraintRemoved) {
20562
+ this._setInvalid(false);
20459
20563
  }
20564
+
20565
+ this.__previousHasConstraints = hasConstraints;
20460
20566
  }
20461
20567
 
20462
20568
  /**
@@ -20512,6 +20618,22 @@ const InputControlMixin = (superclass) =>
20512
20618
  ) {
20513
20619
  static get properties() {
20514
20620
  return {
20621
+ /**
20622
+ * A pattern matched against individual characters the user inputs.
20623
+ *
20624
+ * When set, the field will prevent:
20625
+ * - `keydown` events if the entered key doesn't match `/^allowedCharPattern$/`
20626
+ * - `paste` events if the pasted text doesn't match `/^allowedCharPattern*$/`
20627
+ * - `drop` events if the dropped text doesn't match `/^allowedCharPattern*$/`
20628
+ *
20629
+ * For example, to allow entering only numbers and minus signs, use:
20630
+ * `allowedCharPattern = "[\\d-]"`
20631
+ */
20632
+ allowedCharPattern: {
20633
+ type: String,
20634
+ observer: '_allowedCharPatternChanged',
20635
+ },
20636
+
20515
20637
  /**
20516
20638
  * If true, the input text gets fully selected when the field is focused using click or touch / tap.
20517
20639
  */
@@ -20569,6 +20691,14 @@ const InputControlMixin = (superclass) =>
20569
20691
  return [...super.delegateAttrs, 'name', 'type', 'placeholder', 'readonly', 'invalid', 'title'];
20570
20692
  }
20571
20693
 
20694
+ constructor() {
20695
+ super();
20696
+
20697
+ this._boundOnPaste = this._onPaste.bind(this);
20698
+ this._boundOnDrop = this._onDrop.bind(this);
20699
+ this._boundOnBeforeInput = this._onBeforeInput.bind(this);
20700
+ }
20701
+
20572
20702
  /**
20573
20703
  * Any element extending this mixin is required to implement this getter.
20574
20704
  * It returns the reference to the clear button element.
@@ -20661,6 +20791,115 @@ const InputControlMixin = (superclass) =>
20661
20791
  this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
20662
20792
  }
20663
20793
 
20794
+ /**
20795
+ * Override a method from `InputMixin`.
20796
+ * @param {!HTMLElement} input
20797
+ * @protected
20798
+ * @override
20799
+ */
20800
+ _addInputListeners(input) {
20801
+ super._addInputListeners(input);
20802
+
20803
+ input.addEventListener('paste', this._boundOnPaste);
20804
+ input.addEventListener('drop', this._boundOnDrop);
20805
+ input.addEventListener('beforeinput', this._boundOnBeforeInput);
20806
+ }
20807
+
20808
+ /**
20809
+ * Override a method from `InputMixin`.
20810
+ * @param {!HTMLElement} input
20811
+ * @protected
20812
+ * @override
20813
+ */
20814
+ _removeInputListeners(input) {
20815
+ super._removeInputListeners(input);
20816
+
20817
+ input.removeEventListener('paste', this._boundOnPaste);
20818
+ input.removeEventListener('drop', this._boundOnDrop);
20819
+ input.removeEventListener('beforeinput', this._boundOnBeforeInput);
20820
+ }
20821
+
20822
+ /**
20823
+ * Override an event listener from `KeyboardMixin`.
20824
+ * @param {!KeyboardEvent} event
20825
+ * @protected
20826
+ * @override
20827
+ */
20828
+ _onKeyDown(event) {
20829
+ super._onKeyDown(event);
20830
+
20831
+ if (this.allowedCharPattern && !this.__shouldAcceptKey(event)) {
20832
+ event.preventDefault();
20833
+ this._markInputPrevented();
20834
+ }
20835
+ }
20836
+
20837
+ /** @protected */
20838
+ _markInputPrevented() {
20839
+ // Add input-prevented attribute for 200ms
20840
+ this.setAttribute('input-prevented', '');
20841
+ this._preventInputDebouncer = Debouncer$1.debounce(this._preventInputDebouncer, timeOut.after(200), () => {
20842
+ this.removeAttribute('input-prevented');
20843
+ });
20844
+ }
20845
+
20846
+ /** @private */
20847
+ __shouldAcceptKey(event) {
20848
+ return (
20849
+ event.metaKey ||
20850
+ event.ctrlKey ||
20851
+ !event.key || // Allow typing anything if event.key is not supported
20852
+ event.key.length !== 1 || // Allow "Backspace", "ArrowLeft" etc.
20853
+ this.__allowedCharRegExp.test(event.key)
20854
+ );
20855
+ }
20856
+
20857
+ /** @private */
20858
+ _onPaste(e) {
20859
+ if (this.allowedCharPattern) {
20860
+ const pastedText = e.clipboardData.getData('text');
20861
+ if (!this.__allowedTextRegExp.test(pastedText)) {
20862
+ e.preventDefault();
20863
+ this._markInputPrevented();
20864
+ }
20865
+ }
20866
+ }
20867
+
20868
+ /** @private */
20869
+ _onDrop(e) {
20870
+ if (this.allowedCharPattern) {
20871
+ const draggedText = e.dataTransfer.getData('text');
20872
+ if (!this.__allowedTextRegExp.test(draggedText)) {
20873
+ e.preventDefault();
20874
+ this._markInputPrevented();
20875
+ }
20876
+ }
20877
+ }
20878
+
20879
+ /** @private */
20880
+ _onBeforeInput(e) {
20881
+ // The `beforeinput` event covers all the cases for `allowedCharPattern`: keyboard, pasting and dropping,
20882
+ // but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
20883
+ // because it seems to be the only way to detect and prevent specific keys on mobile devices.
20884
+ // See https://github.com/vaadin/vaadin-text-field/issues/429
20885
+ if (this.allowedCharPattern && e.data && !this.__allowedTextRegExp.test(e.data)) {
20886
+ e.preventDefault();
20887
+ this._markInputPrevented();
20888
+ }
20889
+ }
20890
+
20891
+ /** @private */
20892
+ _allowedCharPatternChanged(charPattern) {
20893
+ if (charPattern) {
20894
+ try {
20895
+ this.__allowedCharRegExp = new RegExp(`^${charPattern}$`);
20896
+ this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`);
20897
+ } catch (e) {
20898
+ console.error(e);
20899
+ }
20900
+ }
20901
+ }
20902
+
20664
20903
  /**
20665
20904
  * Fired when the user commits a value change.
20666
20905
  *
@@ -20699,14 +20938,13 @@ class InputController extends SlotController {
20699
20938
  }
20700
20939
 
20701
20940
  // Ensure every instance has unique ID
20702
- const uniqueId = (InputController._uniqueInputId = 1 + InputController._uniqueInputId || 0);
20703
- host._inputId = `${host.localName}-${uniqueId}`;
20704
- node.id = host._inputId;
20941
+ node.id = this.defaultId;
20705
20942
 
20706
20943
  if (typeof callback === 'function') {
20707
20944
  callback(node);
20708
20945
  }
20709
20946
  },
20947
+ true,
20710
20948
  );
20711
20949
  }
20712
20950
  }
@@ -20888,7 +21126,9 @@ class VirtualKeyboardController {
20888
21126
  * @param {function(new:HTMLElement)} subclass
20889
21127
  */
20890
21128
  const DatePickerMixin = (subclass) =>
20891
- class VaadinDatePickerMixin extends ControllerMixin(DelegateFocusMixin(InputMixin(KeyboardMixin(subclass)))) {
21129
+ class VaadinDatePickerMixin extends ControllerMixin(
21130
+ DelegateFocusMixin(InputConstraintsMixin(KeyboardMixin(subclass))),
21131
+ ) {
20892
21132
  static get properties() {
20893
21133
  return {
20894
21134
  /**
@@ -20917,7 +21157,6 @@ const DatePickerMixin = (subclass) =>
20917
21157
  */
20918
21158
  value: {
20919
21159
  type: String,
20920
- observer: '_valueChanged',
20921
21160
  notify: true,
20922
21161
  value: '',
20923
21162
  },
@@ -20973,13 +21212,6 @@ const DatePickerMixin = (subclass) =>
20973
21212
  value: '(max-width: 420px), (max-height: 420px)',
20974
21213
  },
20975
21214
 
20976
- /**
20977
- * An array of ancestor elements whose -webkit-overflow-scrolling is forced from value
20978
- * 'touch' to value 'auto' in order to prevent them from clipping the dropdown. iOS only.
20979
- * @private
20980
- */
20981
- _touchPrevented: Array,
20982
-
20983
21215
  /**
20984
21216
  * The object used to localize this component.
20985
21217
  * To change the default localization, replace the entire
@@ -21135,7 +21367,6 @@ const DatePickerMixin = (subclass) =>
21135
21367
  */
21136
21368
  min: {
21137
21369
  type: String,
21138
- observer: '_minChanged',
21139
21370
  },
21140
21371
 
21141
21372
  /**
@@ -21149,28 +21380,26 @@ const DatePickerMixin = (subclass) =>
21149
21380
  */
21150
21381
  max: {
21151
21382
  type: String,
21152
- observer: '_maxChanged',
21153
21383
  },
21154
21384
 
21155
21385
  /**
21156
21386
  * The earliest date that can be selected. All earlier dates will be disabled.
21157
- * @type {Date | string}
21387
+ * @type {Date | undefined}
21158
21388
  * @protected
21159
21389
  */
21160
21390
  _minDate: {
21161
21391
  type: Date,
21162
- // Null does not work here because minimizer passes undefined to overlay (#351)
21163
- value: '',
21392
+ computed: '__computeMinOrMaxDate(min)',
21164
21393
  },
21165
21394
 
21166
21395
  /**
21167
21396
  * The latest date that can be selected. All later dates will be disabled.
21168
- * @type {Date | string}
21397
+ * @type {Date | undefined}
21169
21398
  * @protected
21170
21399
  */
21171
21400
  _maxDate: {
21172
21401
  type: Date,
21173
- value: '',
21402
+ computed: '__computeMinOrMaxDate(max)',
21174
21403
  },
21175
21404
 
21176
21405
  /** @private */
@@ -21185,12 +21414,6 @@ const DatePickerMixin = (subclass) =>
21185
21414
  value: isIOS,
21186
21415
  },
21187
21416
 
21188
- /** @private */
21189
- _webkitOverflowScroll: {
21190
- type: Boolean,
21191
- value: document.createElement('div').style.webkitOverflowScrolling === '',
21192
- },
21193
-
21194
21417
  /** @private */
21195
21418
  _focusOverlayOnOpen: Boolean,
21196
21419
 
@@ -21206,6 +21429,10 @@ const DatePickerMixin = (subclass) =>
21206
21429
  ];
21207
21430
  }
21208
21431
 
21432
+ static get constraints() {
21433
+ return [...super.constraints, 'min', 'max'];
21434
+ }
21435
+
21209
21436
  /**
21210
21437
  * Override a getter from `InputControlMixin` to make it optional
21211
21438
  * and to prevent warning when a clear button is missing,
@@ -21272,12 +21499,10 @@ const DatePickerMixin = (subclass) =>
21272
21499
  }
21273
21500
  }
21274
21501
 
21275
- if (this.inputElement.value === '' && this.__dispatchChange) {
21276
- this.validate();
21502
+ this.validate();
21503
+
21504
+ if (this._inputValue === '' && this.value !== '') {
21277
21505
  this.value = '';
21278
- this.__dispatchChange = false;
21279
- } else {
21280
- this.validate();
21281
21506
  }
21282
21507
  }
21283
21508
  }
@@ -21346,14 +21571,19 @@ const DatePickerMixin = (subclass) =>
21346
21571
  this.$.overlay.removeAttribute('disable-upgrade');
21347
21572
  this._overlayInitialized = true;
21348
21573
 
21349
- this.$.overlay.addEventListener('opened-changed', (e) => (this.opened = e.detail.value));
21574
+ this.$.overlay.addEventListener('opened-changed', (e) => {
21575
+ this.opened = e.detail.value;
21576
+ });
21350
21577
 
21351
21578
  this.$.overlay.addEventListener('vaadin-overlay-escape-press', () => {
21352
21579
  this._focusedDate = this._selectedDate;
21353
21580
  this._close();
21354
21581
  });
21355
21582
 
21356
- this._overlayContent.addEventListener('close', this._close.bind(this));
21583
+ this._overlayContent.addEventListener('close', () => {
21584
+ this._close();
21585
+ });
21586
+
21357
21587
  this._overlayContent.addEventListener('focus-input', this._focusAndSelect.bind(this));
21358
21588
 
21359
21589
  // User confirmed selected date by clicking the calendar.
@@ -21362,7 +21592,7 @@ const DatePickerMixin = (subclass) =>
21362
21592
 
21363
21593
  this._selectDate(e.detail.date);
21364
21594
 
21365
- this._close(e);
21595
+ this._close();
21366
21596
  });
21367
21597
 
21368
21598
  // User confirmed selected date by pressing Enter or Today.
@@ -21372,24 +21602,18 @@ const DatePickerMixin = (subclass) =>
21372
21602
  this._selectDate(e.detail.date);
21373
21603
  });
21374
21604
 
21375
- // Keep focus attribute in focusElement for styling
21605
+ // Set focus-ring attribute when moving focus to the overlay
21606
+ // by pressing Tab or arrow key, after opening it on click.
21376
21607
  this._overlayContent.addEventListener('focusin', () => {
21377
- this._setFocused(true);
21608
+ if (this._keyboardActive) {
21609
+ this._setFocused(true);
21610
+ }
21378
21611
  });
21379
21612
 
21380
21613
  this.addEventListener('mousedown', () => this.__bringToFront());
21381
21614
  this.addEventListener('touchstart', () => this.__bringToFront());
21382
21615
  }
21383
21616
 
21384
- /**
21385
- * Returns true if `value` is valid, and sets the `invalid` flag appropriately.
21386
- *
21387
- * @return {boolean} True if the value is valid and sets the `invalid` flag appropriately
21388
- */
21389
- validate() {
21390
- return !(this.invalid = !this.checkValidity());
21391
- }
21392
-
21393
21617
  /**
21394
21618
  * Returns true if the current input value satisfies all constraints (if any)
21395
21619
  *
@@ -21400,7 +21624,7 @@ const DatePickerMixin = (subclass) =>
21400
21624
  checkValidity() {
21401
21625
  const inputValid =
21402
21626
  !this._inputValue ||
21403
- (this._selectedDate && this._inputValue === this._getFormattedDate(this.i18n.formatDate, this._selectedDate));
21627
+ (!!this._selectedDate && this._inputValue === this._getFormattedDate(this.i18n.formatDate, this._selectedDate));
21404
21628
  const minMaxValid = !this._selectedDate || dateAllowed(this._selectedDate, this._minDate, this._maxDate);
21405
21629
 
21406
21630
  let inputValidity = true;
@@ -21416,6 +21640,51 @@ const DatePickerMixin = (subclass) =>
21416
21640
  return inputValid && minMaxValid && inputValidity;
21417
21641
  }
21418
21642
 
21643
+ /**
21644
+ * Override method inherited from `FocusMixin`
21645
+ * to not call `_setFocused(true)` when focus
21646
+ * is restored after closing overlay on click,
21647
+ * and to avoid removing `focus-ring` attribute.
21648
+ *
21649
+ * @param {!FocusEvent} _event
21650
+ * @return {boolean}
21651
+ * @protected
21652
+ * @override
21653
+ */
21654
+ _shouldSetFocus(_event) {
21655
+ return !this._shouldKeepFocusRing;
21656
+ }
21657
+
21658
+ /**
21659
+ * Override method inherited from `FocusMixin`
21660
+ * to prevent removing the `focused` attribute:
21661
+ * - when moving focus to the overlay content,
21662
+ * - when closing on date click / outside click.
21663
+ *
21664
+ * @param {!FocusEvent} _event
21665
+ * @return {boolean}
21666
+ * @protected
21667
+ * @override
21668
+ */
21669
+ _shouldRemoveFocus(_event) {
21670
+ return !this.opened;
21671
+ }
21672
+
21673
+ /**
21674
+ * Override method inherited from `FocusMixin`
21675
+ * to store the `focus-ring` state to restore
21676
+ * it later when closing on outside click.
21677
+ *
21678
+ * @param {boolean} focused
21679
+ * @protected
21680
+ * @override
21681
+ */
21682
+ _setFocused(focused) {
21683
+ super._setFocused(focused);
21684
+
21685
+ this._shouldKeepFocusRing = focused && this._keyboardActive;
21686
+ }
21687
+
21419
21688
  /**
21420
21689
  * Select date on user interaction and set the flag
21421
21690
  * to fire change event if necessary.
@@ -21435,10 +21704,7 @@ const DatePickerMixin = (subclass) =>
21435
21704
  }
21436
21705
 
21437
21706
  /** @private */
21438
- _close(e) {
21439
- if (e) {
21440
- e.stopPropagation();
21441
- }
21707
+ _close() {
21442
21708
  this._focus();
21443
21709
  this.close();
21444
21710
  }
@@ -21567,47 +21833,46 @@ const DatePickerMixin = (subclass) =>
21567
21833
  }
21568
21834
  }
21569
21835
 
21570
- /** @private */
21571
- _handleDateChange(property, value, oldValue) {
21572
- if (!value) {
21573
- this[property] = '';
21574
- return;
21575
- }
21836
+ /**
21837
+ * Override the value observer from `InputMixin` to implement custom
21838
+ * handling of the `value` property. The date-picker doesn't forward
21839
+ * the value directly to the input like the default implementation of `InputMixin`.
21840
+ * Instead, it parses the value into a date, puts it in `_selectedDate` which
21841
+ * is then displayed in the input with respect to the specified date format.
21842
+ *
21843
+ * @param {string | undefined} value
21844
+ * @param {string | undefined} oldValue
21845
+ * @protected
21846
+ * @override
21847
+ */
21848
+ _valueChanged(value, oldValue) {
21849
+ const newDate = this._parseDate(value);
21576
21850
 
21577
- const date = this._parseDate(value);
21578
- if (!date) {
21851
+ if (value && !newDate) {
21852
+ // The new value cannot be parsed, revert the old value.
21579
21853
  this.value = oldValue;
21580
21854
  return;
21581
21855
  }
21582
- if (!dateEquals(this[property], date)) {
21583
- this[property] = date;
21584
- if (this.value) {
21585
- this.validate();
21586
- }
21587
- }
21588
- }
21589
21856
 
21590
- /** @private */
21591
- _valueChanged(value, oldValue) {
21592
- this._handleDateChange('_selectedDate', value, oldValue);
21857
+ if (value) {
21858
+ if (!dateEquals(this._selectedDate, newDate)) {
21859
+ // Update the date instance only if the date has actually changed.
21860
+ this._selectedDate = newDate;
21593
21861
 
21594
- this._toggleHasValue(!!value);
21595
- }
21596
-
21597
- /** @private */
21598
- _minChanged(value, oldValue) {
21599
- this._handleDateChange('_minDate', value, oldValue);
21600
- }
21862
+ if (oldValue !== undefined) {
21863
+ // Validate only if `value` changes after initialization.
21864
+ this.validate();
21865
+ }
21866
+ }
21867
+ } else {
21868
+ this._selectedDate = null;
21869
+ }
21601
21870
 
21602
- /** @private */
21603
- _maxChanged(value, oldValue) {
21604
- this._handleDateChange('_maxDate', value, oldValue);
21871
+ this._toggleHasValue(this._hasValue);
21605
21872
  }
21606
21873
 
21607
21874
  /** @protected */
21608
21875
  _onOverlayOpened() {
21609
- this._openedWithFocusRing = this.hasAttribute('focus-ring');
21610
-
21611
21876
  const parsedInitialPosition = this._parseDate(this.initialPosition);
21612
21877
 
21613
21878
  const initialPosition =
@@ -21627,10 +21892,6 @@ const DatePickerMixin = (subclass) =>
21627
21892
 
21628
21893
  window.addEventListener('scroll', this._boundOnScroll, true);
21629
21894
 
21630
- if (this._webkitOverflowScroll) {
21631
- this._touchPrevented = this._preventWebkitOverflowScrollingTouch(this.parentElement);
21632
- }
21633
-
21634
21895
  if (this._focusOverlayOnOpen) {
21635
21896
  this._overlayContent.focusDateElement();
21636
21897
  this._focusOverlayOnOpen = false;
@@ -21644,25 +21905,6 @@ const DatePickerMixin = (subclass) =>
21644
21905
  }
21645
21906
  }
21646
21907
 
21647
- // A hack needed for iOS to prevent dropdown from being clipped in an
21648
- // ancestor container with -webkit-overflow-scrolling: touch;
21649
- /** @private */
21650
- _preventWebkitOverflowScrollingTouch(element) {
21651
- const result = [];
21652
- while (element) {
21653
- if (window.getComputedStyle(element).webkitOverflowScrolling === 'touch') {
21654
- const oldInlineValue = element.style.webkitOverflowScrolling;
21655
- element.style.webkitOverflowScrolling = 'auto';
21656
- result.push({
21657
- element,
21658
- oldInlineValue,
21659
- });
21660
- }
21661
- element = element.parentElement;
21662
- }
21663
- return result;
21664
- }
21665
-
21666
21908
  /** @private */
21667
21909
  _selectParsedOrFocusedDate() {
21668
21910
  // Select the parsed input or focused date
@@ -21689,13 +21931,6 @@ const DatePickerMixin = (subclass) =>
21689
21931
  _onOverlayClosed() {
21690
21932
  window.removeEventListener('scroll', this._boundOnScroll, true);
21691
21933
 
21692
- if (this._touchPrevented) {
21693
- this._touchPrevented.forEach(
21694
- (prevented) => (prevented.element.style.webkitOverflowScrolling = prevented.oldInlineValue),
21695
- );
21696
- this._touchPrevented = [];
21697
- }
21698
-
21699
21934
  // No need to select date on close if it was confirmed by the user.
21700
21935
  if (this.__userConfirmedDate) {
21701
21936
  this.__userConfirmedDate = false;
@@ -21711,11 +21946,6 @@ const DatePickerMixin = (subclass) =>
21711
21946
  if (!this.value) {
21712
21947
  this.validate();
21713
21948
  }
21714
-
21715
- // If the input isn't focused when overlay closes (fullscreen mode), clear focused state
21716
- if (this.getRootNode().activeElement !== this.inputElement) {
21717
- this._setFocused(false);
21718
- }
21719
21949
  }
21720
21950
 
21721
21951
  /** @private */
@@ -21768,10 +21998,7 @@ const DatePickerMixin = (subclass) =>
21768
21998
  _onChange(event) {
21769
21999
  // For change event on the native <input> blur, after the input is cleared,
21770
22000
  // we schedule change event to be dispatched on date-picker blur.
21771
- if (
21772
- this.inputElement.value === '' &&
21773
- !(event.detail && event.detail.sourceEvent && event.detail.sourceEvent.__fromClearButton)
21774
- ) {
22001
+ if (this._inputValue === '') {
21775
22002
  this.__dispatchChange = true;
21776
22003
  }
21777
22004
 
@@ -21858,7 +22085,7 @@ const DatePickerMixin = (subclass) =>
21858
22085
  if (e.shiftKey) {
21859
22086
  this._overlayContent.focusCancel();
21860
22087
  } else {
21861
- this._overlayContent.focusDate(this._focusedDate);
22088
+ this._overlayContent.focusDateElement();
21862
22089
  }
21863
22090
  }
21864
22091
  break;
@@ -21969,6 +22196,11 @@ const DatePickerMixin = (subclass) =>
21969
22196
  return this.$.overlay.content.querySelector('#overlay-content');
21970
22197
  }
21971
22198
 
22199
+ /** @private */
22200
+ __computeMinOrMaxDate(dateString) {
22201
+ return this._parseDate(dateString);
22202
+ }
22203
+
21972
22204
  /**
21973
22205
  * Fired when the user commits a value change.
21974
22206
  *
@@ -22080,12 +22312,13 @@ registerStyles('vaadin-date-picker', [inputFieldShared, datePickerStyles], { mod
22080
22312
  * Note: the `theme` attribute value set on `<vaadin-date-picker>` is
22081
22313
  * propagated to the internal components listed above.
22082
22314
  *
22083
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
22315
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
22084
22316
  *
22085
22317
  * @fires {Event} change - Fired when the user commits a value change.
22086
22318
  * @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
22087
22319
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
22088
22320
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
22321
+ * @fires {CustomEvent} validated - Fired whenever the field is validated.
22089
22322
  *
22090
22323
  * @extends HTMLElement
22091
22324
  * @mixes ElementMixin
@@ -22139,7 +22372,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
22139
22372
  fullscreen$="[[_fullscreen]]"
22140
22373
  theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
22141
22374
  on-vaadin-overlay-open="_onOverlayOpened"
22142
- on-vaadin-overlay-close="_onOverlayClosed"
22375
+ on-vaadin-overlay-closing="_onOverlayClosed"
22143
22376
  restore-focus-on-close
22144
22377
  restore-focus-node="[[inputElement]]"
22145
22378
  disable-upgrade
@@ -22199,11 +22432,6 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
22199
22432
 
22200
22433
  /** @private */
22201
22434
  _onVaadinOverlayClose(e) {
22202
- if (this._openedWithFocusRing && this.hasAttribute('focused')) {
22203
- this.setAttribute('focus-ring', '');
22204
- } else if (!this.hasAttribute('focused')) {
22205
- this.blur();
22206
- }
22207
22435
  if (e.detail.sourceEvent && e.detail.sourceEvent.composedPath().includes(this)) {
22208
22436
  e.preventDefault();
22209
22437
  }
@@ -22227,11 +22455,12 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
22227
22455
 
22228
22456
  customElements.define(DatePicker.is, DatePicker);
22229
22457
 
22230
- const helperFiltersCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.FilterButtonsWrapper{display:flex;justify-content:flex-end;gap:5px}.FilterButtonsWrapper .FilterOpen{cursor:pointer;border-radius:4px;padding:8px 15px;width:max-content;border:1px solid #00958f;background:#00958f;color:#FFF;font-size:12px;transition:all 0.2s linear;text-align:center;letter-spacing:0}.FilterButtonsWrapper .FilterOpen:hover{background:#00958f;color:#FFF}.FilterButtonsWrapper .FilterClear{cursor:pointer;border-radius:4px;padding:8px 15px;width:max-content;border:1px solid #00958f;background:#FFF;color:#000;font-size:12px;transition:all 0.2s linear;text-align:center;letter-spacing:0}.FilterButtonsWrapper .FilterClear:hover{background:#00958f;color:#FFF}.FilterModalHeader,.FilterModalBody,.FilterModalFooter{display:flex;flex-direction:column;gap:5px;align-items:center;margin:20px 0}.FilterModalHeader .FilterModalTitle,.FilterModalBody .FilterModalTitle,.FilterModalFooter .FilterModalTitle{margin:0;padding:0;font-weight:700;font-size:16px;color:#009993;text-transform:uppercase}.FilterModalHeader .FilterModalSearch,.FilterModalBody .FilterModalSearch,.FilterModalFooter .FilterModalSearch{border-radius:4px;background:#e8ebef;color:#263445;width:100%;height:26px;max-width:280px;padding:5px;font-size:15px;border:none;outline:#009993}.FilterModalHeader .FilterCalendarWrapper,.FilterModalBody .FilterCalendarWrapper,.FilterModalFooter .FilterCalendarWrapper{display:flex;gap:5px}.FilterModalHeader .FilterCalendarWrapper .VaadinDatePicker,.FilterModalBody .FilterCalendarWrapper .VaadinDatePicker,.FilterModalFooter .FilterCalendarWrapper .VaadinDatePicker{width:50%;max-width:143px}.FilterModalHeader .FilterModalButton,.FilterModalBody .FilterModalButton,.FilterModalFooter .FilterModalButton{cursor:pointer;border-radius:4px;padding:8px 60px;width:max-content;margin:5px;border:1px solid #00958f;background:#00958f;color:#FFF;font-size:12px;transition:all 0.2s linear;text-transform:uppercase;text-align:center;letter-spacing:0}.FilterModalHeader .FilterModalButton:hover,.FilterModalBody .FilterModalButton:hover,.FilterModalFooter .FilterModalButton:hover{background:#00958f;color:#FFF}";
22458
+ const helperFiltersCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.FilterButtonsWrapper{display:flex;justify-content:flex-end;gap:5px}.FilterButtonsWrapper .FilterOpen{cursor:pointer;border-radius:4px;padding:8px 15px;width:max-content;border:1px solid #00958f;background:#00958f;color:#FFF;font-size:12px;transition:all 0.2s linear;text-align:center;letter-spacing:0}.FilterButtonsWrapper .FilterOpen:hover{background:#00958f;color:#FFF}.FilterButtonsWrapper .FilterClear{cursor:pointer;border-radius:4px;padding:8px 15px;width:max-content;border:1px solid #00958f;background:#FFF;color:#000;font-size:12px;transition:all 0.2s linear;text-align:center;letter-spacing:0}.FilterButtonsWrapper .FilterClear:hover{background:#00958f;color:#FFF}.FilterModalHeader,.FilterModalBody,.FilterModalFooter{display:flex;flex-direction:column;gap:5px;align-items:center;margin:20px 0}.FilterModalHeader .FilterModalTitle,.FilterModalBody .FilterModalTitle,.FilterModalFooter .FilterModalTitle{margin:0;padding:0;font-weight:700;font-size:16px;color:#009993;text-transform:uppercase}.FilterModalHeader .FilterModalSearch,.FilterModalBody .FilterModalSearch,.FilterModalFooter .FilterModalSearch{border-radius:4px;background:#e8ebef;color:#263445;width:100%;height:26px;max-width:280px;padding:5px;font-size:15px;border:none;outline:#009993}.FilterModalHeader .FilterCalendarWrapper,.FilterModalBody .FilterCalendarWrapper,.FilterModalFooter .FilterCalendarWrapper{display:flex;gap:5px}.FilterModalHeader .FilterCalendarWrapper .VaadinDatePicker,.FilterModalBody .FilterCalendarWrapper .VaadinDatePicker,.FilterModalFooter .FilterCalendarWrapper .VaadinDatePicker{width:50%;max-width:143px}.FilterModalHeader .FilterModalButton,.FilterModalBody .FilterModalButton,.FilterModalFooter .FilterModalButton{cursor:pointer;border-radius:4px;padding:8px 60px;width:max-content;margin:5px;border:1px solid #00958f;background:#00958f;color:#FFF;font-size:12px;transition:all 0.2s linear;text-transform:uppercase;text-align:center;letter-spacing:0}.FilterModalHeader .FilterModalButton:hover,.FilterModalBody .FilterModalButton:hover,.FilterModalFooter .FilterModalButton:hover{background:#00958f;color:#FFF}.FilterModalHeader p,.FilterModalBody p,.FilterModalFooter p{margin:5px 0}";
22231
22459
 
22232
22460
  const HelperFilters = class {
22233
22461
  constructor(hostRef) {
22234
22462
  index.registerInstance(this, hostRef);
22463
+ this.filterDraw = index.createEvent(this, "filterDraw", 7);
22235
22464
  this.filterSelection = index.createEvent(this, "filterSelection", 7);
22236
22465
  this.filterSelectionReset = index.createEvent(this, "filterSelectionReset", 7);
22237
22466
  /**
@@ -22265,23 +22494,29 @@ const HelperFilters = class {
22265
22494
  this.showFilterModal = false;
22266
22495
  this.showClearButton = false;
22267
22496
  this.filterData = {};
22268
- this.filterDataReset = { drawTicketId: '', filterFromCalendar: '', filterToCalendar: '' };
22497
+ this.filterDataReset = { ticketDrawId: '', filterFromCalendar: '', filterToCalendar: '' };
22498
+ }
22499
+ // reset field values each time the filter modal opens
22500
+ componentDidRender() {
22501
+ this.filterData.ticketDrawId = null;
22502
+ this.filterData.filterFromCalendar = null;
22503
+ this.filterData.filterToCalendar = null;
22504
+ // @TODO: to way binding?
22505
+ if (document.getElementById('#FilterById'))
22506
+ document.getElementById('#FilterById').value = '';
22269
22507
  }
22270
22508
  filterSelectionHandler(event) {
22271
- if (this.postMessage) {
22509
+ if (this.postMessage)
22272
22510
  window.postMessage({ type: 'filterSelection', event }, window.location.href);
22273
- }
22274
- else {
22511
+ if (this.filterData.ticketDrawId)
22512
+ this.filterDraw.emit(event);
22513
+ if (this.filterData.filterFromCalendar || this.filterData.filterToCalendar)
22275
22514
  this.filterSelection.emit(event);
22276
- }
22277
22515
  }
22278
22516
  filterSelectionResetHandler(event) {
22279
- if (this.postMessage) {
22517
+ if (this.postMessage)
22280
22518
  window.postMessage({ type: 'filterSelectionReset', event }, window.location.href);
22281
- }
22282
- else {
22283
- this.filterSelectionReset.emit(event);
22284
- }
22519
+ this.filterSelectionReset.emit(event);
22285
22520
  }
22286
22521
  modalCloseEvent() {
22287
22522
  this.showFilterModal = false;
@@ -22299,9 +22534,10 @@ const HelperFilters = class {
22299
22534
  resetSearch() {
22300
22535
  this.showClearButton = false;
22301
22536
  this.filterSelectionResetHandler(this.filterDataReset);
22537
+ this.filterData = {};
22302
22538
  }
22303
- handleDrawTicketId(event) {
22304
- this.filterData.drawTicketId = event.target.value;
22539
+ handleTicketDrawId(event) {
22540
+ this.filterData.ticketDrawId = event.target.value;
22305
22541
  }
22306
22542
  handleFilterFrom(event) {
22307
22543
  this.filterData.filterFromCalendar = new Date(event.target.value).toISOString();
@@ -22310,7 +22546,7 @@ const HelperFilters = class {
22310
22546
  this.filterData.filterToCalendar = new Date(event.target.value).toISOString();
22311
22547
  }
22312
22548
  render() {
22313
- return (index.h("div", { class: "HelperFilters" }, index.h("div", { class: "FilterButtonsWrapper" }, index.h("button", { class: "FilterOpen", onClick: () => this.toggleFilterModal() }, translate$1('filterOpen', this.language)), this.showClearButton ? index.h("button", { class: "FilterClear", onClick: () => this.resetSearch() }, translate$1('filterClear', this.language)) : null), index.h("helper-modal", { "title-modal": "Filter Modal", visible: this.showFilterModal }, index.h("div", { class: "FilterModalHeader" }, index.h("h3", { class: "FilterModalTitle" }, this.activateTicketSearch ? translate$1('filterModalTicketTitle', this.language) : translate$1('filterModalDrawTitle', this.language))), index.h("div", { class: "FilterModalBody" }, index.h("input", { type: "text", value: this.filterData.drawTicketId, onInput: (event) => this.handleDrawTicketId(event), class: "FilterModalSearch", placeholder: this.activateTicketSearch ? translate$1('filterTicketPlaceholder', this.language) : translate$1('filterDrawPlaceholder', this.language) }), index.h("div", { class: "FilterCalendarWrapper" }, index.h("vaadin-date-picker", { value: this.filterData.filterFromCalendar, onChange: (event) => this.handleFilterFrom(event), placeholder: translate$1('filterFromCalendar', this.language), class: "VaadinDatePicker" }), index.h("vaadin-date-picker", { value: this.filterData.filterToCalendar, onChange: (event) => this.handleFilterTo(event), placeholder: translate$1('filterToCalendar', this.language), class: "VaadinDatePicker" }))), index.h("div", { class: "FilterModalFooter" }, index.h("button", { class: "FilterModalButton", onClick: () => this.filterSearch() }, translate$1('filterModalButton', this.language))))));
22549
+ return (index.h("div", { class: "HelperFilters" }, index.h("div", { class: "FilterButtonsWrapper" }, index.h("button", { class: "FilterOpen", onClick: () => this.toggleFilterModal() }, translate$1('filterOpen', this.language)), this.showClearButton ? index.h("button", { class: "FilterClear", onClick: () => this.resetSearch() }, translate$1('filterClear', this.language)) : null), index.h("helper-modal", { "title-modal": "Filter Modal", visible: this.showFilterModal }, index.h("div", { class: "FilterModalHeader" }, index.h("h3", { class: "FilterModalTitle" }, this.activateTicketSearch ? translate$1('filterModalTicketTitle', this.language) : translate$1('filterModalDrawTitle', this.language))), index.h("div", { class: "FilterModalBody" }, index.h("input", { id: "FilterById", type: "text", value: this.filterData.ticketDrawId, onInput: (event) => this.handleTicketDrawId(event), class: "FilterModalSearch", placeholder: this.activateTicketSearch ? translate$1('filterTicketPlaceholder', this.language) : translate$1('filterDrawPlaceholder', this.language) }), index.h("p", null, translate$1('filterOrDate', this.language)), index.h("div", { class: "FilterCalendarWrapper" }, index.h("vaadin-date-picker", { value: this.filterData.filterFromCalendar, onChange: (event) => this.handleFilterFrom(event), placeholder: translate$1('filterFromCalendar', this.language), class: "VaadinDatePicker" }), index.h("vaadin-date-picker", { value: this.filterData.filterToCalendar, onChange: (event) => this.handleFilterTo(event), placeholder: translate$1('filterToCalendar', this.language), class: "VaadinDatePicker" }))), index.h("div", { class: "FilterModalFooter" }, index.h("button", { class: "FilterModalButton", onClick: () => this.filterSearch() }, translate$1('filterModalButton', this.language))))));
22314
22550
  }
22315
22551
  };
22316
22552
  HelperFilters.style = helperFiltersCss;