angular-slickgrid 6.6.2 → 6.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1056,6 +1056,13 @@ class AngularSlickgridComponent {
1056
1056
  if (!this.gridOptions || !this.columnDefinitions) {
1057
1057
  throw new Error('Using `<angular-slickgrid>` requires [gridOptions] and [columnDefinitions], it seems that you might have forgot to provide them since at least of them is undefined.');
1058
1058
  }
1059
+ // save resource refs to register before the grid options are merged and possibly deep copied
1060
+ // since a deep copy of grid options would lose original resource refs but we want to keep them as singleton
1061
+ this._registeredResources = this.gridOptions?.externalResources || this.gridOptions?.registerExternalResources || [];
1062
+ /* istanbul ignore if */
1063
+ if (this.gridOptions?.registerExternalResources) {
1064
+ console.warn('[Angular-Slickgrid] Please note that the grid option `registerExternalResources` was deprecated and will be removed in next major, please use `externalResources` instead.');
1065
+ }
1059
1066
  this.initialization(this._eventHandler);
1060
1067
  this._isGridInitialized = true;
1061
1068
  // recheck the empty warning message after grid is shown so that it works in every use case
@@ -1078,15 +1085,7 @@ class AngularSlickgridComponent {
1078
1085
  });
1079
1086
  this.serviceList = [];
1080
1087
  // dispose all registered external resources
1081
- if (Array.isArray(this._registeredResources)) {
1082
- while (this._registeredResources.length > 0) {
1083
- const resource = this._registeredResources.pop();
1084
- if (resource?.dispose) {
1085
- resource.dispose();
1086
- }
1087
- }
1088
- this._registeredResources = [];
1089
- }
1088
+ this.disposeExternalResources();
1090
1089
  // dispose the Components
1091
1090
  this.slickEmptyWarning?.dispose();
1092
1091
  this.slickFooter?.dispose();
@@ -1126,6 +1125,17 @@ class AngularSlickgridComponent {
1126
1125
  this._angularGridInstances = undefined;
1127
1126
  this.slickGrid = undefined;
1128
1127
  }
1128
+ disposeExternalResources() {
1129
+ if (Array.isArray(this._registeredResources)) {
1130
+ while (this._registeredResources.length > 0) {
1131
+ const res = this._registeredResources.pop();
1132
+ if (res?.dispose) {
1133
+ res.dispose();
1134
+ }
1135
+ }
1136
+ }
1137
+ this._registeredResources = [];
1138
+ }
1129
1139
  emptyGridContainerElm() {
1130
1140
  const gridContainerId = this.gridOptions?.gridContainerId ?? 'grid1';
1131
1141
  const gridContainerElm = document.querySelector(`#${gridContainerId}`);
@@ -1438,7 +1448,7 @@ class AngularSlickgridComponent {
1438
1448
  return showing;
1439
1449
  }
1440
1450
  //
1441
- // private functions
1451
+ // protected functions
1442
1452
  // ------------------
1443
1453
  /**
1444
1454
  * Loop through all column definitions and copy the original optional `width` properties optionally provided by the user.
@@ -1845,9 +1855,19 @@ class AngularSlickgridComponent {
1845
1855
  }
1846
1856
  return options;
1847
1857
  }
1858
+ /** Add a register a new external resource, user could also optional dispose all previous resources before pushing any new resources to the resources array list. */
1859
+ registerExternalResources(resources, disposePreviousResources = false) {
1860
+ if (disposePreviousResources) {
1861
+ this.disposeExternalResources();
1862
+ }
1863
+ resources.forEach(res => this._registeredResources.push(res));
1864
+ this.initializeExternalResources(resources);
1865
+ }
1866
+ resetExternalResources() {
1867
+ this._registeredResources = [];
1868
+ }
1848
1869
  /** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource & RowDetail) */
1849
1870
  preRegisterResources() {
1850
- this._registeredResources = this.gridOptions.registerExternalResources || [];
1851
1871
  // Angular-Slickgrid requires RxJS, so we'll register it as the first resource
1852
1872
  this.registerRxJsResource(new RxJsResource());
1853
1873
  if (this.gridOptions.enableRowDetailView) {
@@ -1857,6 +1877,15 @@ class AngularSlickgridComponent {
1857
1877
  this.extensionService.addExtensionToList(ExtensionName.rowDetailView, { name: ExtensionName.rowDetailView, instance: this.slickRowDetailView });
1858
1878
  }
1859
1879
  }
1880
+ initializeExternalResources(resources) {
1881
+ if (Array.isArray(resources)) {
1882
+ for (const resource of resources) {
1883
+ if (this.slickGrid && typeof resource.init === 'function') {
1884
+ resource.init(this.slickGrid, this.containerService);
1885
+ }
1886
+ }
1887
+ }
1888
+ }
1860
1889
  registerResources() {
1861
1890
  // at this point, we consider all the registered services as external services, anything else registered afterward aren't external
1862
1891
  if (Array.isArray(this._registeredResources)) {
@@ -1881,13 +1910,7 @@ class AngularSlickgridComponent {
1881
1910
  this._registeredResources.push(this.slickEmptyWarning);
1882
1911
  // bind & initialize all Components/Services that were tagged as enabled
1883
1912
  // register all services by executing their init method and providing them with the Grid object
1884
- if (Array.isArray(this._registeredResources)) {
1885
- for (const resource of this._registeredResources) {
1886
- if (this.slickGrid && typeof resource.init === 'function') {
1887
- resource.init(this.slickGrid, this.containerService);
1888
- }
1889
- }
1890
- }
1913
+ this.initializeExternalResources(this._registeredResources);
1891
1914
  }
1892
1915
  /** Register the RxJS Resource in all necessary services which uses */
1893
1916
  registerRxJsResource(resource) {