@platforma-sdk/ui-vue 1.29.9 → 1.29.13

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 (32) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/lib.js +9477 -9003
  3. package/dist/lib.js.map +1 -1
  4. package/dist/lib.umd.cjs +27 -27
  5. package/dist/lib.umd.cjs.map +1 -1
  6. package/dist/src/components/PlAgDataTable/PlAgDataTable.vue.d.ts.map +1 -1
  7. package/dist/src/components/PlAgDataTable/PlAgDataTableV2.vue.d.ts +78 -0
  8. package/dist/src/components/PlAgDataTable/PlAgDataTableV2.vue.d.ts.map +1 -0
  9. package/dist/src/components/PlAgDataTable/index.d.ts +1 -0
  10. package/dist/src/components/PlAgDataTable/index.d.ts.map +1 -1
  11. package/dist/src/components/PlAgDataTable/sources/common.d.ts +21 -0
  12. package/dist/src/components/PlAgDataTable/sources/common.d.ts.map +1 -0
  13. package/dist/src/components/PlAgDataTable/sources/table-source-v2.d.ts +16 -0
  14. package/dist/src/components/PlAgDataTable/sources/table-source-v2.d.ts.map +1 -0
  15. package/dist/src/components/PlAgDataTable/sources/table-source.d.ts +4 -15
  16. package/dist/src/components/PlAgDataTable/sources/table-source.d.ts.map +1 -1
  17. package/dist/src/components/PlAgDataTable/types.d.ts +14 -2
  18. package/dist/src/components/PlAgDataTable/types.d.ts.map +1 -1
  19. package/dist/src/lib.d.ts +2 -1
  20. package/dist/src/lib.d.ts.map +1 -1
  21. package/dist/style.css +1 -1
  22. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  23. package/package.json +3 -3
  24. package/src/components/PlAgDataTable/PlAgDataTable.vue +10 -6
  25. package/src/components/PlAgDataTable/PlAgDataTableV2.vue +539 -0
  26. package/src/components/PlAgDataTable/index.ts +1 -0
  27. package/src/components/PlAgDataTable/sources/common.ts +127 -0
  28. package/src/components/PlAgDataTable/sources/table-source-heterogeneous.ts +2 -2
  29. package/src/components/PlAgDataTable/sources/table-source-v2.ts +260 -0
  30. package/src/components/PlAgDataTable/sources/table-source.ts +2 -115
  31. package/src/components/PlAgDataTable/types.ts +19 -1
  32. package/src/lib.ts +2 -1
