Skip to content

Commit

Permalink
fix: remove unused CellRange interface, use core SlickRange, fix #927 (
Browse files Browse the repository at this point in the history
…#928)

- fixes #927
  • Loading branch information
ghiscoding authored Nov 24, 2023
1 parent 15d53f5 commit 7675dc5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 52 deletions.
19 changes: 0 additions & 19 deletions src/models/cellRange.interface.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
// import type { SlickCellRangeDecorator } from '../plugins/slick.cellrangedecorator';

import type { SlickCellRangeDecorator } from '../plugins/slick.cellrangedecorator';

export interface CellRange {
/** Selection start from which cell? */
fromCell: number;

/** Selection start from which row? */
fromRow: number;

/** Selection goes to which cell? */
toCell: number;

/** Selection goes to which row? */
toRow: number;
}

export interface CellRangeDecoratorOption {
selectionCssClass: string;
selectionCss: CSSStyleDeclaration;
Expand All @@ -41,6 +25,3 @@ export interface CellRangeSelectorOption {
/** styling (for example blue background on cell) */
selectionCss: CSSStyleDeclaration;
}

export type CSSStyleDeclarationReadonly = 'length' | 'parentRule' | 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty';
export type CSSStyleDeclarationWritable = keyof Omit<CSSStyleDeclaration, CSSStyleDeclarationReadonly>;
2 changes: 2 additions & 0 deletions src/models/cssDeclaration.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type CSSStyleDeclarationReadonly = 'length' | 'parentRule' | 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty';
export type CSSStyleDeclarationWritable = keyof Omit<CSSStyleDeclaration, CSSStyleDeclarationReadonly>;
10 changes: 5 additions & 5 deletions src/models/excelCopyBufferOption.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CellRange, Column, FormatterResultWithHtml, FormatterResultWithText } from './index';
import type { SlickEventData } from '../slick.core';
import type { Column, FormatterResultWithHtml, FormatterResultWithText } from './index';
import type { SlickEventData, SlickRange } from '../slick.core';

export interface ExcelCopyBufferOption<T = any> {
/** defaults to 2000(ms), delay in ms to wait before clearing the selection after a paste action */
Expand Down Expand Up @@ -49,11 +49,11 @@ export interface ExcelCopyBufferOption<T = any> {
// ------------

/** Fired when a copy cell is triggered */
onCopyCells?: (e: SlickEventData, args: { ranges: CellRange[] }) => void;
onCopyCells?: (e: SlickEventData, args: { ranges: SlickRange[] }) => void;

/** Fired when the command to copy the cells is cancelled */
onCopyCancelled?: (e: SlickEventData, args: { ranges: CellRange[] }) => void;
onCopyCancelled?: (e: SlickEventData, args: { ranges: SlickRange[] }) => void;

/** Fired when the user paste cells to the grid */
onPasteCells?: (e: SlickEventData, args: { ranges: CellRange[] }) => void;
onPasteCells?: (e: SlickEventData, args: { ranges: SlickRange[] }) => void;
}
7 changes: 4 additions & 3 deletions src/models/externalCopyClipCommand.interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Column, ExcelCopyBufferOption } from './index';
import type { SlickCellExternalCopyManager } from '../plugins/slick.cellexternalcopymanager';
import type { CellRange, Column, ExcelCopyBufferOption } from './index';
import type { SlickRange } from '../slick.core';

