@blocklet/labels 1.4.14 → 1.4.16
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 +16 -16
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -4,7 +4,7 @@ import p from "@mui/material/Box";
|
|
|
4
4
|
import { styled as F } from "@mui/material/styles";
|
|
5
5
|
import { Tree as U } from "react-arborist";
|
|
6
6
|
import { Icon as X } from "@iconify/react";
|
|
7
|
-
import { jsx as e, jsxs as C, Fragment as
|
|
7
|
+
import { jsx as e, jsxs as C, Fragment as B } from "react/jsx-runtime";
|
|
8
8
|
import _ from "lodash/omit";
|
|
9
9
|
import ee, { components as H } from "react-select";
|
|
10
10
|
import te from "@mui/material/Typography";
|
|
@@ -18,7 +18,7 @@ import M from "@mui/material/TextField";
|
|
|
18
18
|
import ie from "@mui/base/ClickAwayListener";
|
|
19
19
|
import { GithubPicker as se } from "react-color";
|
|
20
20
|
import J from "@arcblock/ux/lib/Dialog";
|
|
21
|
-
import { TextField as R, InputAdornment as ae, IconButton as ce, Box as
|
|
21
|
+
import { TextField as R, InputAdornment as ae, IconButton as ce, Box as P } from "@mui/material";
|
|
22
22
|
import de from "@mui/icons-material/Translate";
|
|
23
23
|
import ue from "@mui/material/Popover";
|
|
24
24
|
import { useLocaleContext as $ } from "@arcblock/ux/lib/Locale/context";
|
|
@@ -114,7 +114,7 @@ function Ie({
|
|
|
114
114
|
s.stopPropagation(), t.isInternal && t.toggle();
|
|
115
115
|
}, f = (s) => {
|
|
116
116
|
s.stopPropagation(), l && o(t.id);
|
|
117
|
-
}, x = /* @__PURE__ */ C(
|
|
117
|
+
}, x = /* @__PURE__ */ C(B, {
|
|
118
118
|
children: [/* @__PURE__ */ C(p, {
|
|
119
119
|
sx: {
|
|
120
120
|
display: "flex",
|
|
@@ -244,7 +244,7 @@ const L = (t) => t.reduce((n, c) => {
|
|
|
244
244
|
const h = n.find((g) => g.data.id === d);
|
|
245
245
|
h && o(h);
|
|
246
246
|
};
|
|
247
|
-
return /* @__PURE__ */ C(
|
|
247
|
+
return /* @__PURE__ */ C(B, {
|
|
248
248
|
children: [/* @__PURE__ */ e(H.MenuList, {
|
|
249
249
|
..._(t, ["addon"]),
|
|
250
250
|
children: /* @__PURE__ */ e(p, {
|
|
@@ -383,7 +383,7 @@ function Oe({
|
|
|
383
383
|
})
|
|
384
384
|
});
|
|
385
385
|
}
|
|
386
|
-
function
|
|
386
|
+
function Be({
|
|
387
387
|
I18NProps: t,
|
|
388
388
|
...n
|
|
389
389
|
}) {
|
|
@@ -431,14 +431,14 @@ function Pe({
|
|
|
431
431
|
sx: {
|
|
432
432
|
mt: 2
|
|
433
433
|
},
|
|
434
|
-
children: /* @__PURE__ */ e(
|
|
434
|
+
children: /* @__PURE__ */ e(P, {
|
|
435
435
|
sx: {
|
|
436
436
|
p: 2
|
|
437
437
|
},
|
|
438
438
|
children: g.map(({
|
|
439
439
|
code: f,
|
|
440
440
|
name: x
|
|
441
|
-
}) => /* @__PURE__ */ C(
|
|
441
|
+
}) => /* @__PURE__ */ C(P, {
|
|
442
442
|
sx: {
|
|
443
443
|
display: "flex",
|
|
444
444
|
alignItems: "center",
|
|
@@ -447,12 +447,12 @@ function Pe({
|
|
|
447
447
|
mt: 1
|
|
448
448
|
}
|
|
449
449
|
},
|
|
450
|
-
children: [/* @__PURE__ */ e(
|
|
450
|
+
children: [/* @__PURE__ */ e(P, {
|
|
451
451
|
sx: {
|
|
452
452
|
flex: "0 0 120px"
|
|
453
453
|
},
|
|
454
454
|
children: x
|
|
455
|
-
}), /* @__PURE__ */ e(
|
|
455
|
+
}), /* @__PURE__ */ e(P, {
|
|
456
456
|
sx: {
|
|
457
457
|
flex: 1
|
|
458
458
|
},
|
|
@@ -475,7 +475,7 @@ function Pe({
|
|
|
475
475
|
}
|
|
476
476
|
});
|
|
477
477
|
}
|
|
478
|
-
function
|
|
478
|
+
function Pe({
|
|
479
479
|
open: t,
|
|
480
480
|
initialLabel: n,
|
|
481
481
|
onSubmit: c,
|
|
@@ -509,7 +509,7 @@ function Be({
|
|
|
509
509
|
showCloseButton: !0,
|
|
510
510
|
maxWidth: "lg",
|
|
511
511
|
title: r ? "Create label" : "Edit label",
|
|
512
|
-
actions: /* @__PURE__ */ C(
|
|
512
|
+
actions: /* @__PURE__ */ C(B, {
|
|
513
513
|
children: [/* @__PURE__ */ e(T, {
|
|
514
514
|
color: "inherit",
|
|
515
515
|
variant: "contained",
|
|
@@ -530,7 +530,7 @@ function Be({
|
|
|
530
530
|
children: /* @__PURE__ */ C(p, {
|
|
531
531
|
width: 600,
|
|
532
532
|
minHeight: 280,
|
|
533
|
-
children: [/* @__PURE__ */ e(
|
|
533
|
+
children: [/* @__PURE__ */ e(Be, {
|
|
534
534
|
label: "Name",
|
|
535
535
|
value: i.name,
|
|
536
536
|
placeholder: "New label",
|
|
@@ -630,7 +630,7 @@ function Ne({
|
|
|
630
630
|
showCloseButton: !0,
|
|
631
631
|
maxWidth: "md",
|
|
632
632
|
title: "Delete",
|
|
633
|
-
actions: /* @__PURE__ */ C(
|
|
633
|
+
actions: /* @__PURE__ */ C(B, {
|
|
634
634
|
children: [/* @__PURE__ */ e(T, {
|
|
635
635
|
color: "inherit",
|
|
636
636
|
variant: "contained",
|
|
@@ -764,7 +764,7 @@ function dt({
|
|
|
764
764
|
}), s(u)), o(null);
|
|
765
765
|
}, k = async () => {
|
|
766
766
|
!r || (await n.deleteLabel(r.id), m(r), i(null));
|
|
767
|
-
}, G = (u, y) => /* @__PURE__ */ C(
|
|
767
|
+
}, G = (u, y) => /* @__PURE__ */ C(B, {
|
|
768
768
|
children: [/* @__PURE__ */ C(p, {
|
|
769
769
|
sx: {
|
|
770
770
|
display: "flex",
|
|
@@ -883,7 +883,7 @@ function dt({
|
|
|
883
883
|
rowHeight: 64
|
|
884
884
|
})
|
|
885
885
|
})]
|
|
886
|
-
}), /* @__PURE__ */ e(
|
|
886
|
+
}), /* @__PURE__ */ e(Pe, {
|
|
887
887
|
open: !!l,
|
|
888
888
|
onClose: () => o(null),
|
|
889
889
|
initialLabel: l,
|
|
@@ -949,7 +949,7 @@ function ht({
|
|
|
949
949
|
...s,
|
|
950
950
|
name: ((m = s.translation) == null ? void 0 : m[c]) || s.name
|
|
951
951
|
};
|
|
952
|
-
}, [c]), d = O((s) => s.map((m) => r[m]).map(i), [r, i]), h = O((s) => (s == null ? void 0 : s.split(",")) || [], []), g = O((s = []) => {
|
|
952
|
+
}, [c]), d = O((s) => s.filter(Boolean).map((m) => r[m]).map(i), [r, i]), h = O((s) => (s == null ? void 0 : s.split(",")) || [], []), g = O((s = []) => {
|
|
953
953
|
if (!!(s != null && s.length))
|
|
954
954
|
return s.join(",");
|
|
955
955
|
}, []), f = z(() => l.labels.map(i), [l.labels, i]), x = z(() => ({
|
package/dist/index.umd.js
CHANGED
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
box-sizing: border-box;
|
|
32
32
|
padding: 0 16px;
|
|
33
33
|
}
|
|
34
|
-
`;function Je({locale:t,value:r}){return e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(g.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(g.default,{sx:{pl:.5},children:r})]})}function Ke({data:t,api:r,...c}){const[o,l]=f.useState(null),[n,a]=f.useState(null),[u,p]=f.useState(j(t)),y=f.useMemo(()=>z(u),[u]),x=f.useMemo(()=>{const h=(v,w)=>v.map(I=>(w&&(I.parent=w),I.children&&(I.children=h(I.children,I)),I));return h(u)},[u]),C=h=>{var v,w;h.parent?(h.parent.children=(w=(v=h.parent)==null?void 0:v.children)==null?void 0:w.map(I=>I.id===h.id?{...h}:I),C(h.parent)):p(u.map(I=>I.id===h.id?{...h}:I))},i=h=>{h.parent?(h.parent.children=h.parent.children||[],h.parent.children.push(h),p([...u])):p([...u,h])},m=h=>{var v;h.parent?h.parent.children=(v=h.parent.children)==null?void 0:v.filter(w=>w.id!==h.id):p(u.filter(w=>w.id!==h.id))},S=h=>{if(o)return;l({id:"",name:"New label",parent:h,color:"#dddddd"})},d=h=>{o||l(h)},_=async h=>{if(!o)return;const{parent:v,children:w,translation:I,...A}=h;o.id?(await r.updateLabel({...A,translation:JSON.stringify(I),parentId:v==null?void 0:v.id}),C(h)):(await r.createLabel({...A,translation:JSON.stringify(I),parentId:v==null?void 0:v.id}),i(h)),l(null)},q=async()=>{!n||(await r.deleteLabel(n.id),m(n),a(null))},Ye=(h,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},children:[e.jsx(g.default,{children:h}),v.translation&&e.jsx(g.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},children:Object.keys(v.translation).map(w=>{var A;const I=(A=v.translation)==null?void 0:A[w];return I?e.jsx(Je,{locale:w,value:I},w):null})})]}),e.jsxs(g.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(Ce.default,{sx:{fontSize:20}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>d(v),children:e.jsx(ye.default,{sx:{fontSize:18}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(v),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(g.default,{...c,children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(me.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(T.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>S(),children:"New label"})]}),e.jsxs(g.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(g.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},children:[y.length," labels"]}),e.jsx(g.default,{sx:{pt:.5},children:e.jsx(He,{data:x,selected:[],renderItem:Ye,rowHeight:64})})]}),e.jsx(je,{open:!!o,onClose:()=>l(null),initialLabel:o,onSubmit:_},o==null?void 0:o.id),e.jsx(Ve,{open:!!n,onClose:()=>a(null),label:n,onSubmit:q},n==null?void 0:n.id)]})}const J=f.createContext({}),P=()=>f.useContext(J),$e=()=>{const{updateLabels:t}=P();f.useEffect(()=>()=>{t()},[])};function Qe({fetchLabels:t,children:r}){const{locale:c}=D.useLocaleContext(),[o,l]=f.useState({loading:!0,labels:[],updateCounter:1});f.useEffect(()=>{(async()=>{try{l(S=>({...S,loading:!0}));const m=await t();l(S=>({...S,loading:!1,labels:V(m)}))}catch(m){console.error(m),l(S=>({...S,loading:!1,labels:[]}))}})()},[o.updateCounter]);const n=f.useMemo(()=>{var m;return(m=o.labels)!=null&&m.length?z(o.labels).reduce((S,d)=>({...S,[d.id]:d}),{}):{}},[o.labels]),a=f.useCallback(i=>{var m;return{...i,name:((m=i.translation)==null?void 0:m[c])||i.name}},[c]),u=f.useCallback(i=>i.map(m=>n[m]).map(a),[n,a]),p=f.useCallback(i=>(i==null?void 0:i.split(","))||[],[]),y=f.useCallback((i=[])=>{if(!!(i!=null&&i.length))return i.join(",")},[]),x=f.useMemo(()=>o.labels.map(a),[o.labels,a]),C=f.useMemo(()=>({loading:o.loading,labels:o.labels||[],updateLabels:()=>l(i=>({...i,updateCounter:++o.updateCounter})),getLabelsById:u,parseLabelIds:p,stringifyLabelIds:y,localizedLabels:x}),[o,u,p,y,x]);return e.jsx(J.Provider,{value:C,children:r})}function Ue({labels:t,editable:r,onChange:c,sx:o}){const l=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:u}=P(),[p,y]=f.useState(!1);if(a||!r&&l)return null;const x=m=>{c==null||c(m),setTimeout(()=>{y(!1)},300)};if(p)return e.jsx(Te.default,{onClickAway:()=>p&&y(!1),children:e.jsx("div",{children:e.jsx(H,{data:n,value:t||[],onChange:x})})});const C=u(t||[]),i=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(o)?o:[o]];return e.jsxs(g.default,{sx:i,children:[C.map(m=>m?e.jsx(qe.default,{label:m.name,variant:"filled",size:"small",sx:{borderRadius:1}},m.id):null),r&&!l&&e.jsx(L.default,{color:"inherit",size:"small",onClick:()=>y(!0),sx:{color:"grey.400"},children:e.jsx(_e.default,{sx:{fontSize:20}})}),r&&l&&e.jsx(T.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(ke.default,{}),onClick:()=>y(!0),children:"Edit labels"})]})}s.LabelManager=Ke,s.LabelPicker=H,s.LabelTree=O,s.Labels=Ue,s.LabelsProvider=Qe,s.transformLabels=V,s.useLabelsContext=P,s.useLabelsUpdateOnDestroy=$e,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
34
|
+
`;function Je({locale:t,value:r}){return e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(g.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(g.default,{sx:{pl:.5},children:r})]})}function Ke({data:t,api:r,...c}){const[o,l]=f.useState(null),[n,a]=f.useState(null),[u,p]=f.useState(j(t)),y=f.useMemo(()=>z(u),[u]),x=f.useMemo(()=>{const h=(v,w)=>v.map(I=>(w&&(I.parent=w),I.children&&(I.children=h(I.children,I)),I));return h(u)},[u]),C=h=>{var v,w;h.parent?(h.parent.children=(w=(v=h.parent)==null?void 0:v.children)==null?void 0:w.map(I=>I.id===h.id?{...h}:I),C(h.parent)):p(u.map(I=>I.id===h.id?{...h}:I))},i=h=>{h.parent?(h.parent.children=h.parent.children||[],h.parent.children.push(h),p([...u])):p([...u,h])},m=h=>{var v;h.parent?h.parent.children=(v=h.parent.children)==null?void 0:v.filter(w=>w.id!==h.id):p(u.filter(w=>w.id!==h.id))},S=h=>{if(o)return;l({id:"",name:"New label",parent:h,color:"#dddddd"})},d=h=>{o||l(h)},_=async h=>{if(!o)return;const{parent:v,children:w,translation:I,...A}=h;o.id?(await r.updateLabel({...A,translation:JSON.stringify(I),parentId:v==null?void 0:v.id}),C(h)):(await r.createLabel({...A,translation:JSON.stringify(I),parentId:v==null?void 0:v.id}),i(h)),l(null)},q=async()=>{!n||(await r.deleteLabel(n.id),m(n),a(null))},Ye=(h,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},children:[e.jsx(g.default,{children:h}),v.translation&&e.jsx(g.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},children:Object.keys(v.translation).map(w=>{var A;const I=(A=v.translation)==null?void 0:A[w];return I?e.jsx(Je,{locale:w,value:I},w):null})})]}),e.jsxs(g.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(Ce.default,{sx:{fontSize:20}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>d(v),children:e.jsx(ye.default,{sx:{fontSize:18}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(v),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(g.default,{...c,children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(me.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(T.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>S(),children:"New label"})]}),e.jsxs(g.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(g.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},children:[y.length," labels"]}),e.jsx(g.default,{sx:{pt:.5},children:e.jsx(He,{data:x,selected:[],renderItem:Ye,rowHeight:64})})]}),e.jsx(je,{open:!!o,onClose:()=>l(null),initialLabel:o,onSubmit:_},o==null?void 0:o.id),e.jsx(Ve,{open:!!n,onClose:()=>a(null),label:n,onSubmit:q},n==null?void 0:n.id)]})}const J=f.createContext({}),P=()=>f.useContext(J),$e=()=>{const{updateLabels:t}=P();f.useEffect(()=>()=>{t()},[])};function Qe({fetchLabels:t,children:r}){const{locale:c}=D.useLocaleContext(),[o,l]=f.useState({loading:!0,labels:[],updateCounter:1});f.useEffect(()=>{(async()=>{try{l(S=>({...S,loading:!0}));const m=await t();l(S=>({...S,loading:!1,labels:V(m)}))}catch(m){console.error(m),l(S=>({...S,loading:!1,labels:[]}))}})()},[o.updateCounter]);const n=f.useMemo(()=>{var m;return(m=o.labels)!=null&&m.length?z(o.labels).reduce((S,d)=>({...S,[d.id]:d}),{}):{}},[o.labels]),a=f.useCallback(i=>{var m;return{...i,name:((m=i.translation)==null?void 0:m[c])||i.name}},[c]),u=f.useCallback(i=>i.filter(Boolean).map(m=>n[m]).map(a),[n,a]),p=f.useCallback(i=>(i==null?void 0:i.split(","))||[],[]),y=f.useCallback((i=[])=>{if(!!(i!=null&&i.length))return i.join(",")},[]),x=f.useMemo(()=>o.labels.map(a),[o.labels,a]),C=f.useMemo(()=>({loading:o.loading,labels:o.labels||[],updateLabels:()=>l(i=>({...i,updateCounter:++o.updateCounter})),getLabelsById:u,parseLabelIds:p,stringifyLabelIds:y,localizedLabels:x}),[o,u,p,y,x]);return e.jsx(J.Provider,{value:C,children:r})}function Ue({labels:t,editable:r,onChange:c,sx:o}){const l=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:u}=P(),[p,y]=f.useState(!1);if(a||!r&&l)return null;const x=m=>{c==null||c(m),setTimeout(()=>{y(!1)},300)};if(p)return e.jsx(Te.default,{onClickAway:()=>p&&y(!1),children:e.jsx("div",{children:e.jsx(H,{data:n,value:t||[],onChange:x})})});const C=u(t||[]),i=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(o)?o:[o]];return e.jsxs(g.default,{sx:i,children:[C.map(m=>m?e.jsx(qe.default,{label:m.name,variant:"filled",size:"small",sx:{borderRadius:1}},m.id):null),r&&!l&&e.jsx(L.default,{color:"inherit",size:"small",onClick:()=>y(!0),sx:{color:"grey.400"},children:e.jsx(_e.default,{sx:{fontSize:20}})}),r&&l&&e.jsx(T.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(ke.default,{}),onClick:()=>y(!0),children:"Edit labels"})]})}s.LabelManager=Ke,s.LabelPicker=H,s.LabelTree=O,s.Labels=Ue,s.LabelsProvider=Qe,s.transformLabels=V,s.useLabelsContext=P,s.useLabelsUpdateOnDestroy=$e,Object.defineProperties(s,{__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.4.
|
|
3
|
+
"version": "1.4.16",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"resolutions": {
|
|
75
75
|
"react": "^18.2.0"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "23a1ad24eb0189fc755d3a2586452e898f7c79c6"
|
|
78
78
|
}
|