@genesislcap/grid-pro 14.151.2-alpha-6dc6e2c.0 → 14.152.0

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.
Files changed (50) hide show
  1. package/dist/custom-elements.json +245 -73
  2. package/dist/dts/datasource/base.datasource.d.ts +1 -2
  3. package/dist/dts/datasource/base.datasource.d.ts.map +1 -1
  4. package/dist/dts/datasource/server-side.datasource.d.ts.map +1 -1
  5. package/dist/dts/grid-pro-genesis-datasource/grid-pro-genesis-datasource.d.ts.map +1 -1
  6. package/dist/dts/grid-pro.d.ts +22 -13
  7. package/dist/dts/grid-pro.d.ts.map +1 -1
  8. package/dist/dts/index.d.ts +1 -0
  9. package/dist/dts/index.d.ts.map +1 -1
  10. package/dist/dts/state-persistence/index.d.ts +4 -0
  11. package/dist/dts/state-persistence/index.d.ts.map +1 -0
  12. package/dist/dts/state-persistence/kv-state.d.ts +15 -0
  13. package/dist/dts/state-persistence/kv-state.d.ts.map +1 -0
  14. package/dist/dts/state-persistence/local-state.d.ts +13 -0
  15. package/dist/dts/state-persistence/local-state.d.ts.map +1 -0
  16. package/dist/dts/state-persistence/state-persistence.d.ts +24 -0
  17. package/dist/dts/state-persistence/state-persistence.d.ts.map +1 -0
  18. package/dist/esm/datasource/base.datasource.js +1 -25
  19. package/dist/esm/datasource/server-side.datasource.js +41 -39
  20. package/dist/esm/grid-pro-genesis-datasource/grid-pro-genesis-datasource.js +65 -61
  21. package/dist/esm/grid-pro.js +104 -114
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/state-persistence/index.js +3 -0
  24. package/dist/esm/state-persistence/kv-state.js +58 -0
  25. package/dist/esm/state-persistence/local-state.js +30 -0
  26. package/dist/esm/state-persistence/state-persistence.js +7 -0
  27. package/dist/grid-pro.api.json +780 -203
  28. package/dist/grid-pro.d.ts +71 -16
  29. package/docs/api/grid-pro.gridpro.applytemplatedefinitions.md +2 -2
  30. package/docs/api/grid-pro.gridpro.getsavedcolumnstate.md +3 -3
  31. package/docs/api/grid-pro.gridpro.md +2 -3
  32. package/docs/api/grid-pro.gridpro.mergeallcolumndefsandstates.md +2 -2
  33. package/docs/api/grid-pro.gridpro.statepersistence.md +11 -0
  34. package/docs/api/grid-pro.kvstoragestatepersistence.getcolumnstate.md +22 -0
  35. package/docs/api/grid-pro.kvstoragestatepersistence.kvstorage.md +11 -0
  36. package/docs/api/grid-pro.kvstoragestatepersistence.md +29 -0
  37. package/docs/api/grid-pro.kvstoragestatepersistence.savecolumnstate.md +23 -0
  38. package/docs/api/grid-pro.kvstoragestatepersistence.session.md +11 -0
  39. package/docs/api/grid-pro.localstoragestatepersistence.getcolumnstate.md +22 -0
  40. package/docs/api/grid-pro.localstoragestatepersistence.md +28 -0
  41. package/docs/api/grid-pro.localstoragestatepersistence.savecolumnstate.md +23 -0
  42. package/docs/api/grid-pro.localstoragestatepersistence.session.md +11 -0
  43. package/docs/api/grid-pro.md +3 -0
  44. package/docs/api/grid-pro.statepersistence.getcolumnstate.md +24 -0
  45. package/docs/api/grid-pro.statepersistence.md +21 -0
  46. package/docs/api/grid-pro.statepersistence.savecolumnstate.md +25 -0
  47. package/docs/api-report.md +42 -11
  48. package/package.json +14 -13
  49. package/docs/api/grid-pro.gridpro.selectedcolid.md +0 -11
  50. package/docs/api/grid-pro.gridpro.selectedrowid.md +0 -11
