accessibleprimevue
Version:
Note: This is the forked version of the Primefaces/PrimeVue repository. Since V3 has reached its EOL this is use to fix identified accessibility bugs in the v3 version of primevue. PrimeVue is an open source UI library for Vue featuring a rich set of 80+
1,445 lines (1,440 loc) • 141 kB
JavaScript
'use strict';
var Button = require('primevue/button');
var CalendarIcon = require('primevue/icons/calendar');
var ChevronDownIcon = require('primevue/icons/chevrondown');
var ChevronLeftIcon = require('primevue/icons/chevronleft');
var ChevronRightIcon = require('primevue/icons/chevronright');
var ChevronUpIcon = require('primevue/icons/chevronup');
var OverlayEventBus = require('primevue/overlayeventbus');
var Portal = require('primevue/portal');
var Ripple = require('primevue/ripple');
var utils = require('primevue/utils');
var BaseComponent = require('primevue/basecomponent');
var CalendarStyle = require('primevue/calendar/style');
var vue = require('vue');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);
var CalendarIcon__default = /*#__PURE__*/_interopDefaultLegacy(CalendarIcon);
var ChevronDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(ChevronDownIcon);
var ChevronLeftIcon__default = /*#__PURE__*/_interopDefaultLegacy(ChevronLeftIcon);
var ChevronRightIcon__default = /*#__PURE__*/_interopDefaultLegacy(ChevronRightIcon);
var ChevronUpIcon__default = /*#__PURE__*/_interopDefaultLegacy(ChevronUpIcon);
var OverlayEventBus__default = /*#__PURE__*/_interopDefaultLegacy(OverlayEventBus);
var Portal__default = /*#__PURE__*/_interopDefaultLegacy(Portal);
var Ripple__default = /*#__PURE__*/_interopDefaultLegacy(Ripple);
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
var CalendarStyle__default = /*#__PURE__*/_interopDefaultLegacy(CalendarStyle);
var script$1 = {
name: 'BaseCalendar',
"extends": BaseComponent__default["default"],
props: {
modelValue: null,
selectionMode: {
type: String,
"default": 'single'
},
dateFormat: {
type: String,
"default": null
},
inline: {
type: Boolean,
"default": false
},
showOtherMonths: {
type: Boolean,
"default": true
},
selectOtherMonths: {
type: Boolean,
"default": false
},
showIcon: {
type: Boolean,
"default": false
},
iconDisplay: {
type: String,
"default": 'button'
},
icon: {
type: String,
"default": undefined
},
previousIcon: {
type: String,
"default": undefined
},
nextIcon: {
type: String,
"default": undefined
},
incrementIcon: {
type: String,
"default": undefined
},
decrementIcon: {
type: String,
"default": undefined
},
numberOfMonths: {
type: Number,
"default": 1
},
responsiveOptions: Array,
breakpoint: {
type: String,
"default": '769px'
},
view: {
type: String,
"default": 'date'
},
touchUI: {
type: Boolean,
"default": false
},
monthNavigator: {
type: Boolean,
"default": false
},
yearNavigator: {
type: Boolean,
"default": false
},
yearRange: {
type: String,
"default": null
},
minDate: {
type: Date,
value: null
},
maxDate: {
type: Date,
value: null
},
disabledDates: {
type: Array,
value: null
},
disabledDays: {
type: Array,
value: null
},
maxDateCount: {
type: Number,
value: null
},
showOnFocus: {
type: Boolean,
"default": true
},
autoZIndex: {
type: Boolean,
"default": true
},
baseZIndex: {
type: Number,
"default": 0
},
showButtonBar: {
type: Boolean,
"default": false
},
shortYearCutoff: {
type: String,
"default": '+10'
},
showTime: {
type: Boolean,
"default": false
},
timeOnly: {
type: Boolean,
"default": false
},
hourFormat: {
type: String,
"default": '24'
},
stepHour: {
type: Number,
"default": 1
},
stepMinute: {
type: Number,
"default": 1
},
stepSecond: {
type: Number,
"default": 1
},
showSeconds: {
type: Boolean,
"default": false
},
hideOnDateTimeSelect: {
type: Boolean,
"default": false
},
hideOnRangeSelection: {
type: Boolean,
"default": false
},
timeSeparator: {
type: String,
"default": ':'
},
showWeek: {
type: Boolean,
"default": false
},
manualInput: {
type: Boolean,
"default": true
},
appendTo: {
type: [String, Object],
"default": 'body'
},
variant: {
type: String,
"default": null
},
invalid: {
type: Boolean,
"default": false
},
disabled: {
type: Boolean,
"default": false
},
readonly: {
type: Boolean,
"default": false
},
placeholder: {
type: String,
"default": null
},
id: {
type: String,
"default": null
},
inputId: {
type: String,
"default": null
},
inputClass: {
type: [String, Object],
"default": null
},
inputStyle: {
type: Object,
"default": null
},
inputProps: {
type: null,
"default": null
},
panelClass: {
type: [String, Object],
"default": null
},
panelStyle: {
type: Object,
"default": null
},
panelProps: {
type: null,
"default": null
},
name: {
type: String,
"default": null
},
ariaLabelledby: {
type: String,
"default": null
},
ariaLabel: {
type: String,
"default": null
}
},
style: CalendarStyle__default["default"],
provide: function provide() {
return {
$parentInstance: this
};
}
};
function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
var script = {
name: 'Calendar',
"extends": script$1,
inheritAttrs: false,
emits: ['show', 'hide', 'input', 'month-change', 'year-change', 'date-select', 'update:modelValue', 'today-click', 'clear-click', 'focus', 'blur', 'keydown'],
navigationState: null,
timePickerChange: false,
scrollHandler: null,
outsideClickListener: null,
maskClickListener: null,
resizeListener: null,
matchMediaListener: null,
overlay: null,
input: null,
mask: null,
previousButton: null,
nextButton: null,
timePickerTimer: null,
preventFocus: false,
typeUpdate: false,
hasOpened: false,
data: function data() {
return {
d_id: this.id,
currentMonth: null,
currentYear: null,
currentHour: null,
currentMinute: null,
currentSecond: null,
pm: null,
focused: false,
overlayVisible: false,
currentView: this.view,
query: null,
queryMatches: false
};
},
watch: {
id: function id(newValue) {
this.d_id = newValue || utils.UniqueComponentId();
},
modelValue: {
deep: true,
handler: function handler(newValue) {
this.updateCurrentMetaData();
if (!this.typeUpdate && !this.inline && this.input) {
this.input.value = this.formatValue(newValue);
}
this.typeUpdate = false;
}
},
showTime: function showTime() {
this.updateCurrentMetaData();
},
minDate: function minDate() {
this.updateCurrentMetaData();
},
maxDate: function maxDate() {
this.updateCurrentMetaData();
},
months: function months() {
if (this.overlay) {
if (!this.focused) {
if (this.inline) {
this.preventFocus = true;
}
setTimeout(this.updateFocus, 0);
}
}
},
numberOfMonths: function numberOfMonths() {
this.destroyResponsiveStyleElement();
this.createResponsiveStyle();
},
responsiveOptions: function responsiveOptions() {
this.destroyResponsiveStyleElement();
this.createResponsiveStyle();
},
currentView: function currentView() {
var _this = this;
Promise.resolve(null).then(function () {
return _this.alignOverlay();
});
},
view: function view(newValue) {
this.currentView = newValue;
}
},
created: function created() {
this.updateCurrentMetaData();
},
mounted: function mounted() {
this.d_id = this.d_id || utils.UniqueComponentId();
this.createResponsiveStyle();
this.bindMatchMediaListener();
if (this.inline) {
this.overlay && this.overlay.setAttribute(this.attributeSelector, '');
if (!this.disabled) {
this.preventFocus = true;
this.initFocusableCell();
}
} else {
this.input.value = this.formatValue(this.modelValue);
}
},
updated: function updated() {
if (this.overlay) {
this.preventFocus = true;
setTimeout(this.updateFocus, 0);
}
if (this.input && this.selectionStart != null && this.selectionEnd != null) {
this.input.selectionStart = this.selectionStart;
this.input.selectionEnd = this.selectionEnd;
this.selectionStart = null;
this.selectionEnd = null;
}
},
beforeUnmount: function beforeUnmount() {
if (this.timePickerTimer) {
clearTimeout(this.timePickerTimer);
}
if (this.mask) {
this.destroyMask();
}
this.destroyResponsiveStyleElement();
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindMatchMediaListener();
if (this.scrollHandler) {
this.scrollHandler.destroy();
this.scrollHandler = null;
}
if (this.overlay && this.autoZIndex) {
utils.ZIndexUtils.clear(this.overlay);
}
this.overlay = null;
},
methods: {
isComparable: function isComparable() {
return this.modelValue != null && typeof this.modelValue !== 'string';
},
isSelected: function isSelected(dateMeta) {
if (!this.isComparable()) {
return false;
}
if (this.modelValue) {
if (this.isSingleSelection()) {
return this.isDateEquals(this.modelValue, dateMeta);
} else if (this.isMultipleSelection()) {
var selected = false;
var _iterator = _createForOfIteratorHelper(this.modelValue),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var date = _step.value;
selected = this.isDateEquals(date, dateMeta);
if (selected) {
break;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return selected;
} else if (this.isRangeSelection()) {
if (this.modelValue[1]) return this.isDateEquals(this.modelValue[0], dateMeta) || this.isDateEquals(this.modelValue[1], dateMeta) || this.isDateBetween(this.modelValue[0], this.modelValue[1], dateMeta);else {
return this.isDateEquals(this.modelValue[0], dateMeta);
}
}
}
return false;
},
isMonthSelected: function isMonthSelected(month) {
var _this2 = this;
if (!this.isComparable()) return false;
if (this.isMultipleSelection()) {
return this.modelValue.some(function (currentValue) {
return currentValue.getMonth() === month && currentValue.getFullYear() === _this2.currentYear;
});
} else if (this.isRangeSelection()) {
var _this$modelValue = _slicedToArray(this.modelValue, 2),
start = _this$modelValue[0],
end = _this$modelValue[1];
var startYear = start ? start.getFullYear() : null;
var endYear = end ? end.getFullYear() : null;
var startMonth = start ? start.getMonth() : null;
var endMonth = end ? end.getMonth() : null;
if (!end) {
return startYear === this.currentYear && startMonth === month;
} else {
var currentDate = new Date(this.currentYear, month, 1);
var startDate = new Date(startYear, startMonth, 1);
var endDate = new Date(endYear, endMonth, 1);
return currentDate >= startDate && currentDate <= endDate;
}
} else {
return this.modelValue.getMonth() === month && this.modelValue.getFullYear() === this.currentYear;
}
},
isYearSelected: function isYearSelected(year) {
if (!this.isComparable()) return false;
if (this.isMultipleSelection()) {
return this.modelValue.some(function (currentValue) {
return currentValue.getFullYear() === year;
});
} else if (this.isRangeSelection()) {
var start = this.modelValue[0] ? this.modelValue[0].getFullYear() : null;
var end = this.modelValue[1] ? this.modelValue[1].getFullYear() : null;
return start === year || end === year || start < year && end > year;
} else {
return this.modelValue.getFullYear() === year;
}
},
isDateEquals: function isDateEquals(value, dateMeta) {
if (value) return value.getDate() === dateMeta.day && value.getMonth() === dateMeta.month && value.getFullYear() === dateMeta.year;else return false;
},
isDateBetween: function isDateBetween(start, end, dateMeta) {
var between = false;
if (start && end) {
var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
return start.getTime() <= date.getTime() && end.getTime() >= date.getTime();
}
return between;
},
getFirstDayOfMonthIndex: function getFirstDayOfMonthIndex(month, year) {
var day = new Date();
day.setDate(1);
day.setMonth(month);
day.setFullYear(year);
var dayIndex = day.getDay() + this.sundayIndex;
return dayIndex >= 7 ? dayIndex - 7 : dayIndex;
},
getDaysCountInMonth: function getDaysCountInMonth(month, year) {
return 32 - this.daylightSavingAdjust(new Date(year, month, 32)).getDate();
},
getDaysCountInPrevMonth: function getDaysCountInPrevMonth(month, year) {
var prev = this.getPreviousMonthAndYear(month, year);
return this.getDaysCountInMonth(prev.month, prev.year);
},
getPreviousMonthAndYear: function getPreviousMonthAndYear(month, year) {
var m, y;
if (month === 0) {
m = 11;
y = year - 1;
} else {
m = month - 1;
y = year;
}
return {
month: m,
year: y
};
},
getNextMonthAndYear: function getNextMonthAndYear(month, year) {
var m, y;
if (month === 11) {
m = 0;
y = year + 1;
} else {
m = month + 1;
y = year;
}
return {
month: m,
year: y
};
},
daylightSavingAdjust: function daylightSavingAdjust(date) {
if (!date) {
return null;
}
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
return date;
},
isToday: function isToday(today, day, month, year) {
return today.getDate() === day && today.getMonth() === month && today.getFullYear() === year;
},
isSelectable: function isSelectable(day, month, year, otherMonth) {
var validMin = true;
var validMax = true;
var validDate = true;
var validDay = true;
if (otherMonth && !this.selectOtherMonths) {
return false;
}
if (this.minDate) {
if (this.minDate.getFullYear() > year) {
validMin = false;
} else if (this.minDate.getFullYear() === year) {
if (this.minDate.getMonth() > month) {
validMin = false;
} else if (this.minDate.getMonth() === month) {
if (this.minDate.getDate() > day) {
validMin = false;
}
}
}
}
if (this.maxDate) {
if (this.maxDate.getFullYear() < year) {
validMax = false;
} else if (this.maxDate.getFullYear() === year) {
if (this.maxDate.getMonth() < month) {
validMax = false;
} else if (this.maxDate.getMonth() === month) {
if (this.maxDate.getDate() < day) {
validMax = false;
}
}
}
}
if (this.disabledDates) {
validDate = !this.isDateDisabled(day, month, year);
}
if (this.disabledDays) {
validDay = !this.isDayDisabled(day, month, year);
}
return validMin && validMax && validDate && validDay;
},
onOverlayEnter: function onOverlayEnter(el) {
el.setAttribute(this.attributeSelector, '');
var styles = this.touchUI ? {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)'
} : !this.inline ? {
position: 'absolute',
top: '0',
left: '0'
} : undefined;
utils.DomHandler.addStyles(el, styles);
if (this.autoZIndex) {
if (this.touchUI) utils.ZIndexUtils.set('modal', el, this.baseZIndex || this.$primevue.config.zIndex.modal);else utils.ZIndexUtils.set('overlay', el, this.baseZIndex || this.$primevue.config.zIndex.overlay);
}
this.alignOverlay();
this.$emit('show');
},
onOverlayEnterComplete: function onOverlayEnterComplete() {
this.bindOutsideClickListener();
this.bindScrollListener();
this.bindResizeListener();
},
onOverlayAfterLeave: function onOverlayAfterLeave(el) {
if (this.autoZIndex) {
utils.ZIndexUtils.clear(el);
}
},
onOverlayLeave: function onOverlayLeave() {
this.currentView = this.view;
this.unbindOutsideClickListener();
this.unbindScrollListener();
this.unbindResizeListener();
this.hasOpened = false;
this.$emit('hide');
if (this.mask) {
this.disableModality();
}
this.overlay = null;
},
onPrevButtonClick: function onPrevButtonClick(event) {
if (this.showOtherMonths) {
this.navigationState = {
backward: true,
button: true
};
this.navBackward(event);
}
},
onNextButtonClick: function onNextButtonClick(event) {
if (this.showOtherMonths) {
this.navigationState = {
backward: false,
button: true
};
this.navForward(event);
}
},
navBackward: function navBackward(event) {
event.preventDefault();
if (!this.isEnabled()) {
return;
}
if (this.currentView === 'month') {
this.decrementYear();
this.$emit('year-change', {
month: this.currentMonth,
year: this.currentYear
});
} else if (this.currentView === 'year') {
this.decrementDecade();
} else {
if (event.shiftKey) {
this.decrementYear();
} else {
if (this.currentMonth === 0) {
this.currentMonth = 11;
this.decrementYear();
} else {
this.currentMonth--;
}
this.$emit('month-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
}
}
},
navForward: function navForward(event) {
event.preventDefault();
if (!this.isEnabled()) {
return;
}
if (this.currentView === 'month') {
this.incrementYear();
this.$emit('year-change', {
month: this.currentMonth,
year: this.currentYear
});
} else if (this.currentView === 'year') {
this.incrementDecade();
} else {
if (event.shiftKey) {
this.incrementYear();
} else {
if (this.currentMonth === 11) {
this.currentMonth = 0;
this.incrementYear();
} else {
this.currentMonth++;
}
this.$emit('month-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
}
}
},
decrementYear: function decrementYear() {
this.currentYear--;
},
decrementDecade: function decrementDecade() {
this.currentYear = this.currentYear - 10;
},
incrementYear: function incrementYear() {
this.currentYear++;
},
incrementDecade: function incrementDecade() {
this.currentYear = this.currentYear + 10;
},
switchToMonthView: function switchToMonthView(event) {
this.currentView = 'month';
setTimeout(this.updateFocus, 0);
event.preventDefault();
},
switchToYearView: function switchToYearView(event) {
this.currentView = 'year';
setTimeout(this.updateFocus, 0);
event.preventDefault();
},
isEnabled: function isEnabled() {
return !this.disabled && !this.readonly;
},
updateCurrentTimeMeta: function updateCurrentTimeMeta(date) {
var currentHour = date.getHours();
if (this.hourFormat === '12') {
this.pm = currentHour > 11;
if (currentHour >= 12) currentHour = currentHour == 12 ? 12 : currentHour - 12;else currentHour = currentHour == 0 ? 12 : currentHour;
}
this.currentHour = Math.floor(currentHour / this.stepHour) * this.stepHour;
this.currentMinute = Math.floor(date.getMinutes() / this.stepMinute) * this.stepMinute;
this.currentSecond = Math.floor(date.getSeconds() / this.stepSecond) * this.stepSecond;
},
bindOutsideClickListener: function bindOutsideClickListener() {
var _this3 = this;
if (!this.outsideClickListener) {
this.outsideClickListener = function (event) {
if (_this3.overlayVisible && _this3.isOutsideClicked(event)) {
_this3.overlayVisible = false;
}
};
document.addEventListener('mousedown', this.outsideClickListener);
}
},
unbindOutsideClickListener: function unbindOutsideClickListener() {
if (this.outsideClickListener) {
document.removeEventListener('mousedown', this.outsideClickListener);
this.outsideClickListener = null;
}
},
bindScrollListener: function bindScrollListener() {
var _this4 = this;
if (!this.scrollHandler) {
this.scrollHandler = new utils.ConnectedOverlayScrollHandler(this.$refs.container, function () {
if (_this4.overlayVisible) {
_this4.overlayVisible = false;
}
});
}
this.scrollHandler.bindScrollListener();
},
unbindScrollListener: function unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
},
bindResizeListener: function bindResizeListener() {
var _this5 = this;
if (!this.resizeListener) {
this.resizeListener = function () {
if (_this5.overlayVisible && !utils.DomHandler.isTouchDevice()) {
_this5.overlayVisible = false;
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener: function unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
bindMatchMediaListener: function bindMatchMediaListener() {
var _this6 = this;
if (!this.matchMediaListener) {
var query = matchMedia("(max-width: ".concat(this.breakpoint, ")"));
this.query = query;
this.queryMatches = query.matches;
this.matchMediaListener = function () {
_this6.queryMatches = query.matches;
_this6.mobileActive = false;
};
this.query.addEventListener('change', this.matchMediaListener);
}
},
unbindMatchMediaListener: function unbindMatchMediaListener() {
if (this.matchMediaListener) {
this.query.removeEventListener('change', this.matchMediaListener);
this.matchMediaListener = null;
}
},
isOutsideClicked: function isOutsideClicked(event) {
return !(this.$el.isSameNode(event.target) || this.isNavIconClicked(event) || this.$el.contains(event.target) || this.overlay && this.overlay.contains(event.target));
},
isNavIconClicked: function isNavIconClicked(event) {
return this.previousButton && (this.previousButton.isSameNode(event.target) || this.previousButton.contains(event.target)) || this.nextButton && (this.nextButton.isSameNode(event.target) || this.nextButton.contains(event.target));
},
alignOverlay: function alignOverlay() {
if (this.touchUI) {
this.enableModality();
} else if (this.overlay) {
if (this.appendTo === 'self' || this.inline) {
utils.DomHandler.relativePosition(this.overlay, this.$el);
} else {
if (this.view === 'date') {
this.overlay.style.width = utils.DomHandler.getOuterWidth(this.overlay) + 'px';
this.overlay.style.minWidth = utils.DomHandler.getOuterWidth(this.$el) + 'px';
} else {
this.overlay.style.width = utils.DomHandler.getOuterWidth(this.$el) + 'px';
}
utils.DomHandler.absolutePosition(this.overlay, this.$el);
}
}
},
onButtonClick: function onButtonClick() {
if (this.isEnabled()) {
if (!this.overlayVisible) {
this.input.focus();
this.overlayVisible = true;
} else {
this.overlayVisible = false;
}
}
},
isDateDisabled: function isDateDisabled(day, month, year) {
if (this.disabledDates) {
var _iterator2 = _createForOfIteratorHelper(this.disabledDates),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var disabledDate = _step2.value;
if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) {
return true;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
return false;
},
isDayDisabled: function isDayDisabled(day, month, year) {
if (this.disabledDays) {
var weekday = new Date(year, month, day);
var weekdayNumber = weekday.getDay();
return this.disabledDays.indexOf(weekdayNumber) !== -1;
}
return false;
},
onMonthDropdownChange: function onMonthDropdownChange(value) {
this.currentMonth = parseInt(value);
this.$emit('month-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
},
onYearDropdownChange: function onYearDropdownChange(value) {
this.currentYear = parseInt(value);
this.$emit('year-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
},
onDateSelect: function onDateSelect(event, dateMeta) {
var _this7 = this;
if (this.disabled || !dateMeta.selectable) {
return;
}
utils.DomHandler.find(this.overlay, 'table td span:not([data-p-disabled="true"])').forEach(function (cell) {
return cell.tabIndex = -1;
});
if (event) {
event.currentTarget.focus();
}
if (this.isMultipleSelection() && this.isSelected(dateMeta)) {
var newValue = this.modelValue.filter(function (date) {
return !_this7.isDateEquals(date, dateMeta);
});
this.updateModel(newValue);
} else {
if (this.shouldSelectDate(dateMeta)) {
if (dateMeta.otherMonth) {
this.currentMonth = dateMeta.month;
this.currentYear = dateMeta.year;
this.selectDate(dateMeta);
} else {
this.selectDate(dateMeta);
}
}
}
if (this.isSingleSelection() && (!this.showTime || this.hideOnDateTimeSelect)) {
setTimeout(function () {
if (_this7.input) {
_this7.input.focus();
}
_this7.overlayVisible = false;
}, 150);
}
},
selectDate: function selectDate(dateMeta) {
var _this8 = this;
var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
if (this.showTime) {
this.hourFormat === '12' && this.currentHour !== 12 && this.pm ? date.setHours(this.currentHour + 12) : date.setHours(this.currentHour);
date.setMinutes(this.currentMinute);
date.setSeconds(this.currentSecond);
}
if (this.minDate && this.minDate > date) {
date = this.minDate;
this.currentHour = date.getHours();
this.currentMinute = date.getMinutes();
this.currentSecond = date.getSeconds();
}
if (this.maxDate && this.maxDate < date) {
date = this.maxDate;
this.currentHour = date.getHours();
this.currentMinute = date.getMinutes();
this.currentSecond = date.getSeconds();
}
var modelVal = null;
if (this.isSingleSelection()) {
modelVal = date;
} else if (this.isMultipleSelection()) {
modelVal = this.modelValue ? [].concat(_toConsumableArray(this.modelValue), [date]) : [date];
} else if (this.isRangeSelection()) {
if (this.modelValue && this.modelValue.length) {
var startDate = this.modelValue[0];
var endDate = this.modelValue[1];
if (!endDate && date.getTime() >= startDate.getTime()) {
endDate = date;
} else {
startDate = date;
endDate = null;
}
modelVal = [startDate, endDate];
} else {
modelVal = [date, null];
}
}
if (modelVal !== null) {
this.updateModel(modelVal);
}
if (this.isRangeSelection() && this.hideOnRangeSelection && modelVal[1] !== null) {
setTimeout(function () {
_this8.overlayVisible = false;
}, 150);
}
this.$emit('date-select', date);
},
updateModel: function updateModel(value) {
this.$emit('update:modelValue', value);
},
shouldSelectDate: function shouldSelectDate() {
if (this.isMultipleSelection()) return this.maxDateCount != null ? this.maxDateCount > (this.modelValue ? this.modelValue.length : 0) : true;else return true;
},
isSingleSelection: function isSingleSelection() {
return this.selectionMode === 'single';
},
isRangeSelection: function isRangeSelection() {
return this.selectionMode === 'range';
},
isMultipleSelection: function isMultipleSelection() {
return this.selectionMode === 'multiple';
},
formatValue: function formatValue(value) {
if (typeof value === 'string') {
return value;
}
var formattedValue = '';
if (value) {
try {
if (this.isSingleSelection()) {
formattedValue = this.formatDateTime(value);
} else if (this.isMultipleSelection()) {
for (var i = 0; i < value.length; i++) {
var dateAsString = this.formatDateTime(value[i]);
formattedValue += dateAsString;
if (i !== value.length - 1) {
formattedValue += ', ';
}
}
} else if (this.isRangeSelection()) {
if (value && value.length) {
var startDate = value[0];
var endDate = value[1];
formattedValue = this.formatDateTime(startDate);
if (endDate) {
formattedValue += ' - ' + this.formatDateTime(endDate);
}
}
}
} catch (err) {
formattedValue = value;
}
}
return formattedValue;
},
formatDateTime: function formatDateTime(date) {
var formattedValue = null;
if (date) {
if (this.timeOnly) {
formattedValue = this.formatTime(date);
} else {
formattedValue = this.formatDate(date, this.datePattern);
if (this.showTime) {
formattedValue += ' ' + this.formatTime(date);
}
}
}
return formattedValue;
},
formatDate: function formatDate(date, format) {
if (!date) {
return '';
}
var iFormat;
var lookAhead = function lookAhead(match) {
var matches = iFormat + 1 < format.length && format.charAt(iFormat + 1) === match;
if (matches) {
iFormat++;
}
return matches;
},
formatNumber = function formatNumber(match, value, len) {
var num = '' + value;
if (lookAhead(match)) {
while (num.length < len) {
num = '0' + num;
}
}
return num;
},
formatName = function formatName(match, value, shortNames, longNames) {
return lookAhead(match) ? longNames[value] : shortNames[value];
};
var output = '';
var literal = false;
if (date) {
for (iFormat = 0; iFormat < format.length; iFormat++) {
if (literal) {
if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
literal = false;
} else {
output += format.charAt(iFormat);
}
} else {
switch (format.charAt(iFormat)) {
case 'd':
output += formatNumber('d', date.getDate(), 2);
break;
case 'D':
output += formatName('D', date.getDay(), this.$primevue.config.locale.dayNamesShort, this.$primevue.config.locale.dayNames);
break;
case 'o':
output += formatNumber('o', Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
break;
case 'm':
output += formatNumber('m', date.getMonth() + 1, 2);
break;
case 'M':
output += formatName('M', date.getMonth(), this.$primevue.config.locale.monthNamesShort, this.$primevue.config.locale.monthNames);
break;
case 'y':
output += lookAhead('y') ? date.getFullYear() : (date.getFullYear() % 100 < 10 ? '0' : '') + date.getFullYear() % 100;
break;
case '@':
output += date.getTime();
break;
case '!':
output += date.getTime() * 10000 + this.ticksTo1970;
break;
case "'":
if (lookAhead("'")) {
output += "'";
} else {
literal = true;
}
break;
default:
output += format.charAt(iFormat);
}
}
}
}
return output;
},
formatTime: function formatTime(date) {
if (!date) {
return '';
}
var output = '';
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (this.hourFormat === '12' && hours > 11 && hours !== 12) {
hours -= 12;
}
if (this.hourFormat === '12') {
output += hours === 0 ? 12 : hours < 10 ? '0' + hours : hours;
} else {
output += hours < 10 ? '0' + hours : hours;
}
output += ':';
output += minutes < 10 ? '0' + minutes : minutes;
if (this.showSeconds) {
output += ':';
output += seconds < 10 ? '0' + seconds : seconds;
}
if (this.hourFormat === '12') {
output += date.getHours() > 11 ? " ".concat(this.$primevue.config.locale.pm) : " ".concat(this.$primevue.config.locale.am);
}
return output;
},
onTodayButtonClick: function onTodayButtonClick(event) {
var date = new Date();
var dateMeta = {
day: date.getDate(),
month: date.getMonth(),
year: date.getFullYear(),
otherMonth: date.getMonth() !== this.currentMonth || date.getFullYear() !== this.currentYear,
today: true,
selectable: true
};
this.onDateSelect(null, dateMeta);
this.$emit('today-click', date);
event.preventDefault();
},
onClearButtonClick: function onClearButtonClick(event) {
this.updateModel(null);
this.overlayVisible = false;
this.$emit('clear-click', event);
event.preventDefault();
},
onTimePickerElementMouseDown: function onTimePickerElementMouseDown(event, type, direction) {
if (this.isEnabled()) {
this.repeat(event, null, type, direction);
event.preventDefault();
}
},
onTimePickerElementMouseUp: function onTimePickerElementMouseUp(event) {
if (this.isEnabled()) {
this.clearTimePickerTimer();
this.updateModelTime();
event.preventDefault();
}
},
onTimePickerElementMouseLeave: function onTimePickerElementMouseLeave() {
this.clearTimePickerTimer();
},
repeat: function repeat(event, interval, type, direction) {
var _this9 = this;
var i = interval || 500;
this.clearTimePickerTimer();
this.timePickerTimer = setTimeout(function () {
_this9.repeat(event, 100, type, direction);
}, i);
switch (type) {
case 0:
if (direction === 1) this.incrementHour(event);else this.decrementHour(event);
break;
case 1:
if (direction === 1) this.incrementMinute(event);else this.decrementMinute(event);
break;
case 2:
if (direction === 1) this.incrementSecond(event);else this.decrementSecond(event);
break;
}
},
convertTo24Hour: function convertTo24Hour(hours, pm) {
if (this.hourFormat == '12') {
if (hours === 12) {
return pm ? 12 : 0;
} else {
return pm ? hours + 12 : hours;
}
}
return hours;
},
validateTime: function validateTime(hour, minute, second, pm) {
var value = this.isComparable() ? this.modelValue : this.viewDate;
var convertedHour = this.convertTo24Hour(hour, pm);
if (this.isRangeSelection()) {
value = this.modelValue[1] || this.modelValue[0];
}
if (this.isMultipleSelection()) {
value = this.modelValue[this.modelValue.length - 1];
}
var valueDateString = value ? value.toDateString() : null;
if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
if (this.minDate.getHours() > convertedHour) {
return false;
}
if (this.minDate.getHours() === convertedHour) {
if (this.minDate.getMinutes() > minute) {
return false;
}
if (this.minDate.getMinutes() === minute) {
if (this.minDate.getSeconds() > second) {
return false;
}
}
}
}
if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
if (this.maxDate.getHours() < convertedHour) {
return false;
}
if (this.maxDate.getHours() === convertedHour) {
if (this.maxDate.getMinutes() < minute) {
return false;
}
if (this.maxDate.getMinutes() === minute) {
if (this.maxDate.getSeconds() < second) {
return false;
}
}
}
}
return true;
},
incrementHour: function incrementHour(event) {
var prevHour = this.currentHour;
var newHour = this.currentHour + Number(this.stepHour);
var newPM = this.pm;
if (this.hourFormat == '24') newHour = newHour >= 24 ? newHour - 24 : newHour;else if (this.hourFormat == '12') {
// Before the AM/PM break, now after
if (prevHour < 12 && newHour > 11) {
newPM = !this.pm;
}
newHour = newHour >= 13 ? newHour - 12 : newHour;
}
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
this.currentHour = newHour;
this.pm = newPM;
}
event.preventDefault();
},
decrementHour: function decrementHour(event) {
var newHour = this.currentHour - this.stepHour;
var newPM = this.pm;
if (this.hourFormat == '24') newHour = newHour < 0 ? 24 + newHour : newHour;else if (this.hourFormat == '12') {
// If we were at noon/midnight, then switch
if (this.currentHour === 12) {
newPM = !this.pm;
}
newHour = newHour <= 0 ? 12 + newHour : newHour;
}
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
this.currentHour = newHour;
this.pm = newPM;
}
event.preventDefault();
},
incrementMinute: function incrementMinute(event) {
var newMinute = this.currentMinute + Number(this.stepMinute);
if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
this.currentMinute = newMinute > 59 ? newMinute - 60 : newMinute;
}
event.preventDefault();
},
decrementMinute: function decrementMinute(event) {
var newMinute = this.currentMinute - this.stepMinute;
newMinute = newMinute < 0 ? 60 + newMinute : newMinute;
if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
this.currentMinute = newMinute;
}
event.preventDefault();
},
incrementSecond: function incrementSecond(event) {
var newSecond = this.currentSecond + Number(this.stepSecond);
if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
this.currentSecond = newSecond > 59 ? newSecond - 60 : newSecond;
}
event.preventDefault();
},
decrementSecond: function decrementSecond(event) {
var newSecond = this.currentSecond - this.stepSecond;
newSecond = newSecond < 0 ? 60 + newSecond : newSecond;
if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
this.currentSecond = newSecond;
}
event.preventDefault();
},
updateModelTime: function updateModelTime() {
var _this10 = this;
this.timePickerChange = true;
var value = this.isComparable() ? this.modelValue : this.viewDate;
if (this.isRangeSelection()) {
value = this.modelValue[1] || this.modelValue[0];
}
if (this.isMultipleSelection()) {
value = this.modelValue[this.modelValue.length - 1];
}
value = value ? new Date(value.getTime()) : new Date();
if (this.hourFormat == '12') {
if (this.currentHour === 12) value.setHours(this.pm ? 12 : 0);else value.setHours(this.pm ? this.currentHour + 12 : this.currentHour);
} else {
value.setHours(this.currentHour);
}
value.setMinutes(this.currentMinute);
value.setSeconds(this.currentSecond);
if (this.isRangeSelection()) {
if (this.modelValue[1]) value = [this.modelValue[0], value];else value = [value, null];
}
if (this.isMultipleSelection()) {
value = [].concat(_toConsumableArray(this.modelValue.slice(0, -1)), [value]);
}
this.updateModel(value);
this.$emit('date-select', value);
setTimeout(function () {
return _this10.timePickerChange = false;
}, 0);
},
toggleAMPM: function toggleAMPM(event) {
var validHour = this.validateTime(this.currentHour, this.currentMinute, this.currentSecond, !this.pm);
if (!validHour && (this.maxDate || this.minDate)) return;
this.pm = !this.pm;
this.updateModelTime();
event.preventDefault();
},
clearTimePickerTimer: function clearTimePickerTimer() {
if (this.timePickerTimer) {
clearInterval(this.timePickerTimer);
}
},
onMonthSelect: function onMonthSelect(event, index) {
if (this.view === 'month') {
this.onDateSelect(event, {
year: this.currentYear,
month: index,
day: 1,
selectable: true
});
} else {
var _index$index;
this.currentMonth = (_index$index = index === null || index === void 0 ? void 0 : index.index) !== null && _index$index !== void 0 ? _index$index : index;
console.log(this.currentMonth);
this.currentView = 'date';
this.$emit('month-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
}
setTimeout(this.updateFocus, 0);
},
onYearSelect: function onYearSelect(event, year) {
if (this.view === 'year') {
this.onDateSelect(event, {
year: year.value,
month: 0,
day: 1,
selectable: true
});
} else {
this.currentYear = year.value;
this.currentView = 'month';
this.$emit('year-change', {
month: this.currentMonth + 1,
year: this.currentYear
});
}
setTimeout(this.updateFocus, 0);
},
enableModality: function enableModality() {
var _this11 = this;
if (!this.mask) {
var styleClass = 'p-datepicker-mask p-datepicker-mask-scrollblocker p-component-overlay p-component-overlay-enter';
this.mask = utils.DomHandler.createElement('div', {
"class": !this.isUnstyled && styleClass,
'p-bind': this.ptm('datepickermask')
});
this.mask.style.zIndex = String(parseInt(this.overlay.style.zIndex, 10) - 1);
this.maskClickListener = function () {
_this11.overlayVisible = false;
};
this.mask.addEventListener('click', this.maskClickListener);
document.body.appendChild(this.mask);
utils.DomHandler.blockBodyScroll();
}
},
disableModality: function disableModality() {
var _this12 = this;
if (this.mask) {
if (this.isUnstyled) {
this.destroyMask();
} else {
utils.DomHandler.addClass(this.mask, 'p-component-overlay-leave');
this.mask.addEventListener('animationend', function () {
_this12.destroyMask();
});
}
}
},
destroyMask: function destroyMask() {
this.mask.removeEventListener('click', this.maskClickListener);
this.maskClickListener = null;
document.body.removeChild(this.mask);
this.mask = null;
var bodyChildren = document.body.children;
var hasBlockerMasks;
for (var i = 0; i <