@reportportal/ui-kit 0.0.1-alpha.147 → 0.0.1-alpha.149

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/dist/sortable.js CHANGED
@@ -1,160 +1,214 @@
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 = ({
1
+ import { jsx as R } from "react/jsx-runtime";
2
+ import { c as N } from "./bind-06a7ff84.js";
3
+ import { useRef as w, useState as F, useEffect as k, useCallback as x } from "react";
4
+ import { useDrag as $, useDrop as H, useDragLayer as Y } from "react-dnd";
5
+ import { getEmptyImage as z } from "react-dnd-html5-backend";
6
+ import { DROP_POSITIONS as g, DROP_DETECTION_MODE as E } from "./common.js";
7
+ import { createPortal as V } from "react-dom";
8
+ const I = "SORTABLE_ITEM", X = (e) => {
9
+ if (!e)
10
+ return {
11
+ display: "none"
12
+ };
13
+ const { x: t, y: r } = e, l = `translate(${t}px, ${r}px)`;
14
+ return {
15
+ transform: l,
16
+ WebkitTransform: l
17
+ };
18
+ }, U = ({
19
+ fromIndex: e,
20
+ targetIndex: t,
21
+ isTopZone: r
22
+ }) => r ? e < t ? t - 1 : t : e > t ? t + 1 : t, W = (e, t) => {
23
+ const r = e / t;
24
+ return r < 0.05 || r > 0.95 ? null : r < 0.5 ? g.TOP : g.BOTTOM;
25
+ }, q = ({
8
26
  id: e,
9
- index: r,
10
- type: s = D,
11
- isDisabled: i = !1,
12
- onDrop: l,
13
- hideDefaultPreview: c = !1
27
+ index: t,
28
+ type: r = I,
29
+ isDisabled: l = !1,
30
+ isLast: p = !1,
31
+ onDrop: a,
32
+ hideDefaultPreview: d = !1,
33
+ dropDetectionMode: m = E.INDEX_BASED
14
34
  }) => {
15
- const [{ isDragging: d }, g, a] = S(
35
+ const i = m === E.HOVER, c = w(null), n = w(null), [u, o] = F(null), [{ isDragging: O }, P, _] = $(
16
36
  () => ({
17
- type: s,
18
- item: { id: e, index: r, type: s },
19
- collect: (p) => ({
20
- isDragging: p.isDragging()
37
+ type: r,
38
+ item: { id: e, index: t, type: r },
39
+ collect: (s) => ({
40
+ isDragging: s.isDragging()
21
41
  }),
22
- canDrag: () => !i
42
+ canDrag: () => !l
23
43
  }),
24
- [e, r, s, i]
44
+ [e, t, r, l]
25
45
  );
26
- O(() => {
27
- c && a(E(), { captureDraggingState: !0 });
28
- }, [c, a]);
29
- const [{ isOver: o, draggedItemIndex: t }, n] = T(
46
+ k(() => {
47
+ d && _(z(), { captureDraggingState: !0 });
48
+ }, [d, _]);
49
+ const [{ isOver: b, draggedItemIndex: T }, B] = H(
30
50
  () => ({
31
- accept: s,
32
- collect: (p) => {
33
- const m = p.getItem(), b = (m == null ? void 0 : m.id) !== e ? p.isOver() : !1;
51
+ accept: r,
52
+ collect: (s) => {
53
+ const f = s.getItem(), D = (f == null ? void 0 : f.id) !== e ? s.isOver() : !1;
34
54
  return {
35
- isOver: b,
36
- draggedItemIndex: b ? (m == null ? void 0 : m.index) ?? null : null
55
+ isOver: D,
56
+ draggedItemIndex: D ? (f == null ? void 0 : f.index) ?? null : null
37
57
  };
38
58
  },
39
- drop: (p) => {
40
- p.id !== e && l && l(p.index, r);
59
+ hover: (s, f) => {
60
+ if (!i)
61
+ return;
62
+ if (s.id === e) {
63
+ o(null);
64
+ return;
65
+ }
66
+ const v = c.current;
67
+ if (!v) {
68
+ o(null);
69
+ return;
70
+ }
71
+ const D = v.getBoundingClientRect(), A = D.bottom - D.top, h = f.getClientOffset();
72
+ if (!h) {
73
+ o(null);
74
+ return;
75
+ }
76
+ const Z = h.y - D.top, C = W(Z, A);
77
+ C === null ? (o(null), n.current = null) : C === g.TOP ? (o(g.TOP), n.current = g.TOP) : (o(g.BOTTOM), n.current = g.BOTTOM);
78
+ },
79
+ drop: (s) => {
80
+ if (!(s.id === e || !a))
81
+ if (i) {
82
+ const f = n.current;
83
+ if (!f)
84
+ return;
85
+ const v = f === g.TOP, D = U({
86
+ fromIndex: s.index,
87
+ targetIndex: t,
88
+ isTopZone: v
89
+ });
90
+ a(s.index, D);
91
+ } else
92
+ a(s.index, t);
41
93
  }
42
94
  }),
43
- [e, r, s, l]
44
- ), _ = (() => t === null ? null : t > r ? "top" : "bottom")();
95
+ [e, t, r, a, p, i]
96
+ ), S = x(
97
+ (s) => (c.current = s, B(s)),
98
+ [B]
99
+ );
100
+ k(() => {
101
+ b || o(null);
102
+ }, [b]);
103
+ const L = i ? u : (() => T === null ? null : T > t ? g.TOP : g.BOTTOM)();
45
104
  return {
46
- isDragging: d,
47
- isOver: o,
48
- draggedItemIndex: t,
49
- dropPosition: _,
50
- dragRef: g,
51
- dropRef: n,
52
- previewRef: a
105
+ isDragging: O,
106
+ isOver: b,
107
+ draggedItemIndex: T,
108
+ dropPosition: L,
109
+ dragRef: P,
110
+ dropRef: S,
111
+ previewRef: _
53
112
  };
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 = ({
113
+ }, G = {
114
+ "sortable-item": "_sortable-item_l234k_1",
115
+ "sortable-item--drop-target-top": "_sortable-item--drop-target-top_l234k_7",
116
+ "sortable-item--drop-target-bottom": "_sortable-item--drop-target-bottom_l234k_20",
117
+ "drag-handle": "_drag-handle_l234k_34",
118
+ "drag-handle--disabled": "_drag-handle--disabled_l234k_41"
119
+ }, J = N.bind(G), K = ({
61
120
  id: e,
62
- index: r,
63
- type: s = D,
64
- isDisabled: i = !1,
65
- className: l,
66
- draggingClassName: c,
121
+ index: t,
122
+ type: r = I,
123
+ isDisabled: l = !1,
124
+ className: p,
125
+ draggingClassName: a,
67
126
  dropTargetClassName: d,
68
- onDrop: g,
69
- hideDefaultPreview: a = !1,
70
- children: o
127
+ onDrop: m,
128
+ hideDefaultPreview: i = !1,
129
+ dropDetectionMode: c = E.INDEX_BASED,
130
+ isLast: n = !1,
131
+ children: u
71
132
  }) => {
72
- const { isDragging: t, dropPosition: n, dragRef: f, dropRef: _, previewRef: p } = w({
133
+ const { isDragging: o, dropPosition: O, dragRef: P, dropRef: _, previewRef: b } = q({
73
134
  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
135
+ index: t,
136
+ type: r,
137
+ isDisabled: l,
138
+ onDrop: m,
139
+ hideDefaultPreview: i,
140
+ dropDetectionMode: c,
141
+ isLast: n
142
+ }), T = typeof u == "function", B = J("sortable-item", p, {
143
+ "sortable-item--dragging": o,
144
+ "sortable-item--drop-target-top": O === g.TOP,
145
+ "sortable-item--drop-target-bottom": O === g.BOTTOM,
146
+ [a || ""]: o && a,
147
+ [d || ""]: O && d
85
148
  });
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 = ({
149
+ return /* @__PURE__ */ R("div", { ref: (y) => {
150
+ _(y), i || b(y), T || P(y);
151
+ }, className: B, children: T ? u({
152
+ isDragging: o,
153
+ isOver: O !== null,
154
+ dragRef: P
155
+ }) : u });
156
+ }, ie = ({
94
157
  items: e,
95
- type: r = D,
96
- isDisabled: s = !1,
97
- className: i,
98
- itemClassName: l,
99
- onReorder: c,
158
+ type: t = I,
159
+ isDisabled: r = !1,
160
+ className: l,
161
+ itemClassName: p,
162
+ onReorder: a,
100
163
  renderItem: d,
101
- keyExtractor: g = (a) => a.id
164
+ keyExtractor: m = (i) => i.id
102
165
  }) => {
103
- const a = x(
104
- (o, t) => {
105
- const n = [...e], [f] = n.splice(o, 1);
106
- n.splice(t, 0, f), c(n);
166
+ const i = x(
167
+ (c, n) => {
168
+ const u = [...e], [o] = u.splice(c, 1);
169
+ u.splice(n, 0, o), a(u);
107
170
  },
108
- [e, c]
171
+ [e, a]
109
172
  );
110
- return /* @__PURE__ */ u("div", { className: i, children: e.map((o, t) => /* @__PURE__ */ u(
111
- N,
173
+ return /* @__PURE__ */ R("div", { className: l, children: e.map((c, n) => /* @__PURE__ */ R(
174
+ K,
112
175
  {
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)
176
+ id: m(c),
177
+ index: n,
178
+ type: t,
179
+ isDisabled: r,
180
+ className: p,
181
+ onDrop: i,
182
+ isLast: n === e.length - 1,
183
+ children: ({ dragRef: u, isDragging: o }) => d(c, n, u, o)
120
184
  },
121
- g(o)
185
+ m(c)
122
186
  )) });
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 = {
187
+ }, Q = {
134
188
  "drag-layer": "_drag-layer_1izcx_1",
135
189
  "drag-preview": "_drag-preview_1izcx_11"
136
- }, R = I.bind(A), Y = ({
190
+ }, M = N.bind(Q), le = ({
137
191
  type: e,
138
- renderPreview: r,
139
- className: s,
140
- previewClassName: i,
141
- portalTarget: l = document.body
192
+ renderPreview: t,
193
+ className: r,
194
+ previewClassName: l,
195
+ portalTarget: p = document.body
142
196
  }) => {
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()
197
+ const { itemType: a, isDragging: d, item: m, clientOffset: i } = Y(
198
+ (n) => ({
199
+ item: n.getItem(),
200
+ itemType: n.getItemType(),
201
+ clientOffset: n.getClientOffset(),
202
+ isDragging: n.isDragging()
149
203
  })
150
204
  );
151
- if (!d || c !== e || !g || !l)
205
+ if (!d || a !== e || !m || !p)
152
206
  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);
207
+ const c = /* @__PURE__ */ R("div", { className: M("drag-layer", r), children: /* @__PURE__ */ R("div", { className: M("drag-preview", l), style: X(i), children: t(m) }) });
208
+ return V(c, p);
155
209
  };
156
210
  export {
157
- Y as DragLayer,
158
- N as SortableItem,
159
- W as SortableList
211
+ le as DragLayer,
212
+ K as SortableItem,
213
+ ie as SortableList
160
214
  };