@platforma-sdk/ui-vue 1.24.5 → 1.24.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.24.5",
3
+ "version": "1.24.10",
4
4
  "type": "module",
5
5
  "main": "dist/lib.umd.cjs",
6
6
  "module": "dist/lib.js",
@@ -24,7 +24,7 @@
24
24
  "ag-grid-enterprise": "^33.0.4",
25
25
  "ag-grid-vue3": "^33.0.4",
26
26
  "@milaboratories/uikit": "^2.2.60",
27
- "@platforma-sdk/model": "^1.24.5"
27
+ "@platforma-sdk/model": "^1.24.10"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@faker-js/faker": "^9.2.0",
@@ -46,7 +46,7 @@
46
46
  "@types/semver": "^7.5.8",
47
47
  "rollup-plugin-sourcemaps2": "^0.5.0",
48
48
  "@milaboratories/helpers": "^1.6.11",
49
- "@milaboratories/eslint-config": "^1.0.2"
49
+ "@milaboratories/eslint-config": "^1.0.3"
50
50
  },
51
51
  "scripts": {
52
52
  "test": "vitest run --passWithNoTests",
@@ -22,6 +22,7 @@ import { PlDropdownLine } from '@milaboratories/uikit';
22
22
  import {
23
23
  getAxisId,
24
24
  getRawPlatformaInstance,
25
+ type PlDataTableGridStateWithoutSheets,
25
26
  type AxisId,
26
27
  type PlDataTableState,
27
28
  type PTableColumnSpec,
@@ -118,10 +119,11 @@ function makeSorting(state?: SortState): PTableSorting[] {
118
119
  );
119
120
  }
120
121
 
121
- const gridState = computed({
122
+ const gridState = computed<PlDataTableGridStateWithoutSheets>({
122
123
  get: () => {
123
124
  const state = tableState.value;
124
125
  return {
126
+ sourceId: state.gridState.sourceId,
125
127
  columnOrder: state.gridState.columnOrder,
126
128
  sort: state.gridState.sort,
127
129
  columnVisibility: state.gridState.columnVisibility,
@@ -202,7 +204,7 @@ watch(
202
204
  const newSheetsState: Record<string, string | number> = {};
203
205
  for (const sheet of settings.sheets) {
204
206
  const sheetId = makeSheetId(sheet.axis);
205
- newSheetsState[sheetId] = oldSheetsState[sheetId] ?? sheet.defaultValue ?? sheet.options[0].value;
207
+ newSheetsState[sheetId] = oldSheetsState[sheetId] ?? sheet.defaultValue ?? sheet.options[0]?.value;
206
208
  }
207
209
  sheetsState.value = newSheetsState;
208
210
  },
@@ -316,9 +318,10 @@ const onGridReady = (event: GridReadyEvent) => {
316
318
 
317
319
  const makePartialState = (state: GridState) => {
318
320
  return {
321
+ sourceId: gridState.value.sourceId,
319
322
  columnOrder: state.columnOrder,
320
323
  sort: state.sort,
321
- columnVisibility: state.columnVisibility ?? (state.columnOrder ? { hiddenColIds: [] } : undefined),
324
+ columnVisibility: state.columnVisibility,
322
325
  };
323
326
  };
324
327
 
@@ -443,7 +446,7 @@ watch(
443
446
  settings.pTable,
444
447
  settings.sheets ?? [],
445
448
  !!props.clientSideModel || !!selectedRows.value,
446
- gridState.value?.columnVisibility?.hiddenColIds,
449
+ gridState,
447
450
  {
448
451
  showCellButtonForAxisId: props.showCellButtonForAxisId,
449
452
  cellButtonInvokeRowsOnDoubleClick: props.cellButtonInvokeRowsOnDoubleClick,
@@ -59,8 +59,11 @@ function destroyCellFake(cellFake: HTMLDivElement) {
59
59
  }
60
60
 
61
61
  function adjustRowNumberColumnWidth(gridApi: GridApi, cellFake: HTMLDivElement, force?: boolean) {
62
+ const rowNode = gridApi.getDisplayedRowAtIndex(gridApi.getLastDisplayedRowIndex());
63
+ if (!rowNode) return;
64
+
62
65
  const lastDisplayedRowNumber = gridApi.getCellValue({
63
- rowNode: gridApi.getDisplayedRowAtIndex(gridApi.getLastDisplayedRowIndex())!,
66
+ rowNode,
64
67
  colKey: PlAgDataTableRowNumberColId,
65
68
  });
66
69
 
@@ -86,6 +89,7 @@ function adjustRowNumberColumnWidth(gridApi: GridApi, cellFake: HTMLDivElement,
86
89
  }
87
90
 
88
91
  function fixColumnOrder(gridApi: GridApi) {
92
+ if (gridApi.isDestroyed()) return;
89
93
  const columns = gridApi.getAllGridColumns() ?? [];
90
94
  const selectionIndex = columns.findIndex(isColumnSelectionCol);
91
95
  const numRowsIndex = columns.findIndex((column) => column.getId() === PlAgDataTableRowNumberColId);
@@ -6,6 +6,9 @@ import type {
6
6
  RowModelType,
7
7
  ValueFormatterParams,
8
8
  } from 'ag-grid-enterprise';
9
+ import type {
10
+ PlDataTableGridStateWithoutSheets,
11
+ } from '@platforma-sdk/model';
9
12
  import {
10
13
  getAxisId,
11
14
  pTableValue,
@@ -28,6 +31,8 @@ import type { PlAgDataTableRow, PTableRowKey } from '../types';
28
31
  import { makeRowNumberColDef, PlAgDataTableRowNumberColId } from './row-number';
29
32
  import { getHeterogeneousColumns, updatePFrameGridOptionsHeterogeneousAxes } from './table-source-heterogeneous';
30
33
  import { defaultMainMenuItems } from './menu-items';
34
+ import { objectHash } from '../../../objectHash';
35
+ import type { Ref } from 'vue';
31
36
 
32
37
  type PlAgCellButtonAxisParams = {
33
38
  showCellButtonForAxisId?: AxisId;
@@ -154,7 +159,7 @@ export async function updatePFrameGridOptions(
154
159
  pt: PTableHandle,
155
160
  sheets: PlDataTableSheet[],
156
161
  clientSide: boolean,
157
- hiddenColIds?: string[],
162
+ gridState: Ref<PlDataTableGridStateWithoutSheets>,
158
163
  cellButtonAxisParams?: PlAgCellButtonAxisParams,
159
164
  ): Promise<{
160
165
  columnDefs: ColDef[];
@@ -164,6 +169,21 @@ export async function updatePFrameGridOptions(
164
169
  }> {
165
170
  const specs = await pfDriver.getSpec(pt);
166
171
 
172
+ const oldSourceId = gridState.value.sourceId;
173
+
174
+ const newSourceId = await objectHash(specs);
175
+
176
+ const isSourceIdChanged = oldSourceId !== newSourceId;
177
+
178
+ const columnVisibility = isSourceIdChanged ? undefined : gridState.value.columnVisibility;
179
+
180
+ if (isSourceIdChanged) {
181
+ gridState.value = {
182
+ ...gridState.value,
183
+ sourceId: newSourceId,
184
+ };
185
+ }
186
+
167
187
  let numberOfAxes = specs.findIndex((s) => s.type === 'column');
168
188
  if (numberOfAxes === -1) numberOfAxes = specs.length;
169
189
 
@@ -228,7 +248,7 @@ export async function updatePFrameGridOptions(
228
248
  const rowCount = ptShape.rows;
229
249
  const columnDefs: ColDef<PlAgDataTableRow>[] = [
230
250
  makeRowNumberColDef(),
231
- ...fields.map((i) => makeColDef(i, specs[i], hiddenColIds, cellButtonAxisParams)),
251
+ ...fields.map((i) => makeColDef(i, specs[i], columnVisibility?.hiddenColIds, cellButtonAxisParams)),
232
252
  ];
233
253
 
234
254
  if (hColumns.length > 0) {
@@ -40,12 +40,15 @@ function toggleColumnVisibility(col: Column) {
40
40
  watch(
41
41
  () => gridApi.value,
42
42
  (gridApi) => {
43
+ if (gridApi.isDestroyed()) return;
44
+
43
45
  columns.value = gridApi.getAllGridColumns();
44
46
  if (columns.value.length > 0) {
45
47
  gridApi.moveColumns(columns.value, 0);
46
48
  }
47
49
 
48
50
  gridApi.addEventListener('displayedColumnsChanged', (event) => {
51
+ if (gridApi.isDestroyed()) return;
49
52
  columns.value = event.api.getAllGridColumns();
50
53
  listKey.value++;
51
54
  });
package/src/lib.ts CHANGED
@@ -39,6 +39,8 @@ export * from './aggrid';
39
39
 
40
40
  export * from './utils';
41
41
 
42
+ export * from './objectHash';
43
+
42
44
  export * from './computedResult';
43
45
 
44
46
  export * from './composition/useWatchFetch';
@@ -0,0 +1,24 @@
1
+ import canonicalize from 'canonicalize';
2
+
3
+ /**
4
+ * Calculate a hash of a JSON object
5
+ * @param jsonObject - The JSON object to hash
6
+ * @returns A hash of the JSON object
7
+ */
8
+ export async function objectHash(jsonObject: NonNullable<unknown>) {
9
+ const canonicalJson = canonicalize(jsonObject);
10
+
11
+ if (canonicalJson === undefined) {
12
+ throw new Error('Failed to canonicalize object: Invalid input type or structure');
13
+ }
14
+
15
+ const encoder = new TextEncoder();
16
+
17
+ const data = encoder.encode(canonicalJson);
18
+
19
+ const digest = await crypto.subtle.digest('SHA-256', data);
20
+
21
+ const hashArray = Array.from(new Uint8Array(digest));
22
+
23
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
24
+ }