Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TimeZoneCalculator } from '../../r1/timezone_calculator';
import type { ViewDataProviderType } from '../../types';
import type { DOMMetaData, ViewDataProviderType } from '../../types';
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';
import type { AppointmentItemViewModel } from '../../view_model/types';

Expand All @@ -21,10 +21,7 @@ export interface GetAppointmentDateRangeOptions {
timeZoneCalculator: TimeZoneCalculator;
dataAccessors: AppointmentDataAccessor;
rtlEnabled?: boolean;
DOMMetaData: {
allDayPanelCellsMeta: Rect[];
dateTableCellsMeta: Rect[][];
};
DOMMetaData: DOMMetaData;
viewOffset: number;
}

Expand Down
17 changes: 17 additions & 0 deletions packages/devextreme/js/__internal/scheduler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ export interface ViewDataMap {
allDayPanelMap: CellInfo[];
}

export interface GroupedDataMap {
dateTableGroupedMap: CellInfo[][][];
allDayPanelGroupedMap: CellInfo[][];
}

export interface CellRect {
top: number;
left: number;
width: number;
height: number;
}

export interface DOMMetaData {
dateTableCellsMeta: CellRect[][];
allDayPanelCellsMeta: CellRect[];
}

export interface DateHeaderCellData extends ViewCellData {
colSpan: number;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Orientation } from '@js/common';
import type Scheduler from '@ts/scheduler/m_scheduler';
import type { DOMMetaData } from '@ts/scheduler/types';

