TreeSelect.b53e077a.js 13 KB

123456789101112131415161718192021222324252627
  1. import{c$ as je,G as De,d0 as ze,d1 as $e,d2 as He,cF as We,ck as L,cH as ne,cG as Ge,d as Je,r as v,cJ as Qe,cL as Xe,cN as Ye,aR as _,cM as V,F as c,O as qe,d3 as Ze,cx as et,d4 as tt,cK as oe,cQ as nt,cO as j,cP as at,bj as u,cR as lt,cS as ot,cT as rt,cU as it,a2 as dt,H as st,cy as ct,d5 as ut,cz as ht,cA as ft,cB as gt,d6 as mt,cD as vt,d7 as yt,c_ as p,cX as bt,cY as pt,ct as St,N as wt}from"./index.9b630fd3.js";const kt=t=>{const{popoverColor:h,boxShadow2:i,borderRadius:s,heightMedium:d,dividerColor:y,textColor2:R}=t;return{menuPadding:"4px",menuColor:h,menuBoxShadow:i,menuBorderRadius:s,menuHeight:`calc(${d} * 7.6)`,actionDividerColor:y,actionTextColor:R,actionPadding:"8px 12px"}},xt=je({name:"TreeSelect",common:De,peers:{Tree:ze,Empty:$e,InternalSelection:He},self:kt}),Tt=xt;function ae(t,h){const{rawNode:i}=t;return Object.assign(Object.assign({},i),{label:i[h],value:t.key})}function le(t,h,i,s){const{rawNode:d}=t;return Object.assign(Object.assign({},d),{value:t.key,label:h.map(y=>y.rawNode[s]).join(i)})}const Kt=We([L("tree-select",`
  2. z-index: auto;
  3. outline: none;
  4. width: 100%;
  5. position: relative;
  6. `),L("tree-select-menu",`
  7. position: relative;
  8. overflow: hidden;
  9. margin: 4px 0;
  10. transition: box-shadow .3s var(--n-bezier), background-color .3s var(--n-bezier);
  11. border-radius: var(--n-menu-border-radius);
  12. box-shadow: var(--n-menu-box-shadow);
  13. background-color: var(--n-menu-color);
  14. outline: none;
  15. `,[L("tree","max-height: var(--n-menu-height);"),ne("empty",`
  16. display: flex;
  17. padding: 12px 32px;
  18. flex: 1;
  19. justify-content: center;
  20. `),ne("action",`
  21. padding: var(--n-action-padding);
  22. transition:
  23. color .3s var(--n-bezier);
  24. border-color .3s var(--n-bezier);
  25. border-top: 1px solid var(--n-action-divider-color);
  26. color: var(--n-action-text-color);
  27. `),Ge()])]),Rt=Object.assign(Object.assign(Object.assign(Object.assign({},oe.props),{bordered:{type:Boolean,default:!0},cascade:Boolean,checkable:Boolean,clearable:Boolean,clearFilterAfterSelect:{type:Boolean,default:!0},consistentMenuWidth:{type:Boolean,default:!0},defaultShow:Boolean,defaultValue:{type:[String,Number,Array],default:null},disabled:{type:Boolean,default:void 0},filterable:Boolean,checkStrategy:{type:String,default:"all"},loading:Boolean,maxTagCount:[String,Number],multiple:Boolean,showPath:Boolean,separator:{type:String,default:" / "},options:{type:Array,default:()=>[]},placeholder:String,placement:{type:String,default:"bottom-start"},show:{type:Boolean,default:void 0},size:String,value:[String,Number,Array],to:j.propTo,menuProps:Object,virtualScroll:{type:Boolean,default:!0},status:String,renderTag:Function}),mt),{renderLabel:Function,renderPrefix:Function,renderSuffix:Function,nodeProps:Function,onBlur:Function,onFocus:Function,onLoad:Function,onUpdateShow:[Function,Array],onUpdateValue:[Function,Array],"onUpdate:value":[Function,Array],"onUpdate:show":[Function,Array],leafOnly:Boolean}),Ft=Je({name:"TreeSelect",props:Rt,setup(t){const h=v(null),i=v(null),s=v(null),d=v(null),{mergedClsPrefixRef:y,namespaceRef:R,inlineThemeDisabled:g}=Qe(t),{localeRef:A}=Xe("Select"),{mergedSizeRef:O,mergedDisabledRef:B,mergedStatusRef:re,nTriggerFormBlur:ie,nTriggerFormChange:de,nTriggerFormFocus:se,nTriggerFormInput:ce}=Ye(t),D=v(t.defaultValue),ue=_(t,"value"),S=V(ue,D),z=v(t.defaultShow),he=_(t,"show"),w=V(he,z),C=v(""),fe=c(()=>{const{filter:e}=t;if(e)return e;const{labelField:n}=t;return(l,a)=>l.length?a[n].toLowerCase().includes(l.toLowerCase()):!0}),k=c(()=>vt(t.options,yt(t.keyField,t.childrenField,t.disabledField,void 0))),{value:P}=S,$=v(t.checkable?null:Array.isArray(P)&&P.length?P[P.length-1]:null),M=c(()=>t.multiple&&t.cascade&&t.checkable),H=v(t.defaultExpandAll?void 0:t.defaultExpandedKeys||t.expandedKeys),ge=_(t,"expandedKeys"),me=V(ge,H),F=v(!1),ve=c(()=>{const{placeholder:e}=t;return e!==void 0?e:A.value.placeholder}),ye=c(()=>t.checkable?[]:W.value),W=c(()=>{const{value:e}=S;return t.multiple?Array.isArray(e)?e:[]:e===null||Array.isArray(e)?[]:[e]}),be=c(()=>{const{multiple:e,showPath:n,separator:l,labelField:a}=t;if(e)return null;const{value:o}=S;if(!Array.isArray(o)&&o!==null){const{value:r}=k,m=r.getNode(o);if(m!==null)return n?le(m,r.getPath(o).treeNodePath,l,a):ae(m,a)}return null}),pe=c(()=>{const{multiple:e,showPath:n,separator:l}=t;if(!e)return null;const{value:a}=S;if(Array.isArray(a)){const o=[],{value:r}=k,{checkedKeys:m}=r.getCheckedKeys(a,{checkStrategy:t.checkStrategy,cascade:M.value,allowNotLoaded:t.allowCheckingNotLoaded}),{labelField:f}=t;return m.forEach(te=>{const U=r.getNode(te);U!==null&&o.push(n?le(U,r.getPath(te).treeNodePath,l,f):ae(U,f))}),o}return[]}),Se=c(()=>{const{self:{menuPadding:e}}=E.value;return e});function N(){var e;(e=i.value)===null||e===void 0||e.focus()}function G(){var e;(e=i.value)===null||e===void 0||e.focusInput()}function J(e){const{onUpdateShow:n,"onUpdate:show":l}=t;n&&p(n,e),l&&p(l,e),z.value=e}function x(e,n,l){const{onUpdateValue:a,"onUpdate:value":o}=t;a&&p(a,e,n,l),o&&p(o,e,n,l),D.value=e,ce(),de()}function we(e,n){const{onUpdateIndeterminateKeys:l,"onUpdate:indeterminateKeys":a}=t;l&&p(l,e,n),a&&p(a,e,n)}function ke(e,n,l){const{onUpdateExpandedKeys:a,"onUpdate:expandedKeys":o}=t;a&&p(a,e,n,l),o&&p(o,e,n,l),H.value=e}function Q(e){const{onFocus:n}=t;n&&n(e),se()}function X(e){b();const{onBlur:n}=t;n&&n(e),ie()}function b(){J(!1)}function I(){B.value||(C.value="",J(!0),t.filterable&&G())}function xe(){C.value=""}function Te(e){var n;w.value&&(!((n=i.value)===null||n===void 0)&&n.$el.contains(bt(e))||b())}function Ke(){B.value||(w.value?t.filterable||b():I())}function T(e){const{value:{getNode:n}}=k;return e.map(l=>{var a;return((a=n(l))===null||a===void 0?void 0:a.rawNode)||null})}function Re(e,n,l){const a=T(e),o=l.action==="check"?"select":"unselect",r=l.node;t.multiple?(x(e,a,{node:r,action:o}),t.filterable&&(G(),t.clearFilterAfterSelect&&(C.value=""))):(e.length?x(e[0],a[0]||null,{node:r,action:o}):x(null,null,{node:r,action:o}),b(),N())}function Ce(e){t.checkable&&we(e,T(e))}function Fe(e){var n;!((n=d.value)===null||n===void 0)&&n.contains(e.relatedTarget)||(F.value=!0,Q(e))}function Oe(e){var n;!((n=d.value)===null||n===void 0)&&n.contains(e.relatedTarget)||(F.value=!1,X(e))}function Pe(e){var n,l,a;((n=d.value)===null||n===void 0?void 0:n.contains(e.relatedTarget))||((a=(l=i.value)===null||l===void 0?void 0:l.$el)===null||a===void 0?void 0:a.contains(e.relatedTarget))||(F.value=!0,Q(e))}function Me(e){var n,l,a;((n=d.value)===null||n===void 0?void 0:n.contains(e.relatedTarget))||((a=(l=i.value)===null||l===void 0?void 0:l.$el)===null||a===void 0?void 0:a.contains(e.relatedTarget))||(F.value=!1,X(e))}function Ne(e){e.stopPropagation();const{multiple:n}=t;!n&&t.filterable&&b(),n?x([],[],{node:null,action:"clear"}):x(null,null,{node:null,action:"clear"})}function Ae(e){const{value:n}=S;if(Array.isArray(n)){const{value:l}=k,{checkedKeys:a}=l.getCheckedKeys(n,{cascade:M.value,allowNotLoaded:t.allowCheckingNotLoaded}),o=a.findIndex(r=>r===e.value);if(~o){const r=a[o],m=T([r])[0];if(t.checkable){const{checkedKeys:f}=l.uncheck(e.value,a,{checkStrategy:t.checkStrategy,cascade:M.value,allowNotLoaded:t.allowCheckingNotLoaded});x(f,T(f),{node:m,action:"delete"})}else{const f=Array.from(a);f.splice(o,1),x(f,T(f),{node:m,action:"delete"})}}}}function Be(e){const{value:n}=e.target;C.value=n}function Y(e){const{value:n}=s;n&&n.handleKeydown(e)}function Ie(e){e.key==="Enter"?(w.value?(Y(e),t.multiple||(b(),N())):I(),e.preventDefault()):e.key==="Escape"?w.value&&(pt(e),b(),N()):w.value?Y(e):e.key==="ArrowDown"&&I()}function Ee(){b(),N()}function Ue(e){St(e,"action")||e.preventDefault()}const Le=c(()=>{const{renderTag:e}=t;if(!!e)return function({option:l,handleClose:a}){const{value:o}=l;if(o!==void 0){const r=k.value.getNode(o);if(r)return e({option:r.rawNode,handleClose:a})}return o}});qe(Ze,{pendingNodeKeyRef:$,dataTreeMate:k});function q(){var e;!w.value||(e=h.value)===null||e===void 0||e.syncPosition()}et(d,q);const _e=tt(t),Z=c(()=>{if(t.checkable){const e=S.value;return t.multiple&&Array.isArray(e)?k.value.getCheckedKeys(e,{cascade:t.cascade,checkStrategy:_e.value,allowNotLoaded:t.allowCheckingNotLoaded}):{checkedKeys:Array.isArray(e)||e===null?[]:[e],indeterminateKeys:[]}}return{checkedKeys:[],indeterminateKeys:[]}}),Ve={getCheckedData:()=>{const{checkedKeys:e}=Z.value;return{keys:e,options:T(e)}},getIndeterminateData:()=>{const{indeterminateKeys:e}=Z.value;return{keys:e,options:T(e)}},focus:()=>{var e;return(e=i.value)===null||e===void 0?void 0:e.focus()},blur:()=>{var e;return(e=i.value)===null||e===void 0?void 0:e.blur()}},E=oe("TreeSelect","-tree-select",Kt,Tt,t,y),ee=c(()=>{const{common:{cubicBezierEaseInOut:e},self:{menuBoxShadow:n,menuBorderRadius:l,menuColor:a,menuHeight:o,actionPadding:r,actionDividerColor:m,actionTextColor:f}}=E.value;return{"--n-menu-box-shadow":n,"--n-menu-border-radius":l,"--n-menu-color":a,"--n-menu-height":o,"--n-bezier":e,"--n-action-padding":r,"--n-action-text-color":f,"--n-action-divider-color":m}}),K=g?nt("tree-select",void 0,ee,t):void 0;return Object.assign(Object.assign({},Ve),{menuElRef:d,mergedStatus:re,triggerInstRef:i,followerInstRef:h,treeInstRef:s,mergedClsPrefix:y,mergedValue:S,mergedShow:w,namespace:R,adjustedTo:j(t),isMounted:at(),focused:F,menuPadding:Se,mergedPlaceholder:ve,mergedExpandedKeys:me,treeSelectedKeys:ye,treeCheckedKeys:W,mergedSize:O,mergedDisabled:B,selectedOption:be,selectedOptions:pe,pattern:C,pendingNodeKey:$,mergedCascade:M,mergedFilter:fe,selectionRenderTag:Le,handleTriggerOrMenuResize:q,doUpdateExpandedKeys:ke,handleMenuLeave:xe,handleTriggerClick:Ke,handleMenuClickoutside:Te,handleUpdateCheckedKeys:Re,handleUpdateIndeterminateKeys:Ce,handleTriggerFocus:Fe,handleTriggerBlur:Oe,handleMenuFocusin:Pe,handleMenuFocusout:Me,handleClear:Ne,handleDeleteOption:Ae,handlePatternInput:Be,handleKeydown:Ie,handleTabOut:Ee,handleMenuMousedown:Ue,mergedTheme:E,cssVars:g?void 0:ee,themeClass:K==null?void 0:K.themeClass,onRender:K==null?void 0:K.onRender})},render(){const{mergedTheme:t,mergedClsPrefix:h,$slots:i}=this;return u("div",{class:`${h}-tree-select`},u(lt,null,{default:()=>[u(ot,null,{default:()=>u(rt,{ref:"triggerInstRef",onResize:this.handleTriggerOrMenuResize,status:this.mergedStatus,focused:this.focused,clsPrefix:h,theme:t.peers.InternalSelection,themeOverrides:t.peerOverrides.InternalSelection,renderTag:this.selectionRenderTag,selectedOption:this.selectedOption,selectedOptions:this.selectedOptions,size:this.mergedSize,bordered:this.bordered,placeholder:this.mergedPlaceholder,disabled:this.mergedDisabled,active:this.mergedShow,loading:this.loading,multiple:this.multiple,maxTagCount:this.maxTagCount,showArrow:!0,filterable:this.filterable,clearable:this.clearable,pattern:this.pattern,onPatternInput:this.handlePatternInput,onClear:this.handleClear,onClick:this.handleTriggerClick,onFocus:this.handleTriggerFocus,onBlur:this.handleTriggerBlur,onDeleteOption:this.handleDeleteOption,onKeydown:this.handleKeydown},{arrow:()=>{var s,d;return[(d=(s=this.$slots).arrow)===null||d===void 0?void 0:d.call(s)]}})}),u(it,{ref:"followerInstRef",show:this.mergedShow,placement:this.placement,to:this.adjustedTo,teleportDisabled:this.adjustedTo===j.tdkey,containerClass:this.namespace,width:this.consistentMenuWidth?"target":void 0,minWidth:"target"},{default:()=>u(dt,{name:"fade-in-scale-up-transition",appear:this.isMounted,onLeave:this.handleMenuLeave},{default:()=>{var s;if(!this.mergedShow)return null;const{mergedClsPrefix:d,checkable:y,multiple:R,menuProps:g,options:A}=this;return(s=this.onRender)===null||s===void 0||s.call(this),st(u("div",Object.assign({},g,{class:[`${d}-tree-select-menu`,g==null?void 0:g.class,this.themeClass],ref:"menuElRef",style:[(g==null?void 0:g.style)||"",this.cssVars],tabindex:0,onMousedown:this.handleMenuMousedown,onKeydown:this.handleKeydown,onFocusin:this.handleMenuFocusin,onFocusout:this.handleMenuFocusout}),u(ut,{ref:"treeInstRef",blockLine:!0,allowCheckingNotLoaded:this.allowCheckingNotLoaded,showIrrelevantNodes:!1,animated:!1,pattern:this.pattern,filter:this.mergedFilter,data:A,cancelable:R,labelField:this.labelField,keyField:this.keyField,disabledField:this.disabledField,childrenField:this.childrenField,theme:t.peers.Tree,themeOverrides:t.peerOverrides.Tree,defaultExpandAll:this.defaultExpandAll,defaultExpandedKeys:this.defaultExpandedKeys,expandedKeys:this.mergedExpandedKeys,checkedKeys:this.treeCheckedKeys,selectedKeys:this.treeSelectedKeys,checkable:y,checkStrategy:this.checkStrategy,cascade:this.mergedCascade,leafOnly:this.leafOnly,multiple:this.multiple,renderLabel:this.renderLabel,renderPrefix:this.renderPrefix,renderSuffix:this.renderSuffix,renderSwitcherIcon:this.renderSwitcherIcon,nodeProps:this.nodeProps,virtualScroll:this.consistentMenuWidth&&this.virtualScroll,internalTreeSelect:!0,internalUnifySelectCheck:!0,internalScrollable:!0,internalScrollablePadding:this.menuPadding,internalFocusable:!1,internalCheckboxFocusable:!1,internalRenderEmpty:()=>u("div",{class:`${d}-tree-select-menu__empty`},ht(i.empty,()=>[u(wt,{theme:t.peers.Empty,themeOverrides:t.peerOverrides.Empty})])),onLoad:this.onLoad,onUpdateCheckedKeys:this.handleUpdateCheckedKeys,onUpdateIndeterminateKeys:this.handleUpdateIndeterminateKeys,onUpdateExpandedKeys:this.doUpdateExpandedKeys}),ft(i.action,O=>O?u("div",{class:`${d}-tree-select-menu__action`,"data-action":!0},O):null),u(gt,{onFocus:this.handleTabOut})),[[ct,this.handleMenuClickoutside,void 0,{capture:!0}]])}})})]}))}});export{Ft as N};