@reportportal/ui-kit 0.0.1-alpha.169 → 0.0.1-alpha.170

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,179 @@
1
+ import { useRef as C, useState as V, useEffect as d, useCallback as b } from "react";
2
+ import { useDrag as F, useDrop as Y } from "react-dnd";
3
+ import { getEmptyImage as k } from "react-dnd-html5-backend";
4
+ import { DROP_POSITIONS as l, DROP_DETECTION_MODE as h, TREE_DROP_POSITIONS as Z } from "./common.js";
5
+ const x = "SORTABLE_ITEM", z = (r) => {
6
+ if (!r)
7
+ return {
8
+ display: "none"
9
+ };
10
+ const { x: n, y: t } = r, s = `translate(${n}px, ${t}px)`;
11
+ return {
12
+ transform: s,
13
+ WebkitTransform: s
14
+ };
15
+ }, $ = ({
16
+ fromIndex: r,
17
+ targetIndex: n,
18
+ isTopZone: t
19
+ }) => t ? r < n ? n - 1 : n : r > n ? n + 1 : n, G = (r, n) => r / n < 0.5 ? l.TOP : l.BOTTOM, J = ({
20
+ id: r,
21
+ index: n,
22
+ type: t = x,
23
+ isDisabled: s = !1,
24
+ isLast: a = !1,
25
+ onDrop: g,
26
+ hideDefaultPreview: O = !1,
27
+ dropDetectionMode: E = h.INDEX_BASED
28
+ }) => {
29
+ const T = E === h.HOVER, p = C(null), i = C(null), [_, u] = V(null), [{ isDragging: P }, I, m] = F(
30
+ () => ({
31
+ type: t,
32
+ item: { id: r, index: n, type: t },
33
+ collect: (e) => ({
34
+ isDragging: e.isDragging()
35
+ }),
36
+ canDrag: () => !s
37
+ }),
38
+ [r, n, t, s]
39
+ );
40
+ d(() => {
41
+ O && m(k(), { captureDraggingState: !0 });
42
+ }, [O, m]);
43
+ const [{ isOver: v, draggedItemIndex: B }, o] = Y(
44
+ () => ({
45
+ accept: t,
46
+ collect: (e) => {
47
+ const c = e.getItem(), D = (c == null ? void 0 : c.id) !== r ? e.isOver() : !1;
48
+ return {
49
+ isOver: D,
50
+ draggedItemIndex: D ? (c == null ? void 0 : c.index) ?? null : null
51
+ };
52
+ },
53
+ hover: (e, c) => {
54
+ if (!T)
55
+ return;
56
+ if (e.id === r) {
57
+ u(null);
58
+ return;
59
+ }
60
+ const R = p.current;
61
+ if (!R) {
62
+ u(null);
63
+ return;
64
+ }
65
+ const D = R.getBoundingClientRect(), H = D.bottom - D.top, w = c.getClientOffset();
66
+ if (!w) {
67
+ u(null);
68
+ return;
69
+ }
70
+ const L = w.y - D.top, N = G(L, H);
71
+ N === null ? (u(null), i.current = null) : N === l.TOP ? (u(l.TOP), i.current = l.TOP) : (u(l.BOTTOM), i.current = l.BOTTOM);
72
+ },
73
+ drop: (e) => {
74
+ if (!(e.id === r || !g))
75
+ if (T) {
76
+ const c = i.current;
77
+ if (!c)
78
+ return;
79
+ const R = c === l.TOP, D = $({
80
+ fromIndex: e.index,
81
+ targetIndex: n,
82
+ isTopZone: R
83
+ });
84
+ g(e.index, D);
85
+ } else
86
+ g(e.index, n);
87
+ }
88
+ }),
89
+ [r, n, t, g, a, T]
90
+ ), f = b(
91
+ (e) => (p.current = e, o(e)),
92
+ [o]
93
+ );
94
+ d(() => {
95
+ v || u(null);
96
+ }, [v]);
97
+ const S = T ? _ : (() => B === null ? null : B > n ? l.TOP : l.BOTTOM)();
98
+ return {
99
+ isDragging: P,
100
+ isOver: v,
101
+ draggedItemIndex: B,
102
+ dropPosition: S,
103
+ dragRef: I,
104
+ dropRef: f,
105
+ previewRef: m
106
+ };
107
+ }, A = 2, U = (r, n) => {
108
+ if (!r || !n)
109
+ return null;
110
+ const { top: t, height: s } = n, a = r.y - t;
111
+ return a < A ? Z.BEFORE : a > s - A ? Z.AFTER : Z.INSIDE;
112
+ }, K = ({
113
+ id: r,
114
+ index: n,
115
+ parentId: t = null,
116
+ type: s = x,
117
+ isDisabled: a = !1,
118
+ acceptDrop: g = !0,
119
+ canDropOn: O,
120
+ onDrop: E,
121
+ hideDefaultPreview: T = !1
122
+ }) => {
123
+ const p = C(null), i = C(null), [{ isDragging: _ }, u, P] = F(
124
+ () => ({
125
+ type: s,
126
+ item: { id: r, index: n, type: s, parentId: t },
127
+ collect: (o) => ({
128
+ isDragging: o.isDragging()
129
+ }),
130
+ canDrag: () => !a
131
+ }),
132
+ [r, n, s, t, a]
133
+ );
134
+ d(() => {
135
+ T && P(k(), { captureDraggingState: !0 });
136
+ }, [T, P]);
137
+ const [{ isOver: I, dropPosition: m }, v] = Y(
138
+ () => ({
139
+ accept: s,
140
+ collect: (o) => {
141
+ const f = o.getItem(), S = (f == null ? void 0 : f.id) !== r && g && (!O || !f || O(f, r)) ? o.isOver({ shallow: !0 }) : !1;
142
+ let e = null;
143
+ if (S && p.current) {
144
+ const c = o.getClientOffset(), R = p.current.getBoundingClientRect();
145
+ e = U(c, R), i.current = e;
146
+ } else
147
+ i.current = null;
148
+ return {
149
+ isOver: S,
150
+ dropPosition: e
151
+ };
152
+ },
153
+ drop: (o, f) => {
154
+ if (f.didDrop())
155
+ return;
156
+ const M = !O || O(o, r);
157
+ o.id !== r && g && M && E && i.current && E(o, r, i.current);
158
+ }
159
+ }),
160
+ [r, s, g, O, E]
161
+ );
162
+ return {
163
+ isDragging: _,
164
+ isOver: I,
165
+ dropPosition: m,
166
+ dragRef: u,
167
+ dropRef: (o) => {
168
+ p.current = o, v(o);
169
+ },
170
+ previewRef: P,
171
+ elementRef: p
172
+ };
173
+ };
174
+ export {
175
+ x as D,
176
+ K as a,
177
+ z as g,
178
+ J as u
179
+ };
@@ -0,0 +1,16 @@
1
+ import { useState as t, useEffect as o } from "react";
2
+ const s = () => {
3
+ const [i, n] = t({ width: 0, height: 0 });
4
+ return o(() => {
5
+ const e = () => {
6
+ n({
7
+ width: window.innerWidth,
8
+ height: window.innerHeight
9
+ });
10
+ };
11
+ return window.addEventListener("resize", e), e(), () => window.removeEventListener("resize", e);
12
+ }, []), i;
13
+ };
14
+ export {
15
+ s as u
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/ui-kit",
3
- "version": "0.0.1-alpha.169",
3
+ "version": "0.0.1-alpha.170",
4
4
  "description": "The UI-kit library for ReportPortal Design System.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,208 +0,0 @@
1
- import { jsxs as F, Fragment as j, jsx as r } from "react/jsx-runtime";
2
- import M from "react-datepicker/dist/es/index.js";
3
- import { c as U } from "./bind-06a7ff84.js";
4
- import { useMemo as E, forwardRef as W, useRef as q } from "react";
5
- import { F as $ } from "./fieldText-1749da7a.js";
6
- import { D as I } from "./dropdown-7d024c49.js";
7
- import { S as L } from "./calendarArrow-44c7e60e.js";
8
- import { registerLocale as z } from "react-datepicker";
9
- const we = (e, s) => {
10
- z(e, s);
11
- }, J = (e, s = 20) => {
12
- const d = e + s;
13
- return new Array(d - e).fill(void 0).map((u, _) => e - _);
14
- }, K = "_header_1s3dn_1", Q = "_disabled_1s3dn_25", X = "_dropdown_1s3dn_8", Z = {
15
- header: K,
16
- "dropdowns-wrapper": "_dropdowns-wrapper_1s3dn_8",
17
- "button-prev": "_button-prev_1s3dn_13",
18
- "button-next": "_button-next_1s3dn_14",
19
- disabled: Q,
20
- dropdown: X,
21
- "month-dropdown": "_month-dropdown_1s3dn_44",
22
- "toggle-button": "_toggle-button_1s3dn_47"
23
- }, c = U.bind(Z), ee = ({
24
- date: e = /* @__PURE__ */ new Date(),
25
- changeYear: s = () => {
26
- },
27
- changeMonth: d = () => {
28
- },
29
- decreaseMonth: u = () => {
30
- },
31
- increaseMonth: _ = () => {
32
- },
33
- prevMonthButtonDisabled: b = !1,
34
- nextMonthButtonDisabled: w = !1,
35
- headerNodes: g = null,
36
- customClassName: y = "",
37
- yearsOptions: f = [],
38
- locale: C
39
- }) => {
40
- const p = e.getFullYear(), N = e.getMonth(), A = E(() => {
41
- const n = Array(12).keys(), t = new Intl.DateTimeFormat(C, {
42
- month: "long"
43
- }), o = (h) => t.format(new Date(p, h));
44
- return Array.from(n, o).reduce((h, D, S) => h.concat({
45
- value: S,
46
- label: D
47
- }), []);
48
- }, [C, p]), R = E(() => (f.length > 0 ? f : J(p)).reduce(
49
- (t, o) => t.concat({ value: o, label: `${o}` }),
50
- []
51
- ), [f, p]), a = (n) => {
52
- d(n);
53
- }, l = (n) => {
54
- s(n);
55
- };
56
- return /* @__PURE__ */ F(j, { children: [
57
- g && /* @__PURE__ */ r("div", { className: c(y), children: g }),
58
- /* @__PURE__ */ F("div", { className: c("header"), children: [
59
- /* @__PURE__ */ r(
60
- "button",
61
- {
62
- type: "button",
63
- "aria-label": "Previous Months",
64
- disabled: b,
65
- onClick: (n) => {
66
- n.stopPropagation(), u();
67
- },
68
- className: c("button-prev", { disabled: b }),
69
- children: /* @__PURE__ */ r(L, {})
70
- }
71
- ),
72
- /* @__PURE__ */ F("div", { className: c("dropdowns-wrapper"), children: [
73
- /* @__PURE__ */ r(
74
- I,
75
- {
76
- options: A,
77
- value: N,
78
- onChange: a,
79
- transparentBackground: !0,
80
- className: c("dropdown", "month-dropdown"),
81
- toggleButtonClassName: c("toggle-button")
82
- }
83
- ),
84
- /* @__PURE__ */ r(
85
- I,
86
- {
87
- options: R,
88
- value: p,
89
- onChange: l,
90
- transparentBackground: !0,
91
- className: c("dropdown"),
92
- toggleButtonClassName: c("toggle-button")
93
- }
94
- )
95
- ] }),
96
- /* @__PURE__ */ r(
97
- "button",
98
- {
99
- type: "button",
100
- "aria-label": "Next Months",
101
- disabled: w,
102
- onClick: (n) => {
103
- n.stopPropagation(), _();
104
- },
105
- className: c("button-next", { disabled: w }),
106
- children: /* @__PURE__ */ r(L, {})
107
- }
108
- )
109
- ] })
110
- ] });
111
- }, te = "_calendar_evrpf_5", ne = "_date_evrpf_103", oe = "_disabled_evrpf_149", re = "_popper_evrpf_157", ae = "_input_evrpf_161", se = {
112
- calendar: te,
113
- "current-date": "_current-date_evrpf_102",
114
- date: ne,
115
- "end-date": "_end-date_evrpf_120",
116
- "selected-range": "_selected-range_evrpf_130",
117
- disabled: oe,
118
- popper: re,
119
- input: ae,
120
- "input-range": "_input-range_evrpf_168"
121
- }, i = U.bind(se), de = "en", v = "MM-dd-yyyy", ce = " to ", le = W(({ value: e, ...s }, d) => {
122
- const u = (e == null ? void 0 : e.replace(" - ", ce)) ?? "";
123
- return /* @__PURE__ */ r($, { ...s, value: u, ref: d });
124
- }), Ce = (e) => {
125
- const {
126
- onChange: s = () => {
127
- },
128
- disabled: d = !1,
129
- onBlur: u = () => {
130
- },
131
- onFocus: _ = () => {
132
- },
133
- headerNodes: b = null,
134
- customClassName: w = "",
135
- customTimeInput: g = void 0,
136
- shouldCloseOnSelect: y = !0,
137
- popperClassName: f = "",
138
- calendarClassName: C = "",
139
- fixedHeight: p = !1,
140
- language: N = de,
141
- yearsOptions: A = [],
142
- dateFormat: R = v,
143
- value: a = null
144
- } = e, l = "selectsRange" in e && e.selectsRange === !0, n = q(null), t = l ? (a == null ? void 0 : a[0]) ?? void 0 : void 0, o = l ? (a == null ? void 0 : a[1]) ?? void 0 : void 0, x = t == null ? void 0 : t.toDateString(), h = o == null ? void 0 : o.toDateString(), D = o && t && o > t, S = l ? `${v.toUpperCase()} to ${v.toUpperCase()}` : v.toUpperCase(), Y = e.placeholder ?? S, B = (m) => {
145
- if (!l) {
146
- const H = a == null ? void 0 : a.toDateString(), V = m.toDateString();
147
- return i("date", {
148
- "current-date": V === H,
149
- disabled: d
150
- });
151
- }
152
- const T = m.toDateString(), O = T === x, k = D && T === h, G = t && o && m > t && m < o;
153
- return i("date", {
154
- "current-date": O,
155
- "selected-range": G && !k,
156
- "end-date": k && D,
157
- disabled: d
158
- });
159
- }, P = {
160
- customInput: l ? /* @__PURE__ */ r(le, { className: i("input", "input-range"), defaultWidth: !1, ref: n }) : /* @__PURE__ */ r($, { className: i("input"), defaultWidth: !1, ref: n }),
161
- placeholderText: Y,
162
- disabled: d,
163
- shouldCloseOnSelect: y,
164
- fixedHeight: p,
165
- locale: N,
166
- showPopperArrow: !1,
167
- dayClassName: B,
168
- calendarClassName: i(C, "calendar"),
169
- renderCustomHeader: (m) => /* @__PURE__ */ r(
170
- ee,
171
- {
172
- ...m,
173
- headerNodes: b,
174
- customClassName: w,
175
- yearsOptions: A,
176
- locale: N
177
- }
178
- ),
179
- onBlur: u,
180
- onFocus: _,
181
- customTimeInput: g,
182
- showTimeInput: !!g,
183
- popperClassName: i(f, "popper"),
184
- dateFormat: R,
185
- className: i("datepicker")
186
- };
187
- return l ? /* @__PURE__ */ r(
188
- M,
189
- {
190
- ...P,
191
- selectsRange: !0,
192
- startDate: t,
193
- endDate: o,
194
- onChange: s
195
- }
196
- ) : /* @__PURE__ */ r(
197
- M,
198
- {
199
- ...P,
200
- selected: a,
201
- onChange: s
202
- }
203
- );
204
- };
205
- export {
206
- Ce as D,
207
- we as r
208
- };