@platforma-sdk/ui-vue 1.3.5

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 (91) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +56 -0
  3. package/.prettierrc +6 -0
  4. package/CHANGELOG.md +9 -0
  5. package/README.md +5 -0
  6. package/dist/lib.js +50299 -0
  7. package/dist/lib.umd.cjs +248 -0
  8. package/dist/src/components/BlockLayout.vue.d.ts +5 -0
  9. package/dist/src/components/BlockLayout.vue.d.ts.map +1 -0
  10. package/dist/src/components/LoaderPage.vue.d.ts +3 -0
  11. package/dist/src/components/LoaderPage.vue.d.ts.map +1 -0
  12. package/dist/src/components/NotFound.vue.d.ts +3 -0
  13. package/dist/src/components/NotFound.vue.d.ts.map +1 -0
  14. package/dist/src/components/PlAgDataTable/OverlayLoading.vue.d.ts +11 -0
  15. package/dist/src/components/PlAgDataTable/OverlayLoading.vue.d.ts.map +1 -0
  16. package/dist/src/components/PlAgDataTable/OverlayNoRows.vue.d.ts +3 -0
  17. package/dist/src/components/PlAgDataTable/OverlayNoRows.vue.d.ts.map +1 -0
  18. package/dist/src/components/PlAgDataTable/PlAgDataTable.vue.d.ts +16 -0
  19. package/dist/src/components/PlAgDataTable/PlAgDataTable.vue.d.ts.map +1 -0
  20. package/dist/src/components/PlAgDataTable/index.d.ts +3 -0
  21. package/dist/src/components/PlAgDataTable/index.d.ts.map +1 -0
  22. package/dist/src/components/PlAgDataTable/sources/file-source.d.ts +7 -0
  23. package/dist/src/components/PlAgDataTable/sources/file-source.d.ts.map +1 -0
  24. package/dist/src/components/PlAgDataTable/sources/table-source.d.ts +15 -0
  25. package/dist/src/components/PlAgDataTable/sources/table-source.d.ts.map +1 -0
  26. package/dist/src/components/PlAgDataTable/types.d.ts +35 -0
  27. package/dist/src/components/PlAgDataTable/types.d.ts.map +1 -0
  28. package/dist/src/components/ValueOrErrorsComponent.vue.d.ts +27 -0
  29. package/dist/src/components/ValueOrErrorsComponent.vue.d.ts.map +1 -0
  30. package/dist/src/composition/useWatchResult.d.ts +7 -0
  31. package/dist/src/composition/useWatchResult.d.ts.map +1 -0
  32. package/dist/src/computedResult.d.ts +35 -0
  33. package/dist/src/computedResult.d.ts.map +1 -0
  34. package/dist/src/createApp.d.ts +27 -0
  35. package/dist/src/createApp.d.ts.map +1 -0
  36. package/dist/src/createModel.d.ts +3 -0
  37. package/dist/src/createModel.d.ts.map +1 -0
  38. package/dist/src/defineApp.d.ts +14 -0
  39. package/dist/src/defineApp.d.ts.map +1 -0
  40. package/dist/src/defineStore.d.ts +2 -0
  41. package/dist/src/defineStore.d.ts.map +1 -0
  42. package/dist/src/lib.d.ts +16 -0
  43. package/dist/src/lib.d.ts.map +1 -0
  44. package/dist/src/types.d.ts +73 -0
  45. package/dist/src/types.d.ts.map +1 -0
  46. package/dist/src/types.static-test.d.ts +7 -0
  47. package/dist/src/types.static-test.d.ts.map +1 -0
  48. package/dist/src/urls.d.ts +4 -0
  49. package/dist/src/urls.d.ts.map +1 -0
  50. package/dist/src/utils.d.ts +20 -0
  51. package/dist/src/utils.d.ts.map +1 -0
  52. package/dist/style.css +1 -0
  53. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  54. package/index.html +13 -0
  55. package/package.json +64 -0
  56. package/src/assets/base.scss +9 -0
  57. package/src/assets/block.scss +71 -0
  58. package/src/assets/file-dialog.scss +181 -0
  59. package/src/assets/icons/empty-cat.svg +21 -0
  60. package/src/assets/icons/no-data-cat.svg +40 -0
  61. package/src/assets/ui.scss +9 -0
  62. package/src/components/BlockLayout.vue +40 -0
  63. package/src/components/LoaderPage.vue +7 -0
  64. package/src/components/NotFound.vue +21 -0
  65. package/src/components/PlAgDataTable/OverlayLoading.vue +47 -0
  66. package/src/components/PlAgDataTable/OverlayNoRows.vue +29 -0
  67. package/src/components/PlAgDataTable/PlAgDataTable.vue +293 -0
  68. package/src/components/PlAgDataTable/ag-theme.css +403 -0
  69. package/src/components/PlAgDataTable/assets/cat-in-bag.png +0 -0
  70. package/src/components/PlAgDataTable/assets/sad-cat.png +0 -0
  71. package/src/components/PlAgDataTable/index.ts +3 -0
  72. package/src/components/PlAgDataTable/sources/file-source.ts +25 -0
  73. package/src/components/PlAgDataTable/sources/table-source.ts +235 -0
  74. package/src/components/PlAgDataTable/types.ts +38 -0
  75. package/src/components/ValueOrErrorsComponent.vue +28 -0
  76. package/src/composition/useWatchResult.ts +42 -0
  77. package/src/computedResult.ts +47 -0
  78. package/src/createApp.ts +213 -0
  79. package/src/createModel.ts +108 -0
  80. package/src/defineApp.ts +78 -0
  81. package/src/defineStore.ts +32 -0
  82. package/src/lib.ts +26 -0
  83. package/src/types.static-test.ts +80 -0
  84. package/src/types.ts +106 -0
  85. package/src/urls.ts +14 -0
  86. package/src/utils.ts +75 -0
  87. package/src/vite-env.d.ts +8 -0
  88. package/tsconfig.json +11 -0
  89. package/tsconfig.lib.json +27 -0
  90. package/tsconfig.node.json +13 -0
  91. package/vite.config.ts +26 -0
