@blocklet/labels 1.5.55 → 1.5.56
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/components/label/context.d.ts +1 -1
- package/dist/components/label/label-delete-dialog.d.ts +2 -1
- package/dist/components/label/label-form-dialog.d.ts +2 -1
- package/dist/components/label/label-manager.d.ts +2 -1
- package/dist/components/label/label-picker.d.ts +2 -1
- package/dist/components/label/label-tree.d.ts +1 -1
- package/dist/components/label/labels.d.ts +2 -1
- package/dist/components/label/translation-input.d.ts +2 -1
- package/dist/components/label/types.d.ts +1 -1
- package/dist/index.es.js +42 -42
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
|
@@ -13,5 +13,5 @@ interface LabelsContextValue {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const useLabelsContext: () => LabelsContextValue;
|
|
15
15
|
export declare const useLabelsUpdateOnDestroy: () => void;
|
|
16
|
-
export declare function LabelsProvider({ fetchLabels, children }: LabelsProviderProps):
|
|
16
|
+
export declare function LabelsProvider({ fetchLabels, children }: LabelsProviderProps): JSX.Element;
|
|
17
17
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Label } from './types';
|
|
2
3
|
interface LabelDeleteDialogProps {
|
|
3
4
|
open: boolean;
|
|
@@ -5,5 +6,5 @@ interface LabelDeleteDialogProps {
|
|
|
5
6
|
label: Label;
|
|
6
7
|
onSubmit: () => void;
|
|
7
8
|
}
|
|
8
|
-
export default function LabelDeleteDialog({ open, label, onSubmit, onClose, ...rest }: LabelDeleteDialogProps):
|
|
9
|
+
export default function LabelDeleteDialog({ open, label, onSubmit, onClose, ...rest }: LabelDeleteDialogProps): JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { Label } from './types';
|
|
2
3
|
interface LabelFormDialogProps {
|
|
3
4
|
open: boolean;
|
|
@@ -5,5 +6,5 @@ interface LabelFormDialogProps {
|
|
|
5
6
|
initialLabel: Label | null;
|
|
6
7
|
onSubmit: (payload: Label) => void;
|
|
7
8
|
}
|
|
8
|
-
export default function LabelFormDialog({ open, initialLabel, onSubmit, onClose, ...rest }: LabelFormDialogProps):
|
|
9
|
+
export default function LabelFormDialog({ open, initialLabel, onSubmit, onClose, ...rest }: LabelFormDialogProps): JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Label, LabelDto } from './types';
|
|
2
3
|
interface API {
|
|
3
4
|
createLabel: (label: LabelDto) => Promise<void>;
|
|
@@ -8,5 +9,5 @@ interface LabelManagerProps {
|
|
|
8
9
|
data: Label[];
|
|
9
10
|
api: API;
|
|
10
11
|
}
|
|
11
|
-
export default function LabelManager({ data, api, ...rest }: LabelManagerProps):
|
|
12
|
+
export default function LabelManager({ data, api, ...rest }: LabelManagerProps): JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { GroupBase } from 'react-select';
|
|
2
3
|
import { Label } from './types';
|
|
3
4
|
interface LabelPickerProps {
|
|
@@ -15,5 +16,5 @@ declare module 'react-select/dist/declarations/src/Select' {
|
|
|
15
16
|
data: Label[];
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
export default function LabelPicker({ data, value, editable, addon, onChange, compact, isMulti, maxHeight, ...rest }: LabelPickerProps):
|
|
19
|
+
export default function LabelPicker({ data, value, editable, addon, onChange, compact, isMulti, maxHeight, ...rest }: LabelPickerProps): JSX.Element;
|
|
19
20
|
export {};
|
|
@@ -13,5 +13,5 @@ export interface LabelTreeProps extends SharedProps {
|
|
|
13
13
|
sx?: SxProps;
|
|
14
14
|
rowHeight?: number;
|
|
15
15
|
}
|
|
16
|
-
export default function LabelTree({ data, selectable, selected, onSelect, rowHeight, renderItem, sx, ...rest }: LabelTreeProps):
|
|
16
|
+
export default function LabelTree({ data, selectable, selected, onSelect, rowHeight, renderItem, sx, ...rest }: LabelTreeProps): JSX.Element;
|
|
17
17
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { SxProps } from '@mui/system';
|
|
2
3
|
import { Label } from './types';
|
|
3
4
|
interface LabelsProps {
|
|
@@ -6,5 +7,5 @@ interface LabelsProps {
|
|
|
6
7
|
onChange?: (labels: Label[]) => void;
|
|
7
8
|
sx?: SxProps;
|
|
8
9
|
}
|
|
9
|
-
export default function Labels({ labels, editable, onChange, sx }: LabelsProps):
|
|
10
|
+
export default function Labels({ labels, editable, onChange, sx }: LabelsProps): JSX.Element | null;
|
|
10
11
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { TextFieldProps } from '@mui/material';
|
|
2
3
|
import type { Translation } from './types';
|
|
3
4
|
interface Props {
|
|
@@ -6,5 +7,5 @@ interface Props {
|
|
|
6
7
|
onChange: (translation: Translation) => void;
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
|
-
export default function TranslationInput({ I18NProps, ...rest }: TextFieldProps & Props):
|
|
10
|
+
export default function TranslationInput({ I18NProps, ...rest }: TextFieldProps & Props): JSX.Element;
|
|
10
11
|
export {};
|
package/dist/index.es.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { createContext as
|
|
1
|
+
import { createContext as q, useRef as D, useState as z, useCallback as k, useEffect as W, useMemo as T, useContext as H } from "react";
|
|
2
2
|
import R from "@mui/icons-material/ExpandMore";
|
|
3
3
|
import h from "@mui/material/Box";
|
|
4
|
-
import { styled as
|
|
4
|
+
import { styled as J } from "@mui/material/styles";
|
|
5
5
|
import { Tree as X } from "react-arborist";
|
|
6
6
|
import { Icon as ee } from "@iconify/react";
|
|
7
7
|
import { jsx as n, jsxs as v, Fragment as P } from "react/jsx-runtime";
|
|
8
8
|
import te from "lodash/omit";
|
|
9
|
-
import ne, { components as
|
|
9
|
+
import ne, { components as _ } from "react-select";
|
|
10
10
|
import re from "@mui/material/Typography";
|
|
11
11
|
import A from "@mui/material/Button";
|
|
12
12
|
import N from "@mui/material/IconButton";
|
|
13
13
|
import oe from "@mui/icons-material/DeleteOutlineOutlined";
|
|
14
14
|
import le from "@mui/icons-material/EditOutlined";
|
|
15
15
|
import ie from "@mui/icons-material/Add";
|
|
16
|
-
import
|
|
17
|
-
import
|
|
16
|
+
import j from "@mui/material/TextField";
|
|
17
|
+
import $ from "@mui/material/ClickAwayListener";
|
|
18
18
|
import { GithubPicker as se } from "react-color";
|
|
19
19
|
import K from "@arcblock/ux/lib/Dialog";
|
|
20
20
|
import { TextField as V, InputAdornment as ae, IconButton as ce, Box as B } from "@mui/material";
|
|
21
21
|
import de from "@mui/icons-material/Translate";
|
|
22
22
|
import ue from "@mui/material/Popover";
|
|
23
|
-
import { useLocaleContext as
|
|
23
|
+
import { useLocaleContext as Q } from "@arcblock/ux/lib/Locale/context";
|
|
24
24
|
import he from "@mui/material/Alert";
|
|
25
25
|
import pe from "@mui/icons-material/Edit";
|
|
26
26
|
import me from "@mui/icons-material/LabelOutlined";
|
|
@@ -32,7 +32,7 @@ const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
|
32
32
|
...e,
|
|
33
33
|
children: /* @__PURE__ */ n("path", {
|
|
34
34
|
fill: "currentColor",
|
|
35
|
-
d: "
|
|
35
|
+
d: "M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"
|
|
36
36
|
})
|
|
37
37
|
}), xe = (e) => /* @__PURE__ */ n("svg", {
|
|
38
38
|
viewBox: "0 0 24 24",
|
|
@@ -41,9 +41,9 @@ const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
|
41
41
|
...e,
|
|
42
42
|
children: /* @__PURE__ */ n("path", {
|
|
43
43
|
fill: "currentColor",
|
|
44
|
-
d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.
|
|
44
|
+
d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"
|
|
45
45
|
})
|
|
46
|
-
}),
|
|
46
|
+
}), Y = q({});
|
|
47
47
|
function ye({
|
|
48
48
|
selectable: e = !1,
|
|
49
49
|
selected: t = [],
|
|
@@ -63,7 +63,7 @@ function ye({
|
|
|
63
63
|
}),
|
|
64
64
|
[t]
|
|
65
65
|
);
|
|
66
|
-
return /* @__PURE__ */ n(
|
|
66
|
+
return /* @__PURE__ */ n(Y.Provider, {
|
|
67
67
|
value: a,
|
|
68
68
|
children: o
|
|
69
69
|
});
|
|
@@ -96,7 +96,7 @@ function be({
|
|
|
96
96
|
select: o,
|
|
97
97
|
isSelected: r,
|
|
98
98
|
renderItem: i
|
|
99
|
-
} =
|
|
99
|
+
} = H(Y), {
|
|
100
100
|
data: a
|
|
101
101
|
} = e, u = a.icon ? /* @__PURE__ */ n(ee, {
|
|
102
102
|
icon: a.icon,
|
|
@@ -158,7 +158,7 @@ function be({
|
|
|
158
158
|
children: [!i && x, !!i && i(x, e.data)]
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
const Se =
|
|
161
|
+
const Se = J(h)`
|
|
162
162
|
> div,
|
|
163
163
|
> div > div,
|
|
164
164
|
> div > div > div {
|
|
@@ -182,7 +182,7 @@ function F({
|
|
|
182
182
|
sx: i,
|
|
183
183
|
...a
|
|
184
184
|
}) {
|
|
185
|
-
const u =
|
|
185
|
+
const u = D(), m = [...Array.isArray(i) ? i : [i]], [g, x] = z(0), d = k(() => {
|
|
186
186
|
var y, b;
|
|
187
187
|
x((((b = (y = u.current) == null ? void 0 : y.visibleNodes) == null ? void 0 : b.length) || 0) * o);
|
|
188
188
|
}, [o]);
|
|
@@ -213,9 +213,9 @@ function F({
|
|
|
213
213
|
const L = (e) => e.reduce((t, s) => {
|
|
214
214
|
var l;
|
|
215
215
|
return t.push(s), (l = s.children) != null && l.length && t.push(...L(s.children)), t;
|
|
216
|
-
}, []),
|
|
216
|
+
}, []), Z = (e) => e.map((t) => {
|
|
217
217
|
var s;
|
|
218
|
-
return (s = t.children) != null && s.length && (t.children =
|
|
218
|
+
return (s = t.children) != null && s.length && (t.children = Z(t.children)), t;
|
|
219
219
|
}), we = (e, t = null) => {
|
|
220
220
|
try {
|
|
221
221
|
return JSON.parse(e);
|
|
@@ -243,7 +243,7 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
243
243
|
u && o(u);
|
|
244
244
|
};
|
|
245
245
|
return /* @__PURE__ */ v(P, {
|
|
246
|
-
children: [/* @__PURE__ */ n(
|
|
246
|
+
children: [/* @__PURE__ */ n(_.MenuList, {
|
|
247
247
|
...te(e, ["addon"]),
|
|
248
248
|
children: /* @__PURE__ */ n(h, {
|
|
249
249
|
sx: {
|
|
@@ -264,7 +264,7 @@ const L = (e) => e.reduce((t, s) => {
|
|
|
264
264
|
...t
|
|
265
265
|
}) => {
|
|
266
266
|
const [s, l] = e, o = Array.isArray(s) ? s.length : 0;
|
|
267
|
-
return /* @__PURE__ */ v(
|
|
267
|
+
return /* @__PURE__ */ v(_.ValueContainer, {
|
|
268
268
|
...t,
|
|
269
269
|
children: [/* @__PURE__ */ n(h, {
|
|
270
270
|
component: "span",
|
|
@@ -317,14 +317,14 @@ function Ae({
|
|
|
317
317
|
maxHeight: a = 264,
|
|
318
318
|
...u
|
|
319
319
|
}) {
|
|
320
|
-
const m =
|
|
320
|
+
const m = D(null), g = T(() => L(e).map((p) => ({
|
|
321
321
|
data: p,
|
|
322
322
|
label: p.name,
|
|
323
323
|
value: p.id
|
|
324
324
|
})), [e]), x = g.reduce((p, I) => ({
|
|
325
325
|
...p,
|
|
326
326
|
[I.data.id]: I
|
|
327
|
-
}), {}), d = Array.isArray(t) ? t : [t], f = d.map((p) => x[p]), y =
|
|
327
|
+
}), {}), d = Array.isArray(t) ? t : [t], f = d.map((p) => x[p]), y = D({
|
|
328
328
|
prev: d.map((p) => {
|
|
329
329
|
var I;
|
|
330
330
|
return ((I = x[p]) == null ? void 0 : I.data) || "";
|
|
@@ -334,7 +334,7 @@ function Ae({
|
|
|
334
334
|
var c;
|
|
335
335
|
return (c = m == null ? void 0 : m.current) == null ? void 0 : c.blur();
|
|
336
336
|
}, 1);
|
|
337
|
-
},
|
|
337
|
+
}, M = () => {
|
|
338
338
|
y.current.current && JSON.stringify(y.current.prev.map((I) => I.id)) !== JSON.stringify(y.current.current.map((I) => I.id)) && (o(y.current.current), y.current.prev = y.current.current);
|
|
339
339
|
};
|
|
340
340
|
return /* @__PURE__ */ n(h, {
|
|
@@ -381,7 +381,7 @@ function Ae({
|
|
|
381
381
|
isSearchable: !1,
|
|
382
382
|
isMulti: i,
|
|
383
383
|
closeMenuOnSelect: !i,
|
|
384
|
-
onMenuClose:
|
|
384
|
+
onMenuClose: M,
|
|
385
385
|
isClearable: !0,
|
|
386
386
|
data: e
|
|
387
387
|
})
|
|
@@ -435,7 +435,7 @@ function Ee({
|
|
|
435
435
|
}) {
|
|
436
436
|
const {
|
|
437
437
|
languages: s
|
|
438
|
-
} =
|
|
438
|
+
} = Q(), {
|
|
439
439
|
translation: l,
|
|
440
440
|
onChange: o
|
|
441
441
|
} = e, [r, i] = z(null), a = (g) => {
|
|
@@ -591,7 +591,7 @@ function Le({
|
|
|
591
591
|
translation: b
|
|
592
592
|
})
|
|
593
593
|
}
|
|
594
|
-
}), /* @__PURE__ */ n(
|
|
594
|
+
}), /* @__PURE__ */ n(j, {
|
|
595
595
|
label: "Slug",
|
|
596
596
|
value: i.slug,
|
|
597
597
|
size: "small",
|
|
@@ -603,7 +603,7 @@ function Le({
|
|
|
603
603
|
sx: {
|
|
604
604
|
mt: 2
|
|
605
605
|
}
|
|
606
|
-
}), (t == null ? void 0 : t.parent) && /* @__PURE__ */ n(
|
|
606
|
+
}), (t == null ? void 0 : t.parent) && /* @__PURE__ */ n(j, {
|
|
607
607
|
label: "Parent",
|
|
608
608
|
value: t.parent.name,
|
|
609
609
|
size: "small",
|
|
@@ -612,7 +612,7 @@ function Le({
|
|
|
612
612
|
sx: {
|
|
613
613
|
mt: 2
|
|
614
614
|
}
|
|
615
|
-
}), /* @__PURE__ */ n(
|
|
615
|
+
}), /* @__PURE__ */ n($, {
|
|
616
616
|
onClickAway: () => x(!1),
|
|
617
617
|
children: /* @__PURE__ */ v(h, {
|
|
618
618
|
sx: {
|
|
@@ -633,7 +633,7 @@ function Le({
|
|
|
633
633
|
borderRadius: 1
|
|
634
634
|
},
|
|
635
635
|
onClick: () => x(!0)
|
|
636
|
-
}), /* @__PURE__ */ n(
|
|
636
|
+
}), /* @__PURE__ */ n(j, {
|
|
637
637
|
label: "",
|
|
638
638
|
value: i.color,
|
|
639
639
|
size: "small",
|
|
@@ -664,7 +664,7 @@ function Le({
|
|
|
664
664
|
})
|
|
665
665
|
});
|
|
666
666
|
}
|
|
667
|
-
function
|
|
667
|
+
function Me({
|
|
668
668
|
open: e,
|
|
669
669
|
label: t,
|
|
670
670
|
onSubmit: s,
|
|
@@ -708,7 +708,7 @@ function je({
|
|
|
708
708
|
})
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
|
-
const
|
|
711
|
+
const je = J(F)`
|
|
712
712
|
.label-tree-item {
|
|
713
713
|
&:before {
|
|
714
714
|
content: '';
|
|
@@ -729,7 +729,7 @@ const De = _(F)`
|
|
|
729
729
|
padding: 0 16px;
|
|
730
730
|
}
|
|
731
731
|
`;
|
|
732
|
-
function
|
|
732
|
+
function De({
|
|
733
733
|
locale: e,
|
|
734
734
|
value: t
|
|
735
735
|
}) {
|
|
@@ -764,7 +764,7 @@ function ut({
|
|
|
764
764
|
api: t,
|
|
765
765
|
...s
|
|
766
766
|
}) {
|
|
767
|
-
const [l, o] = z(null), [r, i] = z(null), [a, u] = z(
|
|
767
|
+
const [l, o] = z(null), [r, i] = z(null), [a, u] = z(Z(e)), m = T(() => L(a), [a]), g = T(() => {
|
|
768
768
|
const c = (C, w) => C.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
|
|
769
769
|
return c(a);
|
|
770
770
|
}, [a]), x = (c) => {
|
|
@@ -790,7 +790,7 @@ function ut({
|
|
|
790
790
|
});
|
|
791
791
|
}, b = (c) => {
|
|
792
792
|
l || o(c);
|
|
793
|
-
},
|
|
793
|
+
}, M = async (c) => {
|
|
794
794
|
if (!l)
|
|
795
795
|
return;
|
|
796
796
|
const {
|
|
@@ -829,7 +829,7 @@ function ut({
|
|
|
829
829
|
children: Object.keys(C.translation).map((w) => {
|
|
830
830
|
var O;
|
|
831
831
|
const S = (O = C.translation) == null ? void 0 : O[w];
|
|
832
|
-
return S ? /* @__PURE__ */ n(
|
|
832
|
+
return S ? /* @__PURE__ */ n(De, {
|
|
833
833
|
locale: w,
|
|
834
834
|
value: S
|
|
835
835
|
}, w) : null;
|
|
@@ -922,7 +922,7 @@ function ut({
|
|
|
922
922
|
sx: {
|
|
923
923
|
pt: 0.5
|
|
924
924
|
},
|
|
925
|
-
children: /* @__PURE__ */ n(
|
|
925
|
+
children: /* @__PURE__ */ n(je, {
|
|
926
926
|
data: g,
|
|
927
927
|
selected: [],
|
|
928
928
|
renderItem: I,
|
|
@@ -933,8 +933,8 @@ function ut({
|
|
|
933
933
|
open: !!l,
|
|
934
934
|
onClose: () => o(null),
|
|
935
935
|
initialLabel: l,
|
|
936
|
-
onSubmit:
|
|
937
|
-
}, l == null ? void 0 : l.id), /* @__PURE__ */ n(
|
|
936
|
+
onSubmit: M
|
|
937
|
+
}, l == null ? void 0 : l.id), /* @__PURE__ */ n(Me, {
|
|
938
938
|
open: !!r,
|
|
939
939
|
onClose: () => i(null),
|
|
940
940
|
label: r,
|
|
@@ -942,10 +942,10 @@ function ut({
|
|
|
942
942
|
}, r == null ? void 0 : r.id)]
|
|
943
943
|
});
|
|
944
944
|
}
|
|
945
|
-
const
|
|
945
|
+
const G = q({}), U = () => H(G), ht = () => {
|
|
946
946
|
const {
|
|
947
947
|
updateLabels: e
|
|
948
|
-
} =
|
|
948
|
+
} = U();
|
|
949
949
|
W(() => () => {
|
|
950
950
|
e();
|
|
951
951
|
}, []);
|
|
@@ -956,7 +956,7 @@ function pt({
|
|
|
956
956
|
}) {
|
|
957
957
|
const {
|
|
958
958
|
locale: s
|
|
959
|
-
} =
|
|
959
|
+
} = Q(), [l, o] = z({
|
|
960
960
|
loading: !0,
|
|
961
961
|
labels: [],
|
|
962
962
|
updateCounter: 1
|
|
@@ -1010,7 +1010,7 @@ function pt({
|
|
|
1010
1010
|
stringifyLabelIds: m,
|
|
1011
1011
|
localizedLabels: g
|
|
1012
1012
|
}), [l, a, u, m, g]);
|
|
1013
|
-
return /* @__PURE__ */ n(
|
|
1013
|
+
return /* @__PURE__ */ n(G.Provider, {
|
|
1014
1014
|
value: x,
|
|
1015
1015
|
children: t
|
|
1016
1016
|
});
|
|
@@ -1025,7 +1025,7 @@ function mt({
|
|
|
1025
1025
|
labels: r,
|
|
1026
1026
|
loading: i,
|
|
1027
1027
|
getLabelsById: a
|
|
1028
|
-
} =
|
|
1028
|
+
} = U(), [u, m] = z(!1);
|
|
1029
1029
|
if (i || !t && o)
|
|
1030
1030
|
return null;
|
|
1031
1031
|
const g = (f) => {
|
|
@@ -1034,7 +1034,7 @@ function mt({
|
|
|
1034
1034
|
}, 300);
|
|
1035
1035
|
};
|
|
1036
1036
|
if (u)
|
|
1037
|
-
return /* @__PURE__ */ n(
|
|
1037
|
+
return /* @__PURE__ */ n($, {
|
|
1038
1038
|
onClickAway: () => u && m(!1),
|
|
1039
1039
|
children: /* @__PURE__ */ n("div", {
|
|
1040
1040
|
children: /* @__PURE__ */ n(Ae, {
|
|
@@ -1087,6 +1087,6 @@ export {
|
|
|
1087
1087
|
mt as Labels,
|
|
1088
1088
|
pt as LabelsProvider,
|
|
1089
1089
|
Ie as transformLabels,
|
|
1090
|
-
|
|
1090
|
+
U as useLabelsContext,
|
|
1091
1091
|
ht as useLabelsUpdateOnDestroy
|
|
1092
1092
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/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,Y,Z,
|
|
1
|
+
(function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/material/ClickAwayListener"),require("react-color"),require("@arcblock/ux/lib/Dialog"),require("@mui/material"),require("@mui/icons-material/Translate"),require("@mui/material/Popover"),require("@arcblock/ux/lib/Locale/context"),require("@mui/material/Alert"),require("@mui/icons-material/Edit"),require("@mui/icons-material/LabelOutlined"),require("@mui/material/Chip")):typeof define=="function"&&define.amd?define(["exports","react","@mui/icons-material/ExpandMore","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","react/jsx-runtime","lodash/omit","react-select","@mui/material/Typography","@mui/material/Button","@mui/material/IconButton","@mui/icons-material/DeleteOutlineOutlined","@mui/icons-material/EditOutlined","@mui/icons-material/Add","@mui/material/TextField","@mui/material/ClickAwayListener","react-color","@arcblock/ux/lib/Dialog","@mui/material","@mui/icons-material/Translate","@mui/material/Popover","@arcblock/ux/lib/Locale/context","@mui/material/Alert","@mui/icons-material/Edit","@mui/icons-material/LabelOutlined","@mui/material/Chip"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.DiscussKitComponents={},i.React,i.ExpandMoreIcon,i.Box,i.styles,i.reactArborist,i.react$1,i.jsxRuntime,i.omit,i.Select,i.Typography,i.Button,i.IconButton,i.DeleteOutlineOutlinedIcon,i.EditOutlinedIcon,i.AddIcon,i.TextField,i.ClickAwayListener,i.reactColor,i.Dialog,i.material,i.TranslateIcon,i.Popover,i.context,i.Alert,i.EditIcon,i.LabelOutlinedIcon,i.Chip))})(this,function(i,u,U,Y,N,Z,G,e,X,E,R,ee,te,re,ne,le,oe,ae,se,ie,T,de,ce,F,ue,fe,he,pe){"use strict";const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},j=I(U),p=I(Y),ge=I(X),me=I(E),ye=I(R),k=I(ee),A=I(te),xe=I(re),Ce=I(ne),ve=I(le),P=I(oe),W=I(ae),V=I(ie),be=I(de),Se=I(ce),Ie=I(ue),we=I(fe),_e=I(he),Oe=I(pe),Te=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),ke=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),H=u.createContext({});function qe({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:o}){const n=h=>r.indexOf(h)!==-1,a=h=>{Array.from(new Set(r).add(h)),s==null||s(h)},d=u.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:l}),[r]);return e.jsx(H.Provider,{value:d,children:o})}const Ae=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function ze({node:t}){return Ae(t)?e.jsx("span",{}):t.isOpen?e.jsx(j.default,{style:{fontSize:20}}):e.jsx(j.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Le({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=u.useContext(H),{data:d}=t,h=d.icon?e.jsx(G.Icon,{icon:d.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:d.color||"#ddd"}}),m=f=>{f.stopPropagation(),t.isInternal&&t.toggle()},x=f=>{f.stopPropagation(),l&&o(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(p.default,{sx:{display:"flex",cursor:"pointer"},onClick:m,children:e.jsx(ze,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:h}),e.jsx(p.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),l&&n(t.id)&&e.jsx(ke,{})]});return e.jsxs(p.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:s,onClick:x,children:[!a&&C,!!a&&a(C,t.data)]})}const Be=N.styled(p.default)`
|
|
2
2
|
> div,
|
|
3
3
|
> div > div,
|
|
4
4
|
> div > div > div {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
.label-tree-item {
|
|
12
12
|
width: 100%;
|
|
13
13
|
}
|
|
14
|
-
`;function
|
|
14
|
+
`;function z({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:o=28,renderItem:n,sx:a,...d}){const h=u.useRef(),m=[...Array.isArray(a)?a:[a]],[x,C]=u.useState(0),f=u.useCallback(()=>{var v,S;C((((S=(v=h.current)==null?void 0:v.visibleNodes)==null?void 0:S.length)||0)*o)},[o]);u.useEffect(()=>{f()},[t,f]);const y=()=>{setTimeout(f)};return e.jsx(qe,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Be,{...d,sx:m,children:e.jsx(Z.Tree,{data:t,rowHeight:o,height:x,indent:32,ref:h,onToggle:y,children:Le})})})}const L=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...L(s.children)),r},[]),J=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=J(r.children)),r}),Ee=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},K=t=>{const r=t.reduce((o,n)=>(o[n.id]=o[n.id]||{},n.parentId&&(o[n.id].parent=n.parentId,o[n.parentId]=o[n.parentId]||{},o[n.parentId].children=o[n.parentId].children||[],o[n.parentId].children.push(n.id)),o),{}),s=t.map(({parentId:o,translation:n,...a})=>({...a,translation:Ee(n),children:[]})),l=s.reduce((o,n)=>({...o,[n.id]:n}),{});return s.forEach(o=>{const n=r[o.id];n.parent&&l[n.parent]&&(o.parent=l[n.parent]),n.children&&(o.children=n.children.map(a=>l[a]))}),s.filter(o=>!o.parent)},Pe=t=>{const{options:r,getValue:s,selectProps:l,selectOption:o}=t,n=s(),a=d=>{const h=r.find(m=>m.data.id===d);h&&o(h)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...ge.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(z,{data:l.data,selectable:!0,onSelect:a,selected:n.map(d=>d.data.id)})})}),t.addon]})},Me=({children:t,...r})=>{const[s,l]=t,o=Array.isArray(s)?s.length:0;return e.jsxs(E.components.ValueContainer,{...r,children:[e.jsx(p.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&e.jsx(p.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:o}),l]})},De={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function $({data:t,value:r=[],editable:s=!1,addon:l,onChange:o,compact:n,isMulti:a=!0,maxHeight:d=264,...h}){const m=u.useRef(null),x=u.useMemo(()=>L(t).map(g=>({data:g,label:g.name,value:g.id})),[t]),C=x.reduce((g,O)=>({...g,[O.data.id]:O}),{}),f=Array.isArray(r)?r:[r],y=f.map(g=>C[g]),v=u.useRef({prev:f.map(g=>{var O;return((O=C[g])==null?void 0:O.data)||""})}),S=(g,O)=>{!a||!Array.isArray(g)?o(g?[g.data]:[]):v.current.current=g.map(c=>c.data),["clear","remove-value"].includes(O.action)&&m.current&&setTimeout(()=>{var c;return(c=m==null?void 0:m.current)==null?void 0:c.blur()},1)},D=()=>{v.current.current&&JSON.stringify(v.current.prev.map(O=>O.id))!==JSON.stringify(v.current.current.map(O=>O.id))&&(o(v.current.current),v.current.prev=v.current.current)};return e.jsx(p.default,{...h,children:e.jsx(me.default,{ref:m,defaultValue:y,options:x,onChange:S,components:{MenuList:g=>e.jsx(Pe,{...g,addon:l}),...n&&{ValueContainer:Me}},placeholder:"Select labels",styles:{...n&&De,menu:g=>({...g,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:g=>({...g,overflowY:"auto",maxHeight:`${d}px`})},theme:g=>({...g,colors:{...g.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:a,closeMenuOnSelect:!a,onMenuClose:D,isClearable:!0,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,o=arguments.length;l<o;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},B.apply(this,arguments)};function Ne(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),o,n=[],a;try{for(;(r===void 0||r-- >0)&&!(o=l.next()).done;)n.push(o.value)}catch(d){a={error:d}}finally{try{o&&!o.done&&(s=l.return)&&s.call(l)}finally{if(a)throw a.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var Fe=function(t){return typeof t=="function"},je=function(t){var r=Ne(u.useState(t),2),s=r[0],l=r[1],o=u.useCallback(function(n){l(function(a){var d=Fe(n)?n(a):n;return d?B(B({},a),d):a})},[]);return[s,o]};const We=je;function Ve({I18NProps:t,...r}){const{languages:s}=F.useLocaleContext(),{translation:l,onChange:o}=t,[n,a]=u.useState(null),d=x=>{const C=x.currentTarget.closest(".MuiInputBase-root");C&&a(C)},h=()=>{a(null)},m=s.filter(x=>x.code!=="en");return e.jsx(T.TextField,{...r,InputProps:{endAdornment:e.jsxs(T.InputAdornment,{position:"end",children:[e.jsx(T.IconButton,{edge:"end",onClick:d,children:e.jsx(be.default,{})}),e.jsx(Se.default,{open:!!n,anchorEl:n,onClose:h,transformOrigin:{vertical:"top",horizontal:"right"},anchorOrigin:{vertical:"bottom",horizontal:"right"},PaperProps:{sx:{width:n==null?void 0:n.clientWidth,maxHeight:200,overflowY:"auto",bgcolor:"grey.50"}},elevation:1,sx:{mt:2},children:e.jsx(T.Box,{sx:{p:2},children:m.map(({code:x,name:C})=>e.jsxs(T.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(T.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(T.Box,{sx:{flex:1},children:e.jsx(T.TextField,{value:l[x]||"",size:"small",sx:{width:1},onChange:f=>o({...l,[x]:f.target.value})})})]},x))})})]})}})}function He({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,d]=We({name:(r==null?void 0:r.name)||"",color:(r==null?void 0:r.color)||"#ddd",slug:(r==null?void 0:r.id)||"",translation:(r==null?void 0:r.translation)||{}}),h=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),m=u.useMemo(()=>n?a.name&&a.color&&a.slug&&h(a.color):a.name&&a.color&&h(a.color),[a,n]),[x,C]=u.useState(!1),f=()=>{s({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},y=S=>{d({color:S.hex}),setTimeout(()=>C(!1))},v=S=>{d({color:S.target.value})};return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:f,disabled:!m,children:n?"Create":"Save Changes"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ve,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>d({name:S.target.value}),I18NProps:{translation:a.translation,onChange:S=>d({translation:S})}}),e.jsx(P.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>d({slug:S.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(P.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(W.default,{onClickAway:()=>C(!1),children:e.jsxs(p.default,{sx:{position:"relative",mt:2},children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(p.default,{sx:{width:30,height:30,bgcolor:a.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(P.default,{label:"",value:a.color,size:"small",onChange:v,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),x&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(se.GithubPicker,{color:a.color,onChangeComplete:y})})]})})]})})}function Je({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(V.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(k.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",onClick:s,children:"Delete"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Ie.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(z,{data:[r]})]})})}const Ke=N.styled(z)`
|
|
15
15
|
.label-tree-item {
|
|
16
16
|
&:before {
|
|
17
17
|
content: '';
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
box-sizing: border-box;
|
|
32
32
|
padding: 0 16px;
|
|
33
33
|
}
|
|
34
|
-
`;function $e({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function
|
|
34
|
+
`;function $e({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function Qe({data:t,api:r,...s}){const[l,o]=u.useState(null),[n,a]=u.useState(null),[d,h]=u.useState(J(t)),m=u.useMemo(()=>L(d),[d]),x=u.useMemo(()=>{const c=(b,_)=>b.map(w=>(_&&(w.parent=_),w.children&&(w.children=c(w.children,w)),w));return c(d)},[d]),C=c=>{var b,_;c.parent?(c.parent.children=(_=(b=c.parent)==null?void 0:b.children)==null?void 0:_.map(w=>w.id===c.id?{...c}:w),C(c.parent)):h(d.map(w=>w.id===c.id?{...c}:w))},f=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),h([...d])):h([...d,c])},y=c=>{var b;c.parent?c.parent.children=(b=c.parent.children)==null?void 0:b.filter(_=>_.id!==c.id):h(d.filter(_=>_.id!==c.id))},v=c=>{if(l)return;o({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{l||o(c)},D=async c=>{if(!l)return;const{parent:b,children:_,translation:w,...q}=c;l.id?(await r.updateLabel({...q,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),C(c)):(await r.createLabel({...q,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),f(c)),o(null)},g=async()=>{!n||(await r.deleteLabel(n.id),y(n),a(null))},O=(c,b)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},children:[e.jsx(p.default,{children:c}),b.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},children:Object.keys(b.translation).map(_=>{var q;const w=(q=b.translation)==null?void 0:q[_];return w?e.jsx($e,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>v(b),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(b),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(A.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(b),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(ye.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(k.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>v(),children:"New label"})]}),e.jsxs(p.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(p.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},children:[m.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(Ke,{data:x,selected:[],renderItem:O,rowHeight:64})})]}),e.jsx(He,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:D},l==null?void 0:l.id),e.jsx(Je,{open:!!n,onClose:()=>a(null),label:n,onSubmit:g},n==null?void 0:n.id)]})}const Q=u.createContext({}),M=()=>u.useContext(Q),Ue=()=>{const{updateLabels:t}=M();u.useEffect(()=>()=>{t()},[])};function Ye({fetchLabels:t,children:r}){const{locale:s}=F.useLocaleContext(),[l,o]=u.useState({loading:!0,labels:[],updateCounter:1});u.useEffect(()=>{(async()=>{try{o(v=>({...v,loading:!0}));const y=await t();o(v=>({...v,loading:!1,labels:K(y)}))}catch(y){console.error(y),o(v=>({...v,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=u.useMemo(()=>{var y;return(y=l.labels)!=null&&y.length?L(l.labels).reduce((v,S)=>({...v,[S.id]:S}),{}):{}},[l.labels]),a=u.useCallback(f=>{var y;return{...f,name:((y=f.translation)==null?void 0:y[s])||f.name}},[s]),d=u.useCallback(f=>f.filter(Boolean).map(y=>n[y]).map(a),[n,a]),h=u.useCallback(f=>(f==null?void 0:f.split(","))||[],[]),m=u.useCallback((f=[])=>{if(!!(f!=null&&f.length))return f.join(",")},[]),x=u.useMemo(()=>l.labels.map(a),[l.labels,a]),C=u.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>o(f=>({...f,updateCounter:++l.updateCounter})),getLabelsById:d,parseLabelIds:h,stringifyLabelIds:m,localizedLabels:x}),[l,d,h,m,x]);return e.jsx(Q.Provider,{value:C,children:r})}function Ze({labels:t,editable:r,onChange:s,sx:l}){const o=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:d}=M(),[h,m]=u.useState(!1);if(a||!r&&o)return null;const x=y=>{s==null||s(y),setTimeout(()=>{m(!1)},300)};if(h)return e.jsx(W.default,{onClickAway:()=>h&&m(!1),children:e.jsx("div",{children:e.jsx($,{data:n,value:t||[],onChange:x})})});const C=d(t||[]),f=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:f,children:[C.map(y=>y?e.jsx(Oe.default,{label:y.name,variant:"filled",size:"small",sx:{borderRadius:1}},y.id):null),r&&!o&&e.jsx(A.default,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(we.default,{sx:{fontSize:20}})}),r&&o&&e.jsx(k.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(_e.default,{}),onClick:()=>m(!0),children:"Edit labels"})]})}i.LabelManager=Qe,i.LabelPicker=$,i.LabelTree=z,i.Labels=Ze,i.LabelsProvider=Ye,i.transformLabels=K,i.useLabelsContext=M,i.useLabelsUpdateOnDestroy=Ue,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/labels",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.56",
|
|
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": "
|
|
78
|
+
"gitHead": "f0421c3bc64908662a3473dca07931971aca5228"
|
|
79
79
|
}
|