@blocklet/labels 1.5.150 → 1.5.152
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 +1 -0
- package/dist/index.umd.js +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -591,6 +591,7 @@ const Fe = (e) => {
|
|
|
591
591
|
} catch {
|
|
592
592
|
return e;
|
|
593
593
|
}
|
|
594
|
+
return e;
|
|
594
595
|
};
|
|
595
596
|
function ct({ labels: e, editable: t, onChange: s, sx: l, renderLabel: o }) {
|
|
596
597
|
const n = !(e != null && e.length), { labels: a, loading: u, getLabelsById: p, getFullLabelName: y } = Q(), [b, m] = A(!1);
|
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 Ce({data:r,api:t,...a}){const[s,o]=h.useState(null),[n,l]=h.useState(null),[u,g]=h.useState(_(r)),b=h.useMemo(()=>q(u),[u]),S=h.useMemo(()=>{const d=(C,k)=>C.map(v=>(k&&(v.parent=k),v.children&&(v.children=d(v.children,v)),v));return d(u)},[u]),m=d=>{var C,k;d.parent?(d.parent.children=(k=(C=d.parent)==null?void 0:C.children)==null?void 0:k.map(v=>v.id===d.id?{...d}:v),m(d.parent)):g(u.map(v=>v.id===d.id?{...d}:v))},x=d=>{d.parent?(d.parent.children=d.parent.children||[],d.parent.children.push(d),g([...u])):g([...u,d])},I=d=>{var C;d.parent?d.parent.children=(C=d.parent.children)==null?void 0:C.filter(k=>k.id!==d.id):g(u.filter(k=>k.id!==d.id))},c=d=>{if(s)return;o({id:"",name:"New label",parent:d,color:"#dddddd"})},i=d=>{s||o(d)},w=async d=>{if(!s)return;const{parent:C,children:k,translation:v,...N}=d;s.id?(await t.updateLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),m(d)):(await t.createLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),x(d)),o(null)},p=async()=>{n&&(await t.deleteLabel(n.id),I(n),l(null))},z=(d,C)=>e.jsxs(e.Fragment,{children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(y,{children:d}),C.translation&&e.jsx(y,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(C.translation).map(k=>{var N;const v=(N=C.translation)==null?void 0:N[k];return v?e.jsx(W.TranslationTag,{locale:k,value:v},k):null})})]}),e.jsxs(y,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>c(C),children:e.jsx(T.Add,{sx:{fontSize:20}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>i(C),children:e.jsx(T.EditOutlined,{sx:{fontSize:18}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>l(C),children:e.jsx(T.DeleteOutlineOutlined,{sx:{fontSize:20}})})]})]});return e.jsxs(y,{...a,className:"label-container",children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(G,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(L,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>c(),children:"New label"})]}),e.jsxs(y,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(y,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[b.length," labels"]}),e.jsx(y,{sx:{pt:.5},children:e.jsx(me,{data:S,selected:[],renderItem:z,rowHeight:64})})]}),e.jsx(ge,{open:!!s,onClose:()=>o(null),initialLabel:s,onSubmit:w},s==null?void 0:s.id),e.jsx(ye,{open:!!n,onClose:()=>l(null),label:n,onSubmit:p},n==null?void 0:n.id)]})}const $=h.createContext({}),F=()=>h.useContext($),be=()=>{const{updateLabels:r}=F();h.useEffect(()=>()=>{r()},[])};function xe({fetchLabels:r,children:t}){const{locale:a}=R.useLocaleContext(),[s,o]=h.useState({loading:!0,labels:[],updateCounter:1});h.useEffect(()=>{(async()=>{try{o(w=>({...w,loading:!0}));const i=await r();o(w=>({...w,loading:!1,labels:H(i)}))}catch(i){console.error(i),o(w=>({...w,loading:!1,labels:[]}))}})()},[s.updateCounter]);const n=h.useMemo(()=>{var i;return(i=s.labels)!=null&&i.length?q(s.labels).reduce((w,p)=>({...w,[p.id]:p}),{}):{}},[s.labels]),l=h.useCallback(c=>{var i;return{...c,name:((i=c.translation)==null?void 0:i[a])||c.name}},[a]),u=h.useCallback(c=>c.filter(Boolean).map(i=>n[i]).map(l),[n,l]),g=h.useCallback(c=>{let{parent:i}=c;const w=[];for(;i;)w.unshift(i),i=i.parent;return w},[]),b=h.useCallback(c=>[...g(c),c].map(l).map(w=>w.name).join(" / "),[l,g]),S=h.useCallback(c=>(c==null?void 0:c.split(","))||[],[]),m=h.useCallback((c=[])=>{if(c!=null&&c.length)return c.join(",")},[]),x=h.useMemo(()=>s.labels.map(l),[s.labels,l]),I=h.useMemo(()=>({loading:s.loading,labels:s.labels||[],updateLabels:()=>o(c=>({...c,updateCounter:++s.updateCounter})),getLabelsById:u,parseLabelIds:S,stringifyLabelIds:m,localizedLabels:x,flattenedLabels:q(x||[]),getFullLabelName:b}),[s,u,S,m,x,b]);return e.jsx($.Provider,{value:I,children:t})}const ve=r=>{try{return A.getContrastRatio(r,"#fff")>3.5?"#fff":"#111"}catch{return"#111"}},Se=(r,t)=>{try{if(r)return A.alpha(r,t)}catch{return r}};function we({labels:r,editable:t,onChange:a,sx:s,renderLabel:o}){const n=!(r!=null&&r.length),{labels:l,loading:u,getLabelsById:g,getFullLabelName:b}=F(),[S,m]=h.useState(!1);if(u||!t&&n)return null;const x=i=>{a==null||a(i),setTimeout(()=>{m(!1)},300)};if(S)return e.jsx(A.ClickAwayListener,{onClickAway:()=>S&&m(!1),children:e.jsx("div",{children:e.jsx(K,{data:l,value:r||[],onChange:x})})});const I=g(r||[]),c=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(s)?s:[s]];return e.jsxs(A.Box,{sx:c,children:[I.map(i=>i?o?o(i):e.jsx(A.Chip,{label:b(i),variant:"filled",size:"small",sx:{height:20,borderRadius:1,fontSize:12,bgcolor:Se(i.color,.8),color:ve(i.color)}},i.id):null),t&&!n&&e.jsx(A.IconButton,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(T.Edit,{sx:{fontSize:20}})}),t&&n&&e.jsx(A.Button,{color:"inherit",variant:"outlined",startIcon:e.jsx(T.LabelOutlined,{}),onClick:()=>m(!0),children:"Edit labels"})]})}f.LabelManager=Ce,f.LabelPicker=K,f.LabelTree=O,f.Labels=we,f.LabelsProvider=xe,f.transformLabels=H,f.useLabelsContext=F,f.useLabelsUpdateOnDestroy=be,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
34
|
+
`;function Ce({data:r,api:t,...a}){const[s,o]=h.useState(null),[n,l]=h.useState(null),[u,g]=h.useState(_(r)),b=h.useMemo(()=>q(u),[u]),S=h.useMemo(()=>{const d=(C,k)=>C.map(v=>(k&&(v.parent=k),v.children&&(v.children=d(v.children,v)),v));return d(u)},[u]),m=d=>{var C,k;d.parent?(d.parent.children=(k=(C=d.parent)==null?void 0:C.children)==null?void 0:k.map(v=>v.id===d.id?{...d}:v),m(d.parent)):g(u.map(v=>v.id===d.id?{...d}:v))},x=d=>{d.parent?(d.parent.children=d.parent.children||[],d.parent.children.push(d),g([...u])):g([...u,d])},I=d=>{var C;d.parent?d.parent.children=(C=d.parent.children)==null?void 0:C.filter(k=>k.id!==d.id):g(u.filter(k=>k.id!==d.id))},c=d=>{if(s)return;o({id:"",name:"New label",parent:d,color:"#dddddd"})},i=d=>{s||o(d)},w=async d=>{if(!s)return;const{parent:C,children:k,translation:v,...N}=d;s.id?(await t.updateLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),m(d)):(await t.createLabel({...N,translation:JSON.stringify(v),parentId:C==null?void 0:C.id}),x(d)),o(null)},p=async()=>{n&&(await t.deleteLabel(n.id),I(n),l(null))},z=(d,C)=>e.jsxs(e.Fragment,{children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(y,{children:d}),C.translation&&e.jsx(y,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(C.translation).map(k=>{var N;const v=(N=C.translation)==null?void 0:N[k];return v?e.jsx(W.TranslationTag,{locale:k,value:v},k):null})})]}),e.jsxs(y,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>c(C),children:e.jsx(T.Add,{sx:{fontSize:20}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>i(C),children:e.jsx(T.EditOutlined,{sx:{fontSize:18}})}),e.jsx(M,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>l(C),children:e.jsx(T.DeleteOutlineOutlined,{sx:{fontSize:20}})})]})]});return e.jsxs(y,{...a,className:"label-container",children:[e.jsxs(y,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(G,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(L,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>c(),children:"New label"})]}),e.jsxs(y,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(y,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[b.length," labels"]}),e.jsx(y,{sx:{pt:.5},children:e.jsx(me,{data:S,selected:[],renderItem:z,rowHeight:64})})]}),e.jsx(ge,{open:!!s,onClose:()=>o(null),initialLabel:s,onSubmit:w},s==null?void 0:s.id),e.jsx(ye,{open:!!n,onClose:()=>l(null),label:n,onSubmit:p},n==null?void 0:n.id)]})}const $=h.createContext({}),F=()=>h.useContext($),be=()=>{const{updateLabels:r}=F();h.useEffect(()=>()=>{r()},[])};function xe({fetchLabels:r,children:t}){const{locale:a}=R.useLocaleContext(),[s,o]=h.useState({loading:!0,labels:[],updateCounter:1});h.useEffect(()=>{(async()=>{try{o(w=>({...w,loading:!0}));const i=await r();o(w=>({...w,loading:!1,labels:H(i)}))}catch(i){console.error(i),o(w=>({...w,loading:!1,labels:[]}))}})()},[s.updateCounter]);const n=h.useMemo(()=>{var i;return(i=s.labels)!=null&&i.length?q(s.labels).reduce((w,p)=>({...w,[p.id]:p}),{}):{}},[s.labels]),l=h.useCallback(c=>{var i;return{...c,name:((i=c.translation)==null?void 0:i[a])||c.name}},[a]),u=h.useCallback(c=>c.filter(Boolean).map(i=>n[i]).map(l),[n,l]),g=h.useCallback(c=>{let{parent:i}=c;const w=[];for(;i;)w.unshift(i),i=i.parent;return w},[]),b=h.useCallback(c=>[...g(c),c].map(l).map(w=>w.name).join(" / "),[l,g]),S=h.useCallback(c=>(c==null?void 0:c.split(","))||[],[]),m=h.useCallback((c=[])=>{if(c!=null&&c.length)return c.join(",")},[]),x=h.useMemo(()=>s.labels.map(l),[s.labels,l]),I=h.useMemo(()=>({loading:s.loading,labels:s.labels||[],updateLabels:()=>o(c=>({...c,updateCounter:++s.updateCounter})),getLabelsById:u,parseLabelIds:S,stringifyLabelIds:m,localizedLabels:x,flattenedLabels:q(x||[]),getFullLabelName:b}),[s,u,S,m,x,b]);return e.jsx($.Provider,{value:I,children:t})}const ve=r=>{try{return A.getContrastRatio(r,"#fff")>3.5?"#fff":"#111"}catch{return"#111"}},Se=(r,t)=>{try{if(r)return A.alpha(r,t)}catch{return r}return r};function we({labels:r,editable:t,onChange:a,sx:s,renderLabel:o}){const n=!(r!=null&&r.length),{labels:l,loading:u,getLabelsById:g,getFullLabelName:b}=F(),[S,m]=h.useState(!1);if(u||!t&&n)return null;const x=i=>{a==null||a(i),setTimeout(()=>{m(!1)},300)};if(S)return e.jsx(A.ClickAwayListener,{onClickAway:()=>S&&m(!1),children:e.jsx("div",{children:e.jsx(K,{data:l,value:r||[],onChange:x})})});const I=g(r||[]),c=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(s)?s:[s]];return e.jsxs(A.Box,{sx:c,children:[I.map(i=>i?o?o(i):e.jsx(A.Chip,{label:b(i),variant:"filled",size:"small",sx:{height:20,borderRadius:1,fontSize:12,bgcolor:Se(i.color,.8),color:ve(i.color)}},i.id):null),t&&!n&&e.jsx(A.IconButton,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(T.Edit,{sx:{fontSize:20}})}),t&&n&&e.jsx(A.Button,{color:"inherit",variant:"outlined",startIcon:e.jsx(T.LabelOutlined,{}),onClick:()=>m(!0),children:"Edit labels"})]})}f.LabelManager=Ce,f.LabelPicker=K,f.LabelTree=O,f.Labels=we,f.LabelsProvider=xe,f.transformLabels=H,f.useLabelsContext=F,f.useLabelsUpdateOnDestroy=be,Object.defineProperty(f,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.152",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@blocklet/translation-input": "1.5.
|
|
31
|
+
"@blocklet/translation-input": "1.5.152",
|
|
32
32
|
"@emotion/css": "^11.10.5",
|
|
33
33
|
"@emotion/react": "^11.10.5",
|
|
34
34
|
"@emotion/styled": "^11.10.5",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"resolutions": {
|
|
77
77
|
"react": "^18.2.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "cd85f290d1d617b9625997c913fc592bf671be4c"
|
|
80
80
|
}
|