@blocklet/labels 1.5.39 → 1.5.41

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,62 +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) => {
327
+ }), {}), d = Array.isArray(t) ? t : [t], f = d.map((p) => x[p]), y = D({
328
+ prev: d.map((p) => {
330
329
  var I;
331
- return ((I = x[h]) == null ? void 0 : I.data) || "";
330
+ return ((I = x[p]) == null ? void 0 : I.data) || "";
332
331
  })
333
- }), b = (h, I) => {
334
- !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(() => {
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(() => {
335
334
  var c;
336
335
  return (c = m == null ? void 0 : m.current) == null ? void 0 : c.blur();
337
336
  }, 1);
338
337
  }, M = () => {
339
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);
340
339
  };
341
- return /* @__PURE__ */ n(p, {
340
+ return /* @__PURE__ */ n(h, {
342
341
  ...u,
343
- children: /* @__PURE__ */ n(te, {
342
+ children: /* @__PURE__ */ n(ne, {
344
343
  ref: m,
345
344
  defaultValue: f,
346
345
  options: g,
347
346
  onChange: b,
348
347
  components: {
349
- MenuList: (h) => /* @__PURE__ */ n(ke, {
350
- ...h,
348
+ MenuList: (p) => /* @__PURE__ */ n(ze, {
349
+ ...p,
351
350
  addon: l
352
351
  }),
353
352
  ...r && {
354
- ValueContainer: Ae
353
+ ValueContainer: Te
355
354
  }
356
355
  },
357
356
  placeholder: "Select labels",
358
357
  styles: {
359
- ...r && Te,
360
- menu: (h) => ({
361
- ...h,
358
+ ...r && ke,
359
+ menu: (p) => ({
360
+ ...p,
362
361
  ...s && {
363
362
  paddingBottom: "36px"
364
363
  },
365
364
  zIndex: 99
366
365
  }),
367
- menuList: (h) => ({
368
- ...h,
366
+ menuList: (p) => ({
367
+ ...p,
369
368
  overflowY: "auto",
370
369
  maxHeight: `${a}px`
371
370
  })
372
371
  },
373
- theme: (h) => ({
374
- ...h,
372
+ theme: (p) => ({
373
+ ...p,
375
374
  colors: {
376
- ...h.colors,
375
+ ...p.colors,
377
376
  primary25: "#ddd",
378
377
  primary50: "#ddd",
379
378
  primary: "#ddd"
@@ -398,7 +397,7 @@ var E = function() {
398
397
  return t;
399
398
  }, E.apply(this, arguments);
400
399
  };
401
- function Pe(e, t) {
400
+ function Oe(e, t) {
402
401
  var s = typeof Symbol == "function" && e[Symbol.iterator];
403
402
  if (!s)
404
403
  return e;
@@ -418,25 +417,25 @@ function Pe(e, t) {
418
417
  }
419
418
  return r;
420
419
  }
421
- var Be = function(e) {
420
+ var Pe = function(e) {
422
421
  return typeof e == "function";
423
- }, Ne = function(e) {
424
- 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) {
425
424
  l(function(i) {
426
- var a = Be(r) ? r(i) : r;
425
+ var a = Pe(r) ? r(i) : r;
427
426
  return a ? E(E({}, i), a) : i;
428
427
  });
429
428
  }, []);
430
429
  return [s, o];
431
430
  };
432
- const Ee = Ne;
433
- function Le({
431
+ const Ne = Be;
432
+ function Ee({
434
433
  I18NProps: e,
435
434
  ...t
436
435
  }) {
437
436
  const {
438
437
  languages: s
439
- } = K(), {
438
+ } = Q(), {
440
439
  translation: l,
441
440
  onChange: o
442
441
  } = e, [r, i] = z(null), a = (g) => {
@@ -522,19 +521,19 @@ function Le({
522
521
  }
523
522
  });
524
523
  }
525
- function Me({
524
+ function Le({
526
525
  open: e,
527
526
  initialLabel: t,
528
527
  onSubmit: s,
529
528
  onClose: l,
530
529
  ...o
531
530
  }) {
532
- const r = !(t != null && t.id), [i, a] = Ee({
531
+ const r = !(t != null && t.id), [i, a] = Ne({
533
532
  name: (t == null ? void 0 : t.name) || "",
534
533
  color: (t == null ? void 0 : t.color) || "#ddd",
535
534
  slug: (t == null ? void 0 : t.id) || "",
536
535
  translation: (t == null ? void 0 : t.translation) || {}
537
- }), 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 = () => {
538
537
  s({
539
538
  ...t,
540
539
  name: i.name,
@@ -551,19 +550,19 @@ function Me({
551
550
  color: b.target.value
552
551
  });
553
552
  };
554
- return /* @__PURE__ */ n(_, {
553
+ return /* @__PURE__ */ n(K, {
555
554
  open: e,
556
555
  showCloseButton: !0,
557
556
  maxWidth: "lg",
558
557
  title: r ? "Create label" : "Edit label",
559
558
  actions: /* @__PURE__ */ v(P, {
560
- children: [/* @__PURE__ */ n(T, {
559
+ children: [/* @__PURE__ */ n(A, {
561
560
  color: "inherit",
562
561
  variant: "contained",
563
562
  size: "small",
564
563
  onClick: l,
565
564
  children: "Cancel"
566
- }), /* @__PURE__ */ n(T, {
565
+ }), /* @__PURE__ */ n(A, {
567
566
  color: "primary",
568
567
  variant: "contained",
569
568
  size: "small",
@@ -574,10 +573,10 @@ function Me({
574
573
  }),
575
574
  onClose: l,
576
575
  ...o,
577
- children: /* @__PURE__ */ v(p, {
576
+ children: /* @__PURE__ */ v(h, {
578
577
  width: 600,
579
578
  minHeight: 280,
580
- children: [/* @__PURE__ */ n(Le, {
579
+ children: [/* @__PURE__ */ n(Ee, {
581
580
  label: "Name",
582
581
  value: i.name,
583
582
  placeholder: "New label",
@@ -613,20 +612,20 @@ function Me({
613
612
  sx: {
614
613
  mt: 2
615
614
  }
616
- }), /* @__PURE__ */ n(ie, {
615
+ }), /* @__PURE__ */ n($, {
617
616
  onClickAway: () => x(!1),
618
- children: /* @__PURE__ */ v(p, {
617
+ children: /* @__PURE__ */ v(h, {
619
618
  sx: {
620
619
  position: "relative",
621
620
  mt: 2
622
621
  },
623
- children: [/* @__PURE__ */ v(p, {
622
+ children: [/* @__PURE__ */ v(h, {
624
623
  sx: {
625
624
  display: "flex",
626
625
  alignItems: "center",
627
626
  gap: 1
628
627
  },
629
- children: [/* @__PURE__ */ n(p, {
628
+ children: [/* @__PURE__ */ n(h, {
630
629
  sx: {
631
630
  width: 30,
632
631
  height: 30,
@@ -649,7 +648,7 @@ function Me({
649
648
  }
650
649
  }
651
650
  })]
652
- }), g && /* @__PURE__ */ n(p, {
651
+ }), g && /* @__PURE__ */ n(h, {
653
652
  sx: {
654
653
  position: "absolute",
655
654
  top: 48,
@@ -665,26 +664,26 @@ function Me({
665
664
  })
666
665
  });
667
666
  }
668
- function je({
667
+ function Me({
669
668
  open: e,
670
669
  label: t,
671
670
  onSubmit: s,
672
671
  onClose: l,
673
672
  ...o
674
673
  }) {
675
- return /* @__PURE__ */ n(_, {
674
+ return /* @__PURE__ */ n(K, {
676
675
  open: e,
677
676
  showCloseButton: !0,
678
677
  maxWidth: "md",
679
678
  title: "Delete",
680
679
  actions: /* @__PURE__ */ v(P, {
681
- children: [/* @__PURE__ */ n(T, {
680
+ children: [/* @__PURE__ */ n(A, {
682
681
  color: "inherit",
683
682
  variant: "contained",
684
683
  size: "small",
685
684
  onClick: l,
686
685
  children: "Cancel"
687
- }), /* @__PURE__ */ n(T, {
686
+ }), /* @__PURE__ */ n(A, {
688
687
  color: "primary",
689
688
  variant: "contained",
690
689
  size: "small",
@@ -694,10 +693,10 @@ function je({
694
693
  }),
695
694
  onClose: l,
696
695
  ...o,
697
- children: /* @__PURE__ */ v(p, {
696
+ children: /* @__PURE__ */ v(h, {
698
697
  width: 600,
699
698
  minHeight: 280,
700
- children: [/* @__PURE__ */ n(pe, {
699
+ children: [/* @__PURE__ */ n(he, {
701
700
  severity: "info",
702
701
  sx: {
703
702
  mb: 2
@@ -709,7 +708,7 @@ function je({
709
708
  })
710
709
  });
711
710
  }
712
- const De = H(F)`
711
+ const je = J(F)`
713
712
  .label-tree-item {
714
713
  &:before {
715
714
  content: '';
@@ -730,11 +729,11 @@ const De = H(F)`
730
729
  padding: 0 16px;
731
730
  }
732
731
  `;
733
- function We({
732
+ function De({
734
733
  locale: e,
735
734
  value: t
736
735
  }) {
737
- return /* @__PURE__ */ v(p, {
736
+ return /* @__PURE__ */ v(h, {
738
737
  sx: {
739
738
  display: "flex",
740
739
  alignItems: "center",
@@ -745,14 +744,14 @@ function We({
745
744
  bgcolor: "grey.300",
746
745
  borderRadius: 2
747
746
  },
748
- children: [/* @__PURE__ */ n(p, {
747
+ children: [/* @__PURE__ */ n(h, {
749
748
  sx: {
750
749
  pr: 0.5,
751
750
  borderRight: 1,
752
751
  borderColor: "grey.400"
753
752
  },
754
753
  children: e
755
- }), /* @__PURE__ */ n(p, {
754
+ }), /* @__PURE__ */ n(h, {
756
755
  sx: {
757
756
  pl: 0.5
758
757
  },
@@ -760,12 +759,12 @@ function We({
760
759
  })]
761
760
  });
762
761
  }
763
- function ht({
762
+ function ut({
764
763
  data: e,
765
764
  api: t,
766
765
  ...s
767
766
  }) {
768
- 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(() => {
769
768
  const c = (C, w) => C.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
770
769
  return c(a);
771
770
  }, [a]), x = (c) => {
@@ -809,18 +808,18 @@ function ht({
809
808
  translation: JSON.stringify(S),
810
809
  parentId: C == null ? void 0 : C.id
811
810
  }), d(c)), o(null);
812
- }, h = async () => {
811
+ }, p = async () => {
813
812
  !r || (await t.deleteLabel(r.id), f(r), i(null));
814
813
  }, I = (c, C) => /* @__PURE__ */ v(P, {
815
- children: [/* @__PURE__ */ v(p, {
814
+ children: [/* @__PURE__ */ v(h, {
816
815
  sx: {
817
816
  display: "flex",
818
817
  alignItems: "center",
819
818
  flexWrap: "wrap"
820
819
  },
821
- children: [/* @__PURE__ */ n(p, {
820
+ children: [/* @__PURE__ */ n(h, {
822
821
  children: c
823
- }), C.translation && /* @__PURE__ */ n(p, {
822
+ }), C.translation && /* @__PURE__ */ n(h, {
824
823
  sx: {
825
824
  display: "flex",
826
825
  alignItems: "center",
@@ -830,13 +829,13 @@ function ht({
830
829
  children: Object.keys(C.translation).map((w) => {
831
830
  var O;
832
831
  const S = (O = C.translation) == null ? void 0 : O[w];
833
- return S ? /* @__PURE__ */ n(We, {
832
+ return S ? /* @__PURE__ */ n(De, {
834
833
  locale: w,
835
834
  value: S
836
835
  }, w) : null;
837
836
  })
838
837
  })]
839
- }), /* @__PURE__ */ v(p, {
838
+ }), /* @__PURE__ */ v(h, {
840
839
  sx: {
841
840
  display: "flex",
842
841
  gap: 1,
@@ -849,7 +848,7 @@ function ht({
849
848
  color: "grey.500"
850
849
  },
851
850
  onClick: () => y(C),
852
- children: /* @__PURE__ */ n(le, {
851
+ children: /* @__PURE__ */ n(ie, {
853
852
  sx: {
854
853
  fontSize: 20
855
854
  }
@@ -861,7 +860,7 @@ function ht({
861
860
  color: "grey.500"
862
861
  },
863
862
  onClick: () => b(C),
864
- children: /* @__PURE__ */ n(oe, {
863
+ children: /* @__PURE__ */ n(le, {
865
864
  sx: {
866
865
  fontSize: 18
867
866
  }
@@ -873,7 +872,7 @@ function ht({
873
872
  color: "grey.500"
874
873
  },
875
874
  onClick: () => i(C),
876
- children: /* @__PURE__ */ n(re, {
875
+ children: /* @__PURE__ */ n(oe, {
877
876
  sx: {
878
877
  fontSize: 20
879
878
  }
@@ -881,19 +880,19 @@ function ht({
881
880
  })]
882
881
  })]
883
882
  });
884
- return /* @__PURE__ */ v(p, {
883
+ return /* @__PURE__ */ v(h, {
885
884
  ...s,
886
- children: [/* @__PURE__ */ v(p, {
885
+ children: [/* @__PURE__ */ v(h, {
887
886
  sx: {
888
887
  display: "flex",
889
888
  alignItems: "center",
890
889
  justifyContent: "space-between"
891
890
  },
892
- children: [/* @__PURE__ */ n(ne, {
891
+ children: [/* @__PURE__ */ n(re, {
893
892
  component: "h2",
894
893
  variant: "h6",
895
894
  children: "Manage labels"
896
- }), /* @__PURE__ */ n(T, {
895
+ }), /* @__PURE__ */ n(A, {
897
896
  color: "primary",
898
897
  variant: "contained",
899
898
  size: "small",
@@ -903,7 +902,7 @@ function ht({
903
902
  onClick: () => y(),
904
903
  children: "New label"
905
904
  })]
906
- }), /* @__PURE__ */ v(p, {
905
+ }), /* @__PURE__ */ v(h, {
907
906
  sx: {
908
907
  mt: 2,
909
908
  border: 1,
@@ -911,7 +910,7 @@ function ht({
911
910
  borderRadius: 1,
912
911
  overflow: "hidden"
913
912
  },
914
- children: [/* @__PURE__ */ v(p, {
913
+ children: [/* @__PURE__ */ v(h, {
915
914
  sx: {
916
915
  p: 2,
917
916
  fontSize: 14,
@@ -919,45 +918,45 @@ function ht({
919
918
  bgcolor: "grey.200"
920
919
  },
921
920
  children: [m.length, " labels"]
922
- }), /* @__PURE__ */ n(p, {
921
+ }), /* @__PURE__ */ n(h, {
923
922
  sx: {
924
923
  pt: 0.5
925
924
  },
926
- children: /* @__PURE__ */ n(De, {
925
+ children: /* @__PURE__ */ n(je, {
927
926
  data: g,
928
927
  selected: [],
929
928
  renderItem: I,
930
929
  rowHeight: 64
931
930
  })
932
931
  })]
933
- }), /* @__PURE__ */ n(Me, {
932
+ }), /* @__PURE__ */ n(Le, {
934
933
  open: !!l,
935
934
  onClose: () => o(null),
936
935
  initialLabel: l,
937
936
  onSubmit: M
938
- }, l == null ? void 0 : l.id), /* @__PURE__ */ n(je, {
937
+ }, l == null ? void 0 : l.id), /* @__PURE__ */ n(Me, {
939
938
  open: !!r,
940
939
  onClose: () => i(null),
941
940
  label: r,
942
- onSubmit: h
941
+ onSubmit: p
943
942
  }, r == null ? void 0 : r.id)]
944
943
  });
945
944
  }
946
- const Z = q({}), G = () => $(Z), mt = () => {
945
+ const G = q({}), U = () => H(G), ht = () => {
947
946
  const {
948
947
  updateLabels: e
949
- } = G();
948
+ } = U();
950
949
  W(() => () => {
951
950
  e();
952
951
  }, []);
953
952
  };
954
- function ft({
953
+ function pt({
955
954
  fetchLabels: e,
956
955
  children: t
957
956
  }) {
958
957
  const {
959
958
  locale: s
960
- } = K(), [l, o] = z({
959
+ } = Q(), [l, o] = z({
961
960
  loading: !0,
962
961
  labels: [],
963
962
  updateCounter: 1
@@ -973,7 +972,7 @@ function ft({
973
972
  o((y) => ({
974
973
  ...y,
975
974
  loading: !1,
976
- labels: ze(f)
975
+ labels: Ie(f)
977
976
  }));
978
977
  } catch (f) {
979
978
  console.error(f), o((y) => ({
@@ -984,22 +983,22 @@ function ft({
984
983
  }
985
984
  })();
986
985
  }, [l.updateCounter]);
987
- const r = k(() => {
986
+ const r = T(() => {
988
987
  var f;
989
988
  return (f = l.labels) != null && f.length ? L(l.labels).reduce((y, b) => ({
990
989
  ...y,
991
990
  [b.id]: b
992
991
  }), {}) : {};
993
- }, [l.labels]), i = A((d) => {
992
+ }, [l.labels]), i = k((d) => {
994
993
  var f;
995
994
  return {
996
995
  ...d,
997
996
  name: ((f = d.translation) == null ? void 0 : f[s]) || d.name
998
997
  };
999
- }, [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 = []) => {
1000
999
  if (!!(d != null && d.length))
1001
1000
  return d.join(",");
1002
- }, []), g = k(() => l.labels.map(i), [l.labels, i]), x = k(() => ({
1001
+ }, []), g = T(() => l.labels.map(i), [l.labels, i]), x = T(() => ({
1003
1002
  loading: l.loading,
1004
1003
  labels: l.labels || [],
1005
1004
  updateLabels: () => o((d) => ({
@@ -1011,12 +1010,12 @@ function ft({
1011
1010
  stringifyLabelIds: m,
1012
1011
  localizedLabels: g
1013
1012
  }), [l, a, u, m, g]);
1014
- return /* @__PURE__ */ n(Z.Provider, {
1013
+ return /* @__PURE__ */ n(G.Provider, {
1015
1014
  value: x,
1016
1015
  children: t
1017
1016
  });
1018
1017
  }
1019
- function gt({
1018
+ function mt({
1020
1019
  labels: e,
1021
1020
  editable: t,
1022
1021
  onChange: s,
@@ -1026,7 +1025,7 @@ function gt({
1026
1025
  labels: r,
1027
1026
  loading: i,
1028
1027
  getLabelsById: a
1029
- } = G(), [u, m] = z(!1);
1028
+ } = U(), [u, m] = z(!1);
1030
1029
  if (i || !t && o)
1031
1030
  return null;
1032
1031
  const g = (f) => {
@@ -1035,10 +1034,10 @@ function gt({
1035
1034
  }, 300);
1036
1035
  };
1037
1036
  if (u)
1038
- return /* @__PURE__ */ n(fe, {
1037
+ return /* @__PURE__ */ n($, {
1039
1038
  onClickAway: () => u && m(!1),
1040
1039
  children: /* @__PURE__ */ n("div", {
1041
- children: /* @__PURE__ */ n(Oe, {
1040
+ children: /* @__PURE__ */ n(Ae, {
1042
1041
  data: r,
1043
1042
  value: e || [],
1044
1043
  onChange: g
@@ -1051,9 +1050,9 @@ function gt({
1051
1050
  alignItems: "center",
1052
1051
  flexWrap: "wrap"
1053
1052
  }, ...Array.isArray(l) ? l : [l]];
1054
- return /* @__PURE__ */ v(p, {
1053
+ return /* @__PURE__ */ v(h, {
1055
1054
  sx: d,
1056
- children: [x.map((f) => f ? /* @__PURE__ */ n(ge, {
1055
+ children: [x.map((f) => f ? /* @__PURE__ */ n(fe, {
1057
1056
  label: f.name,
1058
1057
  variant: "filled",
1059
1058
  size: "small",
@@ -1067,12 +1066,12 @@ function gt({
1067
1066
  sx: {
1068
1067
  color: "grey.400"
1069
1068
  },
1070
- children: /* @__PURE__ */ n(he, {
1069
+ children: /* @__PURE__ */ n(pe, {
1071
1070
  sx: {
1072
1071
  fontSize: 20
1073
1072
  }
1074
1073
  })
1075
- }), t && o && /* @__PURE__ */ n(T, {
1074
+ }), t && o && /* @__PURE__ */ n(A, {
1076
1075
  color: "inherit",
1077
1076
  variant: "outlined",
1078
1077
  startIcon: /* @__PURE__ */ n(me, {}),
@@ -1082,12 +1081,12 @@ function gt({
1082
1081
  });
1083
1082
  }
1084
1083
  export {
1085
- ht as LabelManager,
1086
- Oe as LabelPicker,
1084
+ ut as LabelManager,
1085
+ Ae as LabelPicker,
1087
1086
  F as LabelTree,
1088
- gt as Labels,
1089
- ft as LabelsProvider,
1090
- ze as transformLabels,
1091
- G as useLabelsContext,
1092
- mt as useLabelsUpdateOnDestroy
1087
+ mt as Labels,
1088
+ pt as LabelsProvider,
1089
+ Ie as transformLabels,
1090
+ U as useLabelsContext,
1091
+ ht as useLabelsUpdateOnDestroy
1093
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=>{var k;return((k=C[g])==null?void 0:k.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.39",
3
+ "version": "1.5.41",
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": "f1e789911074a8bacbb327ebc017f4fcbe4b7f7f"
78
+ "gitHead": "0a012201eaf6126a006c5456fd18bf456e9387b7"
79
79
  }