ng-primitives 0.67.0 → 0.69.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.
Files changed (35) hide show
  1. package/accordion/accordion-content/accordion-content.d.ts +1 -8
  2. package/date-picker/date-picker/date-picker-state.d.ts +4 -1
  3. package/date-picker/date-picker/date-picker.d.ts +34 -0
  4. package/date-picker/date-picker-cell/date-picker-cell.d.ts +1 -1
  5. package/date-picker/date-picker-date-button/date-picker-date-button.d.ts +13 -6
  6. package/date-picker/date-picker-grid/date-picker-grid.d.ts +1 -1
  7. package/date-picker/date-picker-label/date-picker-label.d.ts +1 -1
  8. package/date-picker/date-picker-next-month/date-picker-next-month.d.ts +0 -4
  9. package/date-picker/date-picker-previous-month/date-picker-previous-month.d.ts +0 -4
  10. package/date-picker/date-range-picker/date-range-picker-state.d.ts +19 -0
  11. package/date-picker/date-range-picker/date-range-picker.d.ts +132 -0
  12. package/date-picker/index.d.ts +2 -1
  13. package/fesm2022/ng-primitives-accordion.mjs +25 -20
  14. package/fesm2022/ng-primitives-accordion.mjs.map +1 -1
  15. package/fesm2022/ng-primitives-date-picker.mjs +346 -49
  16. package/fesm2022/ng-primitives-date-picker.mjs.map +1 -1
  17. package/fesm2022/ng-primitives-menu.mjs +2 -1
  18. package/fesm2022/ng-primitives-menu.mjs.map +1 -1
  19. package/fesm2022/ng-primitives-popover.mjs +2 -1
  20. package/fesm2022/ng-primitives-popover.mjs.map +1 -1
  21. package/fesm2022/ng-primitives-portal.mjs +4 -4
  22. package/fesm2022/ng-primitives-portal.mjs.map +1 -1
  23. package/fesm2022/ng-primitives-toast.mjs +19 -17
  24. package/fesm2022/ng-primitives-toast.mjs.map +1 -1
  25. package/fesm2022/ng-primitives-tooltip.mjs +3 -2
  26. package/fesm2022/ng-primitives-tooltip.mjs.map +1 -1
  27. package/package.json +5 -5
  28. package/schematics/ng-generate/templates/date-picker/date-picker.__fileSuffix@dasherize__.ts.template +5 -3
  29. package/toast/config/toast-config.d.ts +5 -1
  30. package/toast/toast/toast-manager.d.ts +1 -2
  31. package/toast/toast/toast-options.d.ts +2 -2
  32. package/toast/toast/toast.d.ts +2 -1
  33. package/tooltip/tooltip-trigger/tooltip-trigger-state.d.ts +1 -3
  34. package/tooltip/tooltip-trigger/tooltip-trigger.d.ts +1 -1
  35. 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,29 @@ function injectDatePickerDateButton() {
107
107
  return inject(NgpDatePickerDateButtonToken);
108
108
  }
109
109
 
110
- const NgpDatePickerToken = new InjectionToken('NgpDatePickerToken');
111
110
  /**
112
- * Inject the DatePicker directive instance
111
+ * The state token for the DateRangePicker primitive.
113
112
  */
114
- function injectDatePicker() {
115
- return inject(NgpDatePickerToken);
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
- * Provide the DatePicker directive instance
123
+ * The DateRangePicker state registration function.
119
124
  */
120
- function provideDatePicker(datePicker) {
121
- return { provide: NgpDatePickerToken, useExisting: datePicker };
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
+ return (injectDatePickerState({ optional: true }) ?? injectDateRangePickerState({ optional: true }));
122
133
  }
123
134
 
124
135
  /**
@@ -129,7 +140,7 @@ class NgpDatePickerCell {
129
140
  /**
130
141
  * Access the date picker.
131
142
  */
132
- this.datePicker = injectDatePicker();
143
+ this.state = injectDateControllerState();
133
144
  /**
134
145
  * Access the child date picker date button.
135
146
  */
@@ -139,7 +150,7 @@ class NgpDatePickerCell {
139
150
  /**
140
151
  * Access the label id.
141
152
  */
142
- this.labelId = computed(() => this.datePicker.label()?.id());
153
+ this.labelId = computed(() => this.state().label()?.id());
143
154
  }
144
155
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerCell, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
145
156
  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 +171,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
160
171
  }]