import type { PanelName } from '../../types';
import type { CollectorCSS, RealSize } from '../steps/add_geometry/types';
Expand All @@ -22,10 +23,7 @@ export const getPanelCollectorOptions = (schedulerStore: Scheduler, {
DOMMetaData,
panelName,
}: {
DOMMetaData: {
dateTableCellsMeta: RealSize[][];
allDayPanelCellsMeta: RealSize[];
};
DOMMetaData: DOMMetaData;
alwaysReserveSpaceForCollector: boolean;
isTimelineView: boolean;
viewOrientation: Orientation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,73 @@
import { isDateAndTimeView } from '@ts/scheduler/r1/utils/index';
import type { ViewCellData, ViewType } from '@ts/scheduler/types';

interface GridPosition {
rowIndex: number;
columnIndex: number;
}

interface EdgeIndices {
firstColumnIndex: number;
lastColumnIndex: number;
firstRowIndex: number;
lastRowIndex: number;
}

interface ArrowClickOptions {
key: 'up' | 'down' | 'left' | 'right';
focusedCellPosition?: GridPosition;
focusedCellData: ViewCellData;
edgeIndices: EdgeIndices;
getCellDataByPosition: (rowIndex: number, columnIndex: number, isAllDay: boolean) => ViewCellData;
isAllDayPanelCell: boolean;
isRTL: boolean;
isGroupedByDate: boolean;
groupCount: number;
isMultiSelection: boolean;
isMultiSelectionAllowed: boolean;
viewType: ViewType;
}

interface NextColumnPositionOptions extends ArrowClickOptions {
direction: 'next' | 'prev';
focusedCellPosition: GridPosition;
}

interface ProcessEdgeCellOptions {
nextColumnIndex: number;
rowIndex: number;
columnIndex: number;
firstColumnIndex: number;
lastColumnIndex: number;
firstRowIndex: number;
lastRowIndex: number;
step: number;
}

interface MoveToCellOptions {
isMultiSelection: boolean;
isMultiSelectionAllowed: boolean;
focusedCellData: ViewCellData;
currentCellData: ViewCellData;
isVirtualCell?: boolean;
}

export class CellsSelectionController {
handleArrowClick(options) {
handleArrowClick(options: ArrowClickOptions): ViewCellData {
const {
key,
focusedCellPosition,
edgeIndices,
getCellDataByPosition,
isAllDayPanelCell,
focusedCellData,
} = options;

let nextCellIndices;
if (!focusedCellPosition) {
return focusedCellData;
}

let nextCellIndices: GridPosition = focusedCellPosition;

switch (key) {
case 'down':
Expand All @@ -22,12 +79,14 @@ export class CellsSelectionController {
case 'left':
nextCellIndices = this.getCellFromNextColumnPosition({
...options,
focusedCellPosition,
direction: 'prev',
});
break;
case 'right':
nextCellIndices = this.getCellFromNextColumnPosition({
...options,
focusedCellPosition,
direction: 'next',
});
break;
Expand All @@ -47,7 +106,11 @@ export class CellsSelectionController {
});
}

getCellFromNextRowPosition(focusedCellPosition, direction, edgeIndices) {
getCellFromNextRowPosition(
focusedCellPosition: GridPosition,
direction: 'next' | 'prev',
edgeIndices: EdgeIndices,
): GridPosition {
const {
columnIndex,
rowIndex,
Expand All @@ -66,7 +129,7 @@ export class CellsSelectionController {
};
}

getCellFromNextColumnPosition(options) {
getCellFromNextColumnPosition(options: NextColumnPositionOptions): GridPosition {
const {
focusedCellPosition,
direction,
Expand Down Expand Up @@ -115,7 +178,7 @@ export class CellsSelectionController {
});
}

private processEdgeCell(options) {
private processEdgeCell(options: ProcessEdgeCellOptions): GridPosition {
const {
nextColumnIndex,
rowIndex,
Expand All @@ -133,7 +196,7 @@ export class CellsSelectionController {
const isRightEdgeCell = nextColumnIndex > lastColumnIndex;

if (isLeftEdgeCell) {
const columnIndexInNextRow = lastColumnIndex - (step - columnIndex % step - 1);
const columnIndexInNextRow = lastColumnIndex - (step - (columnIndex % step) - 1);
const nextRowIndex = rowIndex - 1;
const isValidRowIndex = nextRowIndex >= firstRowIndex;

Expand All @@ -142,7 +205,7 @@ export class CellsSelectionController {
}

if (isRightEdgeCell) {
const columnIndexInNextRow = firstColumnIndex + columnIndex % step;
const columnIndexInNextRow = firstColumnIndex + (columnIndex % step);
const nextRowIndex = rowIndex + 1;
const isValidRowIndex = nextRowIndex <= lastRowIndex;

Expand All @@ -156,34 +219,45 @@ export class CellsSelectionController {
};
}

moveToCell(options) {
moveToCell(options: MoveToCellOptions): ViewCellData {
const {
isMultiSelection,
isMultiSelectionAllowed,
focusedCellData,
currentCellData,
isVirtualCell,
} = options;

const isValidMultiSelection = isMultiSelection && isMultiSelectionAllowed;

const nextFocusedCellData = isValidMultiSelection
? this.getNextCellData(currentCellData, focusedCellData)
? this.getNextCellData(currentCellData, focusedCellData, isVirtualCell)
: currentCellData;

return nextFocusedCellData;
}

private getNextCellData(nextFocusedCellData, focusedCellData, isVirtualCell?: any) {
private getNextCellData(
nextFocusedCellData: ViewCellData,
focusedCellData: ViewCellData,
isVirtualCell?: boolean,
): ViewCellData {
if (isVirtualCell) {
return focusedCellData;
}

const isValidNextFocusedCell = this.isValidNextFocusedCell(nextFocusedCellData, focusedCellData);
const isValidNextFocusedCell = this.isValidNextFocusedCell(
nextFocusedCellData,
focusedCellData,
);

return isValidNextFocusedCell ? nextFocusedCellData : focusedCellData;
}

private isValidNextFocusedCell(nextFocusedCellData, focusedCellData) {
private isValidNextFocusedCell(
nextFocusedCellData: ViewCellData,
focusedCellData: ViewCellData | null | undefined,
): boolean {
if (!focusedCellData) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import type { CellPositionData, ViewCellData } from '@ts/scheduler/types';

import type { CellPosition } from './view_model/m_types';
import type ViewDataProvider from './view_model/m_view_data_provider';

export default class CellsSelectionState {
private focusedCell: any = null;
private focusedCell: ViewCellData | null = null;

private selectedCells: any = null;
private selectedCells: ViewCellData[] | null = null;

private firstSelectedCell: any = null;
private firstSelectedCell: ViewCellData | null = null;

private prevFocusedCell: any = null;
private prevFocusedCell: ViewCellData | null = null;

private prevFirstSelectedCell: any;
private prevFirstSelectedCell: ViewCellData | null | undefined;

private prevSelectedCells: any = null;
private prevSelectedCells: ViewCellData[] | null = null;

constructor(public viewDataProvider: ViewDataProvider) {}

getFocusedCell() {
getFocusedCell(): {
coordinates: CellPositionData | undefined,
cellData: ViewCellData,
} | undefined {
const { focusedCell } = this;

if (!focusedCell) {
Expand All @@ -31,14 +37,16 @@ export default class CellsSelectionState {
return { coordinates: cellPosition, cellData: focusedCell };
}

setFocusedCell(rowIndex, columnIndex, isAllDay) {
setFocusedCell(rowIndex: number, columnIndex: number, isAllDay: boolean): void {
if (rowIndex >= 0) {
const cell = this.viewDataProvider.getCellData(rowIndex, columnIndex, isAllDay);
this.focusedCell = cell;
this.focusedCell = this.viewDataProvider.getCellData(rowIndex, columnIndex, isAllDay);
}
}

setSelectedCells(lastCellCoordinates, firstCellCoordinates: any = undefined) {
setSelectedCells(
lastCellCoordinates: CellPosition,
firstCellCoordinates?: CellPosition,
): void {
const { viewDataProvider } = this;
const {
rowIndex: lastRowIndex, columnIndex: lastColumnIndex, allDay: isLastCellAllDay,
Expand All @@ -48,57 +56,65 @@ export default class CellsSelectionState {
return;
}

const lastCell = viewDataProvider.getCellData(
lastRowIndex,
lastColumnIndex,
isLastCellAllDay,
);

const firstCell = firstCellCoordinates
? viewDataProvider.getCellData(
firstCellCoordinates.rowIndex,
firstCellCoordinates.columnIndex,
firstCellCoordinates.allDay,
)
: this.firstSelectedCell;
const lastCell = viewDataProvider.getCellData(lastRowIndex, lastColumnIndex, isLastCellAllDay);
: (this.firstSelectedCell ?? lastCell);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fallback for firstSelectedCell, because it can be undefined


this.firstSelectedCell = firstCell;

this.selectedCells = this.viewDataProvider.getCellsBetween(firstCell, lastCell);
this.selectedCells = this.viewDataProvider.getCellsBetween(
firstCell,
lastCell,
);
}

setSelectedCellsByData(selectedCellsData) {
setSelectedCellsByData(selectedCellsData: ViewCellData[]): void {
this.selectedCells = selectedCellsData;
}

getSelectedCells() {
getSelectedCells(): ViewCellData[] | null {
return this.selectedCells;
}

releaseSelectedAndFocusedCells() {
releaseSelectedAndFocusedCells(): void {
this.releaseSelectedCells();
this.releaseFocusedCell();
}

releaseSelectedCells() {
releaseSelectedCells(): void {
this.prevSelectedCells = this.selectedCells;
this.prevFirstSelectedCell = this.firstSelectedCell;

this.selectedCells = null;
this.firstSelectedCell = null;
}

releaseFocusedCell() {
releaseFocusedCell(): void {
this.prevFocusedCell = this.focusedCell;
this.focusedCell = null;
}

restoreSelectedAndFocusedCells() {
this.selectedCells = this.selectedCells || this.prevSelectedCells;
this.focusedCell = this.focusedCell || this.prevFocusedCell;
this.firstSelectedCell = this.firstSelectedCell || this.prevFirstSelectedCell;
restoreSelectedAndFocusedCells(): void {
this.selectedCells = this.selectedCells ?? this.prevSelectedCells;
this.focusedCell = this.focusedCell ?? this.prevFocusedCell;
this.firstSelectedCell = this.firstSelectedCell ?? this.prevFirstSelectedCell ?? null;

this.prevSelectedCells = null;
this.prevFirstSelectedCell = null;
this.prevFocusedCell = null;
}

clearSelectedAndFocusedCells() {
clearSelectedAndFocusedCells(): void {
this.prevSelectedCells = null;
this.selectedCells = null;

Expand Down
Loading
Loading