@bit.rhplus/ui.grid 0.0.14 → 0.0.16
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/AgGridColumns.js +3 -1
- package/ColumnBuilder.jsx +313 -76
- package/ContextBuilder.js +199 -0
- package/dist/AgGridColumns.js +1 -0
- package/dist/AgGridColumns.js.map +1 -1
- package/dist/ColumnBuilder.d.ts +24 -0
- package/dist/ColumnBuilder.js +164 -27
- package/dist/ColumnBuilder.js.map +1 -1
- package/dist/ContextBuilder.d.ts +80 -0
- package/dist/ContextBuilder.js +187 -0
- package/dist/ContextBuilder.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/index.jsx +3 -3
- package/package.json +3 -2
- /package/dist/{preview-1742817007356.js → preview-1746016364446.js} +0 -0
package/AgGridColumns.js
CHANGED
|
@@ -42,9 +42,11 @@ export const AgGridColumn = (column) => {
|
|
|
42
42
|
export const AgGridColumns = (columnDefs, options) => {
|
|
43
43
|
if (!columnDefs) return [];
|
|
44
44
|
|
|
45
|
+
console.log("🚀 ~ AgGridColumns ~ columnDefs:", columnDefs)
|
|
45
46
|
const resolvedColumnDefs = columnDefs instanceof ColumnBuilder && typeof columnDefs.build === 'function'
|
|
46
47
|
? columnDefs.build()
|
|
47
48
|
: columnDefs;
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
const cols = resolvedColumnDefs && resolvedColumnDefs.map((column) => AgGridColumn(column, options));
|
|
49
51
|
return cols;
|
|
50
52
|
};
|
package/ColumnBuilder.jsx
CHANGED
|
@@ -1,6 +1,101 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
// Oprava: import antd před vlastními importy
|
|
3
|
+
import { Checkbox } from 'antd'; // Pokud Checkbox není používán, později ho odstraníme
|
|
4
|
+
import { prepareColDef } from './utils';
|
|
5
|
+
import { currencySymbols } from './enums';
|
|
6
|
+
|
|
7
|
+
// Vytvoříme React hook funkci pro link cell renderer
|
|
8
|
+
const useLinkCellRenderer = (params, onClick, linkStyle, hoverStyle, overviewToggle) => {
|
|
9
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
10
|
+
|
|
11
|
+
const handleMouseEnter = React.useCallback(() => {
|
|
12
|
+
setIsHovered(true);
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
const handleMouseLeave = React.useCallback(() => {
|
|
16
|
+
setIsHovered(false);
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
const handleClick = React.useCallback((event) => {
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
// Odstranění console.log nebo zakomentování
|
|
22
|
+
// console.log('click');
|
|
23
|
+
|
|
24
|
+
if (overviewToggle && params.api) {
|
|
25
|
+
params.api.dispatchEvent({
|
|
26
|
+
type: 'overviewToggle',
|
|
27
|
+
data: params.data,
|
|
28
|
+
params,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (onClick) {
|
|
33
|
+
onClick(params);
|
|
34
|
+
}
|
|
35
|
+
}, [onClick, overviewToggle, params]);
|
|
36
|
+
|
|
37
|
+
const defaultLinkStyle = {
|
|
38
|
+
color: '#1a73e8',
|
|
39
|
+
textDecoration: 'none',
|
|
40
|
+
cursor: 'pointer',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const defaultHoverStyle = {
|
|
44
|
+
textDecoration: 'underline',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const computedLinkStyle = React.useMemo(() => ({
|
|
48
|
+
...defaultLinkStyle,
|
|
49
|
+
...(typeof linkStyle === 'function'
|
|
50
|
+
? linkStyle(params)
|
|
51
|
+
: linkStyle || {}),
|
|
52
|
+
}), [linkStyle, params]);
|
|
53
|
+
|
|
54
|
+
const computedHoverStyle = React.useMemo(() => ({
|
|
55
|
+
...defaultLinkStyle,
|
|
56
|
+
...computedLinkStyle,
|
|
57
|
+
...defaultHoverStyle,
|
|
58
|
+
...(typeof hoverStyle === 'function'
|
|
59
|
+
? hoverStyle(params)
|
|
60
|
+
: hoverStyle || {}),
|
|
61
|
+
}), [computedLinkStyle, hoverStyle, params]);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
isHovered,
|
|
65
|
+
handleMouseEnter,
|
|
66
|
+
handleMouseLeave,
|
|
67
|
+
handleClick,
|
|
68
|
+
computedLinkStyle,
|
|
69
|
+
computedHoverStyle,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Vytvoříme React hook funkci pro object cell renderer
|
|
74
|
+
const useObjectCellRenderer = (params, editable, onEditClick) => {
|
|
75
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
76
|
+
|
|
77
|
+
const handleMouseEnter = React.useCallback(() => {
|
|
78
|
+
setIsHovered(true);
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
const handleMouseLeave = React.useCallback(() => {
|
|
82
|
+
setIsHovered(false);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
const handleEditClick = React.useCallback((event) => {
|
|
86
|
+
event.stopPropagation();
|
|
87
|
+
if (onEditClick) {
|
|
88
|
+
onEditClick(params);
|
|
89
|
+
}
|
|
90
|
+
}, [onEditClick, params]);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
isHovered,
|
|
94
|
+
handleMouseEnter,
|
|
95
|
+
handleMouseLeave,
|
|
96
|
+
handleEditClick,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
4
99
|
|
|
5
100
|
class ColumnBuilder {
|
|
6
101
|
#addPreparedColumn(props) {
|
|
@@ -17,16 +112,58 @@ class ColumnBuilder {
|
|
|
17
112
|
return this;
|
|
18
113
|
}
|
|
19
114
|
|
|
20
|
-
|
|
115
|
+
// Nová metoda pro přidání sloupce s fakturou pro overview mód
|
|
116
|
+
addInvoiceCardColumn({
|
|
117
|
+
field = 'invoice',
|
|
118
|
+
headerName = '',
|
|
119
|
+
width = 340,
|
|
120
|
+
onCheckboxChange,
|
|
121
|
+
...restProps
|
|
122
|
+
} = {}) {
|
|
123
|
+
const cellRenderer = 'invoiceCardRenderer';
|
|
124
|
+
|
|
125
|
+
this.#addPreparedColumn({
|
|
126
|
+
headerName,
|
|
127
|
+
field,
|
|
128
|
+
width,
|
|
129
|
+
cellRenderer,
|
|
130
|
+
suppressSizeToFit: true,
|
|
131
|
+
cellRendererParams: {
|
|
132
|
+
onCheckboxChange: onCheckboxChange || ((id, checked) => {
|
|
133
|
+
// Odstranění console.log nebo zakomentování
|
|
134
|
+
// console.log(`Checkbox changed for ${id}:`, checked);
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
...restProps,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
addCurrencyColumn({
|
|
144
|
+
currency,
|
|
145
|
+
position,
|
|
146
|
+
currencyStyle,
|
|
147
|
+
cellAlign = 'right',
|
|
148
|
+
editable,
|
|
149
|
+
...restProps
|
|
150
|
+
}) {
|
|
21
151
|
const cellRenderer = (params) => {
|
|
22
|
-
const currencyValue =
|
|
152
|
+
const currencyValue =
|
|
153
|
+
typeof currency === 'function' ? currency(params) : currency;
|
|
23
154
|
const symbol = currencySymbols[currencyValue] || currencyValue;
|
|
24
|
-
|
|
155
|
+
|
|
25
156
|
// Použití Number.isNaN místo globální isNaN
|
|
26
|
-
const value =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
157
|
+
const value =
|
|
158
|
+
params.value != null && !Number.isNaN(Number(params.value))
|
|
159
|
+
? params.value.toFixed(2)
|
|
160
|
+
: '0.00';
|
|
161
|
+
|
|
162
|
+
const style =
|
|
163
|
+
typeof currencyStyle === 'function'
|
|
164
|
+
? currencyStyle(params)
|
|
165
|
+
: currencyStyle;
|
|
166
|
+
|
|
30
167
|
return (
|
|
31
168
|
<span>
|
|
32
169
|
{position === 'left' ? (
|
|
@@ -41,63 +178,147 @@ class ColumnBuilder {
|
|
|
41
178
|
</span>
|
|
42
179
|
);
|
|
43
180
|
};
|
|
44
|
-
|
|
45
|
-
this.#addPreparedColumn({
|
|
46
|
-
cellAlign,
|
|
47
|
-
cellRenderer,
|
|
181
|
+
|
|
182
|
+
this.#addPreparedColumn({
|
|
183
|
+
cellAlign,
|
|
184
|
+
cellRenderer,
|
|
48
185
|
editable: this.#resolveEditable(editable),
|
|
49
|
-
...restProps
|
|
186
|
+
...restProps,
|
|
50
187
|
});
|
|
51
188
|
return this;
|
|
52
189
|
}
|
|
53
|
-
|
|
54
|
-
addDateColumn({dateFormat =
|
|
55
|
-
this.#addPreparedColumn({
|
|
56
|
-
dateRenderer: dateFormat,
|
|
190
|
+
|
|
191
|
+
addDateColumn({ dateFormat = 'DD.MM.YYYY', editable, ...restProps }) {
|
|
192
|
+
this.#addPreparedColumn({
|
|
193
|
+
dateRenderer: dateFormat,
|
|
57
194
|
editable: this.#resolveEditable(editable),
|
|
58
|
-
...restProps
|
|
195
|
+
...restProps,
|
|
59
196
|
});
|
|
60
|
-
return this;
|
|
197
|
+
return this;
|
|
61
198
|
}
|
|
62
199
|
|
|
63
|
-
|
|
200
|
+
addLinkColumn({
|
|
201
|
+
onClick,
|
|
202
|
+
linkStyle,
|
|
203
|
+
hoverStyle,
|
|
204
|
+
cellAlign = 'left',
|
|
205
|
+
editable,
|
|
206
|
+
overviewToggle = false, // Přidán výchozí parametr pro overview
|
|
207
|
+
...restProps
|
|
208
|
+
}) {
|
|
209
|
+
// Vytvořím komponentu pro cell renderer, která používá hook
|
|
210
|
+
const LinkCellRenderer = React.memo((params) => {
|
|
211
|
+
const {
|
|
212
|
+
isHovered,
|
|
213
|
+
handleMouseEnter,
|
|
214
|
+
handleMouseLeave,
|
|
215
|
+
handleClick,
|
|
216
|
+
computedLinkStyle,
|
|
217
|
+
computedHoverStyle,
|
|
218
|
+
} = useLinkCellRenderer(params, onClick, linkStyle, hoverStyle, overviewToggle);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<div
|
|
222
|
+
className="link-cell-container"
|
|
223
|
+
style={{
|
|
224
|
+
width: '100%',
|
|
225
|
+
height: '100%',
|
|
226
|
+
display: 'flex',
|
|
227
|
+
alignItems: 'center',
|
|
228
|
+
}}
|
|
229
|
+
>
|
|
230
|
+
<span
|
|
231
|
+
onClick={handleClick}
|
|
232
|
+
onMouseEnter={handleMouseEnter}
|
|
233
|
+
onMouseLeave={handleMouseLeave}
|
|
234
|
+
style={isHovered ? computedHoverStyle : computedLinkStyle}
|
|
235
|
+
role="button"
|
|
236
|
+
tabIndex={0}
|
|
237
|
+
onKeyPress={(event) => {
|
|
238
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
239
|
+
handleClick(event);
|
|
240
|
+
}
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
{params.value}
|
|
244
|
+
</span>
|
|
245
|
+
</div>
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Používáme funkci, která vrátí React komponentu
|
|
64
250
|
const cellRenderer = (params) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
251
|
+
return <LinkCellRenderer {...params} />;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
this.#addPreparedColumn({
|
|
255
|
+
cellAlign,
|
|
256
|
+
cellRenderer,
|
|
257
|
+
editable: this.#resolveEditable(editable),
|
|
258
|
+
overviewToggle, // Předání příznaku dál
|
|
259
|
+
...restProps,
|
|
260
|
+
});
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Přidání Helper metody pro overview link
|
|
265
|
+
addOverviewLinkColumn({
|
|
266
|
+
field = 'documentNumber',
|
|
267
|
+
headerName = '',
|
|
268
|
+
width = 130,
|
|
269
|
+
cellAlign = 'left',
|
|
270
|
+
linkStyle,
|
|
271
|
+
hoverStyle,
|
|
272
|
+
editable = false,
|
|
273
|
+
...rest
|
|
274
|
+
} = {}) {
|
|
275
|
+
return this.addLinkColumn({
|
|
276
|
+
field,
|
|
277
|
+
headerName: this.intl.formatMessage({ id: rest.intlId }) || headerName,
|
|
278
|
+
width,
|
|
279
|
+
cellAlign,
|
|
280
|
+
linkStyle,
|
|
281
|
+
hoverStyle,
|
|
282
|
+
editable,
|
|
283
|
+
overviewToggle: true,
|
|
284
|
+
...rest,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
addObjectColumn({
|
|
289
|
+
contentTooltip,
|
|
290
|
+
tooltipField,
|
|
291
|
+
tooltipInteraction,
|
|
292
|
+
tooltipShowDelay = 100,
|
|
293
|
+
editable,
|
|
294
|
+
onEditClick,
|
|
295
|
+
...restProps
|
|
296
|
+
}) {
|
|
297
|
+
// Vytvořím komponentu pro cell renderer, která používá hook
|
|
298
|
+
const ObjectCellRenderer = React.memo((params) => {
|
|
299
|
+
const {
|
|
300
|
+
isHovered,
|
|
301
|
+
handleMouseEnter,
|
|
302
|
+
handleMouseLeave,
|
|
303
|
+
handleEditClick,
|
|
304
|
+
} = useObjectCellRenderer(params, editable, onEditClick);
|
|
305
|
+
|
|
83
306
|
return (
|
|
84
|
-
<div
|
|
85
|
-
className="object-cell-container"
|
|
86
|
-
style={{
|
|
87
|
-
position: 'relative',
|
|
88
|
-
width: '100%',
|
|
89
|
-
height: '100%',
|
|
90
|
-
display: 'flex',
|
|
91
|
-
alignItems: 'center'
|
|
307
|
+
<div
|
|
308
|
+
className="object-cell-container"
|
|
309
|
+
style={{
|
|
310
|
+
position: 'relative',
|
|
311
|
+
width: '100%',
|
|
312
|
+
height: '100%',
|
|
313
|
+
display: 'flex',
|
|
314
|
+
alignItems: 'center',
|
|
92
315
|
}}
|
|
93
316
|
onMouseEnter={handleMouseEnter}
|
|
94
317
|
onMouseLeave={handleMouseLeave}
|
|
95
318
|
>
|
|
96
|
-
<div style={{ flexGrow: 1 }}>
|
|
97
|
-
{params.value}
|
|
98
|
-
</div>
|
|
319
|
+
<div style={{ flexGrow: 1 }}>{params.value}</div>
|
|
99
320
|
{isHovered && editable && (
|
|
100
|
-
<button
|
|
321
|
+
<button
|
|
101
322
|
className="edit-object-button"
|
|
102
323
|
style={{
|
|
103
324
|
position: 'absolute',
|
|
@@ -108,7 +329,7 @@ class ColumnBuilder {
|
|
|
108
329
|
padding: '4px',
|
|
109
330
|
display: 'flex',
|
|
110
331
|
alignItems: 'center',
|
|
111
|
-
justifyContent: 'center'
|
|
332
|
+
justifyContent: 'center',
|
|
112
333
|
}}
|
|
113
334
|
onClick={handleEditClick}
|
|
114
335
|
title="Upravit"
|
|
@@ -118,55 +339,71 @@ class ColumnBuilder {
|
|
|
118
339
|
)}
|
|
119
340
|
</div>
|
|
120
341
|
);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Používáme funkci, která vrátí React komponentu
|
|
345
|
+
const cellRenderer = (params) => {
|
|
346
|
+
return <ObjectCellRenderer {...params} />;
|
|
121
347
|
};
|
|
122
|
-
|
|
123
|
-
this.#addPreparedColumn({
|
|
124
|
-
contentTooltip,
|
|
125
|
-
tooltipField,
|
|
126
|
-
tooltipInteraction,
|
|
348
|
+
|
|
349
|
+
this.#addPreparedColumn({
|
|
350
|
+
contentTooltip,
|
|
351
|
+
tooltipField,
|
|
352
|
+
tooltipInteraction,
|
|
127
353
|
tooltipShowDelay,
|
|
128
354
|
cellRenderer,
|
|
129
355
|
editable: this.#resolveEditable(editable),
|
|
130
|
-
...restProps
|
|
356
|
+
...restProps,
|
|
131
357
|
});
|
|
132
358
|
return this;
|
|
133
359
|
}
|
|
134
|
-
|
|
135
|
-
addBooleanColumn({
|
|
360
|
+
|
|
361
|
+
addBooleanColumn({
|
|
362
|
+
visibleFalse = true,
|
|
363
|
+
visibleTrue = true,
|
|
364
|
+
cellAlign,
|
|
365
|
+
visibleGetter = () => true,
|
|
366
|
+
editable,
|
|
367
|
+
...restProps
|
|
368
|
+
}) {
|
|
136
369
|
const booleanRendererParams = {
|
|
137
370
|
cellAlign,
|
|
138
371
|
visibleFalse,
|
|
139
372
|
visibleTrue,
|
|
140
|
-
visibleGetter
|
|
141
|
-
}
|
|
142
|
-
this.#addPreparedColumn({
|
|
143
|
-
booleanRenderer: true,
|
|
144
|
-
booleanRendererParams,
|
|
373
|
+
visibleGetter,
|
|
374
|
+
};
|
|
375
|
+
this.#addPreparedColumn({
|
|
376
|
+
booleanRenderer: true,
|
|
377
|
+
booleanRendererParams,
|
|
145
378
|
editable: this.#resolveEditable(editable),
|
|
146
|
-
...restProps
|
|
379
|
+
...restProps,
|
|
147
380
|
});
|
|
148
|
-
|
|
381
|
+
|
|
149
382
|
return this;
|
|
150
383
|
}
|
|
151
384
|
|
|
152
|
-
addButtonColumn({
|
|
385
|
+
addButtonColumn({
|
|
386
|
+
buttons,
|
|
387
|
+
visibleGetter = () => true,
|
|
388
|
+
editable,
|
|
389
|
+
...restProps
|
|
390
|
+
}) {
|
|
153
391
|
const buttonRendererParams = {
|
|
154
392
|
buttons,
|
|
155
|
-
visibleGetter
|
|
156
|
-
}
|
|
157
|
-
this.#addPreparedColumn({
|
|
158
|
-
buttonRenderer: true,
|
|
393
|
+
visibleGetter,
|
|
394
|
+
};
|
|
395
|
+
this.#addPreparedColumn({
|
|
396
|
+
buttonRenderer: true,
|
|
159
397
|
buttonRendererParams,
|
|
160
398
|
editable: this.#resolveEditable(editable),
|
|
161
|
-
...restProps
|
|
162
|
-
})
|
|
399
|
+
...restProps,
|
|
400
|
+
});
|
|
163
401
|
return this;
|
|
164
402
|
}
|
|
165
403
|
|
|
166
404
|
// Pomocná metoda pro správné nastavení editable vlastnosti
|
|
167
405
|
#resolveEditable(editable) {
|
|
168
|
-
if (!editable)
|
|
169
|
-
return false;
|
|
406
|
+
if (!editable) return false;
|
|
170
407
|
return editable;
|
|
171
408
|
}
|
|
172
409
|
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
class ContextBuilder {
|
|
4
|
+
#addPreparedMenuItem(props) {
|
|
5
|
+
this.menuItems.push(props);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
constructor(intl) {
|
|
9
|
+
this.menuItems = [];
|
|
10
|
+
this.intl = intl;
|
|
11
|
+
this.globalStyles = {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addMenuItem(props) {
|
|
15
|
+
this.#addPreparedMenuItem(props);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addActionItem({ name, action, icon, disabled = false, tooltip, showCondition = () => true,
|
|
20
|
+
cssClasses, style, iconStyle, ...restProps }) {
|
|
21
|
+
this.#addPreparedMenuItem({
|
|
22
|
+
name,
|
|
23
|
+
action,
|
|
24
|
+
icon,
|
|
25
|
+
disabled: this.#resolveDisabled(disabled),
|
|
26
|
+
tooltip,
|
|
27
|
+
showCondition,
|
|
28
|
+
cssClasses,
|
|
29
|
+
style,
|
|
30
|
+
iconStyle,
|
|
31
|
+
...restProps
|
|
32
|
+
});
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
addSubMenuItem({ name, icon, items, disabled = false, tooltip, showCondition = () => true,
|
|
37
|
+
cssClasses, style, iconStyle, ...restProps }) {
|
|
38
|
+
this.#addPreparedMenuItem({
|
|
39
|
+
name,
|
|
40
|
+
icon,
|
|
41
|
+
subMenu: Array.isArray(items) ? items : [],
|
|
42
|
+
disabled: this.#resolveDisabled(disabled),
|
|
43
|
+
tooltip,
|
|
44
|
+
showCondition,
|
|
45
|
+
cssClasses,
|
|
46
|
+
style,
|
|
47
|
+
iconStyle,
|
|
48
|
+
...restProps
|
|
49
|
+
});
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
addSeparator({ showCondition = () => true, cssClasses, style }) {
|
|
54
|
+
this.#addPreparedMenuItem({
|
|
55
|
+
separator: true,
|
|
56
|
+
showCondition,
|
|
57
|
+
cssClasses,
|
|
58
|
+
style
|
|
59
|
+
});
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
addCustomItem({ component, showCondition = () => true, cssClasses, style, ...restProps }) {
|
|
64
|
+
const customComponent = (params) => {
|
|
65
|
+
return React.createElement(component, { ...params, ...restProps });
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
this.#addPreparedMenuItem({
|
|
69
|
+
custom: true,
|
|
70
|
+
component: customComponent,
|
|
71
|
+
showCondition,
|
|
72
|
+
cssClasses,
|
|
73
|
+
style,
|
|
74
|
+
...restProps
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addDynamicItems({ itemsGenerator, showCondition = () => true }) {
|
|
80
|
+
this.#addPreparedMenuItem({
|
|
81
|
+
dynamic: true,
|
|
82
|
+
itemsGenerator,
|
|
83
|
+
showCondition
|
|
84
|
+
});
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Nová metoda pro položku s vlastním CSS
|
|
89
|
+
addStyledActionItem({ name, action, icon, disabled = false, tooltip, showCondition = () => true,
|
|
90
|
+
color, backgroundColor, fontWeight, fontSize, border, padding, margin,
|
|
91
|
+
iconColor, iconSize, ...restProps }) {
|
|
92
|
+
|
|
93
|
+
// Vytvoření objektu stylu pro text položky
|
|
94
|
+
const itemStyle = {};
|
|
95
|
+
if (color) itemStyle.color = color;
|
|
96
|
+
if (backgroundColor) itemStyle.backgroundColor = backgroundColor;
|
|
97
|
+
if (fontWeight) itemStyle.fontWeight = fontWeight;
|
|
98
|
+
if (fontSize) itemStyle.fontSize = fontSize;
|
|
99
|
+
if (border) itemStyle.border = border;
|
|
100
|
+
if (padding) itemStyle.padding = padding;
|
|
101
|
+
if (margin) itemStyle.margin = margin;
|
|
102
|
+
|
|
103
|
+
// Vytvoření objektu stylu pro ikonu
|
|
104
|
+
const iconStyleObj = {};
|
|
105
|
+
if (iconColor) iconStyleObj.color = iconColor;
|
|
106
|
+
if (iconSize) iconStyleObj.fontSize = iconSize;
|
|
107
|
+
|
|
108
|
+
this.#addPreparedMenuItem({
|
|
109
|
+
name,
|
|
110
|
+
action,
|
|
111
|
+
icon,
|
|
112
|
+
disabled: this.#resolveDisabled(disabled),
|
|
113
|
+
tooltip,
|
|
114
|
+
showCondition,
|
|
115
|
+
style: itemStyle,
|
|
116
|
+
iconStyle: iconStyleObj,
|
|
117
|
+
...restProps
|
|
118
|
+
});
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Nová metoda pro přidání CSS tříd k položce menu
|
|
123
|
+
addClassedActionItem({ name, action, icon, disabled = false, tooltip, showCondition = () => true,
|
|
124
|
+
cssClasses, iconCssClasses, ...restProps }) {
|
|
125
|
+
this.#addPreparedMenuItem({
|
|
126
|
+
name,
|
|
127
|
+
action,
|
|
128
|
+
icon,
|
|
129
|
+
disabled: this.#resolveDisabled(disabled),
|
|
130
|
+
tooltip,
|
|
131
|
+
showCondition,
|
|
132
|
+
cssClasses,
|
|
133
|
+
iconCssClasses,
|
|
134
|
+
...restProps
|
|
135
|
+
});
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Helper method for properly setting disabled property
|
|
140
|
+
#resolveDisabled(disabled) {
|
|
141
|
+
if (!disabled)
|
|
142
|
+
return false;
|
|
143
|
+
return disabled;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Nová metoda pro nastavení globálního stylu pro všechny položky menu
|
|
147
|
+
setGlobalStyles(styles = {}) {
|
|
148
|
+
this.globalStyles = styles;
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
build() {
|
|
153
|
+
return (params) => {
|
|
154
|
+
// Filter items based on showCondition
|
|
155
|
+
const filteredItems = this.menuItems
|
|
156
|
+
.filter(item => item.showCondition(params))
|
|
157
|
+
.map(item => {
|
|
158
|
+
// For dynamic items, call the generator function to get actual items
|
|
159
|
+
if (item.dynamic) {
|
|
160
|
+
return item.itemsGenerator(params);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Create a new item object instead of modifying the original
|
|
164
|
+
const { showCondition, ...menuItem } = item;
|
|
165
|
+
let newItem = { ...menuItem };
|
|
166
|
+
|
|
167
|
+
// Apply global styles if defined
|
|
168
|
+
if (this.globalStyles && Object.keys(this.globalStyles).length > 0) {
|
|
169
|
+
if (newItem.style) {
|
|
170
|
+
newItem = {
|
|
171
|
+
...newItem,
|
|
172
|
+
style: { ...this.globalStyles, ...newItem.style }
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
newItem = {
|
|
176
|
+
...newItem,
|
|
177
|
+
style: { ...this.globalStyles }
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return newItem;
|
|
183
|
+
})
|
|
184
|
+
// Flatten any arrays returned by dynamic item generators
|
|
185
|
+
.flat();
|
|
186
|
+
|
|
187
|
+
// Pokud používáme AG-Grid's Enterprise verzi, můžeme přidat vlastní CSS styly
|
|
188
|
+
// Tato část je nepovinná a závisí na implementaci AG-Grid
|
|
189
|
+
if (params && params.api && params.api.setPopupParentComponent) {
|
|
190
|
+
// Zde můžete nastavit vlastní komponentu pro kontextové menu
|
|
191
|
+
// To by vyžadovalo vytvoření této komponenty
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return filteredItems;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default ContextBuilder;
|
package/dist/AgGridColumns.js
CHANGED
|
@@ -34,6 +34,7 @@ export const AgGridColumn = (column) => {
|
|
|
34
34
|
export const AgGridColumns = (columnDefs, options) => {
|
|
35
35
|
if (!columnDefs)
|
|
36
36
|
return [];
|
|
37
|
+
console.log("🚀 ~ AgGridColumns ~ columnDefs:", columnDefs);
|
|
37
38
|
const resolvedColumnDefs = columnDefs instanceof ColumnBuilder && typeof columnDefs.build === 'function'
|
|
38
39
|
? columnDefs.build()
|
|
39
40
|
: columnDefs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgGridColumns.js","sourceRoot":"","sources":["../AgGridColumns.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM;CACb,CAAA;AAED,sCAAsC;AACtC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE;IACrC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAErE,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,EAAE;QACvC,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,YAAY,CAAC,IAAI;gBACpB,OAAO,OAAO,CAAC,IAAI,CAAC;YACtB;gBACE,MAAM,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;YAC/B,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;gBAC1B,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBACpD,mBAAmB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,uBAAuB;YAC5D,CAAC;QACH,CAAC,CAAC;QAEF,aAAa,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