@imihai/angular-datetime-picker 22.0.0 → 22.0.6
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/assets/style/picker.min.css +1 -0
- package/fesm2022/imihai-angular-datetime-picker.mjs +5843 -0
- package/fesm2022/imihai-angular-datetime-picker.mjs.map +1 -0
- package/imihai-angular-datetime-picker-22.0.6.tgz +0 -0
- package/package.json +34 -77
- package/types/imihai-angular-datetime-picker.d.ts +2193 -0
- package/.browserslistrc +0 -9
- package/.editorconfig +0 -13
- package/.eslintrc.js +0 -208
- package/.github/workflows/ci_test.yml +0 -35
- package/.prettierrc +0 -2
- package/.travis.yml +0 -16
- package/angular.json +0 -221
- package/e2e/protractor.conf.js +0 -28
- package/e2e/src/app.e2e-spec.ts +0 -14
- package/e2e/src/app.po.ts +0 -11
- package/e2e/tsconfig.e2e.json +0 -13
- package/projects/picker/karma.conf.js +0 -62
- package/projects/picker/ng-package.json +0 -7
- package/projects/picker/package.json +0 -23
- package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +0 -313
- package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +0 -18
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +0 -307
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +0 -11
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +0 -31
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +0 -356
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +0 -14
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +0 -26
- package/projects/picker/src/lib/date-time/calendar-body.component.html +0 -38
- package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +0 -120
- package/projects/picker/src/lib/date-time/calendar-body.component.ts +0 -190
- package/projects/picker/src/lib/date-time/calendar-month-view.component.html +0 -47
- package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +0 -16
- package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +0 -394
- package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +0 -705
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +0 -44
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +0 -343
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +0 -465
- package/projects/picker/src/lib/date-time/calendar-year-view.component.html +0 -16
- package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +0 -381
- package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +0 -549
- package/projects/picker/src/lib/date-time/calendar.component.html +0 -169
- package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar.component.spec.ts +0 -592
- package/projects/picker/src/lib/date-time/calendar.component.ts +0 -496
- package/projects/picker/src/lib/date-time/date-time-inline.component.html +0 -1
- package/projects/picker/src/lib/date-time/date-time-inline.component.scss +0 -4
- package/projects/picker/src/lib/date-time/date-time-inline.component.ts +0 -365
- package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +0 -4
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +0 -126
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +0 -631
- package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +0 -851
- package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +0 -76
- package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +0 -88
- package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +0 -2648
- package/projects/picker/src/lib/date-time/date-time-picker.component.ts +0 -731
- package/projects/picker/src/lib/date-time/date-time.class.ts +0 -256
- package/projects/picker/src/lib/date-time/date-time.module.ts +0 -61
- package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +0 -28
- package/projects/picker/src/lib/date-time/options-provider.ts +0 -44
- package/projects/picker/src/lib/date-time/timer-box.component.html +0 -79
- package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer-box.component.ts +0 -175
- package/projects/picker/src/lib/date-time/timer.component.html +0 -58
- package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer.component.spec.ts +0 -399
- package/projects/picker/src/lib/date-time/timer.component.ts +0 -371
- package/projects/picker/src/lib/dialog/dialog-config.class.ts +0 -220
- package/projects/picker/src/lib/dialog/dialog-container.component.html +0 -1
- package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
- package/projects/picker/src/lib/dialog/dialog-container.component.ts +0 -231
- package/projects/picker/src/lib/dialog/dialog-ref.class.ts +0 -178
- package/projects/picker/src/lib/dialog/dialog.module.ts +0 -25
- package/projects/picker/src/lib/dialog/dialog.service.ts +0 -353
- package/projects/picker/src/lib/utils/array.utils.ts +0 -12
- package/projects/picker/src/lib/utils/constants.ts +0 -59
- package/projects/picker/src/lib/utils/date.utils.ts +0 -97
- package/projects/picker/src/lib/utils/index.ts +0 -5
- package/projects/picker/src/lib/utils/object.utils.ts +0 -29
- package/projects/picker/src/public_api.ts +0 -56
- package/projects/picker/src/sass/picker.scss +0 -743
- package/projects/picker/src/test-helpers.ts +0 -125
- package/projects/picker/src/test.ts +0 -52
- package/projects/picker/tsconfig.lib.json +0 -19
- package/projects/picker/tsconfig.lib.prod.json +0 -7
- package/projects/picker/tsconfig.spec.json +0 -17
- package/projects/picker/tslint.json +0 -8
- package/src/app/app.component.html +0 -77
- package/src/app/app.component.scss +0 -32
- package/src/app/app.component.spec.ts +0 -16
- package/src/app/app.component.ts +0 -35
- package/src/assets/.gitkeep +0 -0
- package/src/environments/environment.prod.ts +0 -3
- package/src/environments/environment.ts +0 -16
- package/src/favicon.ico +0 -0
- package/src/index.html +0 -14
- package/src/karma.conf.js +0 -31
- package/src/main.ts +0 -16
- package/src/polyfills.ts +0 -53
- package/src/styles.scss +0 -7
- package/src/test.ts +0 -50
- package/src/tsconfig.app.json +0 -16
- package/src/tsconfig.spec.json +0 -18
- package/src/tslint.json +0 -17
- package/tsconfig.base.json +0 -31
- package/tsconfig.json +0 -30
- package/tslint.json +0 -130
|
@@ -1,631 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* date-time-picker-container.component
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AfterContentInit,
|
|
7
|
-
AfterViewInit,
|
|
8
|
-
AnimationCallbackEvent,
|
|
9
|
-
ChangeDetectionStrategy,
|
|
10
|
-
ChangeDetectorRef,
|
|
11
|
-
Component,
|
|
12
|
-
ElementRef,
|
|
13
|
-
EventEmitter,
|
|
14
|
-
OnInit,
|
|
15
|
-
Optional,
|
|
16
|
-
ViewChild,
|
|
17
|
-
} from '@angular/core';
|
|
18
|
-
import { OwlDateTimeIntl } from './date-time-picker-intl.service';
|
|
19
|
-
import { OwlCalendarComponent } from './calendar.component';
|
|
20
|
-
import { IDateTimePickerAnimationEvent } from './date-time-picker-animation-event';
|
|
21
|
-
import { OwlTimerComponent } from './timer.component';
|
|
22
|
-
import { DateTimeAdapter } from './adapter/date-time-adapter.class';
|
|
23
|
-
import { OwlDateTime, PickerType } from './date-time.class';
|
|
24
|
-
import { Observable, Subject } from 'rxjs';
|
|
25
|
-
import {
|
|
26
|
-
DOWN_ARROW,
|
|
27
|
-
LEFT_ARROW,
|
|
28
|
-
RIGHT_ARROW,
|
|
29
|
-
SPACE,
|
|
30
|
-
UP_ARROW,
|
|
31
|
-
} from '@angular/cdk/keycodes';
|
|
32
|
-
|
|
33
|
-
@Component({
|
|
34
|
-
exportAs: 'owlDateTimeContainer',
|
|
35
|
-
selector: 'owl-date-time-container',
|
|
36
|
-
templateUrl: './date-time-picker-container.component.html',
|
|
37
|
-
styleUrls: ['./date-time-picker-container.component.scss'],
|
|
38
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
39
|
-
preserveWhitespaces: false,
|
|
40
|
-
standalone: false,
|
|
41
|
-
host: {
|
|
42
|
-
'(animate.enter)': 'onAnimateEnter($event)',
|
|
43
|
-
'(animate.leave)': 'onAnimateLeave($event)',
|
|
44
|
-
'[class.owl-dt-container]': 'owlDTContainerClass',
|
|
45
|
-
'[class.owl-dt-popup-container]': 'owlDTPopupContainerClass',
|
|
46
|
-
'[class.owl-dt-dialog-container]': 'owlDTDialogContainerClass',
|
|
47
|
-
'[class.owl-dt-inline-container]': 'owlDTInlineContainerClass',
|
|
48
|
-
'[class.owl-dt-container-disabled]': 'owlDTContainerDisabledClass',
|
|
49
|
-
'[attr.id]': 'owlDTContainerId',
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
export class OwlDateTimeContainerComponent<T>
|
|
53
|
-
implements OnInit, AfterContentInit, AfterViewInit
|
|
54
|
-
{
|
|
55
|
-
@ViewChild(OwlCalendarComponent)
|
|
56
|
-
calendar: OwlCalendarComponent<T>;
|
|
57
|
-
@ViewChild(OwlTimerComponent)
|
|
58
|
-
timer: OwlTimerComponent<T>;
|
|
59
|
-
|
|
60
|
-
public picker: OwlDateTime<T>;
|
|
61
|
-
public activeSelectedIndex = 0; // The current active SelectedIndex in range select mode (0: 'from', 1: 'to')
|
|
62
|
-
|
|
63
|
-
/** Emits when an animation state changes. */
|
|
64
|
-
public animationStateChanged = new EventEmitter<IDateTimePickerAnimationEvent>();
|
|
65
|
-
|
|
66
|
-
// retain start and end time
|
|
67
|
-
private retainStartTime: T;
|
|
68
|
-
private retainEndTime: T;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Stream emits when try to hide picker
|
|
72
|
-
* */
|
|
73
|
-
private hidePicker$ = new Subject<any>();
|
|
74
|
-
|
|
75
|
-
get hidePickerStream(): Observable<any> {
|
|
76
|
-
return this.hidePicker$.asObservable();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Stream emits when try to confirm the selected value
|
|
81
|
-
* */
|
|
82
|
-
private confirmSelected$ = new Subject<any>();
|
|
83
|
-
|
|
84
|
-
get confirmSelectedStream(): Observable<any> {
|
|
85
|
-
return this.confirmSelected$.asObservable();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private beforePickerOpened$ = new Subject<any>();
|
|
89
|
-
|
|
90
|
-
get beforePickerOpenedStream(): Observable<any> {
|
|
91
|
-
return this.beforePickerOpened$.asObservable();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private pickerOpened$ = new Subject<any>();
|
|
95
|
-
|
|
96
|
-
get pickerOpenedStream(): Observable<any> {
|
|
97
|
-
return this.pickerOpened$.asObservable();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The current picker moment. This determines which time period is shown and which date is
|
|
102
|
-
* highlighted when using keyboard navigation.
|
|
103
|
-
*/
|
|
104
|
-
private _clamPickerMoment: T;
|
|
105
|
-
|
|
106
|
-
get pickerMoment() {
|
|
107
|
-
return this._clamPickerMoment;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
set pickerMoment(value: T) {
|
|
111
|
-
if (value) {
|
|
112
|
-
this._clamPickerMoment = this.dateTimeAdapter.clampDate(
|
|
113
|
-
value,
|
|
114
|
-
this.picker.minDateTime,
|
|
115
|
-
this.picker.maxDateTime,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
this.cdRef.markForCheck();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
get pickerType(): PickerType {
|
|
122
|
-
return this.picker.pickerType;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get cancelLabel(): string {
|
|
126
|
-
return this.pickerIntl.cancelBtnLabel;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
get setLabel(): string {
|
|
130
|
-
return this.pickerIntl.setBtnLabel;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* The range 'from' label
|
|
135
|
-
* */
|
|
136
|
-
get fromLabel(): string {
|
|
137
|
-
return this.pickerIntl.rangeFromLabel;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The range 'to' label
|
|
142
|
-
* */
|
|
143
|
-
get toLabel(): string {
|
|
144
|
-
return this.pickerIntl.rangeToLabel;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* The range 'from' formatted value
|
|
149
|
-
* */
|
|
150
|
-
get fromFormattedValue(): string {
|
|
151
|
-
const value = this.picker.selecteds[0];
|
|
152
|
-
return value
|
|
153
|
-
? this.dateTimeAdapter.format(value, this.picker.formatString)
|
|
154
|
-
: '';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* The range 'to' formatted value
|
|
159
|
-
* */
|
|
160
|
-
get toFormattedValue(): string {
|
|
161
|
-
const value = this.picker.selecteds[1];
|
|
162
|
-
return value
|
|
163
|
-
? this.dateTimeAdapter.format(value, this.picker.formatString)
|
|
164
|
-
: '';
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Cases in which the control buttons show in the picker
|
|
169
|
-
* 1) picker mode is 'dialog'
|
|
170
|
-
* 2) picker type is NOT 'calendar' and the picker mode is NOT 'inline'
|
|
171
|
-
* */
|
|
172
|
-
get showControlButtons(): boolean {
|
|
173
|
-
return (
|
|
174
|
-
this.picker.pickerMode === 'dialog' ||
|
|
175
|
-
(this.picker.pickerType !== 'calendar' &&
|
|
176
|
-
this.picker.pickerMode !== 'inline')
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
get containerElm(): HTMLElement {
|
|
181
|
-
return this.elmRef.nativeElement;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
get owlDTContainerClass(): boolean {
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
get owlDTPopupContainerClass(): boolean {
|
|
189
|
-
return this.picker.pickerMode === 'popup';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
get owlDTDialogContainerClass(): boolean {
|
|
193
|
-
return this.picker.pickerMode === 'dialog';
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
get owlDTInlineContainerClass(): boolean {
|
|
197
|
-
return this.picker.pickerMode === 'inline';
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
get owlDTContainerDisabledClass(): boolean {
|
|
201
|
-
return this.picker.disabled;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
get owlDTContainerId(): string {
|
|
205
|
-
return this.picker.id;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
get owlDTContainerAnimation(): any {
|
|
209
|
-
return this.picker.pickerMode === 'inline' ? '' : 'enter';
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
constructor(
|
|
213
|
-
private cdRef: ChangeDetectorRef,
|
|
214
|
-
private elmRef: ElementRef,
|
|
215
|
-
private pickerIntl: OwlDateTimeIntl,
|
|
216
|
-
@Optional() private dateTimeAdapter: DateTimeAdapter<T>,
|
|
217
|
-
) {}
|
|
218
|
-
|
|
219
|
-
public ngOnInit() {
|
|
220
|
-
if (this.picker.selectMode === 'range') {
|
|
221
|
-
if (this.picker.selecteds[0]) {
|
|
222
|
-
this.retainStartTime = this.dateTimeAdapter.clone(
|
|
223
|
-
this.picker.selecteds[0],
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
if (this.picker.selecteds[1]) {
|
|
227
|
-
this.retainEndTime = this.dateTimeAdapter.clone(
|
|
228
|
-
this.picker.selecteds[1],
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public ngAfterContentInit(): void {
|
|
235
|
-
this.initPicker();
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public ngAfterViewInit(): void {
|
|
239
|
-
this.focusPicker();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
public handleContainerAnimationStart(animationName: 'enter' | 'leave'): void {
|
|
243
|
-
if (animationName === 'enter') {
|
|
244
|
-
this.beforePickerOpened$.next(null);
|
|
245
|
-
}
|
|
246
|
-
this.animationStateChanged.emit({
|
|
247
|
-
phaseName: 'start',
|
|
248
|
-
toState: animationName
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public handleContainerAnimationDone(animationName: 'enter' | 'leave'): void {
|
|
253
|
-
if (animationName === 'enter') {
|
|
254
|
-
this.pickerOpened$.next(null);
|
|
255
|
-
}
|
|
256
|
-
this.animationStateChanged.emit({
|
|
257
|
-
phaseName: 'done',
|
|
258
|
-
toState: animationName
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
public dateSelected(date: T): void {
|
|
263
|
-
let result;
|
|
264
|
-
|
|
265
|
-
if (this.picker.isInSingleMode) {
|
|
266
|
-
result = this.dateSelectedInSingleMode(date);
|
|
267
|
-
if (result) {
|
|
268
|
-
this.pickerMoment = result;
|
|
269
|
-
this.picker.select(result);
|
|
270
|
-
} else {
|
|
271
|
-
// we close the picker when result is null and pickerType is calendar.
|
|
272
|
-
if (this.pickerType === 'calendar') {
|
|
273
|
-
this.hidePicker$.next(null);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (this.picker.isInRangeMode) {
|
|
280
|
-
result = this.dateSelectedInRangeMode(date);
|
|
281
|
-
if (result) {
|
|
282
|
-
this.pickerMoment = result[this.activeSelectedIndex];
|
|
283
|
-
this.picker.select(result);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
public timeSelected(time: T): void {
|
|
289
|
-
this.pickerMoment = this.dateTimeAdapter.clone(time);
|
|
290
|
-
|
|
291
|
-
if (!this.picker.dateTimeChecker(this.pickerMoment)) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (this.picker.isInSingleMode) {
|
|
296
|
-
this.picker.select(this.pickerMoment);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (this.picker.isInRangeMode) {
|
|
301
|
-
const selecteds = [...this.picker.selecteds];
|
|
302
|
-
|
|
303
|
-
// check if the 'from' is after 'to' or 'to'is before 'from'
|
|
304
|
-
// In this case, we set both the 'from' and 'to' the same value
|
|
305
|
-
if (
|
|
306
|
-
(this.activeSelectedIndex === 0 &&
|
|
307
|
-
selecteds[1] &&
|
|
308
|
-
this.dateTimeAdapter.compare(
|
|
309
|
-
this.pickerMoment,
|
|
310
|
-
selecteds[1],
|
|
311
|
-
) === 1) ||
|
|
312
|
-
(this.activeSelectedIndex === 1 &&
|
|
313
|
-
selecteds[0] &&
|
|
314
|
-
this.dateTimeAdapter.compare(
|
|
315
|
-
this.pickerMoment,
|
|
316
|
-
selecteds[0],
|
|
317
|
-
) === -1)
|
|
318
|
-
) {
|
|
319
|
-
selecteds[0] = this.pickerMoment;
|
|
320
|
-
selecteds[1] = this.pickerMoment;
|
|
321
|
-
} else {
|
|
322
|
-
selecteds[this.activeSelectedIndex] = this.pickerMoment;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (selecteds[0]) {
|
|
326
|
-
this.retainStartTime = this.dateTimeAdapter.clone(selecteds[0]);
|
|
327
|
-
}
|
|
328
|
-
if (selecteds[1]) {
|
|
329
|
-
this.retainEndTime = this.dateTimeAdapter.clone(selecteds[1]);
|
|
330
|
-
}
|
|
331
|
-
this.picker.select(selecteds);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Handle click on cancel button
|
|
337
|
-
*/
|
|
338
|
-
public onCancelClicked(event: any): void {
|
|
339
|
-
this.hidePicker$.next(null);
|
|
340
|
-
event.preventDefault();
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Handle click on set button
|
|
346
|
-
*/
|
|
347
|
-
public onSetClicked(event: any): void {
|
|
348
|
-
if (!this.picker.dateTimeChecker(this.pickerMoment)) {
|
|
349
|
-
this.hidePicker$.next(null);
|
|
350
|
-
event.preventDefault();
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
this.confirmSelected$.next(event);
|
|
355
|
-
event.preventDefault();
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Handle click on inform radio group
|
|
361
|
-
*/
|
|
362
|
-
public handleClickOnInfoGroup(event: any, index: number): void {
|
|
363
|
-
this.setActiveSelectedIndex(index);
|
|
364
|
-
event.preventDefault();
|
|
365
|
-
event.stopPropagation();
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Handle click on inform radio group
|
|
370
|
-
*/
|
|
371
|
-
public handleKeydownOnInfoGroup(
|
|
372
|
-
event: any,
|
|
373
|
-
next: any,
|
|
374
|
-
index: number,
|
|
375
|
-
): void {
|
|
376
|
-
switch (event.keyCode) {
|
|
377
|
-
case DOWN_ARROW:
|
|
378
|
-
case RIGHT_ARROW:
|
|
379
|
-
case UP_ARROW:
|
|
380
|
-
case LEFT_ARROW:
|
|
381
|
-
next.focus();
|
|
382
|
-
this.setActiveSelectedIndex(index === 0 ? 1 : 0);
|
|
383
|
-
event.preventDefault();
|
|
384
|
-
event.stopPropagation();
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
case SPACE:
|
|
388
|
-
this.setActiveSelectedIndex(index);
|
|
389
|
-
event.preventDefault();
|
|
390
|
-
event.stopPropagation();
|
|
391
|
-
break;
|
|
392
|
-
|
|
393
|
-
default:
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
protected onAnimateEnter(event: AnimationCallbackEvent): void {
|
|
399
|
-
this.handleContainerAnimationStart('enter');
|
|
400
|
-
const duration = this.parseCssVariableDuration(event.target, '--container-enter-animation-duration');
|
|
401
|
-
if (duration === 0) {
|
|
402
|
-
this.handleContainerAnimationDone('enter');
|
|
403
|
-
event.animationComplete();
|
|
404
|
-
} else {
|
|
405
|
-
const animation = event.target.animate([
|
|
406
|
-
{ opacity: 0, transform: 'scaleY(0)' },
|
|
407
|
-
{ opacity: 1, transform: 'scaleY(1)' }
|
|
408
|
-
], {
|
|
409
|
-
duration: duration ?? 400,
|
|
410
|
-
easing: 'cubic-bezier(0.25, 0.8, 0.25, 1)',
|
|
411
|
-
fill: 'forwards'
|
|
412
|
-
});
|
|
413
|
-
animation.finished.then(() => {
|
|
414
|
-
this.handleContainerAnimationDone('enter');
|
|
415
|
-
event.animationComplete();
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
protected onAnimateLeave(event: AnimationCallbackEvent): void {
|
|
421
|
-
this.handleContainerAnimationStart('leave');
|
|
422
|
-
const duration = this.parseCssVariableDuration(event.target, '--container-leave-animation-duration');
|
|
423
|
-
if (duration === 0) {
|
|
424
|
-
this.handleContainerAnimationDone('leave');
|
|
425
|
-
event.animationComplete();
|
|
426
|
-
} else {
|
|
427
|
-
event.target.animate([
|
|
428
|
-
{ opacity: 1 },
|
|
429
|
-
{ opacity: 0 }
|
|
430
|
-
], {
|
|
431
|
-
duration: duration ?? 100,
|
|
432
|
-
easing: 'linear',
|
|
433
|
-
fill: 'forwards'
|
|
434
|
-
}).finished.then(() => {
|
|
435
|
-
this.handleContainerAnimationDone('leave');
|
|
436
|
-
event.animationComplete();
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Set the value of activeSelectedIndex
|
|
443
|
-
*/
|
|
444
|
-
private setActiveSelectedIndex(index: number): void {
|
|
445
|
-
if (
|
|
446
|
-
this.picker.selectMode === 'range' &&
|
|
447
|
-
this.activeSelectedIndex !== index
|
|
448
|
-
) {
|
|
449
|
-
this.activeSelectedIndex = index;
|
|
450
|
-
|
|
451
|
-
const selected = this.picker.selecteds[this.activeSelectedIndex];
|
|
452
|
-
if (this.picker.selecteds && selected) {
|
|
453
|
-
this.pickerMoment = this.dateTimeAdapter.clone(selected);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
private initPicker(): void {
|
|
460
|
-
this.pickerMoment = this.picker.startAt || this.dateTimeAdapter.now();
|
|
461
|
-
this.activeSelectedIndex = this.picker.selectMode === 'rangeTo' ? 1 : 0;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Select calendar date in single mode,
|
|
466
|
-
* it returns null when date is not selected.
|
|
467
|
-
*/
|
|
468
|
-
private dateSelectedInSingleMode(date: T): T | null {
|
|
469
|
-
if (this.dateTimeAdapter.isSameDay(date, this.picker.selected)) {
|
|
470
|
-
return null;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
return this.updateAndCheckCalendarDate(date);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Select dates in range Mode
|
|
478
|
-
*/
|
|
479
|
-
private dateSelectedInRangeMode(date: T): T[] | null {
|
|
480
|
-
let from = this.picker.selecteds[0];
|
|
481
|
-
let to = this.picker.selecteds[1];
|
|
482
|
-
|
|
483
|
-
const result = this.updateAndCheckCalendarDate(date);
|
|
484
|
-
|
|
485
|
-
if (!result) {
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// if the given calendar day is after or equal to 'from',
|
|
490
|
-
// set ths given date as 'to'
|
|
491
|
-
// otherwise, set it as 'from' and set 'to' to null
|
|
492
|
-
if (this.picker.selectMode === 'range') {
|
|
493
|
-
if (
|
|
494
|
-
this.picker.selecteds &&
|
|
495
|
-
this.picker.selecteds.length &&
|
|
496
|
-
!to &&
|
|
497
|
-
from &&
|
|
498
|
-
this.dateTimeAdapter.differenceInCalendarDays(result, from) >= 0
|
|
499
|
-
) {
|
|
500
|
-
if (this.picker.endAt && !this.retainEndTime) {
|
|
501
|
-
to = this.dateTimeAdapter.createDate(
|
|
502
|
-
this.dateTimeAdapter.getYear(result),
|
|
503
|
-
this.dateTimeAdapter.getMonth(result),
|
|
504
|
-
this.dateTimeAdapter.getDate(result),
|
|
505
|
-
this.dateTimeAdapter.getHours(this.picker.endAt),
|
|
506
|
-
this.dateTimeAdapter.getMinutes(this.picker.endAt),
|
|
507
|
-
this.dateTimeAdapter.getSeconds(this.picker.endAt),
|
|
508
|
-
);
|
|
509
|
-
} else if (this.retainEndTime) {
|
|
510
|
-
to = this.dateTimeAdapter.createDate(
|
|
511
|
-
this.dateTimeAdapter.getYear(result),
|
|
512
|
-
this.dateTimeAdapter.getMonth(result),
|
|
513
|
-
this.dateTimeAdapter.getDate(result),
|
|
514
|
-
this.dateTimeAdapter.getHours(this.retainEndTime),
|
|
515
|
-
this.dateTimeAdapter.getMinutes(this.retainEndTime),
|
|
516
|
-
this.dateTimeAdapter.getSeconds(this.retainEndTime),
|
|
517
|
-
);
|
|
518
|
-
} else {
|
|
519
|
-
to = result;
|
|
520
|
-
}
|
|
521
|
-
this.activeSelectedIndex = 1;
|
|
522
|
-
} else {
|
|
523
|
-
if (this.picker.startAt && !this.retainStartTime) {
|
|
524
|
-
from = this.dateTimeAdapter.createDate(
|
|
525
|
-
this.dateTimeAdapter.getYear(result),
|
|
526
|
-
this.dateTimeAdapter.getMonth(result),
|
|
527
|
-
this.dateTimeAdapter.getDate(result),
|
|
528
|
-
this.dateTimeAdapter.getHours(this.picker.startAt),
|
|
529
|
-
this.dateTimeAdapter.getMinutes(this.picker.startAt),
|
|
530
|
-
this.dateTimeAdapter.getSeconds(this.picker.startAt),
|
|
531
|
-
);
|
|
532
|
-
} else if (this.retainStartTime) {
|
|
533
|
-
from = this.dateTimeAdapter.createDate(
|
|
534
|
-
this.dateTimeAdapter.getYear(result),
|
|
535
|
-
this.dateTimeAdapter.getMonth(result),
|
|
536
|
-
this.dateTimeAdapter.getDate(result),
|
|
537
|
-
this.dateTimeAdapter.getHours(this.retainStartTime),
|
|
538
|
-
this.dateTimeAdapter.getMinutes(this.retainStartTime),
|
|
539
|
-
this.dateTimeAdapter.getSeconds(this.retainStartTime),
|
|
540
|
-
);
|
|
541
|
-
} else {
|
|
542
|
-
from = result;
|
|
543
|
-
}
|
|
544
|
-
to = null;
|
|
545
|
-
this.activeSelectedIndex = 0;
|
|
546
|
-
}
|
|
547
|
-
} else if (this.picker.selectMode === 'rangeFrom') {
|
|
548
|
-
from = result;
|
|
549
|
-
|
|
550
|
-
// if the from value is after the to value, set the to value as null
|
|
551
|
-
if (to && this.dateTimeAdapter.compare(from, to) > 0) {
|
|
552
|
-
to = null;
|
|
553
|
-
}
|
|
554
|
-
} else if (this.picker.selectMode === 'rangeTo') {
|
|
555
|
-
to = result;
|
|
556
|
-
|
|
557
|
-
// if the from value is after the to value, set the from value as null
|
|
558
|
-
if (from && this.dateTimeAdapter.compare(from, to) > 0) {
|
|
559
|
-
from = null;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
return [from, to];
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Update the given calendar date's time and check if it is valid
|
|
568
|
-
* Because the calendar date has 00:00:00 as default time, if the picker type is 'both',
|
|
569
|
-
* we need to update the given calendar date's time before selecting it.
|
|
570
|
-
* if it is valid, return the updated dateTime
|
|
571
|
-
* if it is not valid, return null
|
|
572
|
-
*/
|
|
573
|
-
private updateAndCheckCalendarDate(date: T): T {
|
|
574
|
-
let result;
|
|
575
|
-
|
|
576
|
-
// if the picker is 'both', update the calendar date's time value
|
|
577
|
-
if (this.picker.pickerType === 'both') {
|
|
578
|
-
result = this.dateTimeAdapter.createDate(
|
|
579
|
-
this.dateTimeAdapter.getYear(date),
|
|
580
|
-
this.dateTimeAdapter.getMonth(date),
|
|
581
|
-
this.dateTimeAdapter.getDate(date),
|
|
582
|
-
this.dateTimeAdapter.getHours(this.pickerMoment),
|
|
583
|
-
this.dateTimeAdapter.getMinutes(this.pickerMoment),
|
|
584
|
-
this.dateTimeAdapter.getSeconds(this.pickerMoment),
|
|
585
|
-
);
|
|
586
|
-
result = this.dateTimeAdapter.clampDate(
|
|
587
|
-
result,
|
|
588
|
-
this.picker.minDateTime,
|
|
589
|
-
this.picker.maxDateTime,
|
|
590
|
-
);
|
|
591
|
-
} else {
|
|
592
|
-
result = this.dateTimeAdapter.clone(date);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// check the updated dateTime
|
|
596
|
-
return this.picker.dateTimeChecker(result) ? result : null;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Focus to the picker
|
|
601
|
-
* */
|
|
602
|
-
private focusPicker(): void {
|
|
603
|
-
if (this.picker.pickerMode === 'inline') {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
if (this.calendar) {
|
|
608
|
-
this.calendar.focusActiveCell();
|
|
609
|
-
} else if (this.timer) {
|
|
610
|
-
this.timer.focus();
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
private parseCssVariableDuration(el: Element, cssVariableName: string) {
|
|
615
|
-
const durationStr = getComputedStyle(el).getPropertyValue(cssVariableName).trim();
|
|
616
|
-
|
|
617
|
-
// Convert to ms
|
|
618
|
-
let duration: number | undefined = undefined;
|
|
619
|
-
if (durationStr.endsWith('ms')) {
|
|
620
|
-
duration = parseFloat(durationStr);
|
|
621
|
-
} else if (durationStr.endsWith('s')) {
|
|
622
|
-
duration = parseFloat(durationStr) * 1000;
|
|
623
|
-
} else if (durationStr) {
|
|
624
|
-
duration = parseFloat(durationStr);
|
|
625
|
-
if (isNaN(duration)) {
|
|
626
|
-
duration = undefined;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return duration;
|
|
630
|
-
}
|
|
631
|
-
}
|