diff --git a/README.md b/README.md index eccb6dd7a..62e5d2e44 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ yarn run test:watch - [x] Copy cell text (context menu) doesn't work in SF - [x] Remove all Services init method 2nd argument (we can get DataView directly from the Grid object) - [x] The Pagination/Footer width is a little off sometime compare to the width of the grid container -- [ ] Check why `DOM Purify` doesn't work in SF +- [ ] See if we can get `DOM Purify` to work in SF, else keep the custom sanitizer - [ ] See if we can get all the vanilla-grid-bundle `instances` as `readonly` class members -- [ ] Draggable Grouping pre-header (dragging) is not working as intended +- [ ] See if we can add the number of chars typed in `Editors.longText` +- [ ] Resizer Service doesn't seem to count the `bottomPadding` with Custom Footer in the calculation diff --git a/examples/webpack-demo-vanilla-bundle/src/examples/example03.ts b/examples/webpack-demo-vanilla-bundle/src/examples/example03.ts index f10ff1213..cdf518994 100644 --- a/examples/webpack-demo-vanilla-bundle/src/examples/example03.ts +++ b/examples/webpack-demo-vanilla-bundle/src/examples/example03.ts @@ -297,7 +297,7 @@ export class Example3 { draggableGrouping: { dropPlaceHolderText: 'Drop a column header here to group by the column', // groupIconCssClass: 'fa fa-outdent', - deleteIconCssClass: 'fa fa-times mdi mdi-close', + deleteIconCssClass: 'fa fa-times mdi mdi-close text-danger', onGroupChanged: (e, args) => this.onGroupChanged(args), onExtensionRegistered: (extension) => this.draggableGroupingPlugin = extension, }, diff --git a/examples/webpack-demo-vanilla-bundle/src/examples/example11.ts b/examples/webpack-demo-vanilla-bundle/src/examples/example11.ts index d472e1cb2..1d9ab0da1 100644 --- a/examples/webpack-demo-vanilla-bundle/src/examples/example11.ts +++ b/examples/webpack-demo-vanilla-bundle/src/examples/example11.ts @@ -32,10 +32,7 @@ const customEditableInputFormatter = (row, cell, value, columnDef, dataContext, const gridOptions = grid && grid.getOptions && grid.getOptions(); const isEditableLine = gridOptions.editable && columnDef.editor; value = (value === null || value === undefined) ? '' : value; - // const isUnsavedField = dataContext.__unsaved && dataContext.__unsaved[columnDef.field] || false; - const isUnsavedField = false; - const cssClass = isUnsavedField ? 'unsaved-editable-field' : 'editable-field'; - return isEditableLine ? { text: value, addClasses: cssClass, toolTip: 'Click to Edit' } : value; + return isEditableLine ? { text: value, addClasses: 'editable-field', toolTip: 'Click to Edit' } : value; }; export class Example3 { @@ -46,7 +43,6 @@ export class Example3 { editQueue = []; editedItems = {}; sgb: SlickVanillaGridBundle; - durationOrderByCount = false; get slickerGridInstance(): SlickerGridInstance { return this.sgb?.instances; @@ -186,11 +182,9 @@ export class Example3 { hideInColumnTitleRow: true, }, editCommandHandler: (item, column, editCommand) => { - // keep in an array only the ones that changed, also add an extra "__unsaved" property that we can use for styling these cells if (editCommand.prevSerializedValue !== editCommand.serializedValue) { this.editQueue.push({ item, column, editCommand }); this.editedItems[editCommand.row] = item; // keep items by their row indexes, if the row got edited twice then we'll keep only the last change - // item.__unsaved = { ...item.__unsaved, [column.field]: true }; this.sgb.slickGrid.invalidate(); editCommand.execute(); @@ -217,11 +211,13 @@ export class Example3 { } toggleGridEditReadonly() { - // change a single grid options to make the grid non-editable (readonly) + // first need undo all edits + this.undoAllEdits(); + + // then change a single grid options to make the grid non-editable (readonly) this.isGridEditable = !this.isGridEditable; this.sgb.gridOptions = { editable: this.isGridEditable }; this.gridOptions = this.sgb.gridOptions; - this.removeAllUnsavedStylingFromCell(); } loadData(count: number) { @@ -320,6 +316,7 @@ export class Example3 { // example: editedItems = { 0: { title: task 0, duration: 50, ... }} // ...means that row index 0 got changed and the final merged object is { title: task 0, duration: 50, ... } console.log(this.editedItems); + // console.log(`We changed ${Object.keys(this.editedItems).length} rows`); // since we saved, we can now remove all the unsaved color styling and reset our array/object this.removeAllUnsavedStylingFromCell(); @@ -329,11 +326,6 @@ export class Example3 { removeUnsavedStylingFromCell(item: any, column: Column, row: number) { // remove unsaved css class from that cell - const fieldId = column.field; - if (item.__unsaved) { - delete item.__unsaved[fieldId]; - } - this.sgb.slickGrid.removeCellCssStyles(`unsaved_highlight_${[column.field]}${row}`); } diff --git a/package.json b/package.json index bf086fef0..552a8a75e 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,13 @@ "build": "lerna run build --stream", "build:demo": "lerna run build:demo --stream", "rebuild": "run-s clean build", - "clean": "rimraf packages/*/dist dist", + "clean": "rimraf --maxBusyTries=10 packages/*/dist dist", "cypress": "cypress open --config-file test/cypress.json", "cypress:ci": "cypress run --config-file test/cypress.json --reporter mochawesome", "dev:watch": "lerna run dev:watch --parallel", "diff": "lerna diff", "updated": "lerna updated", - "clean:tsconfig-build-cache": "rimraf packages/*/dist/tsconfig.tsbuildinfo", + "clean:tsconfig-build-cache": "rimraf --maxBusyTries=10 packages/*/dist/tsconfig.tsbuildinfo", "new-version": "lerna version --conventional-commits", "serve:demo": "http-server ./docs -p 8888 -a localhost", "test": "npx jest --runInBand --coverage --config ./test/jest.config.js", @@ -64,4 +64,4 @@ "node": ">=12.13.1", "npm": ">=6.12.1" } -} \ No newline at end of file +} diff --git a/packages/common/package.json b/packages/common/package.json index b74e97edb..ddd460563 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -29,7 +29,7 @@ "bundle:commonjs": "tsc --project tsconfig.build.json --outDir dist/commonjs --module commonjs", "bundle:es2015": "cross-env tsc --project tsconfig.build.json --outDir dist/es2015 --module es2020 --target es2015", "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2020 --target es2020", - "delete:dist": "cross-env rimraf dist", + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist", "sass-build-task:scss-compile:bootstrap": "node-sass src/styles/slickgrid-theme-bootstrap.scss -o dist/styles/css --output-style compressed", "postsass-build-task:scss-compile:bootstrap": "postcss --use autoprefixer --output dist/styles/css/slickgrid-theme-bootstrap.css dist/styles/css/slickgrid-theme-bootstrap.css --output-style compressed", "sass-build-task:scss-compile:material": "node-sass src/styles/slickgrid-theme-material.scss -o dist/styles/css --output-style compressed", diff --git a/packages/common/src/enums/columnReorderFunction.type.ts b/packages/common/src/enums/columnReorderFunction.type.ts new file mode 100644 index 000000000..ac8e38cfa --- /dev/null +++ b/packages/common/src/enums/columnReorderFunction.type.ts @@ -0,0 +1,3 @@ +import { Column, SlickGrid } from '../interfaces/index'; + +export type ColumnReorderFunction = (grid: SlickGrid, headers: HTMLElement[], headerColumnWidthDiff: any, setColumns: (col: Column) => void, setupColumnResize: () => void, columns: Column[], getColumnIndex: number, uid: string, trigger: boolean) => void; diff --git a/packages/common/src/enums/extensionList.type.ts b/packages/common/src/enums/extensionList.type.ts new file mode 100644 index 000000000..85f4a2c80 --- /dev/null +++ b/packages/common/src/enums/extensionList.type.ts @@ -0,0 +1,4 @@ +import { ExtensionName, SlickControlList, SlickPluginList } from './index'; +import { Extension, ExtensionModel } from '../interfaces/index'; + +export type ExtensionList