@@ -0,0 +1,293 @@
1
+ <script lang="ts" setup>
2
+ import './ag-theme.css';
3
+ import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
4
+ import canonicalize from 'canonicalize';
5
+ import type { GridApi, GridOptions, SortState } from '@ag-grid-community/core';
6
+ import { ModuleRegistry } from '@ag-grid-community/core';
7
+ import { InfiniteRowModelModule } from '@ag-grid-community/infinite-row-model';
8
+ import { AgGridVue } from '@ag-grid-community/vue3';
9
+ import { ClipboardModule } from '@ag-grid-enterprise/clipboard';
10
+ import { RangeSelectionModule } from '@ag-grid-enterprise/range-selection';
11
+ import { PlDropdownLine } from '@milaboratories/uikit';
12
+ import type { AxisId, PlDataTableState, PTableRecordFilter, PTableSorting } from '@platforma-sdk/model';
13
+ import { computed, ref, watch, shallowRef, toRefs } from 'vue';
14
+ import OverlayLoading from './OverlayLoading.vue';
15
+ import OverlayNoRows from './OverlayNoRows.vue';
16
+ import { updateXsvGridOptions } from './sources/file-source';
17
+ import { parseColId, updatePFrameGridOptions } from './sources/table-source';
18
+ import type { PlDataTableSettings } from './types';
19
+ import * as lodash from 'lodash';
20
+
21
+ ModuleRegistry.registerModules([ClientSideRowModelModule, ClipboardModule, InfiniteRowModelModule, RangeSelectionModule]);
22
+
23
+ const tableState = defineModel<PlDataTableState>({ default: { gridState: {} } });
24
+ const props = defineProps<{
25
+ settings: Readonly<PlDataTableSettings>;
26
+ }>();
27
+ const { settings } = toRefs(props);
28
+
29
+ function makeSorting(state?: SortState): PTableSorting[] | undefined {
30
+ if (settings.value.sourceType !== 'ptable') return undefined;
31
+ return (
32
+ state?.sortModel.map(
33
+ (item) =>
34
+ ({
35
+ column: parseColId(item.colId),
36
+ ascending: item.sort === 'asc',
37
+ naAndAbsentAreLeastValues: true,
38
+ }) as PTableSorting,
39
+ ) ?? []
40
+ );
41
+ }
42
+
43
+ const gridState = computed({
44
+ get: () => {
45
+ const state = tableState.value;
46
+ return {
47
+ columnOrder: state.gridState.columnOrder,
48
+ sort: state.gridState.sort,
49
+ };
50
+ },
51
+ set: (gridState) => {
52
+ const sorting = makeSorting(gridState.sort);
53
+
54
+ const state = tableState.value;
55
+
56
+ state.gridState.columnOrder = gridState.columnOrder;
57
+ state.gridState.sort = gridState.sort;
58
+
59
+ if (settings.value.sourceType === 'ptable') {
60
+ if (!state.pTableParams) {
61
+ state.pTableParams = {
62
+ sorting: [],
63
+ filters: [],
64
+ };
65
+ }
66
+ state.pTableParams.sorting = sorting;
67
+ }
68
+
69
+ tableState.value = state;
70
+ },
71
+ });
72
+
73
+ const makeSheetId = (axis: AxisId) => canonicalize(axis)!;
74
+
75
+ function makeFilters(sheetsState: Record<string, string | number>): PTableRecordFilter[] | undefined {
76
+ if (settings.value.sourceType !== 'ptable') return undefined;
77
+ return (
78
+ settings.value.sheets?.map((sheet) => ({
79
+ type: 'bySingleColumn',
80
+ column: {
81
+ type: 'axis',
82
+ id: sheet.axis,
83
+ },
84
+ predicate: {
85
+ operator: 'Equal',
86
+ reference: sheetsState[makeSheetId(sheet.axis)],
87
+ },
88
+ })) ?? []
89
+ );
90
+ }
91
+
92
+ const sheetsState = computed({
93
+ get: () => tableState.value.gridState.sheets ?? {},
94
+ set: (sheetsState) => {
95
+ const filters = makeFilters(sheetsState);
96
+
97
+ const state = tableState.value;
98
+
99
+ state.gridState.sheets = sheetsState;
100
+
101
+ if (settings.value.sourceType === 'ptable') {
102
+ if (!state.pTableParams) {
103
+ state.pTableParams = {
104
+ sorting: [],
105
+ filters: [],
106
+ };
107
+ }
108
+ state.pTableParams.filters = filters;
109
+ }
110
+
111
+ tableState.value = state;
112
+ },
113
+ });
114
+
115
+ watch(
116
+ () => settings.value,
117
+ (settings, oldSettings) => {
118
+ if (settings.sourceType === 'ptable' && oldSettings?.sourceType === 'ptable' && lodash.isEqual(settings.sheets, oldSettings.sheets)) return;
119
+
120
+ if (settings.sourceType !== 'ptable') {
121
+ sheetsState.value = {};
122
+ return;
123
+ }
124
+
125
+ const state = sheetsState.value;
126
+ const sheets = settings.sheets ?? [];
127
+ for (const sheet of sheets) {
128
+ const sheetId = makeSheetId(sheet.axis);
129
+ if (!state[sheetId]) {
130
+ // @vadimpiven
131
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
132
+ // @ts-expect-error
133
+ state[sheetId] = sheet.defaultValue ?? sheet.options[0].value;
134
+ }
135
+ }
136
+ sheetsState.value = state;
137
+ },
138
+ { immediate: true },
139
+ );
140
+
141
+ const gridApi = shallowRef<GridApi>();
142
+ const gridOptions: GridOptions = {
143
+ animateRows: false,
144
+ suppressColumnMoveAnimation: true,
145
+ enableRangeSelection: true,
146
+ initialState: tableState.value.gridState,
147
+ onGridReady: (event) => {
148
+ gridApi.value = event.api;
149
+ },
150
+ onStateUpdated: (event) => {
151
+ gridState.value = {
152
+ columnOrder: event.state.columnOrder,
153
+ sort: event.state.sort,
154
+ };
155
+ },
156
+ autoSizeStrategy: { type: 'fitCellContents' },
157
+ onRowDataUpdated: (event) => {
158
+ event.api.autoSizeAllColumns();
159
+ },
160
+ rowModelType: 'infinite',
161
+ maxBlocksInCache: 10000,
162
+ cacheBlockSize: 100,
163
+ getRowId: (params) => params.data.id,
164
+ loading: true,
165
+ loadingOverlayComponentParams: { notReady: true },
166
+ loadingOverlayComponent: OverlayLoading,
167
+ noRowsOverlayComponent: OverlayNoRows,
168
+ };
169
+
170
+ const reloadKey = ref(0);
171
+ watch(
172
+ () => [gridApi.value, gridState.value] as const,
173
+ (state, oldState) => {
174
+ if (lodash.isEqual(state, oldState)) return;
175
+
176
+ const [gridApi, gridState] = state;
177
+ if (!gridApi) return;
178
+
179
+ const selfState = gridApi.getState();
180
+ if (lodash.isEqual(gridState.columnOrder, selfState.columnOrder) && lodash.isEqual(gridState.sort, selfState.sort)) return;
181
+
182
+ gridOptions.initialState = gridState;
183
+ ++reloadKey.value;
184
+ },
185
+ );
186
+
187
+ const onSheetChanged = (sheetId: string, newValue: string | number) => {
188
+ const state = sheetsState.value;
189
+ if (state[sheetId] === newValue) return;
190
+ // @vadimpiven
191
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
192
+ // @ts-expect-error
193
+ state[sheetId] = newValue;
194
+ sheetsState.value = state;
195
+ };
196
+
197
+ watch(
198
+ () => [gridApi.value, settings.value] as const,
199
+ async (state, oldState) => {
200
+ if (lodash.isEqual(state, oldState)) return;
201
+
202
+ const [gridApi, settings] = state;
203
+ if (!gridApi) return;
204
+
205
+ const platforma = window.platforma;
206
+ if (!platforma) throw Error('platforma not set');
207
+
208
+ const sourceType = settings.sourceType;
209
+ switch (sourceType) {
210
+ case 'ptable': {
211
+ const pfDriver = platforma.pFrameDriver;
212
+ if (!pfDriver) throw Error('platforma.pFrameDriver not set');
213
+
214
+ const pTable = settings.pTable;
215
+ if (!pTable?.ok || !pTable.value) {
216
+ return gridApi.updateGridOptions({
217
+ loading: true,
218
+ loadingOverlayComponentParams: { notReady: true },
219
+ columnDefs: [],
220
+ rowData: [],
221
+ });
222
+ }
223
+
224
+ const options = await updatePFrameGridOptions(gridApi, pfDriver, pTable.value, settings.sheets ?? []);
225
+ return gridApi.updateGridOptions({
226
+ loading: true,
227
+ loadingOverlayComponentParams: { notReady: false },
228
+ ...options,
229
+ });
230
+ }
231
+
232
+ case 'xsv': {
233
+ const blobDriver = platforma.blobDriver;
234
+ if (!blobDriver) throw Error('platforma.blobDriver not set');
235
+
236
+ const xsvFile = settings.xsvFile;
237
+ if (!xsvFile?.ok || !xsvFile.value) {
238
+ return gridApi.updateGridOptions({
239
+ loading: true,
240
+ loadingOverlayComponentParams: { notReady: true },
241
+ columnDefs: [],
242
+ rowData: [],
243
+ });
244
+ }
245
+
246
+ const options = await updateXsvGridOptions(gridApi, blobDriver, xsvFile.value);
247
+ return gridApi.updateGridOptions({
248
+ loading: true,
249
+ loadingOverlayComponentParams: { notReady: false },
250
+ ...options,
251
+ });
252
+ }
253
+
254
+ default:
255
+ throw Error(`unsupported source type: ${sourceType satisfies never}`);
256
+ }
257
+ },
258
+ );
259
+ </script>
260
+
261
+ <template>
262
+ <div class="ap-ag-data-table-container">
263
+ <div v-if="settings.sourceType === 'ptable' && (settings.sheets?.length ?? 0) > 0" class="ap-ag-data-table-sheets">
264
+ <PlDropdownLine
265
+ v-for="(sheet, i) in settings.sheets"
266
+ :key="i"
267
+ :model-value="sheetsState[makeSheetId(sheet.axis)]"
268
+ :options="sheet.options"
269
+ @update:model-value="(newValue) => onSheetChanged(makeSheetId(sheet.axis), newValue)"
270
+ />
271
+ </div>
272
+ <AgGridVue class="ap-ag-data-table-grid" :grid-options="gridOptions" />
273
+ </div>
274
+ </template>
275
+
276
+ <style lang="css" scoped>
277
+ .ap-ag-data-table-container {
278
+ display: flex;
279
+ flex-direction: column;
280
+ height: 100%;
281
+ gap: 12px;
282
+ }
283
+ .ap-ag-data-table-sheets {
284
+ display: flex;
285
+ flex-direction: row;
286
+ gap: 12px;
287
+ flex-wrap: wrap;
288
+ z-index: 3;
289
+ }
290
+ .ap-ag-data-table-grid {
291
+ flex: 1;
292
+ }
293
+ </style>