@blocklet/labels 1.5.143 → 1.5.144

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