@platforma-sdk/ui-vue 1.18.0 → 1.18.1

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 (29) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/lib.js +2117 -2084
  3. package/dist/lib.umd.cjs +22 -22
  4. package/dist/src/components/PlAgCsvExporter/PlAgCsvExporter.vue.d.ts +7 -0
  5. package/dist/src/components/PlAgCsvExporter/PlAgCsvExporter.vue.d.ts.map +1 -0
  6. package/dist/src/components/PlAgCsvExporter/export-csv.d.ts +3 -0
  7. package/dist/src/components/PlAgCsvExporter/export-csv.d.ts.map +1 -0
  8. package/dist/src/components/PlAgCsvExporter/index.d.ts +2 -0
  9. package/dist/src/components/PlAgCsvExporter/index.d.ts.map +1 -0
  10. package/dist/src/components/PlAgDataTable/PlAgDataTable.vue.d.ts +7 -1
  11. package/dist/src/components/PlAgDataTable/PlAgDataTable.vue.d.ts.map +1 -1
  12. package/dist/src/components/PlAgDataTable/index.d.ts +1 -0
  13. package/dist/src/components/PlAgDataTable/index.d.ts.map +1 -1
  14. package/dist/src/components/PlAgDataTable/types.d.ts +0 -2
  15. package/dist/src/components/PlAgDataTable/types.d.ts.map +1 -1
  16. package/dist/src/lib.d.ts +2 -0
  17. package/dist/src/lib.d.ts.map +1 -1
  18. package/dist/style.css +1 -1
  19. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  20. package/package.json +5 -5
  21. package/src/components/PlAgCsvExporter/PlAgCsvExporter.vue +31 -0
  22. package/src/components/{PlAgDataTable/sources → PlAgCsvExporter}/export-csv.ts +17 -21
  23. package/src/components/PlAgCsvExporter/index.ts +1 -0
  24. package/src/components/PlAgDataTable/PlAgDataTable.vue +9 -2
  25. package/src/components/PlAgDataTable/index.ts +1 -1
  26. package/src/components/PlAgDataTable/types.ts +0 -2
  27. package/src/lib.ts +3 -1
  28. package/dist/src/components/PlAgDataTable/sources/export-csv.d.ts +0 -4
  29. package/dist/src/components/PlAgDataTable/sources/export-csv.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/ui-vue",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "type": "module",
5
5
  "main": "dist/lib.umd.cjs",
6
6
  "module": "dist/lib.js",
@@ -37,8 +37,8 @@
37
37
  "@ag-grid-community/theming": "^32.3.3",
38
38
  "@ag-grid-enterprise/side-bar": "^32.3.3",
39
39
  "@ag-grid-enterprise/column-tool-panel": "^32.3.3",
40
- "@milaboratories/uikit": "^2.2.28",
41
- "@platforma-sdk/model": "^1.18.0"
40
+ "@platforma-sdk/model": "^1.18.0",
41
+ "@milaboratories/uikit": "^2.2.28"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@faker-js/faker": "^9.2.0",
@@ -58,8 +58,8 @@
58
58
  "yarpm": "^1.2.0",
59
59
  "semver": "^7.6.3",
60
60
  "@types/semver": "^7.5.8",
61
- "@milaboratories/helpers": "^1.6.9",
62
- "@milaboratories/eslint-config": "^1.0.0"
61
+ "@milaboratories/eslint-config": "^1.0.0",
62
+ "@milaboratories/helpers": "^1.6.9"
63
63
  },