export interface ExternalCopyClipCommand {
activeCell: number;
activeRow: number;
cellExternalCopyManager: SlickCellExternalCopyManager;
clippedRange: CellRange[];
clippedRange: SlickRange[];
destH: number;
destW: number;
h: number;
Expand All @@ -18,7 +19,7 @@ export interface ExternalCopyClipCommand {
_options: ExcelCopyBufferOption;

execute: () => void;
markCopySelection: (ranges: CellRange[]) => void;
markCopySelection: (ranges: SlickRange[]) => void;
setDataItemValueForColumn: (item: any, columnDef: Column, value: any) => any | void;
undo: () => void;
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './columnSort.interface';
export * from './compositeEditorOption.interface';
export * from './contextMenuOption.interface';
export * from './core.interface';
export * from './cssDeclaration.interface';
export * from './customTooltipOption.interface';
export * from './dataViewEvents.interface';
export * from './domEvent.interface';
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/slick.cellexternalcopymanager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CellRange, Column, CssStyleHash, ExcelCopyBufferOption, ExternalCopyClipCommand, SlickPlugin } from '../models/index';
import type { Column, CssStyleHash, ExcelCopyBufferOption, ExternalCopyClipCommand, SlickPlugin } from '../models/index';
import type { SlickGrid } from '../slick.grid';
import { SlickEvent as SlickEvent_, SlickRange as SlickRange_, Utils as Utils_ } from '../slick.core';

Expand Down Expand Up @@ -36,15 +36,15 @@ export class SlickCellExternalCopyManager implements SlickPlugin {
// --
// public API
pluginName = 'CellExternalCopyManager' as const;
onCopyCells = new SlickEvent<{ ranges: CellRange[]; }>();
onCopyCancelled = new SlickEvent<{ ranges: CellRange[]; }>();
onPasteCells = new SlickEvent<{ ranges: CellRange[]; }>();
onCopyCells = new SlickEvent<{ ranges: SlickRange_[]; }>();
onCopyCancelled = new SlickEvent<{ ranges: SlickRange_[]; }>();
onPasteCells = new SlickEvent<{ ranges: SlickRange_[]; }>();

// --
// protected props
protected _grid!: SlickGrid;
protected _bodyElement: HTMLElement;
protected _copiedRanges: CellRange[] | null = null;
protected _copiedRanges: SlickRange_[] | null = null;
protected _clearCopyTI?: NodeJS.Timeout;
protected _copiedCellStyle: string;
protected _copiedCellStyleLayerKey: string;
Expand Down Expand Up @@ -354,7 +354,7 @@ export class SlickCellExternalCopyManager implements SlickPlugin {
}

protected handleKeyDown(e: KeyboardEvent): boolean | void {
let ranges: CellRange[];
let ranges: SlickRange_[];
if (!this._grid.getEditorLock().isActive() || this._grid.getOptions().autoEdit) {
if (e.which === this.keyCodes.ESC) {
if (this._copiedRanges) {
Expand Down Expand Up @@ -455,7 +455,7 @@ export class SlickCellExternalCopyManager implements SlickPlugin {
}
}

protected markCopySelection(ranges: CellRange[]) {
protected markCopySelection(ranges: SlickRange_[]) {
this.clearCopySelection();

const columns = this._grid.getColumns();
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/slick.cellrangedecorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CSSStyleDeclarationWritable, CellRange, CellRangeDecoratorOption, SlickPlugin } from '../models/index';
import { Utils as Utils_ } from '../slick.core';
import type { CSSStyleDeclarationWritable, CellRangeDecoratorOption, SlickPlugin } from '../models/index';
import { Utils as Utils_, SlickRange } from '../slick.core';
import type { SlickGrid } from '../slick.grid';

// for (iife) load Slick methods from global Slick object, or use imports for (esm)
Expand Down Expand Up @@ -49,7 +49,7 @@ export class SlickCellRangeDecorator implements SlickPlugin {
this._elem = null;
}

show(range: CellRange) {
show(range: SlickRange) {
if (!this._elem) {
this._elem = document.createElement('div');
this._elem.className = this._options.selectionCssClass;
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/slick.cellselectionmodel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SlickEvent as SlickEvent_, SlickEventData as SlickEventData_, SlickRange as SlickRange_, Utils as Utils_ } from '../slick.core';
import { SlickCellRangeSelector as SlickCellRangeSelector_ } from './slick.cellrangeselector';
import type { CellRange, OnActiveCellChangedEventArgs } from '../models/index';
import type { OnActiveCellChangedEventArgs } from '../models/index';
import type { SlickDataView } from '../slick.dataview';
import type { SlickGrid } from '../slick.grid';

Expand All @@ -20,7 +20,7 @@ export class SlickCellSelectionModel {
// --
// public API
pluginName = 'CellSelectionModel' as const;
onSelectedRangesChanged = new SlickEvent<CellRange[]>();
onSelectedRangesChanged = new SlickEvent<SlickRange_[]>();

// --
// protected props
Expand All @@ -29,7 +29,7 @@ export class SlickCellSelectionModel {
protected _grid!: SlickGrid;
protected _prevSelectedRow?: number;
protected _prevKeyDown = '';
protected _ranges: CellRange[] = [];
protected _ranges: SlickRange_[] = [];
protected _selector: SlickCellRangeSelector_;
protected _options?: CellSelectionModelOption;
protected _defaults: CellSelectionModelOption = {
Expand Down Expand Up @@ -66,8 +66,8 @@ export class SlickCellSelectionModel {
this._selector?.destroy();
}

protected removeInvalidRanges(ranges: CellRange[]) {
const result: CellRange[] = [];
protected removeInvalidRanges(ranges: SlickRange_[]) {
const result: SlickRange_[] = [];

for (let i = 0; i < ranges.length; i++) {
const r = ranges[i];
Expand All @@ -79,7 +79,7 @@ export class SlickCellSelectionModel {
return result;
}

protected rangesAreEqual(range1: CellRange[], range2: CellRange[]) {
protected rangesAreEqual(range1: SlickRange_[], range2: SlickRange_[]) {
let areDifferent = (range1.length !== range2.length);
if (!areDifferent) {
for (let i = 0; i < range1.length; i++) {
Expand All @@ -102,7 +102,7 @@ export class SlickCellSelectionModel {
this._cachedPageRowCount = 0;
}

setSelectedRanges(ranges: CellRange[], caller = 'SlickCellSelectionModel.setSelectedRanges') {
setSelectedRanges(ranges: SlickRange_[], caller = 'SlickCellSelectionModel.setSelectedRanges') {
// simple check for: empty selection didn't change, prevent firing onSelectedRangesChanged
if ((!this._ranges || this._ranges.length === 0) && (!ranges || ranges.length === 0)) { return; }

Expand Down Expand Up @@ -133,7 +133,7 @@ export class SlickCellSelectionModel {
}
}

protected handleCellRangeSelected(_e: any, args: { range: CellRange; }) {
protected handleCellRangeSelected(_e: any, args: { range: SlickRange_; }) {
this._grid.setActiveCell(args.range.fromRow, args.range.fromCell, false, false, true);
this.setSelectedRanges([args.range]);
}
Expand All @@ -153,7 +153,7 @@ export class SlickCellSelectionModel {
}

protected handleKeyDown(e: KeyboardEvent) {
let ranges: CellRange[], last: SlickRange_;
let ranges: SlickRange_[], last: SlickRange_;
const active = this._grid.getActiveCell();
const metaKey = e.ctrlKey || e.metaKey;
let dataLn = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/slick.rowselectionmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SlickCellRangeDecorator as SlickCellRangeDecorator_ } from './slick.cel
import { SlickCellRangeSelector as SlickCellRangeSelector_ } from './slick.cellrangeselector';
import type { SlickCrossGridRowMoveManager as SlickCrossGridRowMoveManager_ } from './slick.crossgridrowmovemanager';
import type { SlickRowMoveManager as SlickRowMoveManager_ } from './slick.rowmovemanager';
import type { CellRange, OnActiveCellChangedEventArgs, RowSelectionModelOption } from '../models/index';
import type { OnActiveCellChangedEventArgs, RowSelectionModelOption } from '../models/index';
import type { SlickGrid } from '../slick.grid';

// for (iife) load Slick methods from global Slick object, or use imports for (esm)
Expand All @@ -22,12 +22,12 @@ export class SlickRowSelectionModel {
// --
// public API
pluginName = 'RowSelectionModel' as const;
onSelectedRangesChanged = new SlickEvent<CellRange[]>();
onSelectedRangesChanged = new SlickEvent<SlickRange_[]>();
// _handler, _inHandler, _isRowMoveManagerHandler, _options, wrapHandler
// --
// protected props
protected _grid!: SlickGrid;
protected _ranges: CellRange[] = [];
protected _ranges: SlickRange_[] = [];
protected _eventHandler = new SlickEventHandler();
protected _inHandler = false;
protected _selector?: SlickCellRangeSelector_;
Expand Down Expand Up @@ -96,7 +96,7 @@ export class SlickRowSelectionModel {
};
}

protected rangesToRows(ranges: CellRange[]): number[] {
protected rangesToRows(ranges: SlickRange_[]): number[] {
const rows: number[] = [];
for (let i = 0; i < ranges.length; i++) {
for (let j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class SlickRowSelectionModel {
this.setSelectedRanges(this.rowsToRanges(rows), 'SlickRowSelectionModel.setSelectedRows');
}

setSelectedRanges(ranges: CellRange[], caller = 'SlickRowSelectionModel.setSelectedRanges') {
setSelectedRanges(ranges: SlickRange_[], caller = 'SlickRowSelectionModel.setSelectedRanges') {
// simple check for: empty selection didn't change, prevent firing onSelectedRangesChanged
if ((!this._ranges || this._ranges.length === 0) && (!ranges || ranges.length === 0)) {
return;
Expand Down Expand Up @@ -250,7 +250,7 @@ export class SlickRowSelectionModel {
this._grid.setActiveCell(cell.row, cell.cell);
}

protected handleCellRangeSelected(_e: SlickEventData_, args: { range: CellRange; }): boolean | void {
protected handleCellRangeSelected(_e: SlickEventData_, args: { range: SlickRange_; }): boolean | void {
if (!this._grid.getOptions().multiSelect || !this._options.selectActiveRow) {
return false;
}
Expand Down

0 comments on commit 7675dc5

Please sign in to comment.