@blocklet/labels 1.5.32 → 1.5.34

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.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(c,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("@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","@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):(c=typeof globalThis<"u"?globalThis:c||self,f(c.DiscussKitComponents={},c.React,c.ExpandMoreIcon,c.Box,c.styles,c.reactArborist,c.react$1,c.jsxRuntime,c.omit,c.Select,c.Typography,c.Button,c.IconButton,c.DeleteOutlineOutlinedIcon,c.EditOutlinedIcon,c.AddIcon,c.TextField,c.ClickAwayListener,c.reactColor,c.Dialog,c.material,c.TranslateIcon,c.Popover,c.context,c.Alert,c.EditIcon,c.LabelOutlinedIcon,c.ClickAwayListener$1,c.Chip))})(this,function(c,f,K,Q,D,U,Y,e,Z,M,G,X,R,ee,te,re,ne,le,oe,ae,k,se,ie,N,de,ce,ue,fe,he){"use strict";const b=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},F=b(K),g=b(Q),pe=b(Z),ge=b(M),me=b(G),O=b(X),L=b(R),ye=b(ee),xe=b(te),Ce=b(re),E=b(ne),ve=b(le),j=b(ae),be=b(se),Se=b(ie),Ie=b(de),we=b(ce),_e=b(ue),ke=b(fe),Oe=b(he),Te=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),Ae=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 Le({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:o}){const n=p=>r.indexOf(p)!==-1,a=p=>{Array.from(new Set(r).add(p)),s==null||s(p)},i=f.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:l}),[r]);return e.jsx(W.Provider,{value:i,children:o})}const qe=t=>{var r;return t.isLeaf||!((r=t.data.children)!=null&&r.length)};function ze({node:t}){return qe(t)?e.jsx("span",{}):t.isOpen?e.jsx(F.default,{style:{fontSize:20}}):e.jsx(F.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Be({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=f.useContext(W),{data:i}=t,p=i.icon?e.jsx(Y.Icon,{icon:i.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:i.color||"#ddd"}}),x=d=>{d.stopPropagation(),t.isInternal&&t.toggle()},y=d=>{d.stopPropagation(),l&&o(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:x,children:e.jsx(ze,{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})]}),l&&n(t.id)&&e.jsx(Ae,{})]});return e.jsxs(g.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 Me=D.styled(g.default)`
1
+ (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react"),require("@mui/icons-material/ExpandMore"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),require("react/jsx-runtime"),require("lodash/omit"),require("react-select"),require("@mui/material/Typography"),require("@mui/material/Button"),require("@mui/material/IconButton"),require("@mui/icons-material/DeleteOutlineOutlined"),require("@mui/icons-material/EditOutlined"),require("@mui/icons-material/Add"),require("@mui/material/TextField"),require("@mui/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","@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"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.DiscussKitComponents={},i.React,i.ExpandMoreIcon,i.Box,i.styles,i.reactArborist,i.react$1,i.jsxRuntime,i.omit,i.Select,i.Typography,i.Button,i.IconButton,i.DeleteOutlineOutlinedIcon,i.EditOutlinedIcon,i.AddIcon,i.TextField,i.ClickAwayListener,i.reactColor,i.Dialog,i.material,i.TranslateIcon,i.Popover,i.context,i.Alert,i.EditIcon,i.LabelOutlinedIcon,i.ClickAwayListener$1,i.Chip))})(this,function(i,u,Q,U,N,Y,Z,e,G,E,X,R,ee,te,re,ne,le,oe,ae,se,A,ie,de,F,ce,ue,fe,he,pe){"use strict";const I=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},j=I(Q),p=I(U),ge=I(G),me=I(E),ye=I(X),O=I(R),L=I(ee),xe=I(te),Ce=I(re),ve=I(ne),P=I(le),be=I(oe),W=I(se),Se=I(ie),Ie=I(de),we=I(ce),_e=I(ue),ke=I(fe),Ae=I(he),Oe=I(pe),Te=t=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...t,children:e.jsx("path",{fill:"currentColor",d:"M5 19q-.825 0-1.413-.587Q3 17.825 3 17V7q0-.825.587-1.412Q4.175 5 5 5h10q.5 0 .938.225q.437.225.712.625l3.525 5q.375.525.375 1.15q0 .625-.375 1.15l-3.525 5q-.275.4-.712.625Q15.5 19 15 19Z"})}),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"})}),V=u.createContext({});function qe({selectable:t=!1,selected:r=[],onSelect:s,renderItem:l,children:o}){const n=h=>r.indexOf(h)!==-1,a=h=>{Array.from(new Set(r).add(h)),s==null||s(h)},d=u.useMemo(()=>({selectable:t,selected:r,isSelected:n,select:a,renderItem:l}),[r]);return e.jsx(V.Provider,{value:d,children:o})}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(j.default,{style:{fontSize:20}}):e.jsx(j.default,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function Ee({node:t,style:r,dragHandle:s}){const{selectable:l,select:o,isSelected:n,renderItem:a}=u.useContext(V),{data:d}=t,h=d.icon?e.jsx(Z.Icon,{icon:d.icon,style:{fontSize:18}}):e.jsx(Te,{style:{fontSize:18,color:d.color||"#ddd"}}),m=f=>{f.stopPropagation(),t.isInternal&&t.toggle()},x=f=>{f.stopPropagation(),l&&o(t.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(p.default,{sx:{display:"flex",cursor:"pointer"},onClick:m,children:e.jsx(Be,{node:t})}),e.jsx(p.default,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:h}),e.jsx(p.default,{component:"span",sx:{color:"grey.700"},children:t.data.name})]}),l&&n(t.id)&&e.jsx(Le,{})]});return e.jsxs(p.default,{className:"label-tree-item",style:r,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:s,onClick:x,children:[!a&&C,!!a&&a(C,t.data)]})}const Pe=N.styled(p.default)`
2
2
  > div,
3
3
  > div > div,
4
4
  > div > div > div {
@@ -11,7 +11,7 @@
11
11
  .label-tree-item {
12
12
  width: 100%;
13
13
  }
14
- `;function q({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:o=28,renderItem:n,sx:a,...i}){const p=f.useRef(),x=[...Array.isArray(a)?a:[a]],[y,C]=f.useState(0),d=f.useCallback(()=>{var I,u;C((((u=(I=p.current)==null?void 0:I.visibleNodes)==null?void 0:u.length)||0)*o)},[o]);f.useEffect(()=>{d()},[t,d]);const m=()=>{setTimeout(d)};return e.jsx(Le,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Me,{...i,sx:x,children:e.jsx(U.Tree,{data:t,rowHeight:o,height:y,indent:32,ref:p,onToggle:m,children:Be})})})}const z=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...z(s.children)),r},[]),V=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=V(r.children)),r}),Ee=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},H=t=>{const r=t.reduce((o,n)=>(o[n.id]=o[n.id]||{},n.parentId&&(o[n.id].parent=n.parentId,o[n.parentId]=o[n.parentId]||{},o[n.parentId].children=o[n.parentId].children||[],o[n.parentId].children.push(n.id)),o),{}),s=t.map(({parentId:o,translation:n,...a})=>({...a,translation:Ee(n),children:[]})),l=s.reduce((o,n)=>({...o,[n.id]:n}),{});return s.forEach(o=>{const n=r[o.id];n.parent&&l[n.parent]&&(o.parent=l[n.parent]),n.children&&(o.children=n.children.map(a=>l[a]))}),s.filter(o=>!o.parent)},Pe=t=>{const{options:r,getValue:s,selectProps:l,selectOption:o}=t,n=s(),a=i=>{const p=r.find(x=>x.data.id===i);p&&o(p)};return e.jsxs(e.Fragment,{children:[e.jsx(M.components.MenuList,{...pe.default(t,["addon"]),children:e.jsx(g.default,{sx:{px:2,py:1},children:e.jsx(q,{data:l.data,selectable:!0,onSelect:a,selected:n.map(i=>i.data.id)})})}),t.addon]})},De=({children:t,...r})=>{const[s,l]=t,o=Array.isArray(s)?s.length:0;return e.jsxs(M.components.ValueContainer,{...r,children:[e.jsx(g.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&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:o}),l]})},Ne={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function J({data:t,value:r=[],editable:s=!1,addon:l,onChange:o,compact:n,...a}){const i=f.useRef(null),p=f.useMemo(()=>z(t).map(u=>({data:u,label:u.name,value:u.id})),[t]),x=p.reduce((u,_)=>({...u,[_.data.id]:_}),{}),y=Array.isArray(r)?r:[r],C=y.map(u=>x[u]),d=f.useRef({prev:y.map(u=>x[u].data)}),m=(u,_)=>{d.current.current=u.map(T=>T.data),["clear","remove-value"].includes(_.action)&&i.current&&setTimeout(()=>{var T;return(T=i==null?void 0:i.current)==null?void 0:T.blur()},1)},I=()=>{d.current.current&&JSON.stringify(d.current.prev.map(_=>_.id))!==JSON.stringify(d.current.current.map(_=>_.id))&&(o(d.current.current),d.current.prev=d.current.current)};return e.jsx(g.default,{...a,children:e.jsx(ge.default,{ref:i,defaultValue:C,options:p,onChange:m,components:{MenuList:u=>e.jsx(Pe,{...u,addon:l}),...n&&{ValueContainer:De}},placeholder:"Select labels",styles:{...n&&Ne,menu:u=>({...u,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:u=>({...u,overflowY:"auto",maxHeight:"264px"})},theme:u=>({...u,colors:{...u.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:!0,closeMenuOnSelect:!1,onMenuClose:I,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,o=arguments.length;l<o;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},B.apply(this,arguments)};function Fe(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 je=function(t){return typeof t=="function"},We=function(t){var r=Fe(f.useState(t),2),s=r[0],l=r[1],o=f.useCallback(function(n){l(function(a){var i=je(n)?n(a):n;return i?B(B({},a),i):a})},[]);return[s,o]};const Ve=We;function He({I18NProps:t,...r}){const{languages:s}=N.useLocaleContext(),{translation:l,onChange:o}=t,[n,a]=f.useState(null),i=y=>{const C=y.currentTarget.closest(".MuiInputBase-root");C&&a(C)},p=()=>{a(null)},x=s.filter(y=>y.code!=="en");return e.jsx(k.TextField,{...r,InputProps:{endAdornment:e.jsxs(k.InputAdornment,{position:"end",children:[e.jsx(k.IconButton,{edge:"end",onClick:i,children:e.jsx(be.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:x.map(({code:y,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:l[y]||"",size:"small",sx:{width:1},onChange:d=>o({...l,[y]:d.target.value})})})]},y))})})]})}})}function Je({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,i]=Ve({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=u=>/^#([0-9A-F]{3}){1,2}$/i.test(u),x=f.useMemo(()=>n?a.name&&a.color&&a.slug&&p(a.color):a.name&&a.color&&p(a.color),[a,n]),[y,C]=f.useState(!1),d=()=>{s({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},m=u=>{i({color:u.hex}),setTimeout(()=>C(!1))},I=u=>{i({color:u.target.value})};return e.jsx(j.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.default,{color:"primary",variant:"contained",size:"small",onClick:d,disabled:!x,children:n?"Create":"Save Changes"})]}),onClose:l,...o,children:e.jsxs(g.default,{width:600,minHeight:280,children:[e.jsx(He,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:u=>i({name:u.target.value}),I18NProps:{translation:a.translation,onChange:u=>i({translation:u})}}),e.jsx(E.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:u=>i({slug:u.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(ve.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(E.default,{label:"",value:a.color,size:"small",onChange:I,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),y&&e.jsx(g.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(oe.GithubPicker,{color:a.color,onChangeComplete:m})})]})})]})})}function $e({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(j.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.default,{color:"primary",variant:"contained",size:"small",onClick:s,children:"Delete"})]}),onClose:l,...o,children:e.jsxs(g.default,{width:600,minHeight:280,children:[e.jsx(Ie.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(q,{data:[r]})]})})}const Ke=D.styled(q)`
14
+ `;function q({data:t,selectable:r,selected:s=[],onSelect:l,rowHeight:o=28,renderItem:n,sx:a,...d}){const h=u.useRef(),m=[...Array.isArray(a)?a:[a]],[x,C]=u.useState(0),f=u.useCallback(()=>{var v,S;C((((S=(v=h.current)==null?void 0:v.visibleNodes)==null?void 0:S.length)||0)*o)},[o]);u.useEffect(()=>{f()},[t,f]);const y=()=>{setTimeout(f)};return e.jsx(qe,{selectable:r,selected:s,onSelect:l,renderItem:n,children:e.jsx(Pe,{...d,sx:m,children:e.jsx(Y.Tree,{data:t,rowHeight:o,height:x,indent:32,ref:h,onToggle:y,children:Ee})})})}const z=t=>t.reduce((r,s)=>{var l;return r.push(s),(l=s.children)!=null&&l.length&&r.push(...z(s.children)),r},[]),H=t=>t.map(r=>{var s;return(s=r.children)!=null&&s.length&&(r.children=H(r.children)),r}),Me=(t,r=null)=>{try{return JSON.parse(t)}catch{return r}},J=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:Me(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)},De=t=>{const{options:r,getValue:s,selectProps:l,selectOption:o}=t,n=s(),a=d=>{const h=r.find(m=>m.data.id===d);h&&o(h)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...ge.default(t,["addon"]),children:e.jsx(p.default,{sx:{px:2,py:1},children:e.jsx(q,{data:l.data,selectable:!0,onSelect:a,selected:n.map(d=>d.data.id)})})}),t.addon]})},Ne=({children:t,...r})=>{const[s,l]=t,o=Array.isArray(s)?s.length:0;return e.jsxs(E.components.ValueContainer,{...r,children:[e.jsx(p.default,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:o?"Labels":"Filter by labels"}),!!o&&e.jsx(p.default,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:o}),l]})},Fe={control:t=>({...t,minHeight:31}),valueContainer:t=>({...t,display:"flex"}),dropdownIndicator:t=>({...t,padding:"0 4px"}),clearIndicator:t=>({...t,padding:"4px"})};function $({data:t,value:r=[],editable:s=!1,addon:l,onChange:o,compact:n,isMulti:a=!0,maxHeight:d=264,...h}){const m=u.useRef(null),x=u.useMemo(()=>z(t).map(g=>({data:g,label:g.name,value:g.id})),[t]),C=x.reduce((g,k)=>({...g,[k.data.id]:k}),{}),f=Array.isArray(r)?r:[r],y=f.map(g=>C[g]),v=u.useRef({prev:f.map(g=>C[g].data)}),S=(g,k)=>{!a||!Array.isArray(g)?o(g?[g.data]:[]):v.current.current=g.map(c=>c.data),["clear","remove-value"].includes(k.action)&&m.current&&setTimeout(()=>{var c;return(c=m==null?void 0:m.current)==null?void 0:c.blur()},1)},D=()=>{v.current.current&&JSON.stringify(v.current.prev.map(k=>k.id))!==JSON.stringify(v.current.current.map(k=>k.id))&&(o(v.current.current),v.current.prev=v.current.current)};return e.jsx(p.default,{...h,children:e.jsx(me.default,{ref:m,defaultValue:y,options:x,onChange:S,components:{MenuList:g=>e.jsx(De,{...g,addon:l}),...n&&{ValueContainer:Ne}},placeholder:"Select labels",styles:{...n&&Fe,menu:g=>({...g,...s&&{paddingBottom:"36px"},zIndex:99}),menuList:g=>({...g,overflowY:"auto",maxHeight:`${d}px`})},theme:g=>({...g,colors:{...g.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:a,closeMenuOnSelect:!a,onMenuClose:D,isClearable:!0,data:t})})}var B=function(){return B=Object.assign||function(r){for(var s,l=1,o=arguments.length;l<o;l++){s=arguments[l];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(r[n]=s[n])}return r},B.apply(this,arguments)};function je(t,r){var s=typeof Symbol=="function"&&t[Symbol.iterator];if(!s)return t;var l=s.call(t),o,n=[],a;try{for(;(r===void 0||r-- >0)&&!(o=l.next()).done;)n.push(o.value)}catch(d){a={error:d}}finally{try{o&&!o.done&&(s=l.return)&&s.call(l)}finally{if(a)throw a.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var We=function(t){return typeof t=="function"},Ve=function(t){var r=je(u.useState(t),2),s=r[0],l=r[1],o=u.useCallback(function(n){l(function(a){var d=We(n)?n(a):n;return d?B(B({},a),d):a})},[]);return[s,o]};const He=Ve;function Je({I18NProps:t,...r}){const{languages:s}=F.useLocaleContext(),{translation:l,onChange:o}=t,[n,a]=u.useState(null),d=x=>{const C=x.currentTarget.closest(".MuiInputBase-root");C&&a(C)},h=()=>{a(null)},m=s.filter(x=>x.code!=="en");return e.jsx(A.TextField,{...r,InputProps:{endAdornment:e.jsxs(A.InputAdornment,{position:"end",children:[e.jsx(A.IconButton,{edge:"end",onClick:d,children:e.jsx(Se.default,{})}),e.jsx(Ie.default,{open:!!n,anchorEl:n,onClose:h,transformOrigin:{vertical:"top",horizontal:"right"},anchorOrigin:{vertical:"bottom",horizontal:"right"},PaperProps:{sx:{width:n==null?void 0:n.clientWidth,maxHeight:200,overflowY:"auto",bgcolor:"grey.50"}},elevation:1,sx:{mt:2},children:e.jsx(A.Box,{sx:{p:2},children:m.map(({code:x,name:C})=>e.jsxs(A.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(A.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(A.Box,{sx:{flex:1},children:e.jsx(A.TextField,{value:l[x]||"",size:"small",sx:{width:1},onChange:f=>o({...l,[x]:f.target.value})})})]},x))})})]})}})}function $e({open:t,initialLabel:r,onSubmit:s,onClose:l,...o}){const n=!(r!=null&&r.id),[a,d]=He({name:(r==null?void 0:r.name)||"",color:(r==null?void 0:r.color)||"#ddd",slug:(r==null?void 0:r.id)||"",translation:(r==null?void 0:r.translation)||{}}),h=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),m=u.useMemo(()=>n?a.name&&a.color&&a.slug&&h(a.color):a.name&&a.color&&h(a.color),[a,n]),[x,C]=u.useState(!1),f=()=>{s({...r,name:a.name,color:a.color,id:a.slug,translation:a.translation})},y=S=>{d({color:S.hex}),setTimeout(()=>C(!1))},v=S=>{d({color:S.target.value})};return e.jsx(W.default,{open:t,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.default,{color:"primary",variant:"contained",size:"small",onClick:f,disabled:!m,children:n?"Create":"Save Changes"})]}),onClose:l,...o,children:e.jsxs(p.default,{width:600,minHeight:280,children:[e.jsx(Je,{label:"Name",value:a.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>d({name:S.target.value}),I18NProps:{translation:a.translation,onChange:S=>d({translation:S})}}),e.jsx(P.default,{label:"Slug",value:a.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>d({slug:S.target.value}),sx:{mt:2}}),(r==null?void 0:r.parent)&&e.jsx(P.default,{label:"Parent",value:r.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(be.default,{onClickAway:()=>C(!1),children:e.jsxs(p.default,{sx:{position:"relative",mt:2},children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(p.default,{sx:{width:30,height:30,bgcolor:a.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(P.default,{label:"",value:a.color,size:"small",onChange:v,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),x&&e.jsx(p.default,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(ae.GithubPicker,{color:a.color,onChangeComplete:y})})]})})]})})}function Ke({open:t,label:r,onSubmit:s,onClose:l,...o}){return e.jsx(W.default,{open:t,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(O.default,{color:"inherit",variant:"contained",size:"small",onClick:l,children:"Cancel"}),e.jsx(O.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(we.default,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(q,{data:[r]})]})})}const Qe=N.styled(q)`
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 Qe({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 Ue({data:t,api:r,...s}){const[l,o]=f.useState(null),[n,a]=f.useState(null),[i,p]=f.useState(V(t)),x=f.useMemo(()=>z(i),[i]),y=f.useMemo(()=>{const h=(v,w)=>v.map(S=>(w&&(S.parent=w),S.children&&(S.children=h(S.children,S)),S));return h(i)},[i]),C=h=>{var v,w;h.parent?(h.parent.children=(w=(v=h.parent)==null?void 0:v.children)==null?void 0:w.map(S=>S.id===h.id?{...h}:S),C(h.parent)):p(i.map(S=>S.id===h.id?{...h}:S))},d=h=>{h.parent?(h.parent.children=h.parent.children||[],h.parent.children.push(h),p([...i])):p([...i,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(i.filter(w=>w.id!==h.id))},I=h=>{if(l)return;o({id:"",name:"New label",parent:h,color:"#dddddd"})},u=h=>{l||o(h)},_=async h=>{if(!l)return;const{parent:v,children:w,translation:S,...A}=h;l.id?(await r.updateLabel({...A,translation:JSON.stringify(S),parentId:v==null?void 0:v.id}),C(h)):(await r.createLabel({...A,translation:JSON.stringify(S),parentId:v==null?void 0:v.id}),d(h)),o(null)},T=async()=>{!n||(await r.deleteLabel(n.id),m(n),a(null))},Xe=(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 S=(A=v.translation)==null?void 0:A[w];return S?e.jsx(Qe,{locale:w,value:S},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:()=>I(v),children:e.jsx(Ce.default,{sx:{fontSize:20}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>u(v),children:e.jsx(xe.default,{sx:{fontSize:18}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(v),children:e.jsx(ye.default,{sx:{fontSize:20}})})]})]});return e.jsxs(g.default,{...s,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(O.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>I(),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:[x.length," labels"]}),e.jsx(g.default,{sx:{pt:.5},children:e.jsx(Ke,{data:y,selected:[],renderItem:Xe,rowHeight:64})})]}),e.jsx(Je,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:_},l==null?void 0:l.id),e.jsx($e,{open:!!n,onClose:()=>a(null),label:n,onSubmit:T},n==null?void 0:n.id)]})}const $=f.createContext({}),P=()=>f.useContext($),Ye=()=>{const{updateLabels:t}=P();f.useEffect(()=>()=>{t()},[])};function Ze({fetchLabels:t,children:r}){const{locale:s}=N.useLocaleContext(),[l,o]=f.useState({loading:!0,labels:[],updateCounter:1});f.useEffect(()=>{(async()=>{try{o(I=>({...I,loading:!0}));const m=await t();o(I=>({...I,loading:!1,labels:H(m)}))}catch(m){console.error(m),o(I=>({...I,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=f.useMemo(()=>{var m;return(m=l.labels)!=null&&m.length?z(l.labels).reduce((I,u)=>({...I,[u.id]:u}),{}):{}},[l.labels]),a=f.useCallback(d=>{var m;return{...d,name:((m=d.translation)==null?void 0:m[s])||d.name}},[s]),i=f.useCallback(d=>d.filter(Boolean).map(m=>n[m]).map(a),[n,a]),p=f.useCallback(d=>(d==null?void 0:d.split(","))||[],[]),x=f.useCallback((d=[])=>{if(!!(d!=null&&d.length))return d.join(",")},[]),y=f.useMemo(()=>l.labels.map(a),[l.labels,a]),C=f.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>o(d=>({...d,updateCounter:++l.updateCounter})),getLabelsById:i,parseLabelIds:p,stringifyLabelIds:x,localizedLabels:y}),[l,i,p,x,y]);return e.jsx($.Provider,{value:C,children:r})}function Ge({labels:t,editable:r,onChange:s,sx:l}){const o=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:i}=P(),[p,x]=f.useState(!1);if(a||!r&&o)return null;const y=m=>{s==null||s(m),setTimeout(()=>{x(!1)},300)};if(p)return e.jsx(ke.default,{onClickAway:()=>p&&x(!1),children:e.jsx("div",{children:e.jsx(J,{data:n,value:t||[],onChange:y})})});const C=i(t||[]),d=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(g.default,{sx:d,children:[C.map(m=>m?e.jsx(Oe.default,{label:m.name,variant:"filled",size:"small",sx:{borderRadius:1}},m.id):null),r&&!o&&e.jsx(L.default,{color:"inherit",size:"small",onClick:()=>x(!0),sx:{color:"grey.400"},children:e.jsx(we.default,{sx:{fontSize:20}})}),r&&o&&e.jsx(O.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(_e.default,{}),onClick:()=>x(!0),children:"Edit labels"})]})}c.LabelManager=Ue,c.LabelPicker=J,c.LabelTree=q,c.Labels=Ge,c.LabelsProvider=Ze,c.transformLabels=H,c.useLabelsContext=P,c.useLabelsUpdateOnDestroy=Ye,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
34
+ `;function Ue({locale:t,value:r}){return e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flex:"0 0 auto",px:1,py:.25,fontSize:12,bgcolor:"grey.300",borderRadius:2},children:[e.jsx(p.default,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:t}),e.jsx(p.default,{sx:{pl:.5},children:r})]})}function Ye({data:t,api:r,...s}){const[l,o]=u.useState(null),[n,a]=u.useState(null),[d,h]=u.useState(H(t)),m=u.useMemo(()=>z(d),[d]),x=u.useMemo(()=>{const c=(b,_)=>b.map(w=>(_&&(w.parent=_),w.children&&(w.children=c(w.children,w)),w));return c(d)},[d]),C=c=>{var b,_;c.parent?(c.parent.children=(_=(b=c.parent)==null?void 0:b.children)==null?void 0:_.map(w=>w.id===c.id?{...c}:w),C(c.parent)):h(d.map(w=>w.id===c.id?{...c}:w))},f=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),h([...d])):h([...d,c])},y=c=>{var b;c.parent?c.parent.children=(b=c.parent.children)==null?void 0:b.filter(_=>_.id!==c.id):h(d.filter(_=>_.id!==c.id))},v=c=>{if(l)return;o({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{l||o(c)},D=async c=>{if(!l)return;const{parent:b,children:_,translation:w,...T}=c;l.id?(await r.updateLabel({...T,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),C(c)):(await r.createLabel({...T,translation:JSON.stringify(w),parentId:b==null?void 0:b.id}),f(c)),o(null)},g=async()=>{!n||(await r.deleteLabel(n.id),y(n),a(null))},k=(c,b)=>e.jsxs(e.Fragment,{children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},children:[e.jsx(p.default,{children:c}),b.translation&&e.jsx(p.default,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},children:Object.keys(b.translation).map(_=>{var T;const w=(T=b.translation)==null?void 0:T[_];return w?e.jsx(Ue,{locale:_,value:w},_):null})})]}),e.jsxs(p.default,{sx:{display:"flex",gap:1,flex:"0 0 auto"},children:[e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>v(b),children:e.jsx(ve.default,{sx:{fontSize:20}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(b),children:e.jsx(Ce.default,{sx:{fontSize:18}})}),e.jsx(L.default,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>a(b),children:e.jsx(xe.default,{sx:{fontSize:20}})})]})]});return e.jsxs(p.default,{...s,children:[e.jsxs(p.default,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(ye.default,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(O.default,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>v(),children:"New label"})]}),e.jsxs(p.default,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(p.default,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},children:[m.length," labels"]}),e.jsx(p.default,{sx:{pt:.5},children:e.jsx(Qe,{data:x,selected:[],renderItem:k,rowHeight:64})})]}),e.jsx($e,{open:!!l,onClose:()=>o(null),initialLabel:l,onSubmit:D},l==null?void 0:l.id),e.jsx(Ke,{open:!!n,onClose:()=>a(null),label:n,onSubmit:g},n==null?void 0:n.id)]})}const K=u.createContext({}),M=()=>u.useContext(K),Ze=()=>{const{updateLabels:t}=M();u.useEffect(()=>()=>{t()},[])};function Ge({fetchLabels:t,children:r}){const{locale:s}=F.useLocaleContext(),[l,o]=u.useState({loading:!0,labels:[],updateCounter:1});u.useEffect(()=>{(async()=>{try{o(v=>({...v,loading:!0}));const y=await t();o(v=>({...v,loading:!1,labels:J(y)}))}catch(y){console.error(y),o(v=>({...v,loading:!1,labels:[]}))}})()},[l.updateCounter]);const n=u.useMemo(()=>{var y;return(y=l.labels)!=null&&y.length?z(l.labels).reduce((v,S)=>({...v,[S.id]:S}),{}):{}},[l.labels]),a=u.useCallback(f=>{var y;return{...f,name:((y=f.translation)==null?void 0:y[s])||f.name}},[s]),d=u.useCallback(f=>f.filter(Boolean).map(y=>n[y]).map(a),[n,a]),h=u.useCallback(f=>(f==null?void 0:f.split(","))||[],[]),m=u.useCallback((f=[])=>{if(!!(f!=null&&f.length))return f.join(",")},[]),x=u.useMemo(()=>l.labels.map(a),[l.labels,a]),C=u.useMemo(()=>({loading:l.loading,labels:l.labels||[],updateLabels:()=>o(f=>({...f,updateCounter:++l.updateCounter})),getLabelsById:d,parseLabelIds:h,stringifyLabelIds:m,localizedLabels:x}),[l,d,h,m,x]);return e.jsx(K.Provider,{value:C,children:r})}function Xe({labels:t,editable:r,onChange:s,sx:l}){const o=!(t!=null&&t.length),{labels:n,loading:a,getLabelsById:d}=M(),[h,m]=u.useState(!1);if(a||!r&&o)return null;const x=y=>{s==null||s(y),setTimeout(()=>{m(!1)},300)};if(h)return e.jsx(Ae.default,{onClickAway:()=>h&&m(!1),children:e.jsx("div",{children:e.jsx($,{data:n,value:t||[],onChange:x})})});const C=d(t||[]),f=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(l)?l:[l]];return e.jsxs(p.default,{sx:f,children:[C.map(y=>y?e.jsx(Oe.default,{label:y.name,variant:"filled",size:"small",sx:{borderRadius:1}},y.id):null),r&&!o&&e.jsx(L.default,{color:"inherit",size:"small",onClick:()=>m(!0),sx:{color:"grey.400"},children:e.jsx(_e.default,{sx:{fontSize:20}})}),r&&o&&e.jsx(O.default,{color:"inherit",variant:"outlined",startIcon:e.jsx(ke.default,{}),onClick:()=>m(!0),children:"Edit labels"})]})}i.LabelManager=Ye,i.LabelPicker=$,i.LabelTree=q,i.Labels=Xe,i.LabelsProvider=Ge,i.transformLabels=J,i.useLabelsContext=M,i.useLabelsUpdateOnDestroy=Ze,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.5.32",
3
+ "version": "1.5.34",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -11,7 +11,8 @@
11
11
  ".": {
12
12
  "import": "./dist/index.es.js",
13
13
  "require": "./dist/index.umd.js"
14
- }
14
+ },
15
+ "./src/*": "./src/*"
15
16
  },
16
17
  "scripts": {
17
18
  "dev": "npm run storybook",
@@ -74,5 +75,5 @@
74
75
  "resolutions": {
75
76
  "react": "^18.2.0"
76
77
  },
77
- "gitHead": "054e1277c3587a95dca1093345e18e3e5662b291"
78
+ "gitHead": "3ff1c28b65f182e70e1701c01e98306893b28046"
78
79
  }