@skyux/datetime 5.7.2 → 6.0.0-beta.2

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.
Files changed (160) hide show
  1. package/esm2020/index.mjs +28 -0
  2. package/esm2020/lib/modules/date-pipe/date-format-utility.mjs +46 -0
  3. package/esm2020/lib/modules/date-pipe/date-pipe.module.mjs +21 -0
  4. package/esm2020/lib/modules/date-pipe/date.pipe.mjs +65 -0
  5. package/esm2020/lib/modules/date-pipe/fuzzy-date.pipe.mjs +47 -0
  6. package/esm2020/lib/modules/date-range-picker/date-range-picker.component.mjs +448 -0
  7. package/esm2020/lib/modules/date-range-picker/date-range-picker.module.mjs +47 -0
  8. package/esm2020/lib/modules/date-range-picker/date-range.service.mjs +97 -0
  9. package/esm2020/lib/modules/date-range-picker/types/date-range-calculation.mjs +2 -0
  10. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-config.mjs +2 -0
  11. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.mjs +2 -0
  12. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-id.mjs +118 -0
  13. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-type.mjs +23 -0
  14. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator-validate-function.mjs +2 -0
  15. package/esm2020/lib/modules/date-range-picker/types/date-range-calculator.mjs +56 -0
  16. package/esm2020/lib/modules/date-range-picker/types/date-range-default-calculator-config.mjs +2 -0
  17. package/esm2020/lib/modules/date-range-picker/types/date-range-default-calculator-configs.mjs +147 -0
  18. package/esm2020/lib/modules/date-range-picker/types/date-range-relative-value.mjs +249 -0
  19. package/esm2020/lib/modules/date-range-picker/types/date-range.mjs +2 -0
  20. package/esm2020/lib/modules/datepicker/date-formatter.mjs +38 -0
  21. package/esm2020/lib/modules/datepicker/datepicker-adapter.service.mjs +33 -0
  22. package/esm2020/lib/modules/datepicker/datepicker-calendar-change.mjs +2 -0
  23. package/esm2020/lib/modules/datepicker/datepicker-calendar-inner.component.mjs +310 -0
  24. package/esm2020/lib/modules/datepicker/datepicker-calendar.component.mjs +104 -0
  25. package/esm2020/lib/modules/datepicker/datepicker-config.service.mjs +21 -0
  26. package/esm2020/lib/modules/datepicker/datepicker-custom-date.mjs +2 -0
  27. package/esm2020/lib/modules/datepicker/datepicker-date.mjs +2 -0
  28. package/esm2020/lib/modules/datepicker/datepicker-input-fuzzy.directive.mjs +466 -0
  29. package/esm2020/lib/modules/datepicker/datepicker-input.directive.mjs +445 -0
  30. package/esm2020/lib/modules/datepicker/datepicker.component.mjs +328 -0
  31. package/esm2020/lib/modules/datepicker/datepicker.module.mjs +95 -0
  32. package/esm2020/lib/modules/datepicker/datepicker.service.mjs +21 -0
  33. package/esm2020/lib/modules/datepicker/daypicker-button.component.mjs +22 -0
  34. package/esm2020/lib/modules/datepicker/daypicker-cell.component.mjs +126 -0
  35. package/esm2020/lib/modules/datepicker/daypicker.component.mjs +211 -0
  36. package/esm2020/lib/modules/datepicker/fuzzy-date.mjs +2 -0
  37. package/esm2020/lib/modules/datepicker/fuzzy-date.service.mjs +403 -0
  38. package/esm2020/lib/modules/datepicker/monthpicker.component.mjs +80 -0
  39. package/esm2020/lib/modules/datepicker/yearpicker.component.mjs +86 -0
  40. package/esm2020/lib/modules/shared/sky-datetime-resources.module.mjs +131 -0
  41. package/esm2020/lib/modules/timepicker/timepicker.component.mjs +361 -0
  42. package/esm2020/lib/modules/timepicker/timepicker.directive.mjs +228 -0
  43. package/esm2020/lib/modules/timepicker/timepicker.interface.mjs +2 -0
  44. package/esm2020/lib/modules/timepicker/timepicker.module.mjs +46 -0
  45. package/esm2020/skyux-datetime.mjs +5 -0
  46. package/esm2020/testing/datepicker-fixture.mjs +54 -0
  47. package/esm2020/testing/public-api.mjs +3 -0
  48. package/esm2020/testing/skyux-datetime-testing.mjs +5 -0
  49. package/esm2020/testing/timepicker-fixture.mjs +50 -0
  50. package/fesm2015/{skyux-datetime-testing.js → skyux-datetime-testing.mjs} +1 -1
  51. package/fesm2015/skyux-datetime-testing.mjs.map +1 -0
  52. package/fesm2015/skyux-datetime.mjs +4726 -0
  53. package/fesm2015/skyux-datetime.mjs.map +1 -0
  54. package/{esm2015/testing/datepicker-fixture.js → fesm2020/skyux-datetime-testing.mjs} +57 -2
  55. package/fesm2020/skyux-datetime-testing.mjs.map +1 -0
  56. package/{fesm2015/skyux-datetime.js → fesm2020/skyux-datetime.mjs} +110 -158
  57. package/fesm2020/skyux-datetime.mjs.map +1 -0
  58. package/package.json +42 -18
  59. package/testing/package.json +5 -5
  60. package/bundles/skyux-datetime-testing.umd.js +0 -143
  61. package/bundles/skyux-datetime.umd.js +0 -5488
  62. package/esm2015/index.js +0 -28
  63. package/esm2015/index.js.map +0 -1
  64. package/esm2015/lib/modules/date-pipe/date-format-utility.js +0 -46
  65. package/esm2015/lib/modules/date-pipe/date-format-utility.js.map +0 -1
  66. package/esm2015/lib/modules/date-pipe/date-pipe.module.js +0 -21
  67. package/esm2015/lib/modules/date-pipe/date-pipe.module.js.map +0 -1
  68. package/esm2015/lib/modules/date-pipe/date.pipe.js +0 -65
  69. package/esm2015/lib/modules/date-pipe/date.pipe.js.map +0 -1
  70. package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js +0 -47
  71. package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js.map +0 -1
  72. package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js +0 -453
  73. package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js.map +0 -1
  74. package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js +0 -47
  75. package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js.map +0 -1
  76. package/esm2015/lib/modules/date-range-picker/date-range.service.js +0 -97
  77. package/esm2015/lib/modules/date-range-picker/date-range.service.js.map +0 -1
  78. package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js +0 -2
  79. package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js.map +0 -1
  80. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js +0 -2
  81. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js.map +0 -1
  82. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js +0 -2
  83. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js.map +0 -1
  84. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js +0 -118
  85. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js.map +0 -1
  86. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js +0 -23
  87. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js.map +0 -1
  88. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js +0 -2
  89. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js.map +0 -1
  90. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js +0 -56
  91. package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js.map +0 -1
  92. package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js +0 -2
  93. package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js.map +0 -1
  94. package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js +0 -147
  95. package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js.map +0 -1
  96. package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js +0 -249
  97. package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js.map +0 -1
  98. package/esm2015/lib/modules/date-range-picker/types/date-range.js +0 -2
  99. package/esm2015/lib/modules/date-range-picker/types/date-range.js.map +0 -1
  100. package/esm2015/lib/modules/datepicker/date-formatter.js +0 -38
  101. package/esm2015/lib/modules/datepicker/date-formatter.js.map +0 -1
  102. package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js +0 -33
  103. package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js.map +0 -1
  104. package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js +0 -2
  105. package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js.map +0 -1
  106. package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js +0 -315
  107. package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js.map +0 -1
  108. package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js +0 -109
  109. package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js.map +0 -1
  110. package/esm2015/lib/modules/datepicker/datepicker-config.service.js +0 -21
  111. package/esm2015/lib/modules/datepicker/datepicker-config.service.js.map +0 -1
  112. package/esm2015/lib/modules/datepicker/datepicker-custom-date.js +0 -2
  113. package/esm2015/lib/modules/datepicker/datepicker-custom-date.js.map +0 -1
  114. package/esm2015/lib/modules/datepicker/datepicker-date.js +0 -2
  115. package/esm2015/lib/modules/datepicker/datepicker-date.js.map +0 -1
  116. package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js +0 -467
  117. package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js.map +0 -1
  118. package/esm2015/lib/modules/datepicker/datepicker-input.directive.js +0 -446
  119. package/esm2015/lib/modules/datepicker/datepicker-input.directive.js.map +0 -1
  120. package/esm2015/lib/modules/datepicker/datepicker.component.js +0 -333
  121. package/esm2015/lib/modules/datepicker/datepicker.component.js.map +0 -1
  122. package/esm2015/lib/modules/datepicker/datepicker.module.js +0 -95
  123. package/esm2015/lib/modules/datepicker/datepicker.module.js.map +0 -1
  124. package/esm2015/lib/modules/datepicker/datepicker.service.js +0 -21
  125. package/esm2015/lib/modules/datepicker/datepicker.service.js.map +0 -1
  126. package/esm2015/lib/modules/datepicker/daypicker-button.component.js +0 -26
  127. package/esm2015/lib/modules/datepicker/daypicker-button.component.js.map +0 -1
  128. package/esm2015/lib/modules/datepicker/daypicker-cell.component.js +0 -130
  129. package/esm2015/lib/modules/datepicker/daypicker-cell.component.js.map +0 -1
  130. package/esm2015/lib/modules/datepicker/daypicker.component.js +0 -215
  131. package/esm2015/lib/modules/datepicker/daypicker.component.js.map +0 -1
  132. package/esm2015/lib/modules/datepicker/fuzzy-date.js +0 -2
  133. package/esm2015/lib/modules/datepicker/fuzzy-date.js.map +0 -1
  134. package/esm2015/lib/modules/datepicker/fuzzy-date.service.js +0 -403
  135. package/esm2015/lib/modules/datepicker/fuzzy-date.service.js.map +0 -1
  136. package/esm2015/lib/modules/datepicker/monthpicker.component.js +0 -84
  137. package/esm2015/lib/modules/datepicker/monthpicker.component.js.map +0 -1
  138. package/esm2015/lib/modules/datepicker/yearpicker.component.js +0 -90
  139. package/esm2015/lib/modules/datepicker/yearpicker.component.js.map +0 -1
  140. package/esm2015/lib/modules/shared/sky-datetime-resources.module.js +0 -131
  141. package/esm2015/lib/modules/shared/sky-datetime-resources.module.js.map +0 -1
  142. package/esm2015/lib/modules/timepicker/timepicker.component.js +0 -367
  143. package/esm2015/lib/modules/timepicker/timepicker.component.js.map +0 -1
  144. package/esm2015/lib/modules/timepicker/timepicker.directive.js +0 -228
  145. package/esm2015/lib/modules/timepicker/timepicker.directive.js.map +0 -1
  146. package/esm2015/lib/modules/timepicker/timepicker.interface.js +0 -2
  147. package/esm2015/lib/modules/timepicker/timepicker.interface.js.map +0 -1
  148. package/esm2015/lib/modules/timepicker/timepicker.module.js +0 -46
  149. package/esm2015/lib/modules/timepicker/timepicker.module.js.map +0 -1
  150. package/esm2015/skyux-datetime.js +0 -5
  151. package/esm2015/skyux-datetime.js.map +0 -1
  152. package/esm2015/testing/datepicker-fixture.js.map +0 -1
  153. package/esm2015/testing/public-api.js +0 -3
  154. package/esm2015/testing/public-api.js.map +0 -1
  155. package/esm2015/testing/skyux-datetime-testing.js +0 -5
  156. package/esm2015/testing/skyux-datetime-testing.js.map +0 -1
  157. package/esm2015/testing/timepicker-fixture.js +0 -50
  158. package/esm2015/testing/timepicker-fixture.js.map +0 -1
  159. package/fesm2015/skyux-datetime-testing.js.map +0 -1
  160. package/fesm2015/skyux-datetime.js.map +0 -1
