1
0
Fork 0
owl-admin-starter/public/admin-assets/assets/Picker-DbAI9BjR.js

2 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import{t as $,l as u,au as M,W as Q,a4 as R,w as U,x as J,Y as G,z as g,G as T,H as S,cy as Y,cT as q,aO as A,ad as I,bn as X,am as x,J as Z,L as W,aV as ee,aQ as z,aK as H,ac as te,ag as j,a9 as ae,M as L,ae as ne,D as b,Q as O,T as i,ap as ie,br as oe,be as re,a_ as se,aM as le,ah as K}from"./index-CEmnTf-r.js";var ce=function(w){$(n,w);function n(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,a=e.addHook,r=e.formItem,l=function(){return T(t,void 0,void 0,function(){var s=this;return S(this,function(d){switch(d.label){case 0:return[4,this.fetchOptions()];case 1:return d.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||!a?r.addInitHook(l):a(l,"init")),t}return n.prototype.componentDidMount=function(){this.mounted=!0},n.prototype.componentDidUpdate=function(e){var t,o=this.props,a=["multiple","source","pickerSchema"];a.some(function(r){return!M(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()},n.prototype.componentWillUnmount=function(){this.toDispose.forEach(function(e){return e()}),this.toDispose=[],this.mounted=!1},n.prototype.fetchOptions=function(){var e,t=this.props,o=t.value,a=t.formItem,r=t.valueField,l=t.labelField,s=t.source,d=t.data,m;if(!(!s||!a||(r||"value")===(l||"label")||(m=a.getSelectedOptions(o))&&(!m.length||m[0][r||"value"]!==m[0][l||"label"]))){var v=R(d,(e={value:o},e[r||"value"]=o,e.op="loadOptions",e));if(U(s))a.setOptions(J(s,d,"| raw"));else if(G(s,v))return a.loadOptions(s,v,{autoAppend:!0})}},n.prototype.buildSchema=function(e){var t,o,a=U(e.source);return g(g({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:a?null:e.source,source:a?e.source:null,keepItemSelectionOnPageChange:!0,valueField:e.valueField,labelField:e.labelField,bulkActions:e.multiple?e.pickerSchema.bulkActions:[]})},n.prototype.crudRef=function(e){for(;e&&e.getWrappedInstance;)e=e.getWrappedInstance();this.crud=e},n.prototype.reload=function(e,t){if(this.crud)this.crud.reload(e,t);else{var o=this.props.reloadOptions;o&&o(e,t)}},n.prototype.open=function(){this.setState({isOpened:!0})},n.prototype.close=function(){this.setState({isOpened:!1})},n.prototype.handleModalConfirm=function(e,t,o,a){return T(this,void 0,void 0,function(){var r;return S(this,function(l){switch(l.label){case 0:return r=se(a,function(s){return s.props.type==="crud"}),[4,this.handleChange(e[r].items)];case 1:return l.sent(),this.close(),[2]}})})},n.prototype.handleChange=function(e){return T(this,void 0,void 0,function(){var t,o,a,r,l,s,d,m,v,f,C,p,c,h;return S(this,function(k){switch(k.label){case 0:return t=this.props,o=t.joinValues,a=t.valueField,r=t.delimiter,l=t.extractValue,s=t.multiple,d=t.options,t.data,m=t.dispatchEvent,t.selectedOptions,v=t.setOptions,f=t.onChange,C=e,o?C=e.map(function(y){return y[a||"value"]}).join(r||","):l?C=s?e.map(function(y){return y[a||"value"]}):e[0]&&e[0][a||"value"]||"":C=s?e:e[0],p=[],e.forEach(function(y){le(d,function(_){return y[a||"value"]==_[a||"value"]})||p.push(y)}),p.length&&v(d.concat(p)),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])}})})},n.prototype.handleItemClick=function(e){return T(this,void 0,void 0,function(){var t,o,a,r;return S(this,function(l){switch(l.label){case 0:return t=this.props,o=t.data,a=t.dispatchEvent,[4,a("itemClick",R(o,{item:e}))];case 1:return r=l.sent(),r!=null&&r.prevented?[2]:[2]}})})},n.prototype.removeItem=function(e){return T(this,void 0,void 0,function(){var t,o,a,r,l,s,d,m,v,f,C,p,c,h;return S(this,function(k){switch(k.label){case 0:return t=this.props,o=t.selectedOptions,a=t.joinValues,r=t.extractValue,l=t.delimiter,s=t.valueField,d=t.onChange,m=t.multiple,v=t.dispatchEvent,f=o.concat(),C=H(f.splice(e,1),1),p=C[0],c=f,a?c=f.map(function(y){return y[s||"value"]}).join(l||","):r?c=m?f.map(function(y){return y[s||"value"]}):f[0]&&f[0][s||"value"]||"":c=m?f:f[0],[4,v("change",K(this.props,{value:c,option:p,selectedItems:p}))];case 1:return h=k.sent(),h!=null&&h.prevented?[2]:(d(c),[2])}})})},n.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)},n.prototype.handleFocus=function(e){this.input.current&&this.input.current.focus(),e.stopPropagation(),this.setState({isFocused:!0})},n.prototype.handleBlur=function(){this.setState({isFocused:!1})},n.prototype.handleClick=function(){this.open()},n.prototype.clearValue=function(e){e.stopPropagation();var t=this.props,o=t.onChange,a=t.resetValue;o(a!==void 0?a:"")},n.prototype.getOverflowConfig=function(){var e=this.props.overflowConfig;return Y(n.defaultProps.overflowConfig,e)},n.prototype.handleSelect=function(e,t){var o=this.props,a=o.selectedOptions,r=o.valueField;if(!(!Array.isArray(e)||!Array.isArray(t)||!e.length&&!t.length)){var l=q(e,a,function(s,d){var m=s[r||"value"],v=d[r||"value"];return m||v?m===v:M(A(s,"value"),A(d,"value"))});l.length===e.length&&l.length===a.length||this.handleChange(e)}},n.prototype.renderTag=function(e,t){var o=this,a=this.props,r=a.itemClearable,l=r===void 0?!0:r,s=a.classPrefix,d=a.classnames,m=a.labelField,v=a.labelTpl;a.translate;var f=a.disabled,C=a.env,p=a.id,c=a.themeCss,h=a.css;return u.createElement("div",{key:t,className:d("".concat(s,"Picker-value"),I(g(g({},this.props),{name:"pickValueWrapClassName",id:p,themeCss:c||h})),{"is-disabled":f})},l&&u.createElement("span",{className:d("".concat(s,"Picker-valueIcon"),I(g(g({},this.props),{name:"pickValueIconClassName",id:p,themeCss:c||h}))),onClick:function(k){k.stopPropagation(),o.removeItem(t)}},"×"),u.createElement(X,{inline:!1,tooltip:x(e,m||"label")},u.createElement("span",{className:d("".concat(s,"Picker-valueLabel"),I(g(g({},this.props),{name:"pickFontClassName",id:p,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")))))},n.prototype.renderValues=function(){var e=this,t=this.props,o=t.classPrefix,a=t.selectedOptions,r=t.translate,l=t.disabled,s=t.multiple,d=t.popOverContainer,m=t.id,v=t.themeCss,f=t.css,C=this.getOverflowConfig(),p=C.maxTagCount,c=C.overflowTagPopover,h=a.length,k=a,y=s!==!1&&ee(p,{start:0,end:h,left:"inclusive",right:"exclusive"});return y&&(k=z(z([],H(a.slice(0,p)),!1),[{label:"+ ".concat(h-p," ..."),value:"__overflow_tag__"}],!1)),u.createElement(u.Fragment,null,k.map(function(_,P){return y&&P===p?u.createElement(te,{key:P,container:d,tooltip:g(g({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"))},a.slice(p,h).map(function(V,N){var E=N+p;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(g(g({},e.props),{name:"pickFontClassName",id:m,themeCss:v||f})))},_.label))):e.renderTag(_,P)}))},n.prototype.overrideCRUDProps=function(){return{}},n.prototype.renderBody=function(e){var t=e===void 0?{}:e,o=t.popOverContainer,a=this.props,r=a.render,l=a.selectedOptions,s=a.options,d=a.multiple,m=a.valueField,v=a.embed,f=a.source,C=a.strictMode,p=a.testIdBuilder,c=this.getOverflowConfig(),h=c.maxTagCount,k=c.overflowTagPopoverInCRUD,y=c.displayPosition;return r("modal-body",this.state.schema,g(g({value:l,valueField:m,primaryField:m,options:f?[]:s,multiple:d,strictMode:C,onSelect:v?this.handleSelect:void 0,testIdBuilder:p==null?void 0:p.getChild("body-schema"),ref:this.crudRef,popOverContainer:o},v||Array.isArray(y)&&y.includes("crud")?{maxTagCount:h,overflowTagPopover:k}:{}),this.overrideCRUDProps()))},n.prototype.render=function(){var e=this.props,t=e.className;e.style;var o=e.modalClassName,a=e.classnames,r=e.disabled,l=e.render,s=e.modalMode,d=e.source,m=e.modalSize,v=e.clearable,f=e.multiple,C=e.placeholder,p=e.embed,c=e.selectedOptions,h=e.translate,k=e.popOverContainer,y=e.modalTitle,_=e.data,P=e.mobileUI,V=e.env,N=e.themeCss,E=e.css,D=e.id,B=e.classPrefix,F=e.testIdBuilder;return u.createElement("div",{className:a("PickerControl",{"is-mobile":P},t)},p?u.createElement("div",{className:a("Picker")},this.renderBody({popOverContainer:k})):u.createElement("div",{className:a("Picker",{"Picker--single":!f,"Picker--multi":f,"is-focused":this.state.isFocused,"is-disabled":r})},u.createElement("div",{onClick:this.handleClick,className:a("Picker-input",r&&"is-disabled",this.state.isFocused&&"is-focused",I(g(g({},this.props),{name:"pickControlClassName",id:D,themeCss:N||E})))},!c.length&&C?u.createElement("div",{className:a("Picker-placeholder")},h(C)):u.createElement("div",g({className:a("Picker-valueWrap")},F==null?void 0:F.getTestId()),this.renderValues(),u.createElement("input",{onChange:ae,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:a("Picker-clear")},u.createElement(L,{icon:"input-clear",className:"icon"})):null,u.createElement("span",g({onClick:this.open,className:a("Picker-btn")},F==null?void 0:F.getChild("picker-open-btn").getTestId()),u.createElement(L,{icon:"window-restore",className:a("icon",I(g(g({},this.props),{name:"pickIconClassName",id:D,themeCss:N||E}))),iconContent:"Picker-icon"}))),l("modal",{title:y&&typeof y=="string"?W(y,_):h("Select.placeholder"),size:m,type:s,className:o,body:{children:this.renderBody},testIdBuilder:F==null?void 0:F.getChild("modal")},{key:"modal",lazyRender:!!d,onConfirm:this.handleModalConfirm,onClose:this.close,show:this.state.isOpened})),u.createElement(ne,g({},this.props,{config:{themeCss:N||E,classNames:[{key:"pickControlClassName",weights:{default:{important:!0},hover:{important:!0},focused:{important:!0,parent:".".concat(B,"Picker.is-focused >")},disabled:{important:!0,parent:".".concat(B,"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})))},n.propsList=["modalTitle","modalMode","modalSize","pickerSchema","labelField","onChange","options","value","inline","multiple","embed","resetValue","placeholder","onQuery"],n.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)],n.prototype,"fetchOptions",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],n.prototype,"crudRef",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"open",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"close",null),b([O,i("design:type",Function),i("design:paramtypes",[Array,Object,Object,Array]),i("design:returntype",Promise)],n.prototype,"handleModalConfirm",null),b([O,i("design:type",Function),i("design:paramtypes",[Array]),i("design:returntype",Promise)],n.prototype,"handleChange",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",Promise)],n.prototype,"handleItemClick",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],n.prototype,"handleKeyDown",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],n.prototype,"handleFocus",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"handleBlur",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"handleClick",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],n.prototype,"clearValue",null),b([O,i("design:type",Function),i("design:paramtypes",[Array,Array]),i("design:returntype",void 0)],n.prototype,"handleSelect",null),b([O,i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"overrideCRUDProps",null),b([O,i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",void 0)],n.prototype,"renderBody",null),b([ie(),i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",void 0)],n.prototype,"render",null),n}(u.PureComponent),pe=function(w){$(n,w);function n(){return w!==null&&w.apply(this,arguments)||this}return n=b([oe({type:"picker",autoLoadOptionsFromSource:!1,sizeMutable:!1})],n),n}(ce);export{pe as PickerControlRenderer,ce as default};