@reportportal/ui-kit 0.0.1-alpha.134 → 0.0.1-alpha.136

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,160 @@
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import { c as I } from "./bind-06a7ff84.js";
3
+ import { useEffect as O, useCallback as x } from "react";
4
+ import { useDrag as S, useDrop as T, useDragLayer as h } from "react-dnd";
5
+ import { getEmptyImage as E } from "react-dnd-html5-backend";
6
+ import { createPortal as L } from "react-dom";
7
+ const D = "SORTABLE_ITEM", w = ({
8
+ id: e,
9
+ index: r,
10
+ type: s = D,
11
+ isDisabled: i = !1,
12
+ onDrop: l,
13
+ hideDefaultPreview: c = !1
14
+ }) => {
15
+ const [{ isDragging: d }, g, a] = S(
16
+ () => ({
17
+ type: s,
18
+ item: { id: e, index: r, type: s },
19
+ collect: (p) => ({
20
+ isDragging: p.isDragging()
21
+ }),
22
+ canDrag: () => !i
23
+ }),
24
+ [e, r, s, i]
25
+ );
26
+ O(() => {
27
+ c && a(E(), { captureDraggingState: !0 });
28
+ }, [c, a]);
29
+ const [{ isOver: o, draggedItemIndex: t }, n] = T(
30
+ () => ({
31
+ accept: s,
32
+ collect: (p) => {
33
+ const m = p.getItem(), b = (m == null ? void 0 : m.id) !== e ? p.isOver() : !1;
34
+ return {
35
+ isOver: b,
36
+ draggedItemIndex: b ? (m == null ? void 0 : m.index) ?? null : null
37
+ };
38
+ },
39
+ drop: (p) => {
40
+ p.id !== e && l && l(p.index, r);
41
+ }
42
+ }),
43
+ [e, r, s, l]
44
+ ), _ = (() => t === null ? null : t > r ? "top" : "bottom")();
45
+ return {
46
+ isDragging: d,
47
+ isOver: o,
48
+ draggedItemIndex: t,
49
+ dropPosition: _,
50
+ dragRef: g,
51
+ dropRef: n,
52
+ previewRef: a
53
+ };
54
+ }, P = {
55
+ "sortable-item": "_sortable-item_8p4ra_1",
56
+ "sortable-item--drop-target-top": "_sortable-item--drop-target-top_8p4ra_6",
57
+ "sortable-item--drop-target-bottom": "_sortable-item--drop-target-bottom_8p4ra_17",
58
+ "drag-handle": "_drag-handle_8p4ra_29",
59
+ "drag-handle--disabled": "_drag-handle--disabled_8p4ra_36"
60
+ }, C = I.bind(P), N = ({
61
+ id: e,
62
+ index: r,
63
+ type: s = D,
64
+ isDisabled: i = !1,
65
+ className: l,
66
+ draggingClassName: c,
67
+ dropTargetClassName: d,
68
+ onDrop: g,
69
+ hideDefaultPreview: a = !1,
70
+ children: o
71
+ }) => {
72
+ const { isDragging: t, dropPosition: n, dragRef: f, dropRef: _, previewRef: p } = w({
73
+ id: e,
74
+ index: r,
75
+ type: s,
76
+ isDisabled: i,
77
+ onDrop: g,
78
+ hideDefaultPreview: a
79
+ }), m = typeof o == "function", y = C("sortable-item", l, {
80
+ "sortable-item--dragging": t,
81
+ "sortable-item--drop-target-top": n === "top",
82
+ "sortable-item--drop-target-bottom": n === "bottom",
83
+ [c || ""]: t && c,
84
+ [d || ""]: n && d
85
+ });
86
+ return /* @__PURE__ */ u("div", { ref: (v) => {
87
+ _(v), a || p(v), m || f(v);
88
+ }, className: y, children: m ? o({
89
+ isDragging: t,
90
+ isOver: n !== null,
91
+ dragRef: f
92
+ }) : o });
93
+ }, W = ({
94
+ items: e,
95
+ type: r = D,
96
+ isDisabled: s = !1,
97
+ className: i,
98
+ itemClassName: l,
99
+ onReorder: c,
100
+ renderItem: d,
101
+ keyExtractor: g = (a) => a.id
102
+ }) => {
103
+ const a = x(
104
+ (o, t) => {
105
+ const n = [...e], [f] = n.splice(o, 1);
106
+ n.splice(t, 0, f), c(n);
107
+ },
108
+ [e, c]
109
+ );
110
+ return /* @__PURE__ */ u("div", { className: i, children: e.map((o, t) => /* @__PURE__ */ u(
111
+ N,
112
+ {
113
+ id: g(o),
114
+ index: t,
115
+ type: r,
116
+ isDisabled: s,
117
+ className: l,
118
+ onDrop: a,
119
+ children: ({ dragRef: n, isDragging: f }) => d(o, t, n, f)
120
+ },
121
+ g(o)
122
+ )) });
123
+ }, $ = (e) => {
124
+ if (!e)
125
+ return {
126
+ display: "none"
127
+ };
128
+ const { x: r, y: s } = e, i = `translate(${r}px, ${s}px)`;
129
+ return {
130
+ transform: i,
131
+ WebkitTransform: i
132
+ };
133
+ }, A = {
134
+ "drag-layer": "_drag-layer_1izcx_1",
135
+ "drag-preview": "_drag-preview_1izcx_11"
136
+ }, R = I.bind(A), Y = ({
137
+ type: e,
138
+ renderPreview: r,
139
+ className: s,
140
+ previewClassName: i,
141
+ portalTarget: l = document.body
142
+ }) => {
143
+ const { itemType: c, isDragging: d, item: g, clientOffset: a } = h(
144
+ (t) => ({
145
+ item: t.getItem(),
146
+ itemType: t.getItemType(),
147
+ clientOffset: t.getClientOffset(),
148
+ isDragging: t.isDragging()
149
+ })
150
+ );
151
+ if (!d || c !== e || !g || !l)
152
+ return null;
153
+ const o = /* @__PURE__ */ u("div", { className: R("drag-layer", s), children: /* @__PURE__ */ u("div", { className: R("drag-preview", i), style: $(a), children: r(g) }) });
154
+ return L(o, l);
155
+ };
156
+ export {
157
+ Y as DragLayer,
158
+ N as SortableItem,
159
+ W as SortableList
160
+ };