@skyux/datetime 5.1.4 → 5.5.0
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/README.md +6 -4
- package/bundles/skyux-datetime.umd.js +80 -80
- package/documentation.json +379 -22
- package/esm2015/index.js +28 -0
- package/esm2015/index.js.map +1 -0
- package/esm2015/lib/modules/date-pipe/date-format-utility.js +48 -0
- package/esm2015/lib/modules/date-pipe/date-format-utility.js.map +1 -0
- package/esm2015/lib/modules/date-pipe/date-pipe.module.js +21 -0
- package/esm2015/lib/modules/date-pipe/date-pipe.module.js.map +1 -0
- package/esm2015/lib/modules/date-pipe/date.pipe.js +65 -0
- package/esm2015/lib/modules/date-pipe/date.pipe.js.map +1 -0
- package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js +47 -0
- package/esm2015/lib/modules/date-pipe/fuzzy-date.pipe.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js +464 -0
- package/esm2015/lib/modules/date-range-picker/date-range-picker.component.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js +47 -0
- package/esm2015/lib/modules/date-range-picker/date-range-picker.module.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/date-range.service.js +97 -0
- package/esm2015/lib/modules/date-range-picker/date-range.service.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculation.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-config.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-date-range-function.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js +118 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-id.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js +23 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-type.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator-validate-function.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js +56 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-calculator.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-config.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js +147 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-default-calculator-configs.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js +252 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range-relative-value.js.map +1 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range.js +2 -0
- package/esm2015/lib/modules/date-range-picker/types/date-range.js.map +1 -0
- package/esm2015/lib/modules/datepicker/date-formatter.js +38 -0
- package/esm2015/lib/modules/datepicker/date-formatter.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js +33 -0
- package/esm2015/lib/modules/datepicker/datepicker-adapter.service.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js +2 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar-change.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js +315 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar-inner.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js +109 -0
- package/esm2015/lib/modules/datepicker/datepicker-calendar.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-config.service.js +21 -0
- package/esm2015/lib/modules/datepicker/datepicker-config.service.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-custom-date.js +2 -0
- package/esm2015/lib/modules/datepicker/datepicker-custom-date.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-date.js +2 -0
- package/esm2015/lib/modules/datepicker/datepicker-date.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js +457 -0
- package/esm2015/lib/modules/datepicker/datepicker-input-fuzzy.directive.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker-input.directive.js +435 -0
- package/esm2015/lib/modules/datepicker/datepicker-input.directive.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker.component.js +333 -0
- package/esm2015/lib/modules/datepicker/datepicker.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker.module.js +95 -0
- package/esm2015/lib/modules/datepicker/datepicker.module.js.map +1 -0
- package/esm2015/lib/modules/datepicker/datepicker.service.js +21 -0
- package/esm2015/lib/modules/datepicker/datepicker.service.js.map +1 -0
- package/esm2015/lib/modules/datepicker/daypicker-button.component.js +26 -0
- package/esm2015/lib/modules/datepicker/daypicker-button.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/daypicker-cell.component.js +130 -0
- package/esm2015/lib/modules/datepicker/daypicker-cell.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/daypicker.component.js +215 -0
- package/esm2015/lib/modules/datepicker/daypicker.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/fuzzy-date.js +2 -0
- package/esm2015/lib/modules/datepicker/fuzzy-date.js.map +1 -0
- package/esm2015/lib/modules/datepicker/fuzzy-date.service.js +403 -0
- package/esm2015/lib/modules/datepicker/fuzzy-date.service.js.map +1 -0
- package/esm2015/lib/modules/datepicker/monthpicker.component.js +84 -0
- package/esm2015/lib/modules/datepicker/monthpicker.component.js.map +1 -0
- package/esm2015/lib/modules/datepicker/yearpicker.component.js +90 -0
- package/esm2015/lib/modules/datepicker/yearpicker.component.js.map +1 -0
- package/esm2015/lib/modules/shared/sky-datetime-resources.module.js +131 -0
- package/esm2015/lib/modules/shared/sky-datetime-resources.module.js.map +1 -0
- package/esm2015/lib/modules/timepicker/timepicker.component.js +367 -0
- package/esm2015/lib/modules/timepicker/timepicker.component.js.map +1 -0
- package/esm2015/lib/modules/timepicker/timepicker.directive.js +229 -0
- package/esm2015/lib/modules/timepicker/timepicker.directive.js.map +1 -0
- package/esm2015/lib/modules/timepicker/timepicker.interface.js +2 -0
- package/esm2015/lib/modules/timepicker/timepicker.interface.js.map +1 -0
- package/esm2015/lib/modules/timepicker/timepicker.module.js +46 -0
- package/esm2015/lib/modules/timepicker/timepicker.module.js.map +1 -0
- package/esm2015/skyux-datetime.js +2 -2
- package/esm2015/skyux-datetime.js.map +1 -0
- package/esm2015/testing/datepicker-fixture.js +1 -1
- package/esm2015/testing/datepicker-fixture.js.map +1 -0
- package/esm2015/testing/public-api.js +1 -1
- package/esm2015/testing/public-api.js.map +1 -0
- package/esm2015/testing/skyux-datetime-testing.js +1 -1
- package/esm2015/testing/skyux-datetime-testing.js.map +1 -0
- package/esm2015/testing/timepicker-fixture.js +1 -1
- package/esm2015/testing/timepicker-fixture.js.map +1 -0
- package/fesm2015/skyux-datetime-testing.js.map +1 -1
- package/fesm2015/skyux-datetime.js +301 -301
- package/fesm2015/skyux-datetime.js.map +1 -1
- package/index.d.ts +25 -0
- package/{modules → lib/modules}/date-pipe/date-format-utility.d.ts +0 -0
- package/{modules → lib/modules}/date-pipe/date-pipe.module.d.ts +0 -0
- package/{modules → lib/modules}/date-pipe/date.pipe.d.ts +0 -0
- package/{modules → lib/modules}/date-pipe/fuzzy-date.pipe.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/date-range-picker.component.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/date-range-picker.module.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/date-range.service.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculation.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator-config.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator-date-range-function.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator-id.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator-type.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator-validate-function.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-calculator.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-default-calculator-config.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-default-calculator-configs.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range-relative-value.d.ts +0 -0
- package/{modules → lib/modules}/date-range-picker/types/date-range.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/date-formatter.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-adapter.service.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-calendar-change.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-calendar-inner.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-calendar.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-config.service.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-custom-date.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-date.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-input-fuzzy.directive.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker-input.directive.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker.module.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/datepicker.service.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/daypicker-button.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/daypicker-cell.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/daypicker.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/fuzzy-date.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/fuzzy-date.service.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/monthpicker.component.d.ts +0 -0
- package/{modules → lib/modules}/datepicker/yearpicker.component.d.ts +0 -0
- package/{modules → lib/modules}/shared/sky-datetime-resources.module.d.ts +0 -0
- package/{modules → lib/modules}/timepicker/timepicker.component.d.ts +0 -0
- package/{modules → lib/modules}/timepicker/timepicker.directive.d.ts +0 -0
- package/{modules → lib/modules}/timepicker/timepicker.interface.d.ts +0 -0
- package/{modules → lib/modules}/timepicker/timepicker.module.d.ts +0 -0
- package/package.json +24 -10
- package/skyux-datetime.d.ts +1 -1
- package/LICENSE +0 -21
- package/bundles/skyux-datetime-testing.umd.js.map +0 -1
- package/bundles/skyux-datetime.umd.js.map +0 -1
- package/esm2015/modules/date-pipe/date-format-utility.js +0 -48
- package/esm2015/modules/date-pipe/date-pipe.module.js +0 -21
- package/esm2015/modules/date-pipe/date.pipe.js +0 -64
- package/esm2015/modules/date-pipe/fuzzy-date.pipe.js +0 -46
- package/esm2015/modules/date-range-picker/date-range-picker.component.js +0 -460
- package/esm2015/modules/date-range-picker/date-range-picker.module.js +0 -47
- package/esm2015/modules/date-range-picker/date-range.service.js +0 -96
- package/esm2015/modules/date-range-picker/types/date-range-calculation.js +0 -2
- package/esm2015/modules/date-range-picker/types/date-range-calculator-config.js +0 -2
- package/esm2015/modules/date-range-picker/types/date-range-calculator-date-range-function.js +0 -2
- package/esm2015/modules/date-range-picker/types/date-range-calculator-id.js +0 -118
- package/esm2015/modules/date-range-picker/types/date-range-calculator-type.js +0 -23
- package/esm2015/modules/date-range-picker/types/date-range-calculator-validate-function.js +0 -2
- package/esm2015/modules/date-range-picker/types/date-range-calculator.js +0 -56
- package/esm2015/modules/date-range-picker/types/date-range-default-calculator-config.js +0 -2
- package/esm2015/modules/date-range-picker/types/date-range-default-calculator-configs.js +0 -147
- package/esm2015/modules/date-range-picker/types/date-range-relative-value.js +0 -252
- package/esm2015/modules/date-range-picker/types/date-range.js +0 -2
- package/esm2015/modules/datepicker/date-formatter.js +0 -38
- package/esm2015/modules/datepicker/datepicker-adapter.service.js +0 -33
- package/esm2015/modules/datepicker/datepicker-calendar-change.js +0 -2
- package/esm2015/modules/datepicker/datepicker-calendar-inner.component.js +0 -315
- package/esm2015/modules/datepicker/datepicker-calendar.component.js +0 -108
- package/esm2015/modules/datepicker/datepicker-config.service.js +0 -21
- package/esm2015/modules/datepicker/datepicker-custom-date.js +0 -2
- package/esm2015/modules/datepicker/datepicker-date.js +0 -2
- package/esm2015/modules/datepicker/datepicker-input-fuzzy.directive.js +0 -453
- package/esm2015/modules/datepicker/datepicker-input.directive.js +0 -432
- package/esm2015/modules/datepicker/datepicker.component.js +0 -331
- package/esm2015/modules/datepicker/datepicker.module.js +0 -95
- package/esm2015/modules/datepicker/datepicker.service.js +0 -21
- package/esm2015/modules/datepicker/daypicker-button.component.js +0 -25
- package/esm2015/modules/datepicker/daypicker-cell.component.js +0 -128
- package/esm2015/modules/datepicker/daypicker.component.js +0 -214
- package/esm2015/modules/datepicker/fuzzy-date.js +0 -2
- package/esm2015/modules/datepicker/fuzzy-date.service.js +0 -402
- package/esm2015/modules/datepicker/monthpicker.component.js +0 -83
- package/esm2015/modules/datepicker/yearpicker.component.js +0 -89
- package/esm2015/modules/shared/sky-datetime-resources.module.js +0 -131
- package/esm2015/modules/timepicker/timepicker.component.js +0 -365
- package/esm2015/modules/timepicker/timepicker.directive.js +0 -227
- package/esm2015/modules/timepicker/timepicker.interface.js +0 -2
- package/esm2015/modules/timepicker/timepicker.module.js +0 -46
- package/esm2015/public-api.js +0 -28
- package/public-api.d.ts +0 -25
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { ChangeDetectorRef, Directive, ElementRef, forwardRef, HostListener, Input, Optional, Renderer2, } from '@angular/core';
|
|
2
|
+
import { NG_VALIDATORS, NG_VALUE_ACCESSOR, } from '@angular/forms';
|
|
3
|
+
import { SkyAppLocaleProvider, SkyLibResourcesService } from '@skyux/i18n';
|
|
4
|
+
import { Subject } from 'rxjs';
|
|
5
|
+
import { distinctUntilChanged, takeUntil } from 'rxjs/operators';
|
|
6
|
+
import { SkyDateFormatter } from './date-formatter';
|
|
7
|
+
import { SkyDatepickerAdapterService } from './datepicker-adapter.service';
|
|
8
|
+
import { SkyDatepickerConfigService } from './datepicker-config.service';
|
|
9
|
+
import { SkyDatepickerComponent } from './datepicker.component';
|
|
10
|
+
import moment from 'moment';
|
|
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.isFirstChange = true;
|
|
45
|
+
this.ngUnsubscribe = new Subject();
|
|
46
|
+
this.onChange = (_) => { };
|
|
47
|
+
/*istanbul ignore next */
|
|
48
|
+
this.onTouched = () => { };
|
|
49
|
+
this.onValidatorChange = () => { };
|
|
50
|
+
this.initialPlaceholder = this.adapter.getPlaceholder(this.elementRef);
|
|
51
|
+
this.updatePlaceholder();
|
|
52
|
+
this.localeProvider
|
|
53
|
+
.getLocaleInfo()
|
|
54
|
+
.pipe(takeUntil(this.ngUnsubscribe))
|
|
55
|
+
.subscribe((localeInfo) => {
|
|
56
|
+
SkyDateFormatter.setLocale(localeInfo.locale);
|
|
57
|
+
this.preferredShortDateFormat =
|
|
58
|
+
SkyDateFormatter.getPreferredShortDateFormat();
|
|
59
|
+
this.applyDateFormat();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Specifies the date format for the input. Place this attribute on the `input` element
|
|
64
|
+
* to override the default in the `SkyDatepickerConfigService`.
|
|
65
|
+
* @default "MM/DD/YYYY"
|
|
66
|
+
*/
|
|
67
|
+
set dateFormat(value) {
|
|
68
|
+
/* istanbul ignore else */
|
|
69
|
+
if (value !== this._dateFormat) {
|
|
70
|
+
this._dateFormat = value;
|
|
71
|
+
this.applyDateFormat();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
get dateFormat() {
|
|
75
|
+
return (this._dateFormat ||
|
|
76
|
+
this.configService.dateFormat ||
|
|
77
|
+
this.preferredShortDateFormat);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Indicates whether to disable the datepicker.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
set disabled(value) {
|
|
84
|
+
this._disabled = value;
|
|
85
|
+
this.datepickerComponent.disabled = value;
|
|
86
|
+
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', value);
|
|
87
|
+
}
|
|
88
|
+
get disabled() {
|
|
89
|
+
return this._disabled || false;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
* Indicates if the input element or any of its children have focus.
|
|
94
|
+
*/
|
|
95
|
+
get inputIsFocused() {
|
|
96
|
+
return this.adapter.elementIsFocused();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Specifies the latest date that is available in the calendar. Place this attribute on
|
|
100
|
+
* the `input` element to override the default in `SkyDatepickerConfigService`.
|
|
101
|
+
*/
|
|
102
|
+
set maxDate(value) {
|
|
103
|
+
this._maxDate = value;
|
|
104
|
+
this.datepickerComponent.maxDate = this.maxDate;
|
|
105
|
+
this.onValidatorChange();
|
|
106
|
+
}
|
|
107
|
+
get maxDate() {
|
|
108
|
+
return this._maxDate || this.configService.maxDate;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Specifies the earliest date that is available in the calendar. Place this attribute on
|
|
112
|
+
* the `input` element to override the default in `SkyDatepickerConfigService`.
|
|
113
|
+
*/
|
|
114
|
+
set minDate(value) {
|
|
115
|
+
this._minDate = value;
|
|
116
|
+
this.datepickerComponent.minDate = this.minDate;
|
|
117
|
+
this.onValidatorChange();
|
|
118
|
+
}
|
|
119
|
+
get minDate() {
|
|
120
|
+
return this._minDate || this.configService.minDate;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates the datepicker input and calendar. Place this directive on an `input` element,
|
|
124
|
+
* and wrap the input in a `sky-datepicker` component. The value that users select is driven
|
|
125
|
+
* through the `ngModel` attribute specified on the `input` element.
|
|
126
|
+
* @required
|
|
127
|
+
*/
|
|
128
|
+
set skyDatepickerInput(value) {
|
|
129
|
+
if (value) {
|
|
130
|
+
console.warn('[Deprecation warning] You no longer need to provide a template reference variable ' +
|
|
131
|
+
'to the `skyDatepickerInput` attribute (this will be a breaking change in the next ' +
|
|
132
|
+
'major version release).\n' +
|
|
133
|
+
'Do this instead:\n' +
|
|
134
|
+
'<sky-datepicker>\n <input skyDatepickerInput />\n</sky-datepicker>');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Specifies the starting day of the week in the calendar, where `0` sets the starting day
|
|
139
|
+
* to Sunday. Place this attribute on the `input` element to override the default
|
|
140
|
+
* in `SkyDatepickerConfigService`.
|
|
141
|
+
* @default 0
|
|
142
|
+
*/
|
|
143
|
+
set startingDay(value) {
|
|
144
|
+
this._startingDay = value;
|
|
145
|
+
this.datepickerComponent.startingDay = this.startingDay;
|
|
146
|
+
this.onValidatorChange();
|
|
147
|
+
}
|
|
148
|
+
get startingDay() {
|
|
149
|
+
return this._startingDay || this.configService.startingDay;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Indicates whether the format of the date value must match the format from the `dateFormat` value.
|
|
153
|
+
* If this property is `true` and the datepicker input directive cannot find an exact match, then
|
|
154
|
+
* the input is marked as invalid.
|
|
155
|
+
* If this property is `false` and the datepicker input directive cannot find an exact match, then
|
|
156
|
+
* it attempts to format the string based on the [ISO 8601 standard format](https://www.iso.org/iso-8601-date-and-time-format.html).
|
|
157
|
+
* @default false
|
|
158
|
+
*/
|
|
159
|
+
set strict(value) {
|
|
160
|
+
this._strict = value;
|
|
161
|
+
}
|
|
162
|
+
get strict() {
|
|
163
|
+
return this._strict || false;
|
|
164
|
+
}
|
|
165
|
+
get value() {
|
|
166
|
+
return this._value;
|
|
167
|
+
}
|
|
168
|
+
set value(value) {
|
|
169
|
+
const dateValue = this.getDateValue(value);
|
|
170
|
+
const areDatesEqual = this._value instanceof Date &&
|
|
171
|
+
dateValue &&
|
|
172
|
+
dateValue.getTime() === this._value.getTime();
|
|
173
|
+
const isValidDateString = this.isDateStringValid(value);
|
|
174
|
+
// If the string value supplied is malformed, do not set the value to its Date equivalent.
|
|
175
|
+
// (JavaScript's Date parser will convert poorly formatted dates to Date objects, such as "abc 123", which isn't ideal.)
|
|
176
|
+
if (!isValidDateString) {
|
|
177
|
+
this._value = value;
|
|
178
|
+
this.notifyUpdatedValue();
|
|
179
|
+
}
|
|
180
|
+
else if (dateValue !== this._value || !areDatesEqual) {
|
|
181
|
+
this._value = dateValue || value;
|
|
182
|
+
this.notifyUpdatedValue();
|
|
183
|
+
}
|
|
184
|
+
if (dateValue && isValidDateString) {
|
|
185
|
+
const formattedDate = this.dateFormatter.format(dateValue, this.dateFormat);
|
|
186
|
+
this.setInputElementValue(formattedDate);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.setInputElementValue(value || '');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
ngOnInit() {
|
|
193
|
+
if (!this.datepickerComponent) {
|
|
194
|
+
throw new Error('You must wrap the `skyDatepickerInput` directive within a ' +
|
|
195
|
+
'`<sky-datepicker>` component!');
|
|
196
|
+
}
|
|
197
|
+
const element = this.elementRef.nativeElement;
|
|
198
|
+
this.renderer.addClass(element, 'sky-form-control');
|
|
199
|
+
const hasAriaLabel = element.getAttribute('aria-label');
|
|
200
|
+
if (!hasAriaLabel) {
|
|
201
|
+
this.resourcesService
|
|
202
|
+
.getString('skyux_date_field_default_label')
|
|
203
|
+
.pipe(takeUntil(this.ngUnsubscribe))
|
|
204
|
+
.subscribe((value) => {
|
|
205
|
+
this.renderer.setAttribute(element, 'aria-label', value);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
ngAfterContentInit() {
|
|
210
|
+
this.datepickerComponent.dateChange
|
|
211
|
+
.pipe(distinctUntilChanged())
|
|
212
|
+
.pipe(takeUntil(this.ngUnsubscribe))
|
|
213
|
+
.subscribe((value) => {
|
|
214
|
+
this.isFirstChange = false;
|
|
215
|
+
this.value = value;
|
|
216
|
+
this.onTouched();
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
ngAfterViewInit() {
|
|
220
|
+
// This is needed to address a bug in Angular 4.
|
|
221
|
+
// When a control value is set intially, its value is not represented on the view.
|
|
222
|
+
// See: https://github.com/angular/angular/issues/13792
|
|
223
|
+
// Of note is the parent check which allows us to determine if the form is reactive.
|
|
224
|
+
// Without this check there is a changed before checked error
|
|
225
|
+
/* istanbul ignore else */
|
|
226
|
+
if (this.control && this.control.parent) {
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
this.control.setValue(this.value, {
|
|
229
|
+
emitEvent: false,
|
|
230
|
+
});
|
|
231
|
+
this.changeDetector.markForCheck();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
this.adapter.init(this.elementRef);
|
|
235
|
+
}
|
|
236
|
+
ngOnDestroy() {
|
|
237
|
+
this.ngUnsubscribe.next();
|
|
238
|
+
this.ngUnsubscribe.complete();
|
|
239
|
+
}
|
|
240
|
+
onInputChange(event) {
|
|
241
|
+
const value = event.target.value;
|
|
242
|
+
if (this.skyDatepickerNoValidate) {
|
|
243
|
+
this.onValueChange(value);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// Don't try to parse the string value into a Date value if it is malformed.
|
|
247
|
+
if (this.isDateStringValid(value)) {
|
|
248
|
+
this.onValueChange(value);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this._value = value;
|
|
252
|
+
this.onChange(value);
|
|
253
|
+
this.control.setErrors({
|
|
254
|
+
skyDate: {
|
|
255
|
+
invalid: true,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
onInputBlur() {
|
|
260
|
+
this.onTouched();
|
|
261
|
+
}
|
|
262
|
+
onInputKeyup() {
|
|
263
|
+
this.control.markAsDirty();
|
|
264
|
+
}
|
|
265
|
+
writeValue(value) {
|
|
266
|
+
this.value = value;
|
|
267
|
+
}
|
|
268
|
+
validate(control) {
|
|
269
|
+
if (!this.control) {
|
|
270
|
+
this.control = control;
|
|
271
|
+
}
|
|
272
|
+
if (this.skyDatepickerNoValidate) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const value = control.value;
|
|
276
|
+
if (!value) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const dateValue = this.getDateValue(value);
|
|
280
|
+
const isDateValid = dateValue && this.dateFormatter.dateIsValid(dateValue);
|
|
281
|
+
if (!isDateValid || !this.isDateStringValid(value)) {
|
|
282
|
+
// Mark the invalid control as touched so that the input's invalid CSS styles appear.
|
|
283
|
+
// (This is only required when the invalid value is set by the FormControl constructor.)
|
|
284
|
+
this.control.markAsTouched();
|
|
285
|
+
return {
|
|
286
|
+
skyDate: {
|
|
287
|
+
invalid: value,
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const minDate = this.minDate;
|
|
292
|
+
if (minDate && this.dateFormatter.dateIsValid(minDate) && value < minDate) {
|
|
293
|
+
return {
|
|
294
|
+
skyDate: {
|
|
295
|
+
minDate,
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const maxDate = this.maxDate;
|
|
300
|
+
if (maxDate && this.dateFormatter.dateIsValid(maxDate) && value > maxDate) {
|
|
301
|
+
return {
|
|
302
|
+
skyDate: {
|
|
303
|
+
maxDate,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
registerOnChange(fn) {
|
|
309
|
+
this.onChange = fn;
|
|
310
|
+
}
|
|
311
|
+
registerOnTouched(fn) {
|
|
312
|
+
this.onTouched = fn;
|
|
313
|
+
}
|
|
314
|
+
registerOnValidatorChange(fn) {
|
|
315
|
+
this.onValidatorChange = fn;
|
|
316
|
+
}
|
|
317
|
+
setDisabledState(disabled) {
|
|
318
|
+
this.disabled = disabled;
|
|
319
|
+
this.datepickerComponent.disabled = disabled;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Detects changes to the underlying input element's value and updates the ngModel accordingly.
|
|
323
|
+
* This is useful if you need to update the ngModel value before the input element loses focus.
|
|
324
|
+
*/
|
|
325
|
+
detectInputValueChange() {
|
|
326
|
+
this.onValueChange(this.elementRef.nativeElement.value);
|
|
327
|
+
}
|
|
328
|
+
applyDateFormat() {
|
|
329
|
+
this.updatePlaceholder();
|
|
330
|
+
if (this.value) {
|
|
331
|
+
const formattedDate = this.dateFormatter.format(this.value, this.dateFormat);
|
|
332
|
+
this.setInputElementValue(formattedDate);
|
|
333
|
+
this.changeDetector.markForCheck();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
onValueChange(newValue) {
|
|
337
|
+
this.isFirstChange = false;
|
|
338
|
+
this.value = newValue;
|
|
339
|
+
}
|
|
340
|
+
setInputElementValue(value) {
|
|
341
|
+
this.renderer.setProperty(this.elementRef.nativeElement, 'value', value);
|
|
342
|
+
}
|
|
343
|
+
getDateValue(value) {
|
|
344
|
+
let dateValue;
|
|
345
|
+
if (value instanceof Date) {
|
|
346
|
+
dateValue = value;
|
|
347
|
+
}
|
|
348
|
+
else if (typeof value === 'string') {
|
|
349
|
+
const date = this.dateFormatter.getDateFromString(value, this.dateFormat, this.strict);
|
|
350
|
+
if (this.dateFormatter.dateIsValid(date)) {
|
|
351
|
+
dateValue = date;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return dateValue;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Validates the input value to ensure it is formatted correctly.
|
|
358
|
+
*/
|
|
359
|
+
isDateStringValid(value) {
|
|
360
|
+
if (!value || typeof value !== 'string') {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
// Does the value only include digits, dashes, or slashes?
|
|
364
|
+
const regexp = /^[\d\/\-]+$/;
|
|
365
|
+
const isValid = regexp.test(value);
|
|
366
|
+
if (isValid) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
// If not, does it conform to the standard ISO format?
|
|
370
|
+
const isValidIso = moment(value, moment.ISO_8601).isValid();
|
|
371
|
+
return isValidIso;
|
|
372
|
+
}
|
|
373
|
+
notifyUpdatedValue() {
|
|
374
|
+
this.onChange(this._value);
|
|
375
|
+
// Do not mark the field as "dirty"
|
|
376
|
+
// if the field has been initialized with a value.
|
|
377
|
+
if (this.isFirstChange && this.control) {
|
|
378
|
+
this.control.markAsPristine();
|
|
379
|
+
}
|
|
380
|
+
if (this.isFirstChange && this._value) {
|
|
381
|
+
this.isFirstChange = false;
|
|
382
|
+
}
|
|
383
|
+
this.datepickerComponent.selectedDate = this._value;
|
|
384
|
+
}
|
|
385
|
+
updatePlaceholder() {
|
|
386
|
+
if (!this.initialPlaceholder) {
|
|
387
|
+
this.adapter.setPlaceholder(this.elementRef, this.dateFormat);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
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 });
|
|
392
|
+
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: [
|
|
393
|
+
SKY_DATEPICKER_VALUE_ACCESSOR,
|
|
394
|
+
SKY_DATEPICKER_VALIDATOR,
|
|
395
|
+
SkyDatepickerAdapterService,
|
|
396
|
+
], ngImport: i0 });
|
|
397
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyDatepickerInputDirective, decorators: [{
|
|
398
|
+
type: Directive,
|
|
399
|
+
args: [{
|
|
400
|
+
selector: '[skyDatepickerInput]',
|
|
401
|
+
providers: [
|
|
402
|
+
SKY_DATEPICKER_VALUE_ACCESSOR,
|
|
403
|
+
SKY_DATEPICKER_VALIDATOR,
|
|
404
|
+
SkyDatepickerAdapterService,
|
|
405
|
+
],
|
|
406
|
+
}]
|
|
407
|
+
}], 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: [{
|
|
408
|
+
type: Optional
|
|
409
|
+
}] }]; }, propDecorators: { dateFormat: [{
|
|
410
|
+
type: Input
|
|
411
|
+
}], disabled: [{
|
|
412
|
+
type: Input
|
|
413
|
+
}], maxDate: [{
|
|
414
|
+
type: Input
|
|
415
|
+
}], minDate: [{
|
|
416
|
+
type: Input
|
|
417
|
+
}], skyDatepickerInput: [{
|
|
418
|
+
type: Input
|
|
419
|
+
}], skyDatepickerNoValidate: [{
|
|
420
|
+
type: Input
|
|
421
|
+
}], startingDay: [{
|
|
422
|
+
type: Input
|
|
423
|
+
}], strict: [{
|
|
424
|
+
type: Input
|
|
425
|
+
}], onInputChange: [{
|
|
426
|
+
type: HostListener,
|
|
427
|
+
args: ['change', ['$event']]
|
|
428
|
+
}], onInputBlur: [{
|
|
429
|
+
type: HostListener,
|
|
430
|
+
args: ['blur']
|
|
431
|
+
}], onInputKeyup: [{
|
|
432
|
+
type: HostListener,
|
|
433
|
+
args: ['keyup']
|
|
434
|
+
}] } });
|
|
435
|
+
//# sourceMappingURL=datepicker-input.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,UAAU,EACV,YAAY,EACZ,KAAK,EAGL,QAAQ,EACR,SAAS,GACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAGL,aAAa,EACb,iBAAiB,GAGlB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,MAAM,MAAM,QAAQ,CAAC;;;;;;AAE5B,sDAAsD;AACtD,MAAM,6BAA6B,GAAG;IACpC,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,2BAA2B,CAAC;IAC1D,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,2BAA2B,CAAC;IAC1D,KAAK,EAAE,IAAI;CACZ,CAAC;AACF,gBAAgB;AAUhB,MAAM,OAAO,2BAA2B;IAuMtC,YACU,OAAoC,EACpC,cAAiC,EACjC,aAAyC,EACzC,UAAsB,EACtB,cAAoC,EACpC,QAAmB,EACnB,gBAAw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;QAED,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,EAAE;YACrC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;SAC5B;QAED,IAAI,CAAC,mBAAmB,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;IACtD,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;SAC/D;IACH,CAAC;;yHApeU,2BAA2B;6GAA3B,2BAA2B,+YAN3B;QACT,6BAA6B;QAC7B,wBAAwB;QACxB,2BAA2B;KAC5B;4FAEU,2BAA2B;kBARvC,SAAS;mBAAC;oBACT,QAAQ,EAAE,sBAAsB;oBAChC,SAAS,EAAE;wBACT,6BAA6B;wBAC7B,wBAAwB;wBACxB,2BAA2B;qBAC5B;iBACF;;0BAgNI,QAAQ;4CAhMA,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;gBAgJC,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 forwardRef,\n HostListener,\n Input,\n OnDestroy,\n OnInit,\n Optional,\n Renderer2,\n} from '@angular/core';\n\nimport {\n AbstractControl,\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n Validator,\n ValidationErrors,\n} from '@angular/forms';\n\nimport { SkyAppLocaleProvider, SkyLibResourcesService } from '@skyux/i18n';\n\nimport { Subject } from 'rxjs';\n\nimport { distinctUntilChanged, takeUntil } from 'rxjs/operators';\n\nimport { SkyDateFormatter } from './date-formatter';\n\nimport { SkyDatepickerAdapterService } from './datepicker-adapter.service';\n\nimport { SkyDatepickerConfigService } from './datepicker-config.service';\n\nimport { SkyDatepickerComponent } from './datepicker.component';\n\nimport moment from 'moment';\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 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 this.notifyUpdatedValue();\n } else if (dateValue !== this._value || !areDatesEqual) {\n this._value = dateValue || value;\n this.notifyUpdatedValue();\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 private control: AbstractControl;\n private dateFormatter = new SkyDateFormatter();\n private isFirstChange = true;\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.isFirstChange = false;\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.value = value;\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.isFirstChange = false;\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 private onChange = (_: any) => {};\n /*istanbul ignore next */\n private onTouched = () => {};\n private onValidatorChange = () => {};\n\n private notifyUpdatedValue(): void {\n this.onChange(this._value);\n\n // Do not mark the field as \"dirty\"\n // if the field has been initialized with a value.\n if (this.isFirstChange && this.control) {\n this.control.markAsPristine();\n }\n\n if (this.isFirstChange && this._value) {\n this.isFirstChange = false;\n }\n\n this.datepickerComponent.selectedDate = this._value;\n }\n\n private updatePlaceholder(): void {\n if (!this.initialPlaceholder) {\n this.adapter.setPlaceholder(this.elementRef, this.dateFormat);\n }\n }\n}\n"]}
|