@platforma-sdk/ui-vue 1.22.32 → 1.22.39

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.22.32",
3
+ "version": "1.22.39",
4
4
  "type": "module",
5
5
  "main": "dist/lib.umd.cjs",
6
6
  "module": "dist/lib.js",
@@ -23,7 +23,7 @@
23
23
  "canonicalize": "^2.0.0",
24
24
  "ag-grid-enterprise": "^33.0.4",
25
25
  "ag-grid-vue3": "^33.0.4",
26
- "@milaboratories/uikit": "^2.2.57",
26
+ "@milaboratories/uikit": "^2.2.58",
27
27
  "@platforma-sdk/model": "^1.22.18"
28
28
  },
29
29
  "devDependencies": {
@@ -0,0 +1,172 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import type { ColDef, ICellRendererParams } from 'ag-grid-enterprise';
3
+ import { PlAgCellProgress } from '../components/PlAgCellProgress';
4
+ import type { PlProgressCellProps } from '@milaboratories/uikit';
5
+ import { tapIf } from '@milaboratories/helpers';
6
+
7
+ /**
8
+ * Represents the available progress statuses for a cell.
9
+ */
10
+ type ProgressStatus = 'not_started' | 'running' | 'done';
11
+
12
+ /**
13
+ * Human-readable labels for each {@link ProgressStatus}.
14
+ */
15
+ const progressStatusLabels: Record<ProgressStatus, string> = {
16
+ not_started: 'Not Started',
17
+ running: 'Running',
18
+ done: 'Done',
19
+ };
20
+
21
+ /**
22
+ * Defines the configuration for rendering a progress overlay in a grid cell.
23
+ *
24
+ * When provided, a progress overlay will be rendered. If the value is
25
+ * `undefined`, no progress overlay is shown.
26
+ */
27
+ export type ColDefProgress = {
28
+ /**
29
+ * The progress status which influences default text and styling:
30
+ * - `'not_started'`: Typically renders gray text without a progress bar.
31
+ * - `'running'`: Indicates an active progress state.
32
+ * - `'done'`: Implies completion (commonly rendered as 100%).
33
+ */
34
+ status: ProgressStatus;
35
+ /**
36
+ * A number (or numeric string) between 0 and 100 that indicates progress.
37
+ * If omitted or invalid, it implies an infinite or indeterminate progress state
38
+ */
39
+ percent?: number | string;
40
+ /**
41
+ * The main label displayed on the left side of the cell.
42
+ */
43
+ text?: string;
44
+ /**
45
+ * Additional text, often used to display the percentage by default.
46
+ */
47
+ suffix?: string;
48
+ /**
49
+ * If provided, this message takes precedence over `text` to indicate an error.
50
+ */
51
+ error?: string;
52
+ } | undefined;
53
+
54
+ /**
55
+ * Callback function type to dynamically generate a {@link ColDefProgress} configuration
56
+ * for a cell based on its rendering parameters.
57
+ *
58
+ * @typeParam TData - The type of the row data.
59
+ * @typeParam TValue - The type of the cell value.
60
+ *
61
+ * @param cellData - The parameters provided by AG Grid's cell renderer.
62
+ * @returns A {@link ColDefProgress} object to configure the progress overlay,
63
+ * or `undefined` if no progress overlay should be rendered.
64
+ */
65
+ export type ColDefProgressCallback<TData, TValue = any> = (cellData: ICellRendererParams<TData, TValue>) => ColDefProgress;
66
+
67
+ /**
68
+ * Extended AG Grid column definition that supports additional properties for
69
+ * progress overlays and layout customization.
70
+ *
71
+ * @typeParam TData - The type of the row data.
72
+ * @typeParam TValue - The type of the cell value.
73
+ *
74
+ * @property progress - An optional callback to provide progress overlay configuration.
75
+ * @property noGutters - If `true`, removes padding from the cell.
76
+ */
77
+ export interface ColDefExtended<TData, TValue = any> extends ColDef<TData> {
78
+ progress?: ColDefProgressCallback<TData, TValue>;
79
+ noGutters?: boolean;
80
+ }
81
+
82
+ /**
83
+ * Utility type to infer the type of a specific property key from a {@link ColDefExtended}. Maybe not useful
84
+ */
85
+ export type InferColDefKey<TData, TValue, K extends keyof ColDefExtended<TData, TValue>> = ColDefExtended<TData, TValue>[K];
86
+
87
+ /**
88
+ * Returns a style object that removes horizontal and vertical padding from an AG Grid cell.
89
+ */
90
+ function noGuttersStyle() {
91
+ return {
92
+ '--ag-cell-horizontal-padding': '0px',
93
+ '--ag-cell-vertical-padding': '0px',
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Creates the configuration object for a progress cell renderer component.
99
+ *
100
+ * @param params - The properties for the progress cell component, conforming to {@link PlProgressCellProps}.
101
+ * @returns An object containing the progress component and its parameters.
102
+ */
103
+ function createProgressComponent(params: PlProgressCellProps) {
104
+ return {
105
+ component: PlAgCellProgress,
106
+ params,
107
+ };
108
+ }
109
+
110
+ /**
111
+ * Enhances the given column definition to support a progress overlay if a progress callback is provided.
112
+ *
113
+ * This function modifies the column definition by:
114
+ * - Merging no-gutters styles into the cell style.
115
+ * - Overriding the `cellRendererSelector` to return a progress component when a valid progress configuration is present.
116
+ *
117
+ * @typeParam TData - The type of the row data.
118
+ * @param def - The extended column definition to be augmented.
119
+ */
120
+ function handleProgress<TData>(def: ColDefExtended<TData>) {
121
+ if (def.progress) {
122
+ const progress = def.progress;
123
+
124
+ const cellRendererSelector = def.cellRendererSelector;
125
+
126
+ // Ensure no padding in the cell when a progress overlay is rendered.
127
+ def.cellStyle = Object.assign({}, def.cellStyle ?? {}, noGuttersStyle());
128
+
129
+ def.cellRendererSelector = (cellData) => {
130
+ const pt = progress(cellData);
131
+
132
+ if (!pt) {
133
+ return cellRendererSelector?.(cellData);
134
+ }
135
+
136
+ return createProgressComponent({
137
+ progress: tapIf(Number(pt.percent), (n) => Number.isFinite(n) ? (n < 0 ? 0 : n) : undefined),
138
+ progressString: pt.suffix ?? (pt.status === 'running' ? `${pt.percent ?? 0}%` : ''),
139
+ step: pt.text ?? progressStatusLabels[pt.status],
140
+ stage: pt.status,
141
+ error: pt.error,
142
+ });
143
+ };
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Creates an AG Grid column definition with extended features such as progress overlays and gutter removal.
149
+ *
150
+ * This function processes an extended column definition by:
151
+ * - Applying progress rendering logic via {@link handleProgress} if a progress callback is provided.
152
+ * - Merging no-gutters styles if the `noGutters` flag is set.
153
+ * - Removing the internal properties (`progress` and `noGutters`) from the final definition.
154
+ *
155
+ * @typeParam TData - The type of the row data.
156
+ * @typeParam TValue - The type of the cell value.
157
+ * @param def - The extended column definition containing custom properties.
158
+ * @returns The processed column definition ready for use with AG Grid.
159
+ */
160
+ export function createAgGridColDef<TData, TValue = any>(def: ColDefExtended<TData, TValue>): ColDef<TData, TValue> {
161
+ handleProgress(def);
162
+
163
+ if (def.noGutters) {
164
+ def.cellStyle = Object.assign({}, def.cellStyle ?? {}, noGuttersStyle());
165
+ }
166
+
167
+ delete def.progress;
168
+
169
+ delete def.noGutters;
170
+
171
+ return def;
172
+ }
@@ -1 +1,2 @@
1
1
  export * from './useAgGridOptionsSimple';
2
+ export * from './createAgGridColDef';
@@ -18,7 +18,7 @@
18
18
  }
19
19
 
20
20
  &__type-icon {
21
- background-color: var(--ic-02);
21
+ background-color: var(--txt-03);
22
22
  }
23
23
 
24
24
  &__menu-icon {