@blocklet/labels 1.5.37 → 1.5.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +4 -1
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -326,7 +326,10 @@ function Oe({
|
|
|
326
326
|
...h,
|
|
327
327
|
[I.data.id]: I
|
|
328
328
|
}), {}), d = Array.isArray(t) ? t : [t], f = d.map((h) => x[h]), y = D({
|
|
329
|
-
prev: d.map((h) =>
|
|
329
|
+
prev: d.map((h) => {
|
|
330
|
+
var I;
|
|
331
|
+
return ((I = x[h]) == null ? void 0 : I.data) || "";
|
|
332
|
+
})
|
|
330
333
|
}), b = (h, I) => {
|
|
331
334
|
!i || !Array.isArray(h) ? o(h ? [h.data] : []) : y.current.current = h.map((c) => c.data), ["clear", "remove-value"].includes(I.action) && m.current && setTimeout(() => {
|
|
332
335
|
var c;
|
package/dist/index.umd.js
CHANGED
|
@@ -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,...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)`
|
|
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=>{var k;return((k=C[g])==null?void 0:k.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: '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/labels",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.39",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"resolutions": {
|
|
76
76
|
"react": "^18.2.0"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "f1e789911074a8bacbb327ebc017f4fcbe4b7f7f"
|
|
79
79
|
}
|