161
172
  }] });
162
173
 
163
- const NgpDatePickerStateToken = createStateToken('DatePicker');
164
- const provideDatePickerState = createStateProvider(NgpDatePickerStateToken);
165
- const injectDatePickerState = createStateInjector(NgpDatePickerStateToken);
166
- const datePickerState = createState(NgpDatePickerStateToken);
167
-
168
174
  /**
169
175
  * A button that represents a date in the date picker grid.
170
176
  */
@@ -178,14 +184,10 @@ class NgpDatePickerDateButton {
178
184
  * Access the focus monitor.
179
185
  */
180
186
  this.focusMonitor = inject(FocusMonitor);
181
- /**
182
- * Access the date picker.
183
- */
184
- this.datePicker = injectDatePicker();
185
187
  /**
186
188
  * Access the date picker state.
187
189
  */
188
- this.state = injectDatePickerState();
190
+ this.state = injectDateControllerState();
189
191
  /**
190
192
  * Access the date adapter.
191
193
  */
@@ -200,12 +202,20 @@ class NgpDatePickerDateButton {
200
202
  this.focused = computed(() => this.dateAdapter.isSameDay(this.date, this.state().focusedDate()));
201
203
  /**
202
204
  * Determine if this is the selected date.
203
- * @internal
204
205
  */
205
- this.selected = computed(() => {
206
- const selected = this.state().date();
207
- return selected && this.dateAdapter.isSameDay(this.date, selected);
208
- });
206
+ this.selected = computed(() => this.state().isSelected(this.date));
207
+ /**
208
+ * Determine if this is the start date of the range.
209
+ */
210
+ this.start = computed(() => this.state().isStartOfRange(this.date));
211
+ /**
212
+ * Determine if this is the end date of the range.
213
+ */
214
+ this.end = computed(() => this.state().isEndOfRange(this.date));
215
+ /**
216
+ * Determine if this is between the start and end dates of the range.
217
+ */
218
+ this.betweenRange = computed(() => this.state().isBetweenRange(this.date));
209
219
  /**
210
220
  * Determine if this date is outside the current month.
211
221
  */
@@ -236,11 +246,11 @@ class NgpDatePickerDateButton {
236
246
  * Determine if the element is a button.
237
247
  */
238
248
  this.isButton = this.elementRef.nativeElement.tagName === 'BUTTON';
239
- this.datePicker.registerButton(this);
249
+ this.state().registerButton(this);
240
250
  setupButton({ disabled: this.disabled });
241
251
  }
242
252
  ngOnDestroy() {
243
- this.datePicker.unregisterButton(this);
253
+ this.state().unregisterButton(this);
244
254
  }
245
255
  /**
246
256
  * When the button is clicked, select the date.
@@ -256,9 +266,8 @@ class NgpDatePickerDateButton {
256
266
  event.preventDefault();
257
267
  event.stopPropagation();
258
268
  }
259
- this.state().date.set(this.date);
260
- this.state().dateChange.emit(this.date);
261
- this.datePicker.setFocusedDate(this.date, 'mouse', 'forward');
269
+ this.state().select(this.date);
270
+ this.state().setFocusedDate(this.date, 'mouse', 'forward');
262
271
  }
263
272
  /**
264
273
  * Focus if this is the current focused date.
@@ -368,7 +377,7 @@ class NgpDatePickerDateButton {
368
377
  }
369
378
  }
370
379
  focusDate(date, direction) {
371
- this.datePicker.setFocusedDate(date, 'keyboard', direction);
380
+ this.state().setFocusedDate(date, 'keyboard', direction);
372
381
  }
373
382
  /**
374
383
  * Get the direction of the element.
@@ -377,7 +386,7 @@ class NgpDatePickerDateButton {
377
386
  return getComputedStyle(this.elementRef.nativeElement).direction === 'rtl' ? 'rtl' : 'ltr';
378
387
  }
379
388
  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 }); }
389
+ 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
390
  }
382
391
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerDateButton, decorators: [{
383
392
  type: Directive,
@@ -392,6 +401,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
392
401
  '[attr.aria-disabled]': 'disabled()',
393
402
  '[attr.data-outside-month]': 'outside() ? "" : null',
394
403
  '[attr.data-today]': 'today() ? "" : null',
404
+ '[attr.data-range-start]': 'start() ? "" : null',
405
+ '[attr.data-range-end]': 'end() ? "" : null',
406
+ '[attr.data-range-between]': 'betweenRange() ? "" : null',
395
407
  },
396
408
  }]
397
409
  }], ctorParameters: () => [], propDecorators: { select: [{
@@ -437,7 +449,7 @@ class NgpDatePickerGrid {
437
449
  /**
438
450
  * Access the date picker state.
439
451
  */
440
- this.state = injectDatePickerState();
452
+ this.state = injectDateControllerState();
441
453
  /**
442
454
  * Determine the id for the label.
443
455
  */
@@ -475,7 +487,7 @@ class NgpDatePickerLabel {
475
487
  /**
476
488
  * Access the date picker.
477
489
  */
478
- this.state = injectDatePickerState();
490
+ this.state = injectDateControllerState();
479
491
  /**
480
492
  * Define a unique id for the label.
481
493
  */
@@ -517,10 +529,6 @@ class NgpDatePickerNextMonth {
517
529
  * Access the date adapter.
518
530
  */
519
531
  this.dateAdapter = injectDateAdapter();
520
- /**
521
- * Access the date picker.
522
- */
523
- this.datePicker = injectDatePicker();
524
532
  /**
525
533
  * Access the date picker state.
526
534
  */
@@ -569,7 +577,7 @@ class NgpDatePickerNextMonth {
569
577
  second: 0,
570
578
  millisecond: 0,
571
579
  });
572
- this.datePicker.setFocusedDate(date, 'mouse', 'forward');
580
+ this.state().setFocusedDate(date, 'mouse', 'forward');
573
581
  }
574
582
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerNextMonth, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
575
583
  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,10 +610,6 @@ class NgpDatePickerPreviousMonth {
602
610
  * Access the date adapter.
603
611
  */
604
612
  this.dateAdapter = injectDateAdapter();
605
- /**
606
- * Access the date picker.
607
- */
608
- this.datePicker = injectDatePicker();
609
613
  /**
610
614
  * Access the date picker state.
611
615
  */
@@ -655,7 +659,7 @@ class NgpDatePickerPreviousMonth {
655
659
  second: 0,
656
660
  millisecond: 0,
657
661
  });
658
- this.datePicker.setFocusedDate(date, 'mouse', 'backward');
662
+ this.state().setFocusedDate(date, 'mouse', 'backward');
659
663
  }
660
664
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePickerPreviousMonth, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
661
665
  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 +691,7 @@ class NgpDatePickerRowRender {
687
691
  /**
688
692
  * Access the date picker.
689
693
  */
690
- this.state = injectDatePickerState();
694
+ this.state = injectDateControllerState();
691
695
  /**
692
696
  * Access the template ref for the cell.
693
697
  */
@@ -910,15 +914,308 @@ class NgpDatePicker {
910
914
  unregisterButton(button) {
911
915
  this.buttons.update(buttons => buttons.filter(b => b !== button));
912
916
  }
917
+ /**
918
+ * Select a date.
919
+ * @param date The date to select.
920
+ * @internal
921
+ */
922
+ select(date) {
923
+ this.state.date.set(date);
924
+ this.dateChange.emit(date);
925
+ }
926
+ /**
927
+ * Determine if a date is selected.
928
+ * @param date The date to check.
929
+ * @returns True if the date is selected, false otherwise.
930
+ * @internal
931
+ */
932
+ isSelected(date) {
933
+ const selected = this.state.date();
934
+ if (!selected) {
935
+ return false;
936
+ }
937
+ return this.dateAdapter.isSameDay(date, selected);
938
+ }
939
+ /**
940
+ * Determine if a date is the start of a range. In a date picker, this is always false.
941
+ * @param date The date to check.
942
+ * @returns Always false.
943
+ * @internal
944
+ */
945
+ isStartOfRange(_) {
946
+ return false;
947
+ }
948
+ /**
949
+ * Determine if a date is the end of a range. In a date picker, this is always false.
950
+ * @param date The date to check.
951
+ * @returns Always false.
952
+ * @internal
953
+ */
954
+ isEndOfRange(_) {
955
+ return false;
956
+ }
957
+ /**
958
+ * Determine if a date is between the start and end dates. In a date picker, this is always false.
959
+ * @param date The date to check.
960
+ * @returns True if the date is between the start and end dates, false otherwise.
961
+ * @internal
962
+ */
963
+ isBetweenRange(_) {
964
+ return false;
965
+ }
913
966
  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: [provideDatePicker(NgpDatePicker), provideDatePickerState()], queries: [{ propertyName: "label", first: true, predicate: NgpDatePickerLabelToken, descendants: true, isSignal: true }], exportAs: ["ngpDatePicker"], ngImport: i0 }); }
