@everymatrix/stage-dm-range-date-picker 1.0.31 → 1.0.32

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/component-lib.js CHANGED
@@ -67274,22 +67274,22 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
67274
67274
  this.elementRef = elementRef;
67275
67275
  this.shadowDomStyleInjectorService = shadowDomStyleInjectorService;
67276
67276
  this.dateControl.valueChanges.subscribe((dates) => {
67277
- if (!dates || !dates[0] || !dates[1] && this.requireEndDate) {
67278
- return;
67279
- }
67280
- if (this.manualDateChange) {
67281
- this.currentAlias = TimePeriod.Custom;
67282
- this.manualDateChange = false;
67283
- }
67277
+ const start = Array.isArray(dates) && this.isDateValid(dates[0]);
67278
+ const end = Array.isArray(dates) && this.isDateValid(dates[1]);
67279
+ const parsed = [];
67280
+ if (start)
67281
+ parsed.push(dates[0]);
67282
+ if (start && end)
67283
+ parsed.push(dates[1]);
67284
67284
  const rangeValue = {
67285
67285
  alias: this.currentAlias ?? "custom",
67286
67286
  start: dates?.[0] ?? null,
67287
67287
  end: dates?.[1] ?? null
67288
67288
  };
67289
- this.inputValue = this.formatDateRange(dates ?? []);
67290
- this.onChangeFn(rangeValue);
67289
+ this.inputValue = this.formatDateRange(parsed);
67290
+ this.onChangeFn(parsed.length ? rangeValue : null);
67291
67291
  this.elementRef.nativeElement.dispatchEvent(new CustomEvent("dm-range-date-picker-changed", {
67292
- detail: rangeValue,
67292
+ detail: parsed.length ? rangeValue : null,
67293
67293
  bubbles: true,
67294
67294
  composed: true
67295
67295
  }));
@@ -67337,19 +67337,23 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
67337
67337
  return this.requireEndDate ? endDateRequired(control) : null;
67338
67338
  }
67339
67339
  writeValue(value) {
67340
- if (!value || typeof value !== "object" || !("alias" in value) || value.alias == "custom" && (!value.start || !value.end && this.requireEndDate)) {
67340
+ if (!value || typeof value !== "object" || !("alias" in value) || !value.alias) {
67341
67341
  this.inputValue = "";
67342
- this._initialValue = null;
67343
67342
  this.dateControl.setValue(null, { emitEvent: false });
67344
67343
  return;
67345
67344
  }
67346
- this._initialValue = value;
67347
67345
  if (value.alias !== "custom") {
67348
67346
  this.onListSelect(value.alias);
67349
67347
  } else {
67350
- this.currentAlias = TimePeriod.Custom;
67351
- const parsed = [new Date(value.start), new Date(value.end)];
67352
- this.dateControl.setValue(parsed, { emitEvent: false });
67348
+ const start = this.isDateValid(value.start);
67349
+ const end = this.isDateValid(value.end);
67350
+ const parsed = [];
67351
+ if (start)
67352
+ parsed.push(value.start);
67353
+ if (start && end)
67354
+ parsed.push(value.end);
67355
+ this.currentAlias = parsed.length ? TimePeriod.Custom : null;
67356
+ this.dateControl.setValue(parsed.length ? parsed : null, { emitEvent: false });
67353
67357
  this.inputValue = this.formatDateRange(parsed);
67354
67358
  }
67355
67359
  }
@@ -67360,7 +67364,6 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
67360
67364
  this.onTouchedFn = fn;
67361
67365
  }
67362
67366
  dateSelection() {
67363
- this.manualDateChange = true;
67364
67367
  const range = this.dateControl.value;
67365
67368
  if (!this.showTimePicker && range && Array.isArray(range) && range.length === 2 && range[1] && (0, import_moment4.default)(range[1]).isValid()) {
67366
67369
  const endDate = new Date(range[1]);
@@ -67368,22 +67371,22 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
67368
67371
  this.dateControl.setValue([range[0], endDate]);
67369
67372
  }
67370
67373
  this.inputValue = this.formatDateRange(this.dateControl.value);
67374
+ this.currentAlias = TimePeriod.Custom;
67371
67375
  }
67372
67376
  onListSelect(key) {
67373
- this.currentAlias = key;
67377
+ this.currentAlias = null;
67374
67378
  const alias = DATE_HINTS.find((item) => item.dateAlias === key);
67375
67379
  if (alias) {
67380
+ this.currentAlias = key;
67376
67381
  const dates = [alias.interval.start, alias.interval.end];
67377
67382
  this.dateControl.setValue(dates);
67378
- this._initialValue = {
67379
- alias: key,
67380
- start: alias.interval.start,
67381
- end: alias.interval.end
67382
- };
67383
67383
  }
67384
67384
  }
67385
+ isDateValid(date) {
67386
+ return !!date && (0, import_moment4.default)(date).isValid();
67387
+ }
67385
67388
  formatDate(date) {
67386
- if (!date || !(0, import_moment4.default)(date).isValid()) {
67389
+ if (!this.isDateValid(date)) {
67387
67390
  return "";
67388
67391
  }
67389
67392
  return (0, import_moment4.default)(date).format("DD/MM/YYYY");
@@ -67442,7 +67445,6 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
67442
67445
  this.dateControl.markAsTouched();
67443
67446
  this.dateControl.markAsDirty();
67444
67447
  this.inputValue = "";
67445
- this._initialValue = null;
67446
67448
  this.currentAlias = null;
67447
67449
  if (this.control) {
67448
67450
  this.control.reset();
package/main.js CHANGED
@@ -64890,22 +64890,22 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
64890
64890
  this.elementRef = elementRef;
64891
64891
  this.shadowDomStyleInjectorService = shadowDomStyleInjectorService;
64892
64892
  this.dateControl.valueChanges.subscribe((dates) => {
64893
- if (!dates || !dates[0] || !dates[1] && this.requireEndDate) {
64894
- return;
64895
- }
64896
- if (this.manualDateChange) {
64897
- this.currentAlias = TimePeriod.Custom;
64898
- this.manualDateChange = false;
64899
- }
64893
+ const start = Array.isArray(dates) && this.isDateValid(dates[0]);
64894
+ const end = Array.isArray(dates) && this.isDateValid(dates[1]);
64895
+ const parsed = [];
64896
+ if (start)
64897
+ parsed.push(dates[0]);
64898
+ if (start && end)
64899
+ parsed.push(dates[1]);
64900
64900
  const rangeValue = {
64901
64901
  alias: this.currentAlias ?? "custom",
64902
64902
  start: dates?.[0] ?? null,
64903
64903
  end: dates?.[1] ?? null
64904
64904
  };
64905
- this.inputValue = this.formatDateRange(dates ?? []);
64906
- this.onChangeFn(rangeValue);
64905
+ this.inputValue = this.formatDateRange(parsed);
64906
+ this.onChangeFn(parsed.length ? rangeValue : null);
64907
64907
  this.elementRef.nativeElement.dispatchEvent(new CustomEvent("dm-range-date-picker-changed", {
64908
- detail: rangeValue,
64908
+ detail: parsed.length ? rangeValue : null,
64909
64909
  bubbles: true,
64910
64910
  composed: true
64911
64911
  }));
@@ -64953,19 +64953,23 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
64953
64953
  return this.requireEndDate ? endDateRequired(control) : null;
64954
64954
  }
64955
64955
  writeValue(value) {
64956
- if (!value || typeof value !== "object" || !("alias" in value) || value.alias == "custom" && (!value.start || !value.end && this.requireEndDate)) {
64956
+ if (!value || typeof value !== "object" || !("alias" in value) || !value.alias) {
64957
64957
  this.inputValue = "";
64958
- this._initialValue = null;
64959
64958
  this.dateControl.setValue(null, { emitEvent: false });
64960
64959
  return;
64961
64960
  }
64962
- this._initialValue = value;
64963
64961
  if (value.alias !== "custom") {
64964
64962
  this.onListSelect(value.alias);
64965
64963
  } else {
64966
- this.currentAlias = TimePeriod.Custom;
64967
- const parsed = [new Date(value.start), new Date(value.end)];
64968
- this.dateControl.setValue(parsed, { emitEvent: false });
64964
+ const start = this.isDateValid(value.start);
64965
+ const end = this.isDateValid(value.end);
64966
+ const parsed = [];
64967
+ if (start)
64968
+ parsed.push(value.start);
64969
+ if (start && end)
64970
+ parsed.push(value.end);
64971
+ this.currentAlias = parsed.length ? TimePeriod.Custom : null;
64972
+ this.dateControl.setValue(parsed.length ? parsed : null, { emitEvent: false });
64969
64973
  this.inputValue = this.formatDateRange(parsed);
64970
64974
  }
64971
64975
  }
@@ -64976,7 +64980,6 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
64976
64980
  this.onTouchedFn = fn;
64977
64981
  }
64978
64982
  dateSelection() {
64979
- this.manualDateChange = true;
64980
64983
  const range = this.dateControl.value;
64981
64984
  if (!this.showTimePicker && range && Array.isArray(range) && range.length === 2 && range[1] && (0, import_moment4.default)(range[1]).isValid()) {
64982
64985
  const endDate = new Date(range[1]);
@@ -64984,22 +64987,22 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
64984
64987
  this.dateControl.setValue([range[0], endDate]);
64985
64988
  }
64986
64989
  this.inputValue = this.formatDateRange(this.dateControl.value);
64990
+ this.currentAlias = TimePeriod.Custom;
64987
64991
  }
64988
64992
  onListSelect(key) {
64989
- this.currentAlias = key;
64993
+ this.currentAlias = null;
64990
64994
  const alias = DATE_HINTS.find((item) => item.dateAlias === key);
64991
64995
  if (alias) {
64996
+ this.currentAlias = key;
64992
64997
  const dates = [alias.interval.start, alias.interval.end];
64993
64998
  this.dateControl.setValue(dates);
64994
- this._initialValue = {
64995
- alias: key,
64996
- start: alias.interval.start,
64997
- end: alias.interval.end
64998
- };
64999
64999
  }
65000
65000
  }
65001
+ isDateValid(date) {
65002
+ return !!date && (0, import_moment4.default)(date).isValid();
65003
+ }
65001
65004
  formatDate(date) {
65002
- if (!date || !(0, import_moment4.default)(date).isValid()) {
65005
+ if (!this.isDateValid(date)) {
65003
65006
  return "";
65004
65007
  }
65005
65008
  return (0, import_moment4.default)(date).format("DD/MM/YYYY");
@@ -65058,7 +65061,6 @@ var DmRangeDatePickerLibComponent = class _DmRangeDatePickerLibComponent {
65058
65061
  this.dateControl.markAsTouched();
65059
65062
  this.dateControl.markAsDirty();
65060
65063
  this.inputValue = "";
65061
- this._initialValue = null;
65062
65064
  this.currentAlias = null;
65063
65065
  if (this.control) {
65064
65066
  this.control.reset();