= Record>; diff --git a/packages/common/src/enums/gridAutosizeColsMode.enum.ts b/packages/common/src/enums/gridAutosizeColsMode.enum.ts index 12b36454d..273674974 100644 --- a/packages/common/src/enums/gridAutosizeColsMode.enum.ts +++ b/packages/common/src/enums/gridAutosizeColsMode.enum.ts @@ -5,4 +5,4 @@ export enum GridAutosizeColsMode { ignoreViewport = 'IGV', fitColsToViewport = 'FCV', fitViewportToCols = 'FVC' -}; +} diff --git a/packages/common/src/enums/gridStateType.enum.ts b/packages/common/src/enums/gridStateType.enum.ts index bbb2845f6..21607be94 100644 --- a/packages/common/src/enums/gridStateType.enum.ts +++ b/packages/common/src/enums/gridStateType.enum.ts @@ -4,4 +4,4 @@ export enum GridStateType { pagination = 'pagination', rowSelection = 'rowSelection', sorter = 'sorter', -}; +} diff --git a/packages/common/src/enums/index.ts b/packages/common/src/enums/index.ts index 05a64dd4e..ce8c4dde1 100644 --- a/packages/common/src/enums/index.ts +++ b/packages/common/src/enums/index.ts @@ -1,20 +1,22 @@ export * from './caseType.enum'; -export * from './delimiterType.enum'; -export * from './emitterType.enum'; -export * from './eventNamingStyle.enum'; -export * from './extensionName.enum'; export * from './fieldType.enum'; +export * from './extensionList.type'; +export * from './eventNamingStyle.enum'; +export * from './emitterType.enum'; export * from './fileType.enum'; +export * from './delimiterType.enum'; +export * from './columnReorderFunction.type'; +export * from './extensionName.enum'; export * from './filterMultiplePassType.enum'; -export * from './filterMultiplePassTypeString.type'; -export * from './gridAutosizeColsMode.enum'; -export * from './gridStateType.enum'; -export * from './keyCode.enum'; -export * from './operatorString.type'; -export * from './operatorType.enum'; -export * from './slickControlList.enum'; -export * from './slickPluginList.enum'; -export * from './sortDirection.enum'; +export * from './sortDirectionString.type'; export * from './sortDirectionNumber.enum'; +export * from './sortDirection.enum'; +export * from './slickPluginList.enum'; +export * from './slickControlList.enum'; export * from './searchTerm.type'; -export * from './sortDirectionString.type'; +export * from './operatorType.enum'; +export * from './operatorString.type'; +export * from './keyCode.enum'; +export * from './gridStateType.enum'; +export * from './gridAutosizeColsMode.enum'; +export * from './filterMultiplePassTypeString.type'; diff --git a/packages/common/src/extensions/__tests__/autoTooltipExtension.spec.ts b/packages/common/src/extensions/__tests__/autoTooltipExtension.spec.ts index 059c5091c..2113bf66b 100644 --- a/packages/common/src/extensions/__tests__/autoTooltipExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/autoTooltipExtension.spec.ts @@ -40,12 +40,12 @@ describe('autoTooltipExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.register(); const addonInstance = extension.getAddonInstance(); diff --git a/packages/common/src/extensions/__tests__/cellExternalCopyManagerExtension.spec.ts b/packages/common/src/extensions/__tests__/cellExternalCopyManagerExtension.spec.ts index 3a16110c8..e02cfbf14 100644 --- a/packages/common/src/extensions/__tests__/cellExternalCopyManagerExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/cellExternalCopyManagerExtension.spec.ts @@ -72,7 +72,7 @@ describe('cellExternalCopyManagerExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); queueCallback = { execute: () => { }, @@ -86,7 +86,7 @@ describe('cellExternalCopyManagerExtension', () => { }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const onRegisteredSpy = jest.spyOn(SharedService.prototype.gridOptions.excelCopyBufferOptions, 'onExtensionRegistered'); const instance = extension.register(); diff --git a/packages/common/src/extensions/__tests__/cellMenuExtension.spec.ts b/packages/common/src/extensions/__tests__/cellMenuExtension.spec.ts index fd8d03e8e..38697ad8f 100644 --- a/packages/common/src/extensions/__tests__/cellMenuExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/cellMenuExtension.spec.ts @@ -106,7 +106,7 @@ describe('CellMenuExtension', () => { describe('registered addon', () => { beforeEach(() => { jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock); @@ -114,7 +114,7 @@ describe('CellMenuExtension', () => { }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const onRegisteredSpy = jest.spyOn(SharedService.prototype.gridOptions.cellMenu, 'onExtensionRegistered'); const instance = extension.register(); diff --git a/packages/common/src/extensions/__tests__/checkboxSelectorExtension.spec.ts b/packages/common/src/extensions/__tests__/checkboxSelectorExtension.spec.ts index 64f764949..4c0ac5175 100644 --- a/packages/common/src/extensions/__tests__/checkboxSelectorExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/checkboxSelectorExtension.spec.ts @@ -74,12 +74,12 @@ describe('checkboxSelectorExtension', () => { { id: 'field2', field: 'field2', width: 50 } ]; columnSelectionMock = { id: '_checkbox_selector', field: 'sel' }; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.create(columnsMock, gridOptionsMock); const selectionModel = extension.register(); @@ -94,8 +94,8 @@ describe('checkboxSelectorExtension', () => { }); it('should register the addon with the registered plugin provided as argument', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); - const selectionSpy = jest.spyOn(SharedService.prototype.grid, 'getSelectionModel'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); + const selectionSpy = jest.spyOn(SharedService.prototype.slickGrid, 'getSelectionModel'); const instance = extension.create(columnsMock, gridOptionsMock); const selectionModel = extension.register(); @@ -170,9 +170,9 @@ describe('checkboxSelectorExtension', () => { it('should be able to pre-select rows', () => { const selectionModelOptions = { ...gridOptionsMock, preselectedRows: [0], rowSelectionOptions: { selectActiveRow: true } }; jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(selectionModelOptions); - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); // @ts-ignore - const selectionSpy = jest.spyOn(SharedService.prototype.grid, 'getSelectionModel').mockReturnValue(mockSelectionModel); + const selectionSpy = jest.spyOn(SharedService.prototype.slickGrid, 'getSelectionModel').mockReturnValue(mockSelectionModel); const instance = extension.create(columnsMock, gridOptionsMock); const rowSpy = jest.spyOn(instance, 'selectRows'); diff --git a/packages/common/src/extensions/__tests__/columnPickerExtension.spec.ts b/packages/common/src/extensions/__tests__/columnPickerExtension.spec.ts index bf58ba1d2..8887443b3 100644 --- a/packages/common/src/extensions/__tests__/columnPickerExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/columnPickerExtension.spec.ts @@ -57,7 +57,7 @@ describe('columnPickerExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock.slice(0, 1)); diff --git a/packages/common/src/extensions/__tests__/contextMenuExtension.spec.ts b/packages/common/src/extensions/__tests__/contextMenuExtension.spec.ts index 32d96dfcb..e1d382986 100644 --- a/packages/common/src/extensions/__tests__/contextMenuExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/contextMenuExtension.spec.ts @@ -143,7 +143,7 @@ describe('contextMenuExtension', () => { describe('registered addon', () => { beforeEach(() => { jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock.slice(0, 1)); @@ -515,7 +515,7 @@ describe('contextMenuExtension', () => { } as GridOption; jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock); diff --git a/packages/common/src/extensions/__tests__/draggableGroupingExtension.spec.ts b/packages/common/src/extensions/__tests__/draggableGroupingExtension.spec.ts index fcc1fa45b..56b718a20 100644 --- a/packages/common/src/extensions/__tests__/draggableGroupingExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/draggableGroupingExtension.spec.ts @@ -55,13 +55,13 @@ describe('draggableGroupingExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); it('should register the addon', () => { const onRegisteredSpy = jest.spyOn(SharedService.prototype.gridOptions.draggableGrouping, 'onExtensionRegistered'); - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.create(gridOptionsMock); const addon = extension.register(); diff --git a/packages/common/src/extensions/__tests__/gridMenuExtension.spec.ts b/packages/common/src/extensions/__tests__/gridMenuExtension.spec.ts index 62a69e4c4..da4f629ee 100644 --- a/packages/common/src/extensions/__tests__/gridMenuExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/gridMenuExtension.spec.ts @@ -144,7 +144,7 @@ describe('gridMenuExtension', () => { describe('registered addon', () => { beforeEach(() => { jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock.slice(0, 1)); @@ -499,7 +499,7 @@ describe('gridMenuExtension', () => { } as unknown as GridOption; jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock); @@ -718,7 +718,7 @@ describe('gridMenuExtension', () => { it('should call the grid "setTopPanelVisibility" method when the command triggered is "toggle-toppanel"', () => { gridOptionsMock.showTopPanel = false; - const gridSpy = jest.spyOn(SharedService.prototype.grid, 'setTopPanelVisibility'); + const gridSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setTopPanelVisibility'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); const instance = extension.register(); @@ -736,7 +736,7 @@ describe('gridMenuExtension', () => { it('should call the grid "setPreHeaderPanelVisibility" method when the command triggered is "toggle-preheader"', () => { gridOptionsMock.showPreHeaderPanel = false; - const gridSpy = jest.spyOn(SharedService.prototype.grid, 'setPreHeaderPanelVisibility'); + const gridSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setPreHeaderPanelVisibility'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.gridMenu, 'onCommand'); const instance = extension.register(); diff --git a/packages/common/src/extensions/__tests__/groupItemMetaProviderExtension.spec.ts b/packages/common/src/extensions/__tests__/groupItemMetaProviderExtension.spec.ts index 648321717..11f3d426f 100644 --- a/packages/common/src/extensions/__tests__/groupItemMetaProviderExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/groupItemMetaProviderExtension.spec.ts @@ -35,11 +35,11 @@ describe('groupItemMetaProviderExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.register(); const addonInstance = extension.getAddonInstance(); diff --git a/packages/common/src/extensions/__tests__/headerButtonExtension.spec.ts b/packages/common/src/extensions/__tests__/headerButtonExtension.spec.ts index 57b9140f9..28a88938d 100644 --- a/packages/common/src/extensions/__tests__/headerButtonExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/headerButtonExtension.spec.ts @@ -61,12 +61,12 @@ describe('headerButtonExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.register(); const addonInstance = extension.getAddonInstance(); diff --git a/packages/common/src/extensions/__tests__/headerMenuExtension.spec.ts b/packages/common/src/extensions/__tests__/headerMenuExtension.spec.ts index f9a96d5ac..ffa6b6eec 100644 --- a/packages/common/src/extensions/__tests__/headerMenuExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/headerMenuExtension.spec.ts @@ -123,7 +123,7 @@ describe('headerMenuExtension', () => { describe('registered addon', () => { beforeEach(() => { jest.spyOn(SharedService.prototype, 'dataView', 'get').mockReturnValue(dataViewStub); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(columnsMock); jest.spyOn(SharedService.prototype, 'visibleColumns', 'get').mockReturnValue(columnsMock); @@ -131,7 +131,7 @@ describe('headerMenuExtension', () => { }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const onRegisteredSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onExtensionRegistered'); const instance = extension.register(); @@ -313,7 +313,7 @@ describe('headerMenuExtension', () => { describe('hideColumn method', () => { it('should call hideColumn and expect "visibleColumns" to be updated accordingly', () => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(gridStub, 'getColumnIndex').mockReturnValue(1); jest.spyOn(gridStub, 'getColumns').mockReturnValue(columnsMock); const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); @@ -411,7 +411,7 @@ describe('headerMenuExtension', () => { it('should trigger the command "hide" and expect the grid "autosizeColumns" method being called', () => { const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); - const autosizeSpy = jest.spyOn(SharedService.prototype.grid, 'autosizeColumns'); + const autosizeSpy = jest.spyOn(SharedService.prototype.slickGrid, 'autosizeColumns'); const instance = extension.register(); instance.onCommand.notify({ column: columnsMock[0], grid: gridStub, command: 'hide', item: { command: 'hide' } }, new Slick.EventData(), gridStub); @@ -449,7 +449,7 @@ describe('headerMenuExtension', () => { const previousSortSpy = jest.spyOn(sortServiceStub, 'getCurrentColumnSorts').mockReturnValue([mockSortedCols[0]]); const backendSortSpy = jest.spyOn(sortServiceStub, 'onBackendSortChanged'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); - const setSortSpy = jest.spyOn(SharedService.prototype.grid, 'setSortColumns'); + const setSortSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setSortColumns'); const instance = extension.register(); instance.onCommand.notify({ column: mockSortedCols[1].sortCol, grid: gridStub, command: 'sort-asc', item: { command: 'sort-asc' } }, new Slick.EventData(), gridStub); @@ -467,7 +467,7 @@ describe('headerMenuExtension', () => { const previousSortSpy = jest.spyOn(sortServiceStub, 'getCurrentColumnSorts').mockReturnValue([mockSortedCols[0]]); const backendSortSpy = jest.spyOn(sortServiceStub, 'onBackendSortChanged'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); - const setSortSpy = jest.spyOn(SharedService.prototype.grid, 'setSortColumns'); + const setSortSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setSortColumns'); const instance = extension.register(); instance.onCommand.notify({ column: mockSortedCols[1].sortCol, grid: gridStub, command: 'sort-desc', item: { command: 'sort-desc' } }, new Slick.EventData(), gridStub); @@ -487,7 +487,7 @@ describe('headerMenuExtension', () => { const previousSortSpy = jest.spyOn(sortServiceStub, 'getCurrentColumnSorts').mockReturnValue([mockSortedCols[0]]); const localSortSpy = jest.spyOn(sortServiceStub, 'onLocalSortChanged'); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); - const setSortSpy = jest.spyOn(SharedService.prototype.grid, 'setSortColumns'); + const setSortSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setSortColumns'); const instance = extension.register(); instance.onCommand.notify({ column: mockSortedCols[1].sortCol, grid: gridStub, command: 'sort-desc', item: { command: 'sort-desc' } }, new Slick.EventData(), gridStub); @@ -506,7 +506,7 @@ describe('headerMenuExtension', () => { const mockSortedOuput: ColumnSort[] = [{ columnId: 'field1', sortAsc: true, sortCol: { id: 'field1', field: 'field1' } }, { columnId: 'field2', sortAsc: false, sortCol: { id: 'field2', field: 'field2' } }]; const previousSortSpy = jest.spyOn(sortServiceStub, 'getCurrentColumnSorts').mockReturnValue([mockSortedCols[0]]); const onCommandSpy = jest.spyOn(SharedService.prototype.gridOptions.headerMenu, 'onCommand'); - const setSortSpy = jest.spyOn(SharedService.prototype.grid, 'setSortColumns'); + const setSortSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setSortColumns'); const gridSortSpy = jest.spyOn(gridStub.onSort, 'notify'); const instance = extension.register(); diff --git a/packages/common/src/extensions/__tests__/rowMoveManagerExtension.spec.ts b/packages/common/src/extensions/__tests__/rowMoveManagerExtension.spec.ts index a1d6ee5e1..7a927dc3f 100644 --- a/packages/common/src/extensions/__tests__/rowMoveManagerExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/rowMoveManagerExtension.spec.ts @@ -79,7 +79,7 @@ describe('rowMoveManagerExtension', () => { { id: 'field1', field: 'field1', width: 100, cssClass: 'red' }, { id: 'field2', field: 'field2', width: 50 } ]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); @@ -169,14 +169,14 @@ describe('rowMoveManagerExtension', () => { beforeEach(() => { columnsMock = [{ id: 'field1', field: 'field1', width: 100, cssClass: 'red' }]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); jest.clearAllMocks(); }); it('should register the addon', () => { const onRegisteredSpy = jest.spyOn(SharedService.prototype.gridOptions.rowMoveManager, 'onExtensionRegistered'); - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'registerPlugin'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'registerPlugin'); const instance = extension.loadAddonWhenNotExists(columnsMock, gridOptionsMock); extension.create(columnsMock, gridOptionsMock); diff --git a/packages/common/src/extensions/__tests__/rowSelectionExtension.spec.ts b/packages/common/src/extensions/__tests__/rowSelectionExtension.spec.ts index f5fefe393..0827ae0fb 100644 --- a/packages/common/src/extensions/__tests__/rowSelectionExtension.spec.ts +++ b/packages/common/src/extensions/__tests__/rowSelectionExtension.spec.ts @@ -42,12 +42,12 @@ describe('rowSelectionExtension', () => { describe('registered addon', () => { beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); }); it('should register the addon', () => { - const pluginSpy = jest.spyOn(SharedService.prototype.grid, 'setSelectionModel'); + const pluginSpy = jest.spyOn(SharedService.prototype.slickGrid, 'setSelectionModel'); const instance = extension.register(); const addonInstance = extension.getAddonInstance(); diff --git a/packages/common/src/extensions/autoTooltipExtension.ts b/packages/common/src/extensions/autoTooltipExtension.ts index 5fa3663e5..c3be699d3 100644 --- a/packages/common/src/extensions/autoTooltipExtension.ts +++ b/packages/common/src/extensions/autoTooltipExtension.ts @@ -24,14 +24,14 @@ export class AutoTooltipExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickAutoTooltips | null { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.autoTooltip); const options = this.sharedService.gridOptions.autoTooltipOptions; this._addon = new Slick.AutoTooltips(options); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } return this._addon; diff --git a/packages/common/src/extensions/cellExternalCopyManagerExtension.ts b/packages/common/src/extensions/cellExternalCopyManagerExtension.ts index e1339587e..d0ae035be 100644 --- a/packages/common/src/extensions/cellExternalCopyManagerExtension.ts +++ b/packages/common/src/extensions/cellExternalCopyManagerExtension.ts @@ -64,7 +64,7 @@ export class CellExternalCopyManagerExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickCellExternalCopyManager | null { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.cellExternalCopyManager); @@ -72,14 +72,14 @@ export class CellExternalCopyManagerExtension implements Extension { this.hookUndoShortcutKey(); this._addonOptions = { ...this.getDefaultOptions(), ...this.sharedService.gridOptions.excelCopyBufferOptions } as ExcelCopyBufferOption; - this.sharedService.grid.setSelectionModel(new Slick.CellSelectionModel() as SlickCellSelectionModel); + this.sharedService.slickGrid.setSelectionModel(new Slick.CellSelectionModel() as SlickCellSelectionModel); this._addon = new Slick.CellExternalCopyManager(this._addonOptions); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } // hook to all possible events - if (this.sharedService.grid && this.sharedService.gridOptions.excelCopyBufferOptions) { + if (this.sharedService.slickGrid && this.sharedService.gridOptions.excelCopyBufferOptions) { if (this._addon && this.sharedService.gridOptions.excelCopyBufferOptions.onExtensionRegistered) { this.sharedService.gridOptions.excelCopyBufferOptions.onExtensionRegistered(this._addon); } @@ -158,7 +158,7 @@ export class CellExternalCopyManagerExtension implements Extension { if (!this.sharedService.gridOptions.editable || !columnDef.editor) { const isEvaluatingFormatter = (columnDef.exportWithFormatter !== undefined) ? columnDef.exportWithFormatter : (this.sharedService.gridOptions.exportOptions && this.sharedService.gridOptions.exportOptions.exportWithFormatter); if (columnDef.formatter && isEvaluatingFormatter) { - const formattedOutput = columnDef.formatter(0, 0, item[columnDef.field], columnDef, item, this.sharedService.grid); + const formattedOutput = columnDef.formatter(0, 0, item[columnDef.field], columnDef, item, this.sharedService.slickGrid); if (columnDef.sanitizeDataExport || (this.sharedService.gridOptions.exportOptions && this.sharedService.gridOptions.exportOptions.sanitizeDataExport)) { let outputString = formattedOutput as string; if (formattedOutput && typeof formattedOutput === 'object' && formattedOutput.hasOwnProperty('text')) { @@ -181,7 +181,7 @@ export class CellExternalCopyManagerExtension implements Extension { includeHeaderWhenCopying: false, newRowCreator: (count: number) => { for (let i = 0; i < count; i++) { - this.sharedService.grid.getData().addItem({ id: `newRow_${newRowIds++}` }); + this.sharedService.slickGrid.getData().addItem({ id: `newRow_${newRowIds++}` }); } } }; diff --git a/packages/common/src/extensions/cellMenuExtension.ts b/packages/common/src/extensions/cellMenuExtension.ts index 0b309e259..a31f017d8 100644 --- a/packages/common/src/extensions/cellMenuExtension.ts +++ b/packages/common/src/extensions/cellMenuExtension.ts @@ -56,7 +56,7 @@ export class CellMenuExtension implements Extension { throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.'); } - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { const cellMenu = this.sharedService.gridOptions.cellMenu; // get locales provided by user in main file or else use default English locales via the Constants this._locales = this.sharedService.gridOptions && this.sharedService.gridOptions.locales || Constants.locales; @@ -75,11 +75,11 @@ export class CellMenuExtension implements Extension { this._addon = new Slick.Plugins.CellMenu(this.sharedService.gridOptions.cellMenu); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } // hook all events - if (this.sharedService.grid && this.sharedService.gridOptions.cellMenu) { + if (this.sharedService.slickGrid && this.sharedService.gridOptions.cellMenu) { if (this._addon && this.sharedService.gridOptions.cellMenu.onExtensionRegistered) { this.sharedService.gridOptions.cellMenu.onExtensionRegistered(this._addon); } diff --git a/packages/common/src/extensions/checkboxSelectorExtension.ts b/packages/common/src/extensions/checkboxSelectorExtension.ts index 8df70b91b..8b1a3ab04 100644 --- a/packages/common/src/extensions/checkboxSelectorExtension.ts +++ b/packages/common/src/extensions/checkboxSelectorExtension.ts @@ -56,20 +56,20 @@ export class CheckboxSelectorExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(rowSelectionPlugin?: SlickRowSelectionModel): SlickRowSelectionModel | null { - if (this._addon && this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this._addon && this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // the plugin has to be created BEFORE the grid (else it behaves oddly), but we can only watch grid events AFTER the grid is created - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); // this also requires the Row Selection Model to be registered as well - if (!rowSelectionPlugin || !this.sharedService.grid.getSelectionModel()) { + if (!rowSelectionPlugin || !this.sharedService.slickGrid.getSelectionModel()) { this.extensionUtility.loadExtensionDynamically(ExtensionName.rowSelection); rowSelectionPlugin = new Slick.RowSelectionModel(this.sharedService.gridOptions.rowSelectionOptions); - this.sharedService.grid.setSelectionModel(rowSelectionPlugin); + this.sharedService.slickGrid.setSelectionModel(rowSelectionPlugin); } // user might want to pre-select some rows // the setTimeout is because of timing issue with styling (row selection happen but rows aren't highlighted properly) - if (this.sharedService.gridOptions.preselectedRows && rowSelectionPlugin && this.sharedService.grid.getSelectionModel()) { + if (this.sharedService.gridOptions.preselectedRows && rowSelectionPlugin && this.sharedService.slickGrid.getSelectionModel()) { setTimeout(() => this._addon?.selectRows(this.sharedService.gridOptions.preselectedRows || [])); } diff --git a/packages/common/src/extensions/columnPickerExtension.ts b/packages/common/src/extensions/columnPickerExtension.ts index 498d2cd4f..bc05734b1 100644 --- a/packages/common/src/extensions/columnPickerExtension.ts +++ b/packages/common/src/extensions/columnPickerExtension.ts @@ -33,7 +33,7 @@ export class ColumnPickerExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickColumnPicker | null { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.columnPicker); @@ -46,9 +46,9 @@ export class ColumnPickerExtension implements Extension { this.sharedService.gridOptions.columnPicker.columnTitle = this.sharedService.gridOptions.columnPicker.columnTitle || columnTitle; this.sharedService.gridOptions.columnPicker.forceFitTitle = this.sharedService.gridOptions.columnPicker.forceFitTitle || forceFitTitle; this.sharedService.gridOptions.columnPicker.syncResizeTitle = this.sharedService.gridOptions.columnPicker.syncResizeTitle || syncResizeTitle; - this._addon = new Slick.Controls.ColumnPicker(this.sharedService.allColumns, this.sharedService.grid, this.sharedService.gridOptions); + this._addon = new Slick.Controls.ColumnPicker(this.sharedService.allColumns, this.sharedService.slickGrid, this.sharedService.gridOptions); - if (this.sharedService.grid && this.sharedService.gridOptions.enableColumnPicker) { + if (this.sharedService.slickGrid && this.sharedService.gridOptions.enableColumnPicker) { if (this._addon && this.sharedService.gridOptions.columnPicker.onExtensionRegistered) { this.sharedService.gridOptions.columnPicker.onExtensionRegistered(this._addon); } @@ -69,7 +69,7 @@ export class ColumnPickerExtension implements Extension { /** Translate the Column Picker headers and also the last 2 checkboxes */ translateColumnPicker() { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // update the properties by pointers, that is the only way to get Column Picker Control to see the new values if (this.sharedService.gridOptions.columnPicker) { this.emptyColumnPickerTitles(); diff --git a/packages/common/src/extensions/contextMenuExtension.ts b/packages/common/src/extensions/contextMenuExtension.ts index 5335360fc..b36270f19 100644 --- a/packages/common/src/extensions/contextMenuExtension.ts +++ b/packages/common/src/extensions/contextMenuExtension.ts @@ -61,7 +61,7 @@ export class ContextMenuExtension implements Extension { throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.'); } - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions && this.sharedService.gridOptions.contextMenu) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions && this.sharedService.gridOptions.contextMenu) { const contextMenu = this.sharedService.gridOptions.contextMenu; // keep original user context menu, useful when switching locale to translate this._userOriginalContextMenu = { ...contextMenu }; @@ -77,7 +77,7 @@ export class ContextMenuExtension implements Extension { this._addon = new Slick.Plugins.ContextMenu(contextMenu); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } // translate the item keys when necessary @@ -86,7 +86,7 @@ export class ContextMenuExtension implements Extension { } // hook all events - if (this.sharedService.grid && contextMenu) { + if (this.sharedService.slickGrid && contextMenu) { if (this._addon && contextMenu.onExtensionRegistered) { contextMenu.onExtensionRegistered(this._addon); } @@ -410,7 +410,7 @@ export class ContextMenuExtension implements Extension { const row = args && args.row || 0; const columnDef = args && args.column; const dataContext = args && args.dataContext; - const grid = this.sharedService && this.sharedService.grid; + const grid = this.sharedService && this.sharedService.slickGrid; const exportOptions = gridOptions && (gridOptions.excelExportOptions || gridOptions.exportOptions); let textToCopy = exportWithFormatterWhenDefined(row, cell, dataContext, columnDef, grid, exportOptions); diff --git a/packages/common/src/extensions/draggableGroupingExtension.ts b/packages/common/src/extensions/draggableGroupingExtension.ts index c808a3e39..015c371f5 100644 --- a/packages/common/src/extensions/draggableGroupingExtension.ts +++ b/packages/common/src/extensions/draggableGroupingExtension.ts @@ -51,11 +51,11 @@ export class DraggableGroupingExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickDraggableGrouping | null { - if (this._addon && this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { - this.sharedService.grid.registerPlugin(this._addon); + if (this._addon && this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { + this.sharedService.slickGrid.registerPlugin(this._addon); // Events - if (this.sharedService.grid && this.sharedService.gridOptions.draggableGrouping) { + if (this.sharedService.slickGrid && this.sharedService.gridOptions.draggableGrouping) { if (this._addon && this.sharedService.gridOptions.draggableGrouping.onExtensionRegistered) { this.sharedService.gridOptions.draggableGrouping.onExtensionRegistered(this._addon); } diff --git a/packages/common/src/extensions/gridMenuExtension.ts b/packages/common/src/extensions/gridMenuExtension.ts index a7c4ac338..d7fd62d1d 100644 --- a/packages/common/src/extensions/gridMenuExtension.ts +++ b/packages/common/src/extensions/gridMenuExtension.ts @@ -90,10 +90,10 @@ export class GridMenuExtension implements Extension { this.extensionUtility.translateItems(this.sharedService.gridOptions.gridMenu.customItems, 'titleKey', 'title'); this.extensionUtility.sortItems(this.sharedService.gridOptions.gridMenu.customItems, 'positionOrder'); - this._addon = new Slick.Controls.GridMenu(this.sharedService.allColumns, this.sharedService.grid, this.sharedService.gridOptions); + this._addon = new Slick.Controls.GridMenu(this.sharedService.allColumns, this.sharedService.slickGrid, this.sharedService.gridOptions); // hook all events - if (this.sharedService.grid && this.sharedService.gridOptions.gridMenu) { + if (this.sharedService.slickGrid && this.sharedService.gridOptions.gridMenu) { if (this.sharedService.gridOptions.gridMenu.onExtensionRegistered) { this.sharedService.gridOptions.gridMenu.onExtensionRegistered(this._addon); } @@ -150,12 +150,12 @@ export class GridMenuExtension implements Extension { } // we also want to resize the columns if the user decided to hide certain column(s) - if (this.sharedService.grid && typeof this.sharedService.grid.autosizeColumns === 'function') { + if (this.sharedService.slickGrid && typeof this.sharedService.slickGrid.autosizeColumns === 'function') { // make sure that the grid still exist (by looking if the Grid UID is found in the DOM tree) - const gridUid = this.sharedService.grid.getUID(); + const gridUid = this.sharedService.slickGrid.getUID(); if (this._areVisibleColumnDifferent && gridUid && $(`.${gridUid}`).length > 0) { if (this.sharedService.gridOptions && this.sharedService.gridOptions.enableAutoSizeColumns) { - this.sharedService.grid.autosizeColumns(); + this.sharedService.slickGrid.autosizeColumns(); } this._areVisibleColumnDifferent = false; } @@ -394,9 +394,9 @@ export class GridMenuExtension implements Extension { switch (args.command) { case 'clear-frozen-columns': const visibleColumns = [...this.sharedService.visibleColumns]; - this.sharedService.grid.setOptions({ frozenColumn: -1 }); + this.sharedService.slickGrid.setOptions({ frozenColumn: -1 }); if (Array.isArray(visibleColumns) && Array.isArray(this.sharedService.allColumns) && visibleColumns.length !== this.sharedService.allColumns.length) { - this.sharedService.grid.setColumns(visibleColumns); + this.sharedService.slickGrid.setColumns(visibleColumns); } break; case 'clear-filter': @@ -447,20 +447,20 @@ export class GridMenuExtension implements Extension { case 'toggle-filter': let showHeaderRow = this.sharedService && this.sharedService.gridOptions && this.sharedService.gridOptions.showHeaderRow || false; showHeaderRow = !showHeaderRow; // inverse show header flag - this.sharedService.grid.setHeaderRowVisibility(showHeaderRow); + this.sharedService.slickGrid.setHeaderRowVisibility(showHeaderRow); // when displaying header row, we'll call "setColumns" which in terms will recreate the header row filters if (showHeaderRow === true) { - this.sharedService.grid.setColumns(this.sharedService.columnDefinitions); + this.sharedService.slickGrid.setColumns(this.sharedService.columnDefinitions); } break; case 'toggle-toppanel': const showTopPanel = this.sharedService && this.sharedService.gridOptions && this.sharedService.gridOptions.showTopPanel || false; - this.sharedService.grid.setTopPanelVisibility(!showTopPanel); + this.sharedService.slickGrid.setTopPanelVisibility(!showTopPanel); break; case 'toggle-preheader': const showPreHeaderPanel = this.sharedService && this.sharedService.gridOptions && this.sharedService.gridOptions.showPreHeaderPanel || false; - this.sharedService.grid.setPreHeaderPanelVisibility(!showPreHeaderPanel); + this.sharedService.slickGrid.setPreHeaderPanelVisibility(!showPreHeaderPanel); break; case 'refresh-dataset': this.refreshBackendDataset(); diff --git a/packages/common/src/extensions/groupItemMetaProviderExtension.ts b/packages/common/src/extensions/groupItemMetaProviderExtension.ts index 9cbf1758d..1b7ef4a9b 100644 --- a/packages/common/src/extensions/groupItemMetaProviderExtension.ts +++ b/packages/common/src/extensions/groupItemMetaProviderExtension.ts @@ -19,10 +19,10 @@ export class GroupItemMetaProviderExtension implements Extension { /** register the group item metadata provider to add expand/collapse group handlers */ register(): SlickGroupItemMetadataProvider | null { - if (this.sharedService && this.sharedService.grid) { + if (this.sharedService && this.sharedService.slickGrid) { this._addon = this.sharedService.groupItemMetadataProvider; if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } return this._addon; } diff --git a/packages/common/src/extensions/headerButtonExtension.ts b/packages/common/src/extensions/headerButtonExtension.ts index de2b8154c..3728bd3c8 100644 --- a/packages/common/src/extensions/headerButtonExtension.ts +++ b/packages/common/src/extensions/headerButtonExtension.ts @@ -34,17 +34,17 @@ export class HeaderButtonExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickHeaderButtons | null { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.headerButton); this._addon = new Slick.Plugins.HeaderButtons(this.sharedService.gridOptions.headerButton); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } // hook all events - if (this._addon && this.sharedService.grid && this.sharedService.gridOptions.headerButton) { + if (this._addon && this.sharedService.slickGrid && this.sharedService.gridOptions.headerButton) { if (this.sharedService.gridOptions.headerButton.onExtensionRegistered) { this.sharedService.gridOptions.headerButton.onExtensionRegistered(this._addon); } diff --git a/packages/common/src/extensions/headerMenuExtension.ts b/packages/common/src/extensions/headerMenuExtension.ts index 1a37dfa79..7850d83f3 100644 --- a/packages/common/src/extensions/headerMenuExtension.ts +++ b/packages/common/src/extensions/headerMenuExtension.ts @@ -68,7 +68,7 @@ export class HeaderMenuExtension implements Extension { throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.'); } - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // get locales provided by user in main file or else use default English locales via the Constants this._locales = this.sharedService.gridOptions && this.sharedService.gridOptions.locales || Constants.locales; @@ -81,11 +81,11 @@ export class HeaderMenuExtension implements Extension { } this._addon = new Slick.Plugins.HeaderMenu(this.sharedService.gridOptions.headerMenu); if (this._addon) { - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); } // hook all events - if (this._addon && this.sharedService.grid && this.sharedService.gridOptions.headerMenu) { + if (this._addon && this.sharedService.slickGrid && this.sharedService.gridOptions.headerMenu) { if (this.sharedService.gridOptions.headerMenu.onExtensionRegistered) { this.sharedService.gridOptions.headerMenu.onExtensionRegistered(this._addon); } @@ -235,12 +235,12 @@ export class HeaderMenuExtension implements Extension { /** Hide a column from the grid */ hideColumn(column: Column) { - if (this.sharedService.grid && this.sharedService.grid.getColumns && this.sharedService.grid.setColumns && this.sharedService.grid.getColumnIndex) { - const columnIndex = this.sharedService.grid.getColumnIndex(column.id); - const currentColumns = this.sharedService.grid.getColumns(); + if (this.sharedService.slickGrid && this.sharedService.slickGrid.getColumns && this.sharedService.slickGrid.setColumns && this.sharedService.slickGrid.getColumnIndex) { + const columnIndex = this.sharedService.slickGrid.getColumnIndex(column.id); + const currentColumns = this.sharedService.slickGrid.getColumns(); const visibleColumns = this.extensionUtility.arrayRemoveItemByIndex(currentColumns, columnIndex); this.sharedService.visibleColumns = visibleColumns; - this.sharedService.grid.setColumns(visibleColumns); + this.sharedService.slickGrid.setColumns(visibleColumns); this.pubSubService.publish('onHeaderMenuColumnsChanged', { columns: visibleColumns }); } } @@ -336,7 +336,7 @@ export class HeaderMenuExtension implements Extension { case 'hide': this.hideColumn(args.column); if (this.sharedService.gridOptions && this.sharedService.gridOptions.enableAutoSizeColumns) { - this.sharedService.grid.autosizeColumns(); + this.sharedService.slickGrid.autosizeColumns(); } break; case 'clear-filter': @@ -348,12 +348,12 @@ export class HeaderMenuExtension implements Extension { case 'freeze-columns': const visibleColumns = [...this.sharedService.visibleColumns]; const columnPosition = visibleColumns.findIndex((col) => col.id === args.column.id); - this.sharedService.grid.setOptions({ frozenColumn: columnPosition, alwaysShowVerticalScroll: false }); + this.sharedService.slickGrid.setOptions({ frozenColumn: columnPosition, alwaysShowVerticalScroll: false }); // to freeze columns, we need to take only the visible columns and we also need to use setColumns() when some of them are hidden // to make sure that we only use the visible columns, not doing this would show back some of the hidden columns if (Array.isArray(visibleColumns) && Array.isArray(this.sharedService.allColumns) && visibleColumns.length !== this.sharedService.allColumns.length) { - this.sharedService.grid.setColumns(visibleColumns); + this.sharedService.slickGrid.setColumns(visibleColumns); } break; case 'sort-asc': @@ -379,10 +379,10 @@ export class HeaderMenuExtension implements Extension { // add to the column array, the column sorted by the header menu sortedColsWithoutCurrent.push({ columnId: columnDef.id, sortCol: columnDef, sortAsc: isSortingAsc }); if (this.sharedService.gridOptions.backendServiceApi) { - this.sortService.onBackendSortChanged(event, { multiColumnSort: true, sortCols: sortedColsWithoutCurrent, grid: this.sharedService.grid }); + this.sortService.onBackendSortChanged(event, { multiColumnSort: true, sortCols: sortedColsWithoutCurrent, grid: this.sharedService.slickGrid }); emitterType = EmitterType.remote; } else if (this.sharedService.dataView) { - this.sortService.onLocalSortChanged(this.sharedService.grid, sortedColsWithoutCurrent); + this.sortService.onLocalSortChanged(this.sharedService.slickGrid, sortedColsWithoutCurrent); emitterType = EmitterType.local; } else { // when using customDataView, we will simply send it as a onSort event with notify @@ -400,7 +400,7 @@ export class HeaderMenuExtension implements Extension { }); // add sort icon in UI - this.sharedService.grid.setSortColumns(newSortColumns); + this.sharedService.slickGrid.setSortColumns(newSortColumns); // if we have an emitter type set, we will emit a sort changed // for the Grid State Service to see the change. diff --git a/packages/common/src/extensions/rowMoveManagerExtension.ts b/packages/common/src/extensions/rowMoveManagerExtension.ts index 1e9f67ec9..723826a25 100644 --- a/packages/common/src/extensions/rowMoveManagerExtension.ts +++ b/packages/common/src/extensions/rowMoveManagerExtension.ts @@ -90,21 +90,21 @@ export class RowMoveManagerExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(rowSelectionPlugin?: SlickRowSelectionModel): SlickRowMoveManager | null { - if (this._addon && this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this._addon && this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.rowMoveManager); // this also requires the Row Selection Model to be registered as well - if (!rowSelectionPlugin || !this.sharedService.grid.getSelectionModel()) { + if (!rowSelectionPlugin || !this.sharedService.slickGrid.getSelectionModel()) { this.extensionUtility.loadExtensionDynamically(ExtensionName.rowSelection); rowSelectionPlugin = new Slick.RowSelectionModel(this.sharedService.gridOptions.rowSelectionOptions); - this.sharedService.grid.setSelectionModel(rowSelectionPlugin); + this.sharedService.slickGrid.setSelectionModel(rowSelectionPlugin); } - this.sharedService.grid.registerPlugin(this._addon); + this.sharedService.slickGrid.registerPlugin(this._addon); // hook all events - if (this._addon && this.sharedService.grid && this.sharedService.gridOptions.rowMoveManager) { + if (this._addon && this.sharedService.slickGrid && this.sharedService.gridOptions.rowMoveManager) { if (this.sharedService.gridOptions.rowMoveManager.onExtensionRegistered) { this.sharedService.gridOptions.rowMoveManager.onExtensionRegistered(this._addon); } diff --git a/packages/common/src/extensions/rowSelectionExtension.ts b/packages/common/src/extensions/rowSelectionExtension.ts index 9828fe12a..d2691bfa2 100644 --- a/packages/common/src/extensions/rowSelectionExtension.ts +++ b/packages/common/src/extensions/rowSelectionExtension.ts @@ -25,13 +25,13 @@ export class RowSelectionExtension implements Extension { /** Register the 3rd party addon (plugin) */ register(): SlickRowSelectionModel | null { - if (this.sharedService && this.sharedService.grid && this.sharedService.gridOptions) { + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.gridOptions) { // dynamically import the SlickGrid plugin (addon) with RequireJS this.extensionUtility.loadExtensionDynamically(ExtensionName.rowSelection); this._addon = new Slick.RowSelectionModel(this.sharedService.gridOptions.rowSelectionOptions); if (this._addon) { - this.sharedService.grid.setSelectionModel(this._addon); + this.sharedService.slickGrid.setSelectionModel(this._addon); } return this._addon; } diff --git a/packages/common/src/interfaces/draggableGroupingOption.interface.ts b/packages/common/src/interfaces/draggableGroupingOption.interface.ts index 531d929e4..0a6a8d8fa 100644 --- a/packages/common/src/interfaces/draggableGroupingOption.interface.ts +++ b/packages/common/src/interfaces/draggableGroupingOption.interface.ts @@ -1,3 +1,4 @@ +import { ColumnReorderFunction } from '../enums/columnReorderFunction.type'; import { GroupingGetterFunction } from './grouping.interface'; export interface DraggableGroupingOption { @@ -26,5 +27,5 @@ export interface DraggableGroupingOption { clearDroppedGroups?: () => void; /** its function to setup draggable feature agains Header Column, should be passed on grid option. Also possible to pass custom function */ - getSetupColumnReorder?: () => void; + getSetupColumnReorder?: ColumnReorderFunction; } diff --git a/packages/common/src/interfaces/gridOption.interface.ts b/packages/common/src/interfaces/gridOption.interface.ts index 4df15b918..0b77eb51b 100644 --- a/packages/common/src/interfaces/gridOption.interface.ts +++ b/packages/common/src/interfaces/gridOption.interface.ts @@ -25,7 +25,7 @@ import { RowSelectionModelOption, TreeDataOption, } from './index'; -import { EventNamingStyle, GridAutosizeColsMode, OperatorType, OperatorString, } from '../enums/index'; +import { ColumnReorderFunction, EventNamingStyle, GridAutosizeColsMode, OperatorType, OperatorString, } from '../enums/index'; import { TranslaterService } from '../services/translater.service'; export interface GridOption { @@ -196,7 +196,7 @@ export interface GridOption { enableColumnPicker?: boolean; /** Defaults to true, which permits the user to move an entire column from a position to another. */ - enableColumnReorder?: boolean; + enableColumnReorder?: boolean | ColumnReorderFunction; /** Do we want to enable Context Menu? (mouse right+click) */ enableContextMenu?: boolean; diff --git a/packages/common/src/interfaces/slickDraggableGrouping.interface.ts b/packages/common/src/interfaces/slickDraggableGrouping.interface.ts index afebb7441..ebc3f6bdf 100644 --- a/packages/common/src/interfaces/slickDraggableGrouping.interface.ts +++ b/packages/common/src/interfaces/slickDraggableGrouping.interface.ts @@ -5,6 +5,7 @@ import { SlickEvent, SlickGrid, } from './index'; +import { ColumnReorderFunction } from '../enums/columnReorderFunction.type'; /** This plugin provides the Draggable Grouping feature */ export interface SlickDraggableGrouping { @@ -23,7 +24,7 @@ export interface SlickDraggableGrouping { clearDroppedGroups?: () => void; /** its function to setup draggable feature agains Header Column, should be passed on grid option. Also possible to pass custom function */ - getSetupColumnReorder?: () => void; + getSetupColumnReorder?: ColumnReorderFunction; /** provide option to set default grouping on loading */ setDroppedGroups?: (groupingInfo: Array | string) => void; diff --git a/packages/common/src/interfaces/slickGrid.interface.ts b/packages/common/src/interfaces/slickGrid.interface.ts index 7f1ea2802..59693b256 100644 --- a/packages/common/src/interfaces/slickGrid.interface.ts +++ b/packages/common/src/interfaces/slickGrid.interface.ts @@ -1,4 +1,4 @@ -import { SlickPluginList } from '../enums'; +import { SlickPluginList } from '../enums/index'; import { Column, ColumnSort, diff --git a/packages/common/src/services/__tests__/extension.service.spec.ts b/packages/common/src/services/__tests__/extension.service.spec.ts index 4aac3e64c..39f17d415 100644 --- a/packages/common/src/services/__tests__/extension.service.spec.ts +++ b/packages/common/src/services/__tests__/extension.service.spec.ts @@ -116,15 +116,13 @@ describe('ExtensionService', () => { }); it('should return "autosizeColumns" from the SharedService Grid object when "autoResizeColumns" method is called', () => { - const spy = jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + const spy = jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); service.autoResizeColumns(); expect(spy).toHaveBeenCalled(); }); - it('should return empty array when "getAllExtensions" method is called', () => { - const spy = jest.spyOn(service, 'getAllExtensions'); - service.getAllExtensions(); - expect(spy).toHaveReturnedWith([]); + it('should return empty object when "extensionlList" GETTER is called', () => { + expect(service.extensionList).toEqual({}); }); describe('getSlickgridAddonInstance method', () => { @@ -447,7 +445,7 @@ describe('ExtensionService', () => { it('should call hideColumn and expect "visibleColumns" to be updated accordingly', () => { const columnsMock = [{ id: 'field1', width: 100 }, { id: 'field2', width: 150 }, { id: 'field3', field: 'field3' }] as Column[]; const updatedColumnsMock = [{ id: 'field1', width: 100 }, { id: 'field3', field: 'field3' }] as Column[]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(gridStub, 'getColumnIndex').mockReturnValue(1); jest.spyOn(gridStub, 'getColumns').mockReturnValue(columnsMock); const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); @@ -568,7 +566,7 @@ describe('ExtensionService', () => { it('should call "setColumns" on the Shared Service with the Shared "columnDefinitions" when no arguments is provided', () => { const columnsMock = [{ id: 'field1', field: 'field1', nameKey: 'HELLO' }] as Column[]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); const colSpy = jest.spyOn(SharedService.prototype, 'columnDefinitions', 'get').mockReturnValue(columnsMock); const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); @@ -583,7 +581,7 @@ describe('ExtensionService', () => { { id: 'field1', field: 'field1', nameKey: 'HELLO' }, { id: 'field2', field: 'field2', nameKey: 'WORLD' } ] as Column[]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); const allColsSpy = jest.spyOn(SharedService.prototype, 'allColumns', 'set'); const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); @@ -598,7 +596,7 @@ describe('ExtensionService', () => { const columnsMock = [ { id: 'field1', field: 'field1', nameKey: 'HELLO' } ] as Column[]; - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); const spyAllCols = jest.spyOn(SharedService.prototype, 'allColumns', 'set'); const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); @@ -618,7 +616,7 @@ describe('ExtensionService', () => { { id: 'field2', field: 'field2', nameKey: 'WORLD' } ] as Column[]; jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); const spyGetExt = jest.spyOn(service, 'getExtensionByName').mockReturnValue(extensionMock); const spyCpDispose = jest.spyOn(extensionColumnPickerStub, 'dispose'); const spyCpRegister = jest.spyOn(extensionColumnPickerStub, 'register'); @@ -644,7 +642,7 @@ describe('ExtensionService', () => { ] as Column[]; jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); const spyGetExt = jest.spyOn(service, 'getExtensionByName').mockReturnValue(extensionMock); const spyGmDispose = jest.spyOn(extensionGridMenuStub, 'dispose'); const spyGmRegister = jest.spyOn(extensionGridMenuStub, 'register').mockReturnValue(instanceMock); diff --git a/packages/common/src/services/__tests__/shared.service.spec.ts b/packages/common/src/services/__tests__/shared.service.spec.ts index b86890f01..b532a70bc 100644 --- a/packages/common/src/services/__tests__/shared.service.spec.ts +++ b/packages/common/src/services/__tests__/shared.service.spec.ts @@ -1,6 +1,6 @@ import { SharedService } from '../shared.service'; import { PubSubService } from '../pubSub.service'; -import { Column, CurrentPagination, SlickDataView, GridOption, SlickGrid } from '../../interfaces/index'; +import { Column, CurrentPagination, SlickDataView, GridOption, SlickGrid, SlickGroupItemMetadataProvider } from '../../interfaces/index'; import { ExcelExportService } from '../excelExport.service'; jest.mock('flatpickr', () => { }); @@ -77,7 +77,7 @@ describe('Shared Service', () => { it('should call "columnDefinitions" GETTER and expect columns array returned', () => { const columnSpy = jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns); - service.grid = gridStub; + service.slickGrid = gridStub; const columns = service.columnDefinitions; expect(columnSpy).toHaveBeenCalled(); @@ -129,20 +129,20 @@ describe('Shared Service', () => { }); it('should call "grid" GETTER and return the grid object', () => { - const spy = jest.spyOn(service, 'grid', 'get').mockReturnValue(gridStub); + const spy = jest.spyOn(service, 'slickGrid', 'get').mockReturnValue(gridStub); - const output = service.grid; + const output = service.slickGrid; expect(spy).toHaveBeenCalled(); expect(output).toEqual(gridStub); }); it('should call "grid" SETTER and expect GETTER to return the same', () => { - const getSpy = jest.spyOn(service, 'grid', 'get'); - const setSpy = jest.spyOn(service, 'grid', 'set'); + const getSpy = jest.spyOn(service, 'slickGrid', 'get'); + const setSpy = jest.spyOn(service, 'slickGrid', 'set'); - service.grid = gridStub; - const output = service.grid; + service.slickGrid = gridStub; + const output = service.slickGrid; expect(getSpy).toHaveBeenCalled(); expect(setSpy).toHaveBeenCalled(); @@ -166,7 +166,7 @@ describe('Shared Service', () => { it('should call "gridOptions" GETTER and expect options array returned', () => { const spy = jest.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptions); - service.grid = gridStub; + service.slickGrid = gridStub; const options = service.gridOptions; expect(spy).toHaveBeenCalled(); @@ -186,7 +186,7 @@ describe('Shared Service', () => { }); it('should call "groupItemMetadataProvider" GETTER and return metadata', () => { - const spy = jest.spyOn(service, 'groupItemMetadataProvider', 'get').mockReturnValue(mockColumns); + const spy = jest.spyOn(service, 'groupItemMetadataProvider', 'get').mockReturnValue(mockColumns as unknown as SlickGroupItemMetadataProvider); const output = service.groupItemMetadataProvider; @@ -198,7 +198,7 @@ describe('Shared Service', () => { const getSpy = jest.spyOn(service, 'groupItemMetadataProvider', 'get'); const setSpy = jest.spyOn(service, 'groupItemMetadataProvider', 'set'); - service.groupItemMetadataProvider = mockColumns; + service.groupItemMetadataProvider = mockColumns as unknown as SlickGroupItemMetadataProvider; const output = service.groupItemMetadataProvider; expect(getSpy).toHaveBeenCalled(); diff --git a/packages/common/src/services/extension.service.ts b/packages/common/src/services/extension.service.ts index 04b0e6bd7..9de3cc00f 100644 --- a/packages/common/src/services/extension.service.ts +++ b/packages/common/src/services/extension.service.ts @@ -4,7 +4,7 @@ import 'slickgrid/plugins/slick.cellrangeselector'; import 'slickgrid/plugins/slick.cellselectionmodel'; import { Column, Extension, ExtensionModel, GridOption, SlickRowSelectionModel, } from '../interfaces/index'; -import { ExtensionName, SlickControlList, SlickPluginList } from '../enums/index'; +import { ExtensionList, ExtensionName, SlickControlList, SlickPluginList } from '../enums/index'; import { AutoTooltipExtension, CellExternalCopyManagerExtension, @@ -25,8 +25,12 @@ import { SharedService } from './shared.service'; import { TranslaterService } from './translater.service'; export class ExtensionService { - private _extensionCreatedList: any[] = []; - private _extensionList: ExtensionModel[] = []; + private _extensionCreatedList: ExtensionList = {} as ExtensionList; + private _extensionList: ExtensionList = {} as ExtensionList; + + get extensionList() { + return this._extensionList; + } constructor( private autoTooltipExtension: AutoTooltipExtension, @@ -52,12 +56,15 @@ export class ExtensionService { this.sharedService.visibleColumns = []; // dispose of each control/plugin & reset the list - this._extensionList.forEach((item) => { - if (item && item.class && item.class.dispose) { - item.class.dispose(); + for (const extensionName of Object.keys(this._extensionList)) { + if (this._extensionList.hasOwnProperty(extensionName)) { + const extension = this._extensionList[extensionName] as ExtensionModel; + if (extension && extension.class && extension.class.dispose) { + extension.class.dispose(); + } } - }); - this._extensionList = []; + } + this._extensionList = {} as ExtensionList; } /** Get all columns (includes visible and non-visible) */ @@ -70,20 +77,15 @@ export class ExtensionService { return this.sharedService.visibleColumns || []; } - /** Get all Extensions */ - getAllExtensions(): ExtensionModel[] { - return this._extensionList; - } - /** * Get an Extension by it's name * @param name */ getExtensionByName

(name: ExtensionName): ExtensionModel | undefined { - if (!Array.isArray(this._extensionList) || this._extensionList.length === 0) { - return undefined; + if (this._extensionList && this._extensionList[name]) { + return this._extensionList[name]; } - return this._extensionList.find(ext => ext.name === name); + return undefined; } /** @@ -104,7 +106,7 @@ export class ExtensionService { /** Auto-resize all the column in the grid to fit the grid width */ autoResizeColumns() { - this.sharedService.grid.autosizeColumns(); + this.sharedService.slickGrid.autosizeColumns(); } /** Bind/Create different Controls or Plugins after the Grid is created */ @@ -120,7 +122,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableAutoTooltip && this.autoTooltipExtension && this.autoTooltipExtension.register) { const instance = this.autoTooltipExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.autoTooltip, class: this.autoTooltipExtension, instance }); + this._extensionList[ExtensionName.autoTooltip] = { name: ExtensionName.autoTooltip, class: this.autoTooltipExtension, instance }; } } @@ -128,7 +130,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableExcelCopyBuffer && this.cellExternalCopyExtension && this.cellExternalCopyExtension.register) { const instance = this.cellExternalCopyExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.cellExternalCopyManager, class: this.cellExternalCopyExtension, instance }); + this._extensionList[ExtensionName.cellExternalCopyManager] = { name: ExtensionName.cellExternalCopyManager, class: this.cellExternalCopyExtension, instance }; } } @@ -136,7 +138,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableCellMenu && this.cellMenuExtension && this.cellMenuExtension.register) { const instance = this.cellMenuExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.cellMenu, class: this.cellMenuExtension, instance }); + this._extensionList[ExtensionName.cellMenu] = { name: ExtensionName.cellMenu, class: this.cellMenuExtension, instance }; } } @@ -146,7 +148,7 @@ export class ExtensionService { if (this.rowSelectionExtension && this.rowSelectionExtension.register) { const instance = this.rowSelectionExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.rowSelection, class: this.rowSelectionExtension, instance }); + this._extensionList[ExtensionName.rowSelection] = { name: ExtensionName.rowSelection, class: this.rowSelectionExtension, instance }; } } } @@ -158,7 +160,7 @@ export class ExtensionService { const createdExtension = this.getCreatedExtensionByName(ExtensionName.checkboxSelector); // get the instance from when it was really created earlier const instance = createdExtension && createdExtension.instance; if (instance) { - this._extensionList.push({ name: ExtensionName.checkboxSelector, class: this.checkboxSelectorExtension, instance }); + this._extensionList[ExtensionName.checkboxSelector] = { name: ExtensionName.checkboxSelector, class: this.checkboxSelectorExtension, instance }; } } @@ -166,7 +168,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableColumnPicker && this.columnPickerExtension && this.columnPickerExtension.register) { const instance = this.columnPickerExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.columnPicker, class: this.columnPickerExtension, instance }); + this._extensionList[ExtensionName.columnPicker] = { name: ExtensionName.columnPicker, class: this.columnPickerExtension, instance }; } } @@ -174,7 +176,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableContextMenu && this.contextMenuExtension && this.contextMenuExtension.register) { const instance = this.contextMenuExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.contextMenu, class: this.contextMenuExtension, instance }); + this._extensionList[ExtensionName.contextMenu] = { name: ExtensionName.contextMenu, class: this.contextMenuExtension, instance }; } } @@ -182,7 +184,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableDraggableGrouping && this.draggableGroupingExtension && this.draggableGroupingExtension.register) { const instance = this.draggableGroupingExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.draggableGrouping, class: this.draggableGroupingExtension, instance }); + this._extensionList[ExtensionName.draggableGrouping] = { name: ExtensionName.draggableGrouping, class: this.draggableGroupingExtension, instance }; } } @@ -190,7 +192,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableGridMenu && this.gridMenuExtension && this.gridMenuExtension.register) { const instance = this.gridMenuExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.gridMenu, class: this.gridMenuExtension, instance }); + this._extensionList[ExtensionName.gridMenu] = { name: ExtensionName.gridMenu, class: this.gridMenuExtension, instance }; } } @@ -200,7 +202,7 @@ export class ExtensionService { if (this.groupItemMetaExtension && this.groupItemMetaExtension.register) { const instance = this.groupItemMetaExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.groupItemMetaProvider, class: this.groupItemMetaExtension, instance }); + this._extensionList[ExtensionName.groupItemMetaProvider] = { name: ExtensionName.groupItemMetaProvider, class: this.groupItemMetaExtension, instance }; } } } @@ -209,7 +211,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableHeaderButton && this.headerButtonExtension && this.headerButtonExtension.register) { const instance = this.headerButtonExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.headerButton, class: this.headerButtonExtension, instance }); + this._extensionList[ExtensionName.headerButton] = { name: ExtensionName.headerButton, class: this.headerButtonExtension, instance }; } } @@ -217,7 +219,7 @@ export class ExtensionService { if (this.sharedService.gridOptions.enableHeaderMenu && this.headerMenuExtension && this.headerMenuExtension.register) { const instance = this.headerMenuExtension.register(); if (instance) { - this._extensionList.push({ name: ExtensionName.headerMenu, class: this.headerMenuExtension, instance }); + this._extensionList[ExtensionName.headerMenu] = { name: ExtensionName.headerMenu, class: this.headerMenuExtension, instance }; } } @@ -229,7 +231,7 @@ export class ExtensionService { // const createdExtension = this.getCreatedExtensionByName(ExtensionName.rowDetailView); // get the plugin from when it was really created earlier // const instance = createdExtension && createdExtension.instance; // if (instance) { - // this._extensionList.push({ name: ExtensionName.rowDetailView, class: this.rowDetailViewExtension, instance }); + // this._extensionList[ExtensionName.rowDetailView] ={ name: ExtensionName.rowDetailView, class: this.rowDetailViewExtension, instance }; // } // } // } @@ -241,7 +243,7 @@ export class ExtensionService { const createdExtension = this.getCreatedExtensionByName(ExtensionName.rowMoveManager); // get the instance from when it was really created earlier const instance = createdExtension && createdExtension.instance; if (instance) { - this._extensionList.push({ name: ExtensionName.rowMoveManager, class: this.rowMoveManagerExtension, instance }); + this._extensionList[ExtensionName.rowMoveManager] = { name: ExtensionName.rowMoveManager, class: this.rowMoveManagerExtension, instance }; } } } @@ -258,7 +260,7 @@ export class ExtensionService { if (!this.getCreatedExtensionByName(ExtensionName.checkboxSelector)) { const checkboxInstance = this.checkboxSelectorExtension.create(columnDefinitions, options); if (checkboxInstance) { - this._extensionCreatedList.push({ name: ExtensionName.checkboxSelector, instance: checkboxInstance }); + this._extensionCreatedList[ExtensionName.checkboxSelector] = { name: ExtensionName.checkboxSelector, instance: checkboxInstance, class: this.checkboxSelectorExtension }; } } } @@ -266,22 +268,22 @@ export class ExtensionService { if (!this.getCreatedExtensionByName(ExtensionName.rowMoveManager)) { const rowMoveInstance = this.rowMoveManagerExtension.create(columnDefinitions, options); if (rowMoveInstance) { - this._extensionCreatedList.push({ name: ExtensionName.rowMoveManager, instance: rowMoveInstance }); + this._extensionCreatedList[ExtensionName.rowMoveManager] = { name: ExtensionName.rowMoveManager, instance: rowMoveInstance, class: this.rowMoveManagerExtension }; } } } // if (options.enableRowDetailView) { // if (!this.getCreatedExtensionByName(ExtensionName.rowDetailView)) { // const rowDetailInstance = this.rowDetailViewExtension.create(columnDefinitions, options); - // this._extensionCreatedList.push({ name: ExtensionName.rowDetailView, instance: rowDetailInstance }); + // this._extensionCreatedList[ExtensionName.rowDetailView] = { name: ExtensionName.rowDetailView, instance: rowDetailInstance, class: this.rowDetailViewExtension }; // } // } if (options.enableDraggableGrouping) { if (!this.getCreatedExtensionByName(ExtensionName.draggableGrouping)) { const draggableInstance = this.draggableGroupingExtension.create(options); - options.enableColumnReorder = draggableInstance?.getSetupColumnReorder !== undefined; if (draggableInstance) { - this._extensionCreatedList.push({ name: ExtensionName.draggableGrouping, instance: draggableInstance }); + options.enableColumnReorder = draggableInstance.getSetupColumnReorder; + this._extensionCreatedList[ExtensionName.draggableGrouping] = { name: ExtensionName.draggableGrouping, instance: draggableInstance, class: this.draggableGroupingExtension }; } } } @@ -289,10 +291,10 @@ export class ExtensionService { /** Hide a column from the grid */ hideColumn(column: Column) { - if (this.sharedService && this.sharedService.grid && this.sharedService.grid.getColumns && this.sharedService.grid.setColumns) { - const columnIndex = this.sharedService.grid.getColumnIndex(column.id); - this.sharedService.visibleColumns = this.removeColumnByIndex(this.sharedService.grid.getColumns(), columnIndex); - this.sharedService.grid.setColumns(this.sharedService.visibleColumns); + if (this.sharedService && this.sharedService.slickGrid && this.sharedService.slickGrid.getColumns && this.sharedService.slickGrid.setColumns) { + const columnIndex = this.sharedService.slickGrid.getColumnIndex(column.id); + this.sharedService.visibleColumns = this.removeColumnByIndex(this.sharedService.slickGrid.getColumns(), columnIndex); + this.sharedService.slickGrid.setColumns(this.sharedService.visibleColumns); } } @@ -389,11 +391,11 @@ export class ExtensionService { if (!collection) { collection = this.sharedService.columnDefinitions; } - if (Array.isArray(collection) && this.sharedService.grid && this.sharedService.grid.setColumns) { + if (Array.isArray(collection) && this.sharedService.slickGrid && this.sharedService.slickGrid.setColumns) { if (collection.length > this.sharedService.allColumns.length || forceColumnDefinitionsOverwrite) { this.sharedService.allColumns = collection; } - this.sharedService.grid.setColumns(collection); + this.sharedService.slickGrid.setColumns(collection); } // dispose of previous Column Picker instance, then re-register it and don't forget to overwrite previous instance ref @@ -426,7 +428,10 @@ export class ExtensionService { * @param name */ private getCreatedExtensionByName

(name: ExtensionName): ExtensionModel | undefined { - return Array.isArray(this._extensionCreatedList) && this._extensionCreatedList.find((p) => p.name === name); + if (this._extensionCreatedList && this._extensionCreatedList.hasOwnProperty(name)) { + return this._extensionCreatedList[name]; + } + return undefined; } /** Translate an array of items from an input key and assign translated value to the output key */ diff --git a/packages/common/src/services/shared.service.ts b/packages/common/src/services/shared.service.ts index f645c7adc..57473c2d5 100644 --- a/packages/common/src/services/shared.service.ts +++ b/packages/common/src/services/shared.service.ts @@ -51,11 +51,11 @@ export class SharedService { } /** Getter for SlickGrid Grid object */ - get grid(): SlickGrid { + get slickGrid(): SlickGrid { return this._grid; } /** Setter for SlickGrid Grid object */ - set grid(grid: SlickGrid) { + set slickGrid(grid: SlickGrid) { this._grid = grid; } diff --git a/packages/excel-export/package.json b/packages/excel-export/package.json index 719d5b8a4..6a46f01f2 100644 --- a/packages/excel-export/package.json +++ b/packages/excel-export/package.json @@ -23,7 +23,7 @@ "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", "bundle": "npm-run-all bundle:commonjs bundle:es2015 bundle:es2020", "prebundle": "npm-run-all delete:dist", - "delete:dist": "cross-env rimraf dist" + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist" }, "author": "Ghislain B.", "license": "MIT", diff --git a/packages/file-export/package.json b/packages/file-export/package.json index 3cca8359e..8c371cf23 100644 --- a/packages/file-export/package.json +++ b/packages/file-export/package.json @@ -23,7 +23,7 @@ "bundle:es2015": "cross-env tsc --project tsconfig.build.json --outDir dist/es2015 --module es2020 --target es2015", "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", "prebundle": "npm-run-all delete:dist", - "delete:dist": "cross-env rimraf dist" + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist" }, "author": "Ghislain B.", "license": "MIT", diff --git a/packages/graphql/package.json b/packages/graphql/package.json index c0c666ae3..4e04dd217 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -23,7 +23,7 @@ "bundle:es2015": "cross-env tsc --project tsconfig.build.json --outDir dist/es2015 --module es2020 --target es2015", "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", "prebundle": "npm-run-all delete:dist", - "delete:dist": "cross-env rimraf dist" + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist" }, "author": "Ghislain B.", "license": "MIT", diff --git a/packages/odata/package.json b/packages/odata/package.json index 36e2049b1..f908eb030 100644 --- a/packages/odata/package.json +++ b/packages/odata/package.json @@ -23,7 +23,7 @@ "bundle:es2015": "cross-env tsc --project tsconfig.build.json --outDir dist/es2015 --module es2020 --target es2015", "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", "prebundle": "npm-run-all delete:dist", - "delete:dist": "cross-env rimraf dist" + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist" }, "author": "Ghislain B.", "license": "MIT", diff --git a/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip b/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip index c9097d7c6..8befcea8f 100644 Binary files a/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip and b/packages/vanilla-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip differ diff --git a/packages/vanilla-bundle/package.json b/packages/vanilla-bundle/package.json index a34eee8f9..94557955c 100644 --- a/packages/vanilla-bundle/package.json +++ b/packages/vanilla-bundle/package.json @@ -24,8 +24,8 @@ "bundle:es2020": "cross-env tsc --project tsconfig.build.json --outDir dist/es2020 --module es2015 --target es2020", "prebundle": "npm-run-all delete:dist delete:zip", "postbundle": "npm-run-all zip:dist", - "delete:dist": "cross-env rimraf dist", - "delete:zip": "cross-env rimraf dist-bundle-zip", + "delete:dist": "cross-env rimraf --maxBusyTries=10 dist", + "delete:zip": "cross-env rimraf --maxBusyTries=10 dist-bundle-zip", "webpack:prod": "webpack --env.production", "zip:dist:dev": "cross-env node compress.js --output-filename=slickgrid-vanilla-bundle-DEV --output-folder=\"dist-grid-bundle-zip/\"", "zip:dist": "cross-env node compress.js --output-filename=slickgrid-vanilla-bundle --output-folder=\"dist-grid-bundle-zip/\"" @@ -61,4 +61,4 @@ "ts-loader": "^8.0.1", "webpack": "^4.44.0" } -} \ No newline at end of file +} diff --git a/packages/vanilla-bundle/src/components/__tests__/slick-pagination-without-i18n.spec.ts b/packages/vanilla-bundle/src/components/__tests__/slick-pagination-without-i18n.spec.ts index 048abfbd4..ba894a122 100644 --- a/packages/vanilla-bundle/src/components/__tests__/slick-pagination-without-i18n.spec.ts +++ b/packages/vanilla-bundle/src/components/__tests__/slick-pagination-without-i18n.spec.ts @@ -65,7 +65,7 @@ describe('Slick-Pagination Component', () => { let translateService: TranslateServiceStub; beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(paginationServiceStub, 'getFullPagination').mockReturnValue(mockFullPagination); div = document.createElement('div'); document.body.appendChild(div); diff --git a/packages/vanilla-bundle/src/components/__tests__/slick-pagination.spec.ts b/packages/vanilla-bundle/src/components/__tests__/slick-pagination.spec.ts index c9364af57..368b77cf2 100644 --- a/packages/vanilla-bundle/src/components/__tests__/slick-pagination.spec.ts +++ b/packages/vanilla-bundle/src/components/__tests__/slick-pagination.spec.ts @@ -61,7 +61,7 @@ describe('Slick-Pagination Component', () => { let translateService: TranslateServiceStub; beforeEach(() => { - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(paginationServiceStub, 'getFullPagination').mockReturnValue(mockFullPagination); jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(mockGridOptions); div = document.createElement('div'); @@ -241,7 +241,7 @@ describe('with different i18n locale', () => { beforeEach(() => { mockGridOptions.enableTranslate = true; jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(mockGridOptions); - jest.spyOn(SharedService.prototype, 'grid', 'get').mockReturnValue(gridStub); + jest.spyOn(SharedService.prototype, 'slickGrid', 'get').mockReturnValue(gridStub); jest.spyOn(paginationServiceStub, 'getFullPagination').mockReturnValue(mockFullPagination2); div = document.createElement('div'); document.body.appendChild(div); diff --git a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid-constructor.spec.ts b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid-constructor.spec.ts index d10486132..136cbe820 100644 --- a/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid-constructor.spec.ts +++ b/packages/vanilla-bundle/src/components/__tests__/slick-vanilla-grid-constructor.spec.ts @@ -6,6 +6,7 @@ import { CurrentPagination, CurrentSorter, Editors, + ExtensionList, ExtensionService, ExtensionUtility, Filters, @@ -21,6 +22,8 @@ import { PaginationService, ServicePagination, SharedService, + SlickDraggableGrouping, + SlickPluginList, SlickGrid, SortService, TreeDataService, @@ -64,6 +67,7 @@ const extensionServiceStub = { translateGridMenu: jest.fn(), translateHeaderMenu: jest.fn(), } as unknown as ExtensionService; +Object.defineProperty(extensionServiceStub, 'extensionList', { get: jest.fn(() => { }), set: jest.fn(), configurable: true }); const mockExtensionUtility = { loadExtensionDynamically: jest.fn(), @@ -318,11 +322,13 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () const pubSubSpy = jest.spyOn(eventPubSubService, 'publish'); component.initialization(divContainer); + const instances = component.instances; + expect(pubSubSpy).toHaveBeenCalled(); expect(pubSubSpy).toHaveBeenNthCalledWith(1, 'onBeforeGridCreate', true); expect(pubSubSpy).toHaveBeenNthCalledWith(2, 'onDataviewCreated', expect.any(Object)); expect(pubSubSpy).toHaveBeenNthCalledWith(3, 'onGridCreated', expect.any(Object)); - expect(pubSubSpy).toHaveBeenNthCalledWith(4, 'onSlickerGridCreated', expect.any(Object)); + expect(pubSubSpy).toHaveBeenNthCalledWith(4, 'onSlickerGridCreated', instances); component.dispose(); expect(pubSubSpy).toHaveBeenNthCalledWith(5, 'onBeforeGridDestroy', expect.any(Object)); @@ -380,7 +386,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () describe('dataset changed', () => { beforeEach(() => { jest.clearAllMocks(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; }); it('should expect "autosizeColumns" being called when "autoFitColumnsOnFirstLoad" is set and we are on first page load', () => { @@ -413,7 +419,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () describe('options changed', () => { beforeEach(() => { jest.clearAllMocks(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; sharedService.gridOptions = gridOptions; }); @@ -562,10 +568,13 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () const dataviewSpy = jest.spyOn(mockDataViewImplementation.prototype, 'constructor'); const groupMetaSpy = jest.spyOn(mockGroupItemMetaProviderImplementation.prototype, 'constructor'); const sharedMetaSpy = jest.spyOn(SharedService.prototype, 'groupItemMetadataProvider', 'set'); + jest.spyOn(extensionServiceStub, 'extensionList', 'get').mockReturnValue({ draggableGrouping: { pluginName: 'DraggableGrouping' } } as unknown as ExtensionList); component.gridOptions = { draggableGrouping: {} }; component.initialization(divContainer); + const extensions = component.extensions; + expect(Object.keys(extensions).length).toBe(1); expect(extensionSpy).toHaveBeenCalledWith('groupItemMetaProvider'); expect(dataviewSpy).toHaveBeenCalledWith({ inlineFilters: false, groupItemMetadataProvider: expect.anything() }); expect(groupMetaSpy).toHaveBeenCalledWith(); @@ -596,7 +605,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () afterEach(() => { component.dispose(); jest.clearAllMocks(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; }); it('should call the onDataviewCreated emitter', () => { @@ -707,7 +716,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () afterEach(() => { jest.clearAllMocks(); component.dispose(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; }); it('should call "showHeaderRow" method with false when its flag is disabled', () => { @@ -1493,7 +1502,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () describe('loadRowSelectionPresetWhenExists method', () => { beforeEach(() => { jest.clearAllMocks(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; }); it('should call the "mapIdsToRows" from the DataView then "setSelectedRows" from the Grid when there are row selection presets with "dataContextIds" array set', (done) => { @@ -1562,7 +1571,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', () describe('onPaginationVisibilityChanged event', () => { beforeEach(() => { jest.clearAllMocks(); - sharedService.grid = mockGrid as unknown as SlickGrid; + sharedService.slickGrid = mockGrid as unknown as SlickGrid; }); it('should change "showPagination" flag when "onPaginationVisibilityChanged" from the Pagination Service is triggered', (done) => { diff --git a/packages/vanilla-bundle/src/components/slick-pagination.ts b/packages/vanilla-bundle/src/components/slick-pagination.ts index 8a3bda97a..28f10eb23 100644 --- a/packages/vanilla-bundle/src/components/slick-pagination.ts +++ b/packages/vanilla-bundle/src/components/slick-pagination.ts @@ -97,7 +97,7 @@ export class SlickPaginationComponent { } get grid(): SlickGrid { - return this.sharedService.grid; + return this.sharedService.slickGrid; } get gridOptions(): GridOption { diff --git a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts index 5b87ef6d6..da26dab2f 100644 --- a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts +++ b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts @@ -8,6 +8,7 @@ import { BackendServiceApi, Column, ColumnEditor, + ExtensionList, ExtensionName, EventNamingStyle, GlobalGridOptions, @@ -89,6 +90,7 @@ export class SlickVanillaGridBundle { private _isLocalGrid = true; private _isPaginationInitialized = false; private _eventHandler: SlickEventHandler = new Slick.EventHandler(); + private _extensions: ExtensionList | undefined; private _paginationOptions: Pagination | undefined; private _registeredServices: any[] = []; private _slickgridInitialized = false; @@ -224,6 +226,10 @@ export class SlickVanillaGridBundle { return this._slickerGridInstances; } + get extensions(): ExtensionList | undefined { + return this._extensions; + } + get registeredServices(): any[] { return this._registeredServices; } @@ -369,7 +375,7 @@ export class SlickVanillaGridBundle { this._columnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(this._columnDefinitions); this.slickGrid = new Slick.Grid(gridContainerElm, this.dataView, this._columnDefinitions, this._gridOptions); this.sharedService.dataView = this.dataView; - this.sharedService.grid = this.slickGrid; + this.sharedService.slickGrid = this.slickGrid; this.extensionService.bindDifferentExtensions(); this.bindDifferentHooks(this.slickGrid, this._gridOptions, this.dataView); @@ -538,6 +544,10 @@ export class SlickVanillaGridBundle { treeDataService: this.treeDataService, }; + // addons (SlickGrid extra plugins/controls) + this._extensions = this.extensionService?.extensionList; + + // all instances (SlickGrid, DataView & all Services) this._eventPubSubService.publish('onSlickerGridCreated', this.instances); this._isGridInitialized = true; }