@@ -1,446 +0,0 @@
1
- import { ChangeDetectorRef, Directive, ElementRef, HostListener, Input, Optional, Renderer2, forwardRef, } from '@angular/core';
2
- import { NG_VALIDATORS, NG_VALUE_ACCESSOR, } from '@angular/forms';
3
- import { SkyAppLocaleProvider, SkyLibResourcesService } from '@skyux/i18n';
4
- import moment from 'moment';
5
- import { Subject } from 'rxjs';
6
- import { distinctUntilChanged, takeUntil } from 'rxjs/operators';
7
- import { SkyDateFormatter } from './date-formatter';
8
- import { SkyDatepickerAdapterService } from './datepicker-adapter.service';
9
- import { SkyDatepickerConfigService } from './datepicker-config.service';
10
- import { SkyDatepickerComponent } from './datepicker.component';
11
- import * as i0 from "@angular/core";
12
- import * as i1 from "./datepicker-adapter.service";
13
- import * as i2 from "./datepicker-config.service";
14
- import * as i3 from "@skyux/i18n";
15
- import * as i4 from "./datepicker.component";
16
- // tslint:disable:no-forward-ref no-use-before-declare
17
- const SKY_DATEPICKER_VALUE_ACCESSOR = {
18
- provide: NG_VALUE_ACCESSOR,
19
- useExisting: forwardRef(() => SkyDatepickerInputDirective),
20
- multi: true,
21
- };
22
- const SKY_DATEPICKER_VALIDATOR = {
23
- provide: NG_VALIDATORS,
24
- useExisting: forwardRef(() => SkyDatepickerInputDirective),
25
- multi: true,
26
- };
27
- // tslint:enable
28
- export class SkyDatepickerInputDirective {
29
- constructor(adapter, changeDetector, configService, elementRef, localeProvider, renderer, resourcesService, datepickerComponent) {
30
- this.adapter = adapter;
31
- this.changeDetector = changeDetector;
32
- this.configService = configService;
33
- this.elementRef = elementRef;
34
- this.localeProvider = localeProvider;
35
- this.renderer = renderer;
36
- this.resourcesService = resourcesService;
37
- this.datepickerComponent = datepickerComponent;
38
- /**
39
- * Indicates whether to disable date validation on the datepicker input.
40
- * @default false
41
- */
42
- this.skyDatepickerNoValidate = false;
43
- this.dateFormatter = new SkyDateFormatter();
44
- this.ngUnsubscribe = new Subject();
45
- // eslint-disable-next-line @typescript-eslint/no-empty-function
46
- this.onChange = (_) => { };
47
- // eslint-disable-next-line @typescript-eslint/no-empty-function
48
- this.onTouched = () => { };
49
- // eslint-disable-next-line @typescript-eslint/no-empty-function
50
- this.onValidatorChange = () => { };
51
- this.initialPlaceholder = this.adapter.getPlaceholder(this.elementRef);
52
- this.updatePlaceholder();
53
- this.localeProvider
54
- .getLocaleInfo()
55
- .pipe(takeUntil(this.ngUnsubscribe))
56
- .subscribe((localeInfo) => {
57
- SkyDateFormatter.setLocale(localeInfo.locale);
58
- this.preferredShortDateFormat =
59
- SkyDateFormatter.getPreferredShortDateFormat();
60
- this.applyDateFormat();
61
- });
62
- }
63
- /**
64
- * Specifies the date format for the input. Place this attribute on the `input` element
65
- * to override the default in the `SkyDatepickerConfigService`.
66
- * @default "MM/DD/YYYY"
67
- */
68
- set dateFormat(value) {
69
- /* istanbul ignore else */
70
- if (value !== this._dateFormat) {
71
- this._dateFormat = value;
72
- this.applyDateFormat();
73
- }
74
- }
75
- get dateFormat() {
76
- return (this._dateFormat ||
77
- this.configService.dateFormat ||
78
- this.preferredShortDateFormat);
79
- }
80
- /**
81
- * Indicates whether to disable the datepicker.
82
- * @default false
83
- */
84
- set disabled(value) {
85
- this._disabled = value;
86
- this.datepickerComponent.disabled = value;
87
- this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', value);
88
- }
89
- get disabled() {
90
- return this._disabled || false;
91
- }
92
- /**
93
- * @internal
94
- * Indicates if the input element or any of its children have focus.
95
- */
96
- get inputIsFocused() {
97
- return this.adapter.elementIsFocused();
98
- }
99
- /**
100
- * Specifies the latest date that is available in the calendar. Place this attribute on
101
- * the `input` element to override the default in `SkyDatepickerConfigService`.
102
- */
103
- set maxDate(value) {
104
- this._maxDate = value;
105
- this.datepickerComponent.maxDate = this.maxDate;
106
- this.onValidatorChange();
107
- }
108
- get maxDate() {
109
- return this._maxDate || this.configService.maxDate;
110
- }
111
- /**
112
- * Specifies the earliest date that is available in the calendar. Place this attribute on
113
- * the `input` element to override the default in `SkyDatepickerConfigService`.
114
- */
115
- set minDate(value) {
116
- this._minDate = value;
117
- this.datepickerComponent.minDate = this.minDate;
118
- this.onValidatorChange();
119
- }
120
- get minDate() {
121
- return this._minDate || this.configService.minDate;
122
- }
123
- /**
124
- * Creates the datepicker input and calendar. Place this directive on an `input` element,
125
- * and wrap the input in a `sky-datepicker` component. The value that users select is driven
126
- * through the `ngModel` attribute specified on the `input` element.
127
- * @required
128
- */
129
- set skyDatepickerInput(value) {
130
- if (value) {
131
- console.warn('[Deprecation warning] You no longer need to provide a template reference variable ' +
132
- 'to the `skyDatepickerInput` attribute (this will be a breaking change in the next ' +
133
- 'major version release).\n' +
134
- 'Do this instead:\n' +
135
- '<sky-datepicker>\n <input skyDatepickerInput />\n</sky-datepicker>');
136
- }
137
- }
138
- /**
139
- * Specifies the starting day of the week in the calendar, where `0` sets the starting day
140
- * to Sunday. Place this attribute on the `input` element to override the default
141
- * in `SkyDatepickerConfigService`.
142
- * @default 0
143
- */
144
- set startingDay(value) {
145
- this._startingDay = value;
146
- this.datepickerComponent.startingDay = this.startingDay;
147
- this.onValidatorChange();
148
- }
149
- get startingDay() {
150
- return this._startingDay || this.configService.startingDay;
151
- }
152
- /**
153
- * Indicates whether the format of the date value must match the format from the `dateFormat` value.
154
- * If this property is `true` and the datepicker input directive cannot find an exact match, then
155
- * the input is marked as invalid.
156
- * If this property is `false` and the datepicker input directive cannot find an exact match, then
157
- * it attempts to format the string based on the [ISO 8601 standard format](https://www.iso.org/iso-8601-date-and-time-format.html).
158
- * @default false
159
- */
160
- set strict(value) {
161
- this._strict = value;
162
- }
163
- get strict() {
164
- return this._strict || false;
165
- }
166
- get value() {
167
- return this._value;
168
- }
169
- set value(value) {
170
- this.updateValue(value);
171
- }
172
- ngOnInit() {
173
- if (!this.datepickerComponent) {
174
- throw new Error('You must wrap the `skyDatepickerInput` directive within a ' +
175
- '`<sky-datepicker>` component!');
176
- }
177
- const element = this.elementRef.nativeElement;
178
- this.renderer.addClass(element, 'sky-form-control');
179
- const hasAriaLabel = element.getAttribute('aria-label');
180
- if (!hasAriaLabel) {
181
- this.resourcesService
182
- .getString('skyux_date_field_default_label')
183
- .pipe(takeUntil(this.ngUnsubscribe))
184
- .subscribe((value) => {
185
- this.renderer.setAttribute(element, 'aria-label', value);
186
- });
187
- }
188
- }
189
- ngAfterContentInit() {
190
- this.datepickerComponent.dateChange
191
- .pipe(distinctUntilChanged())
192
- .pipe(takeUntil(this.ngUnsubscribe))
193
- .subscribe((value) => {
194
- this.value = value;
195
- this.onTouched();
196
- });
197
- }
198
- ngAfterViewInit() {
199
- // This is needed to address a bug in Angular 4.
200
- // When a control value is set intially, its value is not represented on the view.
201
- // See: https://github.com/angular/angular/issues/13792
202
- // Of note is the parent check which allows us to determine if the form is reactive.
203
- // Without this check there is a changed before checked error
204
- /* istanbul ignore else */
205
- if (this.control && this.control.parent) {
206
- setTimeout(() => {
207
- this.control.setValue(this.value, {
208
- emitEvent: false,
209
- });
210
- this.changeDetector.markForCheck();
211
- });
212
- }
213
- this.adapter.init(this.elementRef);
214
- }
215
- ngOnDestroy() {
216
- this.ngUnsubscribe.next();
217
- this.ngUnsubscribe.complete();
218
- }
219
- onInputChange(event) {
220
- const value = event.target.value;
221
- if (this.skyDatepickerNoValidate) {
222
- this.onValueChange(value);
223
- return;
224
- }
225
- // Don't try to parse the string value into a Date value if it is malformed.
226
- if (this.isDateStringValid(value)) {
227
- this.onValueChange(value);
228
- return;
229
- }
230
- this._value = value;
231
- this.onChange(value);
232
- this.control.setErrors({
233
- skyDate: {
234
- invalid: true,
235
- },
236
- });
237
- }
238
- onInputBlur() {
239
- this.onTouched();
240
- }
241
- onInputKeyup() {
242
- this.control.markAsDirty();
243
- }
244
- writeValue(value) {
245
- this.updateValue(value, false);
246
- }
247
- validate(control) {
248
- if (!this.control) {
249
- this.control = control;
250
- }
251
- if (this.skyDatepickerNoValidate) {
252
- return;
253
- }
254
- const value = control.value;
255
- if (!value) {
256
- return;
257
- }
258
- const dateValue = this.getDateValue(value);
259
- const isDateValid = dateValue && this.dateFormatter.dateIsValid(dateValue);
260
- if (!isDateValid || !this.isDateStringValid(value)) {
261
- // Mark the invalid control as touched so that the input's invalid CSS styles appear.
262
- // (This is only required when the invalid value is set by the FormControl constructor.)
263
- this.control.markAsTouched();
264
- return {
265
- skyDate: {
266
- invalid: value,
267
- },
268
- };
269
- }
270
- const minDate = this.minDate;
271
- if (minDate && this.dateFormatter.dateIsValid(minDate) && value < minDate) {
272
- return {
273
- skyDate: {
274
- minDate,
275
- },
276
- };
277
- }
278
- const maxDate = this.maxDate;
279
- if (maxDate && this.dateFormatter.dateIsValid(maxDate) && value > maxDate) {
280
- return {
281
- skyDate: {
282
- maxDate,
283
- },
284
- };
285
- }
286
- }
287
- registerOnChange(fn) {
288
- this.onChange = fn;
289
- }
290
- registerOnTouched(fn) {
291
- this.onTouched = fn;
292
- }
293
- registerOnValidatorChange(fn) {
294
- this.onValidatorChange = fn;
295
- }
296
- setDisabledState(disabled) {
297
- this.disabled = disabled;
298
- this.datepickerComponent.disabled = disabled;
299
- }
300
- /**
301
- * Detects changes to the underlying input element's value and updates the ngModel accordingly.
302
- * This is useful if you need to update the ngModel value before the input element loses focus.
303
- */
304
- detectInputValueChange() {
305
- this.onValueChange(this.elementRef.nativeElement.value);
306
- }
307
- applyDateFormat() {
308
- this.updatePlaceholder();
309
- if (this.value) {
310
- const formattedDate = this.dateFormatter.format(this.value, this.dateFormat);
311
- this.setInputElementValue(formattedDate);
312
- this.changeDetector.markForCheck();
313
- }
314
- }
315
- onValueChange(newValue) {
316
- this.value = newValue;
317
- }
318
- setInputElementValue(value) {
319
- this.renderer.setProperty(this.elementRef.nativeElement, 'value', value);
320
- }
321
- getDateValue(value) {
322
- let dateValue;
323
- if (value instanceof Date) {
324
- dateValue = value;
325
- }
326
- else if (typeof value === 'string') {
327
- const date = this.dateFormatter.getDateFromString(value, this.dateFormat, this.strict);
328
- if (this.dateFormatter.dateIsValid(date)) {
329
- dateValue = date;
330
- }
331
- }
332
- return dateValue;
333
- }
334
- /**
335
- * Validates the input value to ensure it is formatted correctly.
336
- */
337
- isDateStringValid(value) {
338
- if (!value || typeof value !== 'string') {
339
- return true;
340
- }
341
- // Does the value only include digits, dashes, or slashes?
342
- const regexp = /^[\d/-]+$/;
343
- const isValid = regexp.test(value);
344
- if (isValid) {
345
- return true;
346
- }
347
- // If not, does it conform to the standard ISO format?
348
- const isValidIso = moment(value, moment.ISO_8601).isValid();
349
- return isValidIso;
350
- }
351
- updatePlaceholder() {
352
- if (!this.initialPlaceholder) {
353
- this.adapter.setPlaceholder(this.elementRef, this.dateFormat);
354
- }
355
- }
356
- /**
357
- * Update the value of the form control and input element
358
- * @param emitEvent Denotes if we emit an event to the consumer's form control. We do not want to do this if the value is being updated via a `setValue` call or a `patchValue` call as this is already handled by Angular.
359
- * In these cases we do not want to fire `onChange` as it will cause extra `valueChange` and `statusChange` events and the status of the form should not be affected by these changes.
360
- */
361
- updateValue(value, emitEvent = true) {
362
- var _a, _b;
363
- if (this._value === value) {
364
- return;
365
- }
366
- const dateValue = this.getDateValue(value);
367
- const areDatesEqual = this._value instanceof Date &&
368
- dateValue &&
369
- dateValue.getTime() === this._value.getTime();
370
- const isValidDateString = this.isDateStringValid(value);
371
- // If the string value supplied is malformed, do not set the value to its Date equivalent.
372
- // (JavaScript's Date parser will convert poorly formatted dates to Date objects, such as "abc 123", which isn't ideal.)
373
- if (!isValidDateString) {
374
- this._value = value;
375
- if (emitEvent) {
376
- this.onChange(this._value);
377
- }
378
- else {
379
- (_a = this.control) === null || _a === void 0 ? void 0 : _a.setValue(this._value, { emitEvent: false });
380
- }
381
- this.datepickerComponent.selectedDate = this._value;
382
- }
383
- else if (dateValue !== this._value || !areDatesEqual) {
384
- this._value = dateValue || value;
385
- if (emitEvent) {
386
- this.onChange(this._value);
387
- }
388
- else {
389
- (_b = this.control) === null || _b === void 0 ? void 0 : _b.setValue(this._value, { emitEvent: false });
390
- }
391
- this.datepickerComponent.selectedDate = this._value;
392
- }
393
- if (dateValue && isValidDateString) {
394
- const formattedDate = this.dateFormatter.format(dateValue, this.dateFormat);
395
- this.setInputElementValue(formattedDate);
396
- }
397
- else {
398
- this.setInputElementValue(value || '');
399
- }
400
- }
401
- }
402
- SkyDatepickerInputDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyDatepickerInputDirective, deps: [{ token: i1.SkyDatepickerAdapterService }, { token: i0.ChangeDetectorRef }, { token: i2.SkyDatepickerConfigService }, { token: i0.ElementRef }, { token: i3.SkyAppLocaleProvider }, { token: i0.Renderer2 }, { token: i3.SkyLibResourcesService }, { token: i4.SkyDatepickerComponent, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
403
- SkyDatepickerInputDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyDatepickerInputDirective, selector: "[skyDatepickerInput]", inputs: { dateFormat: "dateFormat", disabled: "disabled", maxDate: "maxDate", minDate: "minDate", skyDatepickerInput: "skyDatepickerInput", skyDatepickerNoValidate: "skyDatepickerNoValidate", startingDay: "startingDay", strict: "strict" }, host: { listeners: { "change": "onInputChange($event)", "blur": "onInputBlur()", "keyup": "onInputKeyup()" } }, providers: [
404
- SKY_DATEPICKER_VALUE_ACCESSOR,
405
- SKY_DATEPICKER_VALIDATOR,
406
- SkyDatepickerAdapterService,
407
- ], ngImport: i0 });
408
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyDatepickerInputDirective, decorators: [{
409
- type: Directive,
410
- args: [{
411
- selector: '[skyDatepickerInput]',
412
- providers: [
413
- SKY_DATEPICKER_VALUE_ACCESSOR,
414
- SKY_DATEPICKER_VALIDATOR,
415
- SkyDatepickerAdapterService,
416
- ],
417
- }]
418
- }], ctorParameters: function () { return [{ type: i1.SkyDatepickerAdapterService }, { type: i0.ChangeDetectorRef }, { type: i2.SkyDatepickerConfigService }, { type: i0.ElementRef }, { type: i3.SkyAppLocaleProvider }, { type: i0.Renderer2 }, { type: i3.SkyLibResourcesService }, { type: i4.SkyDatepickerComponent, decorators: [{
419
- type: Optional
420
- }] }]; }, propDecorators: { dateFormat: [{
421
- type: Input
422
- }], disabled: [{
423
- type: Input
424
- }], maxDate: [{
425
- type: Input
426
- }], minDate: [{
427
- type: Input
428
- }], skyDatepickerInput: [{
429
- type: Input
430
- }], skyDatepickerNoValidate: [{
431
- type: Input
432
- }], startingDay: [{
433
- type: Input
434
- }], strict: [{
435
- type: Input
436
- }], onInputChange: [{
437
- type: HostListener,
438
- args: ['change', ['$event']]
439
- }], onInputBlur: [{
440
- type: HostListener,
441
- args: ['blur']
442
- }], onInputKeyup: [{
443
- type: HostListener,
444
- args: ['keyup']
445
- }] } });
446
- //# sourceMappingURL=datepicker-input.directive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datepicker-input.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/datetime/src/lib/modules/datepicker/datepicker-input.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,KAAK,EAGL,QAAQ,EACR,SAAS,EACT,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,aAAa,EACb,iBAAiB,GAGlB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC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BACT,QAAQ,EAAE,sBAAsB;oBAChC,SAAS,EAAE;wBACT,6BAA6B;wBAC7B,wBAAwB;wBACxB,2BAA2B;qBAC5B;iBACF;;0BAoLI,QAAQ;4CApKA,UAAU;sBADpB,KAAK;gBAsBK,QAAQ;sBADlB,KAAK;gBAwBK,OAAO;sBADjB,KAAK;gBAiBK,OAAO;sBADjB,KAAK;gBAmBK,kBAAkB;sBAD5B,KAAK;gBAoBC,uBAAuB;sBAD7B,KAAK;gBAUK,WAAW;sBADrB,KAAK;gBAqBK,MAAM;sBADhB,KAAK;gBAmHC,aAAa;sBADnB,YAAY;uBAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC;gBA0B3B,WAAW;sBADjB,YAAY;uBAAC,MAAM;gBAMb,YAAY;sBADlB,YAAY;uBAAC,OAAO","sourcesContent":["import {\n AfterContentInit,\n AfterViewInit,\n ChangeDetectorRef,\n Directive,\n ElementRef,\n HostListener,\n Input,\n OnDestroy,\n OnInit,\n Optional,\n Renderer2,\n forwardRef,\n} from '@angular/core';\nimport {\n AbstractControl,\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator,\n} from '@angular/forms';\nimport { SkyAppLocaleProvider, SkyLibResourcesService } from '@skyux/i18n';\n\nimport moment from 'moment';\nimport { Subject } from 'rxjs';\nimport { distinctUntilChanged, takeUntil } from 'rxjs/operators';\n\nimport { SkyDateFormatter } from './date-formatter';\nimport { SkyDatepickerAdapterService } from './datepicker-adapter.service';\nimport { SkyDatepickerConfigService } from './datepicker-config.service';\nimport { SkyDatepickerComponent } from './datepicker.component';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_DATEPICKER_VALUE_ACCESSOR = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => SkyDatepickerInputDirective),\n multi: true,\n};\n\nconst SKY_DATEPICKER_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyDatepickerInputDirective),\n multi: true,\n};\n// tslint:enable\n\n@Directive({\n selector: '[skyDatepickerInput]',\n providers: [\n SKY_DATEPICKER_VALUE_ACCESSOR,\n SKY_DATEPICKER_VALIDATOR,\n SkyDatepickerAdapterService,\n ],\n})\nexport class SkyDatepickerInputDirective\n implements\n OnInit,\n OnDestroy,\n AfterViewInit,\n AfterContentInit,\n ControlValueAccessor,\n Validator\n{\n /**\n * Specifies the date format for the input. Place this attribute on the `input` element\n * to override the default in the `SkyDatepickerConfigService`.\n * @default \"MM/DD/YYYY\"\n */\n @Input()\n public set dateFormat(value: string) {\n /* istanbul ignore else */\n if (value !== this._dateFormat) {\n this._dateFormat = value;\n this.applyDateFormat();\n }\n }\n\n public get dateFormat(): string {\n return (\n this._dateFormat ||\n this.configService.dateFormat ||\n this.preferredShortDateFormat\n );\n }\n\n /**\n * Indicates whether to disable the datepicker.\n * @default false\n */\n @Input()\n public set disabled(value: boolean) {\n this._disabled = value;\n this.datepickerComponent.disabled = value;\n this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', value);\n }\n\n public get disabled(): boolean {\n return this._disabled || false;\n }\n\n /**\n * @internal\n * Indicates if the input element or any of its children have focus.\n */\n public get inputIsFocused(): boolean {\n return this.adapter.elementIsFocused();\n }\n\n /**\n * Specifies the latest date that is available in the calendar. Place this attribute on\n * the `input` element to override the default in `SkyDatepickerConfigService`.\n */\n @Input()\n public set maxDate(value: Date) {\n this._maxDate = value;\n this.datepickerComponent.maxDate = this.maxDate;\n\n this.onValidatorChange();\n }\n\n public get maxDate(): Date {\n return this._maxDate || this.configService.maxDate;\n }\n\n /**\n * Specifies the earliest date that is available in the calendar. Place this attribute on\n * the `input` element to override the default in `SkyDatepickerConfigService`.\n */\n @Input()\n public set minDate(value: Date) {\n this._minDate = value;\n this.datepickerComponent.minDate = this.minDate;\n\n this.onValidatorChange();\n }\n\n public get minDate(): Date {\n return this._minDate || this.configService.minDate;\n }\n\n /**\n * Creates the datepicker input and calendar. Place this directive on an `input` element,\n * and wrap the input in a `sky-datepicker` component. The value that users select is driven\n * through the `ngModel` attribute specified on the `input` element.\n * @required\n */\n @Input()\n public set skyDatepickerInput(\n value: SkyDatepickerComponent | undefined | ''\n ) {\n if (value) {\n console.warn(\n '[Deprecation warning] You no longer need to provide a template reference variable ' +\n 'to the `skyDatepickerInput` attribute (this will be a breaking change in the next ' +\n 'major version release).\\n' +\n 'Do this instead:\\n' +\n '<sky-datepicker>\\n <input skyDatepickerInput />\\n</sky-datepicker>'\n );\n }\n }\n\n /**\n * Indicates whether to disable date validation on the datepicker input.\n * @default false\n */\n @Input()\n public skyDatepickerNoValidate = false;\n\n /**\n * Specifies the starting day of the week in the calendar, where `0` sets the starting day\n * to Sunday. Place this attribute on the `input` element to override the default\n * in `SkyDatepickerConfigService`.\n * @default 0\n */\n @Input()\n public set startingDay(value: number) {\n this._startingDay = value;\n this.datepickerComponent.startingDay = this.startingDay;\n\n this.onValidatorChange();\n }\n\n public get startingDay(): number {\n return this._startingDay || this.configService.startingDay;\n }\n\n /**\n * Indicates whether the format of the date value must match the format from the `dateFormat` value.\n * If this property is `true` and the datepicker input directive cannot find an exact match, then\n * the input is marked as invalid.\n * If this property is `false` and the datepicker input directive cannot find an exact match, then\n * it attempts to format the string based on the [ISO 8601 standard format](https://www.iso.org/iso-8601-date-and-time-format.html).\n * @default false\n */\n @Input()\n public set strict(value: boolean) {\n this._strict = value;\n }\n\n public get strict(): boolean {\n return this._strict || false;\n }\n\n private get value(): any {\n return this._value;\n }\n\n private set value(value: any) {\n this.updateValue(value);\n }\n\n private control: AbstractControl;\n private dateFormatter = new SkyDateFormatter();\n private initialPlaceholder: string;\n private preferredShortDateFormat: string;\n private ngUnsubscribe = new Subject<void>();\n\n private _dateFormat: string;\n private _disabled: boolean;\n private _maxDate: Date;\n private _minDate: Date;\n private _startingDay: number;\n private _strict: boolean;\n private _value: any;\n\n constructor(\n private adapter: SkyDatepickerAdapterService,\n private changeDetector: ChangeDetectorRef,\n private configService: SkyDatepickerConfigService,\n private elementRef: ElementRef,\n private localeProvider: SkyAppLocaleProvider,\n private renderer: Renderer2,\n private resourcesService: SkyLibResourcesService,\n @Optional() private datepickerComponent: SkyDatepickerComponent\n ) {\n this.initialPlaceholder = this.adapter.getPlaceholder(this.elementRef);\n this.updatePlaceholder();\n\n this.localeProvider\n .getLocaleInfo()\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((localeInfo) => {\n SkyDateFormatter.setLocale(localeInfo.locale);\n this.preferredShortDateFormat =\n SkyDateFormatter.getPreferredShortDateFormat();\n this.applyDateFormat();\n });\n }\n\n public ngOnInit(): void {\n if (!this.datepickerComponent) {\n throw new Error(\n 'You must wrap the `skyDatepickerInput` directive within a ' +\n '`<sky-datepicker>` component!'\n );\n }\n\n const element = this.elementRef.nativeElement;\n\n this.renderer.addClass(element, 'sky-form-control');\n\n const hasAriaLabel = element.getAttribute('aria-label');\n\n if (!hasAriaLabel) {\n this.resourcesService\n .getString('skyux_date_field_default_label')\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((value: string) => {\n this.renderer.setAttribute(element, 'aria-label', value);\n });\n }\n }\n\n public ngAfterContentInit(): void {\n this.datepickerComponent.dateChange\n .pipe(distinctUntilChanged())\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((value: Date) => {\n this.value = value;\n this.onTouched();\n });\n }\n\n public ngAfterViewInit(): void {\n // This is needed to address a bug in Angular 4.\n // When a control value is set intially, its value is not represented on the view.\n // See: https://github.com/angular/angular/issues/13792\n // Of note is the parent check which allows us to determine if the form is reactive.\n // Without this check there is a changed before checked error\n /* istanbul ignore else */\n if (this.control && this.control.parent) {\n setTimeout(() => {\n this.control.setValue(this.value, {\n emitEvent: false,\n });\n\n this.changeDetector.markForCheck();\n });\n }\n\n this.adapter.init(this.elementRef);\n }\n\n public ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n\n @HostListener('change', ['$event'])\n public onInputChange(event: any) {\n const value = event.target.value;\n\n if (this.skyDatepickerNoValidate) {\n this.onValueChange(value);\n return;\n }\n\n // Don't try to parse the string value into a Date value if it is malformed.\n if (this.isDateStringValid(value)) {\n this.onValueChange(value);\n return;\n }\n\n this._value = value;\n this.onChange(value);\n\n this.control.setErrors({\n skyDate: {\n invalid: true,\n },\n });\n }\n\n @HostListener('blur')\n public onInputBlur(): void {\n this.onTouched();\n }\n\n @HostListener('keyup')\n public onInputKeyup(): void {\n this.control.markAsDirty();\n }\n\n public writeValue(value: any): void {\n this.updateValue(value, false);\n }\n\n public validate(control: AbstractControl): ValidationErrors {\n if (!this.control) {\n this.control = control;\n }\n\n if (this.skyDatepickerNoValidate) {\n return;\n }\n\n const value: any = control.value;\n\n if (!value) {\n return;\n }\n\n const dateValue = this.getDateValue(value);\n const isDateValid = dateValue && this.dateFormatter.dateIsValid(dateValue);\n\n if (!isDateValid || !this.isDateStringValid(value)) {\n // Mark the invalid control as touched so that the input's invalid CSS styles appear.\n // (This is only required when the invalid value is set by the FormControl constructor.)\n this.control.markAsTouched();\n\n return {\n skyDate: {\n invalid: value,\n },\n };\n }\n\n const minDate = this.minDate;\n\n if (minDate && this.dateFormatter.dateIsValid(minDate) && value < minDate) {\n return {\n skyDate: {\n minDate,\n },\n };\n }\n\n const maxDate = this.maxDate;\n\n if (maxDate && this.dateFormatter.dateIsValid(maxDate) && value > maxDate) {\n return {\n skyDate: {\n maxDate,\n },\n };\n }\n }\n\n public registerOnChange(fn: (value: any) => void): void {\n this.onChange = fn;\n }\n\n public registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n public registerOnValidatorChange(fn: () => void): void {\n this.onValidatorChange = fn;\n }\n\n public setDisabledState(disabled: boolean): void {\n this.disabled = disabled;\n this.datepickerComponent.disabled = disabled;\n }\n\n /**\n * Detects changes to the underlying input element's value and updates the ngModel accordingly.\n * This is useful if you need to update the ngModel value before the input element loses focus.\n */\n public detectInputValueChange(): void {\n this.onValueChange(this.elementRef.nativeElement.value);\n }\n\n private applyDateFormat(): void {\n this.updatePlaceholder();\n if (this.value) {\n const formattedDate = this.dateFormatter.format(\n this.value,\n this.dateFormat\n );\n this.setInputElementValue(formattedDate);\n this.changeDetector.markForCheck();\n }\n }\n\n private onValueChange(newValue: string): void {\n this.value = newValue;\n }\n\n private setInputElementValue(value: string): void {\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', value);\n }\n\n private getDateValue(value: any): Date {\n let dateValue: Date;\n if (value instanceof Date) {\n dateValue = value;\n } else if (typeof value === 'string') {\n const date = this.dateFormatter.getDateFromString(\n value,\n this.dateFormat,\n this.strict\n );\n if (this.dateFormatter.dateIsValid(date)) {\n dateValue = date;\n }\n }\n\n return dateValue;\n }\n\n /**\n * Validates the input value to ensure it is formatted correctly.\n */\n private isDateStringValid(value: string): boolean {\n if (!value || typeof value !== 'string') {\n return true;\n }\n\n // Does the value only include digits, dashes, or slashes?\n const regexp = /^[\\d/-]+$/;\n const isValid = regexp.test(value);\n\n if (isValid) {\n return true;\n }\n\n // If not, does it conform to the standard ISO format?\n const isValidIso = moment(value, moment.ISO_8601).isValid();\n\n return isValidIso;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private onChange = (_: any) => {};\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private onTouched = () => {};\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private onValidatorChange = () => {};\n\n private updatePlaceholder(): void {\n if (!this.initialPlaceholder) {\n this.adapter.setPlaceholder(this.elementRef, this.dateFormat);\n }\n }\n\n /**\n * Update the value of the form control and input element\n * @param emitEvent Denotes if we emit an event to the consumer's form control. We do not want to do this if the value is being updated via a `setValue` call or a `patchValue` call as this is already handled by Angular.\n * In these cases we do not want to fire `onChange` as it will cause extra `valueChange` and `statusChange` events and the status of the form should not be affected by these changes.\n */\n private updateValue(value: any, emitEvent = true): void {\n if (this._value === value) {\n return;\n }\n\n const dateValue = this.getDateValue(value);\n\n const areDatesEqual =\n this._value instanceof Date &&\n dateValue &&\n dateValue.getTime() === this._value.getTime();\n\n const isValidDateString = this.isDateStringValid(value);\n\n // If the string value supplied is malformed, do not set the value to its Date equivalent.\n // (JavaScript's Date parser will convert poorly formatted dates to Date objects, such as \"abc 123\", which isn't ideal.)\n if (!isValidDateString) {\n this._value = value;\n if (emitEvent) {\n this.onChange(this._value);\n } else {\n this.control?.setValue(this._value, { emitEvent: false });\n }\n\n this.datepickerComponent.selectedDate = this._value;\n } else if (dateValue !== this._value || !areDatesEqual) {\n this._value = dateValue || value;\n if (emitEvent) {\n this.onChange(this._value);\n } else {\n this.control?.setValue(this._value, { emitEvent: false });\n }\n\n this.datepickerComponent.selectedDate = this._value;\n }\n\n if (dateValue && isValidDateString) {\n const formattedDate = this.dateFormatter.format(\n dateValue,\n this.dateFormat\n );\n this.setInputElementValue(formattedDate);\n } else {\n this.setInputElementValue(value || '');\n }\n }\n}\n"]}