ng-primitives 0.68.0 → 0.69.1
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/date-picker/date-picker/date-picker-state.d.ts +4 -1
- package/date-picker/date-picker/date-picker.d.ts +34 -0
- package/date-picker/date-picker-cell/date-picker-cell.d.ts +1 -1
- package/date-picker/date-picker-date-button/date-picker-date-button.d.ts +13 -6
- package/date-picker/date-picker-grid/date-picker-grid.d.ts +1 -1
- package/date-picker/date-picker-label/date-picker-label.d.ts +1 -1
- package/date-picker/date-picker-next-month/date-picker-next-month.d.ts +0 -4
- package/date-picker/date-picker-previous-month/date-picker-previous-month.d.ts +0 -4
- package/date-picker/date-range-picker/date-range-picker-state.d.ts +19 -0
- package/date-picker/date-range-picker/date-range-picker.d.ts +132 -0
- package/date-picker/index.d.ts +2 -1
- package/fesm2022/ng-primitives-date-picker.mjs +358 -51
- package/fesm2022/ng-primitives-date-picker.mjs.map +1 -1
- package/fesm2022/ng-primitives-tooltip.mjs +1 -1
- package/fesm2022/ng-primitives-tooltip.mjs.map +1 -1
- package/package.json +29 -29
- package/schematics/ng-generate/templates/date-picker/date-picker.__fileSuffix@dasherize__.ts.template +5 -3
- package/tooltip/tooltip-trigger/tooltip-trigger-state.d.ts +1 -3
- package/tooltip/tooltip-trigger/tooltip-trigger.d.ts +1 -1
- package/date-picker/date-picker/date-picker-token.d.ts +0 -11
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, inject, TemplateRef, ViewContainerRef, Injector, Directive, contentChild, computed, ElementRef, HostListener, input, booleanAttribute, output, signal, afterNextRender } from '@angular/core';
|
|
3
|
+
import { createStateToken, createStateProvider, createStateInjector, createState } from 'ng-primitives/state';
|
|
3
4
|
import { FocusMonitor } from '@angular/cdk/a11y';
|
|
4
5
|
import { injectDateAdapter } from 'ng-primitives/date-time';
|
|
5
6
|
import { setupButton } from 'ng-primitives/internal';
|
|
6
|
-
import { createStateToken, createStateProvider, createStateInjector, createState } from 'ng-primitives/state';
|
|
7
7
|
import { uniqueId, onChange } from 'ng-primitives/utils';
|
|
8
8
|
|
|
9
9
|
const NgpDatePickerRowRenderToken = new InjectionToken('NgpDatePickerRowRenderToken');
|
|
@@ -107,18 +107,39 @@ function injectDatePickerDateButton() {
|
|
|
107
107
|
return inject(NgpDatePickerDateButtonToken);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const NgpDatePickerToken = new InjectionToken('NgpDatePickerToken');
|
|
111
110
|
/**
|
|
112
|
-
*
|
|
111
|
+
* The state token for the DateRangePicker primitive.
|
|
113
112
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
const NgpDateRangePickerStateToken = createStateToken('DateRangePicker');
|
|
114
|
+
/**
|
|
115
|
+
* Provides the DateRangePicker state.
|
|
116
|
+
*/
|
|
117
|
+
const provideDateRangePickerState = createStateProvider(NgpDateRangePickerStateToken);
|
|
118
|
+
/**
|
|
119
|
+
* Injects the DateRangePicker state.
|
|
120
|
+
*/
|
|
121
|
+
const injectDateRangePickerState = createStateInjector(NgpDateRangePickerStateToken);
|
|
117
122
|
/**
|
|
118
|
-
*
|
|
123
|
+
* The DateRangePicker state registration function.
|
|
119
124
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
const dateRangePickerState = createState(NgpDateRangePickerStateToken);
|
|
126
|
+
|
|
127
|
+
const NgpDatePickerStateToken = createStateToken('DatePicker');
|
|
128
|
+
const provideDatePickerState = createStateProvider(NgpDatePickerStateToken);
|
|
129
|
+
const injectDatePickerState = createStateInjector(NgpDatePickerStateToken);
|
|
130
|
+
const datePickerState = createState(NgpDatePickerStateToken);
|
|
131
|
+
function injectDateControllerState() {
|
|
132
|
+
const datePickerState = injectDatePickerState({ optional: true });
|
|
133
|
+
const dateRangePickerState = injectDateRangePickerState({ optional: true });
|
|
134
|
+
if (datePickerState()) {
|
|
135
|
+
return datePickerState;
|
|
136
|
+
}
|
|
137
|
+
else if (dateRangePickerState()) {
|
|
138
|
+
return dateRangePickerState;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw new Error('No date picker or date range picker state found');
|
|
142
|
+
}
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
/**
|
|
@@ -129,7 +150,7 @@ class NgpDatePickerCell {
|
|
|
129
150
|
/**
|
|
130
151
|
* Access the date picker.
|
|
131
152
|
*/
|
|
132
|
-
this.
|
|
153
|
+
this.state = injectDateControllerState();
|
|
133
154
|
/**
|
|
134
155
|
* Access the child date picker date button.
|
|
135
156
|
*/
|
|
@@ -139,7 +160,7 @@ class NgpDatePickerCell {
|
|
|
139
160
|
/**
|
|
140
161
|
* Access the label id.
|
|
141
162
|
*/
|
|
142
|
-
this.labelId = computed(() => this.
|
|
163
|
+
this.labelId = computed(() => this.state().label()?.id());
|
|
143
164
|
}
|
|
144
165
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerCell, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
145
166
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "19.2.11", type: NgpDatePickerCell, isStandalone: true, selector: "[ngpDatePickerCell]", host: { attributes: { "role": "gridcell" }, properties: { "attr.data-selected": "datePickerButton()?.selected() ? \"\" : null", "attr.aria-selected": "datePickerButton()?.selected()", "attr.aria-disabled": "datePickerButton()?.disabled()", "attr.data-disabled": "datePickerButton()?.disabled() ? \"\" : null", "attr.aria-labelledby": "labelId()" } }, queries: [{ propertyName: "datePickerButton", first: true, predicate: NgpDatePickerDateButtonToken, descendants: true, isSignal: true }], exportAs: ["ngpDatePickerCell"], ngImport: i0 }); }
|
|
@@ -160,11 +181,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
|
|
|
160
181
|
}]
|
|
161
182
|
}] });
|
|
162
183
|
|
|
163
|
-
const NgpDatePickerStateToken = createStateToken('DatePicker');
|
|
164
|
-
const provideDatePickerState = createStateProvider(NgpDatePickerStateToken);
|
|
165
|
-
const injectDatePickerState = createStateInjector(NgpDatePickerStateToken);
|
|
166
|
-
const datePickerState = createState(NgpDatePickerStateToken);
|
|
167
|
-
|
|
168
184
|
/**
|
|
169
185
|
* A button that represents a date in the date picker grid.
|
|
170
186
|
*/
|
|
@@ -178,14 +194,10 @@ class NgpDatePickerDateButton {
|
|
|
178
194
|
* Access the focus monitor.
|
|
179
195
|
*/
|
|
180
196
|
this.focusMonitor = inject(FocusMonitor);
|
|
181
|
-
/**
|
|
182
|
-
* Access the date picker.
|
|
183
|
-
*/
|
|
184
|
-
this.datePicker = injectDatePicker();
|
|
185
197
|
/**
|
|
186
198
|
* Access the date picker state.
|
|
187
199
|
*/
|
|
188
|
-
this.state =
|
|
200
|
+
this.state = injectDateControllerState();
|
|
189
201
|
/**
|
|
190
202
|
* Access the date adapter.
|
|
191
203
|
*/
|
|
@@ -200,12 +212,20 @@ class NgpDatePickerDateButton {
|
|
|
200
212
|
this.focused = computed(() => this.dateAdapter.isSameDay(this.date, this.state().focusedDate()));
|
|
201
213
|
/**
|
|
202
214
|
* Determine if this is the selected date.
|
|
203
|
-
* @internal
|
|
204
215
|
*/
|
|
205
|
-
this.selected = computed(() =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
this.selected = computed(() => this.state().isSelected(this.date));
|
|
217
|
+
/**
|
|
218
|
+
* Determine if this is the start date of the range.
|
|
219
|
+
*/
|
|
220
|
+
this.start = computed(() => this.state().isStartOfRange(this.date));
|
|
221
|
+
/**
|
|
222
|
+
* Determine if this is the end date of the range.
|
|
223
|
+
*/
|
|
224
|
+
this.end = computed(() => this.state().isEndOfRange(this.date));
|
|
225
|
+
/**
|
|
226
|
+
* Determine if this is between the start and end dates of the range.
|
|
227
|
+
*/
|
|
228
|
+
this.betweenRange = computed(() => this.state().isBetweenRange(this.date));
|
|
209
229
|
/**
|
|
210
230
|
* Determine if this date is outside the current month.
|
|
211
231
|
*/
|
|
@@ -236,11 +256,11 @@ class NgpDatePickerDateButton {
|
|
|
236
256
|
* Determine if the element is a button.
|
|
237
257
|
*/
|
|
238
258
|
this.isButton = this.elementRef.nativeElement.tagName === 'BUTTON';
|
|
239
|
-
this.
|
|
259
|
+
this.state().registerButton(this);
|
|
240
260
|
setupButton({ disabled: this.disabled });
|
|
241
261
|
}
|
|
242
262
|
ngOnDestroy() {
|
|
243
|
-
this.
|
|
263
|
+
this.state().unregisterButton(this);
|
|
244
264
|
}
|
|
245
265
|
/**
|
|
246
266
|
* When the button is clicked, select the date.
|
|
@@ -256,9 +276,8 @@ class NgpDatePickerDateButton {
|
|
|
256
276
|
event.preventDefault();
|
|
257
277
|
event.stopPropagation();
|
|
258
278
|
}
|
|
259
|
-
this.state().
|
|
260
|
-
this.state().
|
|
261
|
-
this.datePicker.setFocusedDate(this.date, 'mouse', 'forward');
|
|
279
|
+
this.state().select(this.date);
|
|
280
|
+
this.state().setFocusedDate(this.date, 'mouse', 'forward');
|
|
262
281
|
}
|
|
263
282
|
/**
|
|
264
283
|
* Focus if this is the current focused date.
|
|
@@ -368,7 +387,7 @@ class NgpDatePickerDateButton {
|
|
|
368
387
|
}
|
|
369
388
|
}
|
|
370
389
|
focusDate(date, direction) {
|
|
371
|
-
this.
|
|
390
|
+
this.state().setFocusedDate(date, 'keyboard', direction);
|
|
372
391
|
}
|
|
373
392
|
/**
|
|
374
393
|
* Get the direction of the element.
|
|
@@ -377,7 +396,7 @@ class NgpDatePickerDateButton {
|
|
|
377
396
|
return getComputedStyle(this.elementRef.nativeElement).direction === 'rtl' ? 'rtl' : 'ltr';
|
|
378
397
|
}
|
|
379
398
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerDateButton, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
380
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.11", type: NgpDatePickerDateButton, isStandalone: true, selector: "[ngpDatePickerDateButton]", host: { listeners: { "click": "select()", "keydown.enter": "select($event)", "keydown.space": "select($event)", "keydown.arrowLeft": "focusPrevious($event)", "keydown.arrowRight": "focusNext($event)", "keydown.arrowUp": "focusAbove($event)", "keydown.arrowDown": "focusBelow($event)", "keydown.home": "focusFirst($event)", "keydown.end": "focusLast($event)", "keydown.pageUp": "focusPreviousMonth($event)", "keydown.pageDown": "focusNextMonth($event)" }, properties: { "attr.role": "!isButton ? \"button\" : null", "attr.tabindex": "focused() ? 0 : -1", "attr.data-selected": "selected() ? \"\" : null", "attr.aria-disabled": "disabled()", "attr.data-outside-month": "outside() ? \"\" : null", "attr.data-today": "today() ? \"\" : null" } }, providers: [{ provide: NgpDatePickerDateButtonToken, useExisting: NgpDatePickerDateButton }], exportAs: ["ngpDatePickerDateButton"], ngImport: i0 }); }
|
|
399
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.11", type: NgpDatePickerDateButton, isStandalone: true, selector: "[ngpDatePickerDateButton]", host: { listeners: { "click": "select()", "keydown.enter": "select($event)", "keydown.space": "select($event)", "keydown.arrowLeft": "focusPrevious($event)", "keydown.arrowRight": "focusNext($event)", "keydown.arrowUp": "focusAbove($event)", "keydown.arrowDown": "focusBelow($event)", "keydown.home": "focusFirst($event)", "keydown.end": "focusLast($event)", "keydown.pageUp": "focusPreviousMonth($event)", "keydown.pageDown": "focusNextMonth($event)" }, properties: { "attr.role": "!isButton ? \"button\" : null", "attr.tabindex": "focused() ? 0 : -1", "attr.data-selected": "selected() ? \"\" : null", "attr.aria-disabled": "disabled()", "attr.data-outside-month": "outside() ? \"\" : null", "attr.data-today": "today() ? \"\" : null", "attr.data-range-start": "start() ? \"\" : null", "attr.data-range-end": "end() ? \"\" : null", "attr.data-range-between": "betweenRange() ? \"\" : null" } }, providers: [{ provide: NgpDatePickerDateButtonToken, useExisting: NgpDatePickerDateButton }], exportAs: ["ngpDatePickerDateButton"], ngImport: i0 }); }
|
|
381
400
|
}
|
|
382
401
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerDateButton, decorators: [{
|
|
383
402
|
type: Directive,
|
|
@@ -392,6 +411,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
|
|
|
392
411
|
'[attr.aria-disabled]': 'disabled()',
|
|
393
412
|
'[attr.data-outside-month]': 'outside() ? "" : null',
|
|
394
413
|
'[attr.data-today]': 'today() ? "" : null',
|
|
414
|
+
'[attr.data-range-start]': 'start() ? "" : null',
|
|
415
|
+
'[attr.data-range-end]': 'end() ? "" : null',
|
|
416
|
+
'[attr.data-range-between]': 'betweenRange() ? "" : null',
|
|
395
417
|
},
|
|
396
418
|
}]
|
|
397
419
|
}], ctorParameters: () => [], propDecorators: { select: [{
|
|
@@ -437,7 +459,7 @@ class NgpDatePickerGrid {
|
|
|
437
459
|
/**
|
|
438
460
|
* Access the date picker state.
|
|
439
461
|
*/
|
|
440
|
-
this.state =
|
|
462
|
+
this.state = injectDateControllerState();
|
|
441
463
|
/**
|
|
442
464
|
* Determine the id for the label.
|
|
443
465
|
*/
|
|
@@ -475,7 +497,7 @@ class NgpDatePickerLabel {
|
|
|
475
497
|
/**
|
|
476
498
|
* Access the date picker.
|
|
477
499
|
*/
|
|
478
|
-
this.state =
|
|
500
|
+
this.state = injectDateControllerState();
|
|
479
501
|
/**
|
|
480
502
|
* Define a unique id for the label.
|
|
481
503
|
*/
|
|
@@ -517,14 +539,10 @@ class NgpDatePickerNextMonth {
|
|
|
517
539
|
* Access the date adapter.
|
|
518
540
|
*/
|
|
519
541
|
this.dateAdapter = injectDateAdapter();
|
|
520
|
-
/**
|
|
521
|
-
* Access the date picker.
|
|
522
|
-
*/
|
|
523
|
-
this.datePicker = injectDatePicker();
|
|
524
542
|
/**
|
|
525
543
|
* Access the date picker state.
|
|
526
544
|
*/
|
|
527
|
-
this.state =
|
|
545
|
+
this.state = injectDateControllerState();
|
|
528
546
|
/**
|
|
529
547
|
* Determine if this is a button element
|
|
530
548
|
*/
|
|
@@ -569,7 +587,7 @@ class NgpDatePickerNextMonth {
|
|
|
569
587
|
second: 0,
|
|
570
588
|
millisecond: 0,
|
|
571
589
|
});
|
|
572
|
-
this.
|
|
590
|
+
this.state().setFocusedDate(date, 'mouse', 'forward');
|
|
573
591
|
}
|
|
574
592
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerNextMonth, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
575
593
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.11", type: NgpDatePickerNextMonth, isStandalone: true, selector: "[ngpDatePickerNextMonth]", host: { listeners: { "click": "navigateToNextMonth()" }, properties: { "attr.aria-disabled": "disabled()", "attr.type": "isButton ? \"button\" : null" } }, exportAs: ["ngpDatePickerNextMonth"], ngImport: i0 }); }
|
|
@@ -602,14 +620,10 @@ class NgpDatePickerPreviousMonth {
|
|
|
602
620
|
* Access the date adapter.
|
|
603
621
|
*/
|
|
604
622
|
this.dateAdapter = injectDateAdapter();
|
|
605
|
-
/**
|
|
606
|
-
* Access the date picker.
|
|
607
|
-
*/
|
|
608
|
-
this.datePicker = injectDatePicker();
|
|
609
623
|
/**
|
|
610
624
|
* Access the date picker state.
|
|
611
625
|
*/
|
|
612
|
-
this.state =
|
|
626
|
+
this.state = injectDateControllerState();
|
|
613
627
|
/**
|
|
614
628
|
* Determine if this is a button element
|
|
615
629
|
*/
|
|
@@ -655,7 +669,7 @@ class NgpDatePickerPreviousMonth {
|
|
|
655
669
|
second: 0,
|
|
656
670
|
millisecond: 0,
|
|
657
671
|
});
|
|
658
|
-
this.
|
|
672
|
+
this.state().setFocusedDate(date, 'mouse', 'backward');
|
|
659
673
|
}
|
|
660
674
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerPreviousMonth, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
661
675
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.11", type: NgpDatePickerPreviousMonth, isStandalone: true, selector: "[ngpDatePickerPreviousMonth]", host: { listeners: { "click": "navigateToPreviouMonth()" }, properties: { "attr.aria-disabled": "disabled()", "attr.type": "isButton ? \"button\" : null" } }, exportAs: ["ngpDatePickerPreviousMonth"], ngImport: i0 }); }
|
|
@@ -687,7 +701,7 @@ class NgpDatePickerRowRender {
|
|
|
687
701
|
/**
|
|
688
702
|
* Access the date picker.
|
|
689
703
|
*/
|
|
690
|
-
this.state =
|
|
704
|
+
this.state = injectDateControllerState();
|
|
691
705
|
/**
|
|
692
706
|
* Access the template ref for the cell.
|
|
693
707
|
*/
|
|
@@ -910,15 +924,308 @@ class NgpDatePicker {
|
|
|
910
924
|
unregisterButton(button) {
|
|
911
925
|
this.buttons.update(buttons => buttons.filter(b => b !== button));
|
|
912
926
|
}
|
|
927
|
+
/**
|
|
928
|
+
* Select a date.
|
|
929
|
+
* @param date The date to select.
|
|
930
|
+
* @internal
|
|
931
|
+
*/
|
|
932
|
+
select(date) {
|
|
933
|
+
this.state.date.set(date);
|
|
934
|
+
this.dateChange.emit(date);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Determine if a date is selected.
|
|
938
|
+
* @param date The date to check.
|
|
939
|
+
* @returns True if the date is selected, false otherwise.
|
|
940
|
+
* @internal
|
|
941
|
+
*/
|
|
942
|
+
isSelected(date) {
|
|
943
|
+
const selected = this.state.date();
|
|
944
|
+
if (!selected) {
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
return this.dateAdapter.isSameDay(date, selected);
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Determine if a date is the start of a range. In a date picker, this is always false.
|
|
951
|
+
* @param date The date to check.
|
|
952
|
+
* @returns Always false.
|
|
953
|
+
* @internal
|
|
954
|
+
*/
|
|
955
|
+
isStartOfRange(_) {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Determine if a date is the end of a range. In a date picker, this is always false.
|
|
960
|
+
* @param date The date to check.
|
|
961
|
+
* @returns Always false.
|
|
962
|
+
* @internal
|
|
963
|
+
*/
|
|
964
|
+
isEndOfRange(_) {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Determine if a date is between the start and end dates. In a date picker, this is always false.
|
|
969
|
+
* @param date The date to check.
|
|
970
|
+
* @returns True if the date is between the start and end dates, false otherwise.
|
|
971
|
+
* @internal
|
|
972
|
+
*/
|
|
973
|
+
isBetweenRange(_) {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
913
976
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePicker, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
914
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "19.2.11", type: NgpDatePicker, isStandalone: true, selector: "[ngpDatePicker]", inputs: { min: { classPropertyName: "min", publicName: "ngpDatePickerMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "ngpDatePickerMax", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpDatePickerDisabled", isSignal: true, isRequired: false, transformFunction: null }, dateDisabled: { classPropertyName: "dateDisabled", publicName: "ngpDatePickerDateDisabled", isSignal: true, isRequired: false, transformFunction: null }, date: { classPropertyName: "date", publicName: "ngpDatePickerDate", isSignal: true, isRequired: false, transformFunction: null }, focusedDate: { classPropertyName: "focusedDate", publicName: "ngpDatePickerFocusedDate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dateChange: "ngpDatePickerDateChange", focusedDateChange: "ngpDatePickerFocusedDateChange" }, host: { properties: { "attr.data-disabled": "state.disabled() ? \"\" : null" } }, providers: [
|
|
977
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "19.2.11", type: NgpDatePicker, isStandalone: true, selector: "[ngpDatePicker]", inputs: { min: { classPropertyName: "min", publicName: "ngpDatePickerMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "ngpDatePickerMax", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpDatePickerDisabled", isSignal: true, isRequired: false, transformFunction: null }, dateDisabled: { classPropertyName: "dateDisabled", publicName: "ngpDatePickerDateDisabled", isSignal: true, isRequired: false, transformFunction: null }, date: { classPropertyName: "date", publicName: "ngpDatePickerDate", isSignal: true, isRequired: false, transformFunction: null }, focusedDate: { classPropertyName: "focusedDate", publicName: "ngpDatePickerFocusedDate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dateChange: "ngpDatePickerDateChange", focusedDateChange: "ngpDatePickerFocusedDateChange" }, host: { properties: { "attr.data-disabled": "state.disabled() ? \"\" : null" } }, providers: [provideDatePickerState()], queries: [{ propertyName: "label", first: true, predicate: NgpDatePickerLabelToken, descendants: true, isSignal: true }], exportAs: ["ngpDatePicker"], ngImport: i0 }); }
|
|
915
978
|
}
|
|
916
979
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePicker, decorators: [{
|
|
917
980
|
type: Directive,
|
|
918
981
|
args: [{
|
|
919
982
|
selector: '[ngpDatePicker]',
|
|
920
983
|
exportAs: 'ngpDatePicker',
|
|
921
|
-
providers: [
|
|
984
|
+
providers: [provideDatePickerState()],
|
|
985
|
+
host: {
|
|
986
|
+
'[attr.data-disabled]': 'state.disabled() ? "" : null',
|
|
987
|
+
},
|
|
988
|
+
}]
|
|
989
|
+
}] });
|
|
990
|
+
|
|
991
|
+
class NgpDateRangePicker {
|
|
992
|
+
constructor() {
|
|
993
|
+
this.dateAdapter = injectDateAdapter();
|
|
994
|
+
/**
|
|
995
|
+
* Access the injector.
|
|
996
|
+
*/
|
|
997
|
+
this.injector = inject(Injector);
|
|
998
|
+
/**
|
|
999
|
+
* The minimum date that can be selected.
|
|
1000
|
+
*/
|
|
1001
|
+
this.min = input(undefined, {
|
|
1002
|
+
alias: 'ngpDateRangePickerMin',
|
|
1003
|
+
});
|
|
1004
|
+
/**
|
|
1005
|
+
* The maximum date that can be selected.
|
|
1006
|
+
*/
|
|
1007
|
+
this.max = input(undefined, {
|
|
1008
|
+
alias: 'ngpDateRangePickerMax',
|
|
1009
|
+
});
|
|
1010
|
+
/**
|
|
1011
|
+
* Determine if the date picker is disabled.
|
|
1012
|
+
*/
|
|
1013
|
+
this.disabled = input(false, {
|
|
1014
|
+
alias: 'ngpDateRangePickerDisabled',
|
|
1015
|
+
transform: booleanAttribute,
|
|
1016
|
+
});
|
|
1017
|
+
/**
|
|
1018
|
+
* A function that is called to determine if a specific date should be disabled.
|
|
1019
|
+
*/
|
|
1020
|
+
this.dateDisabled = input(() => false, {
|
|
1021
|
+
alias: 'ngpDateRangePickerDateDisabled',
|
|
1022
|
+
});
|
|
1023
|
+
/**
|
|
1024
|
+
* The selected start date
|
|
1025
|
+
*/
|
|
1026
|
+
this.startDate = input(undefined, {
|
|
1027
|
+
alias: 'ngpDateRangePickerStartDate',
|
|
1028
|
+
});
|
|
1029
|
+
/**
|
|
1030
|
+
* Emit when the date changes.
|
|
1031
|
+
*/
|
|
1032
|
+
this.startDateChange = output({
|
|
1033
|
+
alias: 'ngpDateRangePickerStartDateChange',
|
|
1034
|
+
});
|
|
1035
|
+
/**
|
|
1036
|
+
* The selected end date
|
|
1037
|
+
*/
|
|
1038
|
+
this.endDate = input(undefined, {
|
|
1039
|
+
alias: 'ngpDateRangePickerEndDate',
|
|
1040
|
+
});
|
|
1041
|
+
/**
|
|
1042
|
+
* Emit when the end date changes.
|
|
1043
|
+
*/
|
|
1044
|
+
this.endDateChange = output({
|
|
1045
|
+
alias: 'ngpDateRangePickerEndDateChange',
|
|
1046
|
+
});
|
|
1047
|
+
/**
|
|
1048
|
+
* The focused value.
|
|
1049
|
+
*/
|
|
1050
|
+
this.focusedDate = input(this.dateAdapter.now(), {
|
|
1051
|
+
alias: 'ngpDateRangePickerFocusedDate',
|
|
1052
|
+
});
|
|
1053
|
+
/**
|
|
1054
|
+
* Emit when the focused date changes.
|
|
1055
|
+
*/
|
|
1056
|
+
this.focusedDateChange = output({
|
|
1057
|
+
alias: 'ngpDateRangePickerFocusedDateChange',
|
|
1058
|
+
});
|
|
1059
|
+
/**
|
|
1060
|
+
* Detect the label element.
|
|
1061
|
+
* @internal
|
|
1062
|
+
*/
|
|
1063
|
+
this.label = contentChild(NgpDatePickerLabelToken, { descendants: true });
|
|
1064
|
+
/**
|
|
1065
|
+
* Access all the date picker buttons
|
|
1066
|
+
*/
|
|
1067
|
+
this.buttons = signal([]);
|
|
1068
|
+
/**
|
|
1069
|
+
* The date range picker state.
|
|
1070
|
+
*/
|
|
1071
|
+
this.state = dateRangePickerState(this);
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Set the focused date.
|
|
1075
|
+
* @param date The date to focus.
|
|
1076
|
+
* @internal
|
|
1077
|
+
*/
|
|
1078
|
+
setFocusedDate(date, origin = 'mouse', direction) {
|
|
1079
|
+
if (this.state.disabled()) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
const min = this.state.min();
|
|
1083
|
+
const max = this.state.max();
|
|
1084
|
+
if (min && this.dateAdapter.isBefore(date, min)) {
|
|
1085
|
+
date = min;
|
|
1086
|
+
}
|
|
1087
|
+
if (max && this.dateAdapter.isAfter(date, max)) {
|
|
1088
|
+
date = max;
|
|
1089
|
+
}
|
|
1090
|
+
// if the date is disabled, find the next available date in the specified direction.
|
|
1091
|
+
if (this.state.dateDisabled()(date)) {
|
|
1092
|
+
let nextDate = this.dateAdapter.add(date, { days: direction === 'forward' ? 1 : -1 });
|
|
1093
|
+
while (this.state.dateDisabled()(nextDate) ||
|
|
1094
|
+
(min && this.dateAdapter.isBefore(nextDate, min)) ||
|
|
1095
|
+
(max && this.dateAdapter.isAfter(nextDate, max))) {
|
|
1096
|
+
nextDate = this.dateAdapter.add(nextDate, { days: direction === 'forward' ? 1 : -1 });
|
|
1097
|
+
}
|
|
1098
|
+
date = nextDate;
|
|
1099
|
+
}
|
|
1100
|
+
this.state.focusedDate.set(date);
|
|
1101
|
+
this.focusedDateChange.emit(date);
|
|
1102
|
+
if (origin === 'keyboard') {
|
|
1103
|
+
afterNextRender({
|
|
1104
|
+
write: () => this.buttons().forEach(button => button.focus()),
|
|
1105
|
+
}, {
|
|
1106
|
+
injector: this.injector,
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Register a date button.
|
|
1112
|
+
* @param button The date button to register.
|
|
1113
|
+
* @internal
|
|
1114
|
+
*/
|
|
1115
|
+
registerButton(button) {
|
|
1116
|
+
this.buttons.update(buttons => [...buttons, button]);
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Unregister a date button.
|
|
1120
|
+
* @param button The date button to unregister.
|
|
1121
|
+
* @internal
|
|
1122
|
+
*/
|
|
1123
|
+
unregisterButton(button) {
|
|
1124
|
+
this.buttons.update(buttons => buttons.filter(b => b !== button));
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Select a date.
|
|
1128
|
+
* @param date The date to select.
|
|
1129
|
+
* @internal
|
|
1130
|
+
*/
|
|
1131
|
+
/**
|
|
1132
|
+
* Handles the selection of a date within the date range picker.
|
|
1133
|
+
*
|
|
1134
|
+
* Selection logic:
|
|
1135
|
+
* - If neither a start date nor an end date is selected:
|
|
1136
|
+
* - Sets the selected date as the start date.
|
|
1137
|
+
* - If a start date is selected but no end date:
|
|
1138
|
+
* - If the selected date is after the start date, sets it as the end date.
|
|
1139
|
+
* - If the selected date is before or equal to the start date, resets the start date to the selected date.
|
|
1140
|
+
* - If both start and end dates are already selected:
|
|
1141
|
+
* - Resets the selection, setting the selected date as the new start date and clearing the end date.
|
|
1142
|
+
*
|
|
1143
|
+
* @param date The date to select.
|
|
1144
|
+
*/
|
|
1145
|
+
select(date) {
|
|
1146
|
+
const start = this.state.startDate();
|
|
1147
|
+
const end = this.state.endDate();
|
|
1148
|
+
if (!start && !end) {
|
|
1149
|
+
this.state.startDate.set(date);
|
|
1150
|
+
this.startDateChange.emit(date);
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
if (start && !end) {
|
|
1154
|
+
if (this.dateAdapter.isAfter(date, start)) {
|
|
1155
|
+
this.state.endDate.set(date);
|
|
1156
|
+
this.endDateChange.emit(date);
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
this.state.startDate.set(date);
|
|
1160
|
+
this.startDateChange.emit(date);
|
|
1161
|
+
}
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
// If both start and end are selected, reset selection
|
|
1165
|
+
this.state.startDate.set(date);
|
|
1166
|
+
this.startDateChange.emit(date);
|
|
1167
|
+
this.state.endDate.set(undefined);
|
|
1168
|
+
this.endDateChange.emit(undefined);
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Determine if a date is selected. A date is selected if it is either the start date or the end date.
|
|
1172
|
+
* @param date The date to check.
|
|
1173
|
+
* @returns True if the date is selected, false otherwise.
|
|
1174
|
+
* @internal
|
|
1175
|
+
*/
|
|
1176
|
+
isSelected(date) {
|
|
1177
|
+
const start = this.state.startDate();
|
|
1178
|
+
const end = this.state.endDate();
|
|
1179
|
+
if (!start && !end) {
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
const isStartSelected = start ? this.dateAdapter.isSameDay(date, start) : false;
|
|
1183
|
+
const isEndSelected = end ? this.dateAdapter.isSameDay(date, end) : false;
|
|
1184
|
+
return isStartSelected || isEndSelected;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Determine if a date is the start of a range.
|
|
1188
|
+
* @param date The date to check.
|
|
1189
|
+
* @returns Always false.
|
|
1190
|
+
* @internal
|
|
1191
|
+
*/
|
|
1192
|
+
isStartOfRange(date) {
|
|
1193
|
+
const start = this.state.startDate();
|
|
1194
|
+
return start ? this.dateAdapter.isSameDay(date, start) : false;
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Determine if a date is the end of a range.
|
|
1198
|
+
* @param date The date to check.
|
|
1199
|
+
* @returns Always false.
|
|
1200
|
+
* @internal
|
|
1201
|
+
*/
|
|
1202
|
+
isEndOfRange(date) {
|
|
1203
|
+
const end = this.state.endDate();
|
|
1204
|
+
return end ? this.dateAdapter.isSameDay(date, end) : false;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Determine if a date is between the start and end dates.
|
|
1208
|
+
* @param date The date to check.
|
|
1209
|
+
* @returns True if the date is between the start and end dates, false otherwise.
|
|
1210
|
+
* @internal
|
|
1211
|
+
*/
|
|
1212
|
+
isBetweenRange(date) {
|
|
1213
|
+
const start = this.state.startDate();
|
|
1214
|
+
const end = this.state.endDate();
|
|
1215
|
+
if (!start || !end) {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
return this.dateAdapter.isAfter(date, start) && this.dateAdapter.isBefore(date, end);
|
|
1219
|
+
}
|
|
1220
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDateRangePicker, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1221
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "19.2.11", type: NgpDateRangePicker, isStandalone: true, selector: "[ngpDateRangePicker]", inputs: { min: { classPropertyName: "min", publicName: "ngpDateRangePickerMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "ngpDateRangePickerMax", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpDateRangePickerDisabled", isSignal: true, isRequired: false, transformFunction: null }, dateDisabled: { classPropertyName: "dateDisabled", publicName: "ngpDateRangePickerDateDisabled", isSignal: true, isRequired: false, transformFunction: null }, startDate: { classPropertyName: "startDate", publicName: "ngpDateRangePickerStartDate", isSignal: true, isRequired: false, transformFunction: null }, endDate: { classPropertyName: "endDate", publicName: "ngpDateRangePickerEndDate", isSignal: true, isRequired: false, transformFunction: null }, focusedDate: { classPropertyName: "focusedDate", publicName: "ngpDateRangePickerFocusedDate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { startDateChange: "ngpDateRangePickerStartDateChange", endDateChange: "ngpDateRangePickerEndDateChange", focusedDateChange: "ngpDateRangePickerFocusedDateChange" }, host: { properties: { "attr.data-disabled": "state.disabled() ? \"\" : null" } }, providers: [provideDateRangePickerState()], queries: [{ propertyName: "label", first: true, predicate: NgpDatePickerLabelToken, descendants: true, isSignal: true }], exportAs: ["ngpDateRangePicker"], ngImport: i0 }); }
|
|
1222
|
+
}
|
|
1223
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDateRangePicker, decorators: [{
|
|
1224
|
+
type: Directive,
|
|
1225
|
+
args: [{
|
|
1226
|
+
selector: '[ngpDateRangePicker]',
|
|
1227
|
+
exportAs: 'ngpDateRangePicker',
|
|
1228
|
+
providers: [provideDateRangePickerState()],
|
|
922
1229
|
host: {
|
|
923
1230
|
'[attr.data-disabled]': 'state.disabled() ? "" : null',
|
|
924
1231
|
},
|
|
@@ -929,5 +1236,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
|
|
|
929
1236
|
* Generated bundle index. Do not edit.
|
|
930
1237
|
*/
|
|
931
1238
|
|
|
932
|
-
export { NgpDatePicker, NgpDatePickerCell, NgpDatePickerCellRender, NgpDatePickerCellRenderToken, NgpDatePickerDateButton, NgpDatePickerDateButtonToken, NgpDatePickerGrid, NgpDatePickerLabel, NgpDatePickerLabelToken, NgpDatePickerNextMonth, NgpDatePickerPreviousMonth, NgpDatePickerRowRender, NgpDatePickerRowRenderToken,
|
|
1239
|
+
export { NgpDatePicker, NgpDatePickerCell, NgpDatePickerCellRender, NgpDatePickerCellRenderToken, NgpDatePickerDateButton, NgpDatePickerDateButtonToken, NgpDatePickerGrid, NgpDatePickerLabel, NgpDatePickerLabelToken, NgpDatePickerNextMonth, NgpDatePickerPreviousMonth, NgpDatePickerRowRender, NgpDatePickerRowRenderToken, NgpDateRangePicker, injectDatePickerCellDate, injectDatePickerCellRender, injectDatePickerDateButton, injectDatePickerLabel, injectDatePickerRowRender, injectDatePickerState, injectDatePickerWeek, injectDateRangePickerState, provideDatePickerState, provideDateRangePickerState };
|
|
933
1240
|
//# sourceMappingURL=ng-primitives-date-picker.mjs.map
|