@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 CHANGED
@@ -1,32 +1,31 @@
1
- import { createContext as q, useRef as D, useState as z, useCallback as A, useEffect as W, useMemo as k, useContext as $ } from "react";
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 p from "@mui/material/Box";
4
- import { styled as H } from "@mui/material/styles";
5
- import { Tree as U } from "react-arborist";
6
- import { Icon as X } from "@iconify/react";
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 ee from "lodash/omit";
9
- import te, { components as J } from "react-select";
10
- import ne from "@mui/material/Typography";
11
- import T from "@mui/material/Button";
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 re from "@mui/icons-material/DeleteOutlineOutlined";
14
- import oe from "@mui/icons-material/EditOutlined";
15
- import le from "@mui/icons-material/Add";
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 ie from "@mui/base/ClickAwayListener";
17
+ import $ from "@mui/material/ClickAwayListener";
18
18
  import { GithubPicker as se } from "react-color";
19
- import _ from "@arcblock/ux/lib/Dialog";
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 K } from "@arcblock/ux/lib/Locale/context";
24
- import pe from "@mui/material/Alert";
25
- import he from "@mui/icons-material/Edit";
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/ClickAwayListener";
28
- import ge from "@mui/material/Chip";
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
- }), ye = (e) => /* @__PURE__ */ n("svg", {
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
- }), Q = q({});
48
- function Ce({
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 = k(
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(Q.Provider, {
66
+ return /* @__PURE__ */ n(Y.Provider, {
68
67
  value: a,
69
68
  children: o
70
69
  });
71
70
  }
72
- const ve = (e) => {
71
+ const Ce = (e) => {
73
72
  var t;
74
73
  return e.isLeaf || !((t = e.data.children) != null && t.length);
75
74
  };
76
- function be({
75
+ function ve({
77
76
  node: e
78
77
  }) {
79
- return ve(e) ? /* @__PURE__ */ n("span", {}) : e.isOpen ? /* @__PURE__ */ n(R, {
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 Se({
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
- } = $(Q), {
99
+ } = H(Y), {
101
100
  data: a
102
- } = e, u = a.icon ? /* @__PURE__ */ n(X, {
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(xe, {
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(p, {
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(p, {
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(be, {
128
+ children: /* @__PURE__ */ n(ve, {
130
129
  node: e
131
130
  })
132
- }), /* @__PURE__ */ n(p, {
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(p, {
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(ye, {})]
146
+ }), l && r(e.id) && /* @__PURE__ */ n(xe, {})]
148
147
  });
149
- return /* @__PURE__ */ v(p, {
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 we = H(p)`
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 = A(() => {
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(Ce, {
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(we, {
196
+ children: /* @__PURE__ */ n(Se, {
198
197
  ...a,
199
198
  sx: m,
200
- children: /* @__PURE__ */ n(U, {
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: Se
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
- }, []), Y = (e) => e.map((t) => {
216
+ }, []), Z = (e) => e.map((t) => {
218
217
  var s;
219
- return (s = t.children) != null && s.length && (t.children = Y(t.children)), t;
220
- }), Ie = (e, t = null) => {
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
- }, ze = (e) => {
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: Ie(r),
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
- }, ke = (e) => {
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(J.MenuList, {
248
- ...ee(e, ["addon"]),
249
- children: /* @__PURE__ */ n(p, {
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
- }, Ae = ({
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(J.ValueContainer, {
267
+ return /* @__PURE__ */ v(_.ValueContainer, {
269
268
  ...t,
270
- children: [/* @__PURE__ */ n(p, {
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(p, {
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
- }, Te = {
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 Oe({
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 = k(() => L(e).map((h) => ({
322
- data: h,
323
- label: h.name,
324
- value: h.id
325
- })), [e]), x = g.reduce((h, I) => ({
326
- ...h,
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((h) => x[h]), y = D({
329
- prev: d.map((h) => x[h].data)
330
- }), b = (h, I) => {
331
- !i || !Array.isArray(h) ? o(h ? [h.data] : []) : y.current.current = h.map((c) => c.data), ["clear", "remove-value"].includes(I.action) && m.current && setTimeout(() => {
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(p, {
340
+ return /* @__PURE__ */ n(h, {
339
341
  ...u,
340
- children: /* @__PURE__ */ n(te, {
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: (h) => /* @__PURE__ */ n(ke, {
347
- ...h,
348
+ MenuList: (p) => /* @__PURE__ */ n(ze, {
349
+ ...p,
348
350
  addon: l
349
351
  }),
350
352
  ...r && {
351
- ValueContainer: Ae
353
+ ValueContainer: Te
352
354
  }
353
355
  },
354
356
  placeholder: "Select labels",
355
357
  styles: {
356
- ...r && Te,
357
- menu: (h) => ({
358
- ...h,
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: (h) => ({
365
- ...h,
366
+ menuList: (p) => ({
367
+ ...p,
366
368
  overflowY: "auto",
367
369
  maxHeight: `${a}px`
368
370
  })
369
371
  },
370
- theme: (h) => ({
371
- ...h,
372
+ theme: (p) => ({
373
+ ...p,
372
374
  colors: {
373
- ...h.colors,
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 Pe(e, t) {
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 Be = function(e) {
420
+ var Pe = function(e) {
419
421
  return typeof e == "function";
420
- }, Ne = function(e) {
421
- var t = Pe(z(e), 2), s = t[0], l = t[1], o = A(function(r) {
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 = Be(r) ? r(i) : r;
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 Ee = Ne;
430
- function Le({
431
+ const Ne = Be;
432
+ function Ee({
431
433
  I18NProps: e,
432
434
  ...t
433
435
  }) {
434
436
  const {
435
437
  languages: s
436
- } = K(), {
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 Me({
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] = Ee({
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 = k(() => r ? i.name && i.color && i.slug && u(i.color) : i.name && i.color && u(i.color), [i, r]), [g, x] = z(!1), d = () => {
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(T, {
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(T, {
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(p, {
576
+ children: /* @__PURE__ */ v(h, {
575
577
  width: 600,
576
578
  minHeight: 280,
577
- children: [/* @__PURE__ */ n(Le, {
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(ie, {
615
+ }), /* @__PURE__ */ n($, {
614
616
  onClickAway: () => x(!1),
615
- children: /* @__PURE__ */ v(p, {
617
+ children: /* @__PURE__ */ v(h, {
616
618
  sx: {
617
619
  position: "relative",
618
620
  mt: 2
619
621
  },
620
- children: [/* @__PURE__ */ v(p, {
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(p, {
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(p, {
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 je({
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(T, {
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(T, {
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(p, {
696
+ children: /* @__PURE__ */ v(h, {
695
697
  width: 600,
696
698
  minHeight: 280,
697
- children: [/* @__PURE__ */ n(pe, {
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 De = H(F)`
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 We({
732
+ function De({
731
733
  locale: e,
732
734
  value: t
733
735
  }) {
734
- return /* @__PURE__ */ v(p, {
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(p, {
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(p, {
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 ht({
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(Y(e)), m = k(() => L(a), [a]), g = k(() => {
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
- }, h = async () => {
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(p, {
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(p, {
820
+ children: [/* @__PURE__ */ n(h, {
819
821
  children: c
820
- }), C.translation && /* @__PURE__ */ n(p, {
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(We, {
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(p, {
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(le, {
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(oe, {
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(re, {
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(p, {
883
+ return /* @__PURE__ */ v(h, {
882
884
  ...s,
883
- children: [/* @__PURE__ */ v(p, {
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(ne, {
891
+ children: [/* @__PURE__ */ n(re, {
890
892
  component: "h2",
891
893
  variant: "h6",
892
894
  children: "Manage labels"
893
- }), /* @__PURE__ */ n(T, {
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(p, {
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(p, {
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(p, {
921
+ }), /* @__PURE__ */ n(h, {
920
922
  sx: {
921
923
  pt: 0.5
922
924
  },
923
- children: /* @__PURE__ */ n(De, {
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(Me, {
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(je, {
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: h
941
+ onSubmit: p
940
942
  }, r == null ? void 0 : r.id)]
941
943
  });
942
944
  }
943
- const Z = q({}), G = () => $(Z), mt = () => {
945
+ const G = q({}), U = () => H(G), ht = () => {
944
946
  const {
945
947
  updateLabels: e
946
- } = G();
948
+ } = U();
947
949
  W(() => () => {
948
950
  e();
949
951
  }, []);
950
952
  };
951
- function ft({
953
+ function pt({
952
954
  fetchLabels: e,
953
955
  children: t
954
956
  }) {
955
957
  const {
956
958
  locale: s
957
- } = K(), [l, o] = z({
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: ze(f)
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 = k(() => {
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 = A((d) => {
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 = A((d) => d.filter(Boolean).map((f) => r[f]).map(i), [r, i]), u = A((d) => (d == null ? void 0 : d.split(",")) || [], []), m = A((d = []) => {
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 = k(() => l.labels.map(i), [l.labels, i]), x = k(() => ({
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(Z.Provider, {
1013
+ return /* @__PURE__ */ n(G.Provider, {
1012
1014
  value: x,
1013
1015
  children: t
1014
1016
  });
1015
1017
  }
1016
- function gt({
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
- } = G(), [u, m] = z(!1);
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(fe, {
1037
+ return /* @__PURE__ */ n($, {
1036
1038
  onClickAway: () => u && m(!1),
1037
1039
  children: /* @__PURE__ */ n("div", {
1038
- children: /* @__PURE__ */ n(Oe, {
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(p, {
1053
+ return /* @__PURE__ */ v(h, {
1052
1054
  sx: d,
1053
- children: [x.map((f) => f ? /* @__PURE__ */ n(ge, {
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(he, {
1069
+ children: /* @__PURE__ */ n(pe, {
1068
1070
  sx: {
1069
1071
  fontSize: 20
1070
1072
  }
1071
1073
  })
1072
- }), t && o && /* @__PURE__ */ n(T, {
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
- ht as LabelManager,
1083
- Oe as LabelPicker,
1084
+ ut as LabelManager,
1085
+ Ae as LabelPicker,
1084
1086
  F as LabelTree,
1085
- gt as Labels,
1086
- ft as LabelsProvider,
1087
- ze as transformLabels,
1088
- G as useLabelsContext,
1089
- mt as useLabelsUpdateOnDestroy
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/base/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/ClickAwayListener"),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/base/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/ClickAwayListener","@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.ClickAwayListener$1,i.Chip))})(this,function(i,u,Q,U,N,Y,Z,e,G,E,X,R,ee,te,re,ne,le,oe,ae,se,A,ie,de,F,ce,ue,fe,he,pe){"use strict";const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},j=I(Q),p=I(U),ge=I(G),me=I(E),ye=I(X),O=I(R),L=I(ee),xe=I(te),Ce=I(re),ve=I(ne),P=I(le),be=I(oe),W=I(se),Se=I(ie),Ie=I(de),we=I(ce),_e=I(ue),ke=I(fe),Ae=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"})}),Le=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"})}),V=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(V.Provider,{value:d,children:o})}const ze=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function Be({node:t}){return ze(t)?e.jsx("span",{}):t.isOpen?e.jsx(j.default,{style:{fontSize:20}}):e.jsx(j.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Ee({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=u.useContext(V),{data:d}=t,h=d.icon?e.jsx(Z.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(Be,{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(Le,{})]});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 Pe=N.styled(p.default)`
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 q({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(Pe,{...d,sx:m,children:e.jsx(Y.Tree,{data:t,rowHeight:o,height:x,indent:32,ref:h,onToggle:y,children:Ee})})})}const z=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...z(s.children)),r},[]),H=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=H(r.children)),r}),Me=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},J=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:Me(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)},De=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(q,{data:l.data,selectable:!0,onSelect:a,selected:n.map(d=>d.data.id)})})}),t.addon]})},Ne=({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]})},Fe={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(()=>z(t).map(g=>({data:g,label:g.name,value:g.id})),[t]),C=x.reduce((g,k)=>({...g,[k.data.id]:k}),{}),f=Array.isArray(r)?r:[r],y=f.map(g=>C[g]),v=u.useRef({prev:f.map(g=>C[g].data)}),S=(g,k)=>{!a||!Array.isArray(g)?o(g?[g.data]:[]):v.current.current=g.map(c=>c.data),["clear","remove-value"].includes(k.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(k=>k.id))!==JSON.stringify(v.current.current.map(k=>k.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(De,{...g,addon:l}),...n&&{ValueContainer:Ne}},placeholder:"Select labels",styles:{...n&&Fe,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 je(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 We=function(t){return typeof t=="function"},Ve=function(t){var r=je(u.useState(t),2),s=r[0],l=r[1],o=u.useCallback(function(n){l(function(a){var d=We(n)?n(a):n;return d?B(B({},a),d):a})},[]);return[s,o]};const He=Ve;function Je({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(A.TextField,{...r,InputProps:{endAdornment:e.jsxs(A.InputAdornment,{position:"end",children:[e.jsx(A.IconButton,{edge:"end",onClick:d,children:e.jsx(Se.default,{})}),e.jsx(Ie.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(A.Box,{sx:{p:2},children:m.map(({code:x,name:C})=>e.jsxs(A.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(A.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(A.Box,{sx:{flex:1},children:e.jsx(A.TextField,{value:l[x]||"",size:"small",sx:{width:1},onChange:f=>o({...l,[x]:f.target.value})})})]},x))})})]})}})}function $e({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,d]=He({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(W.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.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(Je,{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(be.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(ae.GithubPicker,{color:a.color,onChangeComplete:y})})]})})]})})}function Ke({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(W.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.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(we.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(q,{data:[r]})]})})}const Qe=N.styled(q)`
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 Ue({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 Ye({data:t,api:r,...s}){const[l,o]=u.useState(null),[n,a]=u.useState(null),[d,h]=u.useState(H(t)),m=u.useMemo(()=>z(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,...T}=c;l.id?(await r.updateLabel({...T,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),C(c)):(await r.createLabel({...T,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))},k=(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 T;const w=(T=b.translation)==null?void 0:T[_];return w?e.jsx(Ue,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>v(b),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(b),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(L.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(O.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(Qe,{data:x,selected:[],renderItem:k,rowHeight:64})})]}),e.jsx($e,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:D},l==null?void 0:l.id),e.jsx(Ke,{open:!!n,onClose:()=>a(null),label:n,onSubmit:g},n==null?void 0:n.id)]})}const K=u.createContext({}),M=()=>u.useContext(K),Ze=()=>{const{updateLabels:t}=M();u.useEffect(()=>()=>{t()},[])};function Ge({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:J(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?z(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(K.Provider,{value:C,children:r})}function Xe({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(Ae.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(L.default,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(_e.default,{sx:{fontSize:20}})}),r&&o&&e.jsx(O.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(ke.default,{}),onClick:()=>m(!0),children:"Edit labels"})]})}i.LabelManager=Ye,i.LabelPicker=$,i.LabelTree=q,i.Labels=Xe,i.LabelsProvider=Ge,i.transformLabels=J,i.useLabelsContext=M,i.useLabelsUpdateOnDestroy=Ze,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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.38",
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": "a2bf38316ca062d8238979854134e766d8a0e4ae"
78
+ "gitHead": "46867337b45cb831020815924af170e4c3f3329f"
79
79
  }