1 |
- import{s as re,aA as M,w as B,aH as Z,aG as ue,y as j,aF as $,an as ce,az as ae,a5 as H,E as ne,G as ie,d5 as he,K as se,f as R,a3 as ve,ao as ye,ci as oe,a6 as G,ch as pe,z as b,P as g,Q as d,T as fe,D as be,ah as me,cj as Te}from"./index-DT8qTvyx.js";var ge=function(I){re(r,I);function r(e){var t=I.call(this,e)||this;t.newTabDefaultId=3;var a=e.location||window.location,n=e.tabs,s=e.source,l=e.data,o=0;if(typeof e.activeKey<"u")o=e.activeKey;else if(a&&Array.isArray(n)){var v=a.hash.substring(1),u=M(n,function(K){return K.hash===v});u?o=u.hash:e.defaultKey!==void 0?o=typeof e.defaultKey=="string"?B(e.defaultKey,e.data):e.defaultKey:e.defaultActiveKey&&(o=typeof e.defaultActiveKey=="string"?B(e.defaultActiveKey,e.data):e.defaultActiveKey),o=o||n[0]&&n[0].hash||0}var p=Z(t.initTabArray(n,s,l),2),h=p[0],m=p[1];return t.state={prevKey:void 0,activeKey:t.activeKey=o,localTabs:h,isFromSource:m},t}return r.prototype.initTabArray=function(e,t,a){if(!e)return[[],!1];var n=B(t,a,"| raw");if(!Array.isArray(n))return[e,!1];e=Array.isArray(e)?e:[e];var s=[];return n.forEach(function(l){s.push.apply(s,ue([],Z(e.map(function(o){return j(j({},o),{data:l})})),!1))}),[s,!0]},r.prototype.componentDidMount=function(){var e,t;this.autoJumpToNeighbour(this.activeKey);var a=this.props,n=a.name,s=a.value,l=a.onChange,o=a.source;a.tabs;var v=a.data,u=this.state.localTabs;if(!(!n||typeof l!="function"||o))if(s=s??$(v,n),s&&Array.isArray(u)){var p=this.resolveKeyByValue(s);p!==void 0&&this.handleSelect(p)}else{var h=this.resolveTabByKey(this.activeKey);h&&s!==((e=h.value)!==null&&e!==void 0?e:h.title)&&l((t=h.value)!==null&&t!==void 0?t:h.title,n)}},r.prototype.componentDidUpdate=function(e,t){var a,n,s,l=this.props,o=this.state.localTabs,v=B(e.defaultActiveKey,e.data),u=B(l.defaultActiveKey,l.data),p=ce({tabs:l.tabs,source:B(l.source,l.data,"| raw")},{tabs:e.tabs,source:B(e.source,e.data,"| raw")},!1);if(p){var h=Z(this.initTabArray(l.tabs,l.source,l.data),2),m=h[0],K=h[1];this.setState({localTabs:m,isFromSource:K}),o=m}if(l.location&&e.location&&l.location.hash!==e.location.hash){var S=l.location.hash.substring(1);if(!S)return;var y=M(o,function(C){return C.hash===S});y&&y.hash&&y.hash!==this.state.activeKey&&this.setState({activeKey:this.activeKey=y.hash,prevKey:this.state.activeKey})}else if(Array.isArray(o)&&Array.isArray(t.localTabs)&&JSON.stringify(o.map(function(C){return C.hash}))!==JSON.stringify(t.localTabs.map(function(C){return C.hash}))){var A=this.state.activeKey,x=l.location,y=null;if(x&&Array.isArray(o)){var V=x.hash.substring(1);y=M(o,function(_){return _.hash===V})}y?A=y.hash:(!o||!o.some(function(_,q){return _.hash?_.hash===A:q===A}))&&(A=o&&o[0]&&o[0].hash||0),this.setState({prevKey:void 0,activeKey:this.activeKey=A})}else if(v!==u){if(u==null)return;var E=null,y=M(o,function(_){return _.hash===u});y?E=y.hash:typeof u=="number"&&o[u]&&(E=u),E!==null&&this.setState({prevKey:v,activeKey:this.activeKey=E})}this.autoJumpToNeighbour(this.activeKey);var O=this.props,z=O.name,T=O.value,J=O.onChange,W=O.source,k=O.data;if(!(!z||typeof J!="function"||W)){var U;T=T??$(k,z);var Q=(a=e.value)!==null&&a!==void 0?a:$(e.data,e.name);if(T!==Q&&(U=this.resolveKeyByValue(T))!==void 0&&U!==this.activeKey)this.handleSelect(U);else if(this.activeKey!==t.activeKey){var y=this.resolveTabByKey(this.activeKey);y&&T!==((n=y.value)!==null&&n!==void 0?n:y.title)&&J((s=y.value)!==null&&s!==void 0?s:y.title,z)}}},r.prototype.resolveTabByKey=function(e){var t=this.state.localTabs;if(Array.isArray(t))return M(t,function(a,n){return a.hash?a.hash===e:n===e})},r.prototype.resolveKeyByValue=function(e){var t=this.state.localTabs;if(Array.isArray(t)){var a=M(t,function(n){var s;return((s=n.value)!==null&&s!==void 0?s:n.title)===e});return a&&a.hash?a.hash:t.indexOf(a)}},r.prototype.autoJumpToNeighbour=function(e){var t=this.props;t.tabs;var a=t.data,n=this.state.localTabs;if(Array.isArray(n)){var s=ae(n,function(p,h){return p.hash?p.hash===e:h===e});if(n[s]&&!H(n[s],this.props.data))for(var l=n.length,o=s,v=s;o-->=0||v++<l;){var u=null;if(o>=0&&H(n[o],a)?u=n[o].hash||o:v<l&&H(n[v],a)&&(u=n[v].hash||v),u!==null){this.setState({activeKey:this.activeKey=u});break}}}},r.prototype.handleAdd=function(){var e=this,t=this.state.localTabs.concat();t.push({title:"tab".concat(this.newTabDefaultId++),body:"tab"}),this.setState({localTabs:t},function(){e.switchTo(e.state.localTabs.length-1)})},r.prototype.handleClose=function(e,t){var a=this.state.localTabs.concat();a.splice(e,1),this.setState({localTabs:a})},r.prototype.handleEdit=function(e,t){var a=this.state.localTabs.concat();a[e].title=t,this.setState({localTabs:a})},r.prototype.handleDragChange=function(e){return ne(this,void 0,void 0,function(){var t,a,n=this;return ie(this,function(s){return t=this.resolveTabByKey(this.activeKey),a=this.state.localTabs.concat(),a.splice(e.newIndex,0,a.splice(e.oldIndex,1)[0]),this.setState({localTabs:a},function(){if(t){var l=a.indexOf(t);n.switchTo(l)}}),[2]})})},r.prototype.handleSelect=function(e){var t;return ne(this,void 0,void 0,function(){var a,n,s,l,o,v,u,p,h;return ie(this,function(m){switch(m.label){case 0:return a=this.props,n=a.dispatchEvent,a.data,s=a.env,l=a.onSelect,o=a.id,v=this.state.localTabs,u=v==null?void 0:v.find(function(K,S){return e===(K.hash?K.hash:S)}),u?((t=s.tracker)===null||t===void 0||t.call(s,{eventType:"tabChange",eventData:{id:o,key:e}}),[4,n("change",me(this.props,{value:u!=null&&u.hash?u==null?void 0:u.hash:e+1}))]):[2];case 1:return p=m.sent(),p!=null&&p.prevented?[2]:(typeof e=="string"&&s?s.updateLocation("#".concat(e)):typeof this.state.activeKey=="string"&&s&&s.updateLocation("#"),this.setState({activeKey:this.activeKey=e,prevKey:this.state.activeKey}),typeof l=="string"?(h=Te(l,"key","props"),h&&h(e,this.props)):typeof l=="function"&&l(e,this.props),[2])}})})},r.prototype.doAction=function(e,t,a,n){var s=e==null?void 0:e.actionType,l=Number(n==null?void 0:n.activeKey),o=he(l)?n==null?void 0:n.activeKey:l;s==="changeActiveKey"&&this.handleSelect(typeof o=="number"?o-1:o)},r.prototype.switchTo=function(e){var t=this.state.localTabs;Array.isArray(t)&&t[e]&&this.setState({activeKey:this.activeKey=t[e].hash||e})},r.prototype.currentIndex=function(){var e=this,t=this.state.localTabs;return Array.isArray(t)?ae(t,function(a,n){return a.hash?a.hash===e.state.activeKey:n===e.state.activeKey}):-1},r.prototype.renderTabTitle=function(e,t,a){var n=this.props.render;return typeof e=="string"||!e?se(e,a):n("tab-title/".concat(t),e,{data:j({index:t,__index:t},a)})},r.prototype.renderToolbar=function(){var e=this.props,t=e.toolbar,a=e.render,n=e.classnames,s=e.toolbarClassName;return t?R.createElement("div",{className:n("Tabs-toolbar",s)},a("toolbar",t)):null},r.prototype.renderTabs=function(){var e=this,t=this.props,a=t.classnames,n=t.classPrefix,s=t.contentClassName,l=t.linksClassName,o=t.tabRender,v=t.className,u=t.style,p=t.render,h=t.data,m=t.mode,K=t.tabsMode,S=t.unmountOnExit;t.source;var y=t.formStore,A=t.formMode,x=t.formHorizontal,V=t.subFormMode,E=t.subFormHorizontal,O=t.addable,z=t.closable,T=t.draggable,J=t.showTip,W=t.showTipClassName,k=t.editable,U=t.sidePosition,Q=t.translate,C=t.addBtnText,_=t.collapseOnExceed,q=t.collapseBtnLabel,L=t.disabled,P=t.mobileUI,ee=t.swipeable,N=t.testIdBuilder,le=K||m,X=this.props.mountOnEnter;y&&(X=!1);var te=this.state,f=te.localTabs,de=te.isFromSource,Y=[];return de?Y=f.map(function(i,c){var w,F,D=ve(h,ye(i.data)?j({index:c},i.data):{item:i.data,index:c});return H(i,D)?R.createElement(oe,j({},i,{title:e.renderTabTitle(i.title,c,D),disabled:L||G(i,D),key:c,eventKey:se(i.hash,D)||c,prevKey:c>0?((w=f[c-1])===null||w===void 0?void 0:w.hash)||c-1:0,nextKey:c<f.length-1?((F=f[c+1])===null||F===void 0?void 0:F.hash)||c+1:f.length-1,swipeable:ee,mobileUI:P,mountOnEnter:X,unmountOnExit:typeof i.reload=="boolean"?i.reload:typeof i.unmountOnExit=="boolean"?i.unmountOnExit:S,onSelect:e.handleSelect,testIdBuilder:N==null?void 0:N.getChild("tab-".concat(typeof i.title=="string"?i.title:c))}),p("item/".concat(c),i!=null&&i.type?i:i.tab||i.body,{disabled:L||G(i,D)||void 0,data:D,formMode:i.mode||V||A,formHorizontal:i.horizontal||E||x})):null}):Y=f.map(function(i,c){var w,F;return H(i,h)?R.createElement(oe,j({},i,{title:e.renderTabTitle(i.title,c,h),disabled:L||G(i,h),key:c,eventKey:i.hash||c,prevKey:c>0?((w=f[c-1])===null||w===void 0?void 0:w.hash)||c-1:0,nextKey:c<f.length-1?((F=f[c+1])===null||F===void 0?void 0:F.hash)||c+1:f.length-1,swipeable:ee,mobileUI:P,mountOnEnter:X,unmountOnExit:typeof i.reload=="boolean"?i.reload:typeof i.unmountOnExit=="boolean"?i.unmountOnExit:S,onSelect:e.handleSelect,testIdBuilder:N==null?void 0:N.getChild("tab-".concat(typeof i.title=="string"?i.title:c))}),e.renderTab?e.renderTab(i,e.props,c):o?o(i,e.props,c):p("tab/".concat(c),i!=null&&i.type?i:i.tab||i.body,{disabled:L||G(i,h)||void 0,formMode:i.mode||V||A,formHorizontal:i.horizontal||E||x})):null}),R.createElement(pe,{addBtnText:Q(C||"add"),classPrefix:n,classnames:a,mode:le,closable:z,className:v,style:u,contentClassName:s,linksClassName:l,onSelect:this.handleSelect,activeKey:this.state.activeKey,toolbar:this.renderToolbar(),addable:O,onAdd:this.handleAdd,onClose:this.handleClose,draggable:T,onDragChange:this.handleDragChange,showTip:J,showTipClassName:W,editable:k,onEdit:this.handleEdit,sidePosition:U,collapseOnExceed:_,collapseBtnLabel:q,mobileUI:P,testIdBuilder:N},Y)},r.prototype.render=function(){return this.renderTabs()},r.defaultProps={className:"",mode:"",mountOnEnter:!0,unmountOnExit:!1},b([g,d("design:type",Function),d("design:paramtypes",[Array,String,Object]),d("design:returntype",Array)],r.prototype,"initTabArray",null),b([g,d("design:type",Function),d("design:paramtypes",[Object]),d("design:returntype",void 0)],r.prototype,"autoJumpToNeighbour",null),b([g,d("design:type",Function),d("design:paramtypes",[]),d("design:returntype",void 0)],r.prototype,"handleAdd",null),b([g,d("design:type",Function),d("design:paramtypes",[Number,Object]),d("design:returntype",void 0)],r.prototype,"handleClose",null),b([g,d("design:type",Function),d("design:paramtypes",[Number,String]),d("design:returntype",void 0)],r.prototype,"handleEdit",null),b([g,d("design:type",Function),d("design:paramtypes",[Object]),d("design:returntype",Promise)],r.prototype,"handleDragChange",null),b([g,d("design:type",Function),d("design:paramtypes",[Object]),d("design:returntype",Promise)],r.prototype,"handleSelect",null),b([g,d("design:type",Function),d("design:paramtypes",[Number]),d("design:returntype",void 0)],r.prototype,"switchTo",null),b([g,d("design:type",Function),d("design:paramtypes",[]),d("design:returntype",Number)],r.prototype,"currentIndex",null),r}(R.Component),Ae=function(I){re(r,I);function r(e,t){var a=I.call(this,e)||this,n=t;return n.registerComponent(a),a}return r.prototype.componentWillUnmount=function(){var e;(e=I.prototype.componentWillUnmount)===null||e===void 0||e.call(this);var t=this.context;t.unRegisterComponent(this)},r.contextType=fe,r=b([be({type:"tabs"}),d("design:paramtypes",[Object,Object])],r),r}(ge);export{Ae as TabsRenderer,ge as default};
|