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