1 |
- import{p as K,bA as Q,bB as U,s as z,aF as V,f as h,b2 as D,a3 as X,bC as I,L as A,bD as M,y as C,bE as q,ad as O,O as H,ae as J,z as k,P as B,Q as u,aX as Y,bk as Z}from"./index-DT8qTvyx.js";var w=Math.max,ee=Math.min;function te(b,n,e){return b>=ee(n,e)&&b<w(n,e)}var ae=te,ne=ae,j=Q,le=U;function se(b,n,e){return n=j(n),e===void 0?(e=n,n=0):e=j(e),b=le(b),ne(b,n,e)}var ie=se;const oe=K(ie);var re=function(b){z(n,b);function n(){return b!==null&&b.apply(this,arguments)||this}return n.prototype.doAction=function(e,t,i){var l,o,s=this.props,r=s.resetValue,p=s.onChange,m=s.formStore,f=s.store,a=s.name,c=e==null?void 0:e.actionType;if(c==="clear")p("");else if(c==="reset"){var d=(o=V((l=m==null?void 0:m.pristine)!==null&&l!==void 0?l:f==null?void 0:f.pristine,a))!==null&&o!==void 0?o:r;p(d??"")}},n.prototype.reload=function(){var e=this.props.reloadOptions;e&&e()},n.prototype.handleAddClick=function(){var e=this.props.onAdd;e&&e()},n.prototype.handleEditClick=function(e,t){var i=this.props.onEdit;e.preventDefault(),e.stopPropagation(),i&&i(t)},n.prototype.handleDeleteClick=function(e,t){var i=this.props.onDelete;e.preventDefault(),e.stopPropagation(),i&&i(t)},n.prototype.componentDidMount=function(){this.updateBorderStyle(),window.addEventListener("resize",this.updateBorderStyle)},n.prototype.componentWillUnmount=function(){window.removeEventListener("resize",this.updateBorderStyle)},n.prototype.updateBorderStyle=function(){if(this.props.optionType==="button"){var e=this.refs.checkboxRef,t=e.clientWidth,i=Array.from(e.children);i.forEach(function(a){a.style.borderRadius="0",a.style.borderLeftWidth="1px",a.style.borderTopWidth="1px"});var l=i.reduce(function(a,c){return a+c.clientWidth},0);if(l<=t)i.length===1?i[0].style.borderRadius="4px":(i[0].style.borderRadius="4px 0 0 4px",i[i.length-1].style.borderRadius="0 4px 4px 0",i.forEach(function(a,c){c!==0&&(a.style.borderLeftWidth="0")}));else{for(var o=0,s=0,r=Math.floor(l/t),p=[],m=0;m<=r;m++){var f=[];p[m]=f}i.forEach(function(a,c){o+=a.clientWidth,o>t&&(o=a.clientWidth,s++),!(s>r)&&p[s].push(a)}),p.forEach(function(a,c){c===0?(a.forEach(function(d,v){d.style.borderRadius="0",v!==0&&(d.style.borderLeftWidth="0"),a.length>p[c+1].length&&(a[a.length-1].style.borderBottomRightRadius="4px")}),a[0].style.borderTopLeftRadius="4px",a[a.length-1].style.borderTopRightRadius="4px"):c===r?a.forEach(function(d,v){d.style.borderRadius="0",v!==0&&(d.style.borderLeftWidth="0"),d.style.borderTopWidth="0",a[0].style.borderBottomLeftRadius="4px",a[a.length-1].style.borderBottomRightRadius="4px"}):a.forEach(function(d,v){d.style.borderRadius="0",v!==0&&(d.style.borderLeftWidth="0"),d.style.borderTopWidth="0",a.length>p[c+1].length&&(a[a.length-1].style.borderBottomRightRadius="4px")})})}}},n.prototype.renderGroup=function(e,t){var i=this,l,o=this.props,s=o.classnames,r=o.labelField;if(!(!((l=e.children)===null||l===void 0)&&l.length))return null;var p=e.children.map(function(f,a){return i.renderItem(f,a)}),m=this.columnsSplit(p);return h.createElement("div",{key:"group-"+t,className:s("CheckboxesControl-group",e.className)},h.createElement("label",{className:s("CheckboxesControl-groupLabel",e.labelClassName)},e[r||"label"]),m)},n.prototype.renderItem=function(e,t){var i=this;if(e.children)return this.renderGroup(e,t);var l=this.props,o=l.render,s=l.itemClassName,r=l.onToggle,p=l.selectedOptions,m=l.disabled,f=l.inline,a=l.labelClassName,c=l.labelField,d=l.removable,v=l.editable,S=l.translate,F=l.optionType,R=l.menuTpl,x=l.data,N=l.testIdBuilder,E=String(e[c||"label"]),_=e.labelClassName,L=N==null?void 0:N.getChild("item-"+E||t);return h.createElement(D,{className:s,key:t,onChange:function(){return r(e)},checked:!!~p.indexOf(e),disabled:m||e.disabled,inline:f,labelClassName:_||a,description:e.description,optionType:F,testIdBuilder:L},R?o("checkboxes/".concat(t),R,{data:X(x,e)}):E,d&&I(e,"removable")?h.createElement("a",{"data-tooltip":S("Select.clear"),"data-position":"left"},h.createElement(A,{icon:"minus",className:"icon",onClick:function(g){return i.handleDeleteClick(g,e)}})):null,v&&I(e,"editable")?h.createElement("a",{"data-tooltip":"编辑","data-position":"left"},h.createElement(A,{icon:"pencil",className:"icon",onClick:function(g){return i.handleEditClick(g,e)}})):null)},n.prototype.columnsSplit=function(e){var t=this.props,i=t.columnsCount,l=t.classnames,o=[],s=[];return e.forEach(function(r){r&&r.key&&String(r.key).startsWith("group")?(s.length&&(o.push(M(s,l,i)),s=[]),o.push(r)):s.push(r)}),s.length&&o.push(M(s,l,i)),o},n.prototype.formateThemeCss=function(e){if(!e)return{};var t=e.checkboxesClassName,i=t===void 0?{}:t,l={},o={};return Object.keys(i).forEach(function(s){if(s.includes("checked-")){var r=s.replace("checked-","");o[r]=i[s]}else if(s.includes("checkbox-")){var r=s.replace("checkbox-","");l[r]=i[s]}}),C(C({},e),{checkboxesClassName:l,checkboxesCheckedClassName:o})},n.prototype.render=function(){var e=this,t=this.props,i=t.className;t.style;var l=t.disabled,o=t.placeholder,s=t.options,r=t.inline;t.columnsCount;var p=t.selectedOptions;t.onToggle;var m=t.onToggleAll,f=t.checkAll,a=t.checkAllText,c=t.classnames,d=t.itemClassName,v=t.labelClassName,S=t.creatable,F=t.addApi,R=t.createBtnLabel,x=t.translate,N=t.optionType,E=t.loading,_=t.loadingConfig,L=t.themeCss,g=t.id,P=t.env,T=t.classPrefix,y=[];s&&s.length&&(y=s.map(function($,G){return e.renderItem($,G)})),f&&y.length&&N==="default"&&y.unshift(h.createElement(D,{key:"checkall",className:d,onChange:m,checked:!!p.length,partial:oe(p.length,0,q(s).length),disabled:l,inline:r,labelClassName:v},a??x("Checkboxes.selectAll"))),y=this.columnsSplit(y);var W=this.formateThemeCss(L);return h.createElement("div",{className:c("CheckboxesControl",i,O(C(C({},this.props),{name:"checkboxesClassName",id:g,themeCss:W})),O(C(C({},this.props),{name:"checkboxesCheckedClassName",id:g,themeCss:W})),O(C(C({},this.props),{name:"checkboxesLabelClassName",id:g,themeCss:W}))),ref:"checkboxRef"},y&&y.length?y:E?null:h.createElement("span",{className:"Form-placeholder"},x(o)),E?h.createElement(H,{show:!0,icon:"reload",size:"sm",spinnerClassName:c("Checkboxes-spinner"),loadingConfig:_}):null,(S||F)&&!l?h.createElement("a",{className:c("Checkboxes-addBtn"),onClick:this.handleAddClick},h.createElement(A,{icon:"plus",className:"icon"}),x(R)):null,h.createElement(J,C({},this.props,{config:{themeCss:this.formateThemeCss(L),classNames:[{key:"checkboxesClassName",weights:{default:{suf:" label",inner:"i"},hover:{suf:" label",inner:"i"},disabled:{inner:".".concat(T,"Checkbox--checkbox input[disabled] + i")}}},{key:"checkboxesCheckedClassName",weights:{default:{inner:".".concat(T,"Checkbox--checkbox input:checked + i")},hover:{suf:" .".concat(T,"Checkbox--checkbox"),inner:"input:checked + i"},disabled:{inner:".".concat(T,"Checkbox--checkbox input:checked[disabled] + i")}}},{key:"checkboxesLabelClassName",weights:{default:{suf:" label",inner:"span"},hover:{suf:" label",inner:"span"},disabled:{inner:".".concat(T,"Checkbox--checkbox input[disabled] + i + span")}}}],id:g},env:P})))},n.defaultProps={columnsCount:1,multiple:!0,placeholder:"placeholder.noOption",creatable:!1,inline:!0,createBtnLabel:"Select.createLabel",optionType:"default"},k([B,u("design:type",Function),u("design:paramtypes",[]),u("design:returntype",void 0)],n.prototype,"handleAddClick",null),k([B,u("design:type",Function),u("design:paramtypes",[Event,Object]),u("design:returntype",void 0)],n.prototype,"handleEditClick",null),k([B,u("design:type",Function),u("design:paramtypes",[Event,Object]),u("design:returntype",void 0)],n.prototype,"handleDeleteClick",null),k([B,u("design:type",Function),u("design:paramtypes",[]),u("design:returntype",void 0)],n.prototype,"updateBorderStyle",null),k([Y(),u("design:type",Function),u("design:paramtypes",[]),u("design:returntype",void 0)],n.prototype,"render",null),n}(h.Component),de=function(b){z(n,b);function n(){return b!==null&&b.apply(this,arguments)||this}return n=k([Z({type:"checkboxes",sizeMutable:!1,thin:!0})],n),n}(re);export{de as CheckboxesControlRenderer,re as default};
|