@blocklet/labels 1.5.147 → 1.5.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/index.es.js +332 -418
- package/dist/index.umd.js +3 -3
- package/package.json +3 -2
- package/dist/components/label/translation-input.d.ts +0 -10
package/dist/index.es.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { ExpandMore as
|
|
1
|
+
import { jsx as r, jsxs as C, Fragment as L } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as V, useRef as D, useState as A, useCallback as k, useEffect as M, useMemo as N, useContext as q } from "react";
|
|
3
|
+
import { ExpandMore as W, Add as Z, EditOutlined as G, DeleteOutlineOutlined as U, Edit as Y, LabelOutlined as X } from "@mui/icons-material";
|
|
4
4
|
import f from "@mui/material/Box";
|
|
5
|
-
import { styled as
|
|
6
|
-
import { Tree as
|
|
7
|
-
import { Icon as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import
|
|
21
|
-
const
|
|
22
|
-
function
|
|
5
|
+
import { styled as R } from "@mui/material/styles";
|
|
6
|
+
import { Tree as ee } from "react-arborist";
|
|
7
|
+
import { Icon as te } from "@iconify/react";
|
|
8
|
+
import ne from "lodash/omit";
|
|
9
|
+
import re, { components as $ } from "react-select";
|
|
10
|
+
import oe from "@mui/material/Typography";
|
|
11
|
+
import O from "@mui/material/Button";
|
|
12
|
+
import E from "@mui/material/IconButton";
|
|
13
|
+
import { TranslationTextField as le, TranslationTag as ae } from "@blocklet/translation-input";
|
|
14
|
+
import j from "@mui/material/TextField";
|
|
15
|
+
import se from "@mui/material/ClickAwayListener";
|
|
16
|
+
import { GithubPicker as ie } from "react-color";
|
|
17
|
+
import J from "@arcblock/ux/lib/Dialog";
|
|
18
|
+
import ce from "@mui/material/Alert";
|
|
19
|
+
import { ClickAwayListener as de, Box as ue, Chip as he, IconButton as pe, Button as fe, getContrastRatio as me, alpha as ge } from "@mui/material";
|
|
20
|
+
import { useLocaleContext as ye } from "@arcblock/ux/lib/Locale/context";
|
|
21
|
+
const xe = (e) => /* @__PURE__ */ r("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...e, children: /* @__PURE__ */ r("path", { fill: "currentColor", d: "M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z" }) }), Ce = (e) => /* @__PURE__ */ r("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...e, children: /* @__PURE__ */ r("path", { fill: "currentColor", d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z" }) }), _ = V({});
|
|
22
|
+
function ve({
|
|
23
23
|
selectable: e = !1,
|
|
24
24
|
selected: t = [],
|
|
25
|
-
onSelect:
|
|
26
|
-
renderItem:
|
|
27
|
-
children:
|
|
25
|
+
onSelect: s,
|
|
26
|
+
renderItem: l,
|
|
27
|
+
children: o
|
|
28
28
|
}) {
|
|
29
|
-
const
|
|
30
|
-
Array.from(new Set(t).add(
|
|
31
|
-
},
|
|
29
|
+
const n = (p) => t.indexOf(p) !== -1, a = (p) => {
|
|
30
|
+
Array.from(new Set(t).add(p)), s == null || s(p);
|
|
31
|
+
}, u = N(
|
|
32
32
|
() => ({
|
|
33
33
|
selectable: e,
|
|
34
34
|
selected: t,
|
|
35
|
-
isSelected:
|
|
35
|
+
isSelected: n,
|
|
36
36
|
select: a,
|
|
37
|
-
renderItem:
|
|
37
|
+
renderItem: l
|
|
38
38
|
}),
|
|
39
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
40
|
[t]
|
|
41
41
|
);
|
|
42
|
-
return /* @__PURE__ */
|
|
42
|
+
return /* @__PURE__ */ r(_.Provider, { value: u, children: o });
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const be = (e) => {
|
|
45
45
|
var t;
|
|
46
46
|
return e.isLeaf || !((t = e.data.children) != null && t.length);
|
|
47
47
|
};
|
|
48
|
-
function
|
|
49
|
-
return
|
|
48
|
+
function Se({ node: e }) {
|
|
49
|
+
return be(e) ? /* @__PURE__ */ r("span", {}) : e.isOpen ? /* @__PURE__ */ r(W, { style: { fontSize: 20 } }) : /* @__PURE__ */ r(W, { style: { fontSize: 20, transform: "rotate(-90deg)" } });
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
const { selectable:
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
}, m = /* @__PURE__ */
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
/* @__PURE__ */
|
|
59
|
-
/* @__PURE__ */
|
|
60
|
-
/* @__PURE__ */
|
|
51
|
+
function we({ node: e, style: t, dragHandle: s }) {
|
|
52
|
+
const { selectable: l, select: o, isSelected: n, renderItem: a } = q(_), { data: u } = e, p = u.icon ? /* @__PURE__ */ r(te, { icon: u.icon, style: { fontSize: 18 } }) : /* @__PURE__ */ r(xe, { style: { fontSize: 18, color: u.color || "#ddd" } }), y = (x) => {
|
|
53
|
+
x.stopPropagation(), e.isInternal && e.toggle();
|
|
54
|
+
}, b = (x) => {
|
|
55
|
+
x.stopPropagation(), l && o(e.id);
|
|
56
|
+
}, m = /* @__PURE__ */ C(L, { children: [
|
|
57
|
+
/* @__PURE__ */ C(f, { sx: { display: "flex", alignItems: "center", flex: 1 }, children: [
|
|
58
|
+
/* @__PURE__ */ r(f, { sx: { display: "flex", cursor: "pointer" }, onClick: y, children: /* @__PURE__ */ r(Se, { node: e }) }),
|
|
59
|
+
/* @__PURE__ */ r(f, { sx: { display: "flex", alignItems: "center", width: 22, height: 22 }, children: p }),
|
|
60
|
+
/* @__PURE__ */ r(f, { component: "span", sx: { color: "grey.700" }, children: e.data.name })
|
|
61
61
|
] }),
|
|
62
|
-
|
|
62
|
+
l && n(e.id) && /* @__PURE__ */ r(Ce, {})
|
|
63
63
|
] });
|
|
64
|
-
return /* @__PURE__ */
|
|
64
|
+
return /* @__PURE__ */ C(
|
|
65
65
|
f,
|
|
66
66
|
{
|
|
67
67
|
className: "label-tree-item",
|
|
68
68
|
style: t,
|
|
69
69
|
sx: { display: "flex", alignItems: "center", justifyContent: "space-between" },
|
|
70
|
-
ref:
|
|
71
|
-
onClick:
|
|
70
|
+
ref: s,
|
|
71
|
+
onClick: b,
|
|
72
72
|
children: [
|
|
73
73
|
!a && m,
|
|
74
74
|
!!a && a(m, e.data)
|
|
@@ -76,7 +76,7 @@ function ze({ node: e, style: t, dragHandle: i }) {
|
|
|
76
76
|
}
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
|
-
const
|
|
79
|
+
const Ie = R(f)`
|
|
80
80
|
> div,
|
|
81
81
|
> div > div,
|
|
82
82
|
> div > div > div {
|
|
@@ -90,70 +90,70 @@ const Ae = H(f)`
|
|
|
90
90
|
width: 100%;
|
|
91
91
|
}
|
|
92
92
|
`;
|
|
93
|
-
function
|
|
93
|
+
function F({
|
|
94
94
|
data: e,
|
|
95
95
|
selectable: t,
|
|
96
|
-
selected:
|
|
97
|
-
onSelect:
|
|
98
|
-
rowHeight:
|
|
99
|
-
renderItem:
|
|
96
|
+
selected: s = [],
|
|
97
|
+
onSelect: l,
|
|
98
|
+
rowHeight: o = 28,
|
|
99
|
+
renderItem: n,
|
|
100
100
|
sx: a,
|
|
101
|
-
...
|
|
101
|
+
...u
|
|
102
102
|
}) {
|
|
103
|
-
const
|
|
104
|
-
var c,
|
|
105
|
-
m((((
|
|
106
|
-
}, [
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
}, [e,
|
|
110
|
-
setTimeout(
|
|
111
|
-
}, children:
|
|
103
|
+
const p = D(), y = [...Array.isArray(a) ? a : [a]], [b, m] = A(0), x = k(() => {
|
|
104
|
+
var c, i;
|
|
105
|
+
m((((i = (c = p.current) == null ? void 0 : c.visibleNodes) == null ? void 0 : i.length) || 0) * o);
|
|
106
|
+
}, [o]);
|
|
107
|
+
return M(() => {
|
|
108
|
+
x();
|
|
109
|
+
}, [e, x]), /* @__PURE__ */ r(ve, { selectable: t, selected: s, onSelect: l, renderItem: n, children: /* @__PURE__ */ r(Ie, { ...u, sx: y, children: /* @__PURE__ */ r(ee, { data: e, rowHeight: o, height: b, indent: 32, ref: p, onToggle: () => {
|
|
110
|
+
setTimeout(x);
|
|
111
|
+
}, children: we }) }) });
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
var
|
|
115
|
-
return t.push(
|
|
116
|
-
}, []),
|
|
117
|
-
var
|
|
118
|
-
return (
|
|
119
|
-
}),
|
|
113
|
+
const B = (e) => e.reduce((t, s) => {
|
|
114
|
+
var l;
|
|
115
|
+
return t.push(s), (l = s.children) != null && l.length && t.push(...B(s.children)), t;
|
|
116
|
+
}, []), H = (e) => e.map((t) => {
|
|
117
|
+
var s;
|
|
118
|
+
return (s = t.children) != null && s.length && (t.children = H(t.children)), t;
|
|
119
|
+
}), ze = (e, t = null) => {
|
|
120
120
|
try {
|
|
121
121
|
return JSON.parse(e);
|
|
122
122
|
} catch {
|
|
123
123
|
return t;
|
|
124
124
|
}
|
|
125
|
-
},
|
|
126
|
-
const t = e.reduce((
|
|
125
|
+
}, ke = (e) => {
|
|
126
|
+
const t = e.reduce((o, n) => (o[n.id] = o[n.id] || {}, n.parentId && (o[n.id].parent = n.parentId, o[n.parentId] = o[n.parentId] || {}, o[n.parentId].children = o[n.parentId].children || [], o[n.parentId].children.push(n.id)), o), {}), s = e.map(({ parentId: o, translation: n, ...a }) => ({
|
|
127
127
|
...a,
|
|
128
|
-
translation:
|
|
128
|
+
translation: ze(n),
|
|
129
129
|
children: []
|
|
130
|
-
})),
|
|
131
|
-
return
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
}),
|
|
135
|
-
},
|
|
136
|
-
const { options: t, getValue:
|
|
137
|
-
const
|
|
138
|
-
|
|
130
|
+
})), l = s.reduce((o, n) => ({ ...o, [n.id]: n }), {});
|
|
131
|
+
return s.forEach((o) => {
|
|
132
|
+
const n = t[o.id];
|
|
133
|
+
n.parent && l[n.parent] && (o.parent = l[n.parent]), n.children && (o.children = n.children.map((a) => l[a]));
|
|
134
|
+
}), s.filter((o) => !o.parent);
|
|
135
|
+
}, Ae = (e) => {
|
|
136
|
+
const { options: t, getValue: s, selectProps: l, selectOption: o } = e, n = s(), a = (u) => {
|
|
137
|
+
const p = t.find((y) => y.data.id === u);
|
|
138
|
+
p && o(p);
|
|
139
139
|
};
|
|
140
|
-
return /* @__PURE__ */
|
|
141
|
-
/* @__PURE__ */
|
|
142
|
-
|
|
140
|
+
return /* @__PURE__ */ C(L, { children: [
|
|
141
|
+
/* @__PURE__ */ r($.MenuList, { ...ne(e, ["addon"]), children: /* @__PURE__ */ r(f, { sx: { px: 2, py: 1 }, children: /* @__PURE__ */ r(
|
|
142
|
+
F,
|
|
143
143
|
{
|
|
144
|
-
data:
|
|
144
|
+
data: l.data,
|
|
145
145
|
selectable: !0,
|
|
146
146
|
onSelect: a,
|
|
147
|
-
selected:
|
|
147
|
+
selected: n.map((u) => u.data.id)
|
|
148
148
|
}
|
|
149
149
|
) }) }),
|
|
150
150
|
e.addon
|
|
151
151
|
] });
|
|
152
|
-
},
|
|
153
|
-
const [
|
|
154
|
-
return /* @__PURE__ */
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
!!
|
|
152
|
+
}, Ne = ({ children: e, ...t }) => {
|
|
153
|
+
const [s, l] = e, o = Array.isArray(s) ? s.length : 0;
|
|
154
|
+
return /* @__PURE__ */ C($.ValueContainer, { ...t, children: [
|
|
155
|
+
/* @__PURE__ */ r(f, { component: "span", sx: { fontSize: 13, fontWeight: "bold" }, children: o ? "Labels" : "Filter by labels" }),
|
|
156
|
+
!!o && /* @__PURE__ */ r(
|
|
157
157
|
f,
|
|
158
158
|
{
|
|
159
159
|
sx: {
|
|
@@ -167,12 +167,12 @@ const P = (e) => e.reduce((t, i) => {
|
|
|
167
167
|
fontSize: 12,
|
|
168
168
|
bgcolor: "grey.200"
|
|
169
169
|
},
|
|
170
|
-
children:
|
|
170
|
+
children: o
|
|
171
171
|
}
|
|
172
172
|
),
|
|
173
|
-
|
|
173
|
+
l
|
|
174
174
|
] });
|
|
175
|
-
},
|
|
175
|
+
}, Te = {
|
|
176
176
|
control: (e) => ({
|
|
177
177
|
...e,
|
|
178
178
|
minHeight: 31
|
|
@@ -190,67 +190,67 @@ const P = (e) => e.reduce((t, i) => {
|
|
|
190
190
|
padding: "4px"
|
|
191
191
|
})
|
|
192
192
|
};
|
|
193
|
-
function
|
|
193
|
+
function Oe({
|
|
194
194
|
data: e,
|
|
195
195
|
value: t = [],
|
|
196
|
-
editable:
|
|
197
|
-
addon:
|
|
198
|
-
onChange:
|
|
199
|
-
compact:
|
|
196
|
+
editable: s = !1,
|
|
197
|
+
addon: l,
|
|
198
|
+
onChange: o,
|
|
199
|
+
compact: n,
|
|
200
200
|
isMulti: a = !0,
|
|
201
|
-
maxHeight:
|
|
202
|
-
...
|
|
201
|
+
maxHeight: u = 264,
|
|
202
|
+
...p
|
|
203
203
|
}) {
|
|
204
|
-
const
|
|
205
|
-
() =>
|
|
204
|
+
const y = D(null), b = N(
|
|
205
|
+
() => B(e).map((h) => ({ data: h, label: h.name, value: h.id })),
|
|
206
206
|
[e]
|
|
207
|
-
), m =
|
|
208
|
-
(
|
|
207
|
+
), m = b.reduce(
|
|
208
|
+
(h, I) => ({ ...h, [I.data.id]: I }),
|
|
209
209
|
{}
|
|
210
|
-
),
|
|
211
|
-
prev:
|
|
210
|
+
), x = Array.isArray(t) ? t : [t], z = x.map((h) => m[h]), c = D({
|
|
211
|
+
prev: x.map((h) => {
|
|
212
212
|
var I;
|
|
213
|
-
return ((I = m[
|
|
213
|
+
return ((I = m[h]) == null ? void 0 : I.data) || "";
|
|
214
214
|
})
|
|
215
|
-
}),
|
|
216
|
-
!a || !Array.isArray(
|
|
217
|
-
var
|
|
218
|
-
return (
|
|
215
|
+
}), i = (h, I) => {
|
|
216
|
+
!a || !Array.isArray(h) ? o(h ? [h.data] : []) : c.current.current = h.map((d) => d.data), ["clear", "remove-value"].includes(I.action) && y.current && setTimeout(() => {
|
|
217
|
+
var d;
|
|
218
|
+
return (d = y == null ? void 0 : y.current) == null ? void 0 : d.blur();
|
|
219
219
|
}, 1);
|
|
220
|
-
},
|
|
221
|
-
c.current.current && JSON.stringify(c.current.prev.map((I) => I.id)) !== JSON.stringify(c.current.current.map((I) => I.id)) && (
|
|
220
|
+
}, S = () => {
|
|
221
|
+
c.current.current && JSON.stringify(c.current.prev.map((I) => I.id)) !== JSON.stringify(c.current.current.map((I) => I.id)) && (o(c.current.current), c.current.prev = c.current.current);
|
|
222
222
|
};
|
|
223
|
-
return /* @__PURE__ */
|
|
224
|
-
|
|
223
|
+
return /* @__PURE__ */ r(f, { ...p, children: /* @__PURE__ */ r(
|
|
224
|
+
re,
|
|
225
225
|
{
|
|
226
|
-
ref:
|
|
226
|
+
ref: y,
|
|
227
227
|
defaultValue: z,
|
|
228
|
-
options:
|
|
229
|
-
onChange:
|
|
228
|
+
options: b,
|
|
229
|
+
onChange: i,
|
|
230
230
|
components: {
|
|
231
231
|
// @ts-ignore
|
|
232
|
-
MenuList: (
|
|
232
|
+
MenuList: (h) => /* @__PURE__ */ r(Ae, { ...h, addon: l }),
|
|
233
233
|
// eslint-disable-line react/no-unstable-nested-components
|
|
234
|
-
...
|
|
234
|
+
...n && { ValueContainer: Ne }
|
|
235
235
|
},
|
|
236
236
|
placeholder: "Select labels",
|
|
237
237
|
styles: {
|
|
238
|
-
...
|
|
239
|
-
menu: (
|
|
240
|
-
...
|
|
241
|
-
...
|
|
238
|
+
...n && Te,
|
|
239
|
+
menu: (h) => ({
|
|
240
|
+
...h,
|
|
241
|
+
...s && { paddingBottom: "36px" },
|
|
242
242
|
zIndex: 99
|
|
243
243
|
}),
|
|
244
|
-
menuList: (
|
|
245
|
-
...
|
|
244
|
+
menuList: (h) => ({
|
|
245
|
+
...h,
|
|
246
246
|
overflowY: "auto",
|
|
247
|
-
maxHeight: `${
|
|
247
|
+
maxHeight: `${u}px`
|
|
248
248
|
})
|
|
249
249
|
},
|
|
250
|
-
theme: (
|
|
251
|
-
...
|
|
250
|
+
theme: (h) => ({
|
|
251
|
+
...h,
|
|
252
252
|
colors: {
|
|
253
|
-
...
|
|
253
|
+
...h.colors,
|
|
254
254
|
primary25: "#ddd",
|
|
255
255
|
primary50: "#ddd",
|
|
256
256
|
primary: "#ddd"
|
|
@@ -259,184 +259,120 @@ function Pe({
|
|
|
259
259
|
isSearchable: !1,
|
|
260
260
|
isMulti: a,
|
|
261
261
|
closeMenuOnSelect: !a,
|
|
262
|
-
onMenuClose:
|
|
262
|
+
onMenuClose: S,
|
|
263
263
|
isClearable: !0,
|
|
264
264
|
data: e
|
|
265
265
|
}
|
|
266
266
|
) });
|
|
267
267
|
}
|
|
268
|
-
var
|
|
269
|
-
return
|
|
270
|
-
for (var
|
|
271
|
-
|
|
272
|
-
for (var
|
|
273
|
-
Object.prototype.hasOwnProperty.call(
|
|
268
|
+
var P = function() {
|
|
269
|
+
return P = Object.assign || function(t) {
|
|
270
|
+
for (var s, l = 1, o = arguments.length; l < o; l++) {
|
|
271
|
+
s = arguments[l];
|
|
272
|
+
for (var n in s)
|
|
273
|
+
Object.prototype.hasOwnProperty.call(s, n) && (t[n] = s[n]);
|
|
274
274
|
}
|
|
275
275
|
return t;
|
|
276
|
-
},
|
|
276
|
+
}, P.apply(this, arguments);
|
|
277
277
|
};
|
|
278
|
-
function
|
|
279
|
-
var
|
|
280
|
-
if (!
|
|
278
|
+
function Be(e, t) {
|
|
279
|
+
var s = typeof Symbol == "function" && e[Symbol.iterator];
|
|
280
|
+
if (!s)
|
|
281
281
|
return e;
|
|
282
|
-
var
|
|
282
|
+
var l = s.call(e), o, n = [], a;
|
|
283
283
|
try {
|
|
284
|
-
for (; (t === void 0 || t-- > 0) && !(
|
|
285
|
-
|
|
286
|
-
} catch (
|
|
287
|
-
a = { error:
|
|
284
|
+
for (; (t === void 0 || t-- > 0) && !(o = l.next()).done; )
|
|
285
|
+
n.push(o.value);
|
|
286
|
+
} catch (u) {
|
|
287
|
+
a = { error: u };
|
|
288
288
|
} finally {
|
|
289
289
|
try {
|
|
290
|
-
|
|
290
|
+
o && !o.done && (s = l.return) && s.call(l);
|
|
291
291
|
} finally {
|
|
292
292
|
if (a)
|
|
293
293
|
throw a.error;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
return
|
|
296
|
+
return n;
|
|
297
297
|
}
|
|
298
|
-
var
|
|
298
|
+
var Le = function(e) {
|
|
299
299
|
return typeof e == "function";
|
|
300
|
-
},
|
|
301
|
-
var t =
|
|
302
|
-
|
|
303
|
-
var
|
|
304
|
-
return
|
|
300
|
+
}, Pe = function(e) {
|
|
301
|
+
var t = Be(A(e), 2), s = t[0], l = t[1], o = k(function(n) {
|
|
302
|
+
l(function(a) {
|
|
303
|
+
var u = Le(n) ? n(a) : n;
|
|
304
|
+
return u ? P(P({}, a), u) : a;
|
|
305
305
|
});
|
|
306
306
|
}, []);
|
|
307
|
-
return [
|
|
307
|
+
return [s, o];
|
|
308
308
|
};
|
|
309
|
-
const
|
|
310
|
-
function
|
|
311
|
-
const
|
|
312
|
-
const m = g.currentTarget.closest(".MuiInputBase-root");
|
|
313
|
-
m && a(m);
|
|
314
|
-
}, h = () => {
|
|
315
|
-
a(null);
|
|
316
|
-
}, x = i.filter((g) => g.code !== "en");
|
|
317
|
-
return /* @__PURE__ */ n(
|
|
318
|
-
V,
|
|
319
|
-
{
|
|
320
|
-
...t,
|
|
321
|
-
InputProps: {
|
|
322
|
-
endAdornment: /* @__PURE__ */ b(he, { position: "end", children: [
|
|
323
|
-
/* @__PURE__ */ n(K, { edge: "end", onClick: d, children: /* @__PURE__ */ n(X, {}) }),
|
|
324
|
-
/* @__PURE__ */ n(
|
|
325
|
-
ye,
|
|
326
|
-
{
|
|
327
|
-
open: !!r,
|
|
328
|
-
anchorEl: r,
|
|
329
|
-
onClose: h,
|
|
330
|
-
transformOrigin: {
|
|
331
|
-
vertical: "top",
|
|
332
|
-
horizontal: "right"
|
|
333
|
-
},
|
|
334
|
-
anchorOrigin: {
|
|
335
|
-
vertical: "bottom",
|
|
336
|
-
horizontal: "right"
|
|
337
|
-
},
|
|
338
|
-
PaperProps: {
|
|
339
|
-
sx: { width: r == null ? void 0 : r.clientWidth, maxHeight: 200, overflowY: "auto", bgcolor: "grey.50" }
|
|
340
|
-
},
|
|
341
|
-
elevation: 1,
|
|
342
|
-
sx: { mt: 2 },
|
|
343
|
-
children: /* @__PURE__ */ n(O, { sx: { p: 2 }, children: x.map(({ code: g, name: m }) => /* @__PURE__ */ b(
|
|
344
|
-
O,
|
|
345
|
-
{
|
|
346
|
-
sx: {
|
|
347
|
-
display: "flex",
|
|
348
|
-
alignItems: "center",
|
|
349
|
-
justifyContent: "space-between",
|
|
350
|
-
"& + &": { mt: 1 }
|
|
351
|
-
},
|
|
352
|
-
children: [
|
|
353
|
-
/* @__PURE__ */ n(O, { sx: { flex: "0 0 120px" }, children: m }),
|
|
354
|
-
/* @__PURE__ */ n(O, { sx: { flex: 1 }, children: /* @__PURE__ */ n(
|
|
355
|
-
V,
|
|
356
|
-
{
|
|
357
|
-
value: o[g] || "",
|
|
358
|
-
size: "small",
|
|
359
|
-
sx: { width: 1 },
|
|
360
|
-
onChange: (y) => l({ ...o, [g]: y.target.value })
|
|
361
|
-
}
|
|
362
|
-
) })
|
|
363
|
-
]
|
|
364
|
-
},
|
|
365
|
-
g
|
|
366
|
-
)) })
|
|
367
|
-
}
|
|
368
|
-
)
|
|
369
|
-
] })
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
function Fe({ open: e, initialLabel: t, onSubmit: i, onClose: o, ...l }) {
|
|
375
|
-
const r = !(t != null && t.id), [a, d] = Me({
|
|
309
|
+
const Ee = Pe;
|
|
310
|
+
function je({ open: e, initialLabel: t, onSubmit: s, onClose: l, ...o }) {
|
|
311
|
+
const n = !(t != null && t.id), [a, u] = Ee({
|
|
376
312
|
name: (t == null ? void 0 : t.name) || "",
|
|
377
313
|
color: (t == null ? void 0 : t.color) || "#ddd",
|
|
378
314
|
slug: (t == null ? void 0 : t.id) || "",
|
|
379
315
|
translation: (t == null ? void 0 : t.translation) || {}
|
|
380
|
-
}),
|
|
381
|
-
|
|
382
|
-
}, z = (
|
|
383
|
-
|
|
384
|
-
}, c = (
|
|
385
|
-
|
|
316
|
+
}), p = (i) => /^#([0-9A-F]{3}){1,2}$/i.test(i), y = N(() => n ? a.name && a.color && a.slug && p(a.color) : a.name && a.color && p(a.color), [a, n]), [b, m] = A(!1), x = () => {
|
|
317
|
+
s({ ...t, name: a.name, color: a.color, id: a.slug, translation: a.translation });
|
|
318
|
+
}, z = (i) => {
|
|
319
|
+
u({ color: i.hex }), setTimeout(() => m(!1));
|
|
320
|
+
}, c = (i) => {
|
|
321
|
+
u({ color: i.target.value });
|
|
386
322
|
};
|
|
387
|
-
return /* @__PURE__ */
|
|
388
|
-
|
|
323
|
+
return /* @__PURE__ */ r(
|
|
324
|
+
J,
|
|
389
325
|
{
|
|
390
326
|
open: e,
|
|
391
327
|
showCloseButton: !0,
|
|
392
328
|
maxWidth: "lg",
|
|
393
|
-
title:
|
|
394
|
-
actions: /* @__PURE__ */
|
|
395
|
-
/* @__PURE__ */
|
|
396
|
-
/* @__PURE__ */
|
|
329
|
+
title: n ? "Create label" : "Edit label",
|
|
330
|
+
actions: /* @__PURE__ */ C(L, { children: [
|
|
331
|
+
/* @__PURE__ */ r(O, { color: "inherit", variant: "contained", size: "small", onClick: l, children: "Cancel" }),
|
|
332
|
+
/* @__PURE__ */ r(O, { color: "primary", variant: "contained", size: "small", onClick: x, disabled: !y, children: n ? "Create" : "Save Changes" })
|
|
397
333
|
] }),
|
|
398
|
-
onClose:
|
|
399
|
-
...
|
|
400
|
-
children: /* @__PURE__ */
|
|
401
|
-
/* @__PURE__ */
|
|
402
|
-
|
|
334
|
+
onClose: l,
|
|
335
|
+
...o,
|
|
336
|
+
children: /* @__PURE__ */ C(f, { width: 600, minHeight: 320, children: [
|
|
337
|
+
/* @__PURE__ */ r(
|
|
338
|
+
le,
|
|
403
339
|
{
|
|
404
340
|
label: "Name",
|
|
405
341
|
value: a.name,
|
|
406
342
|
placeholder: "New label",
|
|
407
343
|
size: "small",
|
|
408
344
|
fullWidth: !0,
|
|
409
|
-
onChange: (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
onChange: (
|
|
345
|
+
onChange: (i) => u({ name: i.target.value }),
|
|
346
|
+
translationInputProps: {
|
|
347
|
+
value: a.translation,
|
|
348
|
+
onChange: (i) => u({ translation: i })
|
|
413
349
|
}
|
|
414
350
|
}
|
|
415
351
|
),
|
|
416
|
-
/* @__PURE__ */
|
|
417
|
-
|
|
352
|
+
/* @__PURE__ */ r(
|
|
353
|
+
j,
|
|
418
354
|
{
|
|
419
355
|
label: "Slug",
|
|
420
356
|
value: a.slug,
|
|
421
357
|
size: "small",
|
|
422
358
|
fullWidth: !0,
|
|
423
|
-
disabled: !
|
|
424
|
-
onChange: (
|
|
359
|
+
disabled: !n,
|
|
360
|
+
onChange: (i) => u({ slug: i.target.value }),
|
|
425
361
|
sx: { mt: 2 }
|
|
426
362
|
}
|
|
427
363
|
),
|
|
428
|
-
(t == null ? void 0 : t.parent) && /* @__PURE__ */
|
|
429
|
-
/* @__PURE__ */
|
|
430
|
-
/* @__PURE__ */
|
|
431
|
-
/* @__PURE__ */
|
|
364
|
+
(t == null ? void 0 : t.parent) && /* @__PURE__ */ r(j, { label: "Parent", value: t.parent.name, size: "small", fullWidth: !0, disabled: !0, sx: { mt: 2 } }),
|
|
365
|
+
/* @__PURE__ */ r(se, { onClickAway: () => m(!1), children: /* @__PURE__ */ C(f, { sx: { position: "relative", mt: 2 }, children: [
|
|
366
|
+
/* @__PURE__ */ C(f, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
367
|
+
/* @__PURE__ */ r(
|
|
432
368
|
f,
|
|
433
369
|
{
|
|
434
370
|
sx: { width: 30, height: 30, bgcolor: a.color, borderRadius: 1 },
|
|
435
371
|
onClick: () => m(!0)
|
|
436
372
|
}
|
|
437
373
|
),
|
|
438
|
-
/* @__PURE__ */
|
|
439
|
-
|
|
374
|
+
/* @__PURE__ */ r(
|
|
375
|
+
j,
|
|
440
376
|
{
|
|
441
377
|
label: "",
|
|
442
378
|
value: a.color,
|
|
@@ -447,34 +383,34 @@ function Fe({ open: e, initialLabel: t, onSubmit: i, onClose: o, ...l }) {
|
|
|
447
383
|
}
|
|
448
384
|
)
|
|
449
385
|
] }),
|
|
450
|
-
|
|
386
|
+
b && /* @__PURE__ */ r(f, { sx: { position: "absolute", top: 48, zIndex: 1 }, children: /* @__PURE__ */ r(ie, { color: a.color, onChangeComplete: z }) })
|
|
451
387
|
] }) })
|
|
452
388
|
] })
|
|
453
389
|
}
|
|
454
390
|
);
|
|
455
391
|
}
|
|
456
|
-
function
|
|
457
|
-
return /* @__PURE__ */
|
|
458
|
-
|
|
392
|
+
function De({ open: e, label: t, onSubmit: s, onClose: l, ...o }) {
|
|
393
|
+
return /* @__PURE__ */ r(
|
|
394
|
+
J,
|
|
459
395
|
{
|
|
460
396
|
open: e,
|
|
461
397
|
showCloseButton: !0,
|
|
462
398
|
maxWidth: "md",
|
|
463
399
|
title: "Delete",
|
|
464
|
-
actions: /* @__PURE__ */
|
|
465
|
-
/* @__PURE__ */
|
|
466
|
-
/* @__PURE__ */
|
|
400
|
+
actions: /* @__PURE__ */ C(L, { children: [
|
|
401
|
+
/* @__PURE__ */ r(O, { color: "inherit", variant: "contained", size: "small", onClick: l, children: "Cancel" }),
|
|
402
|
+
/* @__PURE__ */ r(O, { color: "primary", variant: "contained", size: "small", onClick: s, children: "Delete" })
|
|
467
403
|
] }),
|
|
468
|
-
onClose:
|
|
469
|
-
...
|
|
470
|
-
children: /* @__PURE__ */
|
|
471
|
-
/* @__PURE__ */
|
|
472
|
-
/* @__PURE__ */
|
|
404
|
+
onClose: l,
|
|
405
|
+
...o,
|
|
406
|
+
children: /* @__PURE__ */ C(f, { width: 600, minHeight: 280, children: [
|
|
407
|
+
/* @__PURE__ */ r(ce, { severity: "info", sx: { mb: 2 }, children: "Are you sure you want to delete these labels ?" }),
|
|
408
|
+
/* @__PURE__ */ r(F, { data: [t] })
|
|
473
409
|
] })
|
|
474
410
|
}
|
|
475
411
|
);
|
|
476
412
|
}
|
|
477
|
-
const
|
|
413
|
+
const Me = R(F)`
|
|
478
414
|
.label-tree-item {
|
|
479
415
|
&:before {
|
|
480
416
|
content: '';
|
|
@@ -495,73 +431,51 @@ const Re = H(W)`
|
|
|
495
431
|
padding: 0 16px;
|
|
496
432
|
}
|
|
497
433
|
`;
|
|
498
|
-
function
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
className: "label-translation-tag",
|
|
513
|
-
children: [
|
|
514
|
-
/* @__PURE__ */ n(f, { sx: { pr: 0.5, borderRight: 1, borderColor: "grey.400" }, children: e }),
|
|
515
|
-
/* @__PURE__ */ n(f, { sx: { pl: 0.5 }, children: t })
|
|
516
|
-
]
|
|
517
|
-
}
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
function dt({ data: e, api: t, ...i }) {
|
|
521
|
-
const [o, l] = A(null), [r, a] = A(null), [d, h] = A(Z(e)), x = N(() => P(d), [d]), g = N(() => {
|
|
522
|
-
const u = (C, S) => C.map((v) => (S && (v.parent = S), v.children && (v.children = u(v.children, v)), v));
|
|
523
|
-
return u(d);
|
|
524
|
-
}, [d]), m = (u) => {
|
|
525
|
-
var C, S;
|
|
526
|
-
u.parent ? (u.parent.children = (S = (C = u.parent) == null ? void 0 : C.children) == null ? void 0 : S.map((v) => v.id === u.id ? { ...u } : v), m(u.parent)) : h(d.map((v) => v.id === u.id ? { ...u } : v));
|
|
527
|
-
}, y = (u) => {
|
|
528
|
-
u.parent ? (u.parent.children = u.parent.children || [], u.parent.children.push(u), h([...d])) : h([...d, u]);
|
|
529
|
-
}, z = (u) => {
|
|
530
|
-
var C;
|
|
531
|
-
u.parent ? u.parent.children = (C = u.parent.children) == null ? void 0 : C.filter((S) => S.id !== u.id) : h(d.filter((S) => S.id !== u.id));
|
|
532
|
-
}, c = (u) => {
|
|
533
|
-
if (o)
|
|
434
|
+
function at({ data: e, api: t, ...s }) {
|
|
435
|
+
const [l, o] = A(null), [n, a] = A(null), [u, p] = A(H(e)), y = N(() => B(u), [u]), b = N(() => {
|
|
436
|
+
const d = (g, w) => g.map((v) => (w && (v.parent = w), v.children && (v.children = d(v.children, v)), v));
|
|
437
|
+
return d(u);
|
|
438
|
+
}, [u]), m = (d) => {
|
|
439
|
+
var g, w;
|
|
440
|
+
d.parent ? (d.parent.children = (w = (g = d.parent) == null ? void 0 : g.children) == null ? void 0 : w.map((v) => v.id === d.id ? { ...d } : v), m(d.parent)) : p(u.map((v) => v.id === d.id ? { ...d } : v));
|
|
441
|
+
}, x = (d) => {
|
|
442
|
+
d.parent ? (d.parent.children = d.parent.children || [], d.parent.children.push(d), p([...u])) : p([...u, d]);
|
|
443
|
+
}, z = (d) => {
|
|
444
|
+
var g;
|
|
445
|
+
d.parent ? d.parent.children = (g = d.parent.children) == null ? void 0 : g.filter((w) => w.id !== d.id) : p(u.filter((w) => w.id !== d.id));
|
|
446
|
+
}, c = (d) => {
|
|
447
|
+
if (l)
|
|
534
448
|
return;
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
-
|
|
538
|
-
},
|
|
539
|
-
if (!
|
|
449
|
+
o({ id: "", name: "New label", parent: d, color: "#dddddd" });
|
|
450
|
+
}, i = (d) => {
|
|
451
|
+
l || o(d);
|
|
452
|
+
}, S = async (d) => {
|
|
453
|
+
if (!l)
|
|
540
454
|
return;
|
|
541
|
-
const { parent:
|
|
542
|
-
|
|
543
|
-
},
|
|
544
|
-
|
|
545
|
-
}, I = (
|
|
546
|
-
/* @__PURE__ */
|
|
547
|
-
/* @__PURE__ */
|
|
548
|
-
|
|
455
|
+
const { parent: g, children: w, translation: v, ...T } = d;
|
|
456
|
+
l.id ? (await t.updateLabel({ ...T, translation: JSON.stringify(v), parentId: g == null ? void 0 : g.id }), m(d)) : (await t.createLabel({ ...T, translation: JSON.stringify(v), parentId: g == null ? void 0 : g.id }), x(d)), o(null);
|
|
457
|
+
}, h = async () => {
|
|
458
|
+
n && (await t.deleteLabel(n.id), z(n), a(null));
|
|
459
|
+
}, I = (d, g) => /* @__PURE__ */ C(L, { children: [
|
|
460
|
+
/* @__PURE__ */ C(f, { sx: { display: "flex", alignItems: "center", flexWrap: "wrap" }, className: "label-name", children: [
|
|
461
|
+
/* @__PURE__ */ r(f, { children: d }),
|
|
462
|
+
g.translation && /* @__PURE__ */ r(f, { sx: { display: "flex", alignItems: "center", gap: 0.5, ml: 2 }, className: "label-translation", children: Object.keys(g.translation).map((w) => {
|
|
549
463
|
var T;
|
|
550
|
-
const v = (T =
|
|
551
|
-
return v ? /* @__PURE__ */
|
|
464
|
+
const v = (T = g.translation) == null ? void 0 : T[w];
|
|
465
|
+
return v ? /* @__PURE__ */ r(ae, { locale: w, value: v }, w) : null;
|
|
552
466
|
}) })
|
|
553
467
|
] }),
|
|
554
|
-
/* @__PURE__ */
|
|
555
|
-
/* @__PURE__ */
|
|
556
|
-
/* @__PURE__ */
|
|
557
|
-
/* @__PURE__ */
|
|
468
|
+
/* @__PURE__ */ C(f, { sx: { display: "flex", gap: 1, flex: "0 0 auto" }, className: "label-action", children: [
|
|
469
|
+
/* @__PURE__ */ r(E, { color: "inherit", size: "small", sx: { color: "grey.500" }, onClick: () => c(g), children: /* @__PURE__ */ r(Z, { sx: { fontSize: 20 } }) }),
|
|
470
|
+
/* @__PURE__ */ r(E, { color: "inherit", size: "small", sx: { color: "grey.500" }, onClick: () => i(g), children: /* @__PURE__ */ r(G, { sx: { fontSize: 18 } }) }),
|
|
471
|
+
/* @__PURE__ */ r(E, { color: "inherit", size: "small", sx: { color: "grey.500" }, onClick: () => a(g), children: /* @__PURE__ */ r(U, { sx: { fontSize: 20 } }) })
|
|
558
472
|
] })
|
|
559
473
|
] });
|
|
560
|
-
return /* @__PURE__ */
|
|
561
|
-
/* @__PURE__ */
|
|
562
|
-
/* @__PURE__ */
|
|
563
|
-
/* @__PURE__ */
|
|
564
|
-
|
|
474
|
+
return /* @__PURE__ */ C(f, { ...s, className: "label-container", children: [
|
|
475
|
+
/* @__PURE__ */ C(f, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
476
|
+
/* @__PURE__ */ r(oe, { component: "h2", variant: "h6", children: "Manage labels" }),
|
|
477
|
+
/* @__PURE__ */ r(
|
|
478
|
+
O,
|
|
565
479
|
{
|
|
566
480
|
color: "primary",
|
|
567
481
|
variant: "contained",
|
|
@@ -572,155 +486,155 @@ function dt({ data: e, api: t, ...i }) {
|
|
|
572
486
|
}
|
|
573
487
|
)
|
|
574
488
|
] }),
|
|
575
|
-
/* @__PURE__ */
|
|
576
|
-
/* @__PURE__ */
|
|
577
|
-
|
|
489
|
+
/* @__PURE__ */ C(f, { sx: { mt: 2, border: 1, borderColor: "grey.300", borderRadius: 1, overflow: "hidden" }, children: [
|
|
490
|
+
/* @__PURE__ */ C(f, { sx: { p: 2, fontSize: 14, fontWeight: "bold", bgcolor: "grey.200" }, className: "label-header", children: [
|
|
491
|
+
y.length,
|
|
578
492
|
" labels"
|
|
579
493
|
] }),
|
|
580
|
-
/* @__PURE__ */
|
|
494
|
+
/* @__PURE__ */ r(f, { sx: { pt: 0.5 }, children: /* @__PURE__ */ r(Me, { data: b, selected: [], renderItem: I, rowHeight: 64 }) })
|
|
581
495
|
] }),
|
|
582
|
-
/* @__PURE__ */
|
|
583
|
-
|
|
496
|
+
/* @__PURE__ */ r(
|
|
497
|
+
je,
|
|
584
498
|
{
|
|
585
|
-
open: !!
|
|
586
|
-
onClose: () =>
|
|
587
|
-
initialLabel:
|
|
588
|
-
onSubmit:
|
|
499
|
+
open: !!l,
|
|
500
|
+
onClose: () => o(null),
|
|
501
|
+
initialLabel: l,
|
|
502
|
+
onSubmit: S
|
|
589
503
|
},
|
|
590
|
-
|
|
504
|
+
l == null ? void 0 : l.id
|
|
591
505
|
),
|
|
592
|
-
/* @__PURE__ */
|
|
593
|
-
|
|
506
|
+
/* @__PURE__ */ r(
|
|
507
|
+
De,
|
|
594
508
|
{
|
|
595
|
-
open: !!
|
|
509
|
+
open: !!n,
|
|
596
510
|
onClose: () => a(null),
|
|
597
|
-
label:
|
|
598
|
-
onSubmit:
|
|
511
|
+
label: n,
|
|
512
|
+
onSubmit: h
|
|
599
513
|
},
|
|
600
|
-
|
|
514
|
+
n == null ? void 0 : n.id
|
|
601
515
|
)
|
|
602
516
|
] });
|
|
603
517
|
}
|
|
604
|
-
const
|
|
605
|
-
const { updateLabels: e } =
|
|
606
|
-
|
|
518
|
+
const K = V({}), Q = () => q(K), st = () => {
|
|
519
|
+
const { updateLabels: e } = Q();
|
|
520
|
+
M(() => () => {
|
|
607
521
|
e();
|
|
608
522
|
}, []);
|
|
609
523
|
};
|
|
610
|
-
function
|
|
611
|
-
const { locale:
|
|
524
|
+
function it({ fetchLabels: e, children: t }) {
|
|
525
|
+
const { locale: s } = ye(), [l, o] = A({
|
|
612
526
|
loading: !0,
|
|
613
527
|
labels: [],
|
|
614
528
|
updateCounter: 1
|
|
615
529
|
});
|
|
616
|
-
|
|
530
|
+
M(() => {
|
|
617
531
|
(async () => {
|
|
618
532
|
try {
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
} catch (
|
|
623
|
-
console.error(
|
|
533
|
+
o((S) => ({ ...S, loading: !0 }));
|
|
534
|
+
const i = await e();
|
|
535
|
+
o((S) => ({ ...S, loading: !1, labels: ke(i) }));
|
|
536
|
+
} catch (i) {
|
|
537
|
+
console.error(i), o((S) => ({ ...S, loading: !1, labels: [] }));
|
|
624
538
|
}
|
|
625
539
|
})();
|
|
626
|
-
}, [
|
|
627
|
-
const
|
|
628
|
-
var
|
|
629
|
-
return (
|
|
630
|
-
}, [
|
|
540
|
+
}, [l.updateCounter]);
|
|
541
|
+
const n = N(() => {
|
|
542
|
+
var i;
|
|
543
|
+
return (i = l.labels) != null && i.length ? B(l.labels).reduce((S, h) => ({ ...S, [h.id]: h }), {}) : {};
|
|
544
|
+
}, [l.labels]), a = k(
|
|
631
545
|
(c) => {
|
|
632
|
-
var
|
|
546
|
+
var i;
|
|
633
547
|
return {
|
|
634
548
|
...c,
|
|
635
|
-
name: ((
|
|
549
|
+
name: ((i = c.translation) == null ? void 0 : i[s]) || c.name
|
|
636
550
|
};
|
|
637
551
|
},
|
|
638
|
-
[
|
|
639
|
-
),
|
|
640
|
-
(c) => c.filter(Boolean).map((
|
|
641
|
-
[
|
|
642
|
-
),
|
|
643
|
-
let { parent:
|
|
644
|
-
const
|
|
645
|
-
for (;
|
|
646
|
-
|
|
647
|
-
return
|
|
648
|
-
}, []),
|
|
649
|
-
(c) => [...
|
|
650
|
-
[a,
|
|
651
|
-
),
|
|
552
|
+
[s]
|
|
553
|
+
), u = k(
|
|
554
|
+
(c) => c.filter(Boolean).map((i) => n[i]).map(a),
|
|
555
|
+
[n, a]
|
|
556
|
+
), p = k((c) => {
|
|
557
|
+
let { parent: i } = c;
|
|
558
|
+
const S = [];
|
|
559
|
+
for (; i; )
|
|
560
|
+
S.unshift(i), i = i.parent;
|
|
561
|
+
return S;
|
|
562
|
+
}, []), y = k(
|
|
563
|
+
(c) => [...p(c), c].map(a).map((S) => S.name).join(" / "),
|
|
564
|
+
[a, p]
|
|
565
|
+
), b = k((c) => (c == null ? void 0 : c.split(",")) || [], []), m = k((c = []) => {
|
|
652
566
|
if (c != null && c.length)
|
|
653
567
|
return c.join(",");
|
|
654
|
-
}, []),
|
|
655
|
-
loading:
|
|
656
|
-
labels:
|
|
657
|
-
updateLabels: () =>
|
|
658
|
-
getLabelsById:
|
|
659
|
-
parseLabelIds:
|
|
568
|
+
}, []), x = N(() => l.labels.map(a), [l.labels, a]), z = N(() => ({
|
|
569
|
+
loading: l.loading,
|
|
570
|
+
labels: l.labels || [],
|
|
571
|
+
updateLabels: () => o((c) => ({ ...c, updateCounter: ++l.updateCounter })),
|
|
572
|
+
getLabelsById: u,
|
|
573
|
+
parseLabelIds: b,
|
|
660
574
|
stringifyLabelIds: m,
|
|
661
|
-
localizedLabels:
|
|
662
|
-
flattenedLabels:
|
|
663
|
-
getFullLabelName:
|
|
664
|
-
}), [
|
|
665
|
-
return /* @__PURE__ */
|
|
575
|
+
localizedLabels: x,
|
|
576
|
+
flattenedLabels: B(x || []),
|
|
577
|
+
getFullLabelName: y
|
|
578
|
+
}), [l, u, b, m, x, y]);
|
|
579
|
+
return /* @__PURE__ */ r(K.Provider, { value: z, children: t });
|
|
666
580
|
}
|
|
667
|
-
const
|
|
581
|
+
const Fe = (e) => {
|
|
668
582
|
try {
|
|
669
|
-
return
|
|
583
|
+
return me(e, "#fff") > 3.5 ? "#fff" : "#111";
|
|
670
584
|
} catch {
|
|
671
585
|
return "#111";
|
|
672
586
|
}
|
|
673
|
-
},
|
|
587
|
+
}, We = (e, t) => {
|
|
674
588
|
try {
|
|
675
589
|
if (e)
|
|
676
|
-
return
|
|
590
|
+
return ge(e, t);
|
|
677
591
|
} catch {
|
|
678
592
|
return e;
|
|
679
593
|
}
|
|
680
594
|
};
|
|
681
|
-
function
|
|
682
|
-
const
|
|
683
|
-
if (
|
|
595
|
+
function ct({ labels: e, editable: t, onChange: s, sx: l, renderLabel: o }) {
|
|
596
|
+
const n = !(e != null && e.length), { labels: a, loading: u, getLabelsById: p, getFullLabelName: y } = Q(), [b, m] = A(!1);
|
|
597
|
+
if (u || !t && n)
|
|
684
598
|
return null;
|
|
685
|
-
const
|
|
686
|
-
|
|
599
|
+
const x = (i) => {
|
|
600
|
+
s == null || s(i), setTimeout(() => {
|
|
687
601
|
m(!1);
|
|
688
602
|
}, 300);
|
|
689
603
|
};
|
|
690
|
-
if (
|
|
691
|
-
return /* @__PURE__ */
|
|
692
|
-
const z =
|
|
604
|
+
if (b)
|
|
605
|
+
return /* @__PURE__ */ r(de, { onClickAway: () => b && m(!1), children: /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r(Oe, { data: a, value: e || [], onChange: x }) }) });
|
|
606
|
+
const z = p(e || []), c = [
|
|
693
607
|
{ display: "flex", gap: 1, alignItems: "center", flexWrap: "wrap" },
|
|
694
|
-
...Array.isArray(
|
|
608
|
+
...Array.isArray(l) ? l : [l]
|
|
695
609
|
];
|
|
696
|
-
return /* @__PURE__ */
|
|
697
|
-
z.map((
|
|
698
|
-
|
|
610
|
+
return /* @__PURE__ */ C(ue, { sx: c, children: [
|
|
611
|
+
z.map((i) => i ? o ? o(i) : /* @__PURE__ */ r(
|
|
612
|
+
he,
|
|
699
613
|
{
|
|
700
|
-
label:
|
|
614
|
+
label: y(i),
|
|
701
615
|
variant: "filled",
|
|
702
616
|
size: "small",
|
|
703
617
|
sx: {
|
|
704
618
|
height: 20,
|
|
705
619
|
borderRadius: 1,
|
|
706
620
|
fontSize: 12,
|
|
707
|
-
bgcolor:
|
|
708
|
-
color:
|
|
621
|
+
bgcolor: We(i.color, 0.8),
|
|
622
|
+
color: Fe(i.color)
|
|
709
623
|
}
|
|
710
624
|
},
|
|
711
|
-
|
|
625
|
+
i.id
|
|
712
626
|
) : null),
|
|
713
|
-
t && !
|
|
714
|
-
t &&
|
|
627
|
+
t && !n && /* @__PURE__ */ r(pe, { color: "inherit", size: "small", onClick: () => m(!0), sx: { color: "grey.400" }, children: /* @__PURE__ */ r(Y, { sx: { fontSize: 20 } }) }),
|
|
628
|
+
t && n && /* @__PURE__ */ r(fe, { color: "inherit", variant: "outlined", startIcon: /* @__PURE__ */ r(X, {}), onClick: () => m(!0), children: "Edit labels" })
|
|
715
629
|
] });
|
|
716
630
|
}
|
|
717
631
|
export {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
632
|
+
at as LabelManager,
|
|
633
|
+
Oe as LabelPicker,
|
|
634
|
+
F as LabelTree,
|
|
635
|
+
ct as Labels,
|
|
636
|
+
it as LabelsProvider,
|
|
637
|
+
ke as transformLabels,
|
|
638
|
+
Q as useLabelsContext,
|
|
639
|
+
st as useLabelsUpdateOnDestroy
|
|
726
640
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@mui/icons-material"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@blocklet/translation-input"),require("@mui/material/TextField"),require("@mui/material/ClickAwayListener"),require("react-color"),require("@arcblock/ux/lib/Dialog"),require("@mui/material/Alert"),require("@mui/material"),require("@arcblock/ux/lib/Locale/context")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@mui/icons-material","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","lodash/omit","react-select","@mui/material/Typography","@mui/material/Button","@mui/material/IconButton","@blocklet/translation-input","@mui/material/TextField","@mui/material/ClickAwayListener","react-color","@arcblock/ux/lib/Dialog","@mui/material/Alert","@mui/material","@arcblock/ux/lib/Locale/context"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f.DiscussKitComponents={},f.jsxRuntime,f.React,f.iconsMaterial,f.Box,f.styles,f.reactArborist,f.react$1,f.omit,f.Select,f.Typography,f.Button,f.IconButton,f.translationInput,f.TextField,f.ClickAwayListener,f.reactColor,f.Dialog,f.Alert,f.material,f.context))})(this,function(f,e,h,T,y,j,Q,U,Z,E,G,L,M,W,D,Y,X,V,B,A,R){"use strict";const ee=r=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...r,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),re=r=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...r,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),J=h.createContext({});function te({selectable:r=!1,selected:t=[],onSelect:a,renderItem:s,children:o}){const n=g=>t.indexOf(g)!==-1,l=g=>{Array.from(new Set(t).add(g)),a==null||a(g)},u=h.useMemo(()=>({selectable:r,selected:t,isSelected:n,select:l,renderItem:s}),[t]);return e.jsx(J.Provider,{value:u,children:o})}const ne=r=>{var t;return r.isLeaf||!((t=r.data.children)!=null&&t.length)};function se({node:r}){return ne(r)?e.jsx("span",{}):r.isOpen?e.jsx(T.ExpandMore,{style:{fontSize:20}}):e.jsx(T.ExpandMore,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function oe({node:r,style:t,dragHandle:a}){const{selectable:s,select:o,isSelected:n,renderItem:l}=h.useContext(J),{data:u}=r,g=u.icon?e.jsx(U.Icon,{icon:u.icon,style:{fontSize:18}}):e.jsx(ee,{style:{fontSize:18,color:u.color||"#ddd"}}),b=x=>{x.stopPropagation(),r.isInternal&&r.toggle()},S=x=>{x.stopPropagation(),s&&o(r.id)},m=e.jsxs(e.Fragment,{children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(y,{sx:{display:"flex",cursor:"pointer"},onClick:b,children:e.jsx(se,{node:r})}),e.jsx(y,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:g}),e.jsx(y,{component:"span",sx:{color:"grey.700"},children:r.data.name})]}),s&&n(r.id)&&e.jsx(re,{})]});return e.jsxs(y,{className:"label-tree-item",style:t,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:a,onClick:S,children:[!l&&m,!!l&&l(m,r.data)]})}const le=j.styled(y)`
|
|
2
2
|
> div,
|
|
3
3
|
> div > div,
|
|
4
4
|
> div > div > div {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
.label-tree-item {
|
|
12
12
|
width: 100%;
|
|
13
13
|
}
|
|
14
|
-
`;function O({data:r,selectable:t,selected:a=[],onSelect:
|
|
14
|
+
`;function O({data:r,selectable:t,selected:a=[],onSelect:s,rowHeight:o=28,renderItem:n,sx:l,...u}){const g=h.useRef(),b=[...Array.isArray(l)?l:[l]],[S,m]=h.useState(0),x=h.useCallback(()=>{var c,i;m((((i=(c=g.current)==null?void 0:c.visibleNodes)==null?void 0:i.length)||0)*o)},[o]);h.useEffect(()=>{x()},[r,x]);const I=()=>{setTimeout(x)};return e.jsx(te,{selectable:t,selected:a,onSelect:s,renderItem:n,children:e.jsx(le,{...u,sx:b,children:e.jsx(Q.Tree,{data:r,rowHeight:o,height:S,indent:32,ref:g,onToggle:I,children:oe})})})}const q=r=>r.reduce((t,a)=>{var s;return t.push(a),(s=a.children)!=null&&s.length&&t.push(...q(a.children)),t},[]),_=r=>r.map(t=>{var a;return(a=t.children)!=null&&a.length&&(t.children=_(t.children)),t}),ae=(r,t=null)=>{try{return JSON.parse(r)}catch{return t}},H=r=>{const t=r.reduce((o,n)=>(o[n.id]=o[n.id]||{},n.parentId&&(o[n.id].parent=n.parentId,o[n.parentId]=o[n.parentId]||{},o[n.parentId].children=o[n.parentId].children||[],o[n.parentId].children.push(n.id)),o),{}),a=r.map(({parentId:o,translation:n,...l})=>({...l,translation:ae(n),children:[]})),s=a.reduce((o,n)=>({...o,[n.id]:n}),{});return a.forEach(o=>{const n=t[o.id];n.parent&&s[n.parent]&&(o.parent=s[n.parent]),n.children&&(o.children=n.children.map(l=>s[l]))}),a.filter(o=>!o.parent)},ie=r=>{const{options:t,getValue:a,selectProps:s,selectOption:o}=r,n=a(),l=u=>{const g=t.find(b=>b.data.id===u);g&&o(g)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...Z(r,["addon"]),children:e.jsx(y,{sx:{px:2,py:1},children:e.jsx(O,{data:s.data,selectable:!0,onSelect:l,selected:n.map(u=>u.data.id)})})}),r.addon]})},ce=({children:r,...t})=>{const[a,s]=r,o=Array.isArray(a)?a.length:0;return e.jsxs(E.components.ValueContainer,{...t,children:[e.jsx(y,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&e.jsx(y,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:o}),s]})},de={control:r=>({...r,minHeight:31}),valueContainer:r=>({...r,display:"flex"}),dropdownIndicator:r=>({...r,padding:"0 4px"}),clearIndicator:r=>({...r,padding:"4px"})};function K({data:r,value:t=[],editable:a=!1,addon:s,onChange:o,compact:n,isMulti:l=!0,maxHeight:u=264,...g}){const b=h.useRef(null),S=h.useMemo(()=>q(r).map(p=>({data:p,label:p.name,value:p.id})),[r]),m=S.reduce((p,z)=>({...p,[z.data.id]:z}),{}),x=Array.isArray(t)?t:[t],I=x.map(p=>m[p]),c=h.useRef({prev:x.map(p=>{var z;return((z=m[p])==null?void 0:z.data)||""})}),i=(p,z)=>{!l||!Array.isArray(p)?o(p?[p.data]:[]):c.current.current=p.map(d=>d.data),["clear","remove-value"].includes(z.action)&&b.current&&setTimeout(()=>{var d;return(d=b==null?void 0:b.current)==null?void 0:d.blur()},1)},w=()=>{c.current.current&&JSON.stringify(c.current.prev.map(z=>z.id))!==JSON.stringify(c.current.current.map(z=>z.id))&&(o(c.current.current),c.current.prev=c.current.current)};return e.jsx(y,{...g,children:e.jsx(E,{ref:b,defaultValue:I,options:S,onChange:i,components:{MenuList:p=>e.jsx(ie,{...p,addon:s}),...n&&{ValueContainer:ce}},placeholder:"Select labels",styles:{...n&&de,menu:p=>({...p,...a&&{paddingBottom:"36px"},zIndex:99}),menuList:p=>({...p,overflowY:"auto",maxHeight:`${u}px`})},theme:p=>({...p,colors:{...p.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:l,closeMenuOnSelect:!l,onMenuClose:w,isClearable:!0,data:r})})}var P=function(){return P=Object.assign||function(t){for(var a,s=1,o=arguments.length;s<o;s++){a=arguments[s];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t},P.apply(this,arguments)};function ue(r,t){var a=typeof Symbol=="function"&&r[Symbol.iterator];if(!a)return r;var s=a.call(r),o,n=[],l;try{for(;(t===void 0||t-- >0)&&!(o=s.next()).done;)n.push(o.value)}catch(u){l={error:u}}finally{try{o&&!o.done&&(a=s.return)&&a.call(s)}finally{if(l)throw l.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var he=function(r){return typeof r=="function"},fe=function(r){var t=ue(h.useState(r),2),a=t[0],s=t[1],o=h.useCallback(function(n){s(function(l){var u=he(n)?n(l):n;return u?P(P({},l),u):l})},[]);return[a,o]};const pe=fe;function ge({open:r,initialLabel:t,onSubmit:a,onClose:s,...o}){const n=!(t!=null&&t.id),[l,u]=pe({name:(t==null?void 0:t.name)||"",color:(t==null?void 0:t.color)||"#ddd",slug:(t==null?void 0:t.id)||"",translation:(t==null?void 0:t.translation)||{}}),g=i=>/^#([0-9A-F]{3}){1,2}$/i.test(i),b=h.useMemo(()=>n?l.name&&l.color&&l.slug&&g(l.color):l.name&&l.color&&g(l.color),[l,n]),[S,m]=h.useState(!1),x=()=>{a({...t,name:l.name,color:l.color,id:l.slug,translation:l.translation})},I=i=>{u({color:i.hex}),setTimeout(()=>m(!1))},c=i=>{u({color:i.target.value})};return e.jsx(V,{open:r,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{color:"inherit",variant:"contained",size:"small",onClick:s,children:"Cancel"}),e.jsx(L,{color:"primary",variant:"contained",size:"small",onClick:x,disabled:!b,children:n?"Create":"Save Changes"})]}),onClose:s,...o,children:e.jsxs(y,{width:600,minHeight:320,children:[e.jsx(W.TranslationTextField,{label:"Name",value:l.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:i=>u({name:i.target.value}),translationInputProps:{value:l.translation,onChange:i=>u({translation:i})}}),e.jsx(D,{label:"Slug",value:l.slug,size:"small",fullWidth:!0,disabled:!n,onChange:i=>u({slug:i.target.value}),sx:{mt:2}}),(t==null?void 0:t.parent)&&e.jsx(D,{label:"Parent",value:t.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(Y,{onClickAway:()=>m(!1),children:e.jsxs(y,{sx:{position:"relative",mt:2},children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(y,{sx:{width:30,height:30,bgcolor:l.color,borderRadius:1},onClick:()=>m(!0)}),e.jsx(D,{label:"",value:l.color,size:"small",onChange:c,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),S&&e.jsx(y,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(X.GithubPicker,{color:l.color,onChangeComplete:I})})]})})]})})}function ye({open:r,label:t,onSubmit:a,onClose:s,...o}){return e.jsx(V,{open:r,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{color:"inherit",variant:"contained",size:"small",onClick:s,children:"Cancel"}),e.jsx(L,{color:"primary",variant:"contained",size:"small",onClick:a,children:"Delete"})]}),onClose:s,...o,children:e.jsxs(y,{width:600,minHeight:280,children:[e.jsx(B,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(O,{data:[t]})]})})}const me=j.styled(O)`
|
|
15
15
|
.label-tree-item {
|
|
16
16
|
&:before {
|
|
17
17
|
content: '';
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
box-sizing: border-box;
|
|
32
32
|
padding: 0 16px;
|
|
33
33
|
}
|
|
34
|
-
`;function
|
|
34
|
+
`;function Ce({data:r,api:t,...a}){const[s,o]=h.useState(null),[n,l]=h.useState(null),[u,g]=h.useState(_(r)),b=h.useMemo(()=>q(u),[u]),S=h.useMemo(()=>{const d=(C,k)=>C.map(v=>(k&&(v.parent=k),v.children&&(v.children=d(v.children,v)),v));return d(u)},[u]),m=d=>{var C,k;d.parent?(d.parent.children=(k=(C=d.parent)==null?void 0:C.children)==null?void 0:k.map(v=>v.id===d.id?{...d}:v),m(d.parent)):g(u.map(v=>v.id===d.id?{...d}:v))},x=d=>{d.parent?(d.parent.children=d.parent.children||[],d.parent.children.push(d),g([...u])):g([...u,d])},I=d=>{var C;d.parent?d.parent.children=(C=d.parent.children)==null?void 0:C.filter(k=>k.id!==d.id):g(u.filter(k=>k.id!==d.id))},c=d=>{if(s)return;o({id:"",name:"New label",parent:d,color:"#dddddd"})},i=d=>{s||o(d)},w=async d=>{if(!s)return;const{parent:C,children:k,translation:v,...N}=d;s.id?(await t.updateLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),m(d)):(await t.createLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),x(d)),o(null)},p=async()=>{n&&(await t.deleteLabel(n.id),I(n),l(null))},z=(d,C)=>e.jsxs(e.Fragment,{children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(y,{children:d}),C.translation&&e.jsx(y,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(C.translation).map(k=>{var N;const v=(N=C.translation)==null?void 0:N[k];return v?e.jsx(W.TranslationTag,{locale:k,value:v},k):null})})]}),e.jsxs(y,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>c(C),children:e.jsx(T.Add,{sx:{fontSize:20}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>i(C),children:e.jsx(T.EditOutlined,{sx:{fontSize:18}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>l(C),children:e.jsx(T.DeleteOutlineOutlined,{sx:{fontSize:20}})})]})]});return e.jsxs(y,{...a,className:"label-container",children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(G,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(L,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>c(),children:"New label"})]}),e.jsxs(y,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(y,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[b.length," labels"]}),e.jsx(y,{sx:{pt:.5},children:e.jsx(me,{data:S,selected:[],renderItem:z,rowHeight:64})})]}),e.jsx(ge,{open:!!s,onClose:()=>o(null),initialLabel:s,onSubmit:w},s==null?void 0:s.id),e.jsx(ye,{open:!!n,onClose:()=>l(null),label:n,onSubmit:p},n==null?void 0:n.id)]})}const $=h.createContext({}),F=()=>h.useContext($),be=()=>{const{updateLabels:r}=F();h.useEffect(()=>()=>{r()},[])};function xe({fetchLabels:r,children:t}){const{locale:a}=R.useLocaleContext(),[s,o]=h.useState({loading:!0,labels:[],updateCounter:1});h.useEffect(()=>{(async()=>{try{o(w=>({...w,loading:!0}));const i=await r();o(w=>({...w,loading:!1,labels:H(i)}))}catch(i){console.error(i),o(w=>({...w,loading:!1,labels:[]}))}})()},[s.updateCounter]);const n=h.useMemo(()=>{var i;return(i=s.labels)!=null&&i.length?q(s.labels).reduce((w,p)=>({...w,[p.id]:p}),{}):{}},[s.labels]),l=h.useCallback(c=>{var i;return{...c,name:((i=c.translation)==null?void 0:i[a])||c.name}},[a]),u=h.useCallback(c=>c.filter(Boolean).map(i=>n[i]).map(l),[n,l]),g=h.useCallback(c=>{let{parent:i}=c;const w=[];for(;i;)w.unshift(i),i=i.parent;return w},[]),b=h.useCallback(c=>[...g(c),c].map(l).map(w=>w.name).join(" / "),[l,g]),S=h.useCallback(c=>(c==null?void 0:c.split(","))||[],[]),m=h.useCallback((c=[])=>{if(c!=null&&c.length)return c.join(",")},[]),x=h.useMemo(()=>s.labels.map(l),[s.labels,l]),I=h.useMemo(()=>({loading:s.loading,labels:s.labels||[],updateLabels:()=>o(c=>({...c,updateCounter:++s.updateCounter})),getLabelsById:u,parseLabelIds:S,stringifyLabelIds:m,localizedLabels:x,flattenedLabels:q(x||[]),getFullLabelName:b}),[s,u,S,m,x,b]);return e.jsx($.Provider,{value:I,children:t})}const ve=r=>{try{return A.getContrastRatio(r,"#fff")>3.5?"#fff":"#111"}catch{return"#111"}},Se=(r,t)=>{try{if(r)return A.alpha(r,t)}catch{return r}};function we({labels:r,editable:t,onChange:a,sx:s,renderLabel:o}){const n=!(r!=null&&r.length),{labels:l,loading:u,getLabelsById:g,getFullLabelName:b}=F(),[S,m]=h.useState(!1);if(u||!t&&n)return null;const x=i=>{a==null||a(i),setTimeout(()=>{m(!1)},300)};if(S)return e.jsx(A.ClickAwayListener,{onClickAway:()=>S&&m(!1),children:e.jsx("div",{children:e.jsx(K,{data:l,value:r||[],onChange:x})})});const I=g(r||[]),c=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(s)?s:[s]];return e.jsxs(A.Box,{sx:c,children:[I.map(i=>i?o?o(i):e.jsx(A.Chip,{label:b(i),variant:"filled",size:"small",sx:{height:20,borderRadius:1,fontSize:12,bgcolor:Se(i.color,.8),color:ve(i.color)}},i.id):null),t&&!n&&e.jsx(A.IconButton,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(T.Edit,{sx:{fontSize:20}})}),t&&n&&e.jsx(A.Button,{color:"inherit",variant:"outlined",startIcon:e.jsx(T.LabelOutlined,{}),onClick:()=>m(!0),children:"Edit labels"})]})}f.LabelManager=Ce,f.LabelPicker=K,f.LabelTree=O,f.Labels=we,f.LabelsProvider=xe,f.transformLabels=H,f.useLabelsContext=F,f.useLabelsUpdateOnDestroy=be,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/labels",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.149",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@blocklet/translation-input": "1.5.149",
|
|
31
32
|
"@emotion/css": "^11.10.5",
|
|
32
33
|
"@emotion/react": "^11.10.5",
|
|
33
34
|
"@emotion/styled": "^11.10.5",
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"resolutions": {
|
|
76
77
|
"react": "^18.2.0"
|
|
77
78
|
},
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "9b13303126c6633a7c668c524dd82f79f4704401"
|
|
79
80
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TextFieldProps } from '@mui/material';
|
|
2
|
-
import type { Translation } from './types';
|
|
3
|
-
interface Props {
|
|
4
|
-
I18NProps: {
|
|
5
|
-
translation: Translation;
|
|
6
|
-
onChange: (translation: Translation) => void;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export default function TranslationInput({ I18NProps, ...rest }: TextFieldProps & Props): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|