Skip to content

Commit

Permalink
fix: remove CellRange, SlickRange, SlickGroup, ... unused interfaces (#…
Browse files Browse the repository at this point in the history
…1219)

* fix: remove CellRange, SlickRange, SlickGroup, ... unused interfaces
- since we moved SlickGrid inside the project, we can now use the TS classes directly instead of relying on similar interfaces
- also remove slick core re-export and replace it by exporting core folder

* chore: move CSS Style Declartion to its own interface file
  • Loading branch information
ghiscoding authored Nov 24, 2023
1 parent d723856 commit a4cc469
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 240 deletions.
4 changes: 2 additions & 2 deletions examples/vite-demo-vanilla-bundle/src/examples/example19.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CellRange, type Column, type GridOption, SlickEventHandler, } from '@slickgrid-universal/common';
import { type Column, type GridOption, SlickEventHandler, type SlickRange } from '@slickgrid-universal/common';
import { Slicker, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
import { ExampleGridOptions } from './example-grid-options';
import '../salesforce-styles.scss';
Expand Down Expand Up @@ -29,7 +29,7 @@ export default class Example19 {

// bind any of the grid events
const cellSelectionModel = this.sgb.slickGrid!.getSelectionModel();
this._eventHandler.subscribe(cellSelectionModel!.onSelectedRangesChanged, (_e, args: CellRange[]) => {
this._eventHandler.subscribe(cellSelectionModel!.onSelectedRangesChanged, (_e, args: SlickRange[]) => {
const targetRange = document.querySelector('#selectionRange') as HTMLSpanElement;
targetRange.textContent = '';

Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/core/slickDataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ import {
import type { SlickGrid } from './slickGrid';

export interface DataViewOption {
groupItemMetadataProvider: SlickGroupItemMetadataProvider | null;
/** Defaults to false, use with great care as this will break built-in filters */
inlineFilters: boolean;

/** Optionally provide a Group Item Metatadata Provider when using Grouping/DraggableGrouping feature */
groupItemMetadataProvider: SlickGroupItemMetadataProvider | null;

/** Defaults to false, should we use CSP Safe filter method? The CSP safe is slighly slower compare to dynamic function default */
useCSPSafeFilter: boolean;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/enums/slickPluginList.enum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ExtensionName } from '../enums/index';
import type { SlickEditorLock, SlickRowDetailView } from '../interfaces/index';
import type { SlickEditorLock } from '../core/index';
import type { SlickRowDetailView } from '../interfaces/index';
import type {
SlickAutoTooltip,
SlickCellExcelCopyManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CellRange, EditCommand, Formatter, GridOption } from '../../interfaces/index';
import type { EditCommand, Formatter, GridOption } from '../../interfaces/index';
import { Formatters } from '../../formatters';
import { SharedService } from '../../services/shared.service';
import { SlickCellExcelCopyManager } from '../slickCellExcelCopyManager';
import { SlickCellSelectionModel } from '../slickCellSelectionModel';
import { SlickCellExternalCopyManager } from '../slickCellExternalCopyManager';
import { SlickEvent, SlickEventData, SlickGrid } from '../../core/index';
import { SlickEvent, SlickEventData, SlickGrid, SlickRange } from '../../core/index';

jest.mock('flatpickr', () => { });

Expand Down Expand Up @@ -57,7 +57,7 @@ jest.mock('../slickCellExternalCopyManager', () => ({
describe('CellExcelCopyManager', () => {
let queueCallback: EditCommand;
const mockEventCallback = () => { };
const mockSelectRange = [{ fromCell: 1, fromRow: 1, toCell: 1, toRow: 1 }] as CellRange[];
const mockSelectRange = [{ fromCell: 1, fromRow: 1, toCell: 1, toRow: 1 }] as SlickRange[];
const mockSelectRangeEvent = { ranges: mockSelectRange };

let plugin: SlickCellExcelCopyManager;
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/extensions/slickCellExternalCopyManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CellRange, Column, ExcelCopyBufferOption, ExternalCopyClipCommand } from '../interfaces/index';
import type { Column, ExcelCopyBufferOption, ExternalCopyClipCommand } from '../interfaces/index';
import { createDomElement, removeHtmlTags } from '../services/domUtilities';
import { SlickEvent, SlickEventData, SlickEventHandler, type SlickGrid, SlickRange } from '../core/index';

Expand All @@ -16,16 +16,16 @@ const CLIPBOARD_PASTE_DELAY = 100;
*/
export class SlickCellExternalCopyManager {
pluginName: 'CellExternalCopyManager' = '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 _addonOptions!: ExcelCopyBufferOption;
protected _bodyElement = document.body;
protected _clearCopyTI?: NodeJS.Timeout;
protected _copiedCellStyle = 'copied';
protected _copiedCellStyleLayerKey = 'copy-manager';
protected _copiedRanges: CellRange[] | null = null;
protected _copiedRanges: SlickRange[] | null = null;
protected _eventHandler: SlickEventHandler;
protected _grid!: SlickGrid;
protected _onCopyInit?: () => void;
Expand Down Expand Up @@ -346,7 +346,7 @@ export class SlickCellExternalCopyManager {


protected handleKeyDown(e: any): boolean | void {
let ranges: CellRange[];
let ranges: SlickRange[];
if (!this._grid.getEditorLock().isActive() || this._grid.getOptions().autoEdit) {
if (e.key === 'Escape') {
if (this._copiedRanges) {
Expand Down Expand Up @@ -445,7 +445,7 @@ export class SlickCellExternalCopyManager {
}
}

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

const columns = this._grid.getColumns();
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/extensions/slickCellRangeDecorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deepMerge } from '@slickgrid-universal/utils';

import type { CellRange, CellRangeDecoratorOption, CSSStyleDeclarationWritable } from '../interfaces/index';
import { createDomElement } from '../services/domUtilities';
import { type SlickGrid } from '../core/index';
import type { CellRangeDecoratorOption, CSSStyleDeclarationWritable } from '../interfaces/index';
import type { SlickGrid, SlickRange } from '../core/index';

/**
* Displays an overlay on top of a given cell range.
Expand Down Expand Up @@ -51,7 +51,7 @@ export class SlickCellRangeDecorator {
this._elem = null;
}

show(range: CellRange) {
show(range: SlickRange) {
if (!this._elem) {
this._elem = createDomElement('div', { className: this._options.selectionCssClass });
Object.keys(this._options.selectionCss as CSSStyleDeclaration).forEach((cssStyleKey) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/extensions/slickCellSelectionModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { type SlickDataView, SlickEvent, SlickEventData, SlickEventHandler, SlickRange, type SlickGrid } from '../core/index';
import type { SelectionModel } from '../enums/index';
import type { CellRange, OnActiveCellChangedEventArgs } from '../interfaces/index';
import type { OnActiveCellChangedEventArgs } from '../interfaces/index';
import { SlickCellRangeSelector } from './index';

export interface CellSelectionModelOption {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class SlickCellSelectionModel implements SelectionModel {
return this._ranges;
}

rangesAreEqual(range1: CellRange[], range2: CellRange[]) {
rangesAreEqual(range1: SlickRange[], range2: SlickRange[]) {
let areDifferent = (range1.length !== range2.length);
if (!areDifferent) {
for (let i = 0; i < range1.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/extensions/slickRowSelectionModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type SelectionModel } from '../enums/index';
import type { CellRange, GridOption, OnActiveCellChangedEventArgs, RowSelectionModelOption, } from '../interfaces/index';
import type { GridOption, OnActiveCellChangedEventArgs, RowSelectionModelOption, } from '../interfaces/index';
import { SlickCellRangeSelector } from '../extensions/slickCellRangeSelector';
import { SlickEvent, SlickEventData, SlickEventHandler, type SlickGrid, SlickRange } from '../core/index';

Expand Down Expand Up @@ -144,7 +144,7 @@ export class SlickRowSelectionModel implements SelectionModel {
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.gridOptions.multiSelect || !this.addonOptions.selectActiveRow) {
return false;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export class SlickRowSelectionModel implements SelectionModel {
return /move|selectAndMove/.test(col);
}

protected rangesToRows(ranges: CellRange[]): number[] {
protected rangesToRows(ranges: SlickRange[]): number[] {
const rows = [];
for (let i = 0; i < ranges.length; i++) {
for (let j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
Expand Down
12 changes: 1 addition & 11 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {
export * from './constants';
export * from './global-grid-options';

export * from './core/index';
export * from './enums/index';
export * from './interfaces/index';
export * from './aggregators/index';
Expand Down Expand Up @@ -45,14 +46,3 @@ export { SlickgridConfig } from './slickgrid-config';

// re-export MultipleSelectOption to avoid breaking previous code implementation
export { MultipleSelectOption } from 'multiple-select-vanilla';

// re-export SlickGrid core files
export {
SlickDataView,
SlickEvent,
SlickEventData,
SlickEventHandler,
SlickGlobalEditorLock,
SlickGrid,
Utils,
} from './core/index';
17 changes: 0 additions & 17 deletions packages/common/src/interfaces/cellRange.interface.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import type { SlickCellRangeDecorator } from '../extensions/slickCellRangeDecorator';

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 @@ -39,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 packages/common/src/interfaces/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>;
9 changes: 0 additions & 9 deletions packages/common/src/interfaces/dataViewOption.interface.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import type { Column, CellRange, FormatterResultWithHtml, FormatterResultWithText, } from './index';
import type { Column, FormatterResultWithHtml, FormatterResultWithText, } from './index';
import type { SlickCellExcelCopyManager, } from '../extensions/slickCellExcelCopyManager';
import type { SlickEventData } from '../core/index';
import type { SlickEventData, SlickRange } from '../core/index';

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 @@ -54,11 +54,11 @@ export interface ExcelCopyBufferOption<T = any> {
onExtensionRegistered?: (plugin: SlickCellExcelCopyManager) => void;

/** 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;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { SlickCellExternalCopyManager } from '../extensions/slickCellExternalCopyManager';
import type { CellRange, Column, ExcelCopyBufferOption } from './index';
import type { Column, ExcelCopyBufferOption } from './index';
import type { SlickRange } from '../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;
}
5 changes: 2 additions & 3 deletions packages/common/src/interfaces/gridOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
ContextMenu,
CustomFooterOption,
CustomTooltipOption,
DataViewOption,
DraggableGrouping,
EditCommand,
EmptyWarning,
Expand All @@ -39,7 +38,7 @@ import type {
} from './index';
import type { ColumnReorderFunction, OperatorString, OperatorType, } from '../enums/index';
import type { TranslaterService } from '../services/translater.service';
import type { SlickEditorLock } from '../core/index';
import type { DataViewOption, SlickEditorLock } from '../core/index';

export interface CellViewportRange {
bottom: number;
Expand Down Expand Up @@ -219,7 +218,7 @@ export interface GridOption<C extends Column = Column> {
datasetIdPropertyName?: string;

/** Some of the SlickGrid DataView options */
dataView?: DataViewOption & {
dataView?: Partial<DataViewOption> & {
/**
* Wires the grid and the DataView together to keep row selection tied to item ids.
* This is useful since, without it, the grid only knows about rows, so if the items
Expand Down
5 changes: 1 addition & 4 deletions packages/common/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from './compositeEditorOpenDetailOption.interface';
export * from './compositeEditorOption.interface';
export * from './contextMenu.interface';
export * from './contextMenuOption.interface';
export * from './cssDeclaration.interface';
export * from './currentColumn.interface';
export * from './currentFilter.interface';
export * from './currentPagination.interface';
Expand All @@ -40,7 +41,6 @@ export * from './cursorPageInfo.interface';
export * from './customFooterOption.interface';
export * from './customTooltipOption.interface';
export * from './dataViewEvents.interface';
export * from './dataViewOption.interface';
export * from './domEvent.interface';
export * from './drag.interface';
export * from './draggableGrouping.interface';
Expand Down Expand Up @@ -140,10 +140,7 @@ export * from './selectOption.interface';
export * from './servicePagination.interface';
export * from './singleColumnSort.interface';
export * from './slickCompositeEditor.interface';
export * from './slickEditorLock.interface';
export * from './slickGroup.interface';
export * from './slickPlugin.interface';
export * from './slickRange.interface';
export * from './slickRemoteModel.interface';
export * from './slickResizer.interface';
export * from './slickRowDetailView.interface';
Expand Down
56 changes: 0 additions & 56 deletions packages/common/src/interfaces/slickEditorLock.interface.ts

This file was deleted.

Loading

0 comments on commit a4cc469

Please sign in to comment.