@blocklet/labels 1.5.99 → 1.5.100
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/components/label/labels.d.ts +2 -1
- package/dist/index.es.js +259 -257
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ interface LabelsProps {
|
|
|
6
6
|
editable?: boolean;
|
|
7
7
|
onChange?: (labels: Label[]) => void;
|
|
8
8
|
sx?: SxProps;
|
|
9
|
+
renderLabel?: (label: Label) => JSX.Element;
|
|
9
10
|
}
|
|
10
|
-
export default function Labels({ labels, editable, onChange, sx }: LabelsProps): JSX.Element | null;
|
|
11
|
+
export default function Labels({ labels, editable, onChange, sx, renderLabel }: LabelsProps): JSX.Element | null;
|
|
11
12
|
export {};
|
package/dist/index.es.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
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
|
|
3
|
+
import p from "@mui/material/Box";
|
|
4
4
|
import { styled as J } from "@mui/material/styles";
|
|
5
5
|
import { Tree as X } from "react-arborist";
|
|
6
6
|
import { Icon as ee } from "@iconify/react";
|
|
7
|
-
import { jsx as n, jsxs as
|
|
7
|
+
import { jsx as n, jsxs as C, Fragment as P } from "react/jsx-runtime";
|
|
8
8
|
import te from "lodash/omit";
|
|
9
9
|
import ne, { components as _ } from "react-select";
|
|
10
10
|
import re from "@mui/material/Typography";
|
|
11
11
|
import A from "@mui/material/Button";
|
|
12
|
-
import
|
|
12
|
+
import E from "@mui/material/IconButton";
|
|
13
13
|
import oe from "@mui/icons-material/DeleteOutlineOutlined";
|
|
14
14
|
import le from "@mui/icons-material/EditOutlined";
|
|
15
15
|
import ie from "@mui/icons-material/Add";
|
|
@@ -17,7 +17,7 @@ import j from "@mui/material/TextField";
|
|
|
17
17
|
import $ from "@mui/material/ClickAwayListener";
|
|
18
18
|
import { GithubPicker as ae } from "react-color";
|
|
19
19
|
import K from "@arcblock/ux/lib/Dialog";
|
|
20
|
-
import { TextField as V, InputAdornment as se, IconButton as ce, Box as
|
|
20
|
+
import { TextField as V, InputAdornment as se, 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
23
|
import { useLocaleContext as Q } from "@arcblock/ux/lib/Locale/context";
|
|
@@ -48,24 +48,24 @@ function ye({
|
|
|
48
48
|
selectable: e = !1,
|
|
49
49
|
selected: t = [],
|
|
50
50
|
onSelect: a,
|
|
51
|
-
renderItem:
|
|
52
|
-
children:
|
|
51
|
+
renderItem: o,
|
|
52
|
+
children: l
|
|
53
53
|
}) {
|
|
54
|
-
const r = (
|
|
55
|
-
Array.from(new Set(t).add(
|
|
54
|
+
const r = (h) => t.indexOf(h) !== -1, i = (h) => {
|
|
55
|
+
Array.from(new Set(t).add(h)), a == null || a(h);
|
|
56
56
|
}, s = T(
|
|
57
57
|
() => ({
|
|
58
58
|
selectable: e,
|
|
59
59
|
selected: t,
|
|
60
60
|
isSelected: r,
|
|
61
61
|
select: i,
|
|
62
|
-
renderItem:
|
|
62
|
+
renderItem: o
|
|
63
63
|
}),
|
|
64
64
|
[t]
|
|
65
65
|
);
|
|
66
66
|
return /* @__PURE__ */ n(Y.Provider, {
|
|
67
67
|
value: s,
|
|
68
|
-
children:
|
|
68
|
+
children: l
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
const Ce = (e) => {
|
|
@@ -92,13 +92,13 @@ function be({
|
|
|
92
92
|
dragHandle: a
|
|
93
93
|
}) {
|
|
94
94
|
const {
|
|
95
|
-
selectable:
|
|
96
|
-
select:
|
|
95
|
+
selectable: o,
|
|
96
|
+
select: l,
|
|
97
97
|
isSelected: r,
|
|
98
98
|
renderItem: i
|
|
99
99
|
} = H(Y), {
|
|
100
100
|
data: s
|
|
101
|
-
} = e,
|
|
101
|
+
} = e, h = s.icon ? /* @__PURE__ */ n(ee, {
|
|
102
102
|
icon: s.icon,
|
|
103
103
|
style: {
|
|
104
104
|
fontSize: 18
|
|
@@ -108,44 +108,44 @@ function be({
|
|
|
108
108
|
fontSize: 18,
|
|
109
109
|
color: s.color || "#ddd"
|
|
110
110
|
}
|
|
111
|
-
}),
|
|
111
|
+
}), g = (d) => {
|
|
112
112
|
d.stopPropagation(), e.isInternal && e.toggle();
|
|
113
|
-
},
|
|
114
|
-
d.stopPropagation(),
|
|
115
|
-
}, x = /* @__PURE__ */
|
|
116
|
-
children: [/* @__PURE__ */
|
|
113
|
+
}, m = (d) => {
|
|
114
|
+
d.stopPropagation(), o && l(e.id);
|
|
115
|
+
}, x = /* @__PURE__ */ C(P, {
|
|
116
|
+
children: [/* @__PURE__ */ C(p, {
|
|
117
117
|
sx: {
|
|
118
118
|
display: "flex",
|
|
119
119
|
alignItems: "center",
|
|
120
120
|
flex: 1
|
|
121
121
|
},
|
|
122
|
-
children: [/* @__PURE__ */ n(
|
|
122
|
+
children: [/* @__PURE__ */ n(p, {
|
|
123
123
|
sx: {
|
|
124
124
|
display: "flex",
|
|
125
125
|
cursor: "pointer"
|
|
126
126
|
},
|
|
127
|
-
onClick:
|
|
127
|
+
onClick: g,
|
|
128
128
|
children: /* @__PURE__ */ n(ve, {
|
|
129
129
|
node: e
|
|
130
130
|
})
|
|
131
|
-
}), /* @__PURE__ */ n(
|
|
131
|
+
}), /* @__PURE__ */ n(p, {
|
|
132
132
|
sx: {
|
|
133
133
|
display: "flex",
|
|
134
134
|
alignItems: "center",
|
|
135
135
|
width: 22,
|
|
136
136
|
height: 22
|
|
137
137
|
},
|
|
138
|
-
children:
|
|
139
|
-
}), /* @__PURE__ */ n(
|
|
138
|
+
children: h
|
|
139
|
+
}), /* @__PURE__ */ n(p, {
|
|
140
140
|
component: "span",
|
|
141
141
|
sx: {
|
|
142
142
|
color: "grey.700"
|
|
143
143
|
},
|
|
144
144
|
children: e.data.name
|
|
145
145
|
})]
|
|
146
|
-
}),
|
|
146
|
+
}), o && r(e.id) && /* @__PURE__ */ n(xe, {})]
|
|
147
147
|
});
|
|
148
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ C(p, {
|
|
149
149
|
className: "label-tree-item",
|
|
150
150
|
style: t,
|
|
151
151
|
sx: {
|
|
@@ -154,11 +154,11 @@ function be({
|
|
|
154
154
|
justifyContent: "space-between"
|
|
155
155
|
},
|
|
156
156
|
ref: a,
|
|
157
|
-
onClick:
|
|
157
|
+
onClick: m,
|
|
158
158
|
children: [!i && x, !!i && i(x, e.data)]
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
const Se = J(
|
|
161
|
+
const Se = J(p)`
|
|
162
162
|
> div,
|
|
163
163
|
> div > div,
|
|
164
164
|
> div > div > div {
|
|
@@ -176,32 +176,32 @@ function F({
|
|
|
176
176
|
data: e,
|
|
177
177
|
selectable: t,
|
|
178
178
|
selected: a = [],
|
|
179
|
-
onSelect:
|
|
180
|
-
rowHeight:
|
|
179
|
+
onSelect: o,
|
|
180
|
+
rowHeight: l = 28,
|
|
181
181
|
renderItem: r,
|
|
182
182
|
sx: i,
|
|
183
183
|
...s
|
|
184
184
|
}) {
|
|
185
|
-
const
|
|
186
|
-
var
|
|
187
|
-
x((((
|
|
188
|
-
}, [
|
|
185
|
+
const h = D(), g = [...Array.isArray(i) ? i : [i]], [m, x] = z(0), d = k(() => {
|
|
186
|
+
var u, v;
|
|
187
|
+
x((((v = (u = h.current) == null ? void 0 : u.visibleNodes) == null ? void 0 : v.length) || 0) * l);
|
|
188
|
+
}, [l]);
|
|
189
189
|
return W(() => {
|
|
190
190
|
d();
|
|
191
191
|
}, [e, d]), /* @__PURE__ */ n(ye, {
|
|
192
192
|
selectable: t,
|
|
193
193
|
selected: a,
|
|
194
|
-
onSelect:
|
|
194
|
+
onSelect: o,
|
|
195
195
|
renderItem: r,
|
|
196
196
|
children: /* @__PURE__ */ n(Se, {
|
|
197
197
|
...s,
|
|
198
|
-
sx:
|
|
198
|
+
sx: g,
|
|
199
199
|
children: /* @__PURE__ */ n(X, {
|
|
200
200
|
data: e,
|
|
201
|
-
rowHeight:
|
|
202
|
-
height:
|
|
201
|
+
rowHeight: l,
|
|
202
|
+
height: m,
|
|
203
203
|
indent: 32,
|
|
204
|
-
ref:
|
|
204
|
+
ref: h,
|
|
205
205
|
onToggle: () => {
|
|
206
206
|
setTimeout(d);
|
|
207
207
|
},
|
|
@@ -210,9 +210,9 @@ function F({
|
|
|
210
210
|
})
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
var
|
|
215
|
-
return t.push(a), (
|
|
213
|
+
const O = (e) => e.reduce((t, a) => {
|
|
214
|
+
var o;
|
|
215
|
+
return t.push(a), (o = a.children) != null && o.length && t.push(...O(a.children)), t;
|
|
216
216
|
}, []), Z = (e) => e.map((t) => {
|
|
217
217
|
var a;
|
|
218
218
|
return (a = t.children) != null && a.length && (t.children = Z(t.children)), t;
|
|
@@ -223,35 +223,35 @@ const L = (e) => e.reduce((t, a) => {
|
|
|
223
223
|
return t;
|
|
224
224
|
}
|
|
225
225
|
}, Ie = (e) => {
|
|
226
|
-
const t = e.reduce((
|
|
226
|
+
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), {}), a = e.map(({ parentId: l, translation: r, ...i }) => ({
|
|
227
227
|
...i,
|
|
228
228
|
translation: we(r),
|
|
229
229
|
children: []
|
|
230
|
-
})),
|
|
231
|
-
return a.forEach((
|
|
232
|
-
const r = t[
|
|
233
|
-
r.parent &&
|
|
234
|
-
}), a.filter((
|
|
230
|
+
})), o = a.reduce((l, r) => ({ ...l, [r.id]: r }), {});
|
|
231
|
+
return a.forEach((l) => {
|
|
232
|
+
const r = t[l.id];
|
|
233
|
+
r.parent && o[r.parent] && (l.parent = o[r.parent]), r.children && (l.children = r.children.map((i) => o[i]));
|
|
234
|
+
}), a.filter((l) => !l.parent);
|
|
235
235
|
}, ze = (e) => {
|
|
236
236
|
const {
|
|
237
237
|
options: t,
|
|
238
238
|
getValue: a,
|
|
239
|
-
selectProps:
|
|
240
|
-
selectOption:
|
|
239
|
+
selectProps: o,
|
|
240
|
+
selectOption: l
|
|
241
241
|
} = e, r = a(), i = (s) => {
|
|
242
|
-
const
|
|
243
|
-
|
|
242
|
+
const h = t.find((g) => g.data.id === s);
|
|
243
|
+
h && l(h);
|
|
244
244
|
};
|
|
245
|
-
return /* @__PURE__ */
|
|
245
|
+
return /* @__PURE__ */ C(P, {
|
|
246
246
|
children: [/* @__PURE__ */ n(_.MenuList, {
|
|
247
247
|
...te(e, ["addon"]),
|
|
248
|
-
children: /* @__PURE__ */ n(
|
|
248
|
+
children: /* @__PURE__ */ n(p, {
|
|
249
249
|
sx: {
|
|
250
250
|
px: 2,
|
|
251
251
|
py: 1
|
|
252
252
|
},
|
|
253
253
|
children: /* @__PURE__ */ n(F, {
|
|
254
|
-
data:
|
|
254
|
+
data: o.data,
|
|
255
255
|
selectable: !0,
|
|
256
256
|
onSelect: i,
|
|
257
257
|
selected: r.map((s) => s.data.id)
|
|
@@ -263,17 +263,17 @@ const L = (e) => e.reduce((t, a) => {
|
|
|
263
263
|
children: e,
|
|
264
264
|
...t
|
|
265
265
|
}) => {
|
|
266
|
-
const [a,
|
|
267
|
-
return /* @__PURE__ */
|
|
266
|
+
const [a, o] = e, l = Array.isArray(a) ? a.length : 0;
|
|
267
|
+
return /* @__PURE__ */ C(_.ValueContainer, {
|
|
268
268
|
...t,
|
|
269
|
-
children: [/* @__PURE__ */ n(
|
|
269
|
+
children: [/* @__PURE__ */ n(p, {
|
|
270
270
|
component: "span",
|
|
271
271
|
sx: {
|
|
272
272
|
fontSize: 13,
|
|
273
273
|
fontWeight: "bold"
|
|
274
274
|
},
|
|
275
|
-
children:
|
|
276
|
-
}), !!
|
|
275
|
+
children: l ? "Labels" : "Filter by labels"
|
|
276
|
+
}), !!l && /* @__PURE__ */ n(p, {
|
|
277
277
|
sx: {
|
|
278
278
|
display: "inline-flex",
|
|
279
279
|
justifyContent: "center",
|
|
@@ -285,8 +285,8 @@ const L = (e) => e.reduce((t, a) => {
|
|
|
285
285
|
fontSize: 12,
|
|
286
286
|
bgcolor: "grey.200"
|
|
287
287
|
},
|
|
288
|
-
children:
|
|
289
|
-
}),
|
|
288
|
+
children: l
|
|
289
|
+
}), o]
|
|
290
290
|
});
|
|
291
291
|
}, ke = {
|
|
292
292
|
control: (e) => ({
|
|
@@ -310,44 +310,44 @@ function Ae({
|
|
|
310
310
|
data: e,
|
|
311
311
|
value: t = [],
|
|
312
312
|
editable: a = !1,
|
|
313
|
-
addon:
|
|
314
|
-
onChange:
|
|
313
|
+
addon: o,
|
|
314
|
+
onChange: l,
|
|
315
315
|
compact: r,
|
|
316
316
|
isMulti: i = !0,
|
|
317
317
|
maxHeight: s = 264,
|
|
318
|
-
...
|
|
318
|
+
...h
|
|
319
319
|
}) {
|
|
320
|
-
const
|
|
321
|
-
data:
|
|
322
|
-
label:
|
|
323
|
-
value:
|
|
324
|
-
})), [e]), x =
|
|
325
|
-
...
|
|
320
|
+
const g = D(null), m = T(() => O(e).map((f) => ({
|
|
321
|
+
data: f,
|
|
322
|
+
label: f.name,
|
|
323
|
+
value: f.id
|
|
324
|
+
})), [e]), x = m.reduce((f, I) => ({
|
|
325
|
+
...f,
|
|
326
326
|
[I.data.id]: I
|
|
327
|
-
}), {}), d = Array.isArray(t) ? t : [t],
|
|
328
|
-
prev: d.map((
|
|
327
|
+
}), {}), d = Array.isArray(t) ? t : [t], b = d.map((f) => x[f]), u = D({
|
|
328
|
+
prev: d.map((f) => {
|
|
329
329
|
var I;
|
|
330
|
-
return ((I = x[
|
|
330
|
+
return ((I = x[f]) == null ? void 0 : I.data) || "";
|
|
331
331
|
})
|
|
332
|
-
}),
|
|
333
|
-
!i || !Array.isArray(
|
|
332
|
+
}), v = (f, I) => {
|
|
333
|
+
!i || !Array.isArray(f) ? l(f ? [f.data] : []) : u.current.current = f.map((c) => c.data), ["clear", "remove-value"].includes(I.action) && g.current && setTimeout(() => {
|
|
334
334
|
var c;
|
|
335
|
-
return (c =
|
|
335
|
+
return (c = g == null ? void 0 : g.current) == null ? void 0 : c.blur();
|
|
336
336
|
}, 1);
|
|
337
337
|
}, M = () => {
|
|
338
|
-
|
|
338
|
+
u.current.current && JSON.stringify(u.current.prev.map((I) => I.id)) !== JSON.stringify(u.current.current.map((I) => I.id)) && (l(u.current.current), u.current.prev = u.current.current);
|
|
339
339
|
};
|
|
340
|
-
return /* @__PURE__ */ n(
|
|
341
|
-
...
|
|
340
|
+
return /* @__PURE__ */ n(p, {
|
|
341
|
+
...h,
|
|
342
342
|
children: /* @__PURE__ */ n(ne, {
|
|
343
|
-
ref:
|
|
344
|
-
defaultValue:
|
|
345
|
-
options:
|
|
346
|
-
onChange:
|
|
343
|
+
ref: g,
|
|
344
|
+
defaultValue: b,
|
|
345
|
+
options: m,
|
|
346
|
+
onChange: v,
|
|
347
347
|
components: {
|
|
348
|
-
MenuList: (
|
|
349
|
-
...
|
|
350
|
-
addon:
|
|
348
|
+
MenuList: (f) => /* @__PURE__ */ n(ze, {
|
|
349
|
+
...f,
|
|
350
|
+
addon: o
|
|
351
351
|
}),
|
|
352
352
|
...r && {
|
|
353
353
|
ValueContainer: Te
|
|
@@ -356,23 +356,23 @@ function Ae({
|
|
|
356
356
|
placeholder: "Select labels",
|
|
357
357
|
styles: {
|
|
358
358
|
...r && ke,
|
|
359
|
-
menu: (
|
|
360
|
-
...
|
|
359
|
+
menu: (f) => ({
|
|
360
|
+
...f,
|
|
361
361
|
...a && {
|
|
362
362
|
paddingBottom: "36px"
|
|
363
363
|
},
|
|
364
364
|
zIndex: 99
|
|
365
365
|
}),
|
|
366
|
-
menuList: (
|
|
367
|
-
...
|
|
366
|
+
menuList: (f) => ({
|
|
367
|
+
...f,
|
|
368
368
|
overflowY: "auto",
|
|
369
369
|
maxHeight: `${s}px`
|
|
370
370
|
})
|
|
371
371
|
},
|
|
372
|
-
theme: (
|
|
373
|
-
...
|
|
372
|
+
theme: (f) => ({
|
|
373
|
+
...f,
|
|
374
374
|
colors: {
|
|
375
|
-
...
|
|
375
|
+
...f.colors,
|
|
376
376
|
primary25: "#ddd",
|
|
377
377
|
primary50: "#ddd",
|
|
378
378
|
primary: "#ddd"
|
|
@@ -387,29 +387,29 @@ function Ae({
|
|
|
387
387
|
})
|
|
388
388
|
});
|
|
389
389
|
}
|
|
390
|
-
var
|
|
391
|
-
return
|
|
392
|
-
for (var a,
|
|
393
|
-
a = arguments[
|
|
390
|
+
var L = function() {
|
|
391
|
+
return L = Object.assign || function(t) {
|
|
392
|
+
for (var a, o = 1, l = arguments.length; o < l; o++) {
|
|
393
|
+
a = arguments[o];
|
|
394
394
|
for (var r in a)
|
|
395
395
|
Object.prototype.hasOwnProperty.call(a, r) && (t[r] = a[r]);
|
|
396
396
|
}
|
|
397
397
|
return t;
|
|
398
|
-
},
|
|
398
|
+
}, L.apply(this, arguments);
|
|
399
399
|
};
|
|
400
400
|
function Ne(e, t) {
|
|
401
401
|
var a = typeof Symbol == "function" && e[Symbol.iterator];
|
|
402
402
|
if (!a)
|
|
403
403
|
return e;
|
|
404
|
-
var
|
|
404
|
+
var o = a.call(e), l, r = [], i;
|
|
405
405
|
try {
|
|
406
|
-
for (; (t === void 0 || t-- > 0) && !(
|
|
407
|
-
r.push(
|
|
406
|
+
for (; (t === void 0 || t-- > 0) && !(l = o.next()).done; )
|
|
407
|
+
r.push(l.value);
|
|
408
408
|
} catch (s) {
|
|
409
409
|
i = { error: s };
|
|
410
410
|
} finally {
|
|
411
411
|
try {
|
|
412
|
-
|
|
412
|
+
l && !l.done && (a = o.return) && a.call(o);
|
|
413
413
|
} finally {
|
|
414
414
|
if (i)
|
|
415
415
|
throw i.error;
|
|
@@ -420,13 +420,13 @@ function Ne(e, t) {
|
|
|
420
420
|
var Oe = function(e) {
|
|
421
421
|
return typeof e == "function";
|
|
422
422
|
}, Pe = function(e) {
|
|
423
|
-
var t = Ne(z(e), 2), a = t[0],
|
|
424
|
-
|
|
423
|
+
var t = Ne(z(e), 2), a = t[0], o = t[1], l = k(function(r) {
|
|
424
|
+
o(function(i) {
|
|
425
425
|
var s = Oe(r) ? r(i) : r;
|
|
426
|
-
return s ?
|
|
426
|
+
return s ? L(L({}, i), s) : i;
|
|
427
427
|
});
|
|
428
428
|
}, []);
|
|
429
|
-
return [a,
|
|
429
|
+
return [a, l];
|
|
430
430
|
};
|
|
431
431
|
const Be = Pe;
|
|
432
432
|
function Ee({
|
|
@@ -436,18 +436,18 @@ function Ee({
|
|
|
436
436
|
const {
|
|
437
437
|
languages: a
|
|
438
438
|
} = Q(), {
|
|
439
|
-
translation:
|
|
440
|
-
onChange:
|
|
441
|
-
} = e, [r, i] = z(null), s = (
|
|
442
|
-
const x =
|
|
439
|
+
translation: o,
|
|
440
|
+
onChange: l
|
|
441
|
+
} = e, [r, i] = z(null), s = (m) => {
|
|
442
|
+
const x = m.currentTarget.closest(".MuiInputBase-root");
|
|
443
443
|
x && i(x);
|
|
444
|
-
},
|
|
444
|
+
}, h = () => {
|
|
445
445
|
i(null);
|
|
446
|
-
},
|
|
446
|
+
}, g = a.filter((m) => m.code !== "en");
|
|
447
447
|
return /* @__PURE__ */ n(V, {
|
|
448
448
|
...t,
|
|
449
449
|
InputProps: {
|
|
450
|
-
endAdornment: /* @__PURE__ */
|
|
450
|
+
endAdornment: /* @__PURE__ */ C(se, {
|
|
451
451
|
position: "end",
|
|
452
452
|
children: [/* @__PURE__ */ n(ce, {
|
|
453
453
|
edge: "end",
|
|
@@ -456,7 +456,7 @@ function Ee({
|
|
|
456
456
|
}), /* @__PURE__ */ n(ue, {
|
|
457
457
|
open: !!r,
|
|
458
458
|
anchorEl: r,
|
|
459
|
-
onClose:
|
|
459
|
+
onClose: h,
|
|
460
460
|
transformOrigin: {
|
|
461
461
|
vertical: "top",
|
|
462
462
|
horizontal: "right"
|
|
@@ -477,14 +477,14 @@ function Ee({
|
|
|
477
477
|
sx: {
|
|
478
478
|
mt: 2
|
|
479
479
|
},
|
|
480
|
-
children: /* @__PURE__ */ n(
|
|
480
|
+
children: /* @__PURE__ */ n(B, {
|
|
481
481
|
sx: {
|
|
482
482
|
p: 2
|
|
483
483
|
},
|
|
484
|
-
children:
|
|
485
|
-
code:
|
|
484
|
+
children: g.map(({
|
|
485
|
+
code: m,
|
|
486
486
|
name: x
|
|
487
|
-
}) => /* @__PURE__ */
|
|
487
|
+
}) => /* @__PURE__ */ C(B, {
|
|
488
488
|
sx: {
|
|
489
489
|
display: "flex",
|
|
490
490
|
alignItems: "center",
|
|
@@ -493,28 +493,28 @@ function Ee({
|
|
|
493
493
|
mt: 1
|
|
494
494
|
}
|
|
495
495
|
},
|
|
496
|
-
children: [/* @__PURE__ */ n(
|
|
496
|
+
children: [/* @__PURE__ */ n(B, {
|
|
497
497
|
sx: {
|
|
498
498
|
flex: "0 0 120px"
|
|
499
499
|
},
|
|
500
500
|
children: x
|
|
501
|
-
}), /* @__PURE__ */ n(
|
|
501
|
+
}), /* @__PURE__ */ n(B, {
|
|
502
502
|
sx: {
|
|
503
503
|
flex: 1
|
|
504
504
|
},
|
|
505
505
|
children: /* @__PURE__ */ n(V, {
|
|
506
|
-
value:
|
|
506
|
+
value: o[m] || "",
|
|
507
507
|
size: "small",
|
|
508
508
|
sx: {
|
|
509
509
|
width: 1
|
|
510
510
|
},
|
|
511
|
-
onChange: (d) =>
|
|
512
|
-
...
|
|
513
|
-
[
|
|
511
|
+
onChange: (d) => l({
|
|
512
|
+
...o,
|
|
513
|
+
[m]: d.target.value
|
|
514
514
|
})
|
|
515
515
|
})
|
|
516
516
|
})]
|
|
517
|
-
},
|
|
517
|
+
}, m))
|
|
518
518
|
})
|
|
519
519
|
})]
|
|
520
520
|
})
|
|
@@ -525,15 +525,15 @@ function Le({
|
|
|
525
525
|
open: e,
|
|
526
526
|
initialLabel: t,
|
|
527
527
|
onSubmit: a,
|
|
528
|
-
onClose:
|
|
529
|
-
...
|
|
528
|
+
onClose: o,
|
|
529
|
+
...l
|
|
530
530
|
}) {
|
|
531
531
|
const r = !(t != null && t.id), [i, s] = Be({
|
|
532
532
|
name: (t == null ? void 0 : t.name) || "",
|
|
533
533
|
color: (t == null ? void 0 : t.color) || "#ddd",
|
|
534
534
|
slug: (t == null ? void 0 : t.id) || "",
|
|
535
535
|
translation: (t == null ? void 0 : t.translation) || {}
|
|
536
|
-
}),
|
|
536
|
+
}), h = (v) => /^#([0-9A-F]{3}){1,2}$/i.test(v), g = T(() => r ? i.name && i.color && i.slug && h(i.color) : i.name && i.color && h(i.color), [i, r]), [m, x] = z(!1), d = () => {
|
|
537
537
|
a({
|
|
538
538
|
...t,
|
|
539
539
|
name: i.name,
|
|
@@ -541,13 +541,13 @@ function Le({
|
|
|
541
541
|
id: i.slug,
|
|
542
542
|
translation: i.translation
|
|
543
543
|
});
|
|
544
|
-
},
|
|
544
|
+
}, b = (v) => {
|
|
545
545
|
s({
|
|
546
|
-
color:
|
|
546
|
+
color: v.hex
|
|
547
547
|
}), setTimeout(() => x(!1));
|
|
548
|
-
},
|
|
548
|
+
}, u = (v) => {
|
|
549
549
|
s({
|
|
550
|
-
color:
|
|
550
|
+
color: v.target.value
|
|
551
551
|
});
|
|
552
552
|
};
|
|
553
553
|
return /* @__PURE__ */ n(K, {
|
|
@@ -555,25 +555,25 @@ function Le({
|
|
|
555
555
|
showCloseButton: !0,
|
|
556
556
|
maxWidth: "lg",
|
|
557
557
|
title: r ? "Create label" : "Edit label",
|
|
558
|
-
actions: /* @__PURE__ */
|
|
558
|
+
actions: /* @__PURE__ */ C(P, {
|
|
559
559
|
children: [/* @__PURE__ */ n(A, {
|
|
560
560
|
color: "inherit",
|
|
561
561
|
variant: "contained",
|
|
562
562
|
size: "small",
|
|
563
|
-
onClick:
|
|
563
|
+
onClick: o,
|
|
564
564
|
children: "Cancel"
|
|
565
565
|
}), /* @__PURE__ */ n(A, {
|
|
566
566
|
color: "primary",
|
|
567
567
|
variant: "contained",
|
|
568
568
|
size: "small",
|
|
569
569
|
onClick: d,
|
|
570
|
-
disabled: !
|
|
570
|
+
disabled: !g,
|
|
571
571
|
children: r ? "Create" : "Save Changes"
|
|
572
572
|
})]
|
|
573
573
|
}),
|
|
574
|
-
onClose:
|
|
575
|
-
...
|
|
576
|
-
children: /* @__PURE__ */
|
|
574
|
+
onClose: o,
|
|
575
|
+
...l,
|
|
576
|
+
children: /* @__PURE__ */ C(p, {
|
|
577
577
|
width: 600,
|
|
578
578
|
minHeight: 280,
|
|
579
579
|
children: [/* @__PURE__ */ n(Ee, {
|
|
@@ -582,13 +582,13 @@ function Le({
|
|
|
582
582
|
placeholder: "New label",
|
|
583
583
|
size: "small",
|
|
584
584
|
fullWidth: !0,
|
|
585
|
-
onChange: (
|
|
586
|
-
name:
|
|
585
|
+
onChange: (v) => s({
|
|
586
|
+
name: v.target.value
|
|
587
587
|
}),
|
|
588
588
|
I18NProps: {
|
|
589
589
|
translation: i.translation,
|
|
590
|
-
onChange: (
|
|
591
|
-
translation:
|
|
590
|
+
onChange: (v) => s({
|
|
591
|
+
translation: v
|
|
592
592
|
})
|
|
593
593
|
}
|
|
594
594
|
}), /* @__PURE__ */ n(j, {
|
|
@@ -597,8 +597,8 @@ function Le({
|
|
|
597
597
|
size: "small",
|
|
598
598
|
fullWidth: !0,
|
|
599
599
|
disabled: !r,
|
|
600
|
-
onChange: (
|
|
601
|
-
slug:
|
|
600
|
+
onChange: (v) => s({
|
|
601
|
+
slug: v.target.value
|
|
602
602
|
}),
|
|
603
603
|
sx: {
|
|
604
604
|
mt: 2
|
|
@@ -614,18 +614,18 @@ function Le({
|
|
|
614
614
|
}
|
|
615
615
|
}), /* @__PURE__ */ n($, {
|
|
616
616
|
onClickAway: () => x(!1),
|
|
617
|
-
children: /* @__PURE__ */
|
|
617
|
+
children: /* @__PURE__ */ C(p, {
|
|
618
618
|
sx: {
|
|
619
619
|
position: "relative",
|
|
620
620
|
mt: 2
|
|
621
621
|
},
|
|
622
|
-
children: [/* @__PURE__ */
|
|
622
|
+
children: [/* @__PURE__ */ C(p, {
|
|
623
623
|
sx: {
|
|
624
624
|
display: "flex",
|
|
625
625
|
alignItems: "center",
|
|
626
626
|
gap: 1
|
|
627
627
|
},
|
|
628
|
-
children: [/* @__PURE__ */ n(
|
|
628
|
+
children: [/* @__PURE__ */ n(p, {
|
|
629
629
|
sx: {
|
|
630
630
|
width: 30,
|
|
631
631
|
height: 30,
|
|
@@ -637,7 +637,7 @@ function Le({
|
|
|
637
637
|
label: "",
|
|
638
638
|
value: i.color,
|
|
639
639
|
size: "small",
|
|
640
|
-
onChange:
|
|
640
|
+
onChange: u,
|
|
641
641
|
inputProps: {
|
|
642
642
|
maxLength: 7
|
|
643
643
|
},
|
|
@@ -648,7 +648,7 @@ function Le({
|
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
})]
|
|
651
|
-
}),
|
|
651
|
+
}), m && /* @__PURE__ */ n(p, {
|
|
652
652
|
sx: {
|
|
653
653
|
position: "absolute",
|
|
654
654
|
top: 48,
|
|
@@ -656,7 +656,7 @@ function Le({
|
|
|
656
656
|
},
|
|
657
657
|
children: /* @__PURE__ */ n(ae, {
|
|
658
658
|
color: i.color,
|
|
659
|
-
onChangeComplete:
|
|
659
|
+
onChangeComplete: b
|
|
660
660
|
})
|
|
661
661
|
})]
|
|
662
662
|
})
|
|
@@ -668,20 +668,20 @@ function Me({
|
|
|
668
668
|
open: e,
|
|
669
669
|
label: t,
|
|
670
670
|
onSubmit: a,
|
|
671
|
-
onClose:
|
|
672
|
-
...
|
|
671
|
+
onClose: o,
|
|
672
|
+
...l
|
|
673
673
|
}) {
|
|
674
674
|
return /* @__PURE__ */ n(K, {
|
|
675
675
|
open: e,
|
|
676
676
|
showCloseButton: !0,
|
|
677
677
|
maxWidth: "md",
|
|
678
678
|
title: "Delete",
|
|
679
|
-
actions: /* @__PURE__ */
|
|
679
|
+
actions: /* @__PURE__ */ C(P, {
|
|
680
680
|
children: [/* @__PURE__ */ n(A, {
|
|
681
681
|
color: "inherit",
|
|
682
682
|
variant: "contained",
|
|
683
683
|
size: "small",
|
|
684
|
-
onClick:
|
|
684
|
+
onClick: o,
|
|
685
685
|
children: "Cancel"
|
|
686
686
|
}), /* @__PURE__ */ n(A, {
|
|
687
687
|
color: "primary",
|
|
@@ -691,9 +691,9 @@ function Me({
|
|
|
691
691
|
children: "Delete"
|
|
692
692
|
})]
|
|
693
693
|
}),
|
|
694
|
-
onClose:
|
|
695
|
-
...
|
|
696
|
-
children: /* @__PURE__ */
|
|
694
|
+
onClose: o,
|
|
695
|
+
...l,
|
|
696
|
+
children: /* @__PURE__ */ C(p, {
|
|
697
697
|
width: 600,
|
|
698
698
|
minHeight: 280,
|
|
699
699
|
children: [/* @__PURE__ */ n(he, {
|
|
@@ -733,7 +733,7 @@ function De({
|
|
|
733
733
|
locale: e,
|
|
734
734
|
value: t
|
|
735
735
|
}) {
|
|
736
|
-
return /* @__PURE__ */
|
|
736
|
+
return /* @__PURE__ */ C(p, {
|
|
737
737
|
sx: {
|
|
738
738
|
display: "flex",
|
|
739
739
|
alignItems: "center",
|
|
@@ -745,14 +745,14 @@ function De({
|
|
|
745
745
|
borderRadius: 2
|
|
746
746
|
},
|
|
747
747
|
className: "label-translation-tag",
|
|
748
|
-
children: [/* @__PURE__ */ n(
|
|
748
|
+
children: [/* @__PURE__ */ n(p, {
|
|
749
749
|
sx: {
|
|
750
750
|
pr: 0.5,
|
|
751
751
|
borderRight: 1,
|
|
752
752
|
borderColor: "grey.400"
|
|
753
753
|
},
|
|
754
754
|
children: e
|
|
755
|
-
}), /* @__PURE__ */ n(
|
|
755
|
+
}), /* @__PURE__ */ n(p, {
|
|
756
756
|
sx: {
|
|
757
757
|
pl: 0.5
|
|
758
758
|
},
|
|
@@ -765,63 +765,63 @@ function ut({
|
|
|
765
765
|
api: t,
|
|
766
766
|
...a
|
|
767
767
|
}) {
|
|
768
|
-
const [
|
|
769
|
-
const c = (
|
|
768
|
+
const [o, l] = z(null), [r, i] = z(null), [s, h] = z(Z(e)), g = T(() => O(s), [s]), m = T(() => {
|
|
769
|
+
const c = (y, w) => y.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
|
|
770
770
|
return c(s);
|
|
771
771
|
}, [s]), x = (c) => {
|
|
772
|
-
var
|
|
773
|
-
c.parent ? (c.parent.children = (w = (
|
|
772
|
+
var y, w;
|
|
773
|
+
c.parent ? (c.parent.children = (w = (y = c.parent) == null ? void 0 : y.children) == null ? void 0 : w.map((S) => S.id === c.id ? {
|
|
774
774
|
...c
|
|
775
|
-
} : S), x(c.parent)) :
|
|
775
|
+
} : S), x(c.parent)) : h(s.map((S) => S.id === c.id ? {
|
|
776
776
|
...c
|
|
777
777
|
} : S));
|
|
778
778
|
}, d = (c) => {
|
|
779
|
-
c.parent ? (c.parent.children = c.parent.children || [], c.parent.children.push(c),
|
|
780
|
-
},
|
|
781
|
-
var
|
|
782
|
-
c.parent ? c.parent.children = (
|
|
783
|
-
},
|
|
784
|
-
if (
|
|
779
|
+
c.parent ? (c.parent.children = c.parent.children || [], c.parent.children.push(c), h([...s])) : h([...s, c]);
|
|
780
|
+
}, b = (c) => {
|
|
781
|
+
var y;
|
|
782
|
+
c.parent ? c.parent.children = (y = c.parent.children) == null ? void 0 : y.filter((w) => w.id !== c.id) : h(s.filter((w) => w.id !== c.id));
|
|
783
|
+
}, u = (c) => {
|
|
784
|
+
if (o)
|
|
785
785
|
return;
|
|
786
|
-
|
|
786
|
+
l({
|
|
787
787
|
id: "",
|
|
788
788
|
name: "New label",
|
|
789
789
|
parent: c,
|
|
790
790
|
color: "#dddddd"
|
|
791
791
|
});
|
|
792
|
-
},
|
|
793
|
-
|
|
792
|
+
}, v = (c) => {
|
|
793
|
+
o || l(c);
|
|
794
794
|
}, M = async (c) => {
|
|
795
|
-
if (!
|
|
795
|
+
if (!o)
|
|
796
796
|
return;
|
|
797
797
|
const {
|
|
798
|
-
parent:
|
|
798
|
+
parent: y,
|
|
799
799
|
children: w,
|
|
800
800
|
translation: S,
|
|
801
801
|
...N
|
|
802
802
|
} = c;
|
|
803
|
-
|
|
803
|
+
o.id ? (await t.updateLabel({
|
|
804
804
|
...N,
|
|
805
805
|
translation: JSON.stringify(S),
|
|
806
|
-
parentId:
|
|
806
|
+
parentId: y == null ? void 0 : y.id
|
|
807
807
|
}), x(c)) : (await t.createLabel({
|
|
808
808
|
...N,
|
|
809
809
|
translation: JSON.stringify(S),
|
|
810
|
-
parentId:
|
|
811
|
-
}), d(c)),
|
|
812
|
-
},
|
|
813
|
-
!r || (await t.deleteLabel(r.id),
|
|
814
|
-
}, I = (c,
|
|
815
|
-
children: [/* @__PURE__ */
|
|
810
|
+
parentId: y == null ? void 0 : y.id
|
|
811
|
+
}), d(c)), l(null);
|
|
812
|
+
}, f = async () => {
|
|
813
|
+
!r || (await t.deleteLabel(r.id), b(r), i(null));
|
|
814
|
+
}, I = (c, y) => /* @__PURE__ */ C(P, {
|
|
815
|
+
children: [/* @__PURE__ */ C(p, {
|
|
816
816
|
sx: {
|
|
817
817
|
display: "flex",
|
|
818
818
|
alignItems: "center",
|
|
819
819
|
flexWrap: "wrap"
|
|
820
820
|
},
|
|
821
821
|
className: "label-name",
|
|
822
|
-
children: [/* @__PURE__ */ n(
|
|
822
|
+
children: [/* @__PURE__ */ n(p, {
|
|
823
823
|
children: c
|
|
824
|
-
}),
|
|
824
|
+
}), y.translation && /* @__PURE__ */ n(p, {
|
|
825
825
|
sx: {
|
|
826
826
|
display: "flex",
|
|
827
827
|
alignItems: "center",
|
|
@@ -829,53 +829,53 @@ function ut({
|
|
|
829
829
|
ml: 2
|
|
830
830
|
},
|
|
831
831
|
className: "label-translation",
|
|
832
|
-
children: Object.keys(
|
|
832
|
+
children: Object.keys(y.translation).map((w) => {
|
|
833
833
|
var N;
|
|
834
|
-
const S = (N =
|
|
834
|
+
const S = (N = y.translation) == null ? void 0 : N[w];
|
|
835
835
|
return S ? /* @__PURE__ */ n(De, {
|
|
836
836
|
locale: w,
|
|
837
837
|
value: S
|
|
838
838
|
}, w) : null;
|
|
839
839
|
})
|
|
840
840
|
})]
|
|
841
|
-
}), /* @__PURE__ */
|
|
841
|
+
}), /* @__PURE__ */ C(p, {
|
|
842
842
|
sx: {
|
|
843
843
|
display: "flex",
|
|
844
844
|
gap: 1,
|
|
845
845
|
flex: "0 0 auto"
|
|
846
846
|
},
|
|
847
847
|
className: "label-action",
|
|
848
|
-
children: [/* @__PURE__ */ n(
|
|
848
|
+
children: [/* @__PURE__ */ n(E, {
|
|
849
849
|
color: "inherit",
|
|
850
850
|
size: "small",
|
|
851
851
|
sx: {
|
|
852
852
|
color: "grey.500"
|
|
853
853
|
},
|
|
854
|
-
onClick: () => y
|
|
854
|
+
onClick: () => u(y),
|
|
855
855
|
children: /* @__PURE__ */ n(ie, {
|
|
856
856
|
sx: {
|
|
857
857
|
fontSize: 20
|
|
858
858
|
}
|
|
859
859
|
})
|
|
860
|
-
}), /* @__PURE__ */ n(
|
|
860
|
+
}), /* @__PURE__ */ n(E, {
|
|
861
861
|
color: "inherit",
|
|
862
862
|
size: "small",
|
|
863
863
|
sx: {
|
|
864
864
|
color: "grey.500"
|
|
865
865
|
},
|
|
866
|
-
onClick: () =>
|
|
866
|
+
onClick: () => v(y),
|
|
867
867
|
children: /* @__PURE__ */ n(le, {
|
|
868
868
|
sx: {
|
|
869
869
|
fontSize: 18
|
|
870
870
|
}
|
|
871
871
|
})
|
|
872
|
-
}), /* @__PURE__ */ n(
|
|
872
|
+
}), /* @__PURE__ */ n(E, {
|
|
873
873
|
color: "inherit",
|
|
874
874
|
size: "small",
|
|
875
875
|
sx: {
|
|
876
876
|
color: "grey.500"
|
|
877
877
|
},
|
|
878
|
-
onClick: () => i(
|
|
878
|
+
onClick: () => i(y),
|
|
879
879
|
children: /* @__PURE__ */ n(oe, {
|
|
880
880
|
sx: {
|
|
881
881
|
fontSize: 20
|
|
@@ -884,10 +884,10 @@ function ut({
|
|
|
884
884
|
})]
|
|
885
885
|
})]
|
|
886
886
|
});
|
|
887
|
-
return /* @__PURE__ */
|
|
887
|
+
return /* @__PURE__ */ C(p, {
|
|
888
888
|
...a,
|
|
889
889
|
className: "label-container",
|
|
890
|
-
children: [/* @__PURE__ */
|
|
890
|
+
children: [/* @__PURE__ */ C(p, {
|
|
891
891
|
sx: {
|
|
892
892
|
display: "flex",
|
|
893
893
|
alignItems: "center",
|
|
@@ -904,10 +904,10 @@ function ut({
|
|
|
904
904
|
sx: {
|
|
905
905
|
textTransform: "none"
|
|
906
906
|
},
|
|
907
|
-
onClick: () =>
|
|
907
|
+
onClick: () => u(),
|
|
908
908
|
children: "New label"
|
|
909
909
|
})]
|
|
910
|
-
}), /* @__PURE__ */
|
|
910
|
+
}), /* @__PURE__ */ C(p, {
|
|
911
911
|
sx: {
|
|
912
912
|
mt: 2,
|
|
913
913
|
border: 1,
|
|
@@ -915,7 +915,7 @@ function ut({
|
|
|
915
915
|
borderRadius: 1,
|
|
916
916
|
overflow: "hidden"
|
|
917
917
|
},
|
|
918
|
-
children: [/* @__PURE__ */
|
|
918
|
+
children: [/* @__PURE__ */ C(p, {
|
|
919
919
|
sx: {
|
|
920
920
|
p: 2,
|
|
921
921
|
fontSize: 14,
|
|
@@ -923,28 +923,28 @@ function ut({
|
|
|
923
923
|
bgcolor: "grey.200"
|
|
924
924
|
},
|
|
925
925
|
className: "label-header",
|
|
926
|
-
children: [
|
|
927
|
-
}), /* @__PURE__ */ n(
|
|
926
|
+
children: [g.length, " labels"]
|
|
927
|
+
}), /* @__PURE__ */ n(p, {
|
|
928
928
|
sx: {
|
|
929
929
|
pt: 0.5
|
|
930
930
|
},
|
|
931
931
|
children: /* @__PURE__ */ n(je, {
|
|
932
|
-
data:
|
|
932
|
+
data: m,
|
|
933
933
|
selected: [],
|
|
934
934
|
renderItem: I,
|
|
935
935
|
rowHeight: 64
|
|
936
936
|
})
|
|
937
937
|
})]
|
|
938
938
|
}), /* @__PURE__ */ n(Le, {
|
|
939
|
-
open: !!
|
|
940
|
-
onClose: () =>
|
|
941
|
-
initialLabel:
|
|
939
|
+
open: !!o,
|
|
940
|
+
onClose: () => l(null),
|
|
941
|
+
initialLabel: o,
|
|
942
942
|
onSubmit: M
|
|
943
|
-
},
|
|
943
|
+
}, o == null ? void 0 : o.id), /* @__PURE__ */ n(Me, {
|
|
944
944
|
open: !!r,
|
|
945
945
|
onClose: () => i(null),
|
|
946
946
|
label: r,
|
|
947
|
-
onSubmit:
|
|
947
|
+
onSubmit: f
|
|
948
948
|
}, r == null ? void 0 : r.id)]
|
|
949
949
|
});
|
|
950
950
|
}
|
|
@@ -962,7 +962,7 @@ function pt({
|
|
|
962
962
|
}) {
|
|
963
963
|
const {
|
|
964
964
|
locale: a
|
|
965
|
-
} = Q(), [
|
|
965
|
+
} = Q(), [o, l] = z({
|
|
966
966
|
loading: !0,
|
|
967
967
|
labels: [],
|
|
968
968
|
updateCounter: 1
|
|
@@ -970,52 +970,53 @@ function pt({
|
|
|
970
970
|
W(() => {
|
|
971
971
|
(async () => {
|
|
972
972
|
try {
|
|
973
|
-
|
|
974
|
-
...
|
|
973
|
+
l((u) => ({
|
|
974
|
+
...u,
|
|
975
975
|
loading: !0
|
|
976
976
|
}));
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
...
|
|
977
|
+
const b = await e();
|
|
978
|
+
l((u) => ({
|
|
979
|
+
...u,
|
|
980
980
|
loading: !1,
|
|
981
|
-
labels: Ie(
|
|
981
|
+
labels: Ie(b)
|
|
982
982
|
}));
|
|
983
|
-
} catch (
|
|
984
|
-
console.error(
|
|
985
|
-
...
|
|
983
|
+
} catch (b) {
|
|
984
|
+
console.error(b), l((u) => ({
|
|
985
|
+
...u,
|
|
986
986
|
loading: !1,
|
|
987
987
|
labels: []
|
|
988
988
|
}));
|
|
989
989
|
}
|
|
990
990
|
})();
|
|
991
|
-
}, [
|
|
991
|
+
}, [o.updateCounter]);
|
|
992
992
|
const r = T(() => {
|
|
993
|
-
var
|
|
994
|
-
return (
|
|
995
|
-
...
|
|
996
|
-
[
|
|
993
|
+
var b;
|
|
994
|
+
return (b = o.labels) != null && b.length ? O(o.labels).reduce((u, v) => ({
|
|
995
|
+
...u,
|
|
996
|
+
[v.id]: v
|
|
997
997
|
}), {}) : {};
|
|
998
|
-
}, [
|
|
999
|
-
var
|
|
998
|
+
}, [o.labels]), i = k((d) => {
|
|
999
|
+
var b;
|
|
1000
1000
|
return {
|
|
1001
1001
|
...d,
|
|
1002
|
-
name: ((
|
|
1002
|
+
name: ((b = d.translation) == null ? void 0 : b[a]) || d.name
|
|
1003
1003
|
};
|
|
1004
|
-
}, [a]), s = k((d) => d.filter(Boolean).map((
|
|
1004
|
+
}, [a]), s = k((d) => d.filter(Boolean).map((b) => r[b]).map(i), [r, i]), h = k((d) => (d == null ? void 0 : d.split(",")) || [], []), g = k((d = []) => {
|
|
1005
1005
|
if (!!(d != null && d.length))
|
|
1006
1006
|
return d.join(",");
|
|
1007
|
-
}, []),
|
|
1008
|
-
loading:
|
|
1009
|
-
labels:
|
|
1010
|
-
updateLabels: () =>
|
|
1007
|
+
}, []), m = T(() => o.labels.map(i), [o.labels, i]), x = T(() => ({
|
|
1008
|
+
loading: o.loading,
|
|
1009
|
+
labels: o.labels || [],
|
|
1010
|
+
updateLabels: () => l((d) => ({
|
|
1011
1011
|
...d,
|
|
1012
|
-
updateCounter: ++
|
|
1012
|
+
updateCounter: ++o.updateCounter
|
|
1013
1013
|
})),
|
|
1014
1014
|
getLabelsById: s,
|
|
1015
|
-
parseLabelIds:
|
|
1016
|
-
stringifyLabelIds:
|
|
1017
|
-
localizedLabels:
|
|
1018
|
-
|
|
1015
|
+
parseLabelIds: h,
|
|
1016
|
+
stringifyLabelIds: g,
|
|
1017
|
+
localizedLabels: m,
|
|
1018
|
+
flattenedLabels: O(m || [])
|
|
1019
|
+
}), [o, s, h, g, m]);
|
|
1019
1020
|
return /* @__PURE__ */ n(G.Provider, {
|
|
1020
1021
|
value: x,
|
|
1021
1022
|
children: t
|
|
@@ -1025,47 +1026,48 @@ function mt({
|
|
|
1025
1026
|
labels: e,
|
|
1026
1027
|
editable: t,
|
|
1027
1028
|
onChange: a,
|
|
1028
|
-
sx:
|
|
1029
|
+
sx: o,
|
|
1030
|
+
renderLabel: l
|
|
1029
1031
|
}) {
|
|
1030
|
-
const
|
|
1031
|
-
labels:
|
|
1032
|
-
loading:
|
|
1033
|
-
getLabelsById:
|
|
1034
|
-
} = U(), [
|
|
1035
|
-
if (
|
|
1032
|
+
const r = !(e != null && e.length), {
|
|
1033
|
+
labels: i,
|
|
1034
|
+
loading: s,
|
|
1035
|
+
getLabelsById: h
|
|
1036
|
+
} = U(), [g, m] = z(!1);
|
|
1037
|
+
if (s || !t && r)
|
|
1036
1038
|
return null;
|
|
1037
|
-
const
|
|
1038
|
-
a == null || a(
|
|
1039
|
+
const x = (u) => {
|
|
1040
|
+
a == null || a(u), setTimeout(() => {
|
|
1039
1041
|
m(!1);
|
|
1040
1042
|
}, 300);
|
|
1041
1043
|
};
|
|
1042
|
-
if (
|
|
1044
|
+
if (g)
|
|
1043
1045
|
return /* @__PURE__ */ n($, {
|
|
1044
|
-
onClickAway: () =>
|
|
1046
|
+
onClickAway: () => g && m(!1),
|
|
1045
1047
|
children: /* @__PURE__ */ n("div", {
|
|
1046
1048
|
children: /* @__PURE__ */ n(Ae, {
|
|
1047
|
-
data:
|
|
1049
|
+
data: i,
|
|
1048
1050
|
value: e || [],
|
|
1049
|
-
onChange:
|
|
1051
|
+
onChange: x
|
|
1050
1052
|
})
|
|
1051
1053
|
})
|
|
1052
1054
|
});
|
|
1053
|
-
const
|
|
1055
|
+
const d = h(e || []), b = [{
|
|
1054
1056
|
display: "flex",
|
|
1055
1057
|
gap: 1,
|
|
1056
1058
|
alignItems: "center",
|
|
1057
1059
|
flexWrap: "wrap"
|
|
1058
|
-
}, ...Array.isArray(
|
|
1059
|
-
return /* @__PURE__ */
|
|
1060
|
-
sx:
|
|
1061
|
-
children: [
|
|
1062
|
-
label:
|
|
1060
|
+
}, ...Array.isArray(o) ? o : [o]];
|
|
1061
|
+
return /* @__PURE__ */ C(p, {
|
|
1062
|
+
sx: b,
|
|
1063
|
+
children: [d.map((u) => u ? l ? l(u) : /* @__PURE__ */ n(fe, {
|
|
1064
|
+
label: u.name,
|
|
1063
1065
|
variant: "filled",
|
|
1064
1066
|
size: "small",
|
|
1065
1067
|
sx: {
|
|
1066
1068
|
borderRadius: 1
|
|
1067
1069
|
}
|
|
1068
|
-
},
|
|
1070
|
+
}, u.id) : null), t && !r && /* @__PURE__ */ n(E, {
|
|
1069
1071
|
color: "inherit",
|
|
1070
1072
|
size: "small",
|
|
1071
1073
|
onClick: () => m(!0),
|
|
@@ -1077,7 +1079,7 @@ function mt({
|
|
|
1077
1079
|
fontSize: 20
|
|
1078
1080
|
}
|
|
1079
1081
|
})
|
|
1080
|
-
}), t &&
|
|
1082
|
+
}), t && r && /* @__PURE__ */ n(A, {
|
|
1081
1083
|
color: "inherit",
|
|
1082
1084
|
variant: "outlined",
|
|
1083
1085
|
startIcon: /* @__PURE__ */ n(me, {}),
|
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/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,D,Z,G,e,X,E,R,ee,te,re,ne,le,ae,oe,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),me=I(X),ge=I(E),ye=I(R),k=I(ee),
|
|
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,D,Z,G,e,X,E,R,ee,te,re,ne,le,ae,oe,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),me=I(X),ge=I(E),ye=I(R),k=I(ee),z=I(te),xe=I(re),Ce=I(ne),ve=I(le),P=I(ae),W=I(oe),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:a}){const n=m=>r.indexOf(m)!==-1,o=m=>{Array.from(new Set(r).add(m)),s==null||s(m)},d=u.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:o,renderItem:l}),[r]);return e.jsx(H.Provider,{value:d,children:a})}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:a,isSelected:n,renderItem:o}=u.useContext(H),{data:d}=t,m=d.icon?e.jsx(G.Icon,{icon:d.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:d.color||"#ddd"}}),x=f=>{f.stopPropagation(),t.isInternal&&t.toggle()},g=f=>{f.stopPropagation(),l&&a(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:x,children:e.jsx(ze,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:m}),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:g,children:[!o&&C,!!o&&o(C,t.data)]})}const Be=D.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 L({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:a=28,renderItem:n,sx:o,...d}){const m=u.useRef(),x=[...Array.isArray(o)?o:[o]],[g,C]=u.useState(0),f=u.useCallback(()=>{var h,S;C((((S=(h=m.current)==null?void 0:h.visibleNodes)==null?void 0:S.length)||0)*a)},[a]);u.useEffect(()=>{f()},[t,f]);const b=()=>{setTimeout(f)};return e.jsx(qe,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Be,{...d,sx:x,children:e.jsx(Z.Tree,{data:t,rowHeight:a,height:g,indent:32,ref:m,onToggle:b,children:Le})})})}const q=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...q(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((a,n)=>(a[n.id]=a[n.id]||{},n.parentId&&(a[n.id].parent=n.parentId,a[n.parentId]=a[n.parentId]||{},a[n.parentId].children=a[n.parentId].children||[],a[n.parentId].children.push(n.id)),a),{}),s=t.map(({parentId:a,translation:n,...o})=>({...o,translation:Ee(n),children:[]})),l=s.reduce((a,n)=>({...a,[n.id]:n}),{});return s.forEach(a=>{const n=r[a.id];n.parent&&l[n.parent]&&(a.parent=l[n.parent]),n.children&&(a.children=n.children.map(o=>l[o]))}),s.filter(a=>!a.parent)},Pe=t=>{const{options:r,getValue:s,selectProps:l,selectOption:a}=t,n=s(),o=d=>{const m=r.find(x=>x.data.id===d);m&&a(m)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...me.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(L,{data:l.data,selectable:!0,onSelect:o,selected:n.map(d=>d.data.id)})})}),t.addon]})},Me=({children:t,...r})=>{const[s,l]=t,a=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:a?"Labels":"Filter by labels"}),!!a&&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:a}),l]})},Ne={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:a,compact:n,isMulti:o=!0,maxHeight:d=264,...m}){const x=u.useRef(null),g=u.useMemo(()=>q(t).map(y=>({data:y,label:y.name,value:y.id})),[t]),C=g.reduce((y,O)=>({...y,[O.data.id]:O}),{}),f=Array.isArray(r)?r:[r],b=f.map(y=>C[y]),h=u.useRef({prev:f.map(y=>{var O;return((O=C[y])==null?void 0:O.data)||""})}),S=(y,O)=>{!o||!Array.isArray(y)?a(y?[y.data]:[]):h.current.current=y.map(c=>c.data),["clear","remove-value"].includes(O.action)&&x.current&&setTimeout(()=>{var c;return(c=x==null?void 0:x.current)==null?void 0:c.blur()},1)},N=()=>{h.current.current&&JSON.stringify(h.current.prev.map(O=>O.id))!==JSON.stringify(h.current.current.map(O=>O.id))&&(a(h.current.current),h.current.prev=h.current.current)};return e.jsx(p.default,{...m,children:e.jsx(ge.default,{ref:x,defaultValue:b,options:g,onChange:S,components:{MenuList:y=>e.jsx(Pe,{...y,addon:l}),...n&&{ValueContainer:Me}},placeholder:"Select labels",styles:{...n&&Ne,menu:y=>({...y,...s&&{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:N,isClearable:!0,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,a=arguments.length;l<a;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 De(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),a,n=[],o;try{for(;(r===void 0||r-- >0)&&!(a=l.next()).done;)n.push(a.value)}catch(d){o={error:d}}finally{try{a&&!a.done&&(s=l.return)&&s.call(l)}finally{if(o)throw o.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var Fe=function(t){return typeof t=="function"},je=function(t){var r=De(u.useState(t),2),s=r[0],l=r[1],a=u.useCallback(function(n){l(function(o){var d=Fe(n)?n(o):n;return d?B(B({},o),d):o})},[]);return[s,a]};const We=je;function Ve({I18NProps:t,...r}){const{languages:s}=F.useLocaleContext(),{translation:l,onChange:a}=t,[n,o]=u.useState(null),d=g=>{const C=g.currentTarget.closest(".MuiInputBase-root");C&&o(C)},m=()=>{o(null)},x=s.filter(g=>g.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:m,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:x.map(({code:g,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[g]||"",size:"small",sx:{width:1},onChange:f=>a({...l,[g]:f.target.value})})})]},g))})})]})}})}function He({open:t,initialLabel:r,onSubmit:s,onClose:l,...a}){const n=!(r!=null&&r.id),[o,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)||{}}),m=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),x=u.useMemo(()=>n?o.name&&o.color&&o.slug&&m(o.color):o.name&&o.color&&m(o.color),[o,n]),[g,C]=u.useState(!1),f=()=>{s({...r,name:o.name,color:o.color,id:o.slug,translation:o.translation})},b=S=>{d({color:S.hex}),setTimeout(()=>C(!1))},h=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:!x,children:n?"Create":"Save Changes"})]}),onClose:l,...a,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ve,{label:"Name",value:o.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>d({name:S.target.value}),I18NProps:{translation:o.translation,onChange:S=>d({translation:S})}}),e.jsx(P.default,{label:"Slug",value:o.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:o.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(P.default,{label:"",value:o.color,size:"small",onChange:h,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),g&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(se.GithubPicker,{color:o.color,onChangeComplete:b})})]})})]})})}function Je({open:t,label:r,onSubmit:s,onClose:l,...a}){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,...a,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(L,{data:[r]})]})})}const Ke=D.styled(L)`
|
|
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 $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},className:"label-translation-tag",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,a]=u.useState(null),[n,o]=u.useState(null),[d,
|
|
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},className:"label-translation-tag",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,a]=u.useState(null),[n,o]=u.useState(null),[d,m]=u.useState(J(t)),x=u.useMemo(()=>q(d),[d]),g=u.useMemo(()=>{const c=(v,_)=>v.map(w=>(_&&(w.parent=_),w.children&&(w.children=c(w.children,w)),w));return c(d)},[d]),C=c=>{var v,_;c.parent?(c.parent.children=(_=(v=c.parent)==null?void 0:v.children)==null?void 0:_.map(w=>w.id===c.id?{...c}:w),C(c.parent)):m(d.map(w=>w.id===c.id?{...c}:w))},f=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),m([...d])):m([...d,c])},b=c=>{var v;c.parent?c.parent.children=(v=c.parent.children)==null?void 0:v.filter(_=>_.id!==c.id):m(d.filter(_=>_.id!==c.id))},h=c=>{if(l)return;a({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{l||a(c)},N=async c=>{if(!l)return;const{parent:v,children:_,translation:w,...A}=c;l.id?(await r.updateLabel({...A,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),C(c)):(await r.createLabel({...A,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),f(c)),a(null)},y=async()=>{!n||(await r.deleteLabel(n.id),b(n),o(null))},O=(c,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(p.default,{children:c}),v.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(v.translation).map(_=>{var A;const w=(A=v.translation)==null?void 0:A[_];return w?e.jsx($e,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>h(v),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>o(v),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,className:"label-container",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:()=>h(),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"},className:"label-header",children:[x.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(Ke,{data:g,selected:[],renderItem:O,rowHeight:64})})]}),e.jsx(He,{open:!!l,onClose:()=>a(null),initialLabel:l,onSubmit:N},l==null?void 0:l.id),e.jsx(Je,{open:!!n,onClose:()=>o(null),label:n,onSubmit:y},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,a]=u.useState({loading:!0,labels:[],updateCounter:1});u.useEffect(()=>{(async()=>{try{a(h=>({...h,loading:!0}));const b=await t();a(h=>({...h,loading:!1,labels:K(b)}))}catch(b){console.error(b),a(h=>({...h,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=u.useMemo(()=>{var b;return(b=l.labels)!=null&&b.length?q(l.labels).reduce((h,S)=>({...h,[S.id]:S}),{}):{}},[l.labels]),o=u.useCallback(f=>{var b;return{...f,name:((b=f.translation)==null?void 0:b[s])||f.name}},[s]),d=u.useCallback(f=>f.filter(Boolean).map(b=>n[b]).map(o),[n,o]),m=u.useCallback(f=>(f==null?void 0:f.split(","))||[],[]),x=u.useCallback((f=[])=>{if(!!(f!=null&&f.length))return f.join(",")},[]),g=u.useMemo(()=>l.labels.map(o),[l.labels,o]),C=u.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>a(f=>({...f,updateCounter:++l.updateCounter})),getLabelsById:d,parseLabelIds:m,stringifyLabelIds:x,localizedLabels:g,flattenedLabels:q(g||[])}),[l,d,m,x,g]);return e.jsx(Q.Provider,{value:C,children:r})}function Ze({labels:t,editable:r,onChange:s,sx:l,renderLabel:a}){const n=!(t!=null&&t.length),{labels:o,loading:d,getLabelsById:m}=M(),[x,g]=u.useState(!1);if(d||!r&&n)return null;const C=h=>{s==null||s(h),setTimeout(()=>{g(!1)},300)};if(x)return e.jsx(W.default,{onClickAway:()=>x&&g(!1),children:e.jsx("div",{children:e.jsx($,{data:o,value:t||[],onChange:C})})});const f=m(t||[]),b=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:b,children:[f.map(h=>h?a?a(h):e.jsx(Oe.default,{label:h.name,variant:"filled",size:"small",sx:{borderRadius:1}},h.id):null),r&&!n&&e.jsx(z.default,{color:"inherit",size:"small",onClick:()=>g(!0),sx:{color:"grey.400"},children:e.jsx(we.default,{sx:{fontSize:20}})}),r&&n&&e.jsx(k.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(_e.default,{}),onClick:()=>g(!0),children:"Edit labels"})]})}i.LabelManager=Qe,i.LabelPicker=$,i.LabelTree=L,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.100",
|
|
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": "d065b10ea680de3e2ee1323eb87a62d0dae70bd4"
|
|
79
79
|
}
|