@blocklet/labels 1.5.103 → 1.5.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,30 +1,24 @@
1
1
  import { createContext as q, useRef as D, useState as z, useCallback as k, useEffect as W, useMemo as T, useContext as H } from "react";
2
- import R from "@mui/icons-material/ExpandMore";
2
+ 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";
3
3
  import p from "@mui/material/Box";
4
4
  import { styled as J } from "@mui/material/styles";
5
- import { Tree as X } from "react-arborist";
6
- import { Icon as ee } from "@iconify/react";
5
+ import { Tree as le } from "react-arborist";
6
+ import { Icon as ie } from "@iconify/react";
7
7
  import { jsx as n, jsxs as C, Fragment as P } from "react/jsx-runtime";
8
- import te from "lodash/omit";
9
- import ne, { components as _ } from "react-select";
10
- import re from "@mui/material/Typography";
8
+ import ae from "lodash/omit";
9
+ import se, { components as _ } from "react-select";
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 oe from "@mui/icons-material/DeleteOutlineOutlined";
14
- import le from "@mui/icons-material/EditOutlined";
15
- import ie from "@mui/icons-material/Add";
16
13
  import j from "@mui/material/TextField";
17
14
  import $ from "@mui/material/ClickAwayListener";
18
- import { GithubPicker as ae } from "react-color";
15
+ import { GithubPicker as de } from "react-color";
19
16
  import K from "@arcblock/ux/lib/Dialog";
20
- import { TextField as V, InputAdornment as se, IconButton as ce, Box as B } from "@mui/material";
21
- import de from "@mui/icons-material/Translate";
22
- import ue from "@mui/material/Popover";
17
+ import { TextField as V, InputAdornment as ue, IconButton as he, Box as B } from "@mui/material";
18
+ import pe from "@mui/material/Popover";
23
19
  import { useLocaleContext as Q } from "@arcblock/ux/lib/Locale/context";
