UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

115 lines (113 loc) 4.89 kB
/** * DevExtreme (cjs/__internal/scheduler/appointments_new/appointments.focus_controller.js) * Version: 25.2.7 * Build date: Tue May 05 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.AppointmentsFocusController = void 0; var _renderer = _interopRequireDefault(require("../../../core/renderer")); var _m_short = require("../../events/m_short"); var _appointment_groups_utils = require("../utils/resource_manager/appointment_groups_utils"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } class AppointmentsFocusController { get sortedAppointments() { return this.appointments.option().getSortedAppointments() } get isVirtualScrolling() { return this.appointments.option().isVirtualScrolling() } get tabIndex() { return this.appointments.option().tabIndex } constructor(appointments) { this.appointments = appointments; this.focusableSortedIndex = 0; this.needRestoreFocusIndex = -1 } onViewItemClick(viewItem) { this.focusViewItem(viewItem) } onViewItemFocusIn() {} onViewItemFocusOut(e) { const focusEvent = e.originalEvent; const $relatedTarget = (0, _renderer.default)(focusEvent.relatedTarget); const { $commonContainer: $commonContainer, $allDayContainer: $allDayContainer } = this.appointments; const isFocusOutside = 0 === $relatedTarget.length || 0 === $relatedTarget.closest($commonContainer).length && 0 === (null === $relatedTarget || void 0 === $relatedTarget ? void 0 : $relatedTarget.closest($allDayContainer ?? (0, _renderer.default)()).length); if (isFocusOutside) { this.resetTabIndex(0) } } onViewItemKeyDown(viewItem, e) { if ("Tab" === e.key) { this.handleTabKeyDown(e, viewItem.option().sortedIndex) } } resetTabIndex(newFocusableIndex) { var _this$appointments$ge2; if (this.needRestoreFocusIndex >= 0) { const viewItem = this.appointments.getViewItemBySortedIndex(this.needRestoreFocusIndex); null === viewItem || void 0 === viewItem || viewItem.setTabIndex(this.tabIndex); _m_short.focus.trigger(null === viewItem || void 0 === viewItem ? void 0 : viewItem.$element()); this.focusableSortedIndex = this.needRestoreFocusIndex; this.needRestoreFocusIndex = -1; return } if (void 0 !== newFocusableIndex) { var _this$appointments$ge; null === (_this$appointments$ge = this.appointments.getViewItemBySortedIndex(this.focusableSortedIndex)) || void 0 === _this$appointments$ge || _this$appointments$ge.setTabIndex(-1); this.focusableSortedIndex = newFocusableIndex } null === (_this$appointments$ge2 = this.appointments.getViewItemBySortedIndex(this.focusableSortedIndex)) || void 0 === _this$appointments$ge2 || _this$appointments$ge2.setTabIndex(this.tabIndex) } handleTabKeyDown(e, sortedIndex) { const nextIndex = sortedIndex + (e.shift ? -1 : 1); const nextItemData = this.sortedAppointments[nextIndex]; if (!nextItemData) { return } e.originalEvent.preventDefault(); this.focusByItemData(nextItemData) } focusByItemData(itemData) { if (this.isVirtualScrolling) { this.scrollToItem(itemData) } const viewItem = this.appointments.getViewItemBySortedIndex(itemData.sortedIndex); if (viewItem) { this.focusViewItem(viewItem) } else if (this.isVirtualScrolling) { this.needRestoreFocusIndex = itemData.sortedIndex } } focusViewItem(viewItem) { this.resetTabIndex(viewItem.option().sortedIndex); _m_short.focus.trigger(null === viewItem || void 0 === viewItem ? void 0 : viewItem.$element()) } scrollToItem(itemData) { const { getStartViewDate: getStartViewDate, getResourceManager: getResourceManager, scrollTo: scrollTo } = this.appointments.option(); const date = new Date(Math.max(getStartViewDate().getTime(), itemData.source.startDate)); const group = (0, _appointment_groups_utils.getRawAppointmentGroupValues)(itemData.itemData, getResourceManager().resources); scrollTo(date, { group: group, allDay: itemData.allDay }) } } exports.AppointmentsFocusController = AppointmentsFocusController;