ngx-bootstrap
Version:
Angular Bootstrap
1,101 lines (1,084 loc) • 231 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('ngx-bootstrap/chronos'), require('ngx-bootstrap/positioning'), require('@angular/animations'), require('rxjs'), require('ngx-bootstrap/mini-ngrx'), require('ngx-bootstrap/component-loader'), require('@angular/forms'), require('ngx-bootstrap/utils'), require('@angular/common'), require('ngx-bootstrap/tooltip')) :
typeof define === 'function' && define.amd ? define('ngx-bootstrap/datepicker', ['exports', '@angular/core', 'rxjs/operators', 'ngx-bootstrap/chronos', 'ngx-bootstrap/positioning', '@angular/animations', 'rxjs', 'ngx-bootstrap/mini-ngrx', 'ngx-bootstrap/component-loader', '@angular/forms', 'ngx-bootstrap/utils', '@angular/common', 'ngx-bootstrap/tooltip'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].datepicker = {}), global.ng.core, global.rxjs.operators, global.chronos, global.positioning, global.ng.animations, global.rxjs, global.miniNgrx, global.componentLoader, global.ng.forms, global.utils, global.ng.common, global.tooltip));
}(this, (function (exports, i0, operators, chronos, positioning, animations, rxjs, miniNgrx, componentLoader, forms, utils, common, tooltip) { 'use strict';
/**
* For date range picker there are `BsDaterangepickerConfig` which inherits all properties,
* except `displayMonths`, for range picker it default to `2`
*/
var BsDatepickerConfig = /** @class */ (function () {
function BsDatepickerConfig() {
/** sets use adaptive position */
this.adaptivePosition = false;
/** sets use UTC date time format */
this.useUtc = false;
/** turn on/off animation */
this.isAnimated = false;
/**
* The view that the datepicker should start in
*/
this.startView = 'day';
/**
* If true, returns focus to the datepicker / daterangepicker input after date selection
*/
this.returnFocusToInput = false;
/** CSS class which will be applied to datepicker container,
* usually used to set color theme
*/
this.containerClass = 'theme-green';
// DatepickerRenderOptions
this.displayMonths = 1;
/**
* Allows to hide week numbers in datepicker
*/
this.showWeekNumbers = true;
this.dateInputFormat = 'L';
// range picker
this.rangeSeparator = ' - ';
/**
* Date format for date range input field
*/
this.rangeInputFormat = 'L';
// DatepickerFormatOptions
this.monthTitle = 'MMMM';
this.yearTitle = 'YYYY';
this.dayLabel = 'D';
this.monthLabel = 'MMMM';
this.yearLabel = 'YYYY';
this.weekNumbers = 'w';
/**
* Shows 'today' button
*/
this.showTodayButton = false;
/**
* Shows clear button
*/
this.showClearButton = false;
/**
* Positioning of 'today' button
*/
this.todayPosition = 'center';
/**
* Positioning of 'clear' button
*/
this.clearPosition = 'right';
/**
* Label for 'today' button
*/
this.todayButtonLabel = 'Today';
/**
* Label for 'clear' button
*/
this.clearButtonLabel = 'Clear';
/**
* Label for 'custom range' button
*/
this.customRangeButtonLabel = 'Custom Range';
}
return BsDatepickerConfig;
}());
BsDatepickerConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function BsDatepickerConfig_Factory() { return new BsDatepickerConfig(); }, token: BsDatepickerConfig, providedIn: "root" });
BsDatepickerConfig.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/*! *****************************************************************************
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 (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
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, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, 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;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
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 __spreadArray(to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
}
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 (k !== "default" && Object.prototype.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;
}
var DATEPICKER_ANIMATION_TIMING = '220ms cubic-bezier(0, 0, 0.2, 1)';
var datepickerAnimation = animations.trigger('datepickerAnimation', [
animations.state('animated-down', animations.style({ height: '*', overflow: 'hidden' })),
animations.transition('* => animated-down', [
animations.style({ height: 0, overflow: 'hidden' }),
animations.animate(DATEPICKER_ANIMATION_TIMING)
]),
animations.state('animated-up', animations.style({ height: '*', overflow: 'hidden' })),
animations.transition('* => animated-up', [
animations.style({ height: '*', overflow: 'hidden' }),
animations.animate(DATEPICKER_ANIMATION_TIMING)
]),
animations.transition('* => unanimated', animations.animate('0s'))
]);
var BsDatepickerAbstractComponent = /** @class */ (function () {
function BsDatepickerAbstractComponent() {
this.containerClass = '';
this.customRanges = [];
this.chosenRange = [];
this._daysCalendarSub = new rxjs.Subscription();
}
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "minDate", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setMinDate(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "maxDate", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setMaxDate(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "daysDisabled", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDaysDisabled(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "datesDisabled", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDatesDisabled(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "datesEnabled", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDatesEnabled(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "isDisabled", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDisabled(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "dateCustomClasses", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDateCustomClasses(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "dateTooltipTexts", {
set: function (value) {
var _a;
(_a = this._effects) === null || _a === void 0 ? void 0 : _a.setDateTooltipTexts(value);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "daysCalendar$", {
get: function () {
return this._daysCalendar$;
},
set: function (value) {
var _this = this;
this._daysCalendar$ = value;
this._daysCalendarSub.unsubscribe();
this._daysCalendarSub.add(this._daysCalendar$.subscribe(function (value) {
_this.multipleCalendars = !!value && value.length > 1;
}));
},
enumerable: false,
configurable: true
});
// todo: valorkin fix
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
BsDatepickerAbstractComponent.prototype.setViewMode = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.navigateTo = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.dayHoverHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.weekHoverHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.monthHoverHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.yearHoverHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.daySelectHandler = function (day) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.monthSelectHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.yearSelectHandler = function (event) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.setRangeOnCalendar = function (dates) { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.setToday = function () { };
// eslint-disable-next-line
BsDatepickerAbstractComponent.prototype.clearDate = function () { };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
BsDatepickerAbstractComponent.prototype._stopPropagation = function (event) {
event.stopPropagation();
};
return BsDatepickerAbstractComponent;
}());
var BsDatepickerActions = /** @class */ (function () {
function BsDatepickerActions() {
}
BsDatepickerActions.prototype.calculate = function () {
return { type: BsDatepickerActions.CALCULATE };
};
BsDatepickerActions.prototype.format = function () {
return { type: BsDatepickerActions.FORMAT };
};
BsDatepickerActions.prototype.flag = function () {
return { type: BsDatepickerActions.FLAG };
};
BsDatepickerActions.prototype.select = function (date) {
return {
type: BsDatepickerActions.SELECT,
payload: date
};
};
BsDatepickerActions.prototype.changeViewMode = function (event) {
return {
type: BsDatepickerActions.CHANGE_VIEWMODE,
payload: event
};
};
BsDatepickerActions.prototype.navigateTo = function (event) {
return {
type: BsDatepickerActions.NAVIGATE_TO,
payload: event
};
};
BsDatepickerActions.prototype.navigateStep = function (step) {
return {
type: BsDatepickerActions.NAVIGATE_OFFSET,
payload: step
};
};
BsDatepickerActions.prototype.setOptions = function (options) {
return {
type: BsDatepickerActions.SET_OPTIONS,
payload: options
};
};
// date range picker
BsDatepickerActions.prototype.selectRange = function (value) {
return {
type: BsDatepickerActions.SELECT_RANGE,
payload: value
};
};
BsDatepickerActions.prototype.hoverDay = function (event) {
return {
type: BsDatepickerActions.HOVER,
payload: event.isHovered ? event.cell.date : null
};
};
BsDatepickerActions.prototype.minDate = function (date) {
return {
type: BsDatepickerActions.SET_MIN_DATE,
payload: date
};
};
BsDatepickerActions.prototype.maxDate = function (date) {
return {
type: BsDatepickerActions.SET_MAX_DATE,
payload: date
};
};
BsDatepickerActions.prototype.daysDisabled = function (days) {
return {
type: BsDatepickerActions.SET_DAYSDISABLED,
payload: days
};
};
BsDatepickerActions.prototype.datesDisabled = function (dates) {
return {
type: BsDatepickerActions.SET_DATESDISABLED,
payload: dates
};
};
BsDatepickerActions.prototype.datesEnabled = function (dates) {
return {
type: BsDatepickerActions.SET_DATESENABLED,
payload: dates
};
};
BsDatepickerActions.prototype.isDisabled = function (value) {
return {
type: BsDatepickerActions.SET_IS_DISABLED,
payload: value
};
};
BsDatepickerActions.prototype.setDateCustomClasses = function (value) {
return {
type: BsDatepickerActions.SET_DATE_CUSTOM_CLASSES,
payload: value
};
};
BsDatepickerActions.prototype.setDateTooltipTexts = function (value) {
return {
type: BsDatepickerActions.SET_DATE_TOOLTIP_TEXTS,
payload: value
};
};
BsDatepickerActions.prototype.setLocale = function (locale) {
return {
type: BsDatepickerActions.SET_LOCALE,
payload: locale
};
};
return BsDatepickerActions;
}());
BsDatepickerActions.CALCULATE = '[datepicker] calculate dates matrix';
BsDatepickerActions.FORMAT = '[datepicker] format datepicker values';
BsDatepickerActions.FLAG = '[datepicker] set flags';
BsDatepickerActions.SELECT = '[datepicker] select date';
BsDatepickerActions.NAVIGATE_OFFSET = '[datepicker] shift view date';
BsDatepickerActions.NAVIGATE_TO = '[datepicker] change view date';
BsDatepickerActions.SET_OPTIONS = '[datepicker] update render options';
BsDatepickerActions.HOVER = '[datepicker] hover date';
BsDatepickerActions.CHANGE_VIEWMODE = '[datepicker] switch view mode';
BsDatepickerActions.SET_MIN_DATE = '[datepicker] set min date';
BsDatepickerActions.SET_MAX_DATE = '[datepicker] set max date';
BsDatepickerActions.SET_DAYSDISABLED = '[datepicker] set days disabled';
BsDatepickerActions.SET_DATESDISABLED = '[datepicker] set dates disabled';
BsDatepickerActions.SET_DATESENABLED = '[datepicker] set dates enabled';
BsDatepickerActions.SET_IS_DISABLED = '[datepicker] set is disabled';
BsDatepickerActions.SET_DATE_CUSTOM_CLASSES = '[datepicker] set date custom classes';
BsDatepickerActions.SET_DATE_TOOLTIP_TEXTS = '[datepicker] set date tooltip texts';
BsDatepickerActions.SET_LOCALE = '[datepicker] set datepicker locale';
BsDatepickerActions.SELECT_RANGE = '[daterangepicker] select dates range';
BsDatepickerActions.decorators = [
{ type: i0.Injectable }
];
var BsLocaleService = /** @class */ (function () {
function BsLocaleService() {
this._defaultLocale = 'en';
this._locale = new rxjs.BehaviorSubject(this._defaultLocale);
this._localeChange = this._locale.asObservable();
}
Object.defineProperty(BsLocaleService.prototype, "locale", {
get: function () {
return this._locale;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsLocaleService.prototype, "localeChange", {
get: function () {
return this._localeChange;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BsLocaleService.prototype, "currentLocale", {
get: function () {
return this._locale.getValue();
},
enumerable: false,
configurable: true
});
BsLocaleService.prototype.use = function (locale) {
if (locale === this.currentLocale) {
return;
}
this._locale.next(locale);
};
return BsLocaleService;
}());
BsLocaleService.decorators = [
{ type: i0.Injectable }
];
var BsDatepickerEffects = /** @class */ (function () {
function BsDatepickerEffects(_actions, _localeService) {
this._actions = _actions;
this._localeService = _localeService;
this._subs = [];
}
BsDatepickerEffects.prototype.init = function (_bsDatepickerStore) {
this._store = _bsDatepickerStore;
return this;
};
/** setters */
BsDatepickerEffects.prototype.setValue = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.select(value));
};
BsDatepickerEffects.prototype.setRangeValue = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.selectRange(value));
};
BsDatepickerEffects.prototype.setMinDate = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.minDate(value));
return this;
};
BsDatepickerEffects.prototype.setMaxDate = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.maxDate(value));
return this;
};
BsDatepickerEffects.prototype.setDaysDisabled = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.daysDisabled(value));
return this;
};
BsDatepickerEffects.prototype.setDatesDisabled = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.datesDisabled(value));
return this;
};
BsDatepickerEffects.prototype.setDatesEnabled = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.datesEnabled(value));
return this;
};
BsDatepickerEffects.prototype.setDisabled = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.isDisabled(value));
return this;
};
BsDatepickerEffects.prototype.setDateCustomClasses = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.setDateCustomClasses(value));
return this;
};
BsDatepickerEffects.prototype.setDateTooltipTexts = function (value) {
var _a;
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.setDateTooltipTexts(value));
return this;
};
/* Set rendering options */
BsDatepickerEffects.prototype.setOptions = function (_config) {
var _a;
var _options = Object.assign({ locale: this._localeService.currentLocale }, _config);
(_a = this._store) === null || _a === void 0 ? void 0 : _a.dispatch(this._actions.setOptions(_options));
return this;
};
/** view to mode bindings */
BsDatepickerEffects.prototype.setBindings = function (container) {
if (!this._store) {
return this;
}
container.daysCalendar$ = this._store.select(function (state) { return state.flaggedMonths; })
.pipe(operators.filter(function (months) { return !!months; }));
// month calendar
container.monthsCalendar = this._store.select(function (state) { return state.flaggedMonthsCalendar; })
.pipe(operators.filter(function (months) { return !!months; }));
// year calendar
container.yearsCalendar = this._store.select(function (state) { return state.yearsCalendarFlagged; })
.pipe(operators.filter(function (years) { return !!years; }));
container.viewMode = this._store.select(function (state) { var _a; return (_a = state.view) === null || _a === void 0 ? void 0 : _a.mode; });
container.options$ = rxjs.combineLatest([
this._store.select(function (state) { return state.showWeekNumbers; }),
this._store.select(function (state) { return state.displayMonths; })
])
.pipe(operators.map(function (latest) { return ({
showWeekNumbers: latest[0],
displayMonths: latest[1]
}); }));
return this;
};
/** event handlers */
BsDatepickerEffects.prototype.setEventHandlers = function (container) {
var _this = this;
container.setViewMode = function (event) {
var _a;
(_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.changeViewMode(event));
};
container.navigateTo = function (event) {
var _a;
(_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.navigateStep(event.step));
};
container.dayHoverHandler = function (event) {
var _a;
var _cell = event.cell;
if (_cell.isOtherMonth || _cell.isDisabled) {
return;
}
(_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.hoverDay(event));
_cell.isHovered = event.isHovered;
};
container.monthHoverHandler = function (event) {
event.cell.isHovered = event.isHovered;
};
container.yearHoverHandler = function (event) {
event.cell.isHovered = event.isHovered;
};
return this;
};
BsDatepickerEffects.prototype.registerDatepickerSideEffects = function () {
var _this = this;
if (!this._store) {
return this;
}
this._subs.push(this._store.select(function (state) { return state.view; }).subscribe(function () {
var _a;
(_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.calculate());
}));
// format calendar values on month model change
this._subs.push(this._store
.select(function (state) { return state.monthsModel; })
.pipe(operators.filter(function (monthModel) { return !!monthModel; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.format()); }));
// flag day values
this._subs.push(this._store
.select(function (state) { return state.formattedMonths; })
.pipe(operators.filter(function (month) { return !!month; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// flag day values
this._subs.push(this._store
.select(function (state) { return state.selectedDate; })
.pipe(operators.filter(function (selectedDate) { return !!selectedDate; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// flag for date range picker
this._subs.push(this._store
.select(function (state) { return state.selectedRange; })
.pipe(operators.filter(function (selectedRange) { return !!selectedRange; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// monthsCalendar
this._subs.push(this._store
.select(function (state) { return state.monthsCalendar; })
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// years calendar
this._subs.push(this._store
.select(function (state) { return state.yearsCalendarModel; })
.pipe(operators.filter(function (state) { return !!state; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// on hover
this._subs.push(this._store
.select(function (state) { return state.hoveredDate; })
.pipe(operators.filter(function (hoveredDate) { return !!hoveredDate; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// date custom classes
this._subs.push(this._store
.select(function (state) { return state.dateCustomClasses; })
.pipe(operators.filter(function (dateCustomClasses) { return !!dateCustomClasses; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// date tooltip texts
this._subs.push(this._store
.select(function (state) { return state.dateTooltipTexts; })
.pipe(operators.filter(function (dateTooltipTexts) { return !!dateTooltipTexts; }))
.subscribe(function () { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.flag()); }));
// on locale change
this._subs.push(this._localeService.localeChange
.subscribe(function (locale) { var _a; return (_a = _this._store) === null || _a === void 0 ? void 0 : _a.dispatch(_this._actions.setLocale(locale)); }));
return this;
};
BsDatepickerEffects.prototype.destroy = function () {
var e_1, _b;
try {
for (var _c = __values(this._subs), _d = _c.next(); !_d.done; _d = _c.next()) {
var sub = _d.value;
sub.unsubscribe();
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
};
return BsDatepickerEffects;
}());
BsDatepickerEffects.decorators = [
{ type: i0.Injectable }
];
BsDatepickerEffects.ctorParameters = function () { return [
{ type: BsDatepickerActions },
{ type: BsLocaleService }
]; };
var defaultMonthOptions = {
width: 7,
height: 6
};
var dayInMilliseconds = 24 * 60 * 60 * 1000;
var BsDatepickerState = /** @class */ (function () {
function BsDatepickerState() {
// DatepickerRenderOptions
this.showWeekNumbers = true;
this.displayMonths = 1;
}
return BsDatepickerState;
}());
var _initialView = { date: new Date(), mode: 'day' };
var initialDatepickerState = Object.assign(new BsDatepickerConfig(), {
locale: 'en',
view: _initialView,
selectedRange: [],
monthViewOptions: defaultMonthOptions
});
function getStartingDayOfCalendar(date, options) {
if (chronos.isFirstDayOfWeek(date, options.firstDayOfWeek)) {
return date;
}
var weekDay = chronos.getDay(date);
var offset = calculateDateOffset(weekDay, options.firstDayOfWeek);
return chronos.shiftDate(date, { day: -offset });
}
function calculateDateOffset(weekday, startingDayOffset) {
var _startingDayOffset = Number(startingDayOffset);
if (isNaN(_startingDayOffset)) {
return 0;
}
if (_startingDayOffset === 0) {
return weekday;
}
var offset = weekday - _startingDayOffset % 7;
return offset < 0 ? offset + 7 : offset;
}
function isMonthDisabled(date, min, max) {
var minBound = min && chronos.isBefore(chronos.endOf(date, 'month'), min, 'day');
var maxBound = max && chronos.isAfter(chronos.startOf(date, 'month'), max, 'day');
return minBound || maxBound || false;
}
function isYearDisabled(date, min, max) {
var minBound = min && chronos.isBefore(chronos.endOf(date, 'year'), min, 'day');
var maxBound = max && chronos.isAfter(chronos.startOf(date, 'year'), max, 'day');
return minBound || maxBound || false;
}
function isDisabledDate(date, datesDisabled) {
if (!datesDisabled || !chronos.isArray(datesDisabled) || !datesDisabled.length) {
return false;
}
return datesDisabled.some(function (dateDisabled) { return chronos.isSame(date, dateDisabled, 'date'); });
}
function isEnabledDate(date, datesEnabled) {
if (!datesEnabled || !chronos.isArray(datesEnabled) || !datesEnabled.length) {
return false;
}
return !datesEnabled.some(function (enabledDate) { return chronos.isSame(date, enabledDate, 'date'); });
}
function getYearsCalendarInitialDate(state, calendarIndex) {
if (calendarIndex === void 0) { calendarIndex = 0; }
var model = state && state.yearsCalendarModel && state.yearsCalendarModel[calendarIndex];
return (model === null || model === void 0 ? void 0 : model.years[0]) && model.years[0][0] && model.years[0][0].date;
}
function checkRangesWithMaxDate(ranges, maxDate) {
if (!ranges)
return ranges;
if (!maxDate)
return ranges;
if (!ranges.length && !ranges[0].value)
return ranges;
ranges.forEach(function (item) {
if (!item || !item.value)
return ranges;
if (item.value instanceof Date)
return ranges;
if (!(item.value instanceof Array && item.value.length))
return ranges;
item.value = compareDateWithMaxDateHelper(item.value, maxDate);
return ranges;
});
return ranges;
}
function checkBsValue(date, maxDate) {
if (!date)
return date;
if (!maxDate)
return date;
if (date instanceof Array && !date.length)
return date;
if (date instanceof Date)
return date;
return compareDateWithMaxDateHelper(date, maxDate);
}
function compareDateWithMaxDateHelper(date, maxDate) {
if (date instanceof Array) {
var editedValues = date.map(function (item) {
if (!item)
return item;
if (chronos.isAfter(item, maxDate, 'date'))
item = maxDate;
return item;
});
return editedValues;
}
return date;
}
function createMatrix(options, fn) {
var prevValue = options.initialDate;
var matrix = new Array(options.height);
for (var i = 0; i < options.height; i++) {
matrix[i] = new Array(options.width);
for (var j = 0; j < options.width; j++) {
matrix[i][j] = fn(prevValue);
prevValue = chronos.shiftDate(prevValue, options.shift);
}
}
return matrix;
}
// user and model input should handle parsing and validating input values
function calcDaysCalendar(startingDate, options) {
var firstDay = chronos.getFirstDayOfMonth(startingDate);
var initialDate = getStartingDayOfCalendar(firstDay, options);
// todo test
var matrixOptions = {
width: options.width || 0,
height: options.height || 0,
initialDate: initialDate,
shift: { day: 1 }
};
var daysMatrix = createMatrix(matrixOptions, function (date) { return date; });
return {
daysMatrix: daysMatrix,
month: firstDay
};
}
function formatDaysCalendar(daysCalendar, formatOptions, monthIndex) {
return {
month: daysCalendar.month,
monthTitle: chronos.formatDate(daysCalendar.month, formatOptions.monthTitle, formatOptions.locale),
yearTitle: chronos.formatDate(daysCalendar.month, formatOptions.yearTitle, formatOptions.locale),
weekNumbers: getWeekNumbers(daysCalendar.daysMatrix, formatOptions.weekNumbers, formatOptions.locale),
weekdays: getShiftedWeekdays(formatOptions.locale),
weeks: daysCalendar.daysMatrix.map(function (week, weekIndex) { return ({
days: week.map(function (date, dayIndex) { return ({
date: date,
label: chronos.formatDate(date, formatOptions.dayLabel, formatOptions.locale),
monthIndex: monthIndex,
weekIndex: weekIndex,
dayIndex: dayIndex
}); })
}); }),
hideLeftArrow: false,
hideRightArrow: false,
disableLeftArrow: false,
disableRightArrow: false
};
}
function getWeekNumbers(daysMatrix, format, locale) {
return daysMatrix.map(function (days) { return (days[0] ? chronos.formatDate(days[0], format, locale) : ''); });
}
function getShiftedWeekdays(locale) {
var _locale = chronos.getLocale(locale);
var weekdays = _locale.weekdaysShort();
var firstDayOfWeek = _locale.firstDayOfWeek();
return __spread(weekdays.slice(firstDayOfWeek), weekdays.slice(0, firstDayOfWeek));
}
function flagDaysCalendar(formattedMonth, options) {
formattedMonth.weeks.forEach(function (week) {
week.days.forEach(function (day, dayIndex) {
// datepicker
var isOtherMonth = !chronos.isSameMonth(day.date, formattedMonth.month);
var isHovered = !isOtherMonth && chronos.isSameDay(day.date, options.hoveredDate);
// date range picker
var isSelectionStart = !isOtherMonth &&
options.selectedRange &&
chronos.isSameDay(day.date, options.selectedRange[0]);
var isSelectionEnd = !isOtherMonth &&
options.selectedRange &&
chronos.isSameDay(day.date, options.selectedRange[1]);
var isSelected = (!isOtherMonth && chronos.isSameDay(day.date, options.selectedDate)) ||
isSelectionStart ||
isSelectionEnd;
var isInRange = !isOtherMonth &&
options.selectedRange &&
isDateInRange(day.date, options.selectedRange, options.hoveredDate);
var isDisabled = options.isDisabled ||