64
64
  "scripts": {
65
65
  "test": "vitest run --passWithNoTests",
@@ -0,0 +1,31 @@
1
+ <script setup lang="ts">
2
+ import type { GridApi } from '@ag-grid-community/core';
3
+ import { PlBtnGhost, PlMaskIcon24 } from '@milaboratories/uikit';
4
+ import { shallowRef, toRefs } from 'vue';
5
+ import { PlAgDataTableToolsPanelId } from '../PlAgDataTableToolsPanel/PlAgDataTableToolsPanelId';
6
+ import { exportCsv } from './export-csv';
7
+
8
+ const props = defineProps<{
9
+ api: GridApi;
10
+ }>();
11
+ const { api: gridApi } = toRefs(props);
12
+
13
+ const exporting = shallowRef(false);
14
+ const initiateExport = () => {
15
+ exporting.value = true;
16
+ exportCsv(gridApi.value, () => exporting.value = false);
17
+ };
18
+ </script>
19
+
20
+ <template>
21
+ <div>
22
+ <Teleport :to="`#${PlAgDataTableToolsPanelId}`">
23
+ <PlBtnGhost :loading="exporting" @click.stop="initiateExport">
24
+ Export
25
+ <template #append>
26
+ <PlMaskIcon24 name="export" />
27
+ </template>
28
+ </PlBtnGhost>
29
+ </Teleport>
30
+ </div>
31
+ </template>
@@ -1,6 +1,5 @@
1
1
  import type { ColDef, ColGroupDef } from '@ag-grid-community/core';
2
2
  import { createGrid, type GridApi, type GridOptions } from '@ag-grid-community/core';
3
- import type { PlAgDataTableRow } from '../types';
4
3
  import { ServerSideRowModelModule } from '@ag-grid-enterprise/server-side-row-model';
5
4
 
6
5
  function createGridDiv(): HTMLDivElement {
@@ -17,22 +16,19 @@ function destroyGridDiv(cellFake: HTMLDivElement) {
17
16
  document.body.removeChild(cellFake);
18
17
  }
19
18
 
20
- export async function exportCsv(gridApi?: GridApi<PlAgDataTableRow>) {
21
- if (!gridApi) return;
22
-
19
+ export async function exportCsv(gridApi: GridApi, completed: () => void) {
23
20
  const rowModel = gridApi.getGridOption('rowModelType');
24
21
  switch (rowModel) {
25
22
  case 'clientSide': {
26
- return gridApi.exportDataAsCsv();
23
+ gridApi.exportDataAsCsv();
24
+ return completed();
27
25
  }
28
26
 
29
27
  case 'serverSide': {
30
- const groupState = gridApi.getServerSideGroupLevelState();
31
- if (groupState.length === 0) return;
32
-
33
- const state = groupState[0];
34
- if (state.rowCount <= state.cacheBlockSize!) {
35
- return gridApi.exportDataAsCsv();
28
+ const state = gridApi.getServerSideGroupLevelState();
29
+ if (state.length === 0 || state[0].rowCount <= state[0].cacheBlockSize!) {
30
+ gridApi.exportDataAsCsv();
31
+ return completed();
36
32
  }
37
33
 
38
34
  const gridDiv = createGridDiv();
@@ -47,23 +43,23 @@ export async function exportCsv(gridApi?: GridApi<PlAgDataTableRow>) {
47
43
  valueGetter: def.valueGetter,
48
44
  })) ?? [],
49
45
  serverSideDatasource: gridApi.getGridOption('serverSideDatasource'),
50
- cacheBlockSize: state.rowCount,
46
+ cacheBlockSize: state[0].rowCount,
51
47
  onModelUpdated: (event) => {
52
- const groupState = event.api.getServerSideGroupLevelState();
53
- if (groupState.length === 0) return;
54
-
55
- const state = groupState[0];
56
- if (state.rowCount !== state.cacheBlockSize) return;
57
-
58
- event.api.exportDataAsCsv();
59
- destroyGridDiv(gridDiv);
48
+ const state = event.api.getServerSideGroupLevelState();
49
+ if (state.length > 0 && state[0].rowCount === state[0].cacheBlockSize) {
50
+ event.api.exportDataAsCsv();
51
+ destroyGridDiv(gridDiv);
52
+ return completed();
53
+ }
60
54
  },
61
55
  defaultCsvExportParams: gridApi.getGridOption('defaultCsvExportParams'),
62
56
  };
63
57
  return createGrid(gridDiv, gridOptions, { modules: [ServerSideRowModelModule] });
64
58
  }
65
59
 
66
- default:
60
+ default: {
61
+ completed();
67
62
  throw Error(`exportCsv unsupported for rowModelType = ${rowModel}`);
63
+ }
68
64
  }
69
65
  };
@@ -0,0 +1 @@
1
+ export { default as PlAgCsvExporter } from './PlAgCsvExporter.vue';
@@ -39,8 +39,8 @@ import { makeRowId, parseColId, updatePFrameGridOptions } from './sources/table-
39
39
  import type { PlAgDataTableController, PlDataTableSettings, PlAgDataTableRow } from './types';
40
40
  import { PlAgGridColumnManager } from '../PlAgGridColumnManager';
41
41
  import { autoSizeRowNumberColumn, PlAgDataTableRowNumberColId } from './sources/row-number';
42
- import { exportCsv } from './sources/export-csv';
43
42
  import { focusRow, makeOnceTracker, trackFirstDataRendered } from './sources/focus-row';
43
+ import PlAgCsvExporter from '../PlAgCsvExporter/PlAgCsvExporter.vue';
44
44
 
45
45
  ModuleRegistry.registerModules([
46
46
  ClientSideRowModelModule,
@@ -60,6 +60,13 @@ const props = defineProps<{
60
60
  * This component serves as the target for teleporting the button.
61
61
  */
62
62
  showColumnsPanel?: boolean;
63
+ /**
64
+ * The showExportButton prop controls the display of a button that allows
65
+ * to export table data in CSV format. To make the button functional
66
+ * and visible, you must also include the PlAgDataTableToolsPanel component in your layout.
67
+ * This component serves as the target for teleporting the button.
68
+ */
69
+ showExportButton?: boolean;
63
70
  showCellButtonForAxisId?: AxisId;
64
71
  }>();
65
72
  const { settings } = toRefs(props);
@@ -247,7 +254,6 @@ const onGridPreDestroyed = () => {
247
254
  };
248
255
 
249
256
  defineExpose<PlAgDataTableController>({
250
- exportCsv: () => exportCsv(gridApi.value),
251
257
  focusRow: (rowKey) => focusRow(makeRowId(rowKey), firstDataRenderedTracker),
252
258
  });
253
259
 
@@ -376,6 +382,7 @@ watch(
376
382
  <template>
377
383
  <div class="ap-ag-data-table-container">
378
384
  <PlAgGridColumnManager v-if="gridApi && showColumnsPanel" :api="gridApi" />
385
+ <PlAgCsvExporter v-if="gridApi && showExportButton" :api="gridApi" />
379
386
  <div v-if="settings?.sourceType === 'ptable' && !!settings.sheets && settings.sheets.length > 0" class="ap-ag-data-table-sheets">
380
387
  <PlDropdownLine
381
388
  v-for="(sheet, i) in settings.sheets"
@@ -3,5 +3,5 @@ export { default as PlAgOverlayLoading } from './PlAgOverlayLoading.vue';
3
3
  export { default as PlAgOverlayNoRows } from './PlAgOverlayNoRows.vue';
4
4
 
5
5
  export * from './types';
6
-
7
6
  export * from './sources/row-number';
7
+ export * from './sources/focus-row';
@@ -46,8 +46,6 @@ export type PTableRowKey = PTableValue[];
46
46
 
47
47
  /** PlAgDataTable controller contains all exported methods */
48
48
  export type PlAgDataTableController = {
49
- /** Export table data as Csv file */
50
- exportCsv: () => void;
51
49
  /** Scroll table to make row with provided key visible */
52
50
  focusRow: (rowKey: PTableRowKey) => void;
53
51
  };
package/src/lib.ts CHANGED
@@ -12,8 +12,10 @@ export * from './components/PlAgColumnHeader';
12
12
  export * from './components/PlAgCellFile';
13
13
 
14
14
  export * from './components/PlAgDataTable/types';
15
-
16
15
  export * from './components/PlAgDataTable/sources/row-number';
16
+ export * from './components/PlAgDataTable/sources/focus-row';
17
+
18
+ export * from './components/PlAgCsvExporter';
17
19
 
18
20
  export * from './components/PlAgTextAndButtonCell';
19
21
 
@@ -1,4 +0,0 @@
1
- import { type GridApi } from '@ag-grid-community/core';
2
- import type { PlAgDataTableRow } from '../types';
3
- export declare function exportCsv(gridApi?: GridApi<PlAgDataTableRow>): Promise<void | GridApi<any>>;
4
- //# sourceMappingURL=export-csv.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"export-csv.d.ts","sourceRoot":"","sources":["../../../../../src/components/PlAgDataTable/sources/export-csv.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiBjD,wBAAsB,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,gCAiDlE"}