@@ -0,0 +1,127 @@
1
+ import type {
2
+ ColDef,
3
+ ICellRendererParams,
4
+ ValueFormatterParams,
5
+ } from 'ag-grid-enterprise';
6
+ import {
7
+ isPTableAbsent,
8
+ type AxisId,
9
+ type PTableColumnSpec,
10
+ type PTableValue,
11
+ PTableNA,
12
+ strinfigyPTableColumnId,
13
+ isColumnOptional,
14
+ isLabelColumn as isLabelColumnSpec,
15
+ canonicalizeJson,
16
+ } from '@platforma-sdk/model';
17
+ import canonicalize from 'canonicalize';
18
+ import * as lodash from 'lodash';
19
+ import { PlAgColumnHeader, type PlAgHeaderComponentParams, type PlAgHeaderComponentType } from '../../PlAgColumnHeader';
20
+ import PlAgTextAndButtonCell from '../../PlAgTextAndButtonCell/PlAgTextAndButtonCell.vue';
21
+ import type { PlAgDataTableRow, PTableRowKey, PTableRowKeyJson } from '../types';
22
+ import { defaultMainMenuItems } from './menu-items';
23
+
24
+ export type PlAgCellButtonAxisParams = {
25
+ showCellButtonForAxisId?: AxisId;
26
+ cellButtonInvokeRowsOnDoubleClick?: boolean;
27
+ trigger: (key?: PTableRowKey) => void;
28
+ };
29
+
30
+ export const PTableHidden = { type: 'hidden' };
31
+ export type PTableHidden = typeof PTableHidden;
32
+
33
+ export function isPTableHidden(value: PTableValue): value is PTableHidden {
34
+ return typeof value === 'object' && value !== null && value.type === 'hidden';
35
+ }
36
+
37
+ export const defaultValueFormatter = (value: ValueFormatterParams<PlAgDataTableRow, PTableValue>) => {
38
+ if (value.value === undefined) {
39
+ return 'undefined';
40
+ } else if (isPTableHidden(value.value)) {
41
+ return 'loading...';
42
+ } else if (isPTableAbsent(value.value) || value.value === PTableNA) {
43
+ return '';
44
+ } else {
45
+ return value.value.toString();
46
+ }
47
+ };
48
+
49
+ /**
50
+ * Calculates column definition for a given p-table column
51
+ */
52
+ export function makeColDef(
53
+ iCol: number,
54
+ spec: PTableColumnSpec,
55
+ hiddenColIds?: string[],
56
+ cellButtonAxisParams?: PlAgCellButtonAxisParams,
57
+ ): ColDef {
58
+ const colId = strinfigyPTableColumnId(spec);
59
+ const valueType = spec.type === 'axis' ? spec.spec.type : spec.spec.valueType;
60
+ return {
61
+ colId,
62
+ mainMenuItems: defaultMainMenuItems,
63
+ context: spec,
64
+ field: iCol.toString(),
65
+ headerName: spec.spec.annotations?.['pl7.app/label']?.trim() ?? 'Unlabeled ' + spec.type + ' ' + iCol.toString(),
66
+ lockPosition: spec.type === 'axis',
67
+ hide: hiddenColIds?.includes(colId) ?? isColumnOptional(spec.spec),
68
+ valueFormatter: defaultValueFormatter,
69
+ headerComponent: PlAgColumnHeader,
70
+ cellRendererSelector: cellButtonAxisParams?.showCellButtonForAxisId
71
+ ? (params: ICellRendererParams) => {
72
+ if (spec.type !== 'axis') return;
73
+
74
+ const axisId = (params.colDef?.context as PTableColumnSpec)?.id as AxisId;
75
+ if (lodash.isEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {
76
+ return {
77
+ component: PlAgTextAndButtonCell,
78
+ params: {
79
+ invokeRowsOnDoubleClick: cellButtonAxisParams.cellButtonInvokeRowsOnDoubleClick,
80
+ onClick: (prms: ICellRendererParams<PlAgDataTableRow>) => {
81
+ cellButtonAxisParams.trigger(prms.data?.key);
82
+ },
83
+ },
84
+ };
85
+ }
86
+ }
87
+ : undefined,
88
+ headerComponentParams: {
89
+ type: ((): PlAgHeaderComponentType => {
90
+ switch (valueType) {
91
+ case 'Int':
92
+ case 'Long':
93
+ case 'Float':
94
+ case 'Double':
95
+ return 'Number';
96
+ case 'String':
97
+ case 'Bytes':
98
+ return 'Text';
99
+ default:
100
+ throw Error(`unsupported data type: ${valueType}`);
101
+ }
102
+ })(),
103
+ } satisfies PlAgHeaderComponentParams,
104
+ cellDataType: (() => {
105
+ switch (valueType) {
106
+ case 'Int':
107
+ case 'Long':
108
+ case 'Float':
109
+ case 'Double':
110
+ return 'number';
111
+ case 'String':
112
+ case 'Bytes':
113
+ return 'text';
114
+ default:
115
+ throw Error(`unsupported data type: ${valueType}`);
116
+ }
117
+ })(),
118
+ };
119
+ }
120
+
121
+ export function makeRowId(rowKey: PTableValue[]): PTableRowKeyJson {
122
+ return canonicalizeJson(rowKey);
123
+ }
124
+
125
+ export function isLabelColumn(column: PTableColumnSpec) {
126
+ return column.type === 'column' && isLabelColumnSpec(column.spec);
127
+ }
@@ -11,7 +11,7 @@ import type {
11
11
  import { getAxisId, pTableValue } from '@platforma-sdk/model';
12
12
  import canonicalize from 'canonicalize';
13
13
  import * as lodash from 'lodash';
14
- import { defaultValueFormatter } from './table-source';
14
+ import { defaultValueFormatter } from './common';
15
15
  import type { PlAgDataTableRow } from '../types';
16
16
 
17
17
  type HeterogeneousColumnInfo = {
@@ -172,7 +172,7 @@ function calculateRowData(
172
172
  let row: PlAgDataTableRow;
173
173
  const id = canonicalize(Object.values(rowPart)) ?? '';
174
174
  if (!uniqueRowsMap.has(id)) {
175
- row = { id: uniqueRowsMap.size.toString(), ...rowPart };
175
+ row = { id: `${uniqueRowsMap.size}`, ...rowPart };
176
176
  uniqueRowsMap.set(id, row);
177
177
  } else {
178
178
  row = uniqueRowsMap.get(id)!;
@@ -0,0 +1,260 @@
1
+ import type {
2
+ ColDef,
3
+ IServerSideDatasource,
4
+ IServerSideGetRowsParams,
5
+ RowModelType,
6
+ } from 'ag-grid-enterprise';
7
+ import type {
8
+ PlDataTableGridStateWithoutSheets,
9
+ PlDataTableModel,
10
+ PTableColumnSpec,
11
+ } from '@platforma-sdk/model';
12
+ import {
13
+ getAxisId,
14
+ pTableValue,
15
+ type PColumnSpec,
16
+ type PFrameDriver,
17
+ type PlDataTableSheet,
18
+ type PTableVector,
19
+ } from '@platforma-sdk/model';
20
+ import * as lodash from 'lodash';
21
+ import type { PlAgDataTableRow } from '../types';
22
+ import { makeRowNumberColDef, PlAgDataTableRowNumberColId } from './row-number';
23
+ import { objectHash } from '../../../objectHash';
24
+ import type { Ref } from 'vue';
25
+ import {
26
+ isLabelColumn,
27
+ makeColDef,
28
+ makeRowId,
29
+ PTableHidden,
30
+ type PlAgCellButtonAxisParams,
31
+ } from './common';
32
+ import canonicalize from 'canonicalize';
33
+
34
+ /** Convert columnar data from the driver to rows, used by ag-grid */
35
+ function columns2rows(
36
+ fields: number[],
37
+ columns: PTableVector[],
38
+ axes: number[],
39
+ resultMapping: number[],
40
+ ): PlAgDataTableRow[] {
41
+ const rowData: PlAgDataTableRow[] = [];
42
+ for (let iRow = 0; iRow < columns[0].data.length; ++iRow) {
43
+ const key = axes.map((iAxis) => pTableValue(columns[resultMapping[iAxis]], iRow));
44
+ const row: PlAgDataTableRow = { id: makeRowId(key), key };
45
+ fields.forEach((field, iCol) => {
46
+ row[field.toString() as `${number}`] = resultMapping[iCol] === -1
47
+ ? PTableHidden
48
+ : pTableValue(columns[resultMapping[iCol]], iRow);
49
+ });
50
+ rowData.push(row);
51
+ }
52
+ return rowData;
53
+ }
54
+
55
+ /**
56
+ * Calculate GridOptions for p-table data source type
57
+ */
58
+ export async function updatePFrameGridOptions(
59
+ pfDriver: PFrameDriver,
60
+ model: PlDataTableModel,
61
+ sheets: PlDataTableSheet[],
62
+ clientSide: boolean,
63
+ gridState: Ref<PlDataTableGridStateWithoutSheets>,
64
+ cellButtonAxisParams?: PlAgCellButtonAxisParams,
65
+ ): Promise<{
66
+ columnDefs: ColDef[];
67
+ serverSideDatasource?: IServerSideDatasource;
68
+ rowModelType: RowModelType;
69
+ rowData?: PlAgDataTableRow[];
70
+ }> {
71
+ const pt = model.tableHandle;
72
+ const specs = model.tableSpec;
73
+ type SpecId = string;
74
+ const specId = (spec: PTableColumnSpec): SpecId =>
75
+ spec.type === 'axis' ? canonicalize(spec.spec)! : spec.id;
76
+ const dataSpecs = await pfDriver.getSpec(pt);
77
+ const dataSpecsMap = new Map<SpecId, number>();
78
+ dataSpecs.forEach((spec, i) => {
79
+ dataSpecsMap.set(specId(spec), i);
80
+ });
81
+ const specsToDataSpecsMapping = new Map<number, number>();
82
+ const dataSpecsToSpecsMapping = new Map<number, number>();
83
+ specs.forEach((spec, i) => {
84
+ const dataSpecIdx = dataSpecsMap.get(specId(spec));
85
+ specsToDataSpecsMapping.set(i, dataSpecIdx ?? -1);
86
+ if (dataSpecIdx !== undefined) dataSpecsToSpecsMapping.set(dataSpecIdx, i);
87
+ });
88
+
89
+ const oldSourceId = gridState.value.sourceId;
90
+
91
+ const newSourceId = await objectHash(specs);
92
+
93
+ const isSourceIdChanged = oldSourceId !== newSourceId;
94
+
95
+ const columnVisibility = isSourceIdChanged ? undefined : gridState.value.columnVisibility;
96
+
97
+ if (isSourceIdChanged) {
98
+ gridState.value = {
99
+ ...gridState.value,
100
+ sourceId: newSourceId,
101
+ };
102
+ }
103
+
104
+ let numberOfAxes = specs.findIndex((s) => s.type === 'column');
105
+ if (numberOfAxes === -1) numberOfAxes = specs.length;
106
+
107
+ // column indices in the specs array that we are going to process
108
+ const indices = [...specs.keys()]
109
+ .filter(
110
+ (i) =>
111
+ !lodash.some(
112
+ sheets,
113
+ (sheet) =>
114
+ lodash.isEqual(getAxisId(sheet.axis), specs[i].id)
115
+ || (specs[i].type === 'column'
116
+ && specs[i].spec.name === 'pl7.app/label'
117
+ && specs[i].spec.axesSpec.length === 1
118
+ && lodash.isEqual(getAxisId(sheet.axis), getAxisId(specs[i].spec.axesSpec[0]))),
119
+ ),
120
+ )
121
+ .sort((a, b) => {
122
+ if (specs[a].type !== specs[b].type) return specs[a].type === 'axis' ? -1 : 1;
123
+
124
+ const aPriority = specs[a].spec.annotations?.['pl7.app/table/orderPriority'];
125
+ const bPriority = specs[b].spec.annotations?.['pl7.app/table/orderPriority'];
126
+
127
+ if (aPriority === undefined) return bPriority === undefined ? 0 : 1;
128
+ if (bPriority === undefined) return -1;
129
+ return Number(bPriority) - Number(aPriority);
130
+ });
131
+
132
+ const fields = [...indices];
133
+
134
+ // process label columns
135
+ for (let i = indices.length - 1; i >= 0; --i) {
136
+ const idx = indices[i];
137
+ if (!isLabelColumn(specs[idx])) continue;
138
+
139
+ // axis of labels
140
+ const axisId = getAxisId((specs[idx].spec as PColumnSpec).axesSpec[0]);
141
+ const axisIdx = indices.findIndex((idx) => lodash.isEqual(specs[idx].id, axisId));
142
+ if (axisIdx === -1) {
143
+ // no axis, it was already processed
144
+ continue;
145
+ }
146
+
147
+ indices[axisIdx] = idx;
148
+
149
+ // remove original axis
150
+ indices.splice(i, 1);
151
+ fields.splice(i, 1);
152
+ }
153
+
154
+ const ptShape = await pfDriver.getShape(pt);
155
+ const rowCount = ptShape.rows;
156
+ const columnDefs: ColDef<PlAgDataTableRow>[] = [
157
+ makeRowNumberColDef(),
158
+ ...fields.map((i) => makeColDef(i, specs[i], columnVisibility?.hiddenColIds, cellButtonAxisParams)),
159
+ ];
160
+
161
+ // mixing in axis indices
162
+
163
+ const allIndices = [...indices];
164
+
165
+ // axisIdx (0..<axesCount) -> idx in allIndices array
166
+ const axisToFieldIdx = new Map<number, number>();
167
+ for (let i = 0; i < numberOfAxes; ++i) axisToFieldIdx.set(i, -1);
168
+
169
+ allIndices.forEach((idx, i) => {
170
+ if (axisToFieldIdx.has(idx)) axisToFieldIdx.set(idx, i);
171
+ });
172
+ // at this point we have axis indices that are not listed in indices set to -1 in axisToFieldIdx
173
+
174
+ // adding those indices at the end of allIndices array, to make sure we have all the axes in our response
175
+ for (const [key, value] of axisToFieldIdx) {
176
+ if (value === -1) {
177
+ axisToFieldIdx.set(key, allIndices.length /* at this index value will be inserted in the next line */);
178
+ allIndices.push(key);
179
+ }
180
+ }
181
+
182
+ // indices of axes in allIndices array
183
+ const axes: number[] = [];
184
+ for (let i = 0; i < numberOfAxes; ++i) {
185
+ const fieldIdx = axisToFieldIdx.get(i);
186
+ if (fieldIdx === undefined || fieldIdx === -1) throw new Error('assertion exception');
187
+ axes.push(fieldIdx);
188
+ }
189
+
190
+ const requestIndices: number[] = [];
191
+ const resultMapping: number[] = [];
192
+ allIndices.forEach((idx) => {
193
+ const dataSpecIdx = specsToDataSpecsMapping.get(idx)!;
194
+ if (dataSpecIdx !== -1) {
195
+ resultMapping.push(requestIndices.length);
196
+ requestIndices.push(dataSpecIdx);
197
+ } else {
198
+ resultMapping.push(-1);
199
+ }
200
+ });
201
+
202
+ if (clientSide) {
203
+ const data = await pfDriver.getData(pt, requestIndices);
204
+ return {
205
+ rowModelType: 'clientSide',
206
+ columnDefs,
207
+ rowData: columns2rows(fields, data, axes, resultMapping),
208
+ };
209
+ }
210
+
211
+ let lastParams: IServerSideGetRowsParams | undefined = undefined;
212
+ const serverSideDatasource = {
213
+ getRows: async (params: IServerSideGetRowsParams) => {
214
+ try {
215
+ if (rowCount == 0) {
216
+ params.success({ rowData: [], rowCount });
217
+ params.api.setGridOption('loading', false);
218
+ params.api.showNoRowsOverlay();
219
+ return;
220
+ }
221
+
222
+ // this is to avoid double flickering when underlying table is changed
223
+ if (lastParams && !lodash.isEqual(lastParams.request.sortModel, params.request.sortModel)) {
224
+ lastParams = undefined;
225
+ params.api.setGridOption('loading', true);
226
+ params.success({ rowData: [], rowCount: 0 });
227
+ return;
228
+ }
229
+ lastParams = params;
230
+
231
+ let length = 0;
232
+ let rowData: PlAgDataTableRow[] = [];
233
+ if (rowCount > 0 && params.request.startRow !== undefined && params.request.endRow !== undefined) {
234
+ length = Math.min(rowCount, params.request.endRow) - params.request.startRow;
235
+ if (length > 0) {
236
+ const data = await pfDriver.getData(pt, requestIndices, {
237
+ offset: params.request.startRow,
238
+ length,
239
+ });
240
+ rowData = columns2rows(fields, data, axes, resultMapping);
241
+ }
242
+ }
243
+
244
+ params.success({ rowData, rowCount });
245
+ params.api.autoSizeColumns(params.api.getAllDisplayedColumns().filter((column) => column.getColId() !== PlAgDataTableRowNumberColId));
246
+ params.api.setGridOption('loading', false);
247
+ } catch (error: unknown) {
248
+ params.api.setGridOption('loading', true);
249
+ params.fail();
250
+ console.trace(error);
251
+ }
252
+ },
253
+ } satisfies IServerSideDatasource;
254
+
255
+ return {
256
+ rowModelType: 'serverSide',
257
+ columnDefs,
258
+ serverSideDatasource,
259
+ };
260
+ }
@@ -1,10 +1,8 @@
1
1
  import type {
2
2
  ColDef,
3
- ICellRendererParams,
4
3
  IServerSideDatasource,
5
4
  IServerSideGetRowsParams,
6
5
  RowModelType,
7
- ValueFormatterParams,
8
6
  } from 'ag-grid-enterprise';
9
7
  import type {
10
8
  PlDataTableGridStateWithoutSheets,
@@ -12,128 +10,19 @@ import type {
12
10
  import {
13
11
  getAxisId,
14
12
  pTableValue,
15
- isPTableAbsent,
16
- type AxisId,
17
13
  type PColumnSpec,
18
14
  type PFrameDriver,
19
15
  type PlDataTableSheet,
20
- type PTableColumnSpec,
21
16
  type PTableHandle,
22
- type PTableValue,
23
17
  type PTableVector,
24
- PTableNA,
25
18
  } from '@platforma-sdk/model';
26
- import canonicalize from 'canonicalize';
27
19
  import * as lodash from 'lodash';
28
- import { PlAgColumnHeader, type PlAgHeaderComponentParams, type PlAgHeaderComponentType } from '../../PlAgColumnHeader';
29
- import PlAgTextAndButtonCell from '../../PlAgTextAndButtonCell/PlAgTextAndButtonCell.vue';
30
- import type { PlAgDataTableRow, PTableRowKey } from '../types';
20
+ import type { PlAgDataTableRow } from '../types';
31
21
  import { makeRowNumberColDef, PlAgDataTableRowNumberColId } from './row-number';
32
22
  import { getHeterogeneousColumns, updatePFrameGridOptionsHeterogeneousAxes } from './table-source-heterogeneous';
33
- import { defaultMainMenuItems } from './menu-items';
34
23
  import { objectHash } from '../../../objectHash';
35
24
  import type { Ref } from 'vue';
36
-
37
- type PlAgCellButtonAxisParams = {
38
- showCellButtonForAxisId?: AxisId;
39
- cellButtonInvokeRowsOnDoubleClick?: boolean;
40
- trigger: (key?: PTableRowKey) => void;
41
- };
42
-
43
- /**
44
- * Generate unique colId based on the column spec.
45
- */
46
- function makeColId(spec: PTableColumnSpec) {
47
- return canonicalize(spec)!;
48
- }
49
-
50
- /**
51
- * Extract `PTableColumnId` from colId string
52
- */
53
- export function parseColId(str: string) {
54
- return JSON.parse(str) as PTableColumnSpec;
55
- }
56
-
57
- export const defaultValueFormatter = (value: ValueFormatterParams<PlAgDataTableRow, PTableValue>) => {
58
- if (value.value === undefined) {
59
- return 'undefined';
60
- } else if (isPTableAbsent(value.value) || value.value === PTableNA) {
61
- return '';
62
- } else {
63
- return value.value.toString();
64
- }
65
- };
66
-
67
- /**
68
- * Calculates column definition for a given p-table column
69
- */
70
- function makeColDef(iCol: number, spec: PTableColumnSpec, hiddenColIds?: string[], cellButtonAxisParams?: PlAgCellButtonAxisParams): ColDef {
71
- const colId = makeColId(spec);
72
- const valueType = spec.type === 'axis' ? spec.spec.type : spec.spec.valueType;
73
- return {
74
- colId,
75
- mainMenuItems: defaultMainMenuItems,
76
- context: spec,
77
- field: iCol.toString(),
78
- headerName: spec.spec.annotations?.['pl7.app/label']?.trim() ?? 'Unlabeled ' + spec.type + ' ' + iCol.toString(),
79
- lockPosition: spec.type === 'axis',
80
- hide: hiddenColIds?.includes(colId) ?? spec.spec.annotations?.['pl7.app/table/visibility'] === 'optional',
81
- valueFormatter: defaultValueFormatter,
82
- headerComponent: PlAgColumnHeader,
83
- cellRendererSelector: cellButtonAxisParams?.showCellButtonForAxisId
84
- ? (params: ICellRendererParams) => {
85
- if (spec.type !== 'axis') return;
86
-
87
- const axisId = (params.colDef?.context as PTableColumnSpec)?.id as AxisId;
88
- if (lodash.isEqual(axisId, cellButtonAxisParams.showCellButtonForAxisId)) {
89
- return {
90
- component: PlAgTextAndButtonCell,
91
- params: {
92
- invokeRowsOnDoubleClick: cellButtonAxisParams.cellButtonInvokeRowsOnDoubleClick,
93
- onClick: (prms: ICellRendererParams<PlAgDataTableRow>) => {
94
- cellButtonAxisParams.trigger(prms.data?.key);
95
- },
96
- },
97
- };
98
- }
99
- }
100
- : undefined,
101
- headerComponentParams: {
102
- type: ((): PlAgHeaderComponentType => {
103
- switch (valueType) {
104
- case 'Int':
105
- case 'Long':
106
- case 'Float':
107
- case 'Double':
108
- return 'Number';
109
- case 'String':
110
- case 'Bytes':
111
- return 'Text';
112
- default:
113
- throw Error(`unsupported data type: ${valueType}`);
114
- }
115
- })(),
116
- } satisfies PlAgHeaderComponentParams,
117
- cellDataType: (() => {
118
- switch (valueType) {
119
- case 'Int':
120
- case 'Long':
121
- case 'Float':
122
- case 'Double':
123
- return 'number';
124
- case 'String':
125
- case 'Bytes':
126
- return 'text';
127
- default:
128
- throw Error(`unsupported data type: ${valueType}`);
129
- }
130
- })(),
131
- };
132
- }
133
-
134
- export function makeRowId(rowKey: PTableValue[]) {
135
- return canonicalize(rowKey)!;
136
- }
25
+ import { isLabelColumn, makeColDef, makeRowId, type PlAgCellButtonAxisParams } from './common';
137
26
 
138
27
  /** Convert columnar data from the driver to rows, used by ag-grid */
139
28
  function columns2rows(fields: number[], columns: PTableVector[], axes: number[]): PlAgDataTableRow[] {
@@ -149,8 +38,6 @@ function columns2rows(fields: number[], columns: PTableVector[], axes: number[])
149
38
  return rowData;
150
39
  }
151
40
 
152
- const isLabelColumn = (col: PTableColumnSpec) => col.type === 'column' && col.spec.axesSpec.length === 1 && col.spec.name === 'pl7.app/label';
153
-
154
41
  /**
155
42
  * Calculate GridOptions for p-table data source type
156
43
  */
@@ -1,5 +1,7 @@
1
1
  import type {
2
+ CanonicalizedJson,
2
3
  LocalBlobHandleAndSize,
4
+ PlDataTableModel,
3
5
  PlDataTableSheet,
4
6
  PlTableFilter,
5
7
  PlTableFilterType,
@@ -29,6 +31,19 @@ export type PlDataTableSettings =
29
31
  | PlDataTableSettingsPTable
30
32
  | PlDataTableSettingsXsv;
31
33
 
34
+ export type PlAgDataTableSettingsPTable = {
35
+ /** The type of the source to feed the data into the table */
36
+ sourceType: 'ptable';
37
+ /** PTable handle output */
38
+ model?: PlDataTableModel;
39
+ /** Sheets that we want to show in our table */
40
+ sheets?: PlDataTableSheet[];
41
+ };
42
+
43
+ /** Data table settings */
44
+ export type PlAgDataTableSettings =
45
+ | PlAgDataTableSettingsPTable;
46
+
32
47
  /** PlTableFilters restriction entry */
33
48
  export type PlTableFiltersRestriction = {
34
49
  /** Spec of the column for which filter types should be restricted */
@@ -57,12 +72,15 @@ export type PlAgDataTableController = {
57
72
  focusRow: (rowKey: PTableRowKey) => Promise<void>;
58
73
  };
59
74
 
75
+ /** Canonicalized PTableValue array JSON string */
76
+ export type PTableRowKeyJson = CanonicalizedJson<PTableValue[]>;
77
+
60
78
  /** PlAgDataTable row */
61
79
  export type PlAgDataTableRow = {
62
80
  /** Axis key is not present for heterogeneous axes */
63
81
  key?: PTableRowKey;
64
82
  /** Unique row identifier, created as canonicalize(key)! when key is present */
65
- id: string;
83
+ id: PTableRowKeyJson | `${number}`;
66
84
  /** Row values by column; sheet axes and labeled axes are excluded */
67
85
  [field: `${number}` | `hC${number}`]: PTableValue;
68
86
  };
package/src/lib.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import './assets/ui.scss';
2
2
  import BlockLayout from './components/BlockLayout.vue';
3
3
  import PlAgDataTable from './components/PlAgDataTable/PlAgDataTable.vue';
4
+ import PlAgDataTableV2 from './components/PlAgDataTable/PlAgDataTableV2.vue';
4
5
  import PlAgOverlayLoading from './components/PlAgDataTable/PlAgOverlayLoading.vue';
5
6
  import PlAgOverlayNoRows from './components/PlAgDataTable/PlAgOverlayNoRows.vue';
6
7
  import ValueOrErrorsComponent from './components/ValueOrErrorsComponent.vue';
7
8
 
8
- export { BlockLayout, PlAgDataTable, PlAgOverlayLoading, PlAgOverlayNoRows, ValueOrErrorsComponent };
9
+ export { BlockLayout, PlAgDataTable, PlAgDataTableV2, PlAgOverlayLoading, PlAgOverlayNoRows, ValueOrErrorsComponent };
9
10
 
10
11
  export * from './AgGridVue';
11
12