@blocklet/labels 1.5.130 → 1.5.132
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 +1 -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 +88 -88
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
|
@@ -14,5 +14,5 @@ interface LabelsContextValue {
|
|
|
14
14
|
}
|
|
15
15
|
export declare const useLabelsContext: () => LabelsContextValue;
|
|
16
16
|
export declare const useLabelsUpdateOnDestroy: () => void;
|
|
17
|
-
export declare function LabelsProvider({ fetchLabels, children }: LabelsProviderProps):
|
|
17
|
+
export declare function LabelsProvider({ fetchLabels, children }: LabelsProviderProps): JSX.Element;
|
|
18
18
|
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 {};
|
|
@@ -8,5 +8,5 @@ interface LabelsProps {
|
|
|
8
8
|
sx?: SxProps;
|
|
9
9
|
renderLabel?: (label: Label) => JSX.Element;
|
|
10
10
|
}
|
|
11
|
-
export default function Labels({ labels, editable, onChange, sx, renderLabel }: LabelsProps):
|
|
11
|
+
export default function Labels({ labels, editable, onChange, sx, renderLabel }: LabelsProps): JSX.Element | null;
|
|
12
12
|
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,24 +1,24 @@
|
|
|
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 { 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
|
-
import { styled as
|
|
4
|
+
import { styled as J } from "@mui/material/styles";
|
|
5
5
|
import { Tree as le } from "react-arborist";
|
|
6
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
8
|
import ae from "lodash/omit";
|
|
9
|
-
import se, { components as
|
|
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
|
|
14
|
-
import
|
|
13
|
+
import j from "@mui/material/TextField";
|
|
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
17
|
import { TextField as V, InputAdornment as ue, IconButton as he, Box as B } from "@mui/material";
|
|
18
18
|
import pe from "@mui/material/Popover";
|
|
19
|
-
import { useLocaleContext as
|
|
20
|
-
import
|
|
21
|
-
import
|
|
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";
|
|
22
22
|
const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
23
23
|
viewBox: "0 0 24 24",
|
|
24
24
|
width: "1.2em",
|
|
@@ -26,7 +26,7 @@ const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
|
26
26
|
...e,
|
|
27
27
|
children: /* @__PURE__ */ n("path", {
|
|
28
28
|
fill: "currentColor",
|
|
29
|
-
d: "
|
|
29
|
+
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"
|
|
30
30
|
})
|
|
31
31
|
}), xe = (e) => /* @__PURE__ */ n("svg", {
|
|
32
32
|
viewBox: "0 0 24 24",
|
|
@@ -35,9 +35,9 @@ const ge = (e) => /* @__PURE__ */ n("svg", {
|
|
|
35
35
|
...e,
|
|
36
36
|
children: /* @__PURE__ */ n("path", {
|
|
37
37
|
fill: "currentColor",
|
|
38
|
-
d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.
|
|
38
|
+
d: "m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"
|
|
39
39
|
})
|
|
40
|
-
}),
|
|
40
|
+
}), Y = q({});
|
|
41
41
|
function ye({
|
|
42
42
|
selectable: e = !1,
|
|
43
43
|
selected: t = [],
|
|
@@ -57,7 +57,7 @@ function ye({
|
|
|
57
57
|
}),
|
|
58
58
|
[t]
|
|
59
59
|
);
|
|
60
|
-
return /* @__PURE__ */ n(
|
|
60
|
+
return /* @__PURE__ */ n(Y.Provider, {
|
|
61
61
|
value: s,
|
|
62
62
|
children: l
|
|
63
63
|
});
|
|
@@ -90,7 +90,7 @@ function be({
|
|
|
90
90
|
select: l,
|
|
91
91
|
isSelected: r,
|
|
92
92
|
renderItem: i
|
|
93
|
-
} =
|
|
93
|
+
} = H(Y), {
|
|
94
94
|
data: s
|
|
95
95
|
} = e, h = s.icon ? /* @__PURE__ */ n(ie, {
|
|
96
96
|
icon: s.icon,
|
|
@@ -104,7 +104,7 @@ function be({
|
|
|
104
104
|
}
|
|
105
105
|
}), g = (d) => {
|
|
106
106
|
d.stopPropagation(), e.isInternal && e.toggle();
|
|
107
|
-
},
|
|
107
|
+
}, f = (d) => {
|
|
108
108
|
d.stopPropagation(), o && l(e.id);
|
|
109
109
|
}, x = /* @__PURE__ */ C(P, {
|
|
110
110
|
children: [/* @__PURE__ */ C(p, {
|
|
@@ -148,11 +148,11 @@ function be({
|
|
|
148
148
|
justifyContent: "space-between"
|
|
149
149
|
},
|
|
150
150
|
ref: a,
|
|
151
|
-
onClick:
|
|
151
|
+
onClick: f,
|
|
152
152
|
children: [!i && x, !!i && i(x, e.data)]
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
|
-
const Se =
|
|
155
|
+
const Se = J(p)`
|
|
156
156
|
> div,
|
|
157
157
|
> div > div,
|
|
158
158
|
> div > div > div {
|
|
@@ -176,7 +176,7 @@ function F({
|
|
|
176
176
|
sx: i,
|
|
177
177
|
...s
|
|
178
178
|
}) {
|
|
179
|
-
const h =
|
|
179
|
+
const h = D(), g = [...Array.isArray(i) ? i : [i]], [f, x] = z(0), d = k(() => {
|
|
180
180
|
var u, v;
|
|
181
181
|
x((((v = (u = h.current) == null ? void 0 : u.visibleNodes) == null ? void 0 : v.length) || 0) * l);
|
|
182
182
|
}, [l]);
|
|
@@ -193,7 +193,7 @@ function F({
|
|
|
193
193
|
children: /* @__PURE__ */ n(le, {
|
|
194
194
|
data: e,
|
|
195
195
|
rowHeight: l,
|
|
196
|
-
height:
|
|
196
|
+
height: f,
|
|
197
197
|
indent: 32,
|
|
198
198
|
ref: h,
|
|
199
199
|
onToggle: () => {
|
|
@@ -207,9 +207,9 @@ function F({
|
|
|
207
207
|
const O = (e) => e.reduce((t, a) => {
|
|
208
208
|
var o;
|
|
209
209
|
return t.push(a), (o = a.children) != null && o.length && t.push(...O(a.children)), t;
|
|
210
|
-
}, []),
|
|
210
|
+
}, []), Z = (e) => e.map((t) => {
|
|
211
211
|
var a;
|
|
212
|
-
return (a = t.children) != null && a.length && (t.children =
|
|
212
|
+
return (a = t.children) != null && a.length && (t.children = Z(t.children)), t;
|
|
213
213
|
}), we = (e, t = null) => {
|
|
214
214
|
try {
|
|
215
215
|
return JSON.parse(e);
|
|
@@ -237,7 +237,7 @@ const O = (e) => e.reduce((t, a) => {
|
|
|
237
237
|
h && l(h);
|
|
238
238
|
};
|
|
239
239
|
return /* @__PURE__ */ C(P, {
|
|
240
|
-
children: [/* @__PURE__ */ n(
|
|
240
|
+
children: [/* @__PURE__ */ n(_.MenuList, {
|
|
241
241
|
...ae(e, ["addon"]),
|
|
242
242
|
children: /* @__PURE__ */ n(p, {
|
|
243
243
|
sx: {
|
|
@@ -258,7 +258,7 @@ const O = (e) => e.reduce((t, a) => {
|
|
|
258
258
|
...t
|
|
259
259
|
}) => {
|
|
260
260
|
const [a, o] = e, l = Array.isArray(a) ? a.length : 0;
|
|
261
|
-
return /* @__PURE__ */ C(
|
|
261
|
+
return /* @__PURE__ */ C(_.ValueContainer, {
|
|
262
262
|
...t,
|
|
263
263
|
children: [/* @__PURE__ */ n(p, {
|
|
264
264
|
component: "span",
|
|
@@ -311,24 +311,24 @@ function Ae({
|
|
|
311
311
|
maxHeight: s = 264,
|
|
312
312
|
...h
|
|
313
313
|
}) {
|
|
314
|
-
const g =
|
|
315
|
-
data:
|
|
316
|
-
label:
|
|
317
|
-
value:
|
|
318
|
-
})), [e]), x =
|
|
319
|
-
...
|
|
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,
|
|
320
320
|
[I.data.id]: I
|
|
321
|
-
}), {}), d = Array.isArray(t) ? t : [t], b = d.map((
|
|
322
|
-
prev: d.map((
|
|
321
|
+
}), {}), d = Array.isArray(t) ? t : [t], b = d.map((m) => x[m]), u = D({
|
|
322
|
+
prev: d.map((m) => {
|
|
323
323
|
var I;
|
|
324
|
-
return ((I = x[
|
|
324
|
+
return ((I = x[m]) == null ? void 0 : I.data) || "";
|
|
325
325
|
})
|
|
326
|
-
}), v = (
|
|
327
|
-
!i || !Array.isArray(
|
|
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(() => {
|
|
328
328
|
var c;
|
|
329
329
|
return (c = g == null ? void 0 : g.current) == null ? void 0 : c.blur();
|
|
330
330
|
}, 1);
|
|
331
|
-
},
|
|
331
|
+
}, M = () => {
|
|
332
332
|
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);
|
|
333
333
|
};
|
|
334
334
|
return /* @__PURE__ */ n(p, {
|
|
@@ -336,11 +336,11 @@ function Ae({
|
|
|
336
336
|
children: /* @__PURE__ */ n(se, {
|
|
337
337
|
ref: g,
|
|
338
338
|
defaultValue: b,
|
|
339
|
-
options:
|
|
339
|
+
options: f,
|
|
340
340
|
onChange: v,
|
|
341
341
|
components: {
|
|
342
|
-
MenuList: (
|
|
343
|
-
...
|
|
342
|
+
MenuList: (m) => /* @__PURE__ */ n(ze, {
|
|
343
|
+
...m,
|
|
344
344
|
addon: o
|
|
345
345
|
}),
|
|
346
346
|
...r && {
|
|
@@ -350,23 +350,23 @@ function Ae({
|
|
|
350
350
|
placeholder: "Select labels",
|
|
351
351
|
styles: {
|
|
352
352
|
...r && ke,
|
|
353
|
-
menu: (
|
|
354
|
-
...
|
|
353
|
+
menu: (m) => ({
|
|
354
|
+
...m,
|
|
355
355
|
...a && {
|
|
356
356
|
paddingBottom: "36px"
|
|
357
357
|
},
|
|
358
358
|
zIndex: 99
|
|
359
359
|
}),
|
|
360
|
-
menuList: (
|
|
361
|
-
...
|
|
360
|
+
menuList: (m) => ({
|
|
361
|
+
...m,
|
|
362
362
|
overflowY: "auto",
|
|
363
363
|
maxHeight: `${s}px`
|
|
364
364
|
})
|
|
365
365
|
},
|
|
366
|
-
theme: (
|
|
367
|
-
...
|
|
366
|
+
theme: (m) => ({
|
|
367
|
+
...m,
|
|
368
368
|
colors: {
|
|
369
|
-
...
|
|
369
|
+
...m.colors,
|
|
370
370
|
primary25: "#ddd",
|
|
371
371
|
primary50: "#ddd",
|
|
372
372
|
primary: "#ddd"
|
|
@@ -375,7 +375,7 @@ function Ae({
|
|
|
375
375
|
isSearchable: !1,
|
|
376
376
|
isMulti: i,
|
|
377
377
|
closeMenuOnSelect: !i,
|
|
378
|
-
onMenuClose:
|
|
378
|
+
onMenuClose: M,
|
|
379
379
|
isClearable: !0,
|
|
380
380
|
data: e
|
|
381
381
|
})
|
|
@@ -429,15 +429,15 @@ function Ee({
|
|
|
429
429
|
}) {
|
|
430
430
|
const {
|
|
431
431
|
languages: a
|
|
432
|
-
} =
|
|
432
|
+
} = Q(), {
|
|
433
433
|
translation: o,
|
|
434
434
|
onChange: l
|
|
435
|
-
} = e, [r, i] = z(null), s = (
|
|
436
|
-
const x =
|
|
435
|
+
} = e, [r, i] = z(null), s = (f) => {
|
|
436
|
+
const x = f.currentTarget.closest(".MuiInputBase-root");
|
|
437
437
|
x && i(x);
|
|
438
438
|
}, h = () => {
|
|
439
439
|
i(null);
|
|
440
|
-
}, g = a.filter((
|
|
440
|
+
}, g = a.filter((f) => f.code !== "en");
|
|
441
441
|
return /* @__PURE__ */ n(V, {
|
|
442
442
|
...t,
|
|
443
443
|
InputProps: {
|
|
@@ -476,7 +476,7 @@ function Ee({
|
|
|
476
476
|
p: 2
|
|
477
477
|
},
|
|
478
478
|
children: g.map(({
|
|
479
|
-
code:
|
|
479
|
+
code: f,
|
|
480
480
|
name: x
|
|
481
481
|
}) => /* @__PURE__ */ C(B, {
|
|
482
482
|
sx: {
|
|
@@ -497,18 +497,18 @@ function Ee({
|
|
|
497
497
|
flex: 1
|
|
498
498
|
},
|
|
499
499
|
children: /* @__PURE__ */ n(V, {
|
|
500
|
-
value: o[
|
|
500
|
+
value: o[f] || "",
|
|
501
501
|
size: "small",
|
|
502
502
|
sx: {
|
|
503
503
|
width: 1
|
|
504
504
|
},
|
|
505
505
|
onChange: (d) => l({
|
|
506
506
|
...o,
|
|
507
|
-
[
|
|
507
|
+
[f]: d.target.value
|
|
508
508
|
})
|
|
509
509
|
})
|
|
510
510
|
})]
|
|
511
|
-
},
|
|
511
|
+
}, f))
|
|
512
512
|
})
|
|
513
513
|
})]
|
|
514
514
|
})
|
|
@@ -527,7 +527,7 @@ function Le({
|
|
|
527
527
|
color: (t == null ? void 0 : t.color) || "#ddd",
|
|
528
528
|
slug: (t == null ? void 0 : t.id) || "",
|
|
529
529
|
translation: (t == null ? void 0 : t.translation) || {}
|
|
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]), [
|
|
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 = () => {
|
|
531
531
|
a({
|
|
532
532
|
...t,
|
|
533
533
|
name: i.name,
|
|
@@ -585,7 +585,7 @@ function Le({
|
|
|
585
585
|
translation: v
|
|
586
586
|
})
|
|
587
587
|
}
|
|
588
|
-
}), /* @__PURE__ */ n(
|
|
588
|
+
}), /* @__PURE__ */ n(j, {
|
|
589
589
|
label: "Slug",
|
|
590
590
|
value: i.slug,
|
|
591
591
|
size: "small",
|
|
@@ -597,7 +597,7 @@ function Le({
|
|
|
597
597
|
sx: {
|
|
598
598
|
mt: 2
|
|
599
599
|
}
|
|
600
|
-
}), (t == null ? void 0 : t.parent) && /* @__PURE__ */ n(
|
|
600
|
+
}), (t == null ? void 0 : t.parent) && /* @__PURE__ */ n(j, {
|
|
601
601
|
label: "Parent",
|
|
602
602
|
value: t.parent.name,
|
|
603
603
|
size: "small",
|
|
@@ -606,7 +606,7 @@ function Le({
|
|
|
606
606
|
sx: {
|
|
607
607
|
mt: 2
|
|
608
608
|
}
|
|
609
|
-
}), /* @__PURE__ */ n(
|
|
609
|
+
}), /* @__PURE__ */ n($, {
|
|
610
610
|
onClickAway: () => x(!1),
|
|
611
611
|
children: /* @__PURE__ */ C(p, {
|
|
612
612
|
sx: {
|
|
@@ -627,7 +627,7 @@ function Le({
|
|
|
627
627
|
borderRadius: 1
|
|
628
628
|
},
|
|
629
629
|
onClick: () => x(!0)
|
|
630
|
-
}), /* @__PURE__ */ n(
|
|
630
|
+
}), /* @__PURE__ */ n(j, {
|
|
631
631
|
label: "",
|
|
632
632
|
value: i.color,
|
|
633
633
|
size: "small",
|
|
@@ -642,7 +642,7 @@ function Le({
|
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
644
|
})]
|
|
645
|
-
}),
|
|
645
|
+
}), f && /* @__PURE__ */ n(p, {
|
|
646
646
|
sx: {
|
|
647
647
|
position: "absolute",
|
|
648
648
|
top: 48,
|
|
@@ -658,7 +658,7 @@ function Le({
|
|
|
658
658
|
})
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
|
-
function
|
|
661
|
+
function Me({
|
|
662
662
|
open: e,
|
|
663
663
|
label: t,
|
|
664
664
|
onSubmit: a,
|
|
@@ -690,7 +690,7 @@ function je({
|
|
|
690
690
|
children: /* @__PURE__ */ C(p, {
|
|
691
691
|
width: 600,
|
|
692
692
|
minHeight: 280,
|
|
693
|
-
children: [/* @__PURE__ */ n(
|
|
693
|
+
children: [/* @__PURE__ */ n(fe, {
|
|
694
694
|
severity: "info",
|
|
695
695
|
sx: {
|
|
696
696
|
mb: 2
|
|
@@ -702,7 +702,7 @@ function je({
|
|
|
702
702
|
})
|
|
703
703
|
});
|
|
704
704
|
}
|
|
705
|
-
const
|
|
705
|
+
const je = J(F)`
|
|
706
706
|
.label-tree-item {
|
|
707
707
|
&:before {
|
|
708
708
|
content: '';
|
|
@@ -723,7 +723,7 @@ const De = _(F)`
|
|
|
723
723
|
padding: 0 16px;
|
|
724
724
|
}
|
|
725
725
|
`;
|
|
726
|
-
function
|
|
726
|
+
function De({
|
|
727
727
|
locale: e,
|
|
728
728
|
value: t
|
|
729
729
|
}) {
|
|
@@ -759,7 +759,7 @@ function lt({
|
|
|
759
759
|
api: t,
|
|
760
760
|
...a
|
|
761
761
|
}) {
|
|
762
|
-
const [o, l] = z(null), [r, i] = z(null), [s, h] = z(
|
|
762
|
+
const [o, l] = z(null), [r, i] = z(null), [s, h] = z(Z(e)), g = T(() => O(s), [s]), f = T(() => {
|
|
763
763
|
const c = (y, w) => y.map((S) => (w && (S.parent = w), S.children && (S.children = c(S.children, S)), S));
|
|
764
764
|
return c(s);
|
|
765
765
|
}, [s]), x = (c) => {
|
|
@@ -785,7 +785,7 @@ function lt({
|
|
|
785
785
|
});
|
|
786
786
|
}, v = (c) => {
|
|
787
787
|
o || l(c);
|
|
788
|
-
},
|
|
788
|
+
}, M = async (c) => {
|
|
789
789
|
if (!o)
|
|
790
790
|
return;
|
|
791
791
|
const {
|
|
@@ -803,7 +803,7 @@ function lt({
|
|
|
803
803
|
translation: JSON.stringify(S),
|
|
804
804
|
parentId: y == null ? void 0 : y.id
|
|
805
805
|
}), d(c)), l(null);
|
|
806
|
-
},
|
|
806
|
+
}, m = async () => {
|
|
807
807
|
!r || (await t.deleteLabel(r.id), b(r), i(null));
|
|
808
808
|
}, I = (c, y) => /* @__PURE__ */ C(P, {
|
|
809
809
|
children: [/* @__PURE__ */ C(p, {
|
|
@@ -826,7 +826,7 @@ function lt({
|
|
|
826
826
|
children: Object.keys(y.translation).map((w) => {
|
|
827
827
|
var N;
|
|
828
828
|
const S = (N = y.translation) == null ? void 0 : N[w];
|
|
829
|
-
return S ? /* @__PURE__ */ n(
|
|
829
|
+
return S ? /* @__PURE__ */ n(De, {
|
|
830
830
|
locale: w,
|
|
831
831
|
value: S
|
|
832
832
|
}, w) : null;
|
|
@@ -922,8 +922,8 @@ function lt({
|
|
|
922
922
|
sx: {
|
|
923
923
|
pt: 0.5
|
|
924
924
|
},
|
|
925
|
-
children: /* @__PURE__ */ n(
|
|
926
|
-
data:
|
|
925
|
+
children: /* @__PURE__ */ n(je, {
|
|
926
|
+
data: f,
|
|
927
927
|
selected: [],
|
|
928
928
|
renderItem: I,
|
|
929
929
|
rowHeight: 64
|
|
@@ -933,19 +933,19 @@ function lt({
|
|
|
933
933
|
open: !!o,
|
|
934
934
|
onClose: () => l(null),
|
|
935
935
|
initialLabel: o,
|
|
936
|
-
onSubmit:
|
|
937
|
-
}, o == null ? void 0 : o.id), /* @__PURE__ */ n(
|
|
936
|
+
onSubmit: M
|
|
937
|
+
}, o == null ? void 0 : o.id), /* @__PURE__ */ n(Me, {
|
|
938
938
|
open: !!r,
|
|
939
939
|
onClose: () => i(null),
|
|
940
940
|
label: r,
|
|
941
|
-
onSubmit:
|
|
941
|
+
onSubmit: m
|
|
942
942
|
}, r == null ? void 0 : r.id)]
|
|
943
943
|
});
|
|
944
944
|
}
|
|
945
|
-
const
|
|
945
|
+
const G = q({}), U = () => H(G), it = () => {
|
|
946
946
|
const {
|
|
947
947
|
updateLabels: e
|
|
948
|
-
} =
|
|
948
|
+
} = U();
|
|
949
949
|
W(() => () => {
|
|
950
950
|
e();
|
|
951
951
|
}, []);
|
|
@@ -956,7 +956,7 @@ function at({
|
|
|
956
956
|
}) {
|
|
957
957
|
const {
|
|
958
958
|
locale: a
|
|
959
|
-
} =
|
|
959
|
+
} = Q(), [o, l] = z({
|
|
960
960
|
loading: !0,
|
|
961
961
|
labels: [],
|
|
962
962
|
updateCounter: 1
|
|
@@ -998,7 +998,7 @@ function at({
|
|
|
998
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 = []) => {
|
|
999
999
|
if (!!(d != null && d.length))
|
|
1000
1000
|
return d.join(",");
|
|
1001
|
-
}, []),
|
|
1001
|
+
}, []), f = T(() => o.labels.map(i), [o.labels, i]), x = T(() => ({
|
|
1002
1002
|
loading: o.loading,
|
|
1003
1003
|
labels: o.labels || [],
|
|
1004
1004
|
updateLabels: () => l((d) => ({
|
|
@@ -1008,10 +1008,10 @@ function at({
|
|
|
1008
1008
|
getLabelsById: s,
|
|
1009
1009
|
parseLabelIds: h,
|
|
1010
1010
|
stringifyLabelIds: g,
|
|
1011
|
-
localizedLabels:
|
|
1012
|
-
flattenedLabels: O(
|
|
1013
|
-
}), [o, s, h, g,
|
|
1014
|
-
return /* @__PURE__ */ n(
|
|
1011
|
+
localizedLabels: f,
|
|
1012
|
+
flattenedLabels: O(f || [])
|
|
1013
|
+
}), [o, s, h, g, f]);
|
|
1014
|
+
return /* @__PURE__ */ n(G.Provider, {
|
|
1015
1015
|
value: x,
|
|
1016
1016
|
children: t
|
|
1017
1017
|
});
|
|
@@ -1027,17 +1027,17 @@ function st({
|
|
|
1027
1027
|
labels: i,
|
|
1028
1028
|
loading: s,
|
|
1029
1029
|
getLabelsById: h
|
|
1030
|
-
} =
|
|
1030
|
+
} = U(), [g, f] = z(!1);
|
|
1031
1031
|
if (s || !t && r)
|
|
1032
1032
|
return null;
|
|
1033
1033
|
const x = (u) => {
|
|
1034
1034
|
a == null || a(u), setTimeout(() => {
|
|
1035
|
-
|
|
1035
|
+
f(!1);
|
|
1036
1036
|
}, 300);
|
|
1037
1037
|
};
|
|
1038
1038
|
if (g)
|
|
1039
|
-
return /* @__PURE__ */ n(
|
|
1040
|
-
onClickAway: () => g &&
|
|
1039
|
+
return /* @__PURE__ */ n($, {
|
|
1040
|
+
onClickAway: () => g && f(!1),
|
|
1041
1041
|
children: /* @__PURE__ */ n("div", {
|
|
1042
1042
|
children: /* @__PURE__ */ n(Ae, {
|
|
1043
1043
|
data: i,
|
|
@@ -1054,7 +1054,7 @@ function st({
|
|
|
1054
1054
|
}, ...Array.isArray(o) ? o : [o]];
|
|
1055
1055
|
return /* @__PURE__ */ C(p, {
|
|
1056
1056
|
sx: b,
|
|
1057
|
-
children: [d.map((u) => u ? l ? l(u) : /* @__PURE__ */ n(
|
|
1057
|
+
children: [d.map((u) => u ? l ? l(u) : /* @__PURE__ */ n(me, {
|
|
1058
1058
|
label: u.name,
|
|
1059
1059
|
variant: "filled",
|
|
1060
1060
|
size: "small",
|
|
@@ -1064,7 +1064,7 @@ function st({
|
|
|
1064
1064
|
}, u.id) : null), t && !r && /* @__PURE__ */ n(E, {
|
|
1065
1065
|
color: "inherit",
|
|
1066
1066
|
size: "small",
|
|
1067
|
-
onClick: () =>
|
|
1067
|
+
onClick: () => f(!0),
|
|
1068
1068
|
sx: {
|
|
1069
1069
|
color: "grey.400"
|
|
1070
1070
|
},
|
|
@@ -1077,7 +1077,7 @@ function st({
|
|
|
1077
1077
|
color: "inherit",
|
|
1078
1078
|
variant: "outlined",
|
|
1079
1079
|
startIcon: /* @__PURE__ */ n(oe, {}),
|
|
1080
|
-
onClick: () =>
|
|
1080
|
+
onClick: () => f(!0),
|
|
1081
1081
|
children: "Edit labels"
|
|
1082
1082
|
})]
|
|
1083
1083
|
});
|
|
@@ -1089,6 +1089,6 @@ export {
|
|
|
1089
1089
|
st as Labels,
|
|
1090
1090
|
at as LabelsProvider,
|
|
1091
1091
|
Ie as transformLabels,
|
|
1092
|
-
|
|
1092
|
+
U as useLabelsContext,
|
|
1093
1093
|
it as useLabelsUpdateOnDestroy
|
|
1094
1094
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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,Y,
|
|
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 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(
|
|
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 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)},
|
|
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.
|
|
3
|
+
"version": "1.5.132",
|
|
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": "2823d96c38469127d2b6ddd15c14fc0388a6a257"
|
|
79
79
|
}
|