InputTree-BWzftqyq.js 12 KB

1
  1. import{s as J,f as m,bf as je,c5 as Be,al as Pe,aG as Ue,c0 as W,bX as Me,y as F,bh as Z,E as D,G as j,a3 as L,c6 as ze,ag as B,aD as Ge,v as Xe,w as $e,c7 as Qe,bM as x,ad as We,O as Ze,ae as qe,z as g,P as O,Q as s,aZ as Je,bm as Ke,bE as q,c8 as Ye,ah as et,X as tt}from"./index-BPRWoLf4.js";var it=function(S){J(n,S);function n(e){var t=this,i;return t=S.call(this,e)||this,t.rootRef=m.createRef(),t.state={keyword:"",filteredOptions:(i=t.props.options)!==null&&i!==void 0?i:[],allowSearch:!1,virtualListHeight:0,othersHeight:0},t.handleSearch=je(t.handleSearch.bind(t),250,{trailing:!0,leading:!1}),t}return n.prototype.componentDidMount=function(){var e=this,t;this.props.heightAuto&&(this.initOthersHeight(),this.handleVirtualListHeight(),this.unSensor=Be((t=this.rootRef.current)===null||t===void 0?void 0:t.parentElement,function(){e.handleVirtualListHeight()},!1,"height"))},n.prototype.componentDidUpdate=function(e,t){var i=this.props,r=this.state,a=this.state.keyword;if(e.options!==i.options||e.searchable!==i.searchable){var l=i.options,o=i.searchable;this.setState({filteredOptions:o&&a?this.filterOptions(l,a):l})}Pe(["label","searchable","creatable","hideRoot","themeCss","wrapperCustomStyle","heightAuto"],e,i)&&i.heightAuto&&this.initOthersHeight(),t.othersHeight!==r.othersHeight&&i.heightAuto&&this.handleVirtualListHeight()},n.prototype.componentWillUnmount=function(){this.unSensor&&(this.unSensor(),delete this.unSensor)},n.prototype.initOthersHeight=function(){var e=this,t,i,r=this.rootRef.current,a=(t=this.rootRef.current)===null||t===void 0?void 0:t.parentElement,l=this.treeRef.virtualListRef.current,o=(i=this.treeRef.virtualListRef.current)===null||i===void 0?void 0:i.parentElement;if(!(!a||!o||!l||!r)){var u=function(p,c){return Array.from(p.children).filter(function(h){return h!==c}).reduce(function(h,v){return h+v.offsetHeight+e.getElementVerticalMargin(v)},0)},d=u(a,r)+this.getElementVerticalMargin(r)+u(o,l)+r.offsetHeight-o.offsetHeight;this.setState({othersHeight:d})}},n.prototype.handleVirtualListHeight=function(){var e,t=this.state.othersHeight,i=(e=this.rootRef.current)===null||e===void 0?void 0:e.parentElement;if(i){var r=i.offsetHeight-t;this.setState({virtualListHeight:r>0?r:0})}},n.prototype.getElementVerticalMargin=function(e){var t=window.getComputedStyle(e,null);return parseInt(t.marginTop||"0")+parseInt(t.marginBottom||"0")},n.prototype.reload=function(){var e=this.props.reloadOptions;e&&e()},n.prototype.doAction=function(e,t,i){var r,a,l,o,u,d,p,c,h,v,y,A=e==null?void 0:e.actionType,b=this.props,E=b.resetValue,f=b.onChange,C=b.formStore,_=b.store,T=b.name;if(A==="clear")f==null||f("");else if(A==="reset"){var I=(a=Ue((r=C==null?void 0:C.pristine)!==null&&r!==void 0?r:_==null?void 0:_.pristine,T))!==null&&a!==void 0?a:E;f==null||f(I??"")}else e.actionType==="expand"?this.treeRef.syncUnFolded(this.props,(l=e.args)===null||l===void 0?void 0:l.openLevel):e.actionType==="collapse"?this.treeRef.syncUnFolded(this.props,((o=e.args)===null||o===void 0?void 0:o.closeLevel)||0):e.actionType==="add"?this.addItemFromAction((u=e.args)===null||u===void 0?void 0:u.item,(d=e.args)===null||d===void 0?void 0:d.parentValue):e.actionType==="edit"?this.editItemFromAction((p=e.args)===null||p===void 0?void 0:p.item,(c=e.args)===null||c===void 0?void 0:c.originValue):e.actionType==="delete"?this.deleteItemFromAction((h=e.args)===null||h===void 0?void 0:h.value):e.actionType==="reload"?this.reload():A==="search"&&(this.setState({allowSearch:!!(!((v=e.args)===null||v===void 0)&&v.keyword)}),this.handleSearch((y=e.args)===null||y===void 0?void 0:y.keyword))},n.prototype.resolveOption=function(e,t){var i=this;return W(e,function(r){var a=i.props.valueField||"value",l=q(r,a)?r[a]:"";return l===t})},n.prototype.addItemFromAction=function(e,t){var i=this.props,r=i.onAdd,a=i.options,l=i.valueField,o=Me(a,function(u){var d=l||"value",p=q(u,d)?u[d]:"";return p===t})||[];r&&r(o.concat(0),e,!0)},n.prototype.editItemFromAction=function(e,t){var i=this.props,r=i.onEdit,a=i.options,l=this.resolveOption(a,t);r&&l&&r(F(F({},e),{originValue:t}),l,!0)},n.prototype.deleteItemFromAction=function(e){var t=this.props,i=t.onDelete,r=t.options,a=this.resolveOption(r,e);i&&a&&i(a)},n.prototype.filterOptions=function(e,t){var i=this,r=this.props,a=r.labelField,l=r.valueField;return e.map(function(o){if(o=F({},o),o.visible=!!Z([o],t,{keys:[a||"label",l||"value"],threshold:Z.rankings.CONTAINS}).length,!o.visible&&o.children){o.children=i.filterOptions(o.children,t);var u=o.children.filter(function(d){return d.visible}).length;o.visible=!!u}return o.visible&&(o.collapsed=!1),o})},n.prototype.handleChange=function(e){return D(this,void 0,void 0,function(){var t,i,r,a,l,o,u,d,p,c,h,v,y,A,b,E,f,C;return j(this,function(_){switch(_.label){case 0:return t=this.props,i=t.onChange,r=t.searchable,a=t.options,l=t.dispatchEvent,o=t.multiple,u=t.delimiter,d=t.valueField,p=t.selectedOptions,c=t.joinValues,h=t.extractValue,v=this.state,y=v.filteredOptions,A=v.allowSearch,b=r||A?y:a,E=Ye(e,{multiple:o,delimiter:u,valueField:d,options:y}),f=o?null:E[0],o&&(r||A)&&p.length&&(p.forEach(function(T){var I=W(y,function(N){return N[d||"value"]===T[d||"value"]});I||E.push(T)}),e=E.map(function(T){return h||c?T[d||"value"]:T}),c&&(e=e.join(u||","))),[4,l("change",et(this.props,{value:e,item:f,items:b,selectedItems:E}))];case 1:return C=_.sent(),C!=null&&C.prevented?[2]:(i&&i(e),[2])}})})},n.prototype.handleNodeClick=function(e){return D(this,void 0,void 0,function(){var t,i,r,a;return j(this,function(l){switch(l.label){case 0:return t=this.props,i=t.dispatchEvent,r=t.data,[4,i("itemClick",L(r,{item:e}))];case 1:return a=l.sent(),a!=null&&a.prevented?[2]:[2]}})})},n.prototype.handleSearch=function(e){return D(this,void 0,void 0,function(){var t,i,r,a,l,o,u,d,p,c;return j(this,function(h){switch(h.label){case 0:if(t=this.props,i=t.searchApi,r=t.options,a=t.env,l=t.data,o=t.translate,u=[],!tt(i))return[3,5];h.label=1;case 1:return h.trys.push([1,3,,4]),[4,a.fetcher(i,L(l,{term:e}))];case 2:if(d=h.sent(),!d.ok)throw new Error(o(d.msg||"networkError"));if(p=d.data.options||d.data.items||d.data,!Array.isArray(p))throw new Error(o("Tree.invalidArray"));return u=p,[3,4];case 3:return c=h.sent(),a.isCancel(c)||!i.silent&&a.notify("error",c.message),[3,4];case 4:return[3,6];case 5:e&&(u=this.filterOptions(r,e)),h.label=6;case 6:return this.setState({keyword:e,filteredOptions:e?u:r}),[2]}})})},n.prototype.domRef=function(e){this.treeRef=e},n.prototype.validate=function(){var e=this.props,t=e.value,i=e.minLength,r=e.maxLength,a=e.delimiter,l=Array.isArray(t)?t:(t?String(t):"").split(a||",");if(i&&l.length<i)return"已选择数量低于设定的最小个数".concat(i,",请选择更多的选项。");if(r&&l.length>r)return"已选择数量超出设定的最大个数".concat(r,",请取消选择超出的选项。")},n.prototype.renderOptionItem=function(e,t){var i=this.props,r=i.menuTpl,a=i.render,l=i.data;return a("option/".concat(t.index),r,{data:L(L(l,F({},t)),e)})},n.prototype.renderItemActions=function(e,t){var i=this.props,r=i.itemActions,a=i.data,l=i.render;return l("action/".concat(t.index),r||"",{data:L(L(a,F({},t)),e)})},n.prototype.renderSearch=function(){var e=this.props,t=e.classPrefix,i=e.searchConfig,r=e.mobileUI,a=e.testIdBuilder;return m.createElement(ze,F({className:B("".concat(t,"TreeControl-searchbox"),i==null?void 0:i.className,{"is-sticky":i==null?void 0:i.sticky}),mini:!1,clearable:!0},Ge(i,"className","sticky"),{onSearch:this.handleSearch,mobileUI:r,testIdBuilder:a==null?void 0:a.getChild("search")}))},n.prototype.render=function(){var e=this.props,t=e.className,i=e.treeContainerClassName,r=e.classPrefix,a=e.value,l=e.enableNodePath,o=e.pathSeparator,u=o===void 0?"/":o,d=e.disabled,p=e.joinValues,c=e.extractValue,h=e.delimiter,v=e.placeholder,y=e.options,A=e.multiple,b=e.valueField,E=e.initiallyOpen,f=e.unfoldedLevel,C=e.withChildren,_=e.onlyChildren,T=e.onlyLeaf,I=e.loading,N=e.hideRoot,K=e.rootLabel,Y=e.autoCheckChildren,ee=e.autoCancelParent,te=e.cascade,ie=e.rootValue,re=e.showIcon,ae=e.showRadio,ne=e.showOutline,oe=e.onAdd,le=e.creatable,se=e.createTip,de=e.addControls,ue=e.onEdit,he=e.editable,pe=e.editTip,ce=e.editControls,ve=e.removable,fe=e.removeTip,me=e.onDelete,ge=e.rootCreatable,ye=e.rootCreateTip,be=e.labelField,Ce=e.iconField,Fe=e.deferField,Ae=e.nodePath,Ee=e.deferLoad,Te=e.expandTreeOptions,P=e.translate,Oe=e.data,_e=e.virtualThreshold,U=e.itemHeight,Ie=e.loadingConfig,Se=e.menuTpl,we=e.enableDefaultIcon,R=e.searchable,M=e.searchConfig,k=M===void 0?{}:M,Le=e.heightAuto,Re=e.mobileUI,w=e.testIdBuilder,He=e.nodeBehavior,Ve=e.itemActions,z=e.id,xe=e.wrapperCustomStyle,G=e.themeCss,Ne=e.env,H=this.props.highlightTxt,V=this.state,ke=V.filteredOptions,De=V.keyword,X=V.allowSearch,$=V.virtualListHeight;Xe(H)&&(H=$e(H,Oe));var Q=m.createElement(Qe,{classPrefix:r,onRef:this.domRef,labelField:be,valueField:b,iconField:Ce,deferField:Fe,disabled:d,onChange:this.handleChange,onHandleNodeClick:this.handleNodeClick,joinValues:p,extractValue:c,delimiter:h,placeholder:P(v),options:R||X?ke:y,highlightTxt:R||X?De:H,multiple:A,initiallyOpen:E,unfoldedLevel:f,withChildren:C,onlyChildren:_,onlyLeaf:T,hideRoot:N,rootLabel:P(K),rootValue:ie,showIcon:re,showRadio:ae,showOutline:ne,autoCheckChildren:Y,autoCancelParent:ee,cascade:te,foldedField:"collapsed",value:a||"",nodePath:Ae,enableNodePath:l,pathSeparator:u,selfDisabledAffectChildren:!1,onAdd:oe,creatable:le,createTip:se,rootCreatable:ge,rootCreateTip:ye,onEdit:ue,editable:he,editTip:pe,removable:ve,removeTip:fe,onDelete:me,bultinCUD:!de&&!ce,onDeferLoad:Ee,onExpandTree:Te,virtualThreshold:_e,virtualHeight:x($)>=0?x($):void 0,itemHeight:x(U)>0?x(U):void 0,itemRender:Se?this.renderOptionItem:void 0,enableDefaultIcon:we,mobileUI:Re,nodeBehavior:He,itemActionsRender:Ve?this.renderItemActions:void 0,actionClassName:B(We(F(F({},this.props),{name:"actionControlClassName",id:z,themeCss:G}))),testIdBuilder:w==null?void 0:w.getChild("tree")});return m.createElement(m.Fragment,null,m.createElement("div",F({ref:this.rootRef,className:B("".concat(r,"TreeControl"),t,i,{"is-sticky":R&&(k==null?void 0:k.sticky),"h-auto":Le})},w==null?void 0:w.getChild("control").getTestId()),m.createElement(Ze,{size:"sm",key:"info",show:I,loadingConfig:Ie}),I?null:R?m.createElement(m.Fragment,null,this.renderSearch(),Q):Q),m.createElement(qe,F({},this.props,{config:{wrapperCustomStyle:xe,id:z,themeCss:G,classNames:[{key:"actionControlClassName"}]},env:Ne})))},n.defaultProps={placeholder:"placeholder.noData",multiple:!1,rootLabel:"Tree.root",rootValue:"",showIcon:!0,enableNodePath:!1,pathSeparator:"/"},g([O,s("design:type",Function),s("design:paramtypes",[Object,Object]),s("design:returntype",void 0)],n.prototype,"addItemFromAction",null),g([O,s("design:type",Function),s("design:paramtypes",[Object,Object]),s("design:returntype",void 0)],n.prototype,"editItemFromAction",null),g([O,s("design:type",Function),s("design:paramtypes",[Object]),s("design:returntype",void 0)],n.prototype,"deleteItemFromAction",null),g([O,s("design:type",Function),s("design:paramtypes",[Object]),s("design:returntype",Promise)],n.prototype,"handleChange",null),g([O,s("design:type",Function),s("design:paramtypes",[Object]),s("design:returntype",Promise)],n.prototype,"handleNodeClick",null),g([O,s("design:type",Function),s("design:paramtypes",[Object]),s("design:returntype",void 0)],n.prototype,"domRef",null),g([O,s("design:type",Function),s("design:paramtypes",[Object,Object]),s("design:returntype",void 0)],n.prototype,"renderOptionItem",null),g([O,s("design:type",Function),s("design:paramtypes",[Object,Object]),s("design:returntype",void 0)],n.prototype,"renderItemActions",null),g([O,s("design:type",Function),s("design:paramtypes",[]),s("design:returntype",void 0)],n.prototype,"renderSearch",null),g([Je(),s("design:type",Function),s("design:paramtypes",[]),s("design:returntype",void 0)],n.prototype,"render",null),n}(m.Component),at=function(S){J(n,S);function n(){return S!==null&&S.apply(this,arguments)||this}return n=g([Ke({type:"input-tree"})],n),n}(it);export{at as TreeControlRenderer,it as default};