Skip to content

Commit

Permalink
feat(plugins): add all Cell Range/Selection plugins into Universal
Browse files Browse the repository at this point in the history
- also add full unit test suite for all plugins
  • Loading branch information
ghiscoding committed Oct 7, 2021
1 parent fc24b6d commit 3b4ddca
Show file tree
Hide file tree
Showing 24 changed files with 2,115 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export class Example13 {
enableFiltering: false,
enableExcelCopyBuffer: true,
excelCopyBufferOptions: {
onCopyCells: (e, args) => console.log(e, args),
onPasteCells: (e, args) => console.log(e, args),
onCopyCancelled: (e, args) => console.log(e, args),
onCopyCells: (e, args) => console.log('onCopyCells', e, args),
onPasteCells: (e, args) => console.log('onPasteCells', e, args),
onCopyCancelled: (e, args) => console.log('onCopyCancelled', e, args),
},
enableCellNavigation: true,
gridHeight: 275,
Expand All @@ -82,6 +82,8 @@ export class Example13 {
...this.gridOptions1,
enableHeaderMenu: true,
enableFiltering: true,
// frozenColumn: 2,
// frozenRow: 2,
headerButton: {
// when floating to left, you might want to inverse the icon orders
inverseOrder: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/enums/keyCode.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export enum KeyCode {
C = 67,
V = 86,
BACKSPACE = 8,
DELETE = 46,
DOWN = 40,
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/enums/slickPluginList.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../interfaces/index';
import {
AutoTooltipPlugin,
CellRangeSelector,
// CellExternalCopyManager,
// CellRangeDecorator,
// CellRangeSelector,
Expand All @@ -25,6 +26,7 @@ import {

export type SlickPluginList =
AutoTooltipPlugin |
CellRangeSelector |
SlickCellExternalCopyManager |
SlickCellMenu |
SlickCellRangeDecorator |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const mockAddon = jest.fn().mockImplementation(() => ({
destroy: jest.fn()
}));

jest.mock('slickgrid/plugins/slick.cellexternalcopymanager', () => mockAddon);
jest.mock('slickgrid/plugins/slick.rowselectionmodel', () => mockAddon);
jest.mock('slickgrid/plugins/slick.rowdetailview', () => mockAddon);
jest.mock('slickgrid/plugins/slick.rowmovemanager', () => mockAddon);
Expand Down
14 changes: 0 additions & 14 deletions packages/common/src/extensions/extensionUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ export class ExtensionUtility {
return output;
}

/**
* Loop through object provided and set to null any property found starting with "onX"
* @param {Object}: obj
*/
nullifyFunctionNameStartingWithOn(obj?: any) {
if (obj) {
for (const prop of Object.keys(obj)) {
if (prop.startsWith('on')) {
obj[prop] = null;
}
}
}
}

/**
* When using ColumnPicker/GridMenu to show/hide a column, we potentially need to readjust the grid option "frozenColumn" index.
* That is because SlickGrid freezes by column index and it has no knowledge of the columns themselves and won't change the index, we need to do that ourselves whenever necessary.
Expand Down
16 changes: 16 additions & 0 deletions packages/common/src/interfaces/cellRange.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CellRangeDecorator } from '../plugins/cellRangeDecorator';

export interface CellRange {
/** Selection start from which cell? */
fromCell: number;
Expand All @@ -11,3 +13,17 @@ export interface CellRange {
/** Selection goes to which row? */
toRow: number;
}

export interface CellRangeDecoratorOption {
selectionCssClass: string;
selectionCss: CSSStyleDeclaration;
offset: { top: number; left: number; height: number; width: number; };
}

export interface CellRangeSelectorOption {
cellDecorator: CellRangeDecorator;
selectionCss: CSSStyleDeclaration;
}

export type CSSStyleDeclarationReadonly = 'length' | 'parentRule' | 'getPropertyPriority' | 'getPropertyValue' | 'item' | 'removeProperty' | 'setProperty';
export type CSSStyleDeclarationWritable = keyof Omit<CSSStyleDeclaration, CSSStyleDeclarationReadonly>;
16 changes: 16 additions & 0 deletions packages/common/src/interfaces/drag.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface DragPosition {
startX: number;
startY: number;
range: DragRange;
}

export interface DragRange {
start: {
row?: number;
cell?: number;
};
end: {
row?: number;
cell?: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import {
import { CellExcelCopyManager, } from '../plugins/cellExcelCopyManager';

export interface ExcelCopyBufferOption<T = any> {
/** defaults to 2000(ms), delay in ms to wait before clearing the selection after a paste action */
clearCopySelectionDelay?: number;

/** defaults to 100(ms), delay in ms to wait before executing focus/paste */
clipboardPasteDelay?: number;

/** defaults to "copied", sets the css className used for copied cells. */
copiedCellStyle?: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CellExternalCopyManager } from '../plugins/cellExternalCopyManager';
import { CellRange, Column, ExcelCopyBufferOption } from './index';

export interface ExternalCopyClipCommand {
activeCell: number;
activeRow: number;
cellExternalCopyManager: CellExternalCopyManager;
clippedRange: CellRange[];
destH: number;
destW: number;
h: number;
w: number;
isClipboardCommand: boolean;
maxDestX: number;
maxDestY: number;
oldValues: any[];
oneCellToMultiple: boolean;
_options: ExcelCopyBufferOption;

execute: () => void;
markCopySelection: (ranges: CellRange[]) => void;
setDataItemValueForColumn: (item: any, columnDef: Column, value: any) => any | void;
undo: () => void;
}
2 changes: 2 additions & 0 deletions packages/common/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export * from './currentSorter.interface';
export * from './customFooterOption.interface';
export * from './dataViewOption.interface';
export * from './domEvent.interface';
export * from './drag.interface';
export * from './draggableGrouping.interface';
export * from './draggableGroupingOption.interface';
export * from './editCommand.interface';
Expand All @@ -58,6 +59,7 @@ export * from './excelWorkbook.interface';
export * from './excelWorksheet.interface';
export * from './extension.interface';
export * from './extensionModel.interface';
export * from './externalCopyClipCommand.interface';
export * from './externalResource.interface';
export * from './filter.interface';
export * from './filterArguments.interface';
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/interfaces/slickRange.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export interface SlickRange extends CellRange {
constructor: (fromRow: number, fromCell: number, toRow: number, toCell: number) => void;

/** Returns whether a range represents a single row. */
isSingleRow: () => boolean;
isSingleRow?: () => boolean;

/** Returns whether a range represents a single cell. */
isSingleCell: () => boolean;
isSingleCell?: () => boolean;

/** Returns whether a range contains a given cell. */
contains: (row: number, cell: number) => boolean;
contains?: (row: number, cell: number) => boolean;

/** Returns a readable representation of a range. */
toString: () => string;
toString?: () => string;
}
Loading

0 comments on commit 3b4ddca

Please sign in to comment.