@blocklet/labels 1.5.38 → 1.5.40
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 +164 -162
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { createContext as q, useRef as D, useState as z, useCallback as
|
|
1
|
+
import { createContext as q, useRef as D, useState as z, useCallback as k, useEffect as W, useMemo as T, useContext as H } from "react";
|
|
2
2
|
import R from "@mui/icons-material/ExpandMore";
|
|
3
|
-
import
|
|
4
|
-
import { styled as
|
|
5
|
-
import { Tree as
|
|
6
|
-
import { Icon as
|
|
3
|
+
import h from "@mui/material/Box";
|
|
4
|
+
import { styled as J } from "@mui/material/styles";
|
|
5
|
+
import { Tree as X } from "react-arborist";
|
|
6
|
+
import { Icon as ee } from "@iconify/react";
|
|
7
7
|
import { jsx as n, jsxs as v, Fragment as P } from "react/jsx-runtime";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
8
|
+
import te from "lodash/omit";
|
|
9
|
+
import ne, { components as _ } from "react-select";
|
|
10
|
+
import re from "@mui/material/Typography";
|
|
11
|
+
import A from "@mui/material/Button";
|
|
12
12
|
import N from "@mui/material/IconButton";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
13
|
+
import oe from "@mui/icons-material/DeleteOutlineOutlined";
|
|
14
|
+
import le from "@mui/icons-material/EditOutlined";
|
|
15
|
+
import ie from "@mui/icons-material/Add";
|
|
16
16
|
import j from "@mui/material/TextField";
|
|
17
|
-
import
|
|
17
|
+
import $ from "@mui/material/ClickAwayListener";
|
|
18
18
|
import { GithubPicker as se } from "react-color";
|
|
19
|
-
import
|
|
19
|
+
import K from "@arcblock/ux/lib/Dialog";
|
|
20
20
|
import { TextField as V, InputAdornment as ae, IconButton as ce, Box as B } from "@mui/material";
|
|
21
21
|
import de from "@mui/icons-material/Translate";
|
|
22
22
|
import ue from "@mui/material/Popover";
|
|
23
|
-
import { useLocaleContext as
|
|
24
|
-
import
|
|
25
|
-
import
|
|
23
|
+
import { useLocaleContext as Q } from "@arcblock/ux/lib/Locale/context";
|
|
24
|
+
import he from "@mui/material/Alert";
|
|
25
|
+
import pe from "@mui/icons-material/Edit";
|
|
26
26
|
import me from "@mui/icons-material/LabelOutlined";
|
|
27
|
-
import fe from "@mui/material/
|
|
28
|
-
|
|
29
|
-
const xe = (e) => /* @__PURE__ */ n("svg", {
|
|
27
|
+
import fe from "@mui/material/Chip";
|
|
28
|
+
const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
30
29
|
viewBox: "0 0 24 24",
|
|
31
30
|
width: "1.2em",
|
|
32
31
|
height: "1.2em",
|
|
@@ -35,7 +34,7 @@ const xe = (e) => /* @__PURE__ */ n("svg", {
|
|
|
35
34
|
fill: "currentColor",
|
|
36
35
|
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"
|
|
37
36
|
})
|
|
38
|
-
}),
|
|
37
|
+
}), xe = (e) => /* @__PURE__ */ n("svg", {
|
|
39
38
|
viewBox: "0 0 24 24",
|
|
40
39
|
width: "1.2em",
|
|
41
40
|
height: "1.2em",
|
|
@@ -44,8 +43,8 @@ const xe = (e) => /* @__PURE__ */ n("svg", {
|
|
|
44
43
|
fill: "currentColor",
|
|
45
44
|
d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"
|
|
46
45
|
})
|
|
47
|
-
}),
|
|
48
|
-
function
|
|
46
|
+
}), Y = q({});
|
|
47
|
+
function ye({
|
|
49
48
|
selectable: e = !1,
|
|
50
49
|
selected: t = [],
|
|
51
50
|
onSelect: s,
|
|
@@ -54,7 +53,7 @@ function Ce({
|
|
|
54
53
|
}) {
|
|
55
54
|
const r = (u) => t.indexOf(u) !== -1, i = (u) => {
|
|
56
55
|
Array.from(new Set(t).add(u)), s == null || s(u);
|
|
57
|
-
}, a =
|
|
56
|
+
}, a = T(
|
|
58
57
|
() => ({
|
|
59
58
|
selectable: e,
|
|
60
59
|
selected: t,
|
|
@@ -64,19 +63,19 @@ function Ce({
|
|
|
64
63
|
}),
|
|
65
64
|
[t]
|
|
66
65
|
);
|
|
67
|
-
return /* @__PURE__ */ n(
|
|
66
|
+
return /* @__PURE__ */ n(Y.Provider, {
|
|
68
67
|
value: a,
|
|
69
68
|
children: o
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
|
-
const
|
|
71
|
+
const Ce = (e) => {
|
|
73
72
|
var t;
|
|
74
73
|
return e.isLeaf || !((t = e.data.children) != null && t.length);
|
|
75
74
|
};
|
|
76
|
-
function
|
|
75
|
+
function ve({
|
|
77
76
|
node: e
|
|
78
77
|
}) {
|
|
79
|
-
return
|
|
78
|
+
return Ce(e) ? /* @__PURE__ */ n("span", {}) : e.isOpen ? /* @__PURE__ */ n(R, {
|
|
80
79
|
style: {
|
|
81
80
|
fontSize: 20
|
|
82
81
|
}
|
|
@@ -87,7 +86,7 @@ function be({
|
|
|
87
86
|
}
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
|
-
function
|
|
89
|
+
function be({
|
|
91
90
|
node: e,
|
|
92
91
|
style: t,
|
|
93
92
|
dragHandle: s
|
|
@@ -97,14 +96,14 @@ function Se({
|
|
|
97
96
|
select: o,
|
|
98
97
|
isSelected: r,
|
|
99
98
|
renderItem: i
|
|
100
|
-
} =
|
|
99
|
+
} = H(Y), {
|
|
101
100
|
data: a
|
|
102
|
-
} = e, u = a.icon ? /* @__PURE__ */ n(
|
|
101
|
+
} = e, u = a.icon ? /* @__PURE__ */ n(ee, {
|
|
103
102
|
icon: a.icon,
|
|
104
103
|
style: {
|
|
105
104
|
fontSize: 18
|
|
106
105
|
}
|
|
107
|
-
}) : /* @__PURE__ */ n(
|
|
106
|
+
}) : /* @__PURE__ */ n(ge, {
|
|
108
107
|
style: {
|
|
109
108
|
fontSize: 18,
|
|
110
109
|
color: a.color || "#ddd"
|
|
@@ -114,22 +113,22 @@ function Se({
|
|
|
114
113
|
}, g = (d) => {
|
|
115
114
|
d.stopPropagation(), l && o(e.id);
|
|
116
115
|
}, x = /* @__PURE__ */ v(P, {
|
|
117
|
-
children: [/* @__PURE__ */ v(
|
|
116
|
+
children: [/* @__PURE__ */ v(h, {
|
|
118
117
|
sx: {
|
|
119
118
|
display: "flex",
|
|
120
119
|
alignItems: "center",
|
|
121
120
|
flex: 1
|
|
122
121
|
},
|
|
123
|
-
children: [/* @__PURE__ */ n(
|
|
122
|
+
children: [/* @__PURE__ */ n(h, {
|
|
124
123
|
sx: {
|
|
125
124
|
display: "flex",
|
|
126
125
|
cursor: "pointer"
|
|
127
126
|
},
|
|
128
127
|
onClick: m,
|
|
129
|
-
children: /* @__PURE__ */ n(
|
|
128
|
+
children: /* @__PURE__ */ n(ve, {
|
|
130
129
|
node: e
|
|
131
130
|
})
|
|
132
|
-
}), /* @__PURE__ */ n(
|
|
131
|
+
}), /* @__PURE__ */ n(h, {
|
|
133
132
|
sx: {
|
|
134
133
|
display: "flex",
|
|
135
134
|
alignItems: "center",
|
|
@@ -137,16 +136,16 @@ function Se({
|
|
|
137
136
|
height: 22
|
|
138
137
|
},
|
|
139
138
|
children: u
|
|
140
|
-
}), /* @__PURE__ */ n(
|
|
139
|
+
}), /* @__PURE__ */ n(h, {
|
|
141
140
|
component: "span",
|
|
142
141
|
sx: {
|
|
143
142
|
color: "grey.700"
|
|
144
143
|
},
|
|
145
144
|
children: e.data.name
|
|
146
145
|
})]
|
|
147
|
-
}), l && r(e.id) && /* @__PURE__ */ n(
|
|
146
|
+
}), l && r(e.id) && /* @__PURE__ */ n(xe, {})]
|
|
148
147
|
});
|
|
149
|
-
return /* @__PURE__ */ v(
|
|
148
|
+
return /* @__PURE__ */ v(h, {
|
|
150
149
|
className: "label-tree-item",
|
|
151
150
|
style: t,
|
|
152
151
|
sx: {
|
|
@@ -159,7 +158,7 @@ function Se({
|
|
|
159
158
|
children: [!i && x, !!i && i(x, e.data)]
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
|
-
const
|
|
161
|
+
const Se = J(h)`
|
|
163
162
|
> div,
|
|
164
163
|
> div > div,
|
|
165
164
|
> div > div > div {
|
|
@@ -183,21 +182,21 @@ function F({
|
|
|
183
182
|
sx: i,
|
|
184
183
|
...a
|
|
185
184
|
}) {
|
|
186
|
-
const u = D(), m = [...Array.isArray(i) ? i : [i]], [g, x] = z(0), d =
|
|
185
|
+
const u = D(), m = [...Array.isArray(i) ? i : [i]], [g, x] = z(0), d = k(() => {
|
|
187
186
|
var y, b;
|
|
188
187
|
x((((b = (y = u.current) == null ? void 0 : y.visibleNodes) == null ? void 0 : b.length) || 0) * o);
|
|
189
188
|
}, [o]);
|
|
190
189
|
return W(() => {
|
|
191
190
|
d();
|
|
192
|
-
}, [e, d]), /* @__PURE__ */ n(
|
|
191
|
+
}, [e, d]), /* @__PURE__ */ n(ye, {
|
|
193
192
|
selectable: t,
|
|
194
193
|
selected: s,
|
|
195
194
|
onSelect: l,
|
|
196
195
|
renderItem: r,
|
|
197
|
-
children: /* @__PURE__ */ n(
|
|
196
|
+
children: /* @__PURE__ */ n(Se, {
|
|
198
197
|
...a,
|
|
199
198
|
sx: m,
|
|
200
|
-
children: /* @__PURE__ */ n(
|
|
199
|
+
children: /* @__PURE__ */ n(X, {
|
|
201
200
|
data: e,
|
|
202
201
|
rowHeight: o,
|
|
203
202
|
height: g,
|
|
@@ -206,7 +205,7 @@ function F({
|
|
|
206
205
|
onToggle: () => {
|
|
207
206
|
setTimeout(d);
|
|
208
207
|
},
|
|
209
|
-
children:
|
|
208
|
+
children: be
|
|
210
209
|
})
|
|
211
210
|
})
|
|
212
211
|
});
|
|
@@ -214,26 +213,26 @@ function F({
|
|
|
214
213
|
const L = (e) => e.reduce((t, s) => {
|
|
215
214
|
var l;
|
|
216
215
|
return t.push(s), (l = s.children) != null && l.length && t.push(...L(s.children)), t;
|
|
217
|
-
}, []),
|
|
216
|
+
}, []), Z = (e) => e.map((t) => {
|
|
218
217
|
var s;
|
|
219
|
-
return (s = t.children) != null && s.length && (t.children =
|
|
220
|
-
}),
|
|
218
|
+
return (s = t.children) != null && s.length && (t.children = Z(t.children)), t;
|
|
219
|
+
}), we = (e, t = null) => {
|
|
221
220
|
try {
|
|
222
221
|
return JSON.parse(e);
|
|
223
222
|
} catch {
|
|
224
223
|
return t;
|
|
225
224
|
}
|
|
226
|
-
},
|
|
225
|
+
}, Ie = (e) => {
|
|
227
226
|
const t = e.reduce((o, r) => (o[r.id] = o[r.id] || {}, r.parentId && (o[r.id].parent = r.parentId, o[r.parentId] = o[r.parentId] || {}, o[r.parentId].children = o[r.parentId].children || [], o[r.parentId].children.push(r.id)), o), {}), s = e.map(({ parentId: o, translation: r, ...i }) => ({
|
|
228
227
|
...i,
|
|
229
|
-
translation:
|
|
228
|
+
translation: we(r),
|
|
230
229
|
children: []
|
|
231
230
|
})), l = s.reduce((o, r) => ({ ...o, [r.id]: r }), {});
|
|
232
231
|
return s.forEach((o) => {
|
|
233
232
|
const r = t[o.id];
|
|
234
233
|
r.parent && l[r.parent] && (o.parent = l[r.parent]), r.children && (o.children = r.children.map((i) => l[i]));
|
|
235
234
|
}), s.filter((o) => !o.parent);
|
|
236
|
-
},
|
|
235
|
+
}, ze = (e) => {
|
|
237
236
|
const {
|
|
238
237
|
options: t,
|
|
239
238
|
getValue: s,
|
|
@@ -244,9 +243,9 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
244
243
|
u && o(u);
|
|
245
244
|
};
|
|
246
245
|
return /* @__PURE__ */ v(P, {
|
|
247
|
-
children: [/* @__PURE__ */ n(
|
|
248
|
-
...
|
|
249
|
-
children: /* @__PURE__ */ n(
|
|
246
|
+
children: [/* @__PURE__ */ n(_.MenuList, {
|
|
247
|
+
...te(e, ["addon"]),
|
|
248
|
+
children: /* @__PURE__ */ n(h, {
|
|
250
249
|
sx: {
|
|
251
250
|
px: 2,
|
|
252
251
|
py: 1
|
|
@@ -260,21 +259,21 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
260
259
|
})
|
|
261
260
|
}), e.addon]
|
|
262
261
|
});
|
|
263
|
-
},
|
|
262
|
+
}, Te = ({
|
|
264
263
|
children: e,
|
|
265
264
|
...t
|
|
266
265
|
}) => {
|
|
267
266
|
const [s, l] = e, o = Array.isArray(s) ? s.length : 0;
|
|
268
|
-
return /* @__PURE__ */ v(
|
|
267
|
+
return /* @__PURE__ */ v(_.ValueContainer, {
|
|
269
268
|
...t,
|
|
270
|
-
children: [/* @__PURE__ */ n(
|
|
269
|
+
children: [/* @__PURE__ */ n(h, {
|
|
271
270
|
component: "span",
|
|
272
271
|
sx: {
|
|
273
272
|
fontSize: 13,
|
|
274
273
|
fontWeight: "bold"
|
|
275
274
|
},
|
|
276
275
|
children: o ? "Labels" : "Filter by labels"
|
|
277
|
-
}), !!o && /* @__PURE__ */ n(
|
|
276
|
+
}), !!o && /* @__PURE__ */ n(h, {
|
|
278
277
|
sx: {
|
|
279
278
|
display: "inline-flex",
|
|
280
279
|
justifyContent: "center",
|
|
@@ -289,7 +288,7 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
289
288
|
children: o
|
|
290
289
|
}), l]
|
|
291
290
|
});
|
|
292
|
-
},
|
|
291
|
+
}, ke = {
|
|
293
292
|
control: (e) => ({
|
|
294
293
|
...e,
|
|
295
294
|
minHeight: 31
|
|
@@ -307,7 +306,7 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
307
306
|
padding: "4px"
|
|
308
307
|
})
|
|
309
308
|
};
|
|
310
|
-
function
|
|
309
|
+
function Ae({
|
|
311
310
|
data: e,
|
|
312
311
|
value: t = [],
|
|
313
312
|
editable: s = !1,
|
|
@@ -318,59 +317,62 @@ function Oe({
|
|
|
318
317
|
maxHeight: a = 264,
|
|
319
318
|
...u
|
|
320
319
|
}) {
|
|
321
|
-
const m = D(null), g =
|
|
322
|
-
data:
|
|
323
|
-
label:
|
|
324
|
-
value:
|
|
325
|
-
})), [e]), x = g.reduce((
|
|
326
|
-
...
|
|
320
|
+
const m = D(null), g = T(() => L(e).map((p) => ({
|
|
321
|
+
data: p,
|
|
322
|
+
label: p.name,
|
|
323
|
+
value: p.id
|
|
324
|
+
})), [e]), x = g.reduce((p, I) => ({
|
|
325
|
+
...p,
|
|
327
326
|
[I.data.id]: I
|
|
328
|
-
}), {}), d = Array.isArray(t) ? t : [t], f = d.map((
|
|
329
|
-
prev: d.map((
|
|
330
|
-
|
|
331
|
-
|
|
327
|
+
}), {}), d = Array.isArray(t) ? t : [t], f = d.map((p) => x[p]), y = D({
|
|
328
|
+
prev: d.map((p) => {
|
|
329
|
+
var I;
|
|
330
|
+
return ((I = x[p]) == null ? void 0 : I.data) || "";
|
|
331
|
+
})
|
|
332
|
+
}), b = (p, I) => {
|
|
333
|
+
!i || !Array.isArray(p) ? o(p ? [p.data] : []) : y.current.current = p.map((c) => c.data), ["clear", "remove-value"].includes(I.action) && m.current && setTimeout(() => {
|
|
332
334
|
var c;
|
|
333
335
|
return (c = m == null ? void 0 : m.current) == null ? void 0 : c.blur();
|
|
334
336
|
}, 1);
|
|
335
337
|
}, M = () => {
|
|
336
338
|
y.current.current && JSON.stringify(y.current.prev.map((I) => I.id)) !== JSON.stringify(y.current.current.map((I) => I.id)) && (o(y.current.current), y.current.prev = y.current.current);
|
|
337
339
|
};
|
|
338
|
-
return /* @__PURE__ */ n(
|
|
340
|
+
return /* @__PURE__ */ n(h, {
|
|
339
341
|
...u,
|
|
340
|
-
children: /* @__PURE__ */ n(
|
|
342
|
+
children: /* @__PURE__ */ n(ne, {
|
|
341
343
|
ref: m,
|
|
342
344
|
defaultValue: f,
|
|
343
345
|
options: g,
|
|
344
346
|
onChange: b,
|
|
345
347
|
components: {
|
|
346
|
-
MenuList: (
|
|
347
|
-
...
|
|
348
|
+
MenuList: (p) => /* @__PURE__ */ n(ze, {
|
|
349
|
+
...p,
|
|
348
350
|
addon: l
|
|
349
351
|
}),
|
|
350
352
|
...r && {
|
|
351
|
-
ValueContainer:
|
|
353
|
+
ValueContainer: Te
|
|
352
354
|
}
|
|
353
355
|
},
|
|
354
356
|
placeholder: "Select labels",
|
|
355
357
|
styles: {
|
|
356
|
-
...r &&
|
|
357
|
-
menu: (
|
|
358
|
-
...
|
|
358
|
+
...r && ke,
|
|
359
|
+
menu: (p) => ({
|
|
360
|
+
...p,
|
|
359
361
|
...s && {
|
|
360
362
|
paddingBottom: "36px"
|
|
361
363
|
},
|
|
362
364
|
zIndex: 99
|
|
363
365
|
}),
|
|
364
|
-
menuList: (
|
|
365
|
-
...
|
|
366
|
+
menuList: (p) => ({
|
|
367
|
+
...p,
|
|
366
368
|
overflowY: "auto",
|
|
367
369
|
maxHeight: `${a}px`
|
|
368
370
|
})
|
|
369
371
|
},
|
|
370
|
-
theme: (
|
|
371
|
-
...
|
|
372
|
+
theme: (p) => ({
|
|
373
|
+
...p,
|
|
372
374
|
colors: {
|
|
373
|
-
...
|
|
375
|
+
...p.colors,
|
|
374
376
|
primary25: "#ddd",
|
|
375
377
|
primary50: "#ddd",
|
|
376
378
|
primary: "#ddd"
|
|
@@ -395,7 +397,7 @@ var E = function() {
|
|
|
395
397
|
return t;
|
|
396
398
|
}, E.apply(this, arguments);
|
|
397
399
|
};
|
|
398
|
-
function
|
|
400
|
+
function Oe(e, t) {
|
|
399
401
|
var s = typeof Symbol == "function" && e[Symbol.iterator];
|
|
400
402
|
if (!s)
|
|
401
403
|
return e;
|
|
@@ -415,25 +417,25 @@ function Pe(e, t) {
|
|
|
415
417
|
}
|
|
416
418
|
return r;
|
|
417
419
|
}
|
|
418
|
-
var
|
|
420
|
+
var Pe = function(e) {
|
|
419
421
|
return typeof e == "function";
|
|
420
|
-
},
|
|
421
|
-
var t =
|
|
422
|
+
}, Be = function(e) {
|
|
423
|
+
var t = Oe(z(e), 2), s = t[0], l = t[1], o = k(function(r) {
|
|
422
424
|
l(function(i) {
|
|
423
|
-
var a =
|
|
425
|
+
var a = Pe(r) ? r(i) : r;
|
|
424
426
|
return a ? E(E({}, i), a) : i;
|
|
425
427
|
});
|
|
426
428
|
}, []);
|
|
427
429
|
return [s, o];
|
|
428
430
|
};
|
|
429
|
-
const
|
|
430
|
-
function
|
|
431
|
+
const Ne = Be;
|
|
432
|
+
function Ee({
|
|
431
433
|
I18NProps: e,
|
|
432
434
|
...t
|
|
433
435
|
}) {
|
|
434
436
|
const {
|
|
435
437
|
languages: s
|
|
436
|
-
} =
|
|
438
|
+
} = Q(), {
|
|
437
439
|
translation: l,
|
|
438
440
|
onChange: o
|
|
439
441
|
} = e, [r, i] = z(null), a = (g) => {
|
|
@@ -519,19 +521,19 @@ function Le({
|
|
|
519
521
|
}
|
|
520
522
|
});
|
|
521
523
|
}
|
|
522
|
-
function
|
|
524
|
+
function Le({
|
|
523
525
|
open: e,
|
|
524
526
|
initialLabel: t,
|
|
525
527
|
onSubmit: s,
|
|
526
528
|
onClose: l,
|
|
527
529
|
...o
|
|
528
530
|
}) {
|
|
529
|
-
const r = !(t != null && t.id), [i, a] =
|
|
531
|
+
const r = !(t != null && t.id), [i, a] = Ne({
|
|
530
532
|
name: (t == null ? void 0 : t.name) || "",
|
|
531
533
|
color: (t == null ? void 0 : t.color) || "#ddd",
|
|
532
534
|
slug: (t == null ? void 0 : t.id) || "",
|
|
533
535
|
translation: (t == null ? void 0 : t.translation) || {}
|
|
534
|
-
}), u = (b) => /^#([0-9A-F]{3}){1,2}$/i.test(b), m =
|
|
536
|
+
}), u = (b) => /^#([0-9A-F]{3}){1,2}$/i.test(b), m = T(() => r ? i.name && i.color && i.slug && u(i.color) : i.name && i.color && u(i.color), [i, r]), [g, x] = z(!1), d = () => {
|
|
535
537
|
s({
|
|
536
538
|
...t,
|
|
537
539
|
name: i.name,
|
|
@@ -548,19 +550,19 @@ function Me({
|
|
|
548
550
|
color: b.target.value
|
|
549
551
|
});
|
|
550
552
|
};
|
|
551
|
-
return /* @__PURE__ */ n(
|
|
553
|
+
return /* @__PURE__ */ n(K, {
|
|
552
554
|
open: e,
|
|
553
555
|
showCloseButton: !0,
|
|
554
556
|
maxWidth: "lg",
|
|
555
557
|
title: r ? "Create label" : "Edit label",
|
|
556
558
|
actions: /* @__PURE__ */ v(P, {
|
|
557
|
-
children: [/* @__PURE__ */ n(
|
|
559
|
+
children: [/* @__PURE__ */ n(A, {
|
|
558
560
|
color: "inherit",
|
|
559
561
|
variant: "contained",
|
|
560
562
|
size: "small",
|
|
561
563
|
onClick: l,
|
|
562
564
|
children: "Cancel"
|
|
563
|
-
}), /* @__PURE__ */ n(
|
|
565
|
+
}), /* @__PURE__ */ n(A, {
|
|
564
566
|
color: "primary",
|
|
565
567
|
variant: "contained",
|
|
566
568
|
size: "small",
|
|
@@ -571,10 +573,10 @@ function Me({
|
|
|
571
573
|
}),
|
|
572
574
|
onClose: l,
|
|
573
575
|
...o,
|
|
574
|
-
children: /* @__PURE__ */ v(
|
|
576
|
+
children: /* @__PURE__ */ v(h, {
|
|
575
577
|
width: 600,
|
|
576
578
|
minHeight: 280,
|
|
577
|
-
children: [/* @__PURE__ */ n(
|
|
579
|
+
children: [/* @__PURE__ */ n(Ee, {
|
|
578
580
|
label: "Name",
|
|
579
581
|
value: i.name,
|
|
580
582
|
placeholder: "New label",
|
|
@@ -610,20 +612,20 @@ function Me({
|
|
|
610
612
|
sx: {
|
|
611
613
|
mt: 2
|
|
612
614
|
}
|
|
613
|
-
}), /* @__PURE__ */ n(
|
|
615
|
+
}), /* @__PURE__ */ n($, {
|
|
614
616
|
onClickAway: () => x(!1),
|
|
615
|
-
children: /* @__PURE__ */ v(
|
|
617
|
+
children: /* @__PURE__ */ v(h, {
|
|
616
618
|
sx: {
|
|
617
619
|
position: "relative",
|
|
618
620
|
mt: 2
|
|
619
621
|
},
|
|
620
|
-
children: [/* @__PURE__ */ v(
|
|
622
|
+
children: [/* @__PURE__ */ v(h, {
|
|
621
623
|
sx: {
|
|
622
624
|
display: "flex",
|
|
623
625
|
alignItems: "center",
|
|
624
626
|
gap: 1
|
|
625
627
|
},
|
|
626
|
-
children: [/* @__PURE__ */ n(
|
|
628
|
+
children: [/* @__PURE__ */ n(h, {
|
|
627
629
|
sx: {
|
|
628
630
|
width: 30,
|
|
629
631
|
height: 30,
|
|
@@ -646,7 +648,7 @@ function Me({
|
|
|
646
648
|
}
|
|
647
649
|
}
|
|
648
650
|
})]
|
|
649
|
-
}), g && /* @__PURE__ */ n(
|
|
651
|
+
}), g && /* @__PURE__ */ n(h, {
|
|
650
652
|
sx: {
|
|
651
653
|
position: "absolute",
|
|
652
654
|
top: 48,
|
|
@@ -662,26 +664,26 @@ function Me({
|
|
|
662
664
|
})
|
|
663
665
|
});
|
|
664
666
|
}
|
|
665
|
-
function
|
|
667
|
+
function Me({
|
|
666
668
|
open: e,
|
|
667
669
|
label: t,
|
|
668
670
|
onSubmit: s,
|
|
669
671
|
onClose: l,
|
|
670
672
|
...o
|
|
671
673
|
}) {
|
|
672
|
-
return /* @__PURE__ */ n(
|
|
674
|
+
return /* @__PURE__ */ n(K, {
|
|
673
675
|
open: e,
|
|
674
676
|
showCloseButton: !0,
|
|
675
677
|
maxWidth: "md",
|
|
676
678
|
title: "Delete",
|
|
677
679
|
actions: /* @__PURE__ */ v(P, {
|
|
678
|
-
children: [/* @__PURE__ */ n(
|
|
680
|
+
children: [/* @__PURE__ */ n(A, {
|
|
679
681
|
color: "inherit",
|
|
680
682
|
variant: "contained",
|
|
681
683
|
size: "small",
|
|
682
684
|
onClick: l,
|
|
683
685
|
children: "Cancel"
|
|
684
|
-
}), /* @__PURE__ */ n(
|
|
686
|
+
}), /* @__PURE__ */ n(A, {
|
|
685
687
|
color: "primary",
|
|
686
688
|
variant: "contained",
|
|
687
689
|
size: "small",
|
|
@@ -691,10 +693,10 @@ function je({
|
|
|
691
693
|
}),
|
|
692
694
|
onClose: l,
|
|
693
695
|
...o,
|
|
694
|
-
children: /* @__PURE__ */ v(
|
|
696
|
+
children: /* @__PURE__ */ v(h, {
|
|
695
697
|
width: 600,
|
|
696
698
|
minHeight: 280,
|
|
697
|
-
children: [/* @__PURE__ */ n(
|
|
699
|
+
children: [/* @__PURE__ */ n(he, {
|
|
698
700
|
severity: "info",
|
|
699
701
|
sx: {
|
|
700
702
|
mb: 2
|
|
@@ -706,7 +708,7 @@ function je({
|
|
|
706
708
|
})
|
|
707
709
|
});
|
|
708
710
|
}
|
|
709
|
-
const
|
|
711
|
+
const je = J(F)`
|
|
710
712
|
.label-tree-item {
|
|
711
713
|
&:before {
|
|
712
714
|
content: '';
|
|
@@ -727,11 +729,11 @@ const De = H(F)`
|
|
|
727
729
|
padding: 0 16px;
|
|
728
730
|
}
|
|
729
731
|
`;
|
|
730
|
-
function
|
|
732
|
+
function De({
|
|
731
733
|
locale: e,
|
|
732
734
|
value: t
|
|
733
735
|
}) {
|
|
734
|
-
return /* @__PURE__ */ v(
|
|
736
|
+
return /* @__PURE__ */ v(h, {
|
|
735
737
|
sx: {
|
|
736
738
|
display: "flex",
|
|
737
739
|
alignItems: "center",
|
|
@@ -742,14 +744,14 @@ function We({
|
|
|
742
744
|
bgcolor: "grey.300",
|
|
743
745
|
borderRadius: 2
|
|
744
746
|
},
|
|
745
|
-
children: [/* @__PURE__ */ n(
|
|
747
|
+
children: [/* @__PURE__ */ n(h, {
|
|
746
748
|
sx: {
|
|
747
749
|
pr: 0.5,
|
|
748
750
|
borderRight: 1,
|
|
749
751
|
borderColor: "grey.400"
|
|
750
752
|
},
|
|
751
753
|
children: e
|
|
752
|
-
}), /* @__PURE__ */ n(
|
|
754
|
+
}), /* @__PURE__ */ n(h, {
|
|
753
755
|
sx: {
|
|
754
756
|
pl: 0.5
|
|
755
757
|
},
|
|
@@ -757,12 +759,12 @@ function We({
|
|
|
757
759
|
})]
|
|
758
760
|
});
|
|
759
761
|
}
|
|
760
|
-
function
|
|
762
|
+
function ut({
|
|
761
763
|
data: e,
|
|
762
764
|
api: t,
|
|
763
765
|
...s
|
|
764
766
|
}) {
|
|
765
|
-
const [l, o] = z(null), [r, i] = z(null), [a, u] = z(
|
|
767
|
+
const [l, o] = z(null), [r, i] = z(null), [a, u] = z(Z(e)), m = T(() => L(a), [a]), g = T(() => {
|
|
766
768
|
const c = (C, w) => C.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
|
|
767
769
|
return c(a);
|
|
768
770
|
}, [a]), x = (c) => {
|
|
@@ -806,18 +808,18 @@ function ht({
|
|
|
806
808
|
translation: JSON.stringify(S),
|
|
807
809
|
parentId: C == null ? void 0 : C.id
|
|
808
810
|
}), d(c)), o(null);
|
|
809
|
-
},
|
|
811
|
+
}, p = async () => {
|
|
810
812
|
!r || (await t.deleteLabel(r.id), f(r), i(null));
|
|
811
813
|
}, I = (c, C) => /* @__PURE__ */ v(P, {
|
|
812
|
-
children: [/* @__PURE__ */ v(
|
|
814
|
+
children: [/* @__PURE__ */ v(h, {
|
|
813
815
|
sx: {
|
|
814
816
|
display: "flex",
|
|
815
817
|
alignItems: "center",
|
|
816
818
|
flexWrap: "wrap"
|
|
817
819
|
},
|
|
818
|
-
children: [/* @__PURE__ */ n(
|
|
820
|
+
children: [/* @__PURE__ */ n(h, {
|
|
819
821
|
children: c
|
|
820
|
-
}), C.translation && /* @__PURE__ */ n(
|
|
822
|
+
}), C.translation && /* @__PURE__ */ n(h, {
|
|
821
823
|
sx: {
|
|
822
824
|
display: "flex",
|
|
823
825
|
alignItems: "center",
|
|
@@ -827,13 +829,13 @@ function ht({
|
|
|
827
829
|
children: Object.keys(C.translation).map((w) => {
|
|
828
830
|
var O;
|
|
829
831
|
const S = (O = C.translation) == null ? void 0 : O[w];
|
|
830
|
-
return S ? /* @__PURE__ */ n(
|
|
832
|
+
return S ? /* @__PURE__ */ n(De, {
|
|
831
833
|
locale: w,
|
|
832
834
|
value: S
|
|
833
835
|
}, w) : null;
|
|
834
836
|
})
|
|
835
837
|
})]
|
|
836
|
-
}), /* @__PURE__ */ v(
|
|
838
|
+
}), /* @__PURE__ */ v(h, {
|
|
837
839
|
sx: {
|
|
838
840
|
display: "flex",
|
|
839
841
|
gap: 1,
|
|
@@ -846,7 +848,7 @@ function ht({
|
|
|
846
848
|
color: "grey.500"
|
|
847
849
|
},
|
|
848
850
|
onClick: () => y(C),
|
|
849
|
-
children: /* @__PURE__ */ n(
|
|
851
|
+
children: /* @__PURE__ */ n(ie, {
|
|
850
852
|
sx: {
|
|
851
853
|
fontSize: 20
|
|
852
854
|
}
|
|
@@ -858,7 +860,7 @@ function ht({
|
|
|
858
860
|
color: "grey.500"
|
|
859
861
|
},
|
|
860
862
|
onClick: () => b(C),
|
|
861
|
-
children: /* @__PURE__ */ n(
|
|
863
|
+
children: /* @__PURE__ */ n(le, {
|
|
862
864
|
sx: {
|
|
863
865
|
fontSize: 18
|
|
864
866
|
}
|
|
@@ -870,7 +872,7 @@ function ht({
|
|
|
870
872
|
color: "grey.500"
|
|
871
873
|
},
|
|
872
874
|
onClick: () => i(C),
|
|
873
|
-
children: /* @__PURE__ */ n(
|
|
875
|
+
children: /* @__PURE__ */ n(oe, {
|
|
874
876
|
sx: {
|
|
875
877
|
fontSize: 20
|
|
876
878
|
}
|
|
@@ -878,19 +880,19 @@ function ht({
|
|
|
878
880
|
})]
|
|
879
881
|
})]
|
|
880
882
|
});
|
|
881
|
-
return /* @__PURE__ */ v(
|
|
883
|
+
return /* @__PURE__ */ v(h, {
|
|
882
884
|
...s,
|
|
883
|
-
children: [/* @__PURE__ */ v(
|
|
885
|
+
children: [/* @__PURE__ */ v(h, {
|
|
884
886
|
sx: {
|
|
885
887
|
display: "flex",
|
|
886
888
|
alignItems: "center",
|
|
887
889
|
justifyContent: "space-between"
|
|
888
890
|
},
|
|
889
|
-
children: [/* @__PURE__ */ n(
|
|
891
|
+
children: [/* @__PURE__ */ n(re, {
|
|
890
892
|
component: "h2",
|
|
891
893
|
variant: "h6",
|
|
892
894
|
children: "Manage labels"
|
|
893
|
-
}), /* @__PURE__ */ n(
|
|
895
|
+
}), /* @__PURE__ */ n(A, {
|
|
894
896
|
color: "primary",
|
|
895
897
|
variant: "contained",
|
|
896
898
|
size: "small",
|
|
@@ -900,7 +902,7 @@ function ht({
|
|
|
900
902
|
onClick: () => y(),
|
|
901
903
|
children: "New label"
|
|
902
904
|
})]
|
|
903
|
-
}), /* @__PURE__ */ v(
|
|
905
|
+
}), /* @__PURE__ */ v(h, {
|
|
904
906
|
sx: {
|
|
905
907
|
mt: 2,
|
|
906
908
|
border: 1,
|
|
@@ -908,7 +910,7 @@ function ht({
|
|
|
908
910
|
borderRadius: 1,
|
|
909
911
|
overflow: "hidden"
|
|
910
912
|
},
|
|
911
|
-
children: [/* @__PURE__ */ v(
|
|
913
|
+
children: [/* @__PURE__ */ v(h, {
|
|
912
914
|
sx: {
|
|
913
915
|
p: 2,
|
|
914
916
|
fontSize: 14,
|
|
@@ -916,45 +918,45 @@ function ht({
|
|
|
916
918
|
bgcolor: "grey.200"
|
|
917
919
|
},
|
|
918
920
|
children: [m.length, " labels"]
|
|
919
|
-
}), /* @__PURE__ */ n(
|
|
921
|
+
}), /* @__PURE__ */ n(h, {
|
|
920
922
|
sx: {
|
|
921
923
|
pt: 0.5
|
|
922
924
|
},
|
|
923
|
-
children: /* @__PURE__ */ n(
|
|
925
|
+
children: /* @__PURE__ */ n(je, {
|
|
924
926
|
data: g,
|
|
925
927
|
selected: [],
|
|
926
928
|
renderItem: I,
|
|
927
929
|
rowHeight: 64
|
|
928
930
|
})
|
|
929
931
|
})]
|
|
930
|
-
}), /* @__PURE__ */ n(
|
|
932
|
+
}), /* @__PURE__ */ n(Le, {
|
|
931
933
|
open: !!l,
|
|
932
934
|
onClose: () => o(null),
|
|
933
935
|
initialLabel: l,
|
|
934
936
|
onSubmit: M
|
|
935
|
-
}, l == null ? void 0 : l.id), /* @__PURE__ */ n(
|
|
937
|
+
}, l == null ? void 0 : l.id), /* @__PURE__ */ n(Me, {
|
|
936
938
|
open: !!r,
|
|
937
939
|
onClose: () => i(null),
|
|
938
940
|
label: r,
|
|
939
|
-
onSubmit:
|
|
941
|
+
onSubmit: p
|
|
940
942
|
}, r == null ? void 0 : r.id)]
|
|
941
943
|
});
|
|
942
944
|
}
|
|
943
|
-
const
|
|
945
|
+
const G = q({}), U = () => H(G), ht = () => {
|
|
944
946
|
const {
|
|
945
947
|
updateLabels: e
|
|
946
|
-
} =
|
|
948
|
+
} = U();
|
|
947
949
|
W(() => () => {
|
|
948
950
|
e();
|
|
949
951
|
}, []);
|
|
950
952
|
};
|
|
951
|
-
function
|
|
953
|
+
function pt({
|
|
952
954
|
fetchLabels: e,
|
|
953
955
|
children: t
|
|
954
956
|
}) {
|
|
955
957
|
const {
|
|
956
958
|
locale: s
|
|
957
|
-
} =
|
|
959
|
+
} = Q(), [l, o] = z({
|
|
958
960
|
loading: !0,
|
|
959
961
|
labels: [],
|
|
960
962
|
updateCounter: 1
|
|
@@ -970,7 +972,7 @@ function ft({
|
|
|
970
972
|
o((y) => ({
|
|
971
973
|
...y,
|
|
972
974
|
loading: !1,
|
|
973
|
-
labels:
|
|
975
|
+
labels: Ie(f)
|
|
974
976
|
}));
|
|
975
977
|
} catch (f) {
|
|
976
978
|
console.error(f), o((y) => ({
|
|
@@ -981,22 +983,22 @@ function ft({
|
|
|
981
983
|
}
|
|
982
984
|
})();
|
|
983
985
|
}, [l.updateCounter]);
|
|
984
|
-
const r =
|
|
986
|
+
const r = T(() => {
|
|
985
987
|
var f;
|
|
986
988
|
return (f = l.labels) != null && f.length ? L(l.labels).reduce((y, b) => ({
|
|
987
989
|
...y,
|
|
988
990
|
[b.id]: b
|
|
989
991
|
}), {}) : {};
|
|
990
|
-
}, [l.labels]), i =
|
|
992
|
+
}, [l.labels]), i = k((d) => {
|
|
991
993
|
var f;
|
|
992
994
|
return {
|
|
993
995
|
...d,
|
|
994
996
|
name: ((f = d.translation) == null ? void 0 : f[s]) || d.name
|
|
995
997
|
};
|
|
996
|
-
}, [s]), a =
|
|
998
|
+
}, [s]), a = k((d) => d.filter(Boolean).map((f) => r[f]).map(i), [r, i]), u = k((d) => (d == null ? void 0 : d.split(",")) || [], []), m = k((d = []) => {
|
|
997
999
|
if (!!(d != null && d.length))
|
|
998
1000
|
return d.join(",");
|
|
999
|
-
}, []), g =
|
|
1001
|
+
}, []), g = T(() => l.labels.map(i), [l.labels, i]), x = T(() => ({
|
|
1000
1002
|
loading: l.loading,
|
|
1001
1003
|
labels: l.labels || [],
|
|
1002
1004
|
updateLabels: () => o((d) => ({
|
|
@@ -1008,12 +1010,12 @@ function ft({
|
|
|
1008
1010
|
stringifyLabelIds: m,
|
|
1009
1011
|
localizedLabels: g
|
|
1010
1012
|
}), [l, a, u, m, g]);
|
|
1011
|
-
return /* @__PURE__ */ n(
|
|
1013
|
+
return /* @__PURE__ */ n(G.Provider, {
|
|
1012
1014
|
value: x,
|
|
1013
1015
|
children: t
|
|
1014
1016
|
});
|
|
1015
1017
|
}
|
|
1016
|
-
function
|
|
1018
|
+
function mt({
|
|
1017
1019
|
labels: e,
|
|
1018
1020
|
editable: t,
|
|
1019
1021
|
onChange: s,
|
|
@@ -1023,7 +1025,7 @@ function gt({
|
|
|
1023
1025
|
labels: r,
|
|
1024
1026
|
loading: i,
|
|
1025
1027
|
getLabelsById: a
|
|
1026
|
-
} =
|
|
1028
|
+
} = U(), [u, m] = z(!1);
|
|
1027
1029
|
if (i || !t && o)
|
|
1028
1030
|
return null;
|
|
1029
1031
|
const g = (f) => {
|
|
@@ -1032,10 +1034,10 @@ function gt({
|
|
|
1032
1034
|
}, 300);
|
|
1033
1035
|
};
|
|
1034
1036
|
if (u)
|
|
1035
|
-
return /* @__PURE__ */ n(
|
|
1037
|
+
return /* @__PURE__ */ n($, {
|
|
1036
1038
|
onClickAway: () => u && m(!1),
|
|
1037
1039
|
children: /* @__PURE__ */ n("div", {
|
|
1038
|
-
children: /* @__PURE__ */ n(
|
|
1040
|
+
children: /* @__PURE__ */ n(Ae, {
|
|
1039
1041
|
data: r,
|
|
1040
1042
|
value: e || [],
|
|
1041
1043
|
onChange: g
|
|
@@ -1048,9 +1050,9 @@ function gt({
|
|
|
1048
1050
|
alignItems: "center",
|
|
1049
1051
|
flexWrap: "wrap"
|
|
1050
1052
|
}, ...Array.isArray(l) ? l : [l]];
|
|
1051
|
-
return /* @__PURE__ */ v(
|
|
1053
|
+
return /* @__PURE__ */ v(h, {
|
|
1052
1054
|
sx: d,
|
|
1053
|
-
children: [x.map((f) => f ? /* @__PURE__ */ n(
|
|
1055
|
+
children: [x.map((f) => f ? /* @__PURE__ */ n(fe, {
|
|
1054
1056
|
label: f.name,
|
|
1055
1057
|
variant: "filled",
|
|
1056
1058
|
size: "small",
|
|
@@ -1064,12 +1066,12 @@ function gt({
|
|
|
1064
1066
|
sx: {
|
|
1065
1067
|
color: "grey.400"
|
|
1066
1068
|
},
|
|
1067
|
-
children: /* @__PURE__ */ n(
|
|
1069
|
+
children: /* @__PURE__ */ n(pe, {
|
|
1068
1070
|
sx: {
|
|
1069
1071
|
fontSize: 20
|
|
1070
1072
|
}
|
|
1071
1073
|
})
|
|
1072
|
-
}), t && o && /* @__PURE__ */ n(
|
|
1074
|
+
}), t && o && /* @__PURE__ */ n(A, {
|
|
1073
1075
|
color: "inherit",
|
|
1074
1076
|
variant: "outlined",
|
|
1075
1077
|
startIcon: /* @__PURE__ */ n(me, {}),
|
|
@@ -1079,12 +1081,12 @@ function gt({
|
|
|
1079
1081
|
});
|
|
1080
1082
|
}
|
|
1081
1083
|
export {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
+
ut as LabelManager,
|
|
1085
|
+
Ae as LabelPicker,
|
|
1084
1086
|
F as LabelTree,
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1087
|
+
mt as Labels,
|
|
1088
|
+
pt as LabelsProvider,
|
|
1089
|
+
Ie as transformLabels,
|
|
1090
|
+
U as useLabelsContext,
|
|
1091
|
+
ht as useLabelsUpdateOnDestroy
|
|
1090
1092
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/
|
|
1
|
+
(function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/material/ClickAwayListener"),require("react-color"),require("@arcblock/ux/lib/Dialog"),require("@mui/material"),require("@mui/icons-material/Translate"),require("@mui/material/Popover"),require("@arcblock/ux/lib/Locale/context"),require("@mui/material/Alert"),require("@mui/icons-material/Edit"),require("@mui/icons-material/LabelOutlined"),require("@mui/material/Chip")):typeof define=="function"&&define.amd?define(["exports","react","@mui/icons-material/ExpandMore","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","react/jsx-runtime","lodash/omit","react-select","@mui/material/Typography","@mui/material/Button","@mui/material/IconButton","@mui/icons-material/DeleteOutlineOutlined","@mui/icons-material/EditOutlined","@mui/icons-material/Add","@mui/material/TextField","@mui/material/ClickAwayListener","react-color","@arcblock/ux/lib/Dialog","@mui/material","@mui/icons-material/Translate","@mui/material/Popover","@arcblock/ux/lib/Locale/context","@mui/material/Alert","@mui/icons-material/Edit","@mui/icons-material/LabelOutlined","@mui/material/Chip"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.DiscussKitComponents={},i.React,i.ExpandMoreIcon,i.Box,i.styles,i.reactArborist,i.react$1,i.jsxRuntime,i.omit,i.Select,i.Typography,i.Button,i.IconButton,i.DeleteOutlineOutlinedIcon,i.EditOutlinedIcon,i.AddIcon,i.TextField,i.ClickAwayListener,i.reactColor,i.Dialog,i.material,i.TranslateIcon,i.Popover,i.context,i.Alert,i.EditIcon,i.LabelOutlinedIcon,i.Chip))})(this,function(i,u,U,Y,N,Z,G,e,X,E,R,ee,te,re,ne,le,oe,ae,se,ie,T,de,ce,F,ue,fe,he,pe){"use strict";const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},j=I(U),p=I(Y),ge=I(X),me=I(E),ye=I(R),k=I(ee),A=I(te),xe=I(re),Ce=I(ne),ve=I(le),P=I(oe),W=I(ae),V=I(ie),be=I(de),Se=I(ce),Ie=I(ue),we=I(fe),_e=I(he),Oe=I(pe),Te=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,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"})}),ke=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),H=u.createContext({});function qe({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:o}){const n=h=>r.indexOf(h)!==-1,a=h=>{Array.from(new Set(r).add(h)),s==null||s(h)},d=u.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:l}),[r]);return e.jsx(H.Provider,{value:d,children:o})}const Ae=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function ze({node:t}){return Ae(t)?e.jsx("span",{}):t.isOpen?e.jsx(j.default,{style:{fontSize:20}}):e.jsx(j.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Le({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=u.useContext(H),{data:d}=t,h=d.icon?e.jsx(G.Icon,{icon:d.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:d.color||"#ddd"}}),m=f=>{f.stopPropagation(),t.isInternal&&t.toggle()},x=f=>{f.stopPropagation(),l&&o(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(p.default,{sx:{display:"flex",cursor:"pointer"},onClick:m,children:e.jsx(ze,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:h}),e.jsx(p.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),l&&n(t.id)&&e.jsx(ke,{})]});return e.jsxs(p.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:s,onClick:x,children:[!a&&C,!!a&&a(C,t.data)]})}const Be=N.styled(p.default)`
|
|
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
|
|
14
|
+
`;function z({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:o=28,renderItem:n,sx:a,...d}){const h=u.useRef(),m=[...Array.isArray(a)?a:[a]],[x,C]=u.useState(0),f=u.useCallback(()=>{var v,S;C((((S=(v=h.current)==null?void 0:v.visibleNodes)==null?void 0:S.length)||0)*o)},[o]);u.useEffect(()=>{f()},[t,f]);const y=()=>{setTimeout(f)};return e.jsx(qe,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Be,{...d,sx:m,children:e.jsx(Z.Tree,{data:t,rowHeight:o,height:x,indent:32,ref:h,onToggle:y,children:Le})})})}const L=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...L(s.children)),r},[]),J=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=J(r.children)),r}),Ee=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},K=t=>{const r=t.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=t.map(({parentId:o,translation:n,...a})=>({...a,translation:Ee(n),children:[]})),l=s.reduce((o,n)=>({...o,[n.id]:n}),{});return s.forEach(o=>{const n=r[o.id];n.parent&&l[n.parent]&&(o.parent=l[n.parent]),n.children&&(o.children=n.children.map(a=>l[a]))}),s.filter(o=>!o.parent)},Pe=t=>{const{options:r,getValue:s,selectProps:l,selectOption:o}=t,n=s(),a=d=>{const h=r.find(m=>m.data.id===d);h&&o(h)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...ge.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(z,{data:l.data,selectable:!0,onSelect:a,selected:n.map(d=>d.data.id)})})}),t.addon]})},Me=({children:t,...r})=>{const[s,l]=t,o=Array.isArray(s)?s.length:0;return e.jsxs(E.components.ValueContainer,{...r,children:[e.jsx(p.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&e.jsx(p.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:o}),l]})},De={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function $({data:t,value:r=[],editable:s=!1,addon:l,onChange:o,compact:n,isMulti:a=!0,maxHeight:d=264,...h}){const m=u.useRef(null),x=u.useMemo(()=>L(t).map(g=>({data:g,label:g.name,value:g.id})),[t]),C=x.reduce((g,O)=>({...g,[O.data.id]:O}),{}),f=Array.isArray(r)?r:[r],y=f.map(g=>C[g]),v=u.useRef({prev:f.map(g=>{var O;return((O=C[g])==null?void 0:O.data)||""})}),S=(g,O)=>{!a||!Array.isArray(g)?o(g?[g.data]:[]):v.current.current=g.map(c=>c.data),["clear","remove-value"].includes(O.action)&&m.current&&setTimeout(()=>{var c;return(c=m==null?void 0:m.current)==null?void 0:c.blur()},1)},D=()=>{v.current.current&&JSON.stringify(v.current.prev.map(O=>O.id))!==JSON.stringify(v.current.current.map(O=>O.id))&&(o(v.current.current),v.current.prev=v.current.current)};return e.jsx(p.default,{...h,children:e.jsx(me.default,{ref:m,defaultValue:y,options:x,onChange:S,components:{MenuList:g=>e.jsx(Pe,{...g,addon:l}),...n&&{ValueContainer:Me}},placeholder:"Select labels",styles:{...n&&De,menu:g=>({...g,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:g=>({...g,overflowY:"auto",maxHeight:`${d}px`})},theme:g=>({...g,colors:{...g.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:a,closeMenuOnSelect:!a,onMenuClose:D,isClearable:!0,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,o=arguments.length;l<o;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},B.apply(this,arguments)};function Ne(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),o,n=[],a;try{for(;(r===void 0||r-- >0)&&!(o=l.next()).done;)n.push(o.value)}catch(d){a={error:d}}finally{try{o&&!o.done&&(s=l.return)&&s.call(l)}finally{if(a)throw a.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var Fe=function(t){return typeof t=="function"},je=function(t){var r=Ne(u.useState(t),2),s=r[0],l=r[1],o=u.useCallback(function(n){l(function(a){var d=Fe(n)?n(a):n;return d?B(B({},a),d):a})},[]);return[s,o]};const We=je;function Ve({I18NProps:t,...r}){const{languages:s}=F.useLocaleContext(),{translation:l,onChange:o}=t,[n,a]=u.useState(null),d=x=>{const C=x.currentTarget.closest(".MuiInputBase-root");C&&a(C)},h=()=>{a(null)},m=s.filter(x=>x.code!=="en");return e.jsx(T.TextField,{...r,InputProps:{endAdornment:e.jsxs(T.InputAdornment,{position:"end",children:[e.jsx(T.IconButton,{edge:"end",onClick:d,children:e.jsx(be.default,{})}),e.jsx(Se.default,{open:!!n,anchorEl:n,onClose:h,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(T.Box,{sx:{p:2},children:m.map(({code:x,name:C})=>e.jsxs(T.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(T.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(T.Box,{sx:{flex:1},children:e.jsx(T.TextField,{value:l[x]||"",size:"small",sx:{width:1},onChange:f=>o({...l,[x]:f.target.value})})})]},x))})})]})}})}function He({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,d]=We({name:(r==null?void 0:r.name)||"",color:(r==null?void 0:r.color)||"#ddd",slug:(r==null?void 0:r.id)||"",translation:(r==null?void 0:r.translation)||{}}),h=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),m=u.useMemo(()=>n?a.name&&a.color&&a.slug&&h(a.color):a.name&&a.color&&h(a.color),[a,n]),[x,C]=u.useState(!1),f=()=>{s({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},y=S=>{d({color:S.hex}),setTimeout(()=>C(!1))},v=S=>{d({color:S.target.value})};return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:f,disabled:!m,children:n?"Create":"Save Changes"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ve,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>d({name:S.target.value}),I18NProps:{translation:a.translation,onChange:S=>d({translation:S})}}),e.jsx(P.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>d({slug:S.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(P.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(W.default,{onClickAway:()=>C(!1),children:e.jsxs(p.default,{sx:{position:"relative",mt:2},children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(p.default,{sx:{width:30,height:30,bgcolor:a.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(P.default,{label:"",value:a.color,size:"small",onChange:v,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),x&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(se.GithubPicker,{color:a.color,onChangeComplete:y})})]})})]})})}function Je({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:s,children:"Delete"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ie.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(z,{data:[r]})]})})}const Ke=N.styled(z)`
|
|
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 $e({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function Qe({data:t,api:r,...s}){const[l,o]=u.useState(null),[n,a]=u.useState(null),[d,h]=u.useState(J(t)),m=u.useMemo(()=>L(d),[d]),x=u.useMemo(()=>{const c=(b,_)=>b.map(w=>(_&&(w.parent=_),w.children&&(w.children=c(w.children,w)),w));return c(d)},[d]),C=c=>{var b,_;c.parent?(c.parent.children=(_=(b=c.parent)==null?void 0:b.children)==null?void 0:_.map(w=>w.id===c.id?{...c}:w),C(c.parent)):h(d.map(w=>w.id===c.id?{...c}:w))},f=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),h([...d])):h([...d,c])},y=c=>{var b;c.parent?c.parent.children=(b=c.parent.children)==null?void 0:b.filter(_=>_.id!==c.id):h(d.filter(_=>_.id!==c.id))},v=c=>{if(l)return;o({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{l||o(c)},D=async c=>{if(!l)return;const{parent:b,children:_,translation:w,...q}=c;l.id?(await r.updateLabel({...q,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),C(c)):(await r.createLabel({...q,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),f(c)),o(null)},g=async()=>{!n||(await r.deleteLabel(n.id),y(n),a(null))},O=(c,b)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},children:[e.jsx(p.default,{children:c}),b.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},children:Object.keys(b.translation).map(_=>{var q;const w=(q=b.translation)==null?void 0:q[_];return w?e.jsx($e,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>v(b),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(b),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(b),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(ye.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>v(),children:"New label"})]}),e.jsxs(p.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(p.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},children:[m.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(Ke,{data:x,selected:[],renderItem:O,rowHeight:64})})]}),e.jsx(He,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:D},l==null?void 0:l.id),e.jsx(Je,{open:!!n,onClose:()=>a(null),label:n,onSubmit:g},n==null?void 0:n.id)]})}const Q=u.createContext({}),M=()=>u.useContext(Q),Ue=()=>{const{updateLabels:t}=M();u.useEffect(()=>()=>{t()},[])};function Ye({fetchLabels:t,children:r}){const{locale:s}=F.useLocaleContext(),[l,o]=u.useState({loading:!0,labels:[],updateCounter:1});u.useEffect(()=>{(async()=>{try{o(v=>({...v,loading:!0}));const y=await t();o(v=>({...v,loading:!1,labels:K(y)}))}catch(y){console.error(y),o(v=>({...v,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=u.useMemo(()=>{var y;return(y=l.labels)!=null&&y.length?L(l.labels).reduce((v,S)=>({...v,[S.id]:S}),{}):{}},[l.labels]),a=u.useCallback(f=>{var y;return{...f,name:((y=f.translation)==null?void 0:y[s])||f.name}},[s]),d=u.useCallback(f=>f.filter(Boolean).map(y=>n[y]).map(a),[n,a]),h=u.useCallback(f=>(f==null?void 0:f.split(","))||[],[]),m=u.useCallback((f=[])=>{if(!!(f!=null&&f.length))return f.join(",")},[]),x=u.useMemo(()=>l.labels.map(a),[l.labels,a]),C=u.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>o(f=>({...f,updateCounter:++l.updateCounter})),getLabelsById:d,parseLabelIds:h,stringifyLabelIds:m,localizedLabels:x}),[l,d,h,m,x]);return e.jsx(Q.Provider,{value:C,children:r})}function Ze({labels:t,editable:r,onChange:s,sx:l}){const o=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:d}=M(),[h,m]=u.useState(!1);if(a||!r&&o)return null;const x=y=>{s==null||s(y),setTimeout(()=>{m(!1)},300)};if(h)return e.jsx(W.default,{onClickAway:()=>h&&m(!1),children:e.jsx("div",{children:e.jsx($,{data:n,value:t||[],onChange:x})})});const C=d(t||[]),f=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:f,children:[C.map(y=>y?e.jsx(Oe.default,{label:y.name,variant:"filled",size:"small",sx:{borderRadius:1}},y.id):null),r&&!o&&e.jsx(A.default,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(we.default,{sx:{fontSize:20}})}),r&&o&&e.jsx(k.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(_e.default,{}),onClick:()=>m(!0),children:"Edit labels"})]})}i.LabelManager=Qe,i.LabelPicker=$,i.LabelTree=z,i.Labels=Ze,i.LabelsProvider=Ye,i.transformLabels=K,i.useLabelsContext=M,i.useLabelsUpdateOnDestroy=Ue,Object.defineProperties(i,{__esModule:{value:!0},[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.40",
|
|
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": "46867337b45cb831020815924af170e4c3f3329f"
|
|
79
79
|
}
|