967
+ 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
968
  }
916
969
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDatePicker, decorators: [{
917
970
  type: Directive,
918
971
  args: [{
919
972
  selector: '[ngpDatePicker]',
920
973
  exportAs: 'ngpDatePicker',
921
- providers: [provideDatePicker(NgpDatePicker), provideDatePickerState()],
974
+ providers: [provideDatePickerState()],
975
+ host: {
976
+ '[attr.data-disabled]': 'state.disabled() ? "" : null',
977
+ },
978
+ }]
979
+ }] });
980
+
981
+ class NgpDateRangePicker {
982
+ constructor() {
983
+ this.dateAdapter = injectDateAdapter();
984
+ /**
985
+ * Access the injector.
986
+ */
987
+ this.injector = inject(Injector);
988
+ /**
989
+ * The minimum date that can be selected.
990
+ */
991
+ this.min = input(undefined, {
992
+ alias: 'ngpDateRangePickerMin',
993
+ });
994
+ /**
995
+ * The maximum date that can be selected.
996
+ */
997
+ this.max = input(undefined, {
998
+ alias: 'ngpDateRangePickerMax',
999
+ });
1000
+ /**
1001
+ * Determine if the date picker is disabled.
1002
+ */
1003
+ this.disabled = input(false, {
1004
+ alias: 'ngpDateRangePickerDisabled',
1005
+ transform: booleanAttribute,
1006
+ });
1007
+ /**
1008
+ * A function that is called to determine if a specific date should be disabled.
1009
+ */
1010
+ this.dateDisabled = input(() => false, {
1011
+ alias: 'ngpDateRangePickerDateDisabled',
1012
+ });
1013
+ /**
1014
+ * The selected start date
1015
+ */
1016
+ this.startDate = input(undefined, {
1017
+ alias: 'ngpDateRangePickerStartDate',
1018
+ });
1019
+ /**
1020
+ * Emit when the date changes.
1021
+ */
1022
+ this.startDateChange = output({
1023
+ alias: 'ngpDateRangePickerStartDateChange',
1024
+ });
1025
+ /**
1026
+ * The selected end date
1027
+ */
1028
+ this.endDate = input(undefined, {
1029
+ alias: 'ngpDateRangePickerEndDate',
1030
+ });
1031
+ /**
1032
+ * Emit when the end date changes.
1033
+ */
1034
+ this.endDateChange = output({
1035
+ alias: 'ngpDateRangePickerEndDateChange',
1036
+ });
1037
+ /**
1038
+ * The focused value.
1039
+ */
1040
+ this.focusedDate = input(this.dateAdapter.now(), {
1041
+ alias: 'ngpDateRangePickerFocusedDate',
1042
+ });
1043
+ /**
1044
+ * Emit when the focused date changes.
1045
+ */
1046
+ this.focusedDateChange = output({
1047
+ alias: 'ngpDateRangePickerFocusedDateChange',
1048
+ });
1049
+ /**
1050
+ * Detect the label element.
1051
+ * @internal
1052
+ */
1053
+ this.label = contentChild(NgpDatePickerLabelToken, { descendants: true });
1054
+ /**
1055
+ * Access all the date picker buttons
1056
+ */
1057
+ this.buttons = signal([]);
1058
+ /**
1059
+ * The date range picker state.
1060
+ */
1061
+ this.state = dateRangePickerState(this);
1062
+ }
1063
+ /**
1064
+ * Set the focused date.
1065
+ * @param date The date to focus.
1066
+ * @internal
1067
+ */
1068
+ setFocusedDate(date, origin = 'mouse', direction) {
1069
+ if (this.state.disabled()) {
1070
+ return;
1071
+ }
1072
+ const min = this.state.min();
1073
+ const max = this.state.max();
1074
+ if (min && this.dateAdapter.isBefore(date, min)) {
1075
+ date = min;
1076
+ }
1077
+ if (max && this.dateAdapter.isAfter(date, max)) {
1078
+ date = max;
1079
+ }
1080
+ // if the date is disabled, find the next available date in the specified direction.
1081
+ if (this.state.dateDisabled()(date)) {
1082
+ let nextDate = this.dateAdapter.add(date, { days: direction === 'forward' ? 1 : -1 });
1083
+ while (this.state.dateDisabled()(nextDate) ||
1084
+ (min && this.dateAdapter.isBefore(nextDate, min)) ||
1085
+ (max && this.dateAdapter.isAfter(nextDate, max))) {
1086
+ nextDate = this.dateAdapter.add(nextDate, { days: direction === 'forward' ? 1 : -1 });
1087
+ }
1088
+ date = nextDate;
1089
+ }
1090
+ this.state.focusedDate.set(date);
1091
+ this.focusedDateChange.emit(date);
1092
+ if (origin === 'keyboard') {
1093
+ afterNextRender({
1094
+ write: () => this.buttons().forEach(button => button.focus()),
1095
+ }, {
1096
+ injector: this.injector,
1097
+ });
1098
+ }
1099
+ }
1100
+ /**
1101
+ * Register a date button.
1102
+ * @param button The date button to register.
1103
+ * @internal
1104
+ */
1105
+ registerButton(button) {
1106
+ this.buttons.update(buttons => [...buttons, button]);
1107
+ }
1108
+ /**
1109
+ * Unregister a date button.
1110
+ * @param button The date button to unregister.
1111
+ * @internal
1112
+ */
1113
+ unregisterButton(button) {
1114
+ this.buttons.update(buttons => buttons.filter(b => b !== button));
1115
+ }
1116
+ /**
1117
+ * Select a date.
1118
+ * @param date The date to select.
1119
+ * @internal
1120
+ */
1121
+ /**
1122
+ * Handles the selection of a date within the date range picker.
1123
+ *
1124
+ * Selection logic:
1125
+ * - If neither a start date nor an end date is selected:
1126
+ * - Sets the selected date as the start date.
1127
+ * - If a start date is selected but no end date:
1128
+ * - If the selected date is after the start date, sets it as the end date.
1129
+ * - If the selected date is before or equal to the start date, resets the start date to the selected date.
1130
+ * - If both start and end dates are already selected:
1131
+ * - Resets the selection, setting the selected date as the new start date and clearing the end date.
1132
+ *
1133
+ * @param date The date to select.
1134
+ */
1135
+ select(date) {
1136
+ const start = this.state.startDate();
1137
+ const end = this.state.endDate();
1138
+ if (!start && !end) {
1139
+ this.state.startDate.set(date);
1140
+ this.startDateChange.emit(date);
1141
+ return;
1142
+ }
1143
+ if (start && !end) {
1144
+ if (this.dateAdapter.isAfter(date, start)) {
1145
+ this.state.endDate.set(date);
1146
+ this.endDateChange.emit(date);
1147
+ }
1148
+ else {
1149
+ this.state.startDate.set(date);
1150
+ this.startDateChange.emit(date);
1151
+ }
1152
+ return;
1153
+ }
1154
+ // If both start and end are selected, reset selection
1155
+ this.state.startDate.set(date);
1156
+ this.startDateChange.emit(date);
1157
+ this.state.endDate.set(undefined);
1158
+ this.endDateChange.emit(undefined);
1159
+ }
1160
+ /**
1161
+ * Determine if a date is selected. A date is selected if it is either the start date or the end date.
1162
+ * @param date The date to check.
1163
+ * @returns True if the date is selected, false otherwise.
1164
+ * @internal
1165
+ */
1166
+ isSelected(date) {
1167
+ const start = this.state.startDate();
1168
+ const end = this.state.endDate();
1169
+ if (!start && !end) {
1170
+ return false;
1171
+ }
1172
+ const isStartSelected = start ? this.dateAdapter.isSameDay(date, start) : false;
1173
+ const isEndSelected = end ? this.dateAdapter.isSameDay(date, end) : false;
1174
+ return isStartSelected || isEndSelected;
1175
+ }
1176
+ /**
1177
+ * Determine if a date is the start of a range.
1178
+ * @param date The date to check.
1179
+ * @returns Always false.
1180
+ * @internal
1181
+ */
1182
+ isStartOfRange(date) {
1183
+ const start = this.state.startDate();
1184
+ return start ? this.dateAdapter.isSameDay(date, start) : false;
1185
+ }
1186
+ /**
1187
+ * Determine if a date is the end of a range.
1188
+ * @param date The date to check.
1189
+ * @returns Always false.
1190
+ * @internal
1191
+ */
1192
+ isEndOfRange(date) {
1193
+ const end = this.state.endDate();
1194
+ return end ? this.dateAdapter.isSameDay(date, end) : false;
1195
+ }
1196
+ /**
1197
+ * Determine if a date is between the start and end dates.
1198
+ * @param date The date to check.
1199
+ * @returns True if the date is between the start and end dates, false otherwise.
1200
+ * @internal
1201
+ */
1202
+ isBetweenRange(date) {
1203
+ const start = this.state.startDate();
1204
+ const end = this.state.endDate();
1205
+ if (!start || !end) {
1206
+ return false;
1207
+ }
1208
+ return this.dateAdapter.isAfter(date, start) && this.dateAdapter.isBefore(date, end);
1209
+ }
1210
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDateRangePicker, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1211
+ 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 }); }
1212
+ }
1213
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: NgpDateRangePicker, decorators: [{
1214
+ type: Directive,
1215
+ args: [{
1216
+ selector: '[ngpDateRangePicker]',
1217
+ exportAs: 'ngpDateRangePicker',
1218
+ providers: [provideDateRangePickerState()],
922
1219
  host: {
923
1220
  '[attr.data-disabled]': 'state.disabled() ? "" : null',
924
1221
  },
@@ -929,5 +1226,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
929
1226
  * Generated bundle index. Do not edit.
930
1227
  */
931
1228
 
932
- export { NgpDatePicker, NgpDatePickerCell, NgpDatePickerCellRender, NgpDatePickerCellRenderToken, NgpDatePickerDateButton, NgpDatePickerDateButtonToken, NgpDatePickerGrid, NgpDatePickerLabel, NgpDatePickerLabelToken, NgpDatePickerNextMonth, NgpDatePickerPreviousMonth, NgpDatePickerRowRender, NgpDatePickerRowRenderToken, NgpDatePickerToken, injectDatePicker, injectDatePickerCellDate, injectDatePickerCellRender, injectDatePickerDateButton, injectDatePickerLabel, injectDatePickerRowRender, injectDatePickerState, injectDatePickerWeek, provideDatePickerState };
1229
+ 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
1230
  //# sourceMappingURL=ng-primitives-date-picker.mjs.map