/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Injectable, InjectionToken, Optional, SkipSelf } from '@angular/core'; import { DateAdapter } from '@angular/material/core'; import { DateRange } from './date-selection-model'; import * as i0 from "@angular/core"; import * as i1 from "@angular/material/core"; /** Injection token used to customize the date range selection behavior. */ export const MAT_DATE_RANGE_SELECTION_STRATEGY = new InjectionToken('MAT_DATE_RANGE_SELECTION_STRATEGY'); /** Provides the default date range selection behavior. */ export class DefaultMatCalendarRangeStrategy { constructor(_dateAdapter) { this._dateAdapter = _dateAdapter; } selectionFinished(date, currentRange) { let { start, end } = currentRange; if (start == null) { start = date; } else if (end == null && date && this._dateAdapter.compareDate(date, start) >= 0) { end = date; } else { start = date; end = null; } return new DateRange(start, end); } createPreview(activeDate, currentRange) { let start = null; let end = null; if (currentRange.start && !currentRange.end && activeDate) { start = currentRange.start; end = activeDate; } return new DateRange(start, end); } createDrag(dragOrigin, originalRange, newDate) { let start = originalRange.start; let end = originalRange.end; if (!start || !end) { // Can't drag from an incomplete range. return null; } const adapter = this._dateAdapter; const isRange = adapter.compareDate(start, end) !== 0; const diffYears = adapter.getYear(newDate) - adapter.getYear(dragOrigin); const diffMonths = adapter.getMonth(newDate) - adapter.getMonth(dragOrigin); const diffDays = adapter.getDate(newDate) - adapter.getDate(dragOrigin); if (isRange && adapter.sameDate(dragOrigin, originalRange.start)) { start = newDate; if (adapter.compareDate(newDate, end) > 0) { end = adapter.addCalendarYears(end, diffYears); end = adapter.addCalendarMonths(end, diffMonths); end = adapter.addCalendarDays(end, diffDays); } } else if (isRange && adapter.sameDate(dragOrigin, originalRange.end)) { end = newDate; if (adapter.compareDate(newDate, start) < 0) { start = adapter.addCalendarYears(start, diffYears); start = adapter.addCalendarMonths(start, diffMonths); start = adapter.addCalendarDays(start, diffDays); } } else { start = adapter.addCalendarYears(start, diffYears); start = adapter.addCalendarMonths(start, diffMonths); start = adapter.addCalendarDays(start, diffDays); end = adapter.addCalendarYears(end, diffYears); end = adapter.addCalendarMonths(end, diffMonths); end = adapter.addCalendarDays(end, diffDays); } return new DateRange(start, end); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: DefaultMatCalendarRangeStrategy, deps: [{ token: i1.DateAdapter }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: DefaultMatCalendarRangeStrategy }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: DefaultMatCalendarRangeStrategy, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i1.DateAdapter }]; } }); /** @docs-private */ export function MAT_CALENDAR_RANGE_STRATEGY_PROVIDER_FACTORY(parent, adapter) { return parent || new DefaultMatCalendarRangeStrategy(adapter); } /** @docs-private */ export const MAT_CALENDAR_RANGE_STRATEGY_PROVIDER = { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, deps: [[new Optional(), new SkipSelf(), MAT_DATE_RANGE_SELECTION_STRATEGY], DateAdapter], useFactory: MAT_CALENDAR_RANGE_STRATEGY_PROVIDER_FACTORY, }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZS1yYW5nZS1zZWxlY3Rpb24tc3RyYXRlZ3kuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvZGF0ZXBpY2tlci9kYXRlLXJhbmdlLXNlbGVjdGlvbi1zdHJhdGVneS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsVUFBVSxFQUFFLGNBQWMsRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFrQixNQUFNLGVBQWUsQ0F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