@blocklet/labels 1.4.12 → 1.4.13
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 +3 -2
- package/dist/components/label/label-form-dialog.d.ts +1 -1
- package/dist/components/label/translation-input.d.ts +11 -0
- package/dist/components/label/types.d.ts +6 -1
- package/dist/components/label/utils.d.ts +1 -0
- package/dist/index.es.js +554 -380
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(s,f){typeof exports=="object"&&typeof module<"u"?f(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("react-use/lib/useSetState"),require("@mui/material/TextField"),require("@mui/base/ClickAwayListener"),require("react-color"),require("@arcblock/ux/lib/Dialog"),require("@mui/material/Alert"),require("@mui/icons-material/Edit"),require("@mui/icons-material/LabelOutlined"),require("@mui/material/ClickAwayListener"),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","react-use/lib/useSetState","@mui/material/TextField","@mui/base/ClickAwayListener","react-color","@arcblock/ux/lib/Dialog","@mui/material/Alert","@mui/icons-material/Edit","@mui/icons-material/LabelOutlined","@mui/material/ClickAwayListener","@mui/material/Chip"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.DiscussKitComponents={},s.React,s.ExpandMoreIcon,s.Box,s.styles,s.reactArborist,s.react$1,s.jsxRuntime,s.omit,s.Select,s.Typography,s.Button,s.IconButton,s.DeleteOutlineOutlinedIcon,s.EditOutlinedIcon,s.AddIcon,s.useSetState,s.TextField,s.ClickAwayListener,s.reactColor,s.Dialog,s.Alert,s.EditIcon,s.LabelOutlinedIcon,s.ClickAwayListener$1,s.Chip))})(this,function(s,f,
|
|
1
|
+
(function(s,f){typeof exports=="object"&&typeof module<"u"?f(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("react-use/lib/useSetState"),require("@mui/material/TextField"),require("@mui/base/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/ClickAwayListener"),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","react-use/lib/useSetState","@mui/material/TextField","@mui/base/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/ClickAwayListener","@mui/material/Chip"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.DiscussKitComponents={},s.React,s.ExpandMoreIcon,s.Box,s.styles,s.reactArborist,s.react$1,s.jsxRuntime,s.omit,s.Select,s.Typography,s.Button,s.IconButton,s.DeleteOutlineOutlinedIcon,s.EditOutlinedIcon,s.AddIcon,s.useSetState,s.TextField,s.ClickAwayListener,s.reactColor,s.Dialog,s.material,s.TranslateIcon,s.Popover,s.context,s.Alert,s.EditIcon,s.LabelOutlinedIcon,s.ClickAwayListener$1,s.Chip))})(this,function(s,f,K,$,E,Q,U,e,Y,B,Z,G,X,R,ee,te,re,ne,le,oe,ae,k,se,ie,D,de,ce,ue,fe,he){"use strict";const b=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},N=b(K),g=b($),pe=b(Y),ge=b(B),me=b(Z),T=b(G),L=b(X),xe=b(R),ye=b(ee),Ce=b(te),ve=b(re),M=b(ne),be=b(le),F=b(ae),Ie=b(se),Se=b(ie),we=b(de),_e=b(ce),ke=b(ue),Te=b(fe),qe=b(he),Ae=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"})}),Le=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"})}),W=f.createContext({});function Oe({selectable:t=!1,selected:r=[],onSelect:c,renderItem:o,children:l}){const n=p=>r.indexOf(p)!==-1,a=p=>{Array.from(new Set(r).add(p)),c==null||c(p)},u=f.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:o}),[r]);return e.jsx(W.Provider,{value:u,children:l})}const ze=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function Be({node:t}){return ze(t)?e.jsx("span",{}):t.isOpen?e.jsx(N.default,{style:{fontSize:20}}):e.jsx(N.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Me({node:t,style:r,dragHandle:c}){const{selectable:o,select:l,isSelected:n,renderItem:a}=f.useContext(W),{data:u}=t,p=u.icon?e.jsx(U.Icon,{icon:u.icon,style:{fontSize:18}}):e.jsx(Ae,{style:{fontSize:18,color:u.color||"#ddd"}}),y=i=>{i.stopPropagation(),t.isInternal&&t.toggle()},x=i=>{i.stopPropagation(),o&&l(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(g.default,{sx:{display:"flex",cursor:"pointer"},onClick:y,children:e.jsx(Be,{node:t})}),e.jsx(g.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:p}),e.jsx(g.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),o&&n(t.id)&&e.jsx(Le,{})]});return e.jsxs(g.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:c,onClick:x,children:[!a&&C,!!a&&a(C,t.data)]})}const Pe=E.styled(g.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 O({data:t,selectable:r,selected:c=[],onSelect:o,rowHeight:l=28,renderItem:n,sx:a,...u}){const p=f.useRef(),y=[...Array.isArray(a)?a:[a]],[x,C]=f.useState(0),i=f.useCallback(()=>{var S,d;C((((d=(S=p.current)==null?void 0:S.visibleNodes)==null?void 0:d.length)||0)*l)},[l]);f.useEffect(()=>{i()},[t,i]);const m=()=>{setTimeout(i)};return e.jsx(Oe,{selectable:r,selected:c,onSelect:o,renderItem:n,children:e.jsx(Pe,{...u,sx:y,children:e.jsx(Q.Tree,{data:t,rowHeight:l,height:x,indent:32,ref:p,onToggle:m,children:Me})})})}const z=t=>t.reduce((r,c)=>{var o;return r.push(c),(o=c.children)!=null&&o.length&&r.push(...z(c.children)),r},[]),j=t=>t.map(r=>{var c;return(c=r.children)!=null&&c.length&&(r.children=j(r.children)),r}),Ee=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},V=t=>{const r=t.reduce((l,n)=>(l[n.id]=l[n.id]||{},n.parentId&&(l[n.id].parent=n.parentId,l[n.parentId]=l[n.parentId]||{},l[n.parentId].children=l[n.parentId].children||[],l[n.parentId].children.push(n.id)),l),{}),c=t.map(({parentId:l,translation:n,...a})=>({...a,translation:Ee(n),children:[]})),o=c.reduce((l,n)=>({...l,[n.id]:n}),{});return c.forEach(l=>{const n=r[l.id];n.parent&&o[n.parent]&&(l.parent=o[n.parent]),n.children&&(l.children=n.children.map(a=>o[a]))}),c.filter(l=>!l.parent)},De=t=>{const{options:r,getValue:c,selectProps:o,selectOption:l}=t,n=c(),a=u=>{const p=r.find(y=>y.data.id===u);p&&l(p)};return e.jsxs(e.Fragment,{children:[e.jsx(B.components.MenuList,{...pe.default(t,["addon"]),children:e.jsx(g.default,{sx:{px:2,py:1},children:e.jsx(O,{data:o.data,selectable:!0,onSelect:a,selected:n.map(u=>u.data.id)})})}),t.addon]})},Ne=({children:t,...r})=>{const[c,o]=t,l=Array.isArray(c)?c.length:0;return e.jsxs(B.components.ValueContainer,{...r,children:[e.jsx(g.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:l?"Labels":"Filter by labels"}),!!l&&e.jsx(g.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:l}),o]})},Fe={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function H({data:t,value:r=[],editable:c=!1,addon:o,onChange:l,compact:n,...a}){const u=f.useRef(null),p=f.useMemo(()=>z(t).map(d=>({data:d,label:d.name,value:d.id})),[t]),y=p.reduce((d,_)=>({...d,[_.data.id]:_}),{}),x=Array.isArray(r)?r:[r],C=x.map(d=>y[d]),i=f.useRef({prev:x.map(d=>y[d].data)}),m=(d,_)=>{i.current.current=d.map(q=>q.data),["clear","remove-value"].includes(_.action)&&u.current&&setTimeout(()=>{var q;return(q=u==null?void 0:u.current)==null?void 0:q.blur()},1)},S=()=>{i.current.current&&JSON.stringify(i.current.prev.map(_=>_.id))!==JSON.stringify(i.current.current.map(_=>_.id))&&(l(i.current.current),i.current.prev=i.current.current)};return e.jsx(g.default,{...a,children:e.jsx(ge.default,{ref:u,defaultValue:C,options:p,onChange:m,components:{MenuList:d=>e.jsx(De,{...d,addon:o}),...n&&{ValueContainer:Ne}},placeholder:"Select labels",styles:{...n&&Fe,menu:d=>({...d,...c&&{paddingBottom:"36px"},zIndex:99}),menuList:d=>({...d,overflowY:"auto",maxHeight:"264px"})},theme:d=>({...d,colors:{...d.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:!0,closeMenuOnSelect:!1,onMenuClose:S,data:t})})}function We({I18NProps:t,...r}){const{languages:c}=D.useLocaleContext(),{translation:o,onChange:l}=t,[n,a]=f.useState(null),u=x=>{const C=x.currentTarget.closest(".MuiInputBase-root");C&&a(C)},p=()=>{a(null)},y=c.filter(x=>x.code!=="en");return e.jsx(k.TextField,{...r,InputProps:{endAdornment:e.jsxs(k.InputAdornment,{position:"end",children:[e.jsx(k.IconButton,{edge:"end",onClick:u,children:e.jsx(Ie.default,{})}),e.jsx(Se.default,{open:!!n,anchorEl:n,onClose:p,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(k.Box,{sx:{p:2},children:y.map(({code:x,name:C})=>e.jsxs(k.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(k.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(k.Box,{sx:{flex:1},children:e.jsx(k.TextField,{value:o[x]||"",size:"small",sx:{width:1},onChange:i=>l({...o,[x]:i.target.value})})})]},x))})})]})}})}function je({open:t,initialLabel:r,onSubmit:c,onClose:o,...l}){const n=!(r!=null&&r.id),[a,u]=ve.default({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)||{}}),p=d=>/^#([0-9A-F]{3}){1,2}$/i.test(d),y=f.useMemo(()=>n?a.name&&a.color&&a.slug&&p(a.color):a.name&&a.color&&p(a.color),[a,n]),[x,C]=f.useState(!1),i=()=>{c({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},m=d=>{u({color:d.hex}),setTimeout(()=>C(!1))},S=d=>{u({color:d.target.value})};return e.jsx(F.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(T.default,{color:"inherit",variant:"contained",size:"small",onClick:o,children:"Cancel"}),e.jsx(T.default,{color:"primary",variant:"contained",size:"small",onClick:i,disabled:!y,children:n?"Create":"Save Changes"})]}),onClose:o,...l,children:e.jsxs(g.default,{width:600,minHeight:280,children:[e.jsx(We,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:d=>u({name:d.target.value}),I18NProps:{translation:a.translation,onChange:d=>u({translation:d})}}),e.jsx(M.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:d=>u({slug:d.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(M.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(be.default,{onClickAway:()=>C(!1),children:e.jsxs(g.default,{sx:{position:"relative",mt:2},children:[e.jsxs(g.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(g.default,{sx:{width:30,height:30,bgcolor:a.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(M.default,{label:"",value:a.color,size:"small",onChange:S,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),x&&e.jsx(g.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(oe.GithubPicker,{color:a.color,onChangeComplete:m})})]})})]})})}function Ve({open:t,label:r,onSubmit:c,onClose:o,...l}){return e.jsx(F.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(T.default,{color:"inherit",variant:"contained",size:"small",onClick:o,children:"Cancel"}),e.jsx(T.default,{color:"primary",variant:"contained",size:"small",onClick:c,children:"Delete"})]}),onClose:o,...l,children:e.jsxs(g.default,{width:600,minHeight:280,children:[e.jsx(we.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(O,{data:[r]})]})})}const He=E.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
|
|
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"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/labels",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.13",
|
|
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": "6158b77b6d0b352a9dbb4883ac07e12127fdc53d"
|
|
78
78
|
}
|