UNPKG

amis-playground

Version:

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

2 lines (1 loc) 13.6 kB
import{a as $,R as u,a2 as B,u as q,D as M,i as U,r as Q,w as X,e as y,j as T,k as S,ce as J,cA as G,am as A,Q as I,b4 as Y,ap as x,H as Z,n as W,aq as ee,ar as H,ai as z,T as te,W as j,N as ne,I as L,U as ae,f as b,p as O,q as i,aT as ie,b8 as oe,aX as re,ay as se,ak as le,X as K}from"./index-7c288cb3.js";var ce=function(w){$(a,w);function a(e){var t=w.call(this,e)||this;t.state={isOpened:!1,schema:t.buildSchema(t.props),isFocused:!1},t.input=u.createRef(),t.toDispose=[],t.mounted=!1;var o=e.formInited,n=e.addHook,r=e.formItem,l=function(){return T(t,void 0,void 0,function(){var s=this;return S(this,function(p){switch(p.label){case 0:return[4,this.fetchOptions()];case 1:return p.sent(),this.mounted&&this.toDispose.push(re(function(){return JSON.stringify(r==null?void 0:r.tmpValue)},function(){return s.fetchOptions()})),[2]}})})};return r&&t.toDispose.push(o||!n?r.addInitHook(l):n(l,"init")),t}return a.prototype.componentDidMount=function(){this.mounted=!0},a.prototype.componentDidUpdate=function(e){var t,o=this.props,n=["multiple","source","pickerSchema"];n.some(function(r){return!B(e[r],o[r])})?this.setState({schema:this.buildSchema(o)}):q(e.source,o.source,e.data,o.data)&&!((t=o.formItem)===null||t===void 0)&&t.inited&&this.fetchOptions()},a.prototype.componentWillUnmount=function(){this.toDispose.forEach(function(e){return e()}),this.toDispose=[],this.mounted=!1},a.prototype.fetchOptions=function(){var e,t=this.props,o=t.value,n=t.formItem,r=t.valueField,l=t.labelField,s=t.source,p=t.data,m;if(!(!s||!n||(r||"value")===(l||"label")||(m=n.getSelectedOptions(o))&&(!m.length||m[0][r||"value"]!==m[0][l||"label"]))){var v=M(p,(e={value:o},e[r||"value"]=o,e.op="loadOptions",e));if(U(s))n.setOptions(Q(s,p,"| raw"));else if(X(s,v))return n.loadOptions(s,v,{autoAppend:!0})}},a.prototype.buildSchema=function(e){var t,o,n=U(e.source);return y(y({checkOnItemClick:!0,listItem:{title:"${".concat(e.labelField||"label","|raw}")}},e.pickerSchema),{labelTpl:(o=(t=e.pickerSchema)===null||t===void 0?void 0:t.labelTpl)!==null&&o!==void 0?o:e.labelTpl,type:"crud",pickerMode:!0,syncLocation:!1,filterCanAccessSuperData:!1,api:n?null:e.source,source:n?e.source:null,keepItemSelectionOnPageChange:!0,valueField:e.valueField,labelField:e.labelField,bulkActions:e.multiple?e.pickerSchema.bulkActions:[]})},a.prototype.crudRef=function(e){for(;e&&e.getWrappedInstance;)e=e.getWrappedInstance();this.crud=e},a.prototype.reload=function(){if(this.crud)this.crud.search();else{var e=this.props.reloadOptions;e&&e()}},a.prototype.open=function(){this.setState({isOpened:!0})},a.prototype.close=function(){this.setState({isOpened:!1})},a.prototype.handleModalConfirm=function(e,t,o,n){return T(this,void 0,void 0,function(){var r;return S(this,function(l){switch(l.label){case 0:return r=se(n,function(s){return s.props.type==="crud"}),[4,this.handleChange(e[r].items)];case 1:return l.sent(),this.close(),[2]}})})},a.prototype.handleChange=function(e){return T(this,void 0,void 0,function(){var t,o,n,r,l,s,p,m,v,f,C,d,c,h;return S(this,function(k){switch(k.label){case 0:return t=this.props,o=t.joinValues,n=t.valueField,r=t.delimiter,l=t.extractValue,s=t.multiple,p=t.options,t.data,m=t.dispatchEvent,t.selectedOptions,v=t.setOptions,f=t.onChange,C=e,o?C=e.map(function(g){return g[n||"value"]}).join(r||","):l?C=s?e.map(function(g){return g[n||"value"]}):e[0]&&e[0][n||"value"]||"":C=s?e:e[0],d=[],e.forEach(function(g){le(p,function(_){return g[n||"value"]==_[n||"value"]})||d.push(g)}),d.length&&v(p.concat(d)),c=s?e:e[0],[4,m("change",K(this.props,{value:C,option:c,selectedItems:c}))];case 1:return h=k.sent(),h!=null&&h.prevented?[2]:(f(C),[2])}})})},a.prototype.handleItemClick=function(e){return T(this,void 0,void 0,function(){var t,o,n,r;return S(this,function(l){switch(l.label){case 0:return t=this.props,o=t.data,n=t.dispatchEvent,[4,n("itemClick",M(o,{item:e}))];case 1:return r=l.sent(),r!=null&&r.prevented?[2]:[2]}})})},a.prototype.removeItem=function(e){return T(this,void 0,void 0,function(){var t,o,n,r,l,s,p,m,v,f,C,d,c,h;return S(this,function(k){switch(k.label){case 0:return t=this.props,o=t.selectedOptions,n=t.joinValues,r=t.extractValue,l=t.delimiter,s=t.valueField,p=t.onChange,m=t.multiple,v=t.dispatchEvent,f=o.concat(),C=z(f.splice(e,1),1),d=C[0],c=f,n?c=f.map(function(g){return g[s||"value"]}).join(l||","):r?c=m?f.map(function(g){return g[s||"value"]}):f[0]&&f[0][s||"value"]||"":c=m?f:f[0],[4,v("change",K(this.props,{value:c,option:d,selectedItems:d}))];case 1:return h=k.sent(),h!=null&&h.prevented?[2]:(p(c),[2])}})})},a.prototype.handleKeyDown=function(e){var t=this.props.selectedOptions;e.key===" "?(this.open(),e.preventDefault()):t.length&&e.key=="Backspace"&&this.removeItem(t.length-1)},a.prototype.handleFocus=function(e){this.input.current&&this.input.current.focus(),e.stopPropagation(),this.setState({isFocused:!0})},a.prototype.handleBlur=function(){this.setState({isFocused:!1})},a.prototype.handleClick=function(){this.open()},a.prototype.clearValue=function(e){e.stopPropagation();var t=this.props,o=t.onChange,n=t.resetValue;o(n!==void 0?n:"")},a.prototype.getOverflowConfig=function(){var e=this.props.overflowConfig;return J(a.defaultProps.overflowConfig,e)},a.prototype.handleSelect=function(e,t){var o=this.props,n=o.selectedOptions,r=o.valueField;if(!(!Array.isArray(e)||!Array.isArray(t)||!e.length&&!t.length)){var l=G(e,n,function(s,p){var m=s[r||"value"],v=p[r||"value"];return m||v?m===v:B(A(s,"value"),A(p,"value"))});l.length===e.length&&l.length===n.length||this.handleChange(e)}},a.prototype.renderTag=function(e,t){var o=this,n=this.props,r=n.itemClearable,l=r===void 0?!0:r,s=n.classPrefix,p=n.classnames,m=n.labelField,v=n.labelTpl;n.translate;var f=n.disabled,C=n.env,d=n.id,c=n.themeCss,h=n.css;return u.createElement("div",{key:t,className:p("".concat(s,"Picker-value"),I(y(y({},this.props),{name:"pickValueWrapClassName",id:d,themeCss:c||h})),{"is-disabled":f})},l&&u.createElement("span",{className:p("".concat(s,"Picker-valueIcon"),I(y(y({},this.props),{name:"pickValueIconClassName",id:d,themeCss:c||h}))),onClick:function(k){k.stopPropagation(),o.removeItem(t)}},"×"),u.createElement(Y,{inline:!1,tooltip:x(e,m||"label")},u.createElement("span",{className:p("".concat(s,"Picker-valueLabel"),I(y(y({},this.props),{name:"pickFontClassName",id:d,themeCss:c||h}))),onClick:function(k){k.stopPropagation(),o.handleItemClick(e)}},v?u.createElement(Z,{html:W(v,e),filterHtml:C.filterHtml}):"".concat(x(e,m||"label")||x(e,"id")))))},a.prototype.renderValues=function(){var e=this,t=this.props,o=t.classPrefix,n=t.selectedOptions,r=t.translate,l=t.disabled,s=t.multiple,p=t.popOverContainer,m=t.id,v=t.themeCss,f=t.css,C=this.getOverflowConfig(),d=C.maxTagCount,c=C.overflowTagPopover,h=n.length,k=n,g=s!==!1&&ee(d,{start:0,end:h,left:"inclusive",right:"exclusive"});return g&&(k=H(H([],z(n.slice(0,d)),!1),[{label:"+ ".concat(h-d," ..."),value:"__overflow_tag__"}],!1)),u.createElement(u.Fragment,null,k.map(function(_,P){return g&&P===d?u.createElement(te,{key:P,container:p,tooltip:y(y({tooltipClassName:j("Picker-overflow",c==null?void 0:c.tooltipClassName),title:r("已选项")},A(c,["children","content","tooltipClassName"])),{children:function(){return u.createElement("div",{className:j("".concat(o,"Picker-overflow-wrapper"))},n.slice(d,h).map(function(V,N){var E=N+d;return e.renderTag(V,E)}))}})},u.createElement("div",{key:P,className:j("".concat(o,"Picker-value"),{"is-disabled":l})},u.createElement("span",{className:"".concat(o,"Picker-valueLabel ").concat(I(y(y({},e.props),{name:"pickFontClassName",id:m,themeCss:v||f})))},_.label))):e.renderTag(_,P)}))},a.prototype.overrideCRUDProps=function(){return{}},a.prototype.renderBody=function(e){var t=e===void 0?{}:e,o=t.popOverContainer,n=this.props,r=n.render,l=n.selectedOptions,s=n.options,p=n.multiple,m=n.valueField,v=n.embed,f=n.source,C=n.strictMode,d=n.testIdBuilder,c=this.getOverflowConfig(),h=c.maxTagCount,k=c.overflowTagPopoverInCRUD,g=c.displayPosition;return r("modal-body",this.state.schema,y(y({value:l,valueField:m,primaryField:m,options:f?[]:s,multiple:p,strictMode:C,onSelect:v?this.handleSelect:void 0,testIdBuilder:d==null?void 0:d.getChild("body-schema"),ref:this.crudRef,popOverContainer:o},v||Array.isArray(g)&&g.includes("crud")?{maxTagCount:h,overflowTagPopover:k}:{}),this.overrideCRUDProps()))},a.prototype.render=function(){var e=this.props,t=e.className;e.style;var o=e.modalClassName,n=e.classnames,r=e.disabled,l=e.render,s=e.modalMode,p=e.source,m=e.size,v=e.clearable,f=e.multiple,C=e.placeholder,d=e.embed,c=e.selectedOptions,h=e.translate,k=e.popOverContainer,g=e.modalTitle,_=e.data,P=e.mobileUI,V=e.env,N=e.themeCss,E=e.css,D=e.id,R=e.classPrefix,F=e.testIdBuilder;return u.createElement("div",{className:n("PickerControl",{"is-mobile":P},t)},d?u.createElement("div",{className:n("Picker")},this.renderBody({popOverContainer:k})):u.createElement("div",{className:n("Picker",{"Picker--single":!f,"Picker--multi":f,"is-focused":this.state.isFocused,"is-disabled":r})},u.createElement("div",{onClick:this.handleClick,className:n("Picker-input",r&&"is-disabled",this.state.isFocused&&"is-focused",I(y(y({},this.props),{name:"pickControlClassName",id:D,themeCss:N||E})))},!c.length&&C?u.createElement("div",{className:n("Picker-placeholder")},h(C)):u.createElement("div",y({className:n("Picker-valueWrap")},F==null?void 0:F.getTestId()),this.renderValues(),u.createElement("input",{onChange:ne,value:"",ref:this.input,onKeyDown:this.handleKeyDown,onClick:this.handleFocus,onBlur:this.handleBlur,readOnly:P})),v&&!r&&c.length?u.createElement("a",{onClick:this.clearValue,className:n("Picker-clear")},u.createElement(L,{icon:"input-clear",className:"icon"})):null,u.createElement("span",y({onClick:this.open,className:n("Picker-btn")},F==null?void 0:F.getChild("picker-open-btn").getTestId()),u.createElement(L,{icon:"window-restore",className:n("icon",I(y(y({},this.props),{name:"pickIconClassName",id:D,themeCss:N||E}))),iconContent:"Picker-icon"}))),l("modal",{title:g&&typeof g=="string"?W(g,_):h("Select.placeholder"),size:m,type:s,className:o,body:{children:this.renderBody},testIdBuilder:F==null?void 0:F.getChild("modal")},{key:"modal",lazyRender:!!p,onConfirm:this.handleModalConfirm,onClose:this.close,show:this.state.isOpened})),u.createElement(ae,y({},this.props,{config:{themeCss:N||E,classNames:[{key:"pickControlClassName",weights:{default:{important:!0},hover:{important:!0},focused:{important:!0,parent:".".concat(R,"Picker.is-focused >")},disabled:{important:!0,parent:".".concat(R,"Picker.is-disabled >")}}},{key:"pickFontClassName"},{key:"pickValueWrapClassName",weights:{default:{important:!0}}},{key:"pickValueIconClassName",weights:{default:{important:!0},hover:{important:!0}}},{key:"pickIconClassName",weights:{default:{suf:" svg"}}}],id:D},env:V})))},a.propsList=["modalTitle","modalMode","pickerSchema","labelField","onChange","options","value","inline","multiple","embed","resetValue","placeholder","onQuery"],a.defaultProps={modalMode:"dialog",multiple:!1,placeholder:"Picker.placeholder",labelField:"label",valueField:"value",pickerSchema:{mode:"list"},embed:!1,overflowConfig:{maxTagCount:-1,displayPosition:["select","crud"],overflowTagPopover:{placement:"top",trigger:"hover",showArrow:!1,offset:[0,-5]},overflowTagPopoverInCRUD:{placement:"bottom",trigger:"hover",showArrow:!1,offset:[0,0]}}},b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",Object)],a.prototype,"fetchOptions",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"crudRef",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"open",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"close",null),b([O,i("design:type",Function),i("design:paramtypes",[Array,Object,Object,Array]),i("design:returntype",Promise)],a.prototype,"handleModalConfirm",null),b([O,i("design:type",Function),i("design:paramtypes",[Array]),i("design:returntype",Promise)],a.prototype,"handleChange",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",Promise)],a.prototype,"handleItemClick",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"handleKeyDown",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"handleFocus",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"handleBlur",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"handleClick",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"clearValue",null),b([O,i("design:type",Function),i("design:paramtypes",[Array,Array]),i("design:returntype",void 0)],a.prototype,"handleSelect",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"overrideCRUDProps",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],a.prototype,"renderBody",null),b([ie(),i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],a.prototype,"render",null),a}(u.PureComponent),de=function(w){$(a,w);function a(){return w!==null&&w.apply(this,arguments)||this}return a=b([oe({type:"picker",autoLoadOptionsFromSource:!1,sizeMutable:!1})],a),a}(ce);export{de as PickerControlRenderer,ce as default};