Select-BjESF3Zv.js 11 KB

1
  1. import{s as H,bd as oe,X,V as ne,aA as Q,E as R,G as E,bu as ie,y as C,ag as j,a3 as P,t as W,f as O,aF as re,aD as ae,ad as J,aq as le,ae as se,z as M,P as x,Q as c,aX as de,bR as ue,O as pe,bk as Y,ah as K}from"./index-DT8qTvyx.js";import{BaseTransferRenderer as ce}from"./Transfer-SIsRyHCh.js";var Z=function(h){H(n,h);function n(t){var e=h.call(this,t)||this;return e.lastTerm="",e.fetchCancel=null,e.changeValue=e.changeValue.bind(e),e.lazyloadRemote=oe(e.loadRemote.bind(e),250,{trailing:!0,leading:!1}),e.inputRef=e.inputRef.bind(e),e}return n.prototype.componentDidUpdate=function(t){var e=this.props;X(e.autoComplete,e.data)&&ne(t.autoComplete,e.autoComplete,t.data,e.data)&&this.lazyloadRemote(this.lastTerm)},n.prototype.componentWillUnmount=function(){this.unHook&&this.unHook(),this.fetchCancel=null},n.prototype.inputRef=function(t){this.input=t},n.prototype.focus=function(){var t,e;this.input&&((e=(t=this.input)===null||t===void 0?void 0:t.focus)===null||e===void 0||e.call(t))},n.prototype.getValue=function(t,e){e===void 0&&(e=[]);var o=this.props,i=o.joinValues,a=o.extractValue,s=o.delimiter,r=o.multiple,l=o.valueField,d=o.options,u=t;return(Array.isArray(t)?t:t?[t]:[]).forEach(function(p){var v=Q(d,function(g){return g[l||"value"]==p[l||"value"]});v||e.push(p)}),i?r?u=Array.isArray(t)?t.map(function(p){return p[l||"value"]}).join(s):t?t[l||"value"]:"":u=u?u[l||"value"]:"":a&&(r?u=Array.isArray(t)?t.map(function(p){return p[l||"value"]}):t?[t[l||"value"]]:[]:u=u?u[l||"value"]:""),u},n.prototype.dispatchEvent=function(t,e){return e===void 0&&(e={}),R(this,void 0,void 0,function(){var o,i,a,s,r,l,d,u;return E(this,function(p){switch(p.label){case 0:return o="on"+t.charAt(0).toUpperCase()+t.slice(1),i=this.props,a=i.dispatchEvent,s=i.options,r=i.value,l=i.multiple,d=i.selectedOptions,[4,a(t,K(this.props,{options:s,items:s,value:r,selectedItems:l?d:d[0]}))];case 1:return u=p.sent(),u!=null&&u.prevented?[2]:(this.props[o](e),[2])}})})},n.prototype.changeValue=function(t){return R(this,void 0,void 0,function(){var e,o,i,a,s,r,l,d;return E(this,function(u){switch(u.label){case 0:return e=this.props,o=e.onChange,i=e.setOptions,a=e.options,e.data,s=e.dispatchEvent,r=[],l=this.getValue(t,r),r.length&&i(a.concat(r)),[4,s("change",K(this.props,{value:l,options:a,items:a,selectedItems:t}))];case 1:return d=u.sent(),d!=null&&d.prevented?[2]:(o==null||o(l),[2])}})})},n.prototype.loadRemote=function(t){var e;return R(this,void 0,void 0,function(){var o,i,a,s,r,l,d,u,p,v,g,f,m=this;return E(this,function(y){switch(y.label){case 0:if(o=this.props,i=o.autoComplete,a=o.env,s=o.data,r=o.setOptions,l=o.setLoading,d=o.formInited,u=o.addHook,!a||!a.fetcher)throw new Error("fetcher is required");if(d===!1&&u)return this.unHook&&this.unHook(),[2,this.unHook=u(this.loadRemote.bind(this,t),"init")];if(this.lastTerm=t,p=P(s,{term:t,value:t}),!X(i,p))return[2,Promise.resolve({options:[]})];this.fetchCancel&&((e=this.fetchCancel)===null||e===void 0||e.call(this,"autoComplete request cancelled."),this.fetchCancel=null,l(!1)),l(!0),y.label=1;case 1:return y.trys.push([1,,3,4]),[4,a.fetcher(i,p,{cancelExecutor:function(_){return m.fetchCancel=_}})];case 2:return v=y.sent(),this.fetchCancel=null,g=v.data&&v.data.options||v.data||[],f=this.mergeOptions(g),r(f),[2,{options:f}];case 3:return l(!1),[7];case 4:return[2]}})})},n.prototype.mergeOptions=function(t){var e=this.props,o=e.selectedOptions,i=e.valueField,a=i===void 0?"value":i,s=ie(t,void 0,a).concat();return Array.isArray(o)&&o.length&&o.forEach(function(r){Q(s,function(l){return l[a]===r[a]})||s.push(C(C({},r),{hidden:!0}))}),s},n.prototype.renderMenu=function(t,e){var o=this.props,i=o.menuTpl,a=o.render,s=o.data,r=o.optionClassName,l=o.testIdBuilder;return a("menu/".concat(e.index),i,{showNativeTitle:!0,className:j("Select-option-content",r),data:P(P(s,e),t),testIdBuilder:l==null?void 0:l.getChild("option-"+t.value||e.index)})},n.prototype.reload=function(){var t=this.props.reloadOptions;t&&t()},n.prototype.option2value=function(){},n.prototype.renderOtherMode=function(){var t=this.props,e=t.selectMode,o=W(t,["selectMode"]);return O.createElement(he,C({},o,{selectMode:e==="group"?"list":e}))},n.prototype.doAction=function(t,e,o){var i,a,s,r=this.props,l=r.resetValue,d=r.onChange,u=r.formStore,p=r.store,v=r.name,g=r.valueField,f=t==null?void 0:t.actionType;if(f==="clear")d==null||d("");else if(f==="reset"){var m=(s=re((a=u==null?void 0:u.pristine)!==null&&a!==void 0?a:p==null?void 0:p.pristine,v))!==null&&s!==void 0?s:l,y=this.getValue((i={},i[g]=m??"",i));d==null||d(y)}},n.prototype.handleOptionAdd=function(t,e,o,i){var a=this;t===void 0&&(t=-1),o===void 0&&(o=!1);var s=this.props,r=s.onAdd,l=s.autoComplete;r==null||r(t,e,o,function(){return R(a,void 0,void 0,function(){return E(this,function(d){switch(d.label){case 0:return i==null||i(e),l?[4,this.loadRemote(this.lastTerm)]:[3,2];case 1:return d.sent(),[2,!1];case 2:return[2]}})})})},n.prototype.handleOptionEdit=function(t,e,o,i){var a=this,s=this.props,r=s.onEdit,l=s.autoComplete;r==null||r(t,e,o,function(){return R(a,void 0,void 0,function(){return E(this,function(d){switch(d.label){case 0:return i==null||i(t),l?[4,this.loadRemote(this.lastTerm)]:[3,2];case 1:return d.sent(),[2,!1];case 2:return[2]}})})})},n.prototype.handleOptionDelete=function(t,e){var o=this,i=this.props,a=i.onDelete,s=i.autoComplete;a==null||a(t,function(){return R(o,void 0,void 0,function(){return E(this,function(r){switch(r.label){case 0:return e==null||e(t),s?[4,this.loadRemote(this.lastTerm)]:[3,2];case 1:return r.sent(),[2,!1];case 2:return[2]}})})})},n.prototype.render=function(){var t=this,e=this.props,o=e.autoComplete,i=e.searchable,a=e.showInvalidMatch,s=e.options,r=e.className,l=e.popoverClassName,d=e.style,u=e.loading;e.value;var p=e.selectedOptions,v=e.multi,g=e.multiple,f=e.placeholder,m=e.id,y=e.classPrefix;e.classnames;var _=e.creatable;e.inline;var w=e.noResultsText,L=e.render,U=e.menuTpl,k=e.borderMode,B=e.selectMode,T=e.env,S=e.mobileUI,z=e.overlay,A=e.filterOption,V=W(e,["autoComplete","searchable","showInvalidMatch","options","className","popoverClassName","style","loading","value","selectedOptions","multi","multiple","placeholder","id","classPrefix","classnames","creatable","inline","noResultsText","render","menuTpl","borderMode","selectMode","env","mobileUI","overlay","filterOption"]),D=this.props,I=D.classPrefix,F=D.themeCss;return w&&(w=L("noResultText",w)),O.createElement("div",{className:j("".concat(y,"SelectControl"),r),style:d},["table","list","group","tree","chained","associated"].includes(B)?this.renderOtherMode():O.createElement(ae,C({},V,{onAdd:this.handleOptionAdd,onEdit:this.handleOptionEdit,onDelete:this.handleOptionDelete,className:j(J(C(C({},this.props),{name:"selectControlClassName",id:m,themeCss:F}))),popoverClassName:j(l,J(C(C({},this.props),{name:"selectPopoverClassName",id:m,themeCss:F}))),mobileUI:S,popOverContainer:S?T==null?void 0:T.getModalContainer:V.popOverContainer||T.getModalContainer,borderMode:k,placeholder:f,multiple:g||v,ref:this.inputRef,value:p,options:s,filterOption:typeof A=="string"?le(A,"options","inputValue","option"):A,loadOptions:X(o)?this.lazyloadRemote:void 0,showInvalidMatch:a,creatable:_,searchable:i||!!o,onChange:this.changeValue,onBlur:function(N){return t.dispatchEvent("blur",N)},onFocus:function(N){return t.dispatchEvent("focus",N)},loading:u,noResultsText:w,renderMenu:U?this.renderMenu:void 0,overlay:z})),O.createElement(se,C({},this.props,{config:{themeCss:F,classNames:[{key:"selectControlClassName",weights:{focused:{suf:".is-opened:not(.is-mobile)"},disabled:{suf:".is-disabled"}}},{key:"selectPopoverClassName",weights:{default:{suf:" .".concat(I,"Select-option")},hover:{suf:" .".concat(I,"Select-option.is-highlight")},focused:{inner:".".concat(I,"Select-option.is-active")}}}],id:m},env:T})))},n.defaultProps={clearable:!1,searchable:!1,multiple:!1,showInvalidMatch:!1},M([x,c("design:type",Function),c("design:paramtypes",[Object,Object]),c("design:returntype",void 0)],n.prototype,"renderMenu",null),M([x,c("design:type",Function),c("design:paramtypes",[Object,Object,Boolean,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionAdd",null),M([x,c("design:type",Function),c("design:paramtypes",[Object,Object,Boolean,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionEdit",null),M([x,c("design:type",Function),c("design:paramtypes",[Object,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionDelete",null),M([de(),c("design:type",Function),c("design:paramtypes",[]),c("design:returntype",void 0)],n.prototype,"render",null),n}(O.Component),he=function(h){H(n,h);function n(){return h!==null&&h.apply(this,arguments)||this}return n.prototype.renderItem=function(t){var e=this.props,o=e.labelField,i=e.menuTpl,a=e.data,s=e.render;return i?s("option/".concat(t.value),i,{data:P(a,t)}):"".concat(t.scopeLabel||"").concat(t[o||"label"])},n.prototype.render=function(){var t,e=this.props,o=e.className;e.classnames;var i=e.selectedOptions,a=e.sortable,s=e.loading,r=e.searchable,l=e.searchResultMode,d=e.showArrow,u=e.deferLoad,p=e.disabled,v=e.clearable,g=e.selectTitle,f=e.selectMode,m=e.multiple,y=e.columns,_=e.leftMode,w=e.borderMode,L=e.mobileUI,U=e.env,k=e.popOverContainer,B=e.maxTagCount,T=e.overflowTagPopover,S=e.placeholder,z=e.itemHeight,A=e.virtualThreshold,V=e.rightMode,D=e.loadingConfig,I=e.labelField,F=e.showInvalidMatch,N=e.checkAll,ee=e.checkAllLabel,te=e.overlay,q=this.props,b=q.options,$=q.leftOptions,G=q.leftDefaultValue;return f==="associated"&&b&&b.length&&b[0].leftOptions&&Array.isArray(b[0].children)&&($=b[0].leftOptions,G=(t=b[0].leftDefaultValue)!==null&&t!==void 0?t:G,b=b[0].children),O.createElement(O.Fragment,null,O.createElement(ue,{selectMode:f,className:o,value:i,disabled:p,clearable:v,options:b,onChange:this.handleChange,option2value:this.option2value,optionItemRender:this.renderItem,itemRender:this.renderItem,sortable:a,searchResultMode:l,onSearch:r?this.handleSearch:void 0,showArrow:d,onDeferLoad:u,selectTitle:g,multiple:m,columns:y,leftMode:_,rightMode:V,leftOptions:$,borderMode:w,mobileUI:L,popOverContainer:k||U.getModalContainer,maxTagCount:B,overflowTagPopover:T,placeholder:S,itemHeight:z,virtualThreshold:A,virtualListHeight:266,labelField:I,showInvalidMatch:F,checkAllLabel:ee,checkAll:N,overlay:te}),O.createElement(pe,{overlay:!0,key:"info",show:s,loadingConfig:D}))},M([x,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",Object)],n.prototype,"renderItem",null),n}(ce),me=function(h){H(n,h);function n(){return h!==null&&h.apply(this,arguments)||this}return n=M([Y({type:"select"})],n),n}(Z),ge=function(h){H(n,h);function n(){return h!==null&&h.apply(this,arguments)||this}return n.defaultProps={multiple:!0},n=M([Y({type:"multi-select"})],n),n}(Z);export{ge as MultiSelectControlRenderer,me as SelectControlRenderer,Z as default};