@colijnit/corecomponents_v12 257.1.17 → 257.1.18

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.
@@ -5446,6 +5446,23 @@ class InputDatePickerComponent extends BaseInputDatePickerDirective {
5446
5446
  this.overlayService.removeComponent(this._calendarComponentRef);
5447
5447
  }
5448
5448
  }
5449
+ finalizeDate() {
5450
+ if (this.isValidDateString(this.modelAsString)) {
5451
+ const [year, month, day] = this.modelAsString.split('-').map(Number);
5452
+ const date = new Date(year, month - 1, day);
5453
+ this.setModel(date);
5454
+ }
5455
+ }
5456
+ isValidDateString(value) {
5457
+ const regex = /^\d{4}-\d{2}-\d{2}$/;
5458
+ if (!regex.test(value))
5459
+ return false;
5460
+ const [year, month, day] = value.split('-').map(Number);
5461
+ const date = new Date(year, month - 1, day);
5462
+ return (date.getFullYear() === year &&
5463
+ date.getMonth() === month - 1 &&
5464
+ date.getDate() === day);
5465
+ }
5449
5466
  handleDateChange(value) {
5450
5467
  if (value) {
5451
5468
  this.setModel(new Date(value));
@@ -5485,9 +5502,10 @@ InputDatePickerComponent.decorators = [
5485
5502
  [placeholder]="placeholder"
5486
5503
  (leftIconClick)="leftIconClick.emit($event)"
5487
5504
  (rightIconClick)="toggleCalendar(true)"
5488
- (blur)="handleDateChange(modelAsString)"
5505
+ (modelChange)="modelAsString = $event"
5489
5506
  (clearIconClick)="handleClearIconClicked()"
5490
5507
  [emptyPlace]="true"
5508
+ (keyup.enter)="finalizeDate()"
5491
5509
  ></co-input-text>
5492
5510
  `,
5493
5511
  providers: [
@@ -6919,6 +6937,11 @@ DoubleCalendarModule.decorators = [
6919
6937
  ];
6920
6938
 
6921
6939
  class InputDateRangePickerComponent extends BaseInputDatePickerDirective {
6940
+ constructor() {
6941
+ super(...arguments);
6942
+ this.EARLIEST_DATE = new Date(1900, 0, 1); // 1900-01-01
6943
+ this.LATEST_DATE = new Date(2100, 11, 31); // 2100-12-31
6944
+ }
6922
6945
  showClass() {
6923
6946
  return true;
6924
6947
  }
@@ -6959,43 +6982,71 @@ class InputDateRangePickerComponent extends BaseInputDatePickerDirective {
6959
6982
  }
6960
6983
  }
6961
6984
  handleFirstDateChanged(value) {
6962
- if (value) {
6963
- if (!this.model) {
6964
- this.setModel([]);
6985
+ setTimeout(() => {
6986
+ var _a, _b;
6987
+ if (this.isValidDateString(value)) {
6988
+ const [year, month, day] = value.split('-').map(Number);
6989
+ const date = new Date(year, month - 1, day);
6990
+ if (!this.model)
6991
+ this.setModel([]);
6992
+ this.setModel([date, (_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : null]);
6965
6993
  }
6966
- this.setModel([new Date(value), this.model[1] ? this.model[1] : null]);
6967
- }
6994
+ });
6968
6995
  }
6969
6996
  handleSecondDateChanged(value) {
6970
- if (value) {
6971
- if (!this.model) {
6972
- this.setModel([]);
6997
+ setTimeout(() => {
6998
+ var _a, _b;
6999
+ if (this.isValidDateString(value)) {
7000
+ const [year, month, day] = value.split('-').map(Number);
7001
+ const date = new Date(year, month - 1, day);
7002
+ if (!this.model)
7003
+ this.setModel([]);
7004
+ this.setModel([(_b = (_a = this.model) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null, date]);
6973
7005
  }
6974
- this.setModel([this.model[0] ? this.model[0] : null, new Date(value)]);
7006
+ });
7007
+ }
7008
+ finalizeDates() {
7009
+ let startDate = this.EARLIEST_DATE;
7010
+ let endDate = this.LATEST_DATE;
7011
+ if (this.isValidDateString(this.firstDateAsString)) {
7012
+ const [y, m, d] = this.firstDateAsString.split('-').map(Number);
7013
+ startDate = new Date(y, m - 1, d);
7014
+ }
7015
+ if (this.isValidDateString(this.secondDateAsString)) {
7016
+ const [y, m, d] = this.secondDateAsString.split('-').map(Number);
7017
+ endDate = new Date(y, m - 1, d);
6975
7018
  }
7019
+ this.setModel([startDate, endDate]);
7020
+ }
7021
+ isValidDateString(value) {
7022
+ const regex = /^\d{4}-\d{2}-\d{2}$/;
7023
+ if (!regex.test(value))
7024
+ return false;
7025
+ const [yearStr, monthStr, dayStr] = value.split('-');
7026
+ const [year, month, day] = [Number(yearStr), Number(monthStr), Number(dayStr)];
7027
+ // Prevent ancient years or too-far future
7028
+ if (year < 1900 || year > 2100)
7029
+ return false;
7030
+ const date = new Date(year, month - 1, day);
7031
+ return (date.getFullYear() === year &&
7032
+ date.getMonth() === month - 1 &&
7033
+ date.getDate() === day);
6976
7034
  }
6977
7035
  modelSet() {
6978
7036
  this.setModelAsString();
6979
7037
  }
6980
7038
  setModelAsString() {
6981
- if (this.model[0]) {
6982
- const year = this.model[0].toLocaleString("default", { year: "numeric" });
6983
- const month = this.model[0].toLocaleString("default", { month: "2-digit" });
6984
- const day = this.model[0].toLocaleString("default", { day: "2-digit" });
6985
- this.firstDateAsString = `${year}-${month}-${day}`;
6986
- }
6987
- else {
6988
- this.firstDateAsString = ``;
6989
- }
6990
- if (this.model[1]) {
6991
- const year = this.model[1].toLocaleString("default", { year: "numeric" });
6992
- const month = this.model[1].toLocaleString("default", { month: "2-digit" });
6993
- const day = this.model[1].toLocaleString("default", { day: "2-digit" });
6994
- this.secondDateAsString = `${year}-${month}-${day}`;
6995
- }
6996
- else {
6997
- this.secondDateAsString = ``;
6998
- }
7039
+ var _a, _b;
7040
+ const isStartDefault = ((_a = this.model[0]) === null || _a === void 0 ? void 0 : _a.getTime()) === this.EARLIEST_DATE.getTime();
7041
+ const isEndDefault = ((_b = this.model[1]) === null || _b === void 0 ? void 0 : _b.getTime()) === this.LATEST_DATE.getTime();
7042
+ this.firstDateAsString = (!this.model[0] || isStartDefault) ? '' : this.formatDate(this.model[0]);
7043
+ this.secondDateAsString = (!this.model[1] || isEndDefault) ? '' : this.formatDate(this.model[1]);
7044
+ }
7045
+ formatDate(date) {
7046
+ const year = date.toLocaleString("default", { year: "numeric" });
7047
+ const month = date.toLocaleString("default", { month: "2-digit" });
7048
+ const day = date.toLocaleString("default", { day: "2-digit" });
7049
+ return `${year}-${month}-${day}`;
6999
7050
  }
7000
7051
  }
7001
7052
  InputDateRangePickerComponent.decorators = [
@@ -7011,10 +7062,11 @@ InputDateRangePickerComponent.decorators = [
7011
7062
  [leftIcon]="leftIcon"
7012
7063
  [leftIconData]="leftIconData"
7013
7064
  [placeholder]="placeholder"
7014
- (blur)="handleFirstDateChanged(firstDateAsString)"
7065
+ (modelChange)="handleFirstDateChanged(firstDateAsString)"
7015
7066
  (clearIconClick)="clearDate(0)"
7016
7067
  (click)="handleFirstInputClick($event)"
7017
7068
  [emptyPlace]="true"
7069
+ (keyup.enter)="finalizeDates()"
7018
7070
  ></co-input-text>
7019
7071
  <co-input-text #secondInput class="no-focus-line custom-height"
7020
7072
  [(model)]= "secondDateAsString"
@@ -7023,10 +7075,11 @@ InputDateRangePickerComponent.decorators = [
7023
7075
  [type]="'date'"
7024
7076
  [rightIcon]="rightIcon"
7025
7077
  (rightIconClick)="toggleCalendar()"
7026
- (blur)="handleSecondDateChanged(secondDateAsString)"
7078
+ (modelChange)="handleSecondDateChanged(secondDateAsString)"
7027
7079
  (clearIconClick)="clearDate(1)"
7028
7080
  (click)="handleSecondInputClick($event)"
7029
7081
  [emptyPlace]="true"
7082
+ (keyup.enter)="finalizeDates()"
7030
7083
  ></co-input-text>
7031
7084
  </div>
7032
7085
  `,
@@ -12574,7 +12627,7 @@ FilterItemComponent.decorators = [
12574
12627
  <co-input-date-range [readonly]="readonly"
12575
12628
  [model]="[dateRangeStart, dateRangeEnd]"
12576
12629
  (modelChange)="handleModelChange($event)"
12577
- [placeholder]="'SELECT_DATE' | coreLocalize">
12630
+ [placeholder]="'Kies datum' | coreLocalize">
12578
12631
  </co-input-date-range>
12579
12632
  </div>
12580
12633
  </ng-template>