UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

116 lines (115 loc) 5.17 kB
/** * DevExtreme (cjs/__internal/scheduler/appointments_new/resizing/get_appointment_date_range.js) * Version: 26.1.4 * Build date: Fri Jul 24 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.getAppointmentDateRange = void 0; var _date = require("../../../core/utils/date"); var _m_date = require("../../../core/utils/m_date"); const toMs = _m_date.dateUtils.dateToMilliseconds; const getCellData = function(_ref, cellRowIndex, cellColumnIndex, isOccupiedAllDay) { let { viewDataProvider: viewDataProvider } = _ref; let isAllDay = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : false; let rtlEnabled = arguments.length > 5 && void 0 !== arguments[5] ? arguments[5] : false; const cellData = viewDataProvider.getCellData(cellRowIndex, cellColumnIndex, isOccupiedAllDay, rtlEnabled); if (!isAllDay) { cellData.endDate = _date.dateUtilsTs.addOffsets(cellData.startDate, toMs("day")) } return cellData }; const getAppointmentLeftCell = options => { const { cellHeight: cellHeight, cellWidth: cellWidth, relativeAppointmentRect: relativeAppointmentRect, appointment: appointment, rtlEnabled: rtlEnabled } = options; const cellRowIndex = Math.floor(relativeAppointmentRect.top / cellHeight); const cellColumnIndex = Math.round(relativeAppointmentRect.left / cellWidth); return getCellData(options, cellRowIndex, cellColumnIndex, appointment.isOccupiedAllDay, appointment.isAllDay, rtlEnabled) }; const getResizedDateRange = options => { const { rtlEnabled: rtlEnabled, handles: handles, appointment: appointment, relativeAppointmentRect: relativeAppointmentRect, cellWidth: cellWidth, cellCountInRow: cellCountInRow } = options; const leftCell = getAppointmentLeftCell(options); const cellsAmount = Math.round(relativeAppointmentRect.width / cellWidth); const isStartEdgeResized = rtlEnabled ? handles.right : handles.left; if (isStartEdgeResized) { const firstCell = rtlEnabled ? getCellData(options, Math.floor(leftCell.index / cellCountInRow), leftCell.index - cellsAmount + 1, appointment.isOccupiedAllDay, appointment.isAllDay) : leftCell; return { startDate: firstCell.startDate, endDate: firstCell.startDate > appointment.endDate ? firstCell.startDate : appointment.endDate } } const lastCellIndex = leftCell.index + cellsAmount - 1; const lastCell = rtlEnabled ? leftCell : getCellData(options, Math.floor(lastCellIndex / cellCountInRow), lastCellIndex % cellCountInRow, appointment.isOccupiedAllDay, appointment.isAllDay); return { startDate: lastCell.endDate < appointment.startDate ? lastCell.endDate : appointment.startDate, endDate: lastCell.endDate } }; const getRelativeAppointmentRect = (appointmentRect, parentAppointmentRect) => { const left = appointmentRect.left - parentAppointmentRect.left; const top = appointmentRect.top - parentAppointmentRect.top; const width = left < 0 ? appointmentRect.width + left : appointmentRect.width; const height = top < 0 ? appointmentRect.height + top : appointmentRect.height; return { left: Math.max(0, left), top: Math.max(0, top), width: width, height: height } }; const getAppointmentCellsInfo = options => { const { appointmentSettings: appointmentSettings, isVerticalGroupedWorkSpace: isVerticalGroupedWorkSpace, DOMMetaData: DOMMetaData } = options; const DOMMetaTable = appointmentSettings.allDay && !isVerticalGroupedWorkSpace ? [DOMMetaData.allDayPanelCellsMeta] : DOMMetaData.dateTableCellsMeta; const { height: cellHeight, width: cellWidth } = DOMMetaTable[appointmentSettings.rowIndex][appointmentSettings.columnIndex]; const cellCountInRow = DOMMetaTable[appointmentSettings.rowIndex].length; return { cellWidth: cellWidth, cellHeight: cellHeight, cellCountInRow: cellCountInRow } }; const getAppointmentDateRange = options => { const { appointmentSettings: appointmentSettings } = options; const relativeAppointmentRect = getRelativeAppointmentRect(options.appointmentRect, options.parentAppointmentRect); const cellInfo = getAppointmentCellsInfo(options); const appointment = { startDate: appointmentSettings.info.sourceAppointment.startDate, endDate: appointmentSettings.info.sourceAppointment.endDate, isAllDay: Boolean(appointmentSettings.info.appointment.allDay), isOccupiedAllDay: Boolean(appointmentSettings.allDay) }; const extendedOptions = Object.assign({}, options, cellInfo, { appointment: appointment, relativeAppointmentRect: relativeAppointmentRect }); return getResizedDateRange(extendedOptions) }; exports.getAppointmentDateRange = getAppointmentDateRange;