@blocklet/labels 1.5.136 → 1.5.137

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