1
0
Fork 0
owl-admin-starter/public/admin-assets/assets/NestedSelect-CFMkOERr.js

2 lines
17 KiB
JavaScript

import{cB as te,g as ne,cC as se,cD as ae,cE as re,t as z,l as v,am as le,G as A,H as j,b$ as q,cF as D,ce as U,ax as G,bx as ie,cG as oe,b8 as J,z as x,M as de,cH as M,a8 as ce,aa as ue,ab as he,ad as Q,by as pe,b5 as ve,P as fe,bz as me,cI as ye,ae as ge,D as k,Q as F,T as l,ap as Ce,br as Z,ah as be,cJ as ke,cK as K,cL as Oe,bm as X,bu as Ne}from"./index-CEmnTf-r.js";var Se=se,Fe=te,Ee=ae,Pe=re,_e=Fe(function(_){return Ee(Se(_,1,Pe,!0))}),Te=_e;const Y=ne(Te);var ee=function(_){z(r,_);function r(){var e=_!==null&&_.apply(this,arguments)||this;return e.outTarget=v.createRef(),e.state={isOpened:!1,isFocused:!1,inputValue:"",stack:[e.props.options]},e}return r.prototype.domRef=function(e){this.target=e},r.prototype.componentDidUpdate=function(e){e.options!==this.props.options&&this.setState({stack:[this.props.options]})},r.prototype.doAction=function(e,t,s){var a,n,i=this.props,o=i.resetValue,d=i.onChange,c=i.formStore,h=i.store,u=i.name,m=e==null?void 0:e.actionType;if(m==="clear")d==null||d("");else if(m==="reset"){var C=(n=le((a=c==null?void 0:c.pristine)!==null&&a!==void 0?a:h==null?void 0:h.pristine,u))!==null&&n!==void 0?n:o;d==null||d(C??"")}},r.prototype.dispatchEvent=function(e,t){return t===void 0&&(t={}),A(this,void 0,void 0,function(){var s,a,n,i,o,d,c;return j(this,function(h){switch(h.label){case 0:return s=this.props,a=s.dispatchEvent,n=s.options,i=s.multiple,o=s.value,d=s.selectedOptions,[4,a(e,be(this.props,x({options:n,items:n,value:o,selectedItems:i?d:d[0]},t)))];case 1:return c=h.sent(),[2,!!(c!=null&&c.prevented)]}})})},r.prototype.isParentNode=function(e){return Array.isArray(e.children)&&e.children.length>0},r.prototype.handleOutClick=function(e){var t;e.stopPropagation(),this.outTargetWidth=(t=this.outTarget.current)===null||t===void 0?void 0:t.clientWidth,e.defaultPrevented||this.setState(function(s){return{isOpened:!s.isOpened}})},r.prototype.handleResultClear=function(){this.setState({inputValue:void 0})},r.prototype.close=function(){this.setState({isOpened:!1})},r.prototype.removeItem=function(e,t){return A(this,void 0,void 0,function(){var s,a,n,i,o;return j(this,function(d){switch(d.label){case 0:return s=this.props,a=s.onChange,n=s.selectedOptions,t&&t.stopPropagation(),n.splice(e,1),i=this.getValue(),[4,this.dispatchEvent("change",{value:i})];case 1:return o=d.sent(),o||a(i),[2]}})})},r.prototype.renderValue=function(e,t){var s=this.props,a=s.classnames,n=s.labelField,i=s.valueField,o=s.options,d=s.hideNodePathLabel,c=this.state.inputValue||"",h=q(c);if(d)return D(e[n||"label"]);var u=U(o,e,!0),m=D(e[n||"label"]),C=" / ",V=u?u.map(function(N){return D(N[n||"label"])}).join(C):m;return v.createElement("span",{className:a("Select-valueLabel"),key:t||e[i||"value"],title:V},u?u.map(function(N,P){var y=D(N[n||"label"]),g=N[i||"value"],R=P===u.length-1;return v.createElement("span",{key:P},h.test(g)||h.test(y)?ke(y,c):y,!R&&C)}):m)},r.prototype.handleOptionClick=function(e){return A(this,void 0,void 0,function(){var t,s,a,n,i,o,d,c,h;return j(this,function(u){switch(u.label){case 0:return t=this.props,s=t.multiple,a=t.onChange,n=t.joinValues,i=t.extractValue,o=t.valueField,d=t.onlyLeaf,s?[2]:(c=n||i?e[o||"value"]:e,c===void 0?[2]:d&&this.isParentNode(e)?[2]:[4,this.dispatchEvent("change",{value:c})]);case 1:return h=u.sent(),h||a(c),h||this.handleResultClear(),this.setState({stack:[this.props.options]}),this.close(),[2]}})})},r.prototype.handleCheck=function(e,t,s){return A(this,void 0,void 0,function(){var a,n,i,o,d,c,h,u,m,C,V,N,P,y,g,R,T,T,f,p,S,O;return j(this,function(E){switch(E.label){case 0:if(a=this.props,n=a.onChange,i=a.selectedOptions,o=a.joinValues,d=a.delimiter,c=a.extractValue,h=a.withChildren,u=a.onlyChildren,m=a.cascade,C=a.options,V=a.onlyLeaf,N=this.state.stack,P=this.props.valueField||"value",V&&!Array.isArray(e)&&this.isParentNode(e))return[2];if(!Array.isArray(e)&&e.children&&e.children.length&&typeof t=="number"&&(N[t]?N.splice(t+1,1,e.children):N.push(e.children)),y=i,R=function(b){return Ne(M(Array.isArray(b)?b:[b],function(w){return w.children&&w.children.length?null:w}))},Array.isArray(e)?(h?e=M(e):u&&(e=R(e)),g=y.length===e.length?[]:e):Array.isArray(e.children)?m?g=K(y,[e]):h?(e=M([e]),T=e.every(function(b){return!!~y.indexOf(b)}),g=(T?K:Y)(y,e)):u?(e=R(e),T=e.every(function(b){return!!~y.indexOf(b)}),g=(T?K:Y)(y,e)):(g=y.filter(function(b){return!~M([e]).indexOf(b)}),!~y.indexOf(e)&&g.push(e)):g=K(y,[e]),!m)for(f=e;;){if(p=Oe(C,f),p!=null&&p.value&&p.children.every(function(b){return~g.indexOf(b)})){p.children.forEach(function(b){var w=g.indexOf(b);~w&&!h&&!u&&g.splice(w,1)}),u||g.push(p),f=p;continue}break}return S=o?g.map(function(b){return b[P]}).join(d):c?g.map(function(b){return b[P]}):g,[4,this.dispatchEvent("change",{value:S})];case 1:return O=E.sent(),O||n(S),O||this.handleResultClear(),s&&this.setState({stack:[this.props.options]}),[2]}})})},r.prototype.allChecked=function(e){var t=this,s=this.props,a=s.selectedOptions,n=s.withChildren,i=s.onlyChildren;return e.every(function(o){return(n||i)&&o.children?t.allChecked(o.children):a.some(function(d){return d===o})})},r.prototype.partialChecked=function(e){var t=this;return e.some(function(s){var a=s.children&&t.partialChecked(s.children);return a||t.props.selectedOptions.some(function(n){return n===s})})},r.prototype.reload=function(e,t){var s=this.props.reloadOptions;s&&s(e,t)},r.prototype.getValue=function(){var e=this.props,t=e.selectedOptions,s=e.joinValues,a=e.valueField,n=e.extractValue,i=e.delimiter,o=e.value;return s?o=t.map(function(d){return d[a||"value"]}).join(i||","):n&&(o=t.map(function(d){return d[a||"value"]})),o},r.prototype.onFocus=function(e){return A(this,void 0,void 0,function(){var t,s,a,n,i;return j(this,function(o){switch(o.label){case 0:return t=this.props,s=t.onFocus,a=t.disabled,n=this.getValue(),!a&&!this.state.isOpened?(this.setState({isFocused:!0}),[4,this.dispatchEvent("focus",{value:n})]):[3,2];case 1:i=o.sent(),i||s&&s(e),o.label=2;case 2:return[2]}})})},r.prototype.onBlur=function(e){return A(this,void 0,void 0,function(){var t,s,a;return j(this,function(n){switch(n.label){case 0:return t=this.props.onBlur,s=this.getValue(),this.setState({isFocused:!1}),[4,this.dispatchEvent("blur",{value:s})];case 1:return a=n.sent(),a||t&&t(e),[2]}})})},r.prototype.getTarget=function(){return this.target||(this.target=G.findDOMNode(this)),this.target},r.prototype.handleKeyPress=function(e){e.key===" "&&(this.handleOutClick(e),e.preventDefault())},r.prototype.handleInputKeyDown=function(e){var t=this.state.inputValue,s=this.props,a=s.multiple,n=s.selectedOptions;e.key==="Backspace"&&!t&&n.length&&a&&this.removeItem(n.length-1)},r.prototype.handleInputChange=function(e){var t=this.props,s=t.options,a=t.labelField,n=t.valueField,i=e&&this.state.isOpened?ie(s,function(o,d,c,h){return!!X([o].concat(h),e,{keys:[a||"label",n||"value"],threshold:X.rankings.CONTAINS}).length||!!(o.children&&o.children.length)},1,!0):s.concat();this.setState({inputValue:e,stack:[i]})},r.prototype.handleResultChange=function(e){return A(this,void 0,void 0,function(){var t,s,a,n,i,o,d,c,h,u;return j(this,function(m){switch(m.label){case 0:return t=this.props,s=t.joinValues,a=t.extractValue,n=t.delimiter,i=t.valueField,o=t.onChange,d=t.multiple,c=Array.isArray(e)?e.concat():[],!d&&!c.length?[4,this.dispatchEvent("change",{value:""})]:[3,2];case 1:return h=m.sent(),h||o(""),[2];case 2:return(s||a)&&(c=e.map(function(C){return C[i||"value"]})),s&&(c=c.join(n||",")),[4,this.dispatchEvent("change",{value:c})];case 3:return u=m.sent(),u||o(c),[2]}})})},r.prototype.getMenuSelectMenuStyle=function(){var e=this.props.options,t=this.outTargetWidth,s=oe(e),a={};return t&&(a={width:t/s}),a},r.prototype.renderOptions=function(){var e=this,t=this.props,s=t.multiple,a=t.selectedOptions,n=t.classnames,i=t.options,o=t.disabled,d=t.checkAll,c=t.checkAllLabel,h=t.translate,u=t.labelField,m=t.menuClassName,C=t.cascade,V=t.onlyChildren,N=t.testIdBuilder,P=this.props.valueField||"value",y=this.state.stack,g=this.partialChecked(i),R=this.allChecked(i);return v.createElement(v.Fragment,null,y.map(function(T,f){return v.createElement("div",{key:f,className:n("NestedSelect-menu",m),style:e.getMenuSelectMenuStyle()},s&&d&&f===0?v.createElement("div",{className:n("NestedSelect-option","checkall")},v.createElement(J,{size:"sm",onChange:e.handleCheck.bind(e,T),checked:g,partial:g&&!R}),v.createElement("span",{onClick:e.handleCheck.bind(e,T)},h(c))):null,T.map(function(p,S){var O=N==null?void 0:N.getChild("menu-".concat(f)).getChild(p.value||S),E=U(i,p),b=E==null?void 0:E.some(function($){return!!~a.indexOf($)}),w=C?!1:s&&b,I=E==null?void 0:E.some(function($){return!!$.disabled}),B=w||p.disabled||I||!!o,W=!!(p.children&&e.partialChecked(p.children)),L=w||!!~a.indexOf(p);!L&&V&&s&&e.isParentNode(p)&&e.allChecked(p.children)&&(L=!0);var H=D(p[u||"label"]);return v.createElement("div",{key:S,className:n("NestedSelect-option",{"is-active":!B&&(L||!C&&W)}),onMouseEnter:e.onMouseEnter.bind(e,p,f)},s?v.createElement(J,{size:"sm",onChange:e.handleCheck.bind(e,p,f,!1),trueValue:p[P],checked:L||!C&&W,partial:!L,disabled:B,testIdBuilder:O==null?void 0:O.getChild("checkbox")}):null,v.createElement("div",x({className:n("NestedSelect-optionLabel",{"is-disabled":B}),onClick:function(){return!B&&(s?e.handleCheck(p,f):e.handleOptionClick(p))},title:H},O==null?void 0:O.getTestId()),H),p.children&&p.children.length?v.createElement("div",x({className:n("NestedSelect-optionArrowRight",{"is-disabled":B})},O==null?void 0:O.getChild("arrow-right").getTestId()),v.createElement(de,{icon:"right-arrow-bold",className:"icon"})):null)}))}))},r.prototype.renderSearchResult=function(){var e=this,t=this.state,s=t.stack,a=t.inputValue,n=this.props,i=n.classnames,o=n.translate,d=n.options,c=n.labelField,h=n.valueField,u=n.cascade,m=n.selectedOptions,C=n.multiple,V=n.disabled,N=n.onlyChildren,P=n.render,y=this.props.noResultsText;y&&(y=P("noResultText",o(y)));var g=q(a||""),R=M(s[0]).filter(function(f){return!!(g.test(f[h||"value"])||g.test(f[c||"label"]))}),T=v.createElement("div",{className:i("NestedSelect-menu"),style:this.getMenuSelectMenuStyle()},R.length?R.map(function(f,p){var S=U(d,f),O=u?!1:C&&(S==null?void 0:S.some(function(I){return!!~m.indexOf(I)})),E=O||f.disabled||!!V||(S==null?void 0:S.some(function(I){return!!I.disabled})),b=!!(f.children&&e.partialChecked(f.children)),w=O||!!~m.indexOf(f);return!w&&N&&e.isParentNode(f)&&e.allChecked(f.children)&&(w=!0),v.createElement("div",{className:i("NestedSelect-option",{"is-active":!E&&(w||!u&&b)}),key:p},v.createElement("div",{className:i("NestedSelect-optionLabel",{"is-disabled":E}),onClick:function(){!E&&(C?e.handleCheck(f,f.value,!0):e.handleOptionClick(f))}},e.renderValue(f,f.value)))}):v.createElement("div",{className:i("NestedSelect-option",{"no-result":!0})},y));return T},r.prototype.onMouseEnter=function(e,t,s){var a=this.state.stack;t=t+1;var n=e.children;n&&n.length?a[t]?a.splice(t,1,n):a.push(n):a[t]&&a.splice(t,1),this.setState({stack:a.slice(0,t+1)})},r.prototype.renderOuter=function(){var e=this,t=this.props,s=t.popOverContainer,a=t.translate,n=t.classnames,i=t.options,o=t.render,d=t.id,c=t.themeCss,h=!!this.state.inputValue,u=this.props.noResultsText;u&&(u=o("noResultText",a(u)));var m=v.createElement(ce,{disabled:!this.state.isOpened,onRootClose:this.close},function(C){return v.createElement("div",{className:n("NestedSelect-menuOuter"),ref:C},h?e.renderSearchResult():i.length?e.renderOptions():v.createElement("div",{className:n("NestedSelect-noResult")},u))});return v.createElement(ue,{target:this.getTarget,container:s||function(){return G.findDOMNode(e)},placement:"auto",show:!0},v.createElement(he,{className:n("NestedSelect-popover",Q(x(x({},this.props),{name:"nestedSelectPopoverClassName",id:d,themeCss:c})))},m))},r.prototype.render=function(){var e,t=this.props,s=t.className,a=t.style,n=t.disabled,i=t.classnames,o=t.multiple,d=t.placeholder,c=t.translate,h=t.inline,u=t.searchable,m=t.selectedOptions,C=t.clearable,V=t.loading,N=t.borderMode,P=t.mobileUI;t.popOverContainer;var y=t.env,g=t.testIdBuilder,R=t.loadingConfig,T=t.maxTagCount,f=t.overflowTagPopover,p=this.props,S=p.classPrefix,O=p.themeCss,E=p.id;return v.createElement("div",{className:i("NestedSelectControl",s),ref:this.outTarget,style:a},v.createElement(pe,{mobileUI:P,maxTagCount:T,overflowTagPopover:f,disabled:n,ref:this.domRef,placeholder:c(d??"placeholder.empty"),inputPlaceholder:"",className:i("NestedSelect",(e={"NestedSelect--inline":h,"NestedSelect--single":!o,"NestedSelect--multi":o,"NestedSelect--searchable":u,"is-opened":this.state.isOpened,"is-focused":this.state.isFocused},e["NestedSelect--border".concat(ve(N))]=N,e),Q(x(x({},this.props),{name:"nestedSelectControlClassName",id:E,themeCss:O}))),result:o?m:m.length?m[0]:"",onResultClick:this.handleOutClick,value:this.state.inputValue,onChange:this.handleInputChange,onResultChange:this.handleResultChange,onClear:this.handleResultClear,itemRender:this.renderValue,onKeyPress:this.handleKeyPress,onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.handleInputKeyDown,clearable:C,hasDropDownArrow:!0,allowInput:u&&!P,testIdBuilder:g},V?v.createElement(fe,{loadingConfig:R,size:"sm"}):void 0),P?v.createElement(me,{className:i("NestedSelect-popup"),container:y.getModalContainer,isShow:this.state.isOpened,onHide:this.close,showConfirm:!1,showClose:!1},v.createElement(ye,x({onClose:this.close},this.props,{onChange:this.handleResultChange,options:this.props.options.slice(),value:m}))):this.state.isOpened?this.renderOuter():null,v.createElement(ge,x({},this.props,{config:{themeCss:O,classNames:[{key:"nestedSelectControlClassName",weights:{hover:{suf:".is-clickable:not(.is-disabled)"},focused:{suf:".is-opened:not(.is-mobile)"},disabled:{suf:".is-disabled"}}},{key:"nestedSelectPopoverClassName",weights:{default:{suf:" .".concat(S,"NestedSelect-option")},hover:{suf:" .".concat(S,"NestedSelect-option.is-highlight")},focused:{inner:".".concat(S,"NestedSelect-option.is-active")}}}],id:E},env:y})))},r.defaultProps={cascade:!1,withChildren:!1,onlyChildren:!1,onlyLeaf:!1,searchPromptText:"Select.searchPromptText",noResultsText:"noResult",checkAll:!0,checkAllLabel:"Select.checkAll",hideNodePathLabel:!1},k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],r.prototype,"domRef",null),k([F,l("design:type",Function),l("design:paramtypes",[String,Object]),l("design:returntype",Promise)],r.prototype,"dispatchEvent",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],r.prototype,"handleOutClick",null),k([F,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"handleResultClear",null),k([F,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"close",null),k([F,l("design:type",Function),l("design:paramtypes",[Object,Object]),l("design:returntype",void 0)],r.prototype,"renderValue",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",Promise)],r.prototype,"handleOptionClick",null),k([F,l("design:type",Function),l("design:paramtypes",[Object,Number,Boolean]),l("design:returntype",Promise)],r.prototype,"handleCheck",null),k([F,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"getValue",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",Promise)],r.prototype,"onFocus",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",Promise)],r.prototype,"onBlur",null),k([F,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"getTarget",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],r.prototype,"handleKeyPress",null),k([F,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],r.prototype,"handleInputKeyDown",null),k([F,l("design:type",Function),l("design:paramtypes",[String]),l("design:returntype",void 0)],r.prototype,"handleInputChange",null),k([F,l("design:type",Function),l("design:paramtypes",[Array]),l("design:returntype",Promise)],r.prototype,"handleResultChange",null),k([F,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"getMenuSelectMenuStyle",null),k([Ce(),l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],r.prototype,"render",null),r}(v.Component),Re=function(_){z(r,_);function r(){return _!==null&&_.apply(this,arguments)||this}return r=k([Z({type:"nested-select"})],r),r}(ee),Ve=function(_){z(r,_);function r(){return _!==null&&_.apply(this,arguments)||this}return r=k([Z({type:"cascader-select"})],r),r}(ee);export{Ve as CascaderSelectControlRenderer,Re as NestedSelectControlRenderer,ee as default};