@reportportal/ui-kit 0.0.1-alpha.146 → 0.0.1-alpha.148

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.
@@ -0,0 +1,595 @@
1
+ import { jsx as o, jsxs as z } from "react/jsx-runtime";
2
+ import { useMemo as se, useState as $, useCallback as x, useEffect as re, useRef as oe, forwardRef as We } from "react";
3
+ import { Resizable as De } from "react-resizable";
4
+ import { c as ce } from "./bind-06a7ff84.js";
5
+ import { c as Oe, b as ee, a as le, S as Ue } from "./resizeColumn-d4107941.js";
6
+ import { C as te } from "./checkbox-ed6cc375.js";
7
+ import { Tooltip as je } from "./tooltip.js";
8
+ const ie = (l) => typeof l == "string", He = "_table_1244e_1", Be = "_resizable_1244e_46", Ge = "_selectable_1244e_63", Xe = "_expanded_1244e_59", Ye = "_label_1244e_303", qe = {
9
+ table: He,
10
+ "fixed-header": "_fixed-header_1244e_8",
11
+ "horizontally-scrollable-container": "_horizontally-scrollable-container_1244e_14",
12
+ "table-header": "_table-header_1244e_19",
13
+ "sticky-header": "_sticky-header_1244e_26",
14
+ "horizontally-scrollable": "_horizontally-scrollable_1244e_14",
15
+ resizable: Be,
16
+ "resizable-column": "_resizable-column_1244e_46",
17
+ "table-row": "_table-row_1244e_54",
18
+ "expanded-cell": "_expanded-cell_1244e_59",
19
+ selectable: Ge,
20
+ "row-content-wrapper": "_row-content-wrapper_1244e_67",
21
+ "table-row-content": "_table-row-content_1244e_75",
22
+ "expand-cell": "_expand-cell_1244e_89",
23
+ "size-small": "_size-small_1244e_92",
24
+ "size-large": "_size-large_1244e_103",
25
+ "table-body": "_table-body_1244e_115",
26
+ "scrollable-body": "_scrollable-body_1244e_121",
27
+ "table-header-cell": "_table-header-cell_1244e_181",
28
+ "table-cell": "_table-cell_1244e_182",
29
+ "action-menu-cell": "_action-menu-cell_1244e_188",
30
+ "checkbox-cell": "_checkbox-cell_1244e_213",
31
+ "expand-all-tooltip-wrapper": "_expand-all-tooltip-wrapper_1244e_255",
32
+ "expand-all-tooltip-content": "_expand-all-tooltip-content_1244e_264",
33
+ "expand-icon": "_expand-icon_1244e_273",
34
+ expanded: Xe,
35
+ "primary-cell": "_primary-cell_1244e_282",
36
+ label: Ye,
37
+ "sortable-cell": "_sortable-cell_1244e_317",
38
+ "align-right": "_align-right_1244e_320",
39
+ "align-center": "_align-center_1244e_326",
40
+ "pinned-column": "_pinned-column_1244e_329"
41
+ }, de = "asc", S = 32, he = 100, Je = 48, Qe = (l) => l.toLowerCase() === de, Ve = (l) => l.map((n) => n.key), N = (l) => "primary" in l && l.primary === !0, Ze = (l) => {
42
+ var s;
43
+ return `size-${((s = l.rowConfigs) == null ? void 0 : s.size) ?? "default"}`;
44
+ }, j = (l) => ie(l) ? l : `${l}px`, Ke = (l, n, s, c, i) => {
45
+ let a = 0;
46
+ c && (a += S), i && (a += S);
47
+ for (let p = 0; p < l; p++) {
48
+ const u = n[p];
49
+ if (N(u)) {
50
+ const t = s.current.get(u.key) || he;
51
+ a += t;
52
+ } else {
53
+ const t = u, h = ie(t.width) ? parseInt(t.width, 10) || 0 : t.width;
54
+ a += h;
55
+ }
56
+ }
57
+ return a;
58
+ }, W = (l, n, s, c, i, a, p) => {
59
+ const u = {};
60
+ if (!N(l)) {
61
+ const t = l;
62
+ u.textAlign = t.align;
63
+ }
64
+ if (n && s !== void 0) {
65
+ const t = Ke(
66
+ s,
67
+ c,
68
+ i,
69
+ a,
70
+ p
71
+ );
72
+ u.left = `${t}px`;
73
+ }
74
+ return u;
75
+ }, ne = (l, n, s, c, i, a = !1, p, u = !1) => {
76
+ const t = [];
77
+ s && t.push(`${S}px`), a && c && t.push(`${S}px`);
78
+ const h = (r) => {
79
+ if ((p == null ? void 0 : p[r.key]) !== void 0) {
80
+ t.push(`${p[r.key]}px`);
81
+ return;
82
+ }
83
+ if (N(r)) {
84
+ const f = r;
85
+ if (u && f.width) {
86
+ t.push(j(f.width));
87
+ return;
88
+ }
89
+ const y = f.width ? j(f.width) : `${he}px`;
90
+ t.push(`minmax(${y}, 1fr)`);
91
+ } else {
92
+ const y = j(r.width);
93
+ t.push(y);
94
+ }
95
+ };
96
+ return l.forEach(h), n.forEach(h), i && t.push(`${Je}px`), t.join(" ");
97
+ }, Fe = ({
98
+ primaryColumns: l,
99
+ fixedColumns: n,
100
+ pinnedColumnKeys: s
101
+ }) => se(() => {
102
+ const c = [], i = [];
103
+ return l.forEach((a) => {
104
+ const p = { ...a, primary: !0 };
105
+ s.includes(a.key) ? c.push(p) : i.push(p);
106
+ }), n.forEach((a) => {
107
+ s.includes(a.key) ? c.push(a) : i.push(a);
108
+ }), {
109
+ pinnedColumns: c,
110
+ scrollableColumns: i
111
+ };
112
+ }, [l, n, s]), Re = () => {
113
+ const [l, n] = $(null), [s, c] = $(null), i = x((t) => {
114
+ n(t);
115
+ }, []), a = x(() => {
116
+ n(null);
117
+ }, []), p = x((t) => {
118
+ c(t);
119
+ }, []), u = x(() => {
120
+ c(null);
121
+ }, []);
122
+ return {
123
+ hoveredColumn: l,
124
+ hoveredRow: s,
125
+ handleColumnMouseEnter: i,
126
+ handleColumnMouseLeave: a,
127
+ handleRowMouseEnter: p,
128
+ handleRowMouseLeave: u
129
+ };
130
+ }, Ie = ({
131
+ primaryColumns: l,
132
+ fixedColumns: n,
133
+ expandedRowIds: s,
134
+ onToggleRowExpansion: c
135
+ }) => {
136
+ const [i, a] = $(/* @__PURE__ */ new Set());
137
+ re(() => {
138
+ const t = [
139
+ ...l.map((r) => r.key),
140
+ ...n.map((r) => r.key)
141
+ ], h = /* @__PURE__ */ new Set();
142
+ s.forEach((r) => {
143
+ t.forEach((f) => {
144
+ h.add(`${r}-${f}`);
145
+ });
146
+ }), a((r) => {
147
+ if (r.size === h.size) {
148
+ let f = !0;
149
+ if (r.forEach((y) => {
150
+ h.has(y) || (f = !1);
151
+ }), f)
152
+ return r;
153
+ }
154
+ return h;
155
+ });
156
+ }, [s, l, n]);
157
+ const p = x(
158
+ (t) => {
159
+ const h = new Set(i), r = s.includes(t), f = [
160
+ ...l.map((y) => y.key),
161
+ ...n.map((y) => y.key)
162
+ ];
163
+ r ? f.forEach((y) => {
164
+ const k = `${t}-${y}`;
165
+ h.delete(k);
166
+ }) : f.forEach((y) => {
167
+ const k = `${t}-${y}`;
168
+ h.add(k);
169
+ }), a(h), c(t);
170
+ },
171
+ [i, s, l, n, c]
172
+ ), u = x(
173
+ (t, h) => {
174
+ const r = `${t}-${h}`;
175
+ return i.has(r);
176
+ },
177
+ [i]
178
+ );
179
+ return {
180
+ expandedCells: i,
181
+ handleToggleRowExpansion: p,
182
+ isCellExpanded: u
183
+ };
184
+ }, el = () => {
185
+ const l = oe(/* @__PURE__ */ new Map()), n = x(
186
+ (s) => (c) => {
187
+ if (!c)
188
+ return;
189
+ const i = c.getBoundingClientRect().width;
190
+ i > 0 && l.current.set(s, i);
191
+ },
192
+ []
193
+ );
194
+ return {
195
+ columnWidthsRef: l,
196
+ setCellRef: n
197
+ };
198
+ }, ll = ({
199
+ enabled: l = !1,
200
+ minWidth: n = 50,
201
+ maxWidth: s = 500,
202
+ columnWidthsRef: c,
203
+ onColumnResize: i
204
+ }) => {
205
+ const [a, p] = $({}), u = x(() => {
206
+ if (!l || Object.keys(a).length > 0 || !c)
207
+ return;
208
+ const r = {};
209
+ c.current.forEach((f, y) => {
210
+ r[y] = f;
211
+ }), p(r);
212
+ }, [l, a, c]), t = x(
213
+ (r) => (f, { size: y }) => {
214
+ if (!l)
215
+ return;
216
+ const k = Math.min(s, Math.max(n, y.width));
217
+ p((m) => ({ ...m, [r]: k }));
218
+ },
219
+ [l, n, s]
220
+ ), h = x(
221
+ (r) => () => {
222
+ !l || !a[r] || i == null || i(r, a[r]);
223
+ },
224
+ [l, a, i]
225
+ );
226
+ return {
227
+ columnWidths: a,
228
+ handleResize: t,
229
+ handleResizeStop: h,
230
+ handleResizeStart: u
231
+ };
232
+ }, tl = {
233
+ "resize-handle": "_resize-handle_15uk3_1"
234
+ }, nl = ce.bind(tl), al = We(
235
+ (l, n) => /* @__PURE__ */ o("div", { ref: n, className: nl("resize-handle"), ...l, children: /* @__PURE__ */ o(Oe, {}) })
236
+ ), d = ce.bind(qe), ae = ({ column: l }) => {
237
+ const n = oe(null), [s, c] = $(!1);
238
+ return re(() => {
239
+ if (n.current) {
240
+ const i = n.current.offsetWidth, a = n.current.scrollWidth;
241
+ c(a > i);
242
+ }
243
+ }, [l.header]), /* @__PURE__ */ o("span", { ref: n, title: s ? l.header : void 0, children: l.header });
244
+ }, pl = ({
245
+ data: l,
246
+ primaryColumn: n,
247
+ fixedColumns: s,
248
+ renderRowActions: c,
249
+ className: i = "",
250
+ rowClassName: a = "",
251
+ headerClassName: p = "",
252
+ bodyClassName: u = "",
253
+ selectable: t = !1,
254
+ selectedRowIds: h = [],
255
+ sortingDirection: r = de,
256
+ sortingColumn: f,
257
+ sortableColumns: y,
258
+ isHeaderFixed: k = !1,
259
+ isHorizontallyScrollable: m = !1,
260
+ pinnedColumnKeys: pe = [],
261
+ isRowsExpandable: v = !1,
262
+ expandedRowIds: E = [],
263
+ isAllExpandedByDefault: H,
264
+ expandAllTooltip: B,
265
+ isResizable: b = !1,
266
+ minColumnWidth: D = 50,
267
+ maxColumnWidth: G = 500,
268
+ onChangeSorting: _e = () => {
269
+ },
270
+ onToggleRowSelection: ye = () => {
271
+ },
272
+ onToggleAllRowsSelection: fe = () => {
273
+ },
274
+ onToggleRowExpansion: ue = () => {
275
+ },
276
+ onToggleAllRowsExpansion: be = () => {
277
+ },
278
+ onColumnResize: ke = () => {
279
+ }
280
+ }) => {
281
+ const T = se(
282
+ () => Array.isArray(n) ? n : [n],
283
+ [n]
284
+ ), w = f ?? T[0], A = y ?? Ve([...T, ...s]), { pinnedColumns: g, scrollableColumns: L } = Fe({
285
+ primaryColumns: T,
286
+ fixedColumns: s,
287
+ pinnedColumnKeys: pe
288
+ }), {
289
+ hoveredColumn: X,
290
+ hoveredRow: ve,
291
+ handleColumnMouseEnter: Y,
292
+ handleColumnMouseLeave: q,
293
+ handleRowMouseEnter: xe,
294
+ handleRowMouseLeave: we
295
+ } = Re(), { columnWidthsRef: M, setCellRef: J } = el(), { handleToggleRowExpansion: Ce, isCellExpanded: Q } = Ie({
296
+ primaryColumns: T,
297
+ fixedColumns: s,
298
+ expandedRowIds: E,
299
+ onToggleRowExpansion: ue
300
+ }), { columnWidths: O, handleResize: ge, handleResizeStop: Ne, handleResizeStart: ze } = ll({
301
+ enabled: b,
302
+ minWidth: D,
303
+ maxWidth: G,
304
+ columnWidthsRef: M,
305
+ onColumnResize: ke
306
+ }), V = (e, C) => /* @__PURE__ */ o(
307
+ De,
308
+ {
309
+ width: O[e.key] ?? (typeof e.width == "number" ? e.width : D),
310
+ height: 0,
311
+ axis: "x",
312
+ handle: /* @__PURE__ */ o(al, {}),
313
+ onResizeStart: ze,
314
+ onResize: ge(e.key),
315
+ onResizeStop: Ne(e.key),
316
+ minConstraints: [D, 0],
317
+ maxConstraints: [G, 0],
318
+ className: d("resizable-column"),
319
+ children: C
320
+ },
321
+ e.key
322
+ ), Z = (e) => {
323
+ A.includes(e) && _e({ key: e, direction: r });
324
+ }, Se = (e) => {
325
+ ye(e);
326
+ }, me = () => {
327
+ fe();
328
+ }, Ee = () => {
329
+ be();
330
+ }, K = (e) => A.includes(e) ? (w == null ? void 0 : w.key) === e ? Qe(r) ? /* @__PURE__ */ o(le, {}) : /* @__PURE__ */ o(Ue, {}) : /* @__PURE__ */ o(le, {}) : null, Me = l.every((e) => h.includes(e.id)), $e = l.some((e) => h.includes(e.id)), F = (h == null ? void 0 : h.length) > 0, Te = l.every((e) => E.includes(e.id)), Ae = H !== void 0 ? H : Te, Le = ne(
331
+ g,
332
+ L,
333
+ v,
334
+ t,
335
+ !!c,
336
+ !1,
337
+ b ? O : void 0,
338
+ b
339
+ ), Pe = ne(
340
+ g,
341
+ L,
342
+ v,
343
+ t,
344
+ !!c,
345
+ !0,
346
+ b ? O : void 0,
347
+ b
348
+ ), R = /* @__PURE__ */ o("button", { onClick: Ee, "aria-label": "Toggle all rows expansion", children: /* @__PURE__ */ o("span", { className: d("expand-icon", { expanded: Ae }), children: /* @__PURE__ */ o(ee, {}) }) });
349
+ return /* @__PURE__ */ z(
350
+ "div",
351
+ {
352
+ className: d(
353
+ "table",
354
+ {
355
+ "fixed-header": k,
356
+ "horizontally-scrollable-container": k && (m || b)
357
+ },
358
+ i
359
+ ),
360
+ children: [
361
+ /* @__PURE__ */ z(
362
+ "div",
363
+ {
364
+ className: d(
365
+ "table-header",
366
+ {
367
+ "sticky-header": k,
368
+ "horizontally-scrollable": m,
369
+ resizable: b
370
+ },
371
+ p
372
+ ),
373
+ style: { gridTemplateColumns: Pe },
374
+ children: [
375
+ t && /* @__PURE__ */ o(
376
+ "div",
377
+ {
378
+ className: d("table-header-cell", "checkbox-cell"),
379
+ style: { left: v ? `${S}px` : "0" },
380
+ children: F && /* @__PURE__ */ o(
381
+ te,
382
+ {
383
+ value: Me,
384
+ partiallyChecked: $e,
385
+ onChange: me,
386
+ className: d("checkbox-cell")
387
+ }
388
+ )
389
+ }
390
+ ),
391
+ v && /* @__PURE__ */ o("div", { className: d("table-header-cell", "expand-cell"), style: { left: "0" }, children: B ? /* @__PURE__ */ o(
392
+ je,
393
+ {
394
+ content: B,
395
+ placement: "top",
396
+ wrapperClassName: d("expand-all-tooltip-wrapper"),
397
+ contentClassName: d("expand-all-tooltip-content"),
398
+ children: R
399
+ }
400
+ ) : R }),
401
+ g.map((e, C) => {
402
+ const _ = /* @__PURE__ */ o(
403
+ "button",
404
+ {
405
+ className: d("table-header-cell", "pinned-column", {
406
+ [`align-${e.align}`]: "align" in e,
407
+ "primary-cell": N(e),
408
+ "sortable-cell": A.includes(e.key),
409
+ resizable: b
410
+ }),
411
+ style: W(
412
+ e,
413
+ !0,
414
+ C,
415
+ g,
416
+ M,
417
+ v,
418
+ t
419
+ ),
420
+ children: /* @__PURE__ */ z(
421
+ "div",
422
+ {
423
+ className: d("label"),
424
+ onClick: () => Z(e.key),
425
+ onMouseEnter: () => Y(e.key),
426
+ onMouseLeave: q,
427
+ children: [
428
+ /* @__PURE__ */ o(ae, { column: e }),
429
+ (X === e.key || (w == null ? void 0 : w.key) === e.key) && K(e.key)
430
+ ]
431
+ }
432
+ )
433
+ },
434
+ e.key
435
+ );
436
+ return b ? V(e, _) : _;
437
+ }),
438
+ L.map((e) => {
439
+ const C = /* @__PURE__ */ o(
440
+ "button",
441
+ {
442
+ className: d("table-header-cell", {
443
+ [`align-${e.align}`]: "align" in e,
444
+ "primary-cell": N(e),
445
+ "sortable-cell": A.includes(e.key),
446
+ resizable: b
447
+ }),
448
+ style: W(
449
+ e,
450
+ !1,
451
+ void 0,
452
+ g,
453
+ M,
454
+ v,
455
+ t
456
+ ),
457
+ children: /* @__PURE__ */ z(
458
+ "div",
459
+ {
460
+ className: d("label"),
461
+ onClick: () => Z(e.key),
462
+ onMouseEnter: () => Y(e.key),
463
+ onMouseLeave: q,
464
+ children: [
465
+ /* @__PURE__ */ o(ae, { column: e }),
466
+ (X === e.key || (w == null ? void 0 : w.key) === e.key) && K(e.key)
467
+ ]
468
+ }
469
+ )
470
+ },
471
+ e.key
472
+ );
473
+ return b ? V(e, C) : C;
474
+ }),
475
+ c && /* @__PURE__ */ o("div", { className: d("table-header-cell", "action-menu-cell") })
476
+ ]
477
+ }
478
+ ),
479
+ /* @__PURE__ */ o(
480
+ "div",
481
+ {
482
+ className: d(
483
+ "table-body",
484
+ {
485
+ "scrollable-body": k,
486
+ "horizontally-scrollable": m,
487
+ resizable: b
488
+ },
489
+ u
490
+ ),
491
+ children: l.map((e, C) => /* @__PURE__ */ z(
492
+ "div",
493
+ {
494
+ className: d("table-row", Ze(e), a, {
495
+ selectable: t
496
+ }),
497
+ onMouseEnter: () => xe(C),
498
+ onMouseLeave: we,
499
+ children: [
500
+ t && /* @__PURE__ */ o(
501
+ "div",
502
+ {
503
+ className: d("table-cell", "checkbox-cell"),
504
+ style: { left: v ? `${S}px` : "0" },
505
+ children: (F || ve === C) && /* @__PURE__ */ o(
506
+ te,
507
+ {
508
+ value: h.includes(e.id),
509
+ onChange: () => Se(e.id),
510
+ className: d("checkbox-cell")
511
+ }
512
+ )
513
+ }
514
+ ),
515
+ /* @__PURE__ */ o("div", { className: d("row-content-wrapper"), children: /* @__PURE__ */ z("div", { className: d("table-row-content"), style: { gridTemplateColumns: Le }, children: [
516
+ v && /* @__PURE__ */ o("div", { className: d("table-cell", "expand-cell"), style: { left: "0" }, children: /* @__PURE__ */ o(
517
+ "button",
518
+ {
519
+ onClick: () => Ce(e.id),
520
+ "aria-label": E.includes(e.id) ? "Collapse row" : "Expand row",
521
+ "aria-expanded": E.includes(e.id),
522
+ children: /* @__PURE__ */ o(
523
+ "span",
524
+ {
525
+ className: d("expand-icon", {
526
+ expanded: E.includes(e.id)
527
+ }),
528
+ children: /* @__PURE__ */ o(ee, {})
529
+ }
530
+ )
531
+ }
532
+ ) }),
533
+ g.map((_, U) => {
534
+ const P = Q(e.id, _.key), I = N(_);
535
+ return /* @__PURE__ */ o(
536
+ "div",
537
+ {
538
+ ref: I ? J(_.key) : void 0,
539
+ className: d("table-cell", "pinned-column", {
540
+ "primary-cell": I,
541
+ "expanded-cell": P
542
+ }),
543
+ style: W(
544
+ _,
545
+ !0,
546
+ U,
547
+ g,
548
+ M,
549
+ v,
550
+ t
551
+ ),
552
+ children: e[_.key].component || e[_.key].content || e[_.key]
553
+ },
554
+ _.key
555
+ );
556
+ }),
557
+ L.map((_) => {
558
+ const U = Q(e.id, _.key), P = N(_);
559
+ return /* @__PURE__ */ o(
560
+ "div",
561
+ {
562
+ ref: P ? J(_.key) : void 0,
563
+ className: d("table-cell", {
564
+ "primary-cell": P,
565
+ "expanded-cell": U
566
+ }),
567
+ style: W(
568
+ _,
569
+ !1,
570
+ void 0,
571
+ g,
572
+ M,
573
+ v,
574
+ t
575
+ ),
576
+ children: e[_.key].component || e[_.key].content || e[_.key]
577
+ },
578
+ _.key
579
+ );
580
+ }),
581
+ c && /* @__PURE__ */ o("div", { className: d("table-cell", "action-menu-cell"), children: c(e.metaData) })
582
+ ] }) })
583
+ ]
584
+ },
585
+ e.id
586
+ ))
587
+ }
588
+ )
589
+ ]
590
+ }
591
+ );
592
+ };
593
+ export {
594
+ pl as T
595
+ };
package/dist/table.js CHANGED
@@ -1,4 +1,4 @@
1
- import { T as r } from "./table-a67da002.js";
1
+ import { T as r } from "./table-f1461100.js";
2
2
  import "react/jsx-runtime";
3
3
  import "react";
4
4
  import "react-resizable";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/ui-kit",
3
- "version": "0.0.1-alpha.146",
3
+ "version": "0.0.1-alpha.148",
4
4
  "description": "The UI-kit library for ReportPortal Design System.",
5
5
  "type": "module",
6
6
  "scripts": {