UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

231 lines (229 loc) • 8.72 kB
/** * DevExtreme (cjs/__internal/ui/date_range_box/strategy/rangeCalendar.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _events_engine = _interopRequireDefault(require("../../../../common/core/events/core/events_engine")); var _extend = require("../../../../core/utils/extend"); var _type = require("../../../../core/utils/type"); var _date_boxStrategy = _interopRequireDefault(require("../../../ui/date_box/date_box.strategy.calendar")); var _date_range = require("../../../ui/date_range_box/date_range.utils"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } class RangeCalendarStrategy extends _date_boxStrategy.default { constructor(dateBox) { super(dateBox); this._dateSelectedCounter = 0; const multiselectDateBoxOptions = dateBox.option(); this.dateRangeBox = multiselectDateBoxOptions._dateRangeBoxInstance } popupConfig(popupConfig) { return (0, _extend.extend)(true, super.popupConfig(popupConfig), { position: { of: this.getDateRangeBox().$element() } }) } popupShowingHandler() { this.getWidget()._restoreViewsMinMaxOptions(); this._dateSelectedCounter = 0 } _getPopup() { return super._getPopup() || this.getDateRangeBox().getStartDateBox()._popup } supportedKeys() { const dateRangeBox = this.getDateRangeBox(); return Object.assign({}, super.supportedKeys(), { rightArrow: () => { if (dateRangeBox.option("opened")) { return true } return }, leftArrow: () => { if (dateRangeBox.option("opened")) { return true } return }, enter: e => { if (dateRangeBox.option("opened")) { const dateBoxValue = this.dateBox.getDateOption("value"); this.dateBox._valueChangeEventHandler(e); const newDateBoxValue = this.dateBox.getDateOption("value"); const dateBoxValueChanged = !(0, _date_range.isSameDates)(dateBoxValue, newDateBoxValue); if (dateBoxValueChanged) { dateRangeBox.getStartDateBox().getStrategy().getWidget().option("value", dateRangeBox.option("value")) } else { dateRangeBox.getStartDateBox().getStrategy().getWidget()._enterKeyHandler(e) } return false } return }, tab: e => { if (!dateRangeBox.option("opened")) { return } if (!this._getPopup().getFocusableElements().length) { if (!e.shiftKey && dateRangeBox._isEndDateActiveElement() || e.shiftKey && dateRangeBox._isStartDateActiveElement()) { dateRangeBox.close() } return } if (!e.shiftKey && dateRangeBox._isStartDateActiveElement() || e.shiftKey && dateRangeBox._isEndDateActiveElement()) { return } const $focusableElement = e.shiftKey ? dateRangeBox.getStartDateBox()._getLastPopupElement() : dateRangeBox.getStartDateBox()._getFirstPopupElement(); if ($focusableElement) { _events_engine.default.trigger($focusableElement, "focus"); $focusableElement.select() } e.preventDefault(); return } }) } _getWidgetOptions() { const { disabledDates: disabledDatesValue, value: value, multiView: multiView } = this.dateRangeBox.option(); const disabledDates = (0, _type.isFunction)(disabledDatesValue) ? this._injectComponent(disabledDatesValue) : disabledDatesValue ?? void 0; return (0, _extend.extend)(super._getWidgetOptions(), { disabledDates: disabledDates, value: value, selectionMode: "range", viewsCount: multiView ? 2 : 1, allowChangeSelectionOrder: true, currentSelection: this.getCurrentSelection() }) } _refreshActiveDescendant(e) { this.getDateRangeBox().setAria("activedescendant", e.actionValue) } _getInjectedComponent() { return this.getDateRangeBox() } getKeyboardListener() { const dateRangeBox = this.getDateRangeBox(); return dateRangeBox.getStartDateBox() ? dateRangeBox.getStartDateBox().getStrategy().getWidget() : this.getWidget() } getValue() { const { value: value } = this.getWidget().option(); return value } _updateValue() { const { value: value } = this.getDateRangeBox().option(); if (!this.getWidget()) { return } this._shouldPreventFocusChange = true; this.getWidget().option("value", value) } _isInstantlyMode() { const { applyValueMode: applyValueMode } = this.getDateRangeBox().option(); return "instantly" === applyValueMode } _getDateSelectedCounter(currentSelection, value) { if ("startDate" === currentSelection) { return 0 } if (!value[0]) { return -1 } return 1 } _valueChangedHandler(_ref) { let { value: value, previousValue: previousValue, event: event } = _ref; if ((0, _date_range.isSameDateArrays)(value, previousValue) && !this.getWidget()._valueSelected) { this._shouldPreventFocusChange = false; return } this.getWidget()._valueSelected = false; const dateRangeBox = this.getDateRangeBox(); if (this._isInstantlyMode()) { if (!dateRangeBox.option("disableOutOfRangeSelection")) { const currentSelection = this._getCalendarCurrentSelection(); this._dateSelectedCounter = this._getDateSelectedCounter(currentSelection, value); if ("startDate" !== currentSelection && value[0] && (0, _date_range.getDeserializedDate)(value[0]) > (0, _date_range.getDeserializedDate)(value[1])) { dateRangeBox.updateValue([value[0], null], event); return } } dateRangeBox.updateValue(value, event); this._dateSelectedCounter += 1; if (2 === this._dateSelectedCounter) { dateRangeBox.close(); return } } else if ("endDate" === this._getCalendarCurrentSelection()) { if (value[0] && (0, _date_range.getDeserializedDate)(value[0]) > (0, _date_range.getDeserializedDate)(value[1])) { return } } if (!this._shouldPreventFocusChange) { this._moveFocusToNextInput() } this._shouldPreventFocusChange = false } _moveFocusToNextInput() { const targetDateBox = "startDate" === this._getCalendarCurrentSelection() ? this.getDateRangeBox().getEndDateBox() : this.getDateRangeBox().getStartDateBox(); targetDateBox.focus(); _events_engine.default.trigger(targetDateBox.field(), "dxclick") } getCurrentSelection() { const { currentSelection: currentSelection } = this.getDateRangeBox().option(); return currentSelection } _getCalendarCurrentSelection() { const { currentSelection: currentSelection } = this.getWidget().option(); return currentSelection } _closeDropDownByEnter() { if ("startDate" === this._getCalendarCurrentSelection()) { return false } return true } _cellClickHandler() {} setActiveStartDateBox() { this.dateBox = this.getDateRangeBox().getStartDateBox() } setActiveEndDateBox() { this.dateBox = this.getDateRangeBox().getEndDateBox() } getDateRangeBox() { return this.dateRangeBox } getWidget() { return this._widget } } var _default = exports.default = RangeCalendarStrategy;