@blocklet/labels 1.5.132 → 1.5.133

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(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)`
1
+ (function(u,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@mui/icons-material"),require("@mui/material/Box"),require("@mui/material/styles"),require("react-arborist"),require("@iconify/react"),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/jsx-runtime","react","@mui/icons-material","@mui/material/Box","@mui/material/styles","react-arborist","@iconify/react","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"],e):(u=typeof globalThis<"u"?globalThis:u||self,e(u.DiscussKitComponents={},u.jsxRuntime,u.React,u.iconsMaterial,u.Box,u.styles,u.reactArborist,u.react$1,u.omit,u.Select,u.Typography,u.Button,u.IconButton,u.TextField,u.ClickAwayListener,u.reactColor,u.Dialog,u.material,u.Popover,u.context,u.Alert,u.Chip))})(this,function(u,e,h,z,f,j,U,Y,Z,E,G,q,O,M,W,X,V,T,B,H,R,ee){"use strict";const re=r=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...r,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"})}),te=r=>e.jsx("svg",{viewBox:"0 0 24 24",width:"1.2em",height:"1.2em",...r,children:e.jsx("path",{fill:"currentColor",d:"m10 16.4l-4-4L7.4 11l2.6 2.6L16.6 7L18 8.4Z"})}),J=h.createContext({});function ne({selectable:r=!1,selected:t=[],onSelect:a,renderItem:s,children:l}){const n=g=>t.indexOf(g)!==-1,o=g=>{Array.from(new Set(t).add(g)),a==null||a(g)},i=h.useMemo(()=>({selectable:r,selected:t,isSelected:n,select:o,renderItem:s}),[t]);return e.jsx(J.Provider,{value:i,children:l})}const se=r=>{var t;return r.isLeaf||!((t=r.data.children)!=null&&t.length)};function le({node:r}){return se(r)?e.jsx("span",{}):r.isOpen?e.jsx(z.ExpandMore,{style:{fontSize:20}}):e.jsx(z.ExpandMore,{style:{fontSize:20,transform:"rotate(-90deg)"}})}function oe({node:r,style:t,dragHandle:a}){const{selectable:s,select:l,isSelected:n,renderItem:o}=h.useContext(J),{data:i}=r,g=i.icon?e.jsx(Y.Icon,{icon:i.icon,style:{fontSize:18}}):e.jsx(re,{style:{fontSize:18,color:i.color||"#ddd"}}),x=d=>{d.stopPropagation(),r.isInternal&&r.toggle()},y=d=>{d.stopPropagation(),s&&l(r.id)},C=e.jsxs(e.Fragment,{children:[e.jsxs(f,{sx:{display:"flex",alignItems:"center",flex:1},children:[e.jsx(f,{sx:{display:"flex",cursor:"pointer"},onClick:x,children:e.jsx(le,{node:r})}),e.jsx(f,{sx:{display:"flex",alignItems:"center",width:22,height:22},children:g}),e.jsx(f,{component:"span",sx:{color:"grey.700"},children:r.data.name})]}),s&&n(r.id)&&e.jsx(te,{})]});return e.jsxs(f,{className:"label-tree-item",style:t,sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},ref:a,onClick:y,children:[!o&&C,!!o&&o(C,r.data)]})}const ae=j.styled(f)`
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(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)`
14
+ `;function P({data:r,selectable:t,selected:a=[],onSelect:s,rowHeight:l=28,renderItem:n,sx:o,...i}){const g=h.useRef(),x=[...Array.isArray(o)?o:[o]],[y,C]=h.useState(0),d=h.useCallback(()=>{var p,S;C((((S=(p=g.current)==null?void 0:p.visibleNodes)==null?void 0:S.length)||0)*l)},[l]);h.useEffect(()=>{d()},[r,d]);const b=()=>{setTimeout(d)};return e.jsx(ne,{selectable:t,selected:a,onSelect:s,renderItem:n,children:e.jsx(ae,{...i,sx:x,children:e.jsx(U.Tree,{data:r,rowHeight:l,height:y,indent:32,ref:g,onToggle:b,children:oe})})})}const A=r=>r.reduce((t,a)=>{var s;return t.push(a),(s=a.children)!=null&&s.length&&t.push(...A(a.children)),t},[]),_=r=>r.map(t=>{var a;return(a=t.children)!=null&&a.length&&(t.children=_(t.children)),t}),ie=(r,t=null)=>{try{return JSON.parse(r)}catch{return t}},K=r=>{const t=r.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),{}),a=r.map(({parentId:l,translation:n,...o})=>({...o,translation:ie(n),children:[]})),s=a.reduce((l,n)=>({...l,[n.id]:n}),{});return a.forEach(l=>{const n=t[l.id];n.parent&&s[n.parent]&&(l.parent=s[n.parent]),n.children&&(l.children=n.children.map(o=>s[o]))}),a.filter(l=>!l.parent)},ce=r=>{const{options:t,getValue:a,selectProps:s,selectOption:l}=r,n=a(),o=i=>{const g=t.find(x=>x.data.id===i);g&&l(g)};return e.jsxs(e.Fragment,{children:[e.jsx(E.components.MenuList,{...Z(r,["addon"]),children:e.jsx(f,{sx:{px:2,py:1},children:e.jsx(P,{data:s.data,selectable:!0,onSelect:o,selected:n.map(i=>i.data.id)})})}),r.addon]})},de=({children:r,...t})=>{const[a,s]=r,l=Array.isArray(a)?a.length:0;return e.jsxs(E.components.ValueContainer,{...t,children:[e.jsx(f,{component:"span",sx:{fontSize:13,fontWeight:"bold"},children:l?"Labels":"Filter by labels"}),!!l&&e.jsx(f,{sx:{display:"inline-flex",justifyContent:"center",alignItems:"center",width:22,height:22,ml:1,borderRadius:"100%",fontSize:12,bgcolor:"grey.200"},children:l}),s]})},ue={control:r=>({...r,minHeight:31}),valueContainer:r=>({...r,display:"flex"}),dropdownIndicator:r=>({...r,padding:"0 4px"}),clearIndicator:r=>({...r,padding:"4px"})};function $({data:r,value:t=[],editable:a=!1,addon:s,onChange:l,compact:n,isMulti:o=!0,maxHeight:i=264,...g}){const x=h.useRef(null),y=h.useMemo(()=>A(r).map(m=>({data:m,label:m.name,value:m.id})),[r]),C=y.reduce((m,I)=>({...m,[I.data.id]:I}),{}),d=Array.isArray(t)?t:[t],b=d.map(m=>C[m]),p=h.useRef({prev:d.map(m=>{var I;return((I=C[m])==null?void 0:I.data)||""})}),S=(m,I)=>{!o||!Array.isArray(m)?l(m?[m.data]:[]):p.current.current=m.map(c=>c.data),["clear","remove-value"].includes(I.action)&&x.current&&setTimeout(()=>{var c;return(c=x==null?void 0:x.current)==null?void 0:c.blur()},1)},F=()=>{p.current.current&&JSON.stringify(p.current.prev.map(I=>I.id))!==JSON.stringify(p.current.current.map(I=>I.id))&&(l(p.current.current),p.current.prev=p.current.current)};return e.jsx(f,{...g,children:e.jsx(E,{ref:x,defaultValue:b,options:y,onChange:S,components:{MenuList:m=>e.jsx(ce,{...m,addon:s}),...n&&{ValueContainer:de}},placeholder:"Select labels",styles:{...n&&ue,menu:m=>({...m,...a&&{paddingBottom:"36px"},zIndex:99}),menuList:m=>({...m,overflowY:"auto",maxHeight:`${i}px`})},theme:m=>({...m,colors:{...m.colors,primary25:"#ddd",primary50:"#ddd",primary:"#ddd"}}),isSearchable:!1,isMulti:o,closeMenuOnSelect:!o,onMenuClose:F,isClearable:!0,data:r})})}var N=function(){return N=Object.assign||function(t){for(var a,s=1,l=arguments.length;s<l;s++){a=arguments[s];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t},N.apply(this,arguments)};function he(r,t){var a=typeof Symbol=="function"&&r[Symbol.iterator];if(!a)return r;var s=a.call(r),l,n=[],o;try{for(;(t===void 0||t-- >0)&&!(l=s.next()).done;)n.push(l.value)}catch(i){o={error:i}}finally{try{l&&!l.done&&(a=s.return)&&a.call(s)}finally{if(o)throw o.error}}return n}typeof SuppressedError=="function"&&SuppressedError;var pe=function(r){return typeof r=="function"},fe=function(r){var t=he(h.useState(r),2),a=t[0],s=t[1],l=h.useCallback(function(n){s(function(o){var i=pe(n)?n(o):n;return i?N(N({},o),i):o})},[]);return[a,l]};const ge=fe;function ye({I18NProps:r,...t}){const{languages:a}=H.useLocaleContext(),{translation:s,onChange:l}=r,[n,o]=h.useState(null),i=y=>{const C=y.currentTarget.closest(".MuiInputBase-root");C&&o(C)},g=()=>{o(null)},x=a.filter(y=>y.code!=="en");return e.jsx(T.TextField,{...t,InputProps:{endAdornment:e.jsxs(T.InputAdornment,{position:"end",children:[e.jsx(T.IconButton,{edge:"end",onClick:i,children:e.jsx(z.Translate,{})}),e.jsx(B,{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(T.Box,{sx:{p:2},children:x.map(({code:y,name:C})=>e.jsxs(T.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between","& + &":{mt:1}},children:[e.jsx(T.Box,{sx:{flex:"0 0 120px"},children:C}),e.jsx(T.Box,{sx:{flex:1},children:e.jsx(T.TextField,{value:s[y]||"",size:"small",sx:{width:1},onChange:d=>l({...s,[y]:d.target.value})})})]},y))})})]})}})}function me({open:r,initialLabel:t,onSubmit:a,onClose:s,...l}){const n=!(t!=null&&t.id),[o,i]=ge({name:(t==null?void 0:t.name)||"",color:(t==null?void 0:t.color)||"#ddd",slug:(t==null?void 0:t.id)||"",translation:(t==null?void 0:t.translation)||{}}),g=S=>/^#([0-9A-F]{3}){1,2}$/i.test(S),x=h.useMemo(()=>n?o.name&&o.color&&o.slug&&g(o.color):o.name&&o.color&&g(o.color),[o,n]),[y,C]=h.useState(!1),d=()=>{a({...t,name:o.name,color:o.color,id:o.slug,translation:o.translation})},b=S=>{i({color:S.hex}),setTimeout(()=>C(!1))},p=S=>{i({color:S.target.value})};return e.jsx(V,{open:r,showCloseButton:!0,maxWidth:"lg",title:n?"Create label":"Edit label",actions:e.jsxs(e.Fragment,{children:[e.jsx(q,{color:"inherit",variant:"contained",size:"small",onClick:s,children:"Cancel"}),e.jsx(q,{color:"primary",variant:"contained",size:"small",onClick:d,disabled:!x,children:n?"Create":"Save Changes"})]}),onClose:s,...l,children:e.jsxs(f,{width:600,minHeight:280,children:[e.jsx(ye,{label:"Name",value:o.name,placeholder:"New label",size:"small",fullWidth:!0,onChange:S=>i({name:S.target.value}),I18NProps:{translation:o.translation,onChange:S=>i({translation:S})}}),e.jsx(M,{label:"Slug",value:o.slug,size:"small",fullWidth:!0,disabled:!n,onChange:S=>i({slug:S.target.value}),sx:{mt:2}}),(t==null?void 0:t.parent)&&e.jsx(M,{label:"Parent",value:t.parent.name,size:"small",fullWidth:!0,disabled:!0,sx:{mt:2}}),e.jsx(W,{onClickAway:()=>C(!1),children:e.jsxs(f,{sx:{position:"relative",mt:2},children:[e.jsxs(f,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(f,{sx:{width:30,height:30,bgcolor:o.color,borderRadius:1},onClick:()=>C(!0)}),e.jsx(M,{label:"",value:o.color,size:"small",onChange:p,inputProps:{maxLength:7},sx:{width:100,".MuiInputBase-root":{height:32}}})]}),y&&e.jsx(f,{sx:{position:"absolute",top:48,zIndex:1},children:e.jsx(X.GithubPicker,{color:o.color,onChangeComplete:b})})]})})]})})}function xe({open:r,label:t,onSubmit:a,onClose:s,...l}){return e.jsx(V,{open:r,showCloseButton:!0,maxWidth:"md",title:"Delete",actions:e.jsxs(e.Fragment,{children:[e.jsx(q,{color:"inherit",variant:"contained",size:"small",onClick:s,children:"Cancel"}),e.jsx(q,{color:"primary",variant:"contained",size:"small",onClick:a,children:"Delete"})]}),onClose:s,...l,children:e.jsxs(f,{width:600,minHeight:280,children:[e.jsx(R,{severity:"info",sx:{mb:2},children:"Are you sure you want to delete these labels ?"}),e.jsx(P,{data:[t]})]})})}const Ce=j.styled(P)`
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)},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"}})});
34
+ `;function ve({locale:r,value:t}){return e.jsxs(f,{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(f,{sx:{pr:.5,borderRight:1,borderColor:"grey.400"},children:r}),e.jsx(f,{sx:{pl:.5},children:t})]})}function be({data:r,api:t,...a}){const[s,l]=h.useState(null),[n,o]=h.useState(null),[i,g]=h.useState(_(r)),x=h.useMemo(()=>A(i),[i]),y=h.useMemo(()=>{const c=(v,k)=>v.map(w=>(k&&(w.parent=k),w.children&&(w.children=c(w.children,w)),w));return c(i)},[i]),C=c=>{var v,k;c.parent?(c.parent.children=(k=(v=c.parent)==null?void 0:v.children)==null?void 0:k.map(w=>w.id===c.id?{...c}:w),C(c.parent)):g(i.map(w=>w.id===c.id?{...c}:w))},d=c=>{c.parent?(c.parent.children=c.parent.children||[],c.parent.children.push(c),g([...i])):g([...i,c])},b=c=>{var v;c.parent?c.parent.children=(v=c.parent.children)==null?void 0:v.filter(k=>k.id!==c.id):g(i.filter(k=>k.id!==c.id))},p=c=>{if(s)return;l({id:"",name:"New label",parent:c,color:"#dddddd"})},S=c=>{s||l(c)},F=async c=>{if(!s)return;const{parent:v,children:k,translation:w,...L}=c;s.id?(await t.updateLabel({...L,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),C(c)):(await t.createLabel({...L,translation:JSON.stringify(w),parentId:v==null?void 0:v.id}),d(c)),l(null)},m=async()=>{n&&(await t.deleteLabel(n.id),b(n),o(null))},I=(c,v)=>e.jsxs(e.Fragment,{children:[e.jsxs(f,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap"},className:"label-name",children:[e.jsx(f,{children:c}),v.translation&&e.jsx(f,{sx:{display:"flex",alignItems:"center",gap:.5,ml:2},className:"label-translation",children:Object.keys(v.translation).map(k=>{var L;const w=(L=v.translation)==null?void 0:L[k];return w?e.jsx(ve,{locale:k,value:w},k):null})})]}),e.jsxs(f,{sx:{display:"flex",gap:1,flex:"0 0 auto"},className:"label-action",children:[e.jsx(O,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>p(v),children:e.jsx(z.Add,{sx:{fontSize:20}})}),e.jsx(O,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>S(v),children:e.jsx(z.EditOutlined,{sx:{fontSize:18}})}),e.jsx(O,{color:"inherit",size:"small",sx:{color:"grey.500"},onClick:()=>o(v),children:e.jsx(z.DeleteOutlineOutlined,{sx:{fontSize:20}})})]})]});return e.jsxs(f,{...a,className:"label-container",children:[e.jsxs(f,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(G,{component:"h2",variant:"h6",children:"Manage labels"}),e.jsx(q,{color:"primary",variant:"contained",size:"small",sx:{textTransform:"none"},onClick:()=>p(),children:"New label"})]}),e.jsxs(f,{sx:{mt:2,border:1,borderColor:"grey.300",borderRadius:1,overflow:"hidden"},children:[e.jsxs(f,{sx:{p:2,fontSize:14,fontWeight:"bold",bgcolor:"grey.200"},className:"label-header",children:[x.length," labels"]}),e.jsx(f,{sx:{pt:.5},children:e.jsx(Ce,{data:y,selected:[],renderItem:I,rowHeight:64})})]}),e.jsx(me,{open:!!s,onClose:()=>l(null),initialLabel:s,onSubmit:F},s==null?void 0:s.id),e.jsx(xe,{open:!!n,onClose:()=>o(null),label:n,onSubmit:m},n==null?void 0:n.id)]})}const Q=h.createContext({}),D=()=>h.useContext(Q),Se=()=>{const{updateLabels:r}=D();h.useEffect(()=>()=>{r()},[])};function we({fetchLabels:r,children:t}){const{locale:a}=H.useLocaleContext(),[s,l]=h.useState({loading:!0,labels:[],updateCounter:1});h.useEffect(()=>{(async()=>{try{l(p=>({...p,loading:!0}));const b=await r();l(p=>({...p,loading:!1,labels:K(b)}))}catch(b){console.error(b),l(p=>({...p,loading:!1,labels:[]}))}})()},[s.updateCounter]);const n=h.useMemo(()=>{var b;return(b=s.labels)!=null&&b.length?A(s.labels).reduce((p,S)=>({...p,[S.id]:S}),{}):{}},[s.labels]),o=h.useCallback(d=>{var b;return{...d,name:((b=d.translation)==null?void 0:b[a])||d.name}},[a]),i=h.useCallback(d=>d.filter(Boolean).map(b=>n[b]).map(o),[n,o]),g=h.useCallback(d=>(d==null?void 0:d.split(","))||[],[]),x=h.useCallback((d=[])=>{if(d!=null&&d.length)return d.join(",")},[]),y=h.useMemo(()=>s.labels.map(o),[s.labels,o]),C=h.useMemo(()=>({loading:s.loading,labels:s.labels||[],updateLabels:()=>l(d=>({...d,updateCounter:++s.updateCounter})),getLabelsById:i,parseLabelIds:g,stringifyLabelIds:x,localizedLabels:y,flattenedLabels:A(y||[])}),[s,i,g,x,y]);return e.jsx(Q.Provider,{value:C,children:t})}function ke({labels:r,editable:t,onChange:a,sx:s,renderLabel:l}){const n=!(r!=null&&r.length),{labels:o,loading:i,getLabelsById:g}=D(),[x,y]=h.useState(!1);if(i||!t&&n)return null;const C=p=>{a==null||a(p),setTimeout(()=>{y(!1)},300)};if(x)return e.jsx(W,{onClickAway:()=>x&&y(!1),children:e.jsx("div",{children:e.jsx($,{data:o,value:r||[],onChange:C})})});const d=g(r||[]),b=[{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},...Array.isArray(s)?s:[s]];return e.jsxs(f,{sx:b,children:[d.map(p=>p?l?l(p):e.jsx(ee,{label:p.name,variant:"filled",size:"small",sx:{borderRadius:1}},p.id):null),t&&!n&&e.jsx(O,{color:"inherit",size:"small",onClick:()=>y(!0),sx:{color:"grey.400"},children:e.jsx(z.Edit,{sx:{fontSize:20}})}),t&&n&&e.jsx(q,{color:"inherit",variant:"outlined",startIcon:e.jsx(z.LabelOutlined,{}),onClick:()=>y(!0),children:"Edit labels"})]})}u.LabelManager=be,u.LabelPicker=$,u.LabelTree=P,u.Labels=ke,u.LabelsProvider=we,u.transformLabels=K,u.useLabelsContext=D,u.useLabelsUpdateOnDestroy=Se,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,2 @@
1
+ import type { Label } from '../../components/label/types';
2
+ export declare const labels: Label[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/labels",
3
- "version": "1.5.132",
3
+ "version": "1.5.133",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -62,18 +62,18 @@
62
62
  "@types/react": "^18.0.24",
63
63
  "@types/react-color": "^3.0.6",
64
64
  "@types/react-dom": "^18.0.8",
65
- "@vitejs/plugin-react": "^2.2.0",
65
+ "@vitejs/plugin-react": "^4.1.0",
66
66
  "babel-loader": "^8.3.0",
67
67
  "react": "^18.2.0",
68
68
  "react-dom": "^18.2.0",
69
69
  "typescript": "^4.6.4",
70
70
  "unplugin-icons": "^0.14.14",
71
- "vite": "^3.2.5",
72
- "vite-plugin-dts": "^1.7.1",
73
- "vite-plugin-libcss": "^1.0.5"
71
+ "vite": "^4.4.11",
72
+ "vite-plugin-dts": "^3.6.0",
73
+ "vite-plugin-libcss": "^1.1.1"
74
74
  },
75
75
  "resolutions": {
76
76
  "react": "^18.2.0"
77
77
  },
78
- "gitHead": "2823d96c38469127d2b6ddd15c14fc0388a6a257"
78
+ "gitHead": "5d49833f64fb9bc067365d36ef31a4609bfcff17"
79
79
  }
package/dist/global.d.ts DELETED
@@ -1,9 +0,0 @@
1
- declare module '@arcblock/ux/*';
2
- declare module '@arcblock/did-connect/*';
3
- interface Window {
4
- blocklet: {
5
- appId: string;
6
- prefix: string;
7
- preferences: { [key: string]: any };
8
- };
9
- }
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />