@danielmoncada/angular-datetime-picker
Version:
Angular Date Time Picker
1,160 lines (1,150 loc) • 323 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/cdk/a11y'), require('@angular/cdk/overlay'), require('rxjs'), require('@angular/cdk/portal'), require('@angular/cdk/keycodes'), require('@angular/cdk/coercion'), require('rxjs/operators'), require('@angular/animations'), require('@angular/forms'), require('@angular/cdk/platform'), require('moment')) :
typeof define === 'function' && define.amd ? define('@danielmoncada/angular-datetime-picker', ['exports', '@angular/core', '@angular/common', '@angular/cdk/a11y', '@angular/cdk/overlay', 'rxjs', '@angular/cdk/portal', '@angular/cdk/keycodes', '@angular/cdk/coercion', 'rxjs/operators', '@angular/animations', '@angular/forms', '@angular/cdk/platform', 'moment'], factory) :
(global = global || self, factory((global.danielmoncada = global.danielmoncada || {}, global.danielmoncada['angular-datetime-picker'] = {}), global.ng.core, global.ng.common, global.ng.cdk.a11y, global.ng.cdk.overlay, global.rxjs, global.ng.cdk.portal, global.ng.cdk.keycodes, global.ng.cdk.coercion, global.rxjs.operators, global.ng.animations, global.ng.forms, global.ng.cdk.platform, global._moment));
}(this, (function (exports, i0, common, a11y, overlay, rxjs, portal, keycodes, coercion, operators, animations, forms, platform, _moment) { 'use strict';
var _moment__default = 'default' in _moment ? _moment['default'] : _moment;
/**
* date-time-picker-trigger.directive
*/
var OwlDateTimeTriggerDirective = /** @class */ (function () {
function OwlDateTimeTriggerDirective(changeDetector) {
this.changeDetector = changeDetector;
this.stateChanges = rxjs.Subscription.EMPTY;
}
Object.defineProperty(OwlDateTimeTriggerDirective.prototype, "disabled", {
get: function () {
return this._disabled === undefined ? this.dtPicker.disabled : !!this._disabled;
},
set: function (value) {
this._disabled = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTimeTriggerDirective.prototype, "owlDTTriggerDisabledClass", {
get: function () {
return this.disabled;
},
enumerable: false,
configurable: true
});
OwlDateTimeTriggerDirective.prototype.ngOnInit = function () {
};
OwlDateTimeTriggerDirective.prototype.ngOnChanges = function (changes) {
if (changes.datepicker) {
this.watchStateChanges();
}
};
OwlDateTimeTriggerDirective.prototype.ngAfterContentInit = function () {
this.watchStateChanges();
};
OwlDateTimeTriggerDirective.prototype.ngOnDestroy = function () {
this.stateChanges.unsubscribe();
};
OwlDateTimeTriggerDirective.prototype.handleClickOnHost = function (event) {
if (this.dtPicker) {
this.dtPicker.open();
event.stopPropagation();
}
};
OwlDateTimeTriggerDirective.prototype.watchStateChanges = function () {
var _this = this;
this.stateChanges.unsubscribe();
var inputDisabled = this.dtPicker && this.dtPicker.dtInput ?
this.dtPicker.dtInput.disabledChange : rxjs.of();
var pickerDisabled = this.dtPicker ?
this.dtPicker.disabledChange : rxjs.of();
this.stateChanges = rxjs.merge(pickerDisabled, inputDisabled)
.subscribe(function () {
_this.changeDetector.markForCheck();
});
};
return OwlDateTimeTriggerDirective;
}());
OwlDateTimeTriggerDirective.decorators = [
{ type: i0.Directive, args: [{
selector: '[owlDateTimeTrigger]',
host: {
'(click)': 'handleClickOnHost($event)',
'[class.owl-dt-trigger-disabled]': 'owlDTTriggerDisabledClass'
}
},] }
];
OwlDateTimeTriggerDirective.ctorParameters = function () { return [
{ type: i0.ChangeDetectorRef }
]; };
OwlDateTimeTriggerDirective.propDecorators = {
dtPicker: [{ type: i0.Input, args: ['owlDateTimeTrigger',] }],
disabled: [{ type: i0.Input }]
};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, exports) {
for (var p in m)
if (p !== "default" && !exports.hasOwnProperty(p))
__createBinding(exports, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
;
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
/**
* date-time-picker-intl.service
*/
var OwlDateTimeIntl = /** @class */ (function () {
function OwlDateTimeIntl() {
/**
* Stream that emits whenever the labels here are changed. Use this to notify
* components if the labels have changed after initialization.
*/
this.changes = new rxjs.Subject();
/** A label for the up second button (used by screen readers). */
this.upSecondLabel = 'Add a second';
/** A label for the down second button (used by screen readers). */
this.downSecondLabel = 'Minus a second';
/** A label for the up minute button (used by screen readers). */
this.upMinuteLabel = 'Add a minute';
/** A label for the down minute button (used by screen readers). */
this.downMinuteLabel = 'Minus a minute';
/** A label for the up hour button (used by screen readers). */
this.upHourLabel = 'Add a hour';
/** A label for the down hour button (used by screen readers). */
this.downHourLabel = 'Minus a hour';
/** A label for the previous month button (used by screen readers). */
this.prevMonthLabel = 'Previous month';
/** A label for the next month button (used by screen readers). */
this.nextMonthLabel = 'Next month';
/** A label for the previous year button (used by screen readers). */
this.prevYearLabel = 'Previous year';
/** A label for the next year button (used by screen readers). */
this.nextYearLabel = 'Next year';
/** A label for the previous multi-year button (used by screen readers). */
this.prevMultiYearLabel = 'Previous 21 years';
/** A label for the next multi-year button (used by screen readers). */
this.nextMultiYearLabel = 'Next 21 years';
/** A label for the 'switch to month view' button (used by screen readers). */
this.switchToMonthViewLabel = 'Change to month view';
/** A label for the 'switch to year view' button (used by screen readers). */
this.switchToMultiYearViewLabel = 'Choose month and year';
/** A label for the cancel button */
this.cancelBtnLabel = 'Cancel';
/** A label for the set button */
this.setBtnLabel = 'Set';
/** A label for the range 'from' in picker info */
this.rangeFromLabel = 'From';
/** A label for the range 'to' in picker info */
this.rangeToLabel = 'To';
/** A label for the hour12 button (AM) */
this.hour12AMLabel = 'AM';
/** A label for the hour12 button (PM) */
this.hour12PMLabel = 'PM';
}
return OwlDateTimeIntl;
}());
OwlDateTimeIntl.ɵprov = i0.ɵɵdefineInjectable({ factory: function OwlDateTimeIntl_Factory() { return new OwlDateTimeIntl(); }, token: OwlDateTimeIntl, providedIn: "root" });
OwlDateTimeIntl.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
/**
* date-time-adapter.class
*/
/** InjectionToken for date time picker that can be used to override default locale code. */
var OWL_DATE_TIME_LOCALE = new i0.InjectionToken('OWL_DATE_TIME_LOCALE', {
providedIn: 'root',
factory: OWL_DATE_TIME_LOCALE_FACTORY
});
/** @docs-private */
function OWL_DATE_TIME_LOCALE_FACTORY() {
return i0.inject(i0.LOCALE_ID);
}
/** Provider for OWL_DATE_TIME_LOCALE injection token. */
var OWL_DATE_TIME_LOCALE_PROVIDER = {
provide: OWL_DATE_TIME_LOCALE,
useExisting: i0.LOCALE_ID
};
var DateTimeAdapter = /** @class */ (function () {
function DateTimeAdapter() {
/** A stream that emits when the locale changes. */
this._localeChanges = new rxjs.Subject();
/** total milliseconds in a day. */
this.millisecondsInDay = 86400000;
/** total milliseconds in a minute. */
this.milliseondsInMinute = 60000;
}
Object.defineProperty(DateTimeAdapter.prototype, "localeChanges", {
get: function () {
return this._localeChanges;
},
enumerable: false,
configurable: true
});
/**
* Compare two given dates
* 1 if the first date is after the second,
* -1 if the first date is before the second
* 0 if dates are equal.
* */
DateTimeAdapter.prototype.compare = function (first, second) {
if (!this.isValid(first) || !this.isValid(second)) {
throw Error('JSNativeDate: Cannot compare invalid dates.');
}
var dateFirst = this.clone(first);
var dateSecond = this.clone(second);
var diff = this.getTime(dateFirst) - this.getTime(dateSecond);
if (diff < 0) {
return -1;
}
else if (diff > 0) {
return 1;
}
else {
// Return 0 if diff is 0; return NaN if diff is NaN
return diff;
}
};
/**
* Check if two given dates are in the same year
* 1 if the first date's year is after the second,
* -1 if the first date's year is before the second
* 0 if two given dates are in the same year
* */
DateTimeAdapter.prototype.compareYear = function (first, second) {
if (!this.isValid(first) || !this.isValid(second)) {
throw Error('JSNativeDate: Cannot compare invalid dates.');
}
var yearLeft = this.getYear(first);
var yearRight = this.getYear(second);
var diff = yearLeft - yearRight;
if (diff < 0) {
return -1;
}
else if (diff > 0) {
return 1;
}
else {
return 0;
}
};
/**
* Attempts to deserialize a value to a valid date object. This is different from parsing in that
* deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601
* string). The default implementation does not allow any deserialization, it simply checks that
* the given value is already a valid date object or null. The `<mat-datepicker>` will call this
* method on all of it's `@Input()` properties that accept dates. It is therefore possible to
* support passing values from your backend directly to these properties by overriding this method
* to also deserialize the format used by your backend.
*/
DateTimeAdapter.prototype.deserialize = function (value) {
if (value == null ||
(this.isDateInstance(value) && this.isValid(value))) {
return value;
}
return this.invalid();
};
/**
* Sets the locale used for all dates.
*/
DateTimeAdapter.prototype.setLocale = function (locale) {
this.locale = locale;
this._localeChanges.next(locale);
};
/**
* Get the locale used for all dates.
* */
DateTimeAdapter.prototype.getLocale = function () {
return this.locale;
};
/**
* Clamp the given date between min and max dates.
*/
DateTimeAdapter.prototype.clampDate = function (date, min, max) {
if (min && this.compare(date, min) < 0) {
return min;
}
if (max && this.compare(date, max) > 0) {
return max;
}
return date;
};
return DateTimeAdapter;
}());
/**
* date-time-format.class
*/
/** InjectionToken for date time picker that can be used to override default format. */
var OWL_DATE_TIME_FORMATS = new i0.InjectionToken('OWL_DATE_TIME_FORMATS');
/**
* date-time.class
*/
var nextUniqueId = 0;
var DateView;
(function (DateView) {
DateView["MONTH"] = "month";
DateView["YEAR"] = "year";
DateView["MULTI_YEARS"] = "multi-years";
})(DateView || (DateView = {}));
var OwlDateTime = /** @class */ (function () {
function OwlDateTime(dateTimeAdapter, dateTimeFormats) {
var _this = this;
this.dateTimeAdapter = dateTimeAdapter;
this.dateTimeFormats = dateTimeFormats;
/**
* Whether to show the second's timer
*/
this._showSecondsTimer = false;
/**
* Whether the timer is in hour12 format
*/
this._hour12Timer = false;
/**
* The view that the calendar should start in.
*/
this.startView = DateView.MONTH;
/**
* Whether to should only the year and multi-year views.
*/
this.yearOnly = false;
/**
* Whether to should only the multi-year view.
*/
this.multiyearOnly = false;
/**
* Hours to change per step
*/
this._stepHour = 1;
/**
* Minutes to change per step
*/
this._stepMinute = 1;
/**
* Seconds to change per step
*/
this._stepSecond = 1;
/**
* Whether to hide dates in other months at the start or end of the current month.
*/
this._hideOtherMonths = false;
/**
* Date Time Checker to check if the give dateTime is selectable
*/
this.dateTimeChecker = function (dateTime) {
return (!!dateTime &&
(!_this.dateTimeFilter || _this.dateTimeFilter(dateTime)) &&
(!_this.minDateTime ||
_this.dateTimeAdapter.compare(dateTime, _this.minDateTime) >=
0) &&
(!_this.maxDateTime ||
_this.dateTimeAdapter.compare(dateTime, _this.maxDateTime) <= 0));
};
if (!this.dateTimeAdapter) {
throw Error("OwlDateTimePicker: No provider found for DateTimeAdapter. You must import one of the following " +
"modules at your application root: OwlNativeDateTimeModule, OwlMomentDateTimeModule, or provide a " +
"custom implementation.");
}
if (!this.dateTimeFormats) {
throw Error("OwlDateTimePicker: No provider found for OWL_DATE_TIME_FORMATS. You must import one of the following " +
"modules at your application root: OwlNativeDateTimeModule, OwlMomentDateTimeModule, or provide a " +
"custom implementation.");
}
this._id = "owl-dt-picker-" + nextUniqueId++;
}
Object.defineProperty(OwlDateTime.prototype, "showSecondsTimer", {
get: function () {
return this._showSecondsTimer;
},
set: function (val) {
this._showSecondsTimer = coercion.coerceBooleanProperty(val);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "hour12Timer", {
get: function () {
return this._hour12Timer;
},
set: function (val) {
this._hour12Timer = coercion.coerceBooleanProperty(val);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "stepHour", {
get: function () {
return this._stepHour;
},
set: function (val) {
this._stepHour = coercion.coerceNumberProperty(val, 1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "stepMinute", {
get: function () {
return this._stepMinute;
},
set: function (val) {
this._stepMinute = coercion.coerceNumberProperty(val, 1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "stepSecond", {
get: function () {
return this._stepSecond;
},
set: function (val) {
this._stepSecond = coercion.coerceNumberProperty(val, 1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "firstDayOfWeek", {
get: function () {
return this._firstDayOfWeek;
},
set: function (value) {
value = coercion.coerceNumberProperty(value);
if (value > 6 || value < 0) {
this._firstDayOfWeek = undefined;
}
else {
this._firstDayOfWeek = value;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "hideOtherMonths", {
get: function () {
return this._hideOtherMonths;
},
set: function (val) {
this._hideOtherMonths = coercion.coerceBooleanProperty(val);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "id", {
get: function () {
return this._id;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "formatString", {
get: function () {
return this.pickerType === 'both'
? this.dateTimeFormats.fullPickerInput
: this.pickerType === 'calendar'
? this.dateTimeFormats.datePickerInput
: this.dateTimeFormats.timePickerInput;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlDateTime.prototype, "disabled", {
get: function () {
return false;
},
enumerable: false,
configurable: true
});
OwlDateTime.prototype.getValidDate = function (obj) {
return this.dateTimeAdapter.isDateInstance(obj) &&
this.dateTimeAdapter.isValid(obj)
? obj
: null;
};
return OwlDateTime;
}());
OwlDateTime.decorators = [
{ type: i0.Directive }
];
OwlDateTime.ctorParameters = function () { return [
{ type: DateTimeAdapter, decorators: [{ type: i0.Optional }] },
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [OWL_DATE_TIME_FORMATS,] }] }
]; };
OwlDateTime.propDecorators = {
showSecondsTimer: [{ type: i0.Input }],
hour12Timer: [{ type: i0.Input }],
startView: [{ type: i0.Input }],
yearOnly: [{ type: i0.Input }],
multiyearOnly: [{ type: i0.Input }],
stepHour: [{ type: i0.Input }],
stepMinute: [{ type: i0.Input }],
stepSecond: [{ type: i0.Input }],
firstDayOfWeek: [{ type: i0.Input }],
hideOtherMonths: [{ type: i0.Input }]
};
/**
* calendar.component
*/
var OwlCalendarComponent = /** @class */ (function () {
function OwlCalendarComponent(elmRef, pickerIntl, ngZone, cdRef, dateTimeAdapter, dateTimeFormats) {
var _this = this;
this.elmRef = elmRef;
this.pickerIntl = pickerIntl;
this.ngZone = ngZone;
this.cdRef = cdRef;
this.dateTimeAdapter = dateTimeAdapter;
this.dateTimeFormats = dateTimeFormats;
this.DateView = DateView;
this._selecteds = [];
/**
* The view that the calendar should start in.
*/
this.startView = DateView.MONTH;
/**
* Whether to should only the year and multi-year views.
*/
this.yearOnly = false;
/**
* Whether to should only the multi-year view.
*/
this.multiyearOnly = false;
/** Emits when the currently picker moment changes. */
this.pickerMomentChange = new i0.EventEmitter();
/** Emits when the currently selected date changes. */
this.selectedChange = new i0.EventEmitter();
/** Emits when any date is selected. */
this.userSelection = new i0.EventEmitter();
/**
* Emits the selected year. This doesn't imply a change on the selected date
* */
this.yearSelected = new i0.EventEmitter();
/**
* Emits the selected month. This doesn't imply a change on the selected date
* */
this.monthSelected = new i0.EventEmitter();
this.intlChangesSub = rxjs.Subscription.EMPTY;
/**
* Used for scheduling that focus should be moved to the active cell on the next tick.
* We need to schedule it, rather than do it immediately, because we have to wait
* for Angular to re-evaluate the view children.
*/
this.moveFocusOnNextTick = false;
/**
* Date filter for the month and year view
*/
this.dateFilterForViews = function (date) {
return (!!date &&
(!_this.dateFilter || _this.dateFilter(date)) &&
(!_this.minDate ||
_this.dateTimeAdapter.compare(date, _this.minDate) >= 0) &&
(!_this.maxDate ||
_this.dateTimeAdapter.compare(date, _this.maxDate) <= 0));
};
this.intlChangesSub = this.pickerIntl.changes.subscribe(function () {
_this.cdRef.markForCheck();
});
}
Object.defineProperty(OwlCalendarComponent.prototype, "minDate", {
get: function () {
return this._minDate;
},
set: function (value) {
value = this.dateTimeAdapter.deserialize(value);
value = this.getValidDate(value);
this._minDate = value
? this.dateTimeAdapter.createDate(this.dateTimeAdapter.getYear(value), this.dateTimeAdapter.getMonth(value), this.dateTimeAdapter.getDate(value))
: null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "maxDate", {
get: function () {
return this._maxDate;
},
set: function (value) {
value = this.dateTimeAdapter.deserialize(value);
value = this.getValidDate(value);
this._maxDate = value
? this.dateTimeAdapter.createDate(this.dateTimeAdapter.getYear(value), this.dateTimeAdapter.getMonth(value), this.dateTimeAdapter.getDate(value))
: null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "pickerMoment", {
get: function () {
return this._pickerMoment;
},
set: function (value) {
value = this.dateTimeAdapter.deserialize(value);
this._pickerMoment =
this.getValidDate(value) || this.dateTimeAdapter.now();
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "selected", {
get: function () {
return this._selected;
},
set: function (value) {
value = this.dateTimeAdapter.deserialize(value);
this._selected = this.getValidDate(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "selecteds", {
get: function () {
return this._selecteds;
},
set: function (values) {
var _this = this;
this._selecteds = values.map(function (v) {
v = _this.dateTimeAdapter.deserialize(v);
return _this.getValidDate(v);
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "periodButtonText", {
get: function () {
return this.isMonthView
? this.dateTimeAdapter.format(this.pickerMoment, this.dateTimeFormats.monthYearLabel)
: this.dateTimeAdapter.getYearName(this.pickerMoment);
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "periodButtonLabel", {
get: function () {
return this.isMonthView
? this.pickerIntl.switchToMultiYearViewLabel
: this.pickerIntl.switchToMonthViewLabel;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "prevButtonLabel", {
get: function () {
if (this._currentView === DateView.MONTH) {
return this.pickerIntl.prevMonthLabel;
}
else if (this._currentView === DateView.YEAR) {
return this.pickerIntl.prevYearLabel;
}
else {
return null;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "nextButtonLabel", {
get: function () {
if (this._currentView === DateView.MONTH) {
return this.pickerIntl.nextMonthLabel;
}
else if (this._currentView === DateView.YEAR) {
return this.pickerIntl.nextYearLabel;
}
else {
return null;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "currentView", {
get: function () {
return this._currentView;
},
set: function (view) {
this._currentView = view;
this.moveFocusOnNextTick = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "isInSingleMode", {
get: function () {
return this.selectMode === 'single';
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "isInRangeMode", {
get: function () {
return (this.selectMode === 'range' ||
this.selectMode === 'rangeFrom' ||
this.selectMode === 'rangeTo');
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "showControlArrows", {
get: function () {
return this._currentView !== DateView.MULTI_YEARS;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "isMonthView", {
get: function () {
return this._currentView === DateView.MONTH;
},
enumerable: false,
configurable: true
});
Object.defineProperty(OwlCalendarComponent.prototype, "owlDTCalendarClass", {
/**
* Bind class 'owl-dt-calendar' to host
* */
get: function () {
return true;
},
enumerable: false,
configurable: true
});
OwlCalendarComponent.prototype.ngOnInit = function () {
};
OwlCalendarComponent.prototype.ngAfterContentInit = function () {
this._currentView = this.startView;
};
OwlCalendarComponent.prototype.ngAfterViewChecked = function () {
if (this.moveFocusOnNextTick) {
this.moveFocusOnNextTick = false;
this.focusActiveCell();
}
};
OwlCalendarComponent.prototype.ngOnDestroy = function () {
this.intlChangesSub.unsubscribe();
};
/**
* Toggle between month view and year view
*/
OwlCalendarComponent.prototype.toggleViews = function () {
var nextView = null;
if (this._currentView === DateView.MONTH) {
nextView = DateView.MULTI_YEARS;
}
else {
if (this.multiyearOnly) {
nextView = DateView.MULTI_YEARS;
}
else if (this.yearOnly) {
nextView = this._currentView === DateView.YEAR ? DateView.MULTI_YEARS : DateView.YEAR;
}
else {
nextView = DateView.MONTH;
}
}
this.currentView = nextView;
};
/**
* Handles user clicks on the previous button.
* */
OwlCalendarComponent.prototype.previousClicked = function () {
this.pickerMoment = this.isMonthView
? this.dateTimeAdapter.addCalendarMonths(this.pickerMoment, -1)
: this.dateTimeAdapter.addCalendarYears(this.pickerMoment, -1);
this.pickerMomentChange.emit(this.pickerMoment);
};
/**
* Handles user clicks on the next button.
* */
OwlCalendarComponent.prototype.nextClicked = function () {
this.pickerMoment = this.isMonthView
? this.dateTimeAdapter.addCalendarMonths(this.pickerMoment, 1)
: this.dateTimeAdapter.addCalendarYears(this.pickerMoment, 1);
this.pickerMomentChange.emit(this.pickerMoment);
};
OwlCalendarComponent.prototype.dateSelected = function (date) {
if (!this.dateFilterForViews(date)) {
return;
}
this.selectedChange.emit(date);
/*if ((this.isInSingleMode && !this.dateTimeAdapter.isSameDay(date, this.selected)) ||
this.isInRangeMode) {
this.selectedChange.emit(date);
}*/
};
/**
* Change the pickerMoment value and switch to a specific view
*/
OwlCalendarComponent.prototype.goToDateInView = function (date, view) {
this.handlePickerMomentChange(date);
if ((!this.yearOnly && !this.multiyearOnly) ||
(this.multiyearOnly && (view !== DateView.MONTH && view !== DateView.YEAR)) ||
(this.yearOnly && view !== DateView.MONTH)) {
this.currentView = view;
}
return;
};
/**
* Change the pickerMoment value
*/
OwlCalendarComponent.prototype.handlePickerMomentChange = function (date) {
this.pickerMoment = this.dateTimeAdapter.clampDate(date, this.minDate, this.maxDate);
this.pickerMomentChange.emit(this.pickerMoment);
return;
};
OwlCalendarComponent.prototype.userSelected = function () {
this.userSelection.emit();
};
/**
* Whether the previous period button is enabled.
*/
OwlCalendarComponent.prototype.prevButtonEnabled = function () {
return (!this.minDate || !this.isSameView(this.pickerMoment, this.minDate));
};
/**
* Whether the next period button is enabled.
*/
OwlCalendarComponent.prototype.nextButtonEnabled = function () {
return (!this.maxDate || !this.isSameView(this.pickerMoment, this.maxDate));
};
/**
* Focus to the host element
* */
OwlCalendarComponent.prototype.focusActiveCell = function () {
var _this = this;
this.ngZone.runOutsideAngular(function () {
_this.ngZone.onStable
.asObservable()
.pipe(operators.take(1))
.subscribe(function () {
_this.elmRef.nativeElement
.querySelector('.owl-dt-calendar-cell-active')
.focus();
});
});
};
OwlCalendarComponent.prototype.selectYearInMultiYearView = function (normalizedYear) {
this.yearSelected.emit(normalizedYear);
};
OwlCalendarComponent.prototype.selectMonthInYearView = function (normalizedMonth) {
this.monthSelected.emit(normalizedMonth);
};
/**
* Whether the two dates represent the same view in the current view mode (month or year).
*/
OwlCalendarComponent.prototype.isSameView = function (date1, date2) {
if (this._currentView === DateView.MONTH) {
return !!(date1 &&
date2 &&
this.dateTimeAdapter.getYear(date1) ===
this.dateTimeAdapter.getYear(date2) &&
this.dateTimeAdapter.getMonth(date1) ===
this.dateTimeAdapter.getMonth(date2));
}
else if (this._currentView === DateView.YEAR) {
return !!(date1 &&
date2 &&
this.dateTimeAdapter.getYear(date1) ===
this.dateTimeAdapter.getYear(date2));
}
else {
return false;
}
};
/**
* Get a valid date object
*/
OwlCalendarComponent.prototype.getValidDate = function (obj) {
return this.dateTimeAdapter.isDateInstance(obj) &&
this.dateTimeAdapter.isValid(obj)
? obj
: null;
};
return OwlCalendarComponent;
}());
OwlCalendarComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'owl-date-time-calendar',
exportAs: 'owlDateTimeCalendar',
template: "<div class=\"owl-dt-calendar-control\">\n <!-- focus when keyboard tab (http://kizu.ru/en/blog/keyboard-only-focus/#x) -->\n <button class=\"owl-dt-control owl-dt-control-button owl-dt-control-arrow-button\"\n type=\"button\" tabindex=\"0\"\n [style.visibility]=\"showControlArrows? 'visible': 'hidden'\"\n [disabled]=\"!prevButtonEnabled()\"\n [attr.aria-label]=\"prevButtonLabel\"\n (click)=\"previousClicked()\">\n <span class=\"owl-dt-control-content owl-dt-control-button-content\" tabindex=\"-1\">\n <!-- <editor-fold desc=\"SVG Arrow Left\"> -->\n <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n version=\"1.1\" x=\"0px\" y=\"0px\" viewBox=\"0 0 250.738 250.738\"\n style=\"enable-background:new 0 0 250.738 250.738;\" xml:space=\"preserve\"\n width=\"100%\" height=\"100%\">\n <pa