UNPKG

amis-playground

Version:

amis-playground 是一个amis在线代码编辑器可实时预览运行效果

2 lines (1 loc) 11 kB
import{a as P,b1 as ne,w as W,u as ie,ak as X,j as R,k as _,bi as re,e as C,W as j,D as H,d as G,R as O,ap as le,an as ae,Q as J,a6 as se,U as de,f as M,p as S,q as c,aT as ue,bH as pe,S as ce,b8 as Y,X as K}from"./index-7c288cb3.js";import{BaseTransferRenderer as he}from"./Transfer-35262b14.js";var Z=function(h){P(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=ne(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;W(e.autoComplete,e.data)&&ie(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,l=o.extractValue,s=o.delimiter,r=o.multiple,a=o.valueField,d=o.options,u=t;return(Array.isArray(t)?t:t?[t]:[]).forEach(function(p){var v=X(d,function(g){return g[a||"value"]==p[a||"value"]});v||e.push(p)}),i?r?u=Array.isArray(t)?t.map(function(p){return p[a||"value"]}).join(s):t?t[a||"value"]:"":u=u?u[a||"value"]:"":l&&(r?u=Array.isArray(t)?t.map(function(p){return p[a||"value"]}):t?[t[a||"value"]]:[]:u=u?u[a||"value"]:""),u},n.prototype.dispatchEvent=function(t,e){return e===void 0&&(e={}),R(this,void 0,void 0,function(){var o,i,l,s,r,a,d,u;return _(this,function(p){switch(p.label){case 0:return o="on"+t.charAt(0).toUpperCase()+t.slice(1),i=this.props,l=i.dispatchEvent,s=i.options,r=i.value,a=i.multiple,d=i.selectedOptions,[4,l(t,K(this.props,{options:s,items:s,value:r,selectedItems:a?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,l,s,r,a,d;return _(this,function(u){switch(u.label){case 0:return e=this.props,o=e.onChange,i=e.setOptions,l=e.options,e.data,s=e.dispatchEvent,r=[],a=this.getValue(t,r),r.length&&i(l.concat(r)),[4,s("change",K(this.props,{value:a,options:l,items:l,selectedItems:t}))];case 1:return d=u.sent(),d!=null&&d.prevented?[2]:(o==null||o(a),[2])}})})},n.prototype.loadRemote=function(t){var e;return R(this,void 0,void 0,function(){var o,i,l,s,r,a,d,u,p,v,g,f,m=this;return _(this,function(y){switch(y.label){case 0:if(o=this.props,i=o.autoComplete,l=o.env,s=o.data,r=o.setOptions,a=o.setLoading,d=o.formInited,u=o.addHook,!l||!l.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=H(s,{term:t,value:t}),!W(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,a(!1)),a(!0),y.label=1;case 1:return y.trys.push([1,,3,4]),[4,l.fetcher(i,p,{cancelExecutor:function(E){return m.fetchCancel=E}})];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 a(!1),[7];case 4:return[2]}})})},n.prototype.mergeOptions=function(t){var e=this.props,o=e.selectedOptions,i=e.valueField,l=i===void 0?"value":i,s=re(t,void 0,l).concat();return Array.isArray(o)&&o.length&&o.forEach(function(r){X(s,function(a){return a[l]===r[l]})||s.push(C(C({},r),{hidden:!0}))}),s},n.prototype.renderMenu=function(t,e){var o=this.props,i=o.menuTpl,l=o.render,s=o.data,r=o.optionClassName,a=o.testIdBuilder;return l("menu/".concat(e.index),i,{showNativeTitle:!0,className:j("Select-option-content",r),data:H(H(s,e),t),testIdBuilder:a==null?void 0:a.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=G(t,["selectMode"]);return O.createElement(ve,C({},o,{selectMode:e==="group"?"list":e}))},n.prototype.doAction=function(t,e,o){var i,l,s,r=this.props,a=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=le((l=u==null?void 0:u.pristine)!==null&&l!==void 0?l:p==null?void 0:p.pristine,v))!==null&&s!==void 0?s:a,y=this.getValue((i={},i[g]=m??"",i));d==null||d(y)}},n.prototype.handleOptionAdd=function(t,e,o,i){var l=this;t===void 0&&(t=-1),o===void 0&&(o=!1);var s=this.props,r=s.onAdd,a=s.autoComplete;r==null||r(t,e,o,function(){return R(l,void 0,void 0,function(){return _(this,function(d){switch(d.label){case 0:return i==null||i(e),a?[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 l=this,s=this.props,r=s.onEdit,a=s.autoComplete;r==null||r(t,e,o,function(){return R(l,void 0,void 0,function(){return _(this,function(d){switch(d.label){case 0:return i==null||i(t),a?[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,l=i.onDelete,s=i.autoComplete;l==null||l(t,function(){return R(o,void 0,void 0,function(){return _(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,l=e.showInvalidMatch,s=e.options,r=e.className,a=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=e.creatable;e.inline;var w=e.noResultsText,U=e.render,k=e.menuTpl,L=e.borderMode,B=e.selectMode,T=e.env,x=e.mobileUI,z=e.overlay,A=e.filterOption,V=G(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=U("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(a,J(C(C({},this.props),{name:"selectPopoverClassName",id:m,themeCss:F}))),mobileUI:x,popOverContainer:x?T==null?void 0:T.getModalContainer:V.popOverContainer||T.getModalContainer,borderMode:L,placeholder:f,multiple:g||v,ref:this.inputRef,value:p,options:s,filterOption:typeof A=="string"?se(A,"options","inputValue","option"):A,loadOptions:W(o)?this.lazyloadRemote:void 0,showInvalidMatch:l,creatable:E,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:k?this.renderMenu:void 0,overlay:z})),O.createElement(de,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([S,c("design:type",Function),c("design:paramtypes",[Object,Object]),c("design:returntype",void 0)],n.prototype,"renderMenu",null),M([S,c("design:type",Function),c("design:paramtypes",[Object,Object,Boolean,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionAdd",null),M([S,c("design:type",Function),c("design:paramtypes",[Object,Object,Boolean,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionEdit",null),M([S,c("design:type",Function),c("design:paramtypes",[Object,Function]),c("design:returntype",void 0)],n.prototype,"handleOptionDelete",null),M([ue(),c("design:type",Function),c("design:paramtypes",[]),c("design:returntype",void 0)],n.prototype,"render",null),n}(O.Component),ve=function(h){P(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,l=e.data,s=e.render;return i?s("option/".concat(t.value),i,{data:H(l,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,l=e.sortable,s=e.loading,r=e.searchable,a=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=e.leftMode,w=e.borderMode,U=e.mobileUI,k=e.env,L=e.popOverContainer,B=e.maxTagCount,T=e.overflowTagPopover,x=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,oe=e.valueField,q=this.props,b=q.options,$=q.leftOptions,Q=q.leftDefaultValue;return f==="associated"&&b&&b.length&&b[0].leftOptions&&Array.isArray(b[0].children)&&($=b[0].leftOptions,Q=(t=b[0].leftDefaultValue)!==null&&t!==void 0?t:Q,b=b[0].children),O.createElement(O.Fragment,null,O.createElement(pe,{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:l,searchResultMode:a,onSearch:r?this.handleSearch:void 0,showArrow:d,onDeferLoad:u,selectTitle:g,multiple:m,columns:y,leftMode:E,rightMode:V,leftOptions:$,borderMode:w,mobileUI:U,popOverContainer:L||k.getModalContainer,maxTagCount:B,overflowTagPopover:T,placeholder:x,itemHeight:z,virtualThreshold:A,virtualListHeight:266,labelField:I,showInvalidMatch:F,checkAllLabel:ee,checkAll:N,overlay:te,valueField:oe}),O.createElement(ce,{overlay:!0,key:"info",show:s,loadingConfig:D}))},M([S,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",Object)],n.prototype,"renderItem",null),n}(he),ge=function(h){P(n,h);function n(){return h!==null&&h.apply(this,arguments)||this}return n=M([Y({type:"select"})],n),n}(Z),ye=function(h){P(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{ye as MultiSelectControlRenderer,ge as SelectControlRenderer,Z as default};