@@ -1,13 +1,13 @@
1
- import { __decorate, __rest } from "tslib";
1
+ import { __awaiter, __decorate, __rest } from "tslib";
2
2
  import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
3
3
  import { ComponentUtil, Grid, ModuleRegistry, } from '@ag-grid-community/core';
4
4
  import { CsvExportModule } from '@ag-grid-community/csv-export';
5
- import { Session } from '@genesislcap/foundation-comms';
6
5
  import { insertDocumentCSSRule, LifecycleMixin, respondToVisibility, } from '@genesislcap/foundation-utils';
7
6
  import { attr, DOM, observable } from '@microsoft/fast-element';
8
7
  import { FoundationElement } from '@microsoft/fast-foundation';
9
8
  import { classNames } from '@microsoft/fast-web-utilities';
10
9
  import * as changeCase from 'change-case';
10
+ import debounce from 'lodash.debounce';
11
11
  import { GridProCell } from './cell';
12
12
  import { SelectEditor, NumberEditor, MultiselectEditor, DateEditor, StringEditor, } from './cell-editors';
13
13
  import { ActionRenderer, ActionsMenuRenderer, BooleanRenderer, EditableRenderer, } from './cell-renderers';
@@ -19,6 +19,7 @@ import { DEBOUNCED_RESIZE_TIME } from './grid-pro.definitions';
19
19
  import { foundationGridProStyles as styles } from './grid-pro.styles';
20
20
  import { gridProTemplate as template } from './grid-pro.template';
21
21
  import { AgGridTheme, GridProRendererTypes, agThemeFontsId, agThemeTokenMapClassname, GRID_READY_EVENT, ERROR_COLUMN_FIELD, EDITED_COLUMN_FIELD, GridOptionsConfig, } from './grid-pro.types';
22
+ import { StatePersistence } from './state-persistence';
22
23
  import { ErrorTooltip } from './tooltips';
23
24
  import { convertToKebabCase, logger, mergeAndDedupColDefWithColumnState } from './utils';
24
25
  GridProGenesisDatasource;
@@ -27,6 +28,7 @@ GridProServerSideDatasource;
27
28
  GridProCell;
28
29
  GridProColumn;
29
30
  ModuleRegistry.registerModules([CsvExportModule, ClientSideRowModelModule]);
31
+ const DEBOUNCE_TIME = 400;
30
32
  /**
31
33
  * The Grid Pro element.
32
34
  * @remarks Grid Pro is a Web Component wrapper around the AG Grid Community library.
@@ -90,12 +92,6 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
90
92
  this.gridFontFace = defaultAgGridFontFace;
91
93
  this.columnComponentName = 'grid-pro-column';
92
94
  this.theme = AgGridTheme.alpine;
93
- /**
94
- * If true, will block scrolling when context menu is open and keep the grid in the same position without scrolling to new records
95
- * @remarks Defaults to false
96
- * @alpha
97
- */
98
- this.blockScrollingOnContextMenu = false;
99
95
  this.rehydrationAttempted = false;
100
96
  this.gridEventsQueue = [];
101
97
  this.filterConfig = undefined;
@@ -199,44 +195,45 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
199
195
  return colState.map((col) => (Object.assign(Object.assign({}, col), { width: null })));
200
196
  }
201
197
  saveColumnState() {
202
- if (this.rehydrationAttempted && this.statePersistanceEnabled()) {
203
- const existingOptions = JSON.parse(this.session.getLocalStorageItem('gridOptions') || '{}');
204
- let colState = this.columnApi.getColumnState();
205
- colState = this.gridAutosizingEnabled
206
- ? this.removeConfigWidthsToAutosize(colState)
207
- : colState;
208
- if (colState.length === 0)
209
- return;
210
- existingOptions[this.persistColumnStateKey] = JSON.stringify(colState);
211
- this.session.setLocalStorageItem('gridOptions', JSON.stringify(existingOptions));
212
- }
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ if (this.rehydrationAttempted && this.statePersistanceEnabled()) {
200
+ let colState = this.columnApi.getColumnState();
201
+ colState = this.gridAutosizingEnabled
202
+ ? this.removeConfigWidthsToAutosize(colState)
203
+ : colState;
204
+ if (colState.length === 0 || JSON.stringify(colState) === JSON.stringify(this.columnState))
205
+ return;
206
+ yield this.statePersistence.saveColumnState(this.persistColumnStateKey, colState);
207
+ }
208
+ });
213
209
  }
214
210
  /**
215
- * Gets the saved grid ColumnState[] from local storage
211
+ * Gets the saved grid ColumnState[] from storage
216
212
  * @remarks This is used to restore the grid state when the grid is rehydrated
217
213
  * @privateRemarks Not using `columnApi.get|setColumnState()` for these flows as it doesn't work setting new columnDefs vs different ordering.
218
214
  * @public
219
215
  */
220
216
  getSavedColumnState() {
221
- const localStorageGridOptions = this.session.getLocalStorageItem('gridOptions');
222
- if (this.statePersistanceEnabled() && localStorageGridOptions) {
223
- const allGridOptions = JSON.parse(localStorageGridOptions);
224
- if (this.persistColumnStateKey in allGridOptions) {
225
- return JSON.parse(allGridOptions[this.persistColumnStateKey]);
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ this.columnState = [];
219
+ if (this.statePersistanceEnabled()) {
220
+ this.columnState = yield this.statePersistence.getColumnState(this.persistColumnStateKey);
226
221
  }
227
- }
228
- return [];
222
+ return this.columnState;
223
+ });
229
224
  }
230
225
  restoreColumnState() {
231
226
  var _a;
232
- this.rehydrationAttempted = true;
233
- const colState = this.getSavedColumnState();
234
- if (colState && colState.length > 0) {
235
- (_a = this.columnApi) === null || _a === void 0 ? void 0 : _a.applyColumnState({
236
- state: colState,
237
- applyOrder: true,
238
- });
239
- }
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ this.rehydrationAttempted = true;
229
+ const colState = yield this.getSavedColumnState();
230
+ if (colState && colState.length > 0) {
231
+ (_a = this.columnApi) === null || _a === void 0 ? void 0 : _a.applyColumnState({
232
+ state: colState,
233
+ applyOrder: true,
234
+ });
235
+ }
236
+ });
240
237
  }
241
238
  cacheFilterConfig() {
242
239
  var _a;
@@ -261,9 +258,10 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
261
258
  this.querySelector('grid-pro-server-side-datasource'));
262
259
  }
263
260
  set gridOptions(options) {
261
+ const debounceSaveColumnState = debounce(this.saveColumnState.bind(this), DEBOUNCE_TIME);
264
262
  const globalEventListener = this.globalEventListener.bind(this);
265
263
  const gridOnChangeCallback = () => {
266
- this.saveColumnState.bind(this)();
264
+ debounceSaveColumnState();
267
265
  this.debouncedColumnAutosize.bind(this)();
268
266
  };
269
267
  Array.from(this.attributes).forEach((attribute) => {
@@ -272,7 +270,7 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
272
270
  return;
273
271
  this.agAttributes[attrName] = attribute.value;
274
272
  });
275
- const { columnDefs, components, defaultColDef, onCellContextMenu, onGridReady, onFirstDataRendered } = options, rest = __rest(options, ["columnDefs", "components", "defaultColDef", "onCellContextMenu", "onGridReady", "onFirstDataRendered"]);
273
+ const { columnDefs, components, defaultColDef, onGridReady, onFirstDataRendered } = options, rest = __rest(options, ["columnDefs", "components", "defaultColDef", "onGridReady", "onFirstDataRendered"]);
276
274
  const derivedOptions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.gridOptionsConfig), { defaultColDef: Object.assign({ enableCellChangeFlash: this.enableCellFlashing, filter: true, resizable: true, sortable: true }, defaultColDef), components: this.combineAllGridComponents(components), suppressDragLeaveHidesColumns: true }), this.eventsAndCallbacks), { onGridReady: (event) => {
277
275
  var _a, _b;
278
276
  this.gridApi = (_a = options.api) !== null && _a !== void 0 ? _a : event.api;
@@ -296,26 +294,19 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
296
294
  if (onFirstDataRendered) {
297
295
  onFirstDataRendered(event);
298
296
  }
299
- }, onColumnPinned: gridOnChangeCallback, onColumnResized: gridOnChangeCallback, onColumnMoved: gridOnChangeCallback, onDisplayedColumnsChanged: gridOnChangeCallback, onFilterChanged: gridOnChangeCallback, onGridSizeChanged: gridOnChangeCallback, onSortChanged: gridOnChangeCallback, onCellContextMenu: (event) => {
300
- if (this.blockScrollingOnContextMenu) {
301
- debugger;
302
- this.selectedRowId = event.node.id;
303
- this.selectedColId = event.colDef.colId;
304
- this.addEventListener('click', (e) => {
305
- this.selectedRowId = undefined;
306
- this.selectedColId = undefined;
307
- }, { once: true });
308
- }
309
- if (onCellContextMenu) {
310
- onCellContextMenu(event);
311
- }
312
- } }), rest);
297
+ }, onColumnPinned: gridOnChangeCallback, onColumnResized: gridOnChangeCallback, onColumnMoved: gridOnChangeCallback, onDisplayedColumnsChanged: gridOnChangeCallback, onFilterChanged: gridOnChangeCallback, onGridSizeChanged: gridOnChangeCallback, onSortChanged: gridOnChangeCallback }), rest);
313
298
  if (this.gridProDatasource) {
314
299
  derivedOptions.columnDefs = columnDefs;
300
+ this.initGridOptions(derivedOptions, globalEventListener);
315
301
  }
316
302
  else {
317
- derivedOptions.columnDefs = this.mergeAllColumnDefsAndStates(columnDefs);
303
+ this.mergeAllColumnDefsAndStates(columnDefs).then((value) => {
304
+ derivedOptions.columnDefs = value;
305
+ this.initGridOptions(derivedOptions, globalEventListener);
306
+ });
318
307
  }
308
+ }
309
+ initGridOptions(derivedOptions, globalEventListener) {
319
310
  this.agGridOptions = Object.assign(Object.assign({}, this.agGridOptions), ComponentUtil.copyAttributesToGridOptions(derivedOptions, this.agAttributes));
320
311
  const gridParams = {
321
312
  globalEventListener: globalEventListener,
@@ -354,70 +345,72 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
354
345
  */
355
346
  mergeAllColumnDefsAndStates(columnDefs, deferredColumnDefsOrState = false) {
356
347
  var _a;
357
- const columnDefinitionsFromMetadata = columnDefs || [];
358
- columnDefinitionsFromMetadata.forEach((colDefFromMetadata) => {
359
- if (this.headerCaseType && colDefFromMetadata.field && !colDefFromMetadata.headerName) {
360
- const changeCaseByType = changeCase[this.headerCaseType];
361
- if (changeCaseByType) {
362
- colDefFromMetadata.headerName = changeCaseByType(colDefFromMetadata.field);
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ const columnDefinitionsFromMetadata = columnDefs || [];
350
+ columnDefinitionsFromMetadata.forEach((colDefFromMetadata) => {
351
+ if (this.headerCaseType && colDefFromMetadata.field && !colDefFromMetadata.headerName) {
352
+ const changeCaseByType = changeCase[this.headerCaseType];
353
+ if (changeCaseByType) {
354
+ colDefFromMetadata.headerName = changeCaseByType(colDefFromMetadata.field);
355
+ }
356
+ else {
357
+ logger.warn(`Invalid header-case-type attribute value: ${this.headerCaseType}. Please use one of the following: camelCase, capitalCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase.`);
358
+ }
363
359
  }
364
- else {
365
- logger.warn(`Invalid header-case-type attribute value: ${this.headerCaseType}. Please use one of the following: camelCase, capitalCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase.`);
360
+ });
361
+ const templateColumnDefs = Array.from(this.querySelectorAll(this.columnComponentName))
362
+ .map((templateColumn) => templateColumn.definition)
363
+ .map((columnDef) => {
364
+ // enable cell flashing for each column if unspecified on column level but enabled on grid level
365
+ if (this.enableCellFlashing && columnDef.enableCellChangeFlash === undefined) {
366
+ columnDef.enableCellChangeFlash = true;
366
367
  }
367
- }
368
- });
369
- const templateColumnDefs = Array.from(this.querySelectorAll(this.columnComponentName))
370
- .map((templateColumn) => templateColumn.definition)
371
- .map((columnDef) => {
372
- // enable cell flashing for each column if unspecified on column level but enabled on grid level
373
- if (this.enableCellFlashing && columnDef.enableCellChangeFlash === undefined) {
374
- columnDef.enableCellChangeFlash = true;
375
- }
376
- if (columnDef.editable) {
377
- if (!columnDef.cellRenderer && !columnDef.cellRendererSelector) {
378
- columnDef.cellRendererSelector = (params) => {
379
- if (params.data[EDITED_COLUMN_FIELD] === columnDef.field) {
380
- return {
381
- component: GridProRendererTypes.editable,
382
- };
383
- }
384
- };
368
+ if (columnDef.editable) {
369
+ if (!columnDef.cellRenderer && !columnDef.cellRendererSelector) {
370
+ columnDef.cellRendererSelector = (params) => {
371
+ if (params.data[EDITED_COLUMN_FIELD] === columnDef.field) {
372
+ return {
373
+ component: GridProRendererTypes.editable,
374
+ };
375
+ }
376
+ };
377
+ }
378
+ if (!columnDef.tooltipComponent && !columnDef.tooltipValueGetter) {
379
+ columnDef.tooltipComponent = ErrorTooltip;
380
+ columnDef.tooltipValueGetter = (params) => {
381
+ const error = params.data[ERROR_COLUMN_FIELD];
382
+ if (error && error.column === columnDef.field) {
383
+ return error.message;
384
+ }
385
+ };
386
+ }
387
+ if (!columnDef.cellClassRules) {
388
+ columnDef.cellClassRules = {
389
+ error: (params) => { var _a; return ((_a = params.data[ERROR_COLUMN_FIELD]) === null || _a === void 0 ? void 0 : _a.column) === params.colDef.field; },
390
+ };
391
+ }
385
392
  }
386
- if (!columnDef.tooltipComponent && !columnDef.tooltipValueGetter) {
387
- columnDef.tooltipComponent = ErrorTooltip;
388
- columnDef.tooltipValueGetter = (params) => {
389
- const error = params.data[ERROR_COLUMN_FIELD];
390
- if (error && error.column === columnDef.field) {
391
- return error.message;
392
- }
393
- };
393
+ const metadataColumnDef = columnDefinitionsFromMetadata.find((colDef) => columnDef.field === colDef.field);
394
+ return Object.assign(Object.assign({}, metadataColumnDef), columnDef);
395
+ });
396
+ const templateColumnKeys = templateColumnDefs.map((x) => x.field);
397
+ const colDefsToReturn = [
398
+ ...templateColumnDefs,
399
+ ...(this.onlyTemplateColDefs
400
+ ? []
401
+ : columnDefinitionsFromMetadata.filter((g) => !templateColumnKeys.includes(g.field))),
402
+ ];
403
+ if (this.gridProDatasource && deferredColumnDefsOrState) {
404
+ const savedColumnState = yield this.getSavedColumnState();
405
+ if ((savedColumnState === null || savedColumnState === void 0 ? void 0 : savedColumnState.length) > 0) {
406
+ return mergeAndDedupColDefWithColumnState(colDefsToReturn, savedColumnState);
394
407
  }
395
- if (!columnDef.cellClassRules) {
396
- columnDef.cellClassRules = {
397
- error: (params) => { var _a; return ((_a = params.data[ERROR_COLUMN_FIELD]) === null || _a === void 0 ? void 0 : _a.column) === params.colDef.field; },
398
- };
408
+ else if (((_a = this.gridProDatasource.deferredColumnStates) === null || _a === void 0 ? void 0 : _a.length) > 0) {
409
+ return mergeAndDedupColDefWithColumnState(colDefsToReturn, this.gridProDatasource.deferredColumnStates);
399
410
  }
400
411
  }
401
- const metadataColumnDef = columnDefinitionsFromMetadata.find((colDef) => columnDef.field === colDef.field);
402
- return Object.assign(Object.assign({}, metadataColumnDef), columnDef);
412
+ return colDefsToReturn;
403
413
  });
404
- const templateColumnKeys = templateColumnDefs.map((x) => x.field);
405
- const colDefsToReturn = [
406
- ...templateColumnDefs,
407
- ...(this.onlyTemplateColDefs
408
- ? []
409
- : columnDefinitionsFromMetadata.filter((g) => !templateColumnKeys.includes(g.field))),
410
- ];
411
- if (this.gridProDatasource && deferredColumnDefsOrState) {
412
- const savedColumnState = this.getSavedColumnState();
413
- if ((savedColumnState === null || savedColumnState === void 0 ? void 0 : savedColumnState.length) > 0) {
414
- return mergeAndDedupColDefWithColumnState(colDefsToReturn, savedColumnState);
415
- }
416
- else if (((_a = this.gridProDatasource.deferredColumnStates) === null || _a === void 0 ? void 0 : _a.length) > 0) {
417
- return mergeAndDedupColDefWithColumnState(colDefsToReturn, this.gridProDatasource.deferredColumnStates);
418
- }
419
- }
420
- return colDefsToReturn;
421
414
  }
422
415
  get observedAttributes() {
423
416
  // allow properties to be supplied either lowercased or kebab-cased
@@ -479,8 +472,8 @@ __decorate([
479
472
  observable
480
473
  ], GridPro.prototype, "gridApi", void 0);
481
474
  __decorate([
482
- Session
483
- ], GridPro.prototype, "session", void 0);
475
+ StatePersistence
476
+ ], GridPro.prototype, "statePersistence", void 0);
484
477
  __decorate([
485
478
  attr({ attribute: 'auto-cell-renderer-by-type', mode: 'boolean' })
486
479
  ], GridPro.prototype, "autoCellRendererByType", void 0);
@@ -535,9 +528,6 @@ __decorate([
535
528
  __decorate([
536
529
  attr
537
530
  ], GridPro.prototype, "theme", void 0);
538
- __decorate([
539
- attr({ attribute: 'block-scrolling-on-context-menu', mode: 'boolean' })
540
- ], GridPro.prototype, "blockScrollingOnContextMenu", void 0);
541
531
  __decorate([
542
532
  observable
543
533
  ], GridPro.prototype, "classNames", void 0);
package/dist/esm/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './grid-pro.template';
11
11
  export * from './grid-pro.types';
12
12
  export * from './grid-pro';
13
13
  export * from './grid-pro-genesis-datasource';
14
+ export * from './state-persistence';
14
15
  export * from './style';
15
16
  export * from './tooltips';
16
17
  export * from './utils';
@@ -0,0 +1,3 @@
1
+ export * from './kv-state';
2
+ export * from './local-state';
3
+ export * from './state-persistence';
@@ -0,0 +1,58 @@
1
+ import { __awaiter, __decorate } from "tslib";
2
+ import { KVStorage, Session } from '@genesislcap/foundation-comms';
3
+ import { logger } from '../utils';
4
+ /**
5
+ * Implementation for the KV Storage State Persistence interface.
6
+ * @public
7
+ */
8
+ export class KVStorageStatePersistence {
9
+ getColumnState(persistColumnStateKey) {
10
+ var _a, _b;
11
+ return __awaiter(this, void 0, void 0, function* () {
12
+ yield this.migrateLocalStorageToKVStorage(persistColumnStateKey);
13
+ const kvColumnState = yield this.kvStorage.get(persistColumnStateKey);
14
+ const storageColumnState = kvColumnState ? (_b = (_a = kvColumnState[0]) === null || _a === void 0 ? void 0 : _a.kv) === null || _b === void 0 ? void 0 : _b.value : undefined;
15
+ if (storageColumnState) {
16
+ return JSON.parse(storageColumnState);
17
+ }
18
+ return [];
19
+ });
20
+ }
21
+ saveColumnState(persistColumnStateKey, columnState) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ this.kvStorage.put([
24
+ {
25
+ key: persistColumnStateKey,
26
+ value: JSON.stringify(columnState),
27
+ },
28
+ ]);
29
+ });
30
+ }
31
+ migrateLocalStorageToKVStorage(persistColumnStateKey) {
32
+ var _a, _b;
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const kv = yield this.kvStorage.get(persistColumnStateKey);
35
+ if (kv && ((_b = (_a = kv[0]) === null || _a === void 0 ? void 0 : _a.kv) === null || _b === void 0 ? void 0 : _b.value))
36
+ return;
37
+ const localGridOptions = this.session.getLocalStorageItem('gridOptions');
38
+ const localState = localGridOptions
39
+ ? JSON.parse(localGridOptions)[persistColumnStateKey]
40
+ : undefined;
41
+ if (localState) {
42
+ logger.debug(`Columns state migration for key: ${persistColumnStateKey} from LocalStorage to KV Storage`);
43
+ this.kvStorage.put([
44
+ {
45
+ key: persistColumnStateKey,
46
+ value: localState,
47
+ },
48
+ ]);
49
+ }
50
+ });
51
+ }
52
+ }
53
+ __decorate([
54
+ KVStorage
55
+ ], KVStorageStatePersistence.prototype, "kvStorage", void 0);
56
+ __decorate([
57
+ Session
58
+ ], KVStorageStatePersistence.prototype, "session", void 0);
@@ -0,0 +1,30 @@
1
+ import { __awaiter, __decorate } from "tslib";
2
+ import { Session } from '@genesislcap/foundation-comms';
3
+ /**
4
+ * Implementation for the Local Storage State Persistence interface.
5
+ * @public
6
+ */
7
+ export class LocalStorageStatePersistence {
8
+ getColumnState(persistColumnStateKey) {
9
+ return __awaiter(this, void 0, void 0, function* () {
10
+ const localStorageGridOptions = this.session.getLocalStorageItem('gridOptions');
11
+ if (localStorageGridOptions) {
12
+ const allGridOptions = JSON.parse(localStorageGridOptions);
13
+ if (persistColumnStateKey in allGridOptions) {
14
+ return JSON.parse(allGridOptions[persistColumnStateKey]);
15
+ }
16
+ }
17
+ return [];
18
+ });
19
+ }
20
+ saveColumnState(persistColumnStateKey, columnState) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const existingOptions = JSON.parse(this.session.getLocalStorageItem('gridOptions') || '{}');
23
+ existingOptions[persistColumnStateKey] = JSON.stringify(columnState);
24
+ this.session.setLocalStorageItem('gridOptions', JSON.stringify(existingOptions));
25
+ });
26
+ }
27
+ }
28
+ __decorate([
29
+ Session
30
+ ], LocalStorageStatePersistence.prototype, "session", void 0);
@@ -0,0 +1,7 @@
1
+ import { DI } from '@microsoft/fast-foundation';
2
+ import { LocalStorageStatePersistence } from './local-state';
3
+ /**
4
+ * The DI token for the StatePersistence interface.
5
+ * @internal
6
+ */
7
+ export const StatePersistence = DI.createInterface((x) => x.singleton(LocalStorageStatePersistence));