Tabs-GvyvBFrS.js 13 KB

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