primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
1,234 lines (1,203 loc) • 123 kB
JavaScript
this.primereact = this.primereact || {};
this.primereact.calendar = (function (exports, React, PrimeReact, button, hooks, inputtext, overlayservice, ripple, utils, csstransition, portal) {
'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var PrimeReact__default = /*#__PURE__*/_interopDefaultLegacy(PrimeReact);
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _toPrimitive(input, hint) {
if (_typeof(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (_typeof(res) !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return _typeof(key) === "symbol" ? key : String(key);
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _arrayLikeToArray$1(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;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray$1(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen);
}
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 _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
if (null != _i) {
var _s,
_e,
_x,
_r,
_arr = [],
_n = !0,
_d = !1;
try {
if (_x = (_i = _i.call(arr)).next, 0 === i) {
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
} catch (err) {
_d = !0, _e = err;
} finally {
try {
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
} finally {
if (_d) throw _e;
}
}
return _arr;
}
}
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 _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
}
var CalendarBase = {
defaultProps: {
__TYPE: 'Calendar',
appendTo: null,
ariaLabelledBy: null,
autoZIndex: true,
baseZIndex: 0,
className: null,
clearButtonClassName: 'p-button-secondary',
dateFormat: null,
dateTemplate: null,
decadeTemplate: null,
disabled: false,
disabledDates: null,
disabledDays: null,
footerTemplate: null,
formatDateTime: null,
headerTemplate: null,
hideOnDateTimeSelect: false,
hourFormat: '24',
icon: 'pi pi-calendar',
iconPos: 'right',
id: null,
inline: false,
inputClassName: null,
inputId: null,
inputMode: 'none',
inputRef: null,
inputStyle: null,
keepInvalid: false,
locale: null,
mask: null,
maxDate: null,
maxDateCount: null,
minDate: null,
monthNavigator: false,
monthNavigatorTemplate: null,
name: null,
numberOfMonths: 1,
onBlur: null,
onChange: null,
onClearButtonClick: null,
onFocus: null,
onHide: null,
onInput: null,
onMonthChange: null,
onSelect: null,
onShow: null,
onTodayButtonClick: null,
onViewDateChange: null,
onVisibleChange: null,
panelClassName: null,
panelStyle: null,
parseDateTime: null,
placeholder: null,
readOnlyInput: false,
required: false,
selectOtherMonths: false,
selectionMode: 'single',
shortYearCutoff: '+10',
showButtonBar: false,
showIcon: false,
showMillisec: false,
showMinMaxRange: false,
showOnFocus: true,
showOtherMonths: true,
showSeconds: false,
showTime: false,
showWeek: false,
stepHour: 1,
stepMillisec: 1,
stepMinute: 1,
stepSecond: 1,
style: null,
tabIndex: null,
timeOnly: false,
todayButtonClassName: 'p-button-secondary',
tooltip: null,
tooltipOptions: null,
touchUI: false,
transitionOptions: null,
value: null,
view: 'date',
viewDate: null,
visible: false,
yearNavigator: false,
yearNavigatorTemplate: null,
yearRange: null,
children: undefined
},
getProps: function getProps(props) {
return utils.ObjectUtils.getMergedProps(props, CalendarBase.defaultProps);
},
getOtherProps: function getOtherProps(props) {
return utils.ObjectUtils.getDiffProps(props, CalendarBase.defaultProps);
}
};
var CalendarPanel = /*#__PURE__*/React__namespace.forwardRef(function (props, ref) {
var createElement = function createElement() {
return /*#__PURE__*/React__namespace.createElement(csstransition.CSSTransition, {
nodeRef: ref,
classNames: "p-connected-overlay",
"in": props["in"],
timeout: {
enter: 120,
exit: 100
},
options: props.transitionOptions,
unmountOnExit: true,
onEnter: props.onEnter,
onEntered: props.onEntered,
onExit: props.onExit,
onExited: props.onExited
}, /*#__PURE__*/React__namespace.createElement("div", {
ref: ref,
className: props.className,
style: props.style,
onClick: props.onClick,
onMouseUp: props.onMouseUp
}, props.children));
};
var element = createElement();
return props.inline ? element : /*#__PURE__*/React__namespace.createElement(portal.Portal, {
element: element,
appendTo: props.appendTo
});
});
CalendarPanel.displayName = 'CalendarPanel';
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 Calendar = /*#__PURE__*/React__namespace.memo( /*#__PURE__*/React__namespace.forwardRef(function (inProps, ref) {
var _classNames;
var props = CalendarBase.getProps(inProps);
var _React$useState = React__namespace.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
focusedState = _React$useState2[0],
setFocusedState = _React$useState2[1];
var _React$useState3 = React__namespace.useState(false),
_React$useState4 = _slicedToArray(_React$useState3, 2),
overlayVisibleState = _React$useState4[0],
setOverlayVisibleState = _React$useState4[1];
var _React$useState5 = React__namespace.useState(null),
_React$useState6 = _slicedToArray(_React$useState5, 2),
viewDateState = _React$useState6[0],
setViewDateState = _React$useState6[1];
var elementRef = React__namespace.useRef(null);
var overlayRef = React__namespace.useRef(null);
var inputRef = React__namespace.useRef(props.inputRef);
var navigation = React__namespace.useRef(null);
var ignoreFocusFunctionality = React__namespace.useRef(false);
var isKeydown = React__namespace.useRef(false);
var timePickerTimer = React__namespace.useRef(null);
var viewStateChanged = React__namespace.useRef(false);
var touchUIMask = React__namespace.useRef(null);
var overlayEventListener = React__namespace.useRef(null);
var touchUIMaskClickListener = React__namespace.useRef(null);
var isOverlayClicked = React__namespace.useRef(false);
var ignoreMaskChange = React__namespace.useRef(false);
var _React$useState7 = React__namespace.useState('date'),
_React$useState8 = _slicedToArray(_React$useState7, 2),
currentView = _React$useState8[0],
setCurrentView = _React$useState8[1];
var _React$useState9 = React__namespace.useState(null),
_React$useState10 = _slicedToArray(_React$useState9, 2),
currentMonth = _React$useState10[0],
setCurrentMonth = _React$useState10[1];
var _React$useState11 = React__namespace.useState(null),
_React$useState12 = _slicedToArray(_React$useState11, 2),
currentYear = _React$useState12[0],
setCurrentYear = _React$useState12[1];
var _React$useState13 = React__namespace.useState([]),
_React$useState14 = _slicedToArray(_React$useState13, 2),
yearOptions = _React$useState14[0],
setYearOptions = _React$useState14[1];
var previousValue = hooks.usePrevious(props.value);
var visible = props.inline || (props.onVisibleChange ? props.visible : overlayVisibleState);
var attributeSelector = utils.UniqueComponentId();
var _useOverlayListener = hooks.useOverlayListener({
target: elementRef,
overlay: overlayRef,
listener: function listener(event, _ref) {
var type = _ref.type,
valid = _ref.valid;
if (valid) {
type === 'outside' ? !isOverlayClicked.current && !isNavIconClicked(event.target) && hide('outside') : hide();
}
isOverlayClicked.current = false;
},
when: !(props.touchUI || props.inline) && visible
}),
_useOverlayListener2 = _slicedToArray(_useOverlayListener, 2),
bindOverlayListener = _useOverlayListener2[0],
unbindOverlayListener = _useOverlayListener2[1];
var getDateFormat = function getDateFormat() {
return props.dateFormat || PrimeReact.localeOption('dateFormat', props.locale);
};
var onInputFocus = function onInputFocus(event) {
if (ignoreFocusFunctionality.current) {
setFocusedState(true);
ignoreFocusFunctionality.current = false;
} else {
if (props.showOnFocus && !visible) {
show();
}
setFocusedState(true);
props.onFocus && props.onFocus(event);
}
};
var onInputBlur = function onInputBlur(event) {
setFocusedState(false);
!props.keepInvalid && updateInputfield(props.value);
props.onBlur && props.onBlur(event);
};
var onInputKeyDown = function onInputKeyDown(event) {
isKeydown.current = true;
switch (event.which) {
//escape
case 27:
{
hide();
break;
}
//tab
case 9:
{
visible && trapFocus(event);
props.touchUI && disableModality();
break;
}
}
};
var onUserInput = function onUserInput(event) {
// IE 11 Workaround for input placeholder
if (!isKeydown.current) {
return;
}
isKeydown.current = false;
updateValueOnInput(event, event.target.value);
props.onInput && props.onInput(event);
};
var updateValueOnInput = function updateValueOnInput(event, rawValue) {
try {
var value = parseValueFromString(rawValue);
if (isValidSelection(value)) {
updateModel(event, value);
updateViewDate(event, value.length ? value[0] : value);
}
} catch (err) {
//invalid date
var _value = props.keepInvalid ? rawValue : null;
updateModel(event, _value);
}
};
var reFocusInputField = function reFocusInputField() {
if (!props.inline && inputRef.current) {
ignoreFocusFunctionality.current = true;
utils.DomHandler.focus(inputRef.current);
}
};
var isValidSelection = function isValidSelection(value) {
var isValid = true;
if (isSingleSelection()) {
if (!(isSelectable(value.getDate(), value.getMonth(), value.getFullYear(), false) && isSelectableTime(value))) {
isValid = false;
}
} else if (value.every(function (v) {
return isSelectable(v.getDate(), v.getMonth(), v.getFullYear(), false) && isSelectableTime(v);
})) {
if (isRangeSelection()) {
isValid = value.length > 1 && value[1] > value[0] ? true : false;
}
}
return isValid;
};
var onButtonClick = function onButtonClick() {
visible ? hide() : show();
};
var onPrevButtonClick = function onPrevButtonClick(event) {
navigation.current = {
backward: true,
button: true
};
navBackward(event);
};
var onNextButtonClick = function onNextButtonClick(event) {
navigation.current = {
backward: false,
button: true
};
navForward(event);
};
var onContainerButtonKeydown = function onContainerButtonKeydown(event) {
switch (event.which) {
//tab
case 9:
trapFocus(event);
break;
//escape
case 27:
hide(null, reFocusInputField);
event.preventDefault();
break;
}
};
var trapFocus = function trapFocus(event) {
event.preventDefault();
var focusableElements = utils.DomHandler.getFocusableElements(overlayRef.current);
if (focusableElements && focusableElements.length > 0) {
if (!document.activeElement) {
focusableElements[0].focus();
} else {
var focusedIndex = focusableElements.indexOf(document.activeElement);
if (event.shiftKey) {
if (focusedIndex === -1 || focusedIndex === 0) focusableElements[focusableElements.length - 1].focus();else focusableElements[focusedIndex - 1].focus();
} else {
if (focusedIndex === -1 || focusedIndex === focusableElements.length - 1) focusableElements[0].focus();else focusableElements[focusedIndex + 1].focus();
}
}
}
};
var updateFocus = function updateFocus() {
if (navigation.current) {
if (navigation.current.button) {
initFocusableCell();
if (navigation.current.backward) utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-prev').focus();else utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-next').focus();
} else {
var cell;
if (navigation.current.backward) {
var cells = utils.DomHandler.find(overlayRef.current, '.p-datepicker-calendar td span:not(.p-disabled)');
cell = cells[cells.length - 1];
} else {
cell = utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-calendar td span:not(.p-disabled)');
}
if (cell) {
cell.tabIndex = '0';
cell.focus();
}
}
navigation.current = null;
} else {
initFocusableCell();
}
};
var initFocusableCell = function initFocusableCell() {
var cell;
if (props.view === 'month') {
var cells = utils.DomHandler.find(overlayRef.current, '.p-monthpicker .p-monthpicker-month');
var selectedCell = utils.DomHandler.findSingle(overlayRef.current, '.p-monthpicker .p-monthpicker-month.p-highlight');
cells.forEach(function (cell) {
return cell.tabIndex = -1;
});
cell = selectedCell || cells[0];
} else {
cell = utils.DomHandler.findSingle(overlayRef.current, 'span.p-highlight');
if (!cell) {
var todayCell = utils.DomHandler.findSingle(overlayRef.current, 'td.p-datepicker-today span:not(.p-disabled)');
cell = todayCell || utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-calendar td span:not(.p-disabled)');
}
}
if (cell) {
cell.tabIndex = '0';
}
};
var navBackward = function navBackward(event) {
if (props.disabled) {
event.preventDefault();
return;
}
var newViewDate = new Date(getViewDate().getTime());
newViewDate.setDate(1);
if (currentView === 'date') {
if (newViewDate.getMonth() === 0) {
newViewDate.setMonth(11);
newViewDate.setFullYear(decrementYear());
setCurrentMonth(11);
} else {
newViewDate.setMonth(newViewDate.getMonth() - 1);
setCurrentMonth(function (prevState) {
return prevState - 1;
});
}
} else if (currentView === 'month') {
var newYear = newViewDate.getFullYear() - 1;
if (props.yearNavigator) {
var minYear = parseInt(props.yearRange.split(':')[0], 10);
if (newYear < minYear) {
newYear = minYear;
}
}
newViewDate.setFullYear(newYear);
}
if (currentView === 'month') {
newViewDate.setFullYear(decrementYear());
} else if (currentView === 'year') {
newViewDate.setFullYear(decrementDecade());
}
updateViewDate(event, newViewDate);
event.preventDefault();
};
var navForward = function navForward(event) {
if (props.disabled) {
event.preventDefault();
return;
}
var newViewDate = new Date(getViewDate().getTime());
newViewDate.setDate(1);
if (currentView === 'date') {
if (newViewDate.getMonth() === 11) {
newViewDate.setMonth(0);
newViewDate.setFullYear(incrementYear());
setCurrentMonth(0);
} else {
newViewDate.setMonth(newViewDate.getMonth() + 1);
setCurrentMonth(function (prevState) {
return prevState + 1;
});
}
} else if (currentView === 'month') {
var newYear = newViewDate.getFullYear() + 1;
if (props.yearNavigator) {
var maxYear = parseInt(props.yearRange.split(':')[1], 10);
if (newYear > maxYear) {
newYear = maxYear;
}
}
newViewDate.setFullYear(newYear);
}
if (currentView === 'month') {
newViewDate.setFullYear(incrementYear());
} else if (currentView === 'year') {
newViewDate.setFullYear(incrementDecade());
}
updateViewDate(event, newViewDate);
event.preventDefault();
};
var populateYearOptions = function populateYearOptions(start, end) {
var _yearOptions = [];
for (var i = start; i <= end; i++) {
yearOptions.push(i);
}
setYearOptions(_yearOptions);
};
var decrementYear = function decrementYear() {
var _currentYear = currentYear - 1;
setCurrentYear(_currentYear);
if (props.yearNavigator && _currentYear < yearOptions[0]) {
var difference = yearOptions[yearOptions.length - 1] - yearOptions[0];
populateYearOptions(yearOptions[0] - difference, yearOptions[yearOptions.length - 1] - difference);
}
return _currentYear;
};
var incrementYear = function incrementYear() {
var _currentYear = currentYear + 1;
setCurrentYear(_currentYear);
if (props.yearNavigator && _currentYear.current > yearOptions[yearOptions.length - 1]) {
var difference = yearOptions[yearOptions.length - 1] - yearOptions[0];
populateYearOptions(yearOptions[0] + difference, yearOptions[yearOptions.length - 1] + difference);
}
return _currentYear;
};
var onMonthDropdownChange = function onMonthDropdownChange(event, value) {
var currentViewDate = getViewDate();
var newViewDate = new Date(currentViewDate.getTime());
newViewDate.setMonth(parseInt(value, 10));
updateViewDate(event, newViewDate);
};
var onYearDropdownChange = function onYearDropdownChange(event, value) {
var currentViewDate = getViewDate();
var newViewDate = new Date(currentViewDate.getTime());
newViewDate.setFullYear(parseInt(value, 10));
updateViewDate(event, newViewDate);
};
var onTodayButtonClick = function onTodayButtonClick(event) {
var today = new Date();
var dateMeta = {
day: today.getDate(),
month: today.getMonth(),
year: today.getFullYear(),
today: true,
selectable: true
};
var timeMeta = {
hours: today.getHours(),
minutes: today.getMinutes(),
seconds: today.getSeconds(),
milliseconds: today.getMilliseconds()
};
updateViewDate(event, today);
onDateSelect(event, dateMeta, timeMeta);
props.onTodayButtonClick && props.onTodayButtonClick(event);
};
var onClearButtonClick = function onClearButtonClick(event) {
updateModel(event, null);
updateInputfield(null);
hide();
props.onClearButtonClick && props.onClearButtonClick(event);
};
var onPanelClick = function onPanelClick(event) {
if (!props.inline) {
overlayservice.OverlayService.emit('overlay-click', {
originalEvent: event,
target: elementRef.current
});
}
};
var onPanelMouseUp = function onPanelMouseUp(event) {
onPanelClick(event);
};
var onTimePickerElementMouseDown = function onTimePickerElementMouseDown(event, type, direction) {
if (!props.disabled) {
repeat(event, null, type, direction);
event.preventDefault();
}
};
var onTimePickerElementMouseUp = function onTimePickerElementMouseUp() {
if (!props.disabled) {
clearTimePickerTimer();
}
};
var onTimePickerElementMouseLeave = function onTimePickerElementMouseLeave() {
if (!props.disabled) {
clearTimePickerTimer();
}
};
var repeat = function repeat(event, interval, type, direction) {
clearTimePickerTimer();
timePickerTimer.current = setTimeout(function () {
repeat(event, 100, type, direction);
}, interval || 500);
switch (type) {
case 0:
if (direction === 1) incrementHour(event);else decrementHour(event);
break;
case 1:
if (direction === 1) incrementMinute(event);else decrementMinute(event);
break;
case 2:
if (direction === 1) incrementSecond(event);else decrementSecond(event);
break;
case 3:
if (direction === 1) incrementMilliSecond(event);else decrementMilliSecond(event);
break;
}
};
var clearTimePickerTimer = function clearTimePickerTimer() {
if (timePickerTimer.current) {
clearTimeout(timePickerTimer.current);
}
};
var incrementHour = function incrementHour(event) {
var currentTime = getCurrentDateTime();
var currentHour = currentTime.getHours();
var newHour = currentHour + props.stepHour;
newHour = newHour >= 24 ? newHour - 24 : newHour;
if (validateHour(newHour, currentTime)) {
if (props.maxDate && props.maxDate.toDateString() === currentTime.toDateString() && props.maxDate.getHours() === newHour) {
if (props.maxDate.getMinutes() < currentTime.getMinutes()) {
if (props.maxDate.getSeconds() < currentTime.getSeconds()) {
if (props.maxDate.getMilliseconds() < currentTime.getMilliseconds()) {
updateTime(event, newHour, props.maxDate.getMinutes(), props.maxDate.getSeconds(), props.maxDate.getMilliseconds());
} else {
updateTime(event, newHour, props.maxDate.getMinutes(), props.maxDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, props.maxDate.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else if (props.maxDate.getMinutes() === currentTime.getMinutes()) {
if (props.maxDate.getSeconds() < currentTime.getSeconds()) {
if (props.maxDate.getMilliseconds() < currentTime.getMilliseconds()) {
updateTime(event, newHour, props.maxDate.getMinutes(), props.maxDate.getSeconds(), props.maxDate.getMilliseconds());
} else {
updateTime(event, newHour, props.maxDate.getMinutes(), props.maxDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, props.maxDate.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var decrementHour = function decrementHour(event) {
var currentTime = getCurrentDateTime();
var currentHour = currentTime.getHours();
var newHour = currentHour - props.stepHour;
newHour = newHour < 0 ? newHour + 24 : newHour;
if (validateHour(newHour, currentTime)) {
if (props.minDate && props.minDate.toDateString() === currentTime.toDateString() && props.minDate.getHours() === newHour) {
if (props.minDate.getMinutes() > currentTime.getMinutes()) {
if (props.minDate.getSeconds() > currentTime.getSeconds()) {
if (props.minDate.getMilliseconds() > currentTime.getMilliseconds()) {
updateTime(event, newHour, props.minDate.getMinutes(), props.minDate.getSeconds(), props.minDate.getMilliseconds());
} else {
updateTime(event, newHour, props.minDate.getMinutes(), props.minDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, props.minDate.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else if (props.minDate.getMinutes() === currentTime.getMinutes()) {
if (props.minDate.getSeconds() > currentTime.getSeconds()) {
if (props.minDate.getMilliseconds() > currentTime.getMilliseconds()) {
updateTime(event, newHour, props.minDate.getMinutes(), props.minDate.getSeconds(), props.minDate.getMilliseconds());
} else {
updateTime(event, newHour, props.minDate.getMinutes(), props.minDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, props.minDate.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var doStepMinute = function doStepMinute(currentMinute, step) {
if (props.stepMinute <= 1) {
return step ? currentMinute + step : currentMinute;
}
if (!step) {
step = props.stepMinute;
if (currentMinute % step === 0) {
return currentMinute;
}
}
return Math.floor((currentMinute + step) / step) * step;
};
var incrementMinute = function incrementMinute(event) {
var currentTime = getCurrentDateTime();
var currentMinute = currentTime.getMinutes();
var newMinute = doStepMinute(currentMinute, props.stepMinute);
newMinute = newMinute > 59 ? newMinute - 60 : newMinute;
if (validateMinute(newMinute, currentTime)) {
if (props.maxDate && props.maxDate.toDateString() === currentTime.toDateString() && props.maxDate.getMinutes() === newMinute) {
if (props.maxDate.getSeconds() < currentTime.getSeconds()) {
if (props.maxDate.getMilliseconds() < currentTime.getMilliseconds()) {
updateTime(event, currentTime.getHours(), newMinute, props.maxDate.getSeconds(), props.maxDate.getMilliseconds());
} else {
updateTime(event, currentTime.getHours(), newMinute, props.maxDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds(), currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var decrementMinute = function decrementMinute(event) {
var currentTime = getCurrentDateTime();
var currentMinute = currentTime.getMinutes();
var newMinute = doStepMinute(currentMinute, -props.stepMinute);
newMinute = newMinute < 0 ? newMinute + 60 : newMinute;
if (validateMinute(newMinute, currentTime)) {
if (props.minDate && props.minDate.toDateString() === currentTime.toDateString() && props.minDate.getMinutes() === newMinute) {
if (props.minDate.getSeconds() > currentTime.getSeconds()) {
if (props.minDate.getMilliseconds() > currentTime.getMilliseconds()) {
updateTime(event, currentTime.getHours(), newMinute, props.minDate.getSeconds(), props.minDate.getMilliseconds());
} else {
updateTime(event, currentTime.getHours(), newMinute, props.minDate.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds(), currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), newMinute, currentTime.getSeconds(), currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var incrementSecond = function incrementSecond(event) {
var currentTime = getCurrentDateTime();
var currentSecond = currentTime.getSeconds();
var newSecond = currentSecond + props.stepSecond;
newSecond = newSecond > 59 ? newSecond - 60 : newSecond;
if (validateSecond(newSecond, currentTime)) {
if (props.maxDate && props.maxDate.toDateString() === currentTime.toDateString() && props.maxDate.getSeconds() === newSecond) {
if (props.maxDate.getMilliseconds() < currentTime.getMilliseconds()) {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, props.maxDate.getMilliseconds());
} else {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var decrementSecond = function decrementSecond(event) {
var currentTime = getCurrentDateTime();
var currentSecond = currentTime.getSeconds();
var newSecond = currentSecond - props.stepSecond;
newSecond = newSecond < 0 ? newSecond + 60 : newSecond;
if (validateSecond(newSecond, currentTime)) {
if (props.minDate && props.minDate.toDateString() === currentTime.toDateString() && props.minDate.getSeconds() === newSecond) {
if (props.minDate.getMilliseconds() > currentTime.getMilliseconds()) {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, props.minDate.getMilliseconds());
} else {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, currentTime.getMilliseconds());
}
} else {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), newSecond, currentTime.getMilliseconds());
}
}
event.preventDefault();
};
var incrementMilliSecond = function incrementMilliSecond(event) {
var currentTime = getCurrentDateTime();
var currentMillisecond = currentTime.getMilliseconds();
var newMillisecond = currentMillisecond + props.stepMillisec;
newMillisecond = newMillisecond > 999 ? newMillisecond - 1000 : newMillisecond;
if (validateMillisecond(newMillisecond, currentTime)) {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), currentTime.getSeconds(), newMillisecond);
}
event.preventDefault();
};
var decrementMilliSecond = function decrementMilliSecond(event) {
var currentTime = getCurrentDateTime();
var currentMillisecond = currentTime.getMilliseconds();
var newMillisecond = currentMillisecond - props.stepMillisec;
newMillisecond = newMillisecond < 0 ? newMillisecond + 999 : newMillisecond;
if (validateMillisecond(newMillisecond, currentTime)) {
updateTime(event, currentTime.getHours(), currentTime.getMinutes(), currentTime.getSeconds(), newMillisecond);
}
event.preventDefault();
};
var toggleAmPm = function toggleAmPm(event) {
var currentTime = getCurrentDateTime();
var currentHour = currentTime.getHours();
var newHour = currentHour >= 12 ? currentHour - 12 : currentHour + 12;
if (validateHour(convertTo24Hour(newHour, !(currentHour > 11)), currentTime)) {
updateTime(event, newHour, currentTime.getMinutes(), currentTime.getSeconds(), currentTime.getMilliseconds());
}
event.preventDefault();
};
var getViewDate = function getViewDate(date) {
var propValue = props.value;
var viewDate = date || (props.onViewDateChange ? props.viewDate : viewDateState);
if (Array.isArray(propValue)) {
propValue = propValue[0];
}
return viewDate && isValidDate(viewDate) ? viewDate : propValue && isValidDate(propValue) ? propValue : new Date();
};
var getCurrentDateTime = function getCurrentDateTime() {
if (isSingleSelection()) {
return props.value && props.value instanceof Date ? props.value : getViewDate();
} else if (isMultipleSelection()) {
if (props.value && props.value.length) {
return props.value[props.value.length - 1];
}
} else if (isRangeSelection()) {
if (props.value && props.value.length) {
var startDate = props.value[0];
var endDate = props.value[1];
return endDate || startDate;
}
}
return new Date();
};
var isValidDate = function isValidDate(date) {
return date instanceof Date && !isNaN(date);
};
var convertTo24Hour = function convertTo24Hour(hour, pm) {
if (props.hourFormat == '12') {
return hour === 12 ? pm ? 12 : 0 : pm ? hour + 12 : hour;
}
return hour;
};
var validateHour = function validateHour(hour, value) {
var valid = true;
var valueDateString = value ? value.toDateString() : null;
if (props.minDate && valueDateString && props.minDate.toDateString() === valueDateString) {
if (props.minDate.getHours() > hour) {
valid = false;
}
}
if (props.maxDate && valueDateString && props.maxDate.toDateString() === valueDateString) {
if (props.maxDate.getHours() < hour) {
valid = false;
}
}
return valid;
};
var validateMinute = function validateMinute(minute, value) {
var valid = true;
var valueDateString = value ? value.toDateString() : null;
if (props.minDate && valueDateString && props.minDate.toDateString() === valueDateString) {
if (value.getHours() === props.minDate.getHours()) {
if (props.minDate.getMinutes() > minute) {
valid = false;
}
}
}
if (props.maxDate && valueDateString && props.maxDate.toDateString() === valueDateString) {
if (value.getHours() === props.maxDate.getHours()) {
if (props.maxDate.getMinutes() < minute) {
valid = false;
}
}
}
return valid;
};
var validateSecond = function validateSecond(second, value) {
var valid = true;
var valueDateString = value ? value.toDateString() : null;
if (props.minDate && valueDateString && props.minDate.toDateString() === valueDateString) {
if (value.getHours() === props.minDate.getHours() && value.getMinutes() === props.minDate.getMinutes()) {
if (props.minDate.getSeconds() > second) {
valid = false;
}
}
}
if (props.maxDate && valueDateString && props.maxDate.toDateString() === valueDateString) {
if (value.getHours() === props.maxDate.getHours() && value.getMinutes() === props.maxDate.getMinutes()) {
if (props.maxDate.getSeconds() < second) {
valid = false;
}
}
}
return valid;
};
var validateMillisecond = function validateMillisecond(millisecond, value) {
var valid = true;
var valueDateString = value ? value.toDateString() : null;
if (props.minDate && valueDateString && props.minDate.toDateString() === valueDateString) {
if (value.getHours() === props.minDate.getHours() && value.getSeconds() === props.minDate.getSeconds() && value.getMinutes() === props.minDate.getMinutes()) {
if (props.minDate.getMilliseconds() > millisecond) {
valid = false;
}
}
}
if (props.maxDate && valueDateString && props.maxDate.toDateString() === valueDateString) {
if (value.getHours() === props.maxDate.getHours() && value.getSeconds() === props.maxDate.getSeconds() && value.getMinutes() === props.maxDate.getMinutes()) {
if (props.maxDate.getMilliseconds() < millisecond) {
valid = false;
}
}
}
return valid;
};
var validateDate = function validateDate(value) {
if (props.yearNavigator) {
var viewYear = value.getFullYear();
var minRangeYear = props.yearRange ? parseInt(props.yearRange.split(':')[0], 10) : null;
var maxRangeYear = props.yearRange ? parseInt(props.yearRange.split(':')[1], 10) : null;
var minYear = props.minDate && minRangeYear != null ? Math.max(props.minDate.getFullYear(), minRangeYear) : props.minDate || minRangeYear;
var maxYear = props.maxDate && maxRangeYear != null ? Math.min(props.maxDate.getFullYear(), maxRangeYear) : props.maxDate || maxRangeYear;
if (minYear && minYear > viewYear) {
viewYear = minYear;
}
if (maxYear && maxYear < viewYear) {
viewYear = maxYear;
}
value.setFullYear(viewYear);
}
if (props.monthNavigator && props.view !== 'month') {
var viewMonth = value.getMonth();
var viewMonthWithMinMax = parseInt(isInMinYear(value) && Math.max(props.minDate.getMonth(), viewMonth).toString() || isInMaxYear(value) && Math.min(props.maxDate.getMonth(), viewMonth).toString() || viewMonth);
value.setMonth(viewMonthWithMinMax);
}
};
var updateTime = function updateTime(event, hour, minute, second, millisecond) {
var newDateTime = getCurrentDateTime();
newDateTime.setHours(hour);
newDateTime.setMinutes(minute);
newDateTime.setSeconds(second);
newDateTime.setMilliseconds(millisecond);
if (isMultipleSelection()) {
if (props.value && props.value.length) {
var value = _toConsumableArray(props.value);
value[value.length - 1] = newDateTime;
newDateTime = value;
} else {
newDateTime = [newDateTime];
}
} else if (isRangeSelection()) {
if (props.value && props.value.length) {
var startDate = props.value[0];
var endDate = props.value[1];
newDateTime = endDate ? [startDate, newDateTime] : [newDateTime, null];
} else {
newDateTime = [newDateTime, null];
}
}
updateModel(event, newDateTime);
if (props.onSelect) {
props.onSelect({
originalEvent: event,
value: newDateTime
});
}
updateInputfield(newDateTime);
};
var updateViewDate = function updateViewDate(event, value) {
validateDate(value);
if (props.onViewDateChange) {
props.onViewDateChange({
originalEvent: event,
value: value
});
} else {
viewStateChanged.current = true;
setViewDateState(value);
}
setCurrentMonth(value.getMonth());
setCurrentYear(value.getFullYear());
};
var setNavigationState = function setNavigationState(newViewDate) {
if (!props.showMinMaxRange || props.view !== 'date' || !overlayRef.current) {
return;
}
var navPrev = utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-prev');
var navNext = utils.DomHandler.findSingle(overlayRef.current, '.p-datepicker-next');
if (props.disabled) {
utils.DomHandler.addClass(navPrev, 'p-disabled');
utils.DomHandler.addClass(navNext, 'p-disabled');
return;
}
// previous (check first day of month at 00:00:00)
if (props.minDate) {
var firstDayOfMonth = new Date(newViewDate.getTime());
if (firstDayOfMonth.getMonth() === 0) {
firstDayOfMonth.setMonth(11, 1);
firstDayOfMonth.setFullYear(firstDayOfMonth.getFullYear() - 1);
} else {
firstDayOfMonth.setMonth(firstDayOfMonth.getMonth() - 1, 1);
}
firstDayOfMonth.setHours(0);
firstDayOfMonth.setMinutes(0);
firstDayOfMonth.setSeconds(0);
if (props.minDate > firstDayOfMonth) {
utils.DomHandler.addClass(navPrev, 'p-disabled');
} else {
utils.DomHandler.removeClass(navPrev, 'p-disabled');
}
}
// next (check last day of month at 11:59:59)
if (props.maxDate) {
var lastDayOfMonth = new Date(newViewDate.getTime());
if (lastDayOfMonth.getMonth() === 11) {
lastDayOfMonth.setMonth(0, 1);
lastDayOfMonth.setFullYear(lastDayOfMonth.getFullYear() + 1);
} else {
lastDayOfMonth.setMonth(lastDayOfMonth.getMonth() + 1, 1);
}
lastDayOfMonth.setHours(0);
lastDayOfMonth.setMinutes(0);
lastDayOfMonth.setSeconds(0);
lastDayOfMonth.setSeconds(-1);
if (props.maxDate < lastDayOfMonth) {
utils.DomHandler.addClass(navNext, 'p-disabled');
} else {
utils.DomHandler.removeClass(navNext, 'p-disabled');
}
}
};
var onDateCellKeydown = function onDateCellKeydown(event, date, groupIndex) {
var cellContent = event.currentTarget;
var cell = cellContent.parentElement;
switch (event.which) {
//down arrow
case 40:
{
cellContent.tabIndex = '-1';
var cellIndex = utils.DomHandler.index(cell);
var nextRow = cell.parentElement.nextElementSibling;
if (nextRow) {
var focusCell = nextRow.children[cellIndex].children[0];
if (utils.DomHandler.hasClass(focusCell, 'p-disabled')) {
navigation.current = {
backward: false
};
navForward(event);
} else {
nextRow.children[cellIndex].children[0].tabIndex = '0';
nextRow.children[cellIndex].children[0].focus();
}
} else {
navigation.current = {
backward: false
};
navForward(event);
}
event.preventDefault();
break;
}
//up arrow
case 38:
{
cellContent.tabIndex = '-1';
var _cellIndex = utils.DomHandler.index(cell);
var prevRow = cell.parentElement.previousElementSibling;
if (prevRow) {
var _focusCell = prevRow.children[_cellIndex].children[0];
if (utils.DomHandler.hasClass(_focusCell, 'p-disabled')) {
navigation.current = {
backward: true
};
navBackward(event);
} else {
_focusCell.tabIndex = '0';
_focusCell.focus();
}
} else {
navigation.current = {
backward: true
};
navBackward(event);
}
event.preventDefault();
break;
}
//left arrow
case 37:
{
cellContent.tabIndex = '-1';
var prevCell = cell.previousElementSibling;
if (prevCell) {
var _focusCell2 = prevCell.children[0];
if (utils.DomHandler.hasClass(_focusCell2, 'p-disabled')) {
navigateToMonth(true, groupIndex, event);
} else {
_focusCell2.tabIndex = '0';
_focusCell2.focus();
}
} else {
navigateToMonth(true, groupIndex, event);
}
event.preventDefault();
break;
}
//right arrow
case 39:
{
cellContent.tabIndex = '-1';
var nextCell = cell.nextElementSibling;
if (nextCell) {
var _focusCell3 = nextCell.children[0];
if (utils.DomHandler.hasClass(_focusCell3, 'p-disabled')) {
navigateToMonth(false, groupIndex, event);
} else {
_focusCell3.tabIndex = '0';
_focusCell3.focus();
}
} else {
navigateToMonth(false, groupIndex, event);
}
event.preventDefault();
break;
}
//enter
case 13:
{
onDateSelect(event, date);
event.preventDefault();
break;
}
//escape
case 27:
{
hide(null, reFocus