24
- import he from "@mui/material/Alert";
25
- import pe from "@mui/icons-material/Edit";
26
- import me from "@mui/icons-material/LabelOutlined";
27
- import fe from "@mui/material/Chip";
20
+ import fe from "@mui/material/Alert";
21
+ import me from "@mui/material/Chip";
28
22
  const ge = (e) => /* @__PURE__ */ n("svg", {
29
23
  viewBox: "0 0 24 24",
30
24
  width: "1.2em",
@@ -98,7 +92,7 @@ function be({
98
92
  renderItem: i
99
93
  } = H(Y), {
100
94
  data: s
101
- } = e, h = s.icon ? /* @__PURE__ */ n(ee, {
95
+ } = e, h = s.icon ? /* @__PURE__ */ n(ie, {
102
96
  icon: s.icon,
103
97
  style: {
104
98
  fontSize: 18
@@ -110,7 +104,7 @@ function be({
110
104
  }
111
105
  }), g = (d) => {
112
106
  d.stopPropagation(), e.isInternal && e.toggle();
113
- }, m = (d) => {
107
+ }, f = (d) => {
114
108
  d.stopPropagation(), o && l(e.id);
115
109
  }, x = /* @__PURE__ */ C(P, {
116
110
  children: [/* @__PURE__ */ C(p, {
@@ -154,7 +148,7 @@ function be({
154
148
  justifyContent: "space-between"
155
149
  },
156
150
  ref: a,
157
- onClick: m,
151
+ onClick: f,
158
152
  children: [!i && x, !!i && i(x, e.data)]
159
153
  });
160
154
  }
@@ -182,7 +176,7 @@ function F({
182
176
  sx: i,
183
177
  ...s
184
178
  }) {
185
- const h = D(), g = [...Array.isArray(i) ? i : [i]], [m, x] = z(0), d = k(() => {
179
+ const h = D(), g = [...Array.isArray(i) ? i : [i]], [f, x] = z(0), d = k(() => {
186
180
  var u, v;
187
181
  x((((v = (u = h.current) == null ? void 0 : u.visibleNodes) == null ? void 0 : v.length) || 0) * l);
188
182
  }, [l]);
@@ -196,10 +190,10 @@ function F({
196
190
  children: /* @__PURE__ */ n(Se, {
197
191
  ...s,
198
192
  sx: g,
199
- children: /* @__PURE__ */ n(X, {
193
+ children: /* @__PURE__ */ n(le, {
200
194
  data: e,
201
195
  rowHeight: l,
202
- height: m,
196
+ height: f,
203
197
  indent: 32,
204
198
  ref: h,
205
199
  onToggle: () => {
@@ -244,7 +238,7 @@ const O = (e) => e.reduce((t, a) => {
244
238
  };
245
239
  return /* @__PURE__ */ C(P, {
246
240
  children: [/* @__PURE__ */ n(_.MenuList, {
247
- ...te(e, ["addon"]),
241
+ ...ae(e, ["addon"]),
248
242
  children: /* @__PURE__ */ n(p, {
249
243
  sx: {
250
244
  px: 2,
@@ -317,20 +311,20 @@ function Ae({
317
311
  maxHeight: s = 264,
318
312
  ...h
319
313
  }) {
320
- const g = D(null), m = T(() => O(e).map((f) => ({
321
- data: f,
322
- label: f.name,
323
- value: f.id
324
- })), [e]), x = m.reduce((f, I) => ({
325
- ...f,
314
+ const g = D(null), f = T(() => O(e).map((m) => ({
315
+ data: m,
316
+ label: m.name,
317
+ value: m.id
318
+ })), [e]), x = f.reduce((m, I) => ({
319
+ ...m,
326
320
  [I.data.id]: I
327
- }), {}), d = Array.isArray(t) ? t : [t], b = d.map((f) => x[f]), u = D({
328
- prev: d.map((f) => {
321
+ }), {}), d = Array.isArray(t) ? t : [t], b = d.map((m) => x[m]), u = D({
322
+ prev: d.map((m) => {
329
323
  var I;
330
- return ((I = x[f]) == null ? void 0 : I.data) || "";
324
+ return ((I = x[m]) == null ? void 0 : I.data) || "";
331
325
  })
332
- }), v = (f, I) => {
333
- !i || !Array.isArray(f) ? l(f ? [f.data] : []) : u.current.current = f.map((c) => c.data), ["clear", "remove-value"].includes(I.action) && g.current && setTimeout(() => {
326
+ }), v = (m, I) => {
327
+ !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(() => {
334
328
  var c;
335
329
  return (c = g == null ? void 0 : g.current) == null ? void 0 : c.blur();
336
330
  }, 1);
@@ -339,14 +333,14 @@ function Ae({
339
333
  };
340
334
  return /* @__PURE__ */ n(p, {
341
335
  ...h,
342
- children: /* @__PURE__ */ n(ne, {
336
+ children: /* @__PURE__ */ n(se, {
343
337
  ref: g,
344
338
  defaultValue: b,
345
- options: m,
339
+ options: f,
346
340
  onChange: v,
347
341
  components: {
348
- MenuList: (f) => /* @__PURE__ */ n(ze, {
349
- ...f,
342
+ MenuList: (m) => /* @__PURE__ */ n(ze, {
343
+ ...m,
350
344
  addon: o
351
345
  }),
352
346
  ...r && {
@@ -356,23 +350,23 @@ function Ae({
356
350
  placeholder: "Select labels",
357
351
  styles: {
358
352
  ...r && ke,
359
- menu: (f) => ({
360
- ...f,
353
+ menu: (m) => ({
354
+ ...m,
361
355
  ...a && {
362
356
  paddingBottom: "36px"
363
357
  },
364
358
  zIndex: 99
365
359
  }),
366
- menuList: (f) => ({
367
- ...f,
360
+ menuList: (m) => ({
361
+ ...m,
368
362
  overflowY: "auto",
369
363
  maxHeight: `${s}px`
370
364
  })
371
365
  },
372
- theme: (f) => ({
373
- ...f,
366
+ theme: (m) => ({
367
+ ...m,
374
368
  colors: {
375
- ...f.colors,
369
+ ...m.colors,
376
370
  primary25: "#ddd",
377
371
  primary50: "#ddd",
378
372
  primary: "#ddd"
@@ -438,22 +432,22 @@ function Ee({
438
432
  } = Q(), {
439
433
  translation: o,
440
434
  onChange: l
441
- } = e, [r, i] = z(null), s = (m) => {
442
- const x = m.currentTarget.closest(".MuiInputBase-root");
435
+ } = e, [r, i] = z(null), s = (f) => {
436
+ const x = f.currentTarget.closest(".MuiInputBase-root");
443
437
  x && i(x);
444
438
  }, h = () => {
445
439
  i(null);
446
- }, g = a.filter((m) => m.code !== "en");
440
+ }, g = a.filter((f) => f.code !== "en");
447
441
  return /* @__PURE__ */ n(V, {
448
442
  ...t,
449
443
  InputProps: {
450
- endAdornment: /* @__PURE__ */ C(se, {
444
+ endAdornment: /* @__PURE__ */ C(ue, {
451
445
  position: "end",
452
- children: [/* @__PURE__ */ n(ce, {
446
+ children: [/* @__PURE__ */ n(he, {
453
447
  edge: "end",
454
448
  onClick: s,
455
- children: /* @__PURE__ */ n(de, {})
456
- }), /* @__PURE__ */ n(ue, {
449
+ children: /* @__PURE__ */ n(X, {})
450
+ }), /* @__PURE__ */ n(pe, {
457
451
  open: !!r,
458
452
  anchorEl: r,
459
453
  onClose: h,
@@ -482,7 +476,7 @@ function Ee({
482
476
  p: 2
483
477
  },
484
478
  children: g.map(({
485
- code: m,
479
+ code: f,
486
480
  name: x
487
481
  }) => /* @__PURE__ */ C(B, {
488
482
  sx: {
@@ -503,18 +497,18 @@ function Ee({
503
497
  flex: 1
504
498
  },
505
499
  children: /* @__PURE__ */ n(V, {
506
- value: o[m] || "",
500
+ value: o[f] || "",
507
501
  size: "small",
508
502
  sx: {
509
503
  width: 1
510
504
  },
511
505
  onChange: (d) => l({
512
506
  ...o,
513
- [m]: d.target.value
507
+ [f]: d.target.value
514
508
  })
515
509
  })
516
510
  })]
517
- }, m))
511
+ }, f))
518
512
  })
519
513
  })]
520
514
  })
@@ -533,7 +527,7 @@ function Le({
533
527
  color: (t == null ? void 0 : t.color) || "#ddd",
534
528
  slug: (t == null ? void 0 : t.id) || "",
535
529
  translation: (t == null ? void 0 : t.translation) || {}
536
- }), h = (v) => /^#([0-9A-F]{3}){1,2}$/i.test(v), g = T(() => r ? i.name && i.color && i.slug && h(i.color) : i.name && i.color && h(i.color), [i, r]), [m, x] = z(!1), d = () => {
530
+ }), 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 = () => {
537
531
  a({
538
532
  ...t,
539
533
  name: i.name,
@@ -648,13 +642,13 @@ function Le({
648
642
  }
649
643
  }
650
644
  })]
651
- }), m && /* @__PURE__ */ n(p, {
645
+ }), f && /* @__PURE__ */ n(p, {
652
646
  sx: {
653
647
  position: "absolute",
654
648
  top: 48,
655
649
  zIndex: 1
656
650
  },
657
- children: /* @__PURE__ */ n(ae, {
651
+ children: /* @__PURE__ */ n(de, {
658
652
  color: i.color,
659
653
  onChangeComplete: b
660
654
  })
@@ -696,7 +690,7 @@ function Me({
696
690
  children: /* @__PURE__ */ C(p, {
697
691
  width: 600,
698
692
  minHeight: 280,
699
- children: [/* @__PURE__ */ n(he, {
693
+ children: [/* @__PURE__ */ n(fe, {
700
694
  severity: "info",
701
695
  sx: {
702
696
  mb: 2
@@ -760,12 +754,12 @@ function De({
760
754
  })]
761
755
  });
762
756
  }
763
- function ut({
757
+ function lt({
764
758
  data: e,
765
759
  api: t,
766
760
  ...a
767
761
  }) {
768
- const [o, l] = z(null), [r, i] = z(null), [s, h] = z(Z(e)), g = T(() => O(s), [s]), m = T(() => {
762
+ const [o, l] = z(null), [r, i] = z(null), [s, h] = z(Z(e)), g = T(() => O(s), [s]), f = T(() => {
769
763
  const c = (y, w) => y.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
770
764
  return c(s);
771
765
  }, [s]), x = (c) => {
@@ -809,7 +803,7 @@ function ut({
809
803
  translation: JSON.stringify(S),
810
804
  parentId: y == null ? void 0 : y.id
811
805
  }), d(c)), l(null);
812
- }, f = async () => {
806
+ }, m = async () => {
813
807
  !r || (await t.deleteLabel(r.id), b(r), i(null));
814
808
  }, I = (c, y) => /* @__PURE__ */ C(P, {
815
809
  children: [/* @__PURE__ */ C(p, {
@@ -852,7 +846,7 @@ function ut({
852
846
  color: "grey.500"
853
847
  },
854
848
  onClick: () => u(y),
855
- children: /* @__PURE__ */ n(ie, {
849
+ children: /* @__PURE__ */ n(ee, {
856
850
  sx: {
857
851
  fontSize: 20
858
852
  }
@@ -864,7 +858,7 @@ function ut({
864
858
  color: "grey.500"
865
859
  },
866
860
  onClick: () => v(y),
867
- children: /* @__PURE__ */ n(le, {
861
+ children: /* @__PURE__ */ n(te, {
868
862
  sx: {
869
863
  fontSize: 18
870
864
  }
@@ -876,7 +870,7 @@ function ut({
876
870
  color: "grey.500"
877
871
  },
878
872
  onClick: () => i(y),
879
- children: /* @__PURE__ */ n(oe, {
873
+ children: /* @__PURE__ */ n(ne, {
880
874
  sx: {
881
875
  fontSize: 20
882
876
  }
@@ -893,7 +887,7 @@ function ut({
893
887
  alignItems: "center",
894
888
  justifyContent: "space-between"
895
889
  },
896
- children: [/* @__PURE__ */ n(re, {
890
+ children: [/* @__PURE__ */ n(ce, {
897
891
  component: "h2",
898
892
  variant: "h6",
899
893
  children: "Manage labels"
@@ -929,7 +923,7 @@ function ut({
929
923
  pt: 0.5
930
924
  },
931
925
  children: /* @__PURE__ */ n(je, {
932
- data: m,
926
+ data: f,
933
927
  selected: [],
934
928
  renderItem: I,
935
929
  rowHeight: 64
@@ -944,11 +938,11 @@ function ut({
944
938
  open: !!r,
945
939
  onClose: () => i(null),
946
940
  label: r,
947
- onSubmit: f
941
+ onSubmit: m
948
942
  }, r == null ? void 0 : r.id)]
949
943
  });
950
944
  }
951
- const G = q({}), U = () => H(G), ht = () => {
945
+ const G = q({}), U = () => H(G), it = () => {
952
946
  const {
953
947
  updateLabels: e
954
948
  } = U();
@@ -956,7 +950,7 @@ const G = q({}), U = () => H(G), ht = () => {
956
950
  e();
957
951
  }, []);
958
952
  };
959
- function pt({
953
+ function at({
960
954
  fetchLabels: e,
961
955
  children: t
962
956
  }) {
@@ -1004,7 +998,7 @@ function pt({
1004
998
  }, [a]), s = k((d) => d.filter(Boolean).map((b) => r[b]).map(i), [r, i]), h = k((d) => (d == null ? void 0 : d.split(",")) || [], []), g = k((d = []) => {
1005
999
  if (!!(d != null && d.length))
1006
1000
  return d.join(",");
1007
- }, []), m = T(() => o.labels.map(i), [o.labels, i]), x = T(() => ({
1001
+ }, []), f = T(() => o.labels.map(i), [o.labels, i]), x = T(() => ({
1008
1002
  loading: o.loading,
1009
1003
  labels: o.labels || [],
1010
1004
  updateLabels: () => l((d) => ({
@@ -1014,15 +1008,15 @@ function pt({
1014
1008
  getLabelsById: s,
1015
1009
  parseLabelIds: h,
1016
1010
  stringifyLabelIds: g,
1017
- localizedLabels: m,
1018
- flattenedLabels: O(m || [])
1019
- }), [o, s, h, g, m]);
1011
+ localizedLabels: f,
1012
+ flattenedLabels: O(f || [])
1013
+ }), [o, s, h, g, f]);
1020
1014
  return /* @__PURE__ */ n(G.Provider, {
1021
1015
  value: x,
1022
1016
  children: t
1023
1017
  });
1024
1018
  }
1025
- function mt({
1019
+ function st({
1026
1020
  labels: e,
1027
1021
  editable: t,
1028
1022
  onChange: a,
@@ -1033,17 +1027,17 @@ function mt({
1033
1027
  labels: i,
1034
1028
  loading: s,
1035
1029
  getLabelsById: h
1036
- } = U(), [g, m] = z(!1);
1030
+ } = U(), [g, f] = z(!1);
1037
1031
  if (s || !t && r)
1038
1032
  return null;
1039
1033
  const x = (u) => {
1040
1034
  a == null || a(u), setTimeout(() => {
1041
- m(!1);
1035
+ f(!1);
1042
1036
  }, 300);
1043
1037
  };
1044
1038
  if (g)
1045
1039
  return /* @__PURE__ */ n($, {
1046
- onClickAway: () => g && m(!1),
1040
+ onClickAway: () => g && f(!1),
1047
1041
  children: /* @__PURE__ */ n("div", {
1048
1042
  children: /* @__PURE__ */ n(Ae, {
1049
1043
  data: i,
@@ -1060,7 +1054,7 @@ function mt({
1060
1054
  }, ...Array.isArray(o) ? o : [o]];
1061
1055
  return /* @__PURE__ */ C(p, {
1062
1056
  sx: b,
1063
- children: [d.map((u) => u ? l ? l(u) : /* @__PURE__ */ n(fe, {
1057
+ children: [d.map((u) => u ? l ? l(u) : /* @__PURE__ */ n(me, {
1064
1058
  label: u.name,
1065
1059
  variant: "filled",
1066
1060
  size: "small",
@@ -1070,11 +1064,11 @@ function mt({
1070
1064
  }, u.id) : null), t && !r && /* @__PURE__ */ n(E, {
1071
1065
  color: "inherit",
1072
1066
  size: "small",
1073
- onClick: () => m(!0),
1067
+ onClick: () => f(!0),
1074
1068
  sx: {
1075
1069
  color: "grey.400"
1076
1070
  },
1077
- children: /* @__PURE__ */ n(pe, {
1071
+ children: /* @__PURE__ */ n(re, {
1078
1072
  sx: {
1079
1073
  fontSize: 20
1080
1074
  }
@@ -1082,19 +1076,19 @@ function mt({
1082
1076
  }), t && r && /* @__PURE__ */ n(A, {
1083
1077
  color: "inherit",
1084
1078
  variant: "outlined",
1085
- startIcon: /* @__PURE__ */ n(me, {}),
1086
- onClick: () => m(!0),
1079
+ startIcon: /* @__PURE__ */ n(oe, {}),
1080
+ onClick: () => f(!0),
1087
1081
  children: "Edit labels"
1088
1082
  })]
1089
1083
  });
1090
1084
  }
1091
1085
  export {
1092
- ut as LabelManager,
1086
+ lt as LabelManager,
1093
1087
  Ae as LabelPicker,
1094
1088
  F as LabelTree,
1095
- mt as Labels,
1096
- pt as LabelsProvider,
1089
+ st as Labels,
1090
+ at as LabelsProvider,
1097
1091
  Ie as transformLabels,
1098
1092
  U as useLabelsContext,
1099
- ht as useLabelsUpdateOnDestroy
1093
+ it as useLabelsUpdateOnDestroy
1100
1094
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/material/ClickAwayListener"),require("react-color"),require("@arcblock/ux/lib/Dialog"),require("@mui/material"),require("@mui/icons-material/Translate"),require("@mui/material/Popover"),require("@arcblock/ux/lib/Locale/context"),require("@mui/material/Alert"),require("@mui/icons-material/Edit"),require("@mui/icons-material/LabelOutlined"),require("@mui/material/Chip")):typeof define=="function"&&define.amd?define(["exports","react","@mui/icons-material/ExpandMore","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","react/jsx-runtime","lodash/omit","react-select","@mui/material/Typography","@mui/material/Button","@mui/material/IconButton","@mui/icons-material/DeleteOutlineOutlined","@mui/icons-material/EditOutlined","@mui/icons-material/Add","@mui/material/TextField","@mui/material/ClickAwayListener","react-color","@arcblock/ux/lib/Dialog","@mui/material","@mui/icons-material/Translate","@mui/material/Popover","@arcblock/ux/lib/Locale/context","@mui/material/Alert","@mui/icons-material/Edit","@mui/icons-material/LabelOutlined","@mui/material/Chip"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.DiscussKitComponents={},i.React,i.ExpandMoreIcon,i.Box,i.styles,i.reactArborist,i.react$1,i.jsxRuntime,i.omit,i.Select,i.Typography,i.Button,i.IconButton,i.DeleteOutlineOutlinedIcon,i.EditOutlinedIcon,i.AddIcon,i.TextField,i.ClickAwayListener,i.reactColor,i.Dialog,i.material,i.TranslateIcon,i.Popover,i.context,i.Alert,i.EditIcon,i.LabelOutlinedIcon,i.Chip))})(this,function(i,u,U,Y,D,Z,G,e,X,E,R,ee,te,re,ne,le,ae,oe,se,ie,T,de,ce,F,ue,fe,he,pe){"use strict";const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},j=I(U),p=I(Y),me=I(X),ge=I(E),ye=I(R),k=I(ee),z=I(te),xe=I(re),Ce=I(ne),ve=I(le),P=I(ae),W=I(oe),V=I(ie),be=I(de),Se=I(ce),Ie=I(ue),we=I(fe),_e=I(he),Oe=I(pe),Te=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),ke=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),H=u.createContext({});function qe({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:a}){const n=m=>r.indexOf(m)!==-1,o=m=>{Array.from(new Set(r).add(m)),s==null||s(m)},d=u.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:o,renderItem:l}),[r]);return e.jsx(H.Provider,{value:d,children:a})}const Ae=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function ze({node:t}){return Ae(t)?e.jsx("span",{}):t.isOpen?e.jsx(j.default,{style:{fontSize:20}}):e.jsx(j.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Le({node:t,style:r,dragHandle:s}){const{selectable:l,select:a,isSelected:n,renderItem:o}=u.useContext(H),{data:d}=t,m=d.icon?e.jsx(G.Icon,{icon:d.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:d.color||"#ddd"}}),x=f=>{f.stopPropagation(),t.isInternal&&t.toggle()},g=f=>{f.stopPropagation(),l&&a(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(p.default,{sx:{display:"flex",cursor:"pointer"},onClick:x,children:e.jsx(ze,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:m}),e.jsx(p.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),l&&n(t.id)&&e.jsx(ke,{})]});return e.jsxs(p.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:s,onClick:g,children:[!o&&C,!!o&&o(C,t.data)]})}const Be=D.styled(p.default)`
1
+ (function(f,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react"),require("@mui/icons-material"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/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","@mui/icons-material","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","react/jsx-runtime","lodash/omit","react-select","@mui/material/Typography","@mui/material/Button","@mui/material/IconButton","@mui/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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f.DiscussKitComponents={},f.React,f.iconsMaterial,f.Box,f.styles,f.reactArborist,f.react$1,f.jsxRuntime,f.omit,f.Select,f.Typography,f.Button,f.IconButton,f.TextField,f.ClickAwayListener,f.reactColor,f.Dialog,f.material,f.Popover,f.context,f.Alert,f.Chip))})(this,function(f,c,z,U,F,Y,Z,e,G,N,X,R,ee,te,re,ne,le,_,oe,j,ae,se){"use strict";const T=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},p=T(U),ie=T(G),de=T(N),ce=T(X),A=T(R),q=T(ee),E=T(te),W=T(re),V=T(le),ue=T(oe),fe=T(ae),he=T(se),pe=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),ge=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),H=c.createContext({});function ye({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:o}){const n=g=>r.indexOf(g)!==-1,a=g=>{Array.from(new Set(r).add(g)),s==null||s(g)},i=c.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:l}),[r]);return e.jsx(H.Provider,{value:i,children:o})}const xe=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function me({node:t}){return xe(t)?e.jsx("span",{}):t.isOpen?e.jsx(z.ExpandMore,{style:{fontSize:20}}):e.jsx(z.ExpandMore,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Ce({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=c.useContext(H),{data:i}=t,g=i.icon?e.jsx(Z.Icon,{icon:i.icon,style:{fontSize:18}}):e.jsx(pe,{style:{fontSize:18,color:i.color||"#ddd"}}),m=u=>{u.stopPropagation(),t.isInternal&&t.toggle()},y=u=>{u.stopPropagation(),l&&o(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(p.default,{sx:{display:"flex",cursor:"pointer"},onClick:m,children:e.jsx(me,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:g}),e.jsx(p.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),l&&n(t.id)&&e.jsx(ge,{})]});return e.jsxs(p.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:s,onClick:y,children:[!a&&C,!!a&&a(C,t.data)]})}const ve=F.styled(p.default)`
2
2
  > div,
3
3
  > div > div,
4
4
  > div > div > div {
@@ -11,7 +11,7 @@
11
11
  .label-tree-item {
12
12
  width: 100%;
13
13
  }
14
- `;function L({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:a=28,renderItem:n,sx:o,...d}){const m=u.useRef(),x=[...Array.isArray(o)?o:[o]],[g,C]=u.useState(0),f=u.useCallback(()=>{var h,S;C((((S=(h=m.current)==null?void 0:h.visibleNodes)==null?void 0:S.length)||0)*a)},[a]);u.useEffect(()=>{f()},[t,f]);const b=()=>{setTimeout(f)};return e.jsx(qe,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Be,{...d,sx:x,children:e.jsx(Z.Tree,{data:t,rowHeight:a,height:g,indent:32,ref:m,onToggle:b,children:Le})})})}const q=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...q(s.children)),r},[]),J=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=J(r.children)),r}),Ee=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},K=t=>{const r=t.reduce((a,n)=>(a[n.id]=a[n.id]||{},n.parentId&&(a[n.id].parent=n.parentId,a[n.parentId]=a[n.parentId]||{},a[n.parentId].children=a[n.parentId].children||[],a[n.parentId].children.push(n.id)),a),{}),s=t.map(({parentId:a,translation:n,...o})=>({...o,translation:Ee(n),children:[]})),l=s.reduce((a,n)=>({...a,[n.id]:n}),{});return s.forEach(a=>{const n=r[a.id];n.parent&&l[n.parent]&&(a.parent=l[n.parent]),n.children&&(a.children=n.children.map(o=>l[o]))}),s.filter(a=>!a.parent)},Pe=t=>{const{options:r,getValue:s,selectProps:l,selectOption:a}=t,n=s(),o=d=>{const m=r.find(x=>x.data.id===d);m&&a(m)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...me.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(L,{data:l.data,selectable:!0,onSelect:o,selected:n.map(d=>d.data.id)})})}),t.addon]})},Me=({children:t,...r})=>{const[s,l]=t,a=Array.isArray(s)?s.length:0;return e.jsxs(E.components.ValueContainer,{...r,children:[e.jsx(p.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:a?"Labels":"Filter by labels"}),!!a&&e.jsx(p.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:a}),l]})},Ne={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function $({data:t,value:r=[],editable:s=!1,addon:l,onChange:a,compact:n,isMulti:o=!0,maxHeight:d=264,...m}){const x=u.useRef(null),g=u.useMemo(()=>q(t).map(y=>({data:y,label:y.name,value:y.id})),[t]),C=g.reduce((y,O)=>({...y,[O.data.id]:O}),{}),f=Array.isArray(r)?r:[r],b=f.map(y=>C[y]),h=u.useRef({prev:f.map(y=>{var O;return((O=C[y])==null?void 0:O.data)||""})}),S=(y,O)=>{!o||!Array.isArray(y)?a(y?[y.data]:[]):h.current.current=y.map(c=>c.data),["clear","remove-value"].includes(O.action)&&x.current&&setTimeout(()=>{var c;return(c=x==null?void 0:x.current)==null?void 0:c.blur()},1)},N=()=>{h.current.current&&JSON.stringify(h.current.prev.map(O=>O.id))!==JSON.stringify(h.current.current.map(O=>O.id))&&(a(h.current.current),h.current.prev=h.current.current)};return e.jsx(p.default,{...m,children:e.jsx(ge.default,{ref:x,defaultValue:b,options:g,onChange:S,components:{MenuList:y=>e.jsx(Pe,{...y,addon:l}),...n&&{ValueContainer:Me}},placeholder:"Select labels",styles:{...n&&Ne,menu:y=>({...y,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:y=>({...y,overflowY:"auto",maxHeight:`${d}px`})},theme:y=>({...y,colors:{...y.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:o,closeMenuOnSelect:!o,onMenuClose:N,isClearable:!0,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,a=arguments.length;l<a;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},B.apply(this,arguments)};function De(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),a,n=[],o;try{for(;(r===void 0||r-- >0)&&!(a=l.next()).done;)n.push(a.value)}catch(d){o={error:d}}finally{try{a&&!a.done&&(s=l.return)&&s.call(l)}finally{if(o)throw o.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var Fe=function(t){return typeof t=="function"},je=function(t){var r=De(u.useState(t),2),s=r[0],l=r[1],a=u.useCallback(function(n){l(function(o){var d=Fe(n)?n(o):n;return d?B(B({},o),d):o})},[]);return[s,a]};const We=je;function Ve({I18NProps:t,...r}){const{languages:s}=F.useLocaleContext(),{translation:l,onChange:a}=t,[n,o]=u.useState(null),d=g=>{const C=g.currentTarget.closest(".MuiInputBase-root");C&&o(C)},m=()=>{o(null)},x=s.filter(g=>g.code!=="en");return e.jsx(T.TextField,{...r,InputProps:{endAdornment:e.jsxs(T.InputAdornment,{position:"end",children:[e.jsx(T.IconButton,{edge:"end",onClick:d,children:e.jsx(be.default,{})}),e.jsx(Se.default,{open:!!n,anchorEl:n,onClose:m,transformOrigin:{vertical:"top",horizontal:"right"},anchorOrigin:{vertical:"bottom",horizontal:"right"},PaperProps:{sx:{width:n==null?void 0:n.clientWidth,maxHeight:200,overflowY:"auto",bgcolor:"grey.50"}},elevation:1,sx:{mt:2},children:e.jsx(T.Box,{sx:{p:2},children:x.map(({code:g,name:C})=>e.jsxs(T.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(T.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(T.Box,{sx:{flex:1},children:e.jsx(T.TextField,{value:l[g]||"",size:"small",sx:{width:1},onChange:f=>a({...l,[g]:f.target.value})})})]},g))})})]})}})}function He({open:t,initialLabel:r,onSubmit:s,onClose:l,...a}){const n=!(r!=null&&r.id),[o,d]=We({name:(r==null?void 0:r.name)||"",color:(r==null?void 0:r.color)||"#ddd",slug:(r==null?void 0:r.id)||"",translation:(r==null?void 0:r.translation)||{}}),m=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),x=u.useMemo(()=>n?o.name&&o.color&&o.slug&&m(o.color):o.name&&o.color&&m(o.color),[o,n]),[g,C]=u.useState(!1),f=()=>{s({...r,name:o.name,color:o.color,id:o.slug,translation:o.translation})},b=S=>{d({color:S.hex}),setTimeout(()=>C(!1))},h=S=>{d({color:S.target.value})};return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:f,disabled:!x,children:n?"Create":"Save Changes"})]}),onClose:l,...a,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ve,{label:"Name",value:o.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>d({name:S.target.value}),I18NProps:{translation:o.translation,onChange:S=>d({translation:S})}}),e.jsx(P.default,{label:"Slug",value:o.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>d({slug:S.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(P.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(W.default,{onClickAway:()=>C(!1),children:e.jsxs(p.default,{sx:{position:"relative",mt:2},children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(p.default,{sx:{width:30,height:30,bgcolor:o.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(P.default,{label:"",value:o.color,size:"small",onChange:h,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),g&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(se.GithubPicker,{color:o.color,onChangeComplete:b})})]})})]})})}function Je({open:t,label:r,onSubmit:s,onClose:l,...a}){return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:s,children:"Delete"})]}),onClose:l,...a,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ie.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(L,{data:[r]})]})})}const Ke=D.styled(L)`
14
+ `;function O({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:o=28,renderItem:n,sx:a,...i}){const g=c.useRef(),m=[...Array.isArray(a)?a:[a]],[y,C]=c.useState(0),u=c.useCallback(()=>{var h,S;C((((S=(h=g.current)==null?void 0:h.visibleNodes)==null?void 0:S.length)||0)*o)},[o]);c.useEffect(()=>{u()},[t,u]);const b=()=>{setTimeout(u)};return e.jsx(ye,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(ve,{...i,sx:m,children:e.jsx(Y.Tree,{data:t,rowHeight:o,height:y,indent:32,ref:g,onToggle:b,children:Ce})})})}const B=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...B(s.children)),r},[]),J=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=J(r.children)),r}),be=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},K=t=>{const r=t.reduce((o,n)=>(o[n.id]=o[n.id]||{},n.parentId&&(o[n.id].parent=n.parentId,o[n.parentId]=o[n.parentId]||{},o[n.parentId].children=o[n.parentId].children||[],o[n.parentId].children.push(n.id)),o),{}),s=t.map(({parentId:o,translation:n,...a})=>({...a,translation:be(n),children:[]})),l=s.reduce((o,n)=>({...o,[n.id]:n}),{});return s.forEach(o=>{const n=r[o.id];n.parent&&l[n.parent]&&(o.parent=l[n.parent]),n.children&&(o.children=n.children.map(a=>l[a]))}),s.filter(o=>!o.parent)},Se=t=>{const{options:r,getValue:s,selectProps:l,selectOption:o}=t,n=s(),a=i=>{const g=r.find(m=>m.data.id===i);g&&o(g)};return e.jsxs(e.Fragment,{children:[e.jsx(N.components.MenuList,{...ie.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(O,{data:l.data,selectable:!0,onSelect:a,selected:n.map(i=>i.data.id)})})}),t.addon]})},we=({children:t,...r})=>{const[s,l]=t,o=Array.isArray(s)?s.length:0;return e.jsxs(N.components.ValueContainer,{...r,children:[e.jsx(p.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&e.jsx(p.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:o}),l]})},Ie={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function $({data:t,value:r=[],editable:s=!1,addon:l,onChange:o,compact:n,isMulti:a=!0,maxHeight:i=264,...g}){const m=c.useRef(null),y=c.useMemo(()=>B(t).map(x=>({data:x,label:x.name,value:x.id})),[t]),C=y.reduce((x,k)=>({...x,[k.data.id]:k}),{}),u=Array.isArray(r)?r:[r],b=u.map(x=>C[x]),h=c.useRef({prev:u.map(x=>{var k;return((k=C[x])==null?void 0:k.data)||""})}),S=(x,k)=>{!a||!Array.isArray(x)?o(x?[x.data]:[]):h.current.current=x.map(d=>d.data),["clear","remove-value"].includes(k.action)&&m.current&&setTimeout(()=>{var d;return(d=m==null?void 0:m.current)==null?void 0:d.blur()},1)},M=()=>{h.current.current&&JSON.stringify(h.current.prev.map(k=>k.id))!==JSON.stringify(h.current.current.map(k=>k.id))&&(o(h.current.current),h.current.prev=h.current.current)};return e.jsx(p.default,{...g,children:e.jsx(de.default,{ref:m,defaultValue:b,options:y,onChange:S,components:{MenuList:x=>e.jsx(Se,{...x,addon:l}),...n&&{ValueContainer:we}},placeholder:"Select labels",styles:{...n&&Ie,menu:x=>({...x,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:x=>({...x,overflowY:"auto",maxHeight:`${i}px`})},theme:x=>({...x,colors:{...x.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:a,closeMenuOnSelect:!a,onMenuClose:M,isClearable:!0,data:t})})}var P=function(){return P=Object.assign||function(r){for(var s,l=1,o=arguments.length;l<o;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},P.apply(this,arguments)};function ke(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),o,n=[],a;try{for(;(r===void 0||r-- >0)&&!(o=l.next()).done;)n.push(o.value)}catch(i){a={error:i}}finally{try{o&&!o.done&&(s=l.return)&&s.call(l)}finally{if(a)throw a.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var Te=function(t){return typeof t=="function"},ze=function(t){var r=ke(c.useState(t),2),s=r[0],l=r[1],o=c.useCallback(function(n){l(function(a){var i=Te(n)?n(a):n;return i?P(P({},a),i):a})},[]);return[s,o]};const _e=ze;function Ae({I18NProps:t,...r}){const{languages:s}=j.useLocaleContext(),{translation:l,onChange:o}=t,[n,a]=c.useState(null),i=y=>{const C=y.currentTarget.closest(".MuiInputBase-root");C&&a(C)},g=()=>{a(null)},m=s.filter(y=>y.code!=="en");return e.jsx(_.TextField,{...r,InputProps:{endAdornment:e.jsxs(_.InputAdornment,{position:"end",children:[e.jsx(_.IconButton,{edge:"end",onClick:i,children:e.jsx(z.Translate,{})}),e.jsx(ue.default,{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(_.Box,{sx:{p:2},children:m.map(({code:y,name:C})=>e.jsxs(_.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(_.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(_.Box,{sx:{flex:1},children:e.jsx(_.TextField,{value:l[y]||"",size:"small",sx:{width:1},onChange:u=>o({...l,[y]:u.target.value})})})]},y))})})]})}})}function Be({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,i]=_e({name:(r==null?void 0:r.name)||"",color:(r==null?void 0:r.color)||"#ddd",slug:(r==null?void 0:r.id)||"",translation:(r==null?void 0:r.translation)||{}}),g=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),m=c.useMemo(()=>n?a.name&&a.color&&a.slug&&g(a.color):a.name&&a.color&&g(a.color),[a,n]),[y,C]=c.useState(!1),u=()=>{s({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},b=S=>{i({color:S.hex}),setTimeout(()=>C(!1))},h=S=>{i({color:S.target.value})};return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(A.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(A.default,{color:"primary",variant:"contained",size:"small",onClick:u,disabled:!m,children:n?"Create":"Save Changes"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ae,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>i({name:S.target.value}),I18NProps:{translation:a.translation,onChange:S=>i({translation:S})}}),e.jsx(E.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>i({slug:S.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(E.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(W.default,{onClickAway:()=>C(!1),children:e.jsxs(p.default,{sx:{position:"relative",mt:2},children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(p.default,{sx:{width:30,height:30,bgcolor:a.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(E.default,{label:"",value:a.color,size:"small",onChange:h,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),y&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(ne.GithubPicker,{color:a.color,onChangeComplete:b})})]})})]})})}function Le({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(A.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(A.default,{color:"primary",variant:"contained",size:"small",onClick:s,children:"Delete"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(fe.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(O,{data:[r]})]})})}const qe=F.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 $e({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},className:"label-translation-tag",children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function Qe({data:t,api:r,...s}){const[l,a]=u.useState(null),[n,o]=u.useState(null),[d,m]=u.useState(J(t)),x=u.useMemo(()=>q(d),[d]),g=u.useMemo(()=>{const c=(v,_)=>v.map(w=>(_&&(w.parent=_),w.children&&(w.children=c(w.children,w)),w));return c(d)},[d]),C=c=>{var v,_;c.parent?(c.parent.children=(_=(v=c.parent)==null?void 0:v.children)==null?void 0:_.map(w=>w.id===c.id?{...c}:w),C(c.parent)):m(d.map(w=>w.id===c.id?{...c}:w))},f=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),m([...d])):m([...d,c])},b=c=>{var v;c.parent?c.parent.children=(v=c.parent.children)==null?void 0:v.filter(_=>_.id!==c.id):m(d.filter(_=>_.id!==c.id))},h=c=>{if(l)return;a({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{l||a(c)},N=async c=>{if(!l)return;const{parent:v,children:_,translation:w,...A}=c;l.id?(await r.updateLabel({...A,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),C(c)):(await r.createLabel({...A,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),f(c)),a(null)},y=async()=>{!n||(await r.deleteLabel(n.id),b(n),o(null))},O=(c,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(p.default,{children:c}),v.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(v.translation).map(_=>{var A;const w=(A=v.translation)==null?void 0:A[_];return w?e.jsx($e,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>h(v),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(z.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>o(v),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,className:"label-container",children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(ye.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>h(),children:"New label"})]}),e.jsxs(p.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(p.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[x.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(Ke,{data:g,selected:[],renderItem:O,rowHeight:64})})]}),e.jsx(He,{open:!!l,onClose:()=>a(null),initialLabel:l,onSubmit:N},l==null?void 0:l.id),e.jsx(Je,{open:!!n,onClose:()=>o(null),label:n,onSubmit:y},n==null?void 0:n.id)]})}const Q=u.createContext({}),M=()=>u.useContext(Q),Ue=()=>{const{updateLabels:t}=M();u.useEffect(()=>()=>{t()},[])};function Ye({fetchLabels:t,children:r}){const{locale:s}=F.useLocaleContext(),[l,a]=u.useState({loading:!0,labels:[],updateCounter:1});u.useEffect(()=>{(async()=>{try{a(h=>({...h,loading:!0}));const b=await t();a(h=>({...h,loading:!1,labels:K(b)}))}catch(b){console.error(b),a(h=>({...h,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=u.useMemo(()=>{var b;return(b=l.labels)!=null&&b.length?q(l.labels).reduce((h,S)=>({...h,[S.id]:S}),{}):{}},[l.labels]),o=u.useCallback(f=>{var b;return{...f,name:((b=f.translation)==null?void 0:b[s])||f.name}},[s]),d=u.useCallback(f=>f.filter(Boolean).map(b=>n[b]).map(o),[n,o]),m=u.useCallback(f=>(f==null?void 0:f.split(","))||[],[]),x=u.useCallback((f=[])=>{if(!!(f!=null&&f.length))return f.join(",")},[]),g=u.useMemo(()=>l.labels.map(o),[l.labels,o]),C=u.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>a(f=>({...f,updateCounter:++l.updateCounter})),getLabelsById:d,parseLabelIds:m,stringifyLabelIds:x,localizedLabels:g,flattenedLabels:q(g||[])}),[l,d,m,x,g]);return e.jsx(Q.Provider,{value:C,children:r})}function Ze({labels:t,editable:r,onChange:s,sx:l,renderLabel:a}){const n=!(t!=null&&t.length),{labels:o,loading:d,getLabelsById:m}=M(),[x,g]=u.useState(!1);if(d||!r&&n)return null;const C=h=>{s==null||s(h),setTimeout(()=>{g(!1)},300)};if(x)return e.jsx(W.default,{onClickAway:()=>x&&g(!1),children:e.jsx("div",{children:e.jsx($,{data:o,value:t||[],onChange:C})})});const f=m(t||[]),b=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:b,children:[f.map(h=>h?a?a(h):e.jsx(Oe.default,{label:h.name,variant:"filled",size:"small",sx:{borderRadius:1}},h.id):null),r&&!n&&e.jsx(z.default,{color:"inherit",size:"small",onClick:()=>g(!0),sx:{color:"grey.400"},children:e.jsx(we.default,{sx:{fontSize:20}})}),r&&n&&e.jsx(k.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(_e.default,{}),onClick:()=>g(!0),children:"Edit labels"})]})}i.LabelManager=Qe,i.LabelPicker=$,i.LabelTree=L,i.Labels=Ze,i.LabelsProvider=Ye,i.transformLabels=K,i.useLabelsContext=M,i.useLabelsUpdateOnDestroy=Ue,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
34
+ `;function Oe({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},className:"label-translation-tag",children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function Pe({data:t,api:r,...s}){const[l,o]=c.useState(null),[n,a]=c.useState(null),[i,g]=c.useState(J(t)),m=c.useMemo(()=>B(i),[i]),y=c.useMemo(()=>{const d=(v,I)=>v.map(w=>(I&&(w.parent=I),w.children&&(w.children=d(w.children,w)),w));return d(i)},[i]),C=d=>{var v,I;d.parent?(d.parent.children=(I=(v=d.parent)==null?void 0:v.children)==null?void 0:I.map(w=>w.id===d.id?{...d}:w),C(d.parent)):g(i.map(w=>w.id===d.id?{...d}:w))},u=d=>{d.parent?(d.parent.children=d.parent.children||[],d.parent.children.push(d),g([...i])):g([...i,d])},b=d=>{var v;d.parent?d.parent.children=(v=d.parent.children)==null?void 0:v.filter(I=>I.id!==d.id):g(i.filter(I=>I.id!==d.id))},h=d=>{if(l)return;o({id:"",name:"New label",parent:d,color:"#dddddd"})},S=d=>{l||o(d)},M=async d=>{if(!l)return;const{parent:v,children:I,translation:w,...L}=d;l.id?(await r.updateLabel({...L,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),C(d)):(await r.createLabel({...L,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),u(d)),o(null)},x=async()=>{!n||(await r.deleteLabel(n.id),b(n),a(null))},k=(d,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(p.default,{children:d}),v.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(v.translation).map(I=>{var L;const w=(L=v.translation)==null?void 0:L[I];return w?e.jsx(Oe,{locale:I,value:w},I):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(q.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>h(v),children:e.jsx(z.Add,{sx:{fontSize:20}})}),e.jsx(q.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(z.EditOutlined,{sx:{fontSize:18}})}),e.jsx(q.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(v),children:e.jsx(z.DeleteOutlineOutlined,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,className:"label-container",children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(ce.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(A.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>h(),children:"New label"})]}),e.jsxs(p.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(p.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[m.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(qe,{data:y,selected:[],renderItem:k,rowHeight:64})})]}),e.jsx(Be,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:M},l==null?void 0:l.id),e.jsx(Le,{open:!!n,onClose:()=>a(null),label:n,onSubmit:x},n==null?void 0:n.id)]})}const Q=c.createContext({}),D=()=>c.useContext(Q),Ne=()=>{const{updateLabels:t}=D();c.useEffect(()=>()=>{t()},[])};function Ee({fetchLabels:t,children:r}){const{locale:s}=j.useLocaleContext(),[l,o]=c.useState({loading:!0,labels:[],updateCounter:1});c.useEffect(()=>{(async()=>{try{o(h=>({...h,loading:!0}));const b=await t();o(h=>({...h,loading:!1,labels:K(b)}))}catch(b){console.error(b),o(h=>({...h,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=c.useMemo(()=>{var b;return(b=l.labels)!=null&&b.length?B(l.labels).reduce((h,S)=>({...h,[S.id]:S}),{}):{}},[l.labels]),a=c.useCallback(u=>{var b;return{...u,name:((b=u.translation)==null?void 0:b[s])||u.name}},[s]),i=c.useCallback(u=>u.filter(Boolean).map(b=>n[b]).map(a),[n,a]),g=c.useCallback(u=>(u==null?void 0:u.split(","))||[],[]),m=c.useCallback((u=[])=>{if(!!(u!=null&&u.length))return u.join(",")},[]),y=c.useMemo(()=>l.labels.map(a),[l.labels,a]),C=c.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>o(u=>({...u,updateCounter:++l.updateCounter})),getLabelsById:i,parseLabelIds:g,stringifyLabelIds:m,localizedLabels:y,flattenedLabels:B(y||[])}),[l,i,g,m,y]);return e.jsx(Q.Provider,{value:C,children:r})}function De({labels:t,editable:r,onChange:s,sx:l,renderLabel:o}){const n=!(t!=null&&t.length),{labels:a,loading:i,getLabelsById:g}=D(),[m,y]=c.useState(!1);if(i||!r&&n)return null;const C=h=>{s==null||s(h),setTimeout(()=>{y(!1)},300)};if(m)return e.jsx(W.default,{onClickAway:()=>m&&y(!1),children:e.jsx("div",{children:e.jsx($,{data:a,value:t||[],onChange:C})})});const u=g(t||[]),b=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:b,children:[u.map(h=>h?o?o(h):e.jsx(he.default,{label:h.name,variant:"filled",size:"small",sx:{borderRadius:1}},h.id):null),r&&!n&&e.jsx(q.default,{color:"inherit",size:"small",onClick:()=>y(!0),sx:{color:"grey.400"},children:e.jsx(z.Edit,{sx:{fontSize:20}})}),r&&n&&e.jsx(A.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(z.LabelOutlined,{}),onClick:()=>y(!0),children:"Edit labels"})]})}f.LabelManager=Pe,f.LabelPicker=$,f.LabelTree=O,f.Labels=De,f.LabelsProvider=Ee,f.transformLabels=K,f.useLabelsContext=D,f.useLabelsUpdateOnDestroy=Ne,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.5.103",
3
+ "version": "1.5.105",
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": "118547ab15173d00b50295f872be7e363470d004"
78
+ "gitHead": "7f57f0b1c40c2c4f91c73afab103257785d78687"
79
79
  }