2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{t as me,aM as z,x,aK as W,aQ as ge,z as y,am as se,av as Ce,a_ as ue,a5 as M,G as ne,H as ie,dl as Ke,L as ce,l as b,ad as H,a4 as he,aw as ve,cr as pe,a6 as Q,ae as re,cq as Ne,D as T,Q as N,T as c,U as Ae,E as Se,dm as Ee,ah as ye,cs as _e}from"./index-CEmnTf-r.js";var we=function(D){me(l,D);function l(e){var t=D.call(this,e)||this;t.newTabDefaultId=3;var a=e.location||window.location,n=e.tabs,i=e.source,o=e.data,r=0;if(typeof e.activeKey<"u")r=e.activeKey;else if(a&&Array.isArray(n)){var h=a.hash.substring(1),u=z(n,function(A){return A.hash===h});u?r=u.hash:e.defaultKey!==void 0?r=typeof e.defaultKey=="string"?x(e.defaultKey,e.data):e.defaultKey:e.defaultActiveKey&&(r=typeof e.defaultActiveKey=="string"?x(e.defaultActiveKey,e.data):e.defaultActiveKey),r=r||n[0]&&n[0].hash||0}var p=W(t.initTabArray(n,i,o),2),v=p[0],g=p[1];return t.state={prevKey:void 0,activeKey:t.activeKey=r,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 i=[];return n.forEach(function(o){i.push.apply(i,ge([],W(e.map(function(r){return y(y({},r),{data:o})})),!1))}),[i,!0]},l.prototype.componentDidMount=function(){var e,t;this.autoJumpToNeighbour(this.activeKey);var a=this.props,n=a.name,i=a.value,o=a.onChange,r=a.source;a.tabs;var h=a.data,u=this.state.localTabs;if(!(!n||typeof o!="function"||r))if(i=i??se(h,n),i&&Array.isArray(u)){var p=this.resolveKeyByValue(i);p!==void 0&&this.handleSelect(p)}else{var v=this.resolveTabByKey(this.activeKey);v&&i!==((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,i,o=this.props,r=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=W(this.initTabArray(o.tabs,o.source,o.data),2),g=v[0],A=v[1];this.setState({localTabs:g,isFromSource:A}),r=g}if(o.location&&e.location&&o.location.hash!==e.location.hash){var _=o.location.hash.substring(1);if(!_)return;var m=z(r,function(F){return F.hash===_});m&&m.hash&&m.hash!==this.state.activeKey&&this.setState({activeKey:this.activeKey=m.hash,prevKey:this.state.activeKey})}else if(Array.isArray(r)&&Array.isArray(t.localTabs)&&JSON.stringify(r.map(function(F){return F.hash}))!==JSON.stringify(t.localTabs.map(function(F){return F.hash}))){var S=this.state.activeKey,U=o.location,m=null;if(U&&Array.isArray(r)){var k=U.hash.substring(1);m=z(r,function(E){return E.hash===k})}m?S=m.hash:(!r||!r.some(function(E,Y){return E.hash?E.hash===S:Y===S}))&&(S=r&&r[0]&&r[0].hash||0),this.setState({prevKey:void 0,activeKey:this.activeKey=S})}else if(h!==u){if(u==null)return;var w=null,m=z(r,function(E){return E.hash===u});m?w=m.hash:typeof u=="number"&&r[u]&&(w=u),w!==null&&this.setState({prevKey:h,activeKey:this.activeKey=w})}this.autoJumpToNeighbour(this.activeKey);var O=this.props,V=O.name,C=O.value,J=O.onChange,q=O.source,P=O.data;if(!(!V||typeof J!="function"||q)){var R;C=C??se(P,V);var X=(a=e.value)!==null&&a!==void 0?a:se(e.data,e.name);if(C!==X&&(R=this.resolveKeyByValue(C))!==void 0&&R!==this.activeKey)this.handleSelect(R);else if(this.activeKey!==t.activeKey){var m=this.resolveTabByKey(this.activeKey);m&&C!==((n=m.value)!==null&&n!==void 0?n:m.title)&&J((i=m.value)!==null&&i!==void 0?i:m.title,V)}}},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 i;return((i=n.value)!==null&&i!==void 0?i: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 i=ue(n,function(p,v){return p.hash?p.hash===e:v===e});if(n[i]&&!M(n[i],this.props.data))for(var o=n.length,r=i,h=i;r-->=0||h++<o;){var u=null;if(r>=0&&M(n[r],a)?u=n[r].hash||r:h<o&&M(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,i,o;return ie(this,function(r){switch(r.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),i=this.props.dispatchEvent,[4,i("delete",ye(this.props,{value:e}))]);case 1:return o=r.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(i){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,i,o,r,h,u,p,v;return ie(this,function(g){switch(g.label){case 0:return a=this.props,n=a.dispatchEvent,a.data,i=a.env,o=a.onSelect,r=a.id,h=this.state.localTabs,u=h==null?void 0:h.find(function(A,_){return e===(A.hash?A.hash:_)}),u?((t=i.tracker)===null||t===void 0||t.call(i,{eventType:"tabChange",eventData:{id:r,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"&&i?i.updateLocation("#".concat(e)):typeof this.state.activeKey=="string"&&i&&i.updateLocation("#"),this.setState({activeKey:this.activeKey=e,prevKey:this.state.activeKey}),typeof o=="string"?(v=_e(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 i=e==null?void 0:e.actionType,o=Number(n==null?void 0:n.activeKey),r=Ke(o)?n==null?void 0:n.activeKey:o,h=n==null?void 0:n.deleteHash;i==="changeActiveKey"?this.handleSelect(typeof r=="number"?r-1:r):i==="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,i=e.toolbarClassName,o=e.id,r=e.themeCss;return t?b.createElement("div",{className:n("Tabs-toolbar",i,H(y(y({},this.props),{name:"toolbarControlClassName",id:o,themeCss:r})))},a("toolbar",t)):null},l.prototype.renderTabs=function(){var e=this,t=this.props,a=t.classnames,n=t.classPrefix,i=t.contentClassName,o=t.linksClassName,r=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 m=t.formStore,S=t.formMode,U=t.formHorizontal,k=t.subFormMode,w=t.subFormHorizontal,O=t.addable,V=t.closable,C=t.draggable,J=t.showTip,q=t.showTipClassName,P=t.editable,R=t.sidePosition,X=t.translate,F=t.addBtnText,E=t.collapseOnExceed,Y=t.collapseBtnLabel,L=t.disabled,Z=t.mobileUI,oe=t.swipeable,I=t.testIdBuilder,G=t.id,le=t.wrapperCustomStyle,$=t.themeCss,fe=t.env,be=A||g,ee=this.props.mountOnEnter;m&&(ee=!1);var de=this.state,f=de.localTabs,Te=de.isFromSource,te=[],ae=[];return Te?(te=f.map(function(s,d){var K,B,j=he(v,ve(s.data)?y({index:d},s.data):{item:s.data,index:d});return M(s,j)?b.createElement(pe,y({},s,{title:e.renderTabTitle(s.title,d,j),disabled:L||Q(s,j),key:d,eventKey:ce(s.hash,j)||d,prevKey:d>0?((K=f[d-1])===null||K===void 0?void 0:K.hash)||d-1:0,nextKey:d<f.length-1?((B=f[d+1])===null||B===void 0?void 0:B.hash)||d+1:f.length-1,swipeable:oe,mobileUI:Z,mountOnEnter:ee,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||Q(s,j)||void 0,data:j,formMode:s.mode||k||S,formHorizontal:s.horizontal||w||U})):null}),ae=f.map(function(s,d){var K=he(v,ve(s.data)?y({index:d},s.data):{item:s.data,index:d});return M(s,K)?b.createElement(re,y({},s,{config:{id:s.id,themeCss:s.themeCss,classNames:[{key:"panelControlClassName"}]},env:e.props.env,key:"customstyle_".concat(d)})):null})):(te=f.map(function(s,d){var K,B;return M(s,v)?b.createElement(pe,y({},s,{title:e.renderTabTitle(s.title,d,v),disabled:L||Q(s,v),key:d,eventKey:s.hash||d,prevKey:d>0?((K=f[d-1])===null||K===void 0?void 0:K.hash)||d-1:0,nextKey:d<f.length-1?((B=f[d+1])===null||B===void 0?void 0:B.hash)||d+1:f.length-1,swipeable:oe,mobileUI:Z,mountOnEnter:ee,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):r?r(s,e.props,d):p("tab/".concat(d),s!=null&&s.type?s:s.tab||s.body,{disabled:L||Q(s,v)||void 0,formMode:s.mode||k||S,formHorizontal:s.horizontal||w||U})):null}),ae=f.map(function(s,d){return M(s,v)?b.createElement(re,{config:{id:s.id,themeCss:s.themeCss,classNames:[{key:"panelControlClassName"}]},env:e.props.env,key:"customstyle_".concat(d)}):null})),b.createElement(b.Fragment,null,b.createElement(Ne,{addBtnText:X(F||"add"),classPrefix:n,classnames:a,mode:be,closable:V,className:a(h,H(y(y({},this.props),{name:"wrapperCustomStyle",id:G,themeCss:le}))),style:u,contentClassName:a(i,H(y(y({},this.props),{name:"contentControlClassName",id:G,themeCss:$}))),linksClassName:o,titleClassName:a(H(y(y({},this.props),{name:"titleControlClassName",id:G,themeCss:$}))),onSelect:this.handleSelect,activeKey:this.state.activeKey,toolbar:this.renderToolbar(),addable:O,onAdd:this.handleAdd,onClose:this.handleClose,draggable:C,onDragChange:this.handleDragChange,showTip:J,showTipClassName:q,editable:P,onEdit:this.handleEdit,sidePosition:R,collapseOnExceed:E,collapseBtnLabel:Y,mobileUI:Z,testIdBuilder:I},te),ae,b.createElement(re,y({},this.props,{config:{wrapperCustomStyle:le,id:G,themeCss:$,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:fe})))},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),Fe=function(D){me(l,D);function l(e,t){var a=D.call(this,e)||this,n=t;return n.registerComponent(a),a}return l.prototype.componentWillUnmount=function(){var e;(e=D.prototype.componentWillUnmount)===null||e===void 0||e.call(this);var t=this.context;t.unRegisterComponent(this)},l.contextType=Ae,l=T([Se({type:"tabs",onGlobalVarChanged:function(e,t,a){if(Ee(t.source)){var n=W(e.initTabArray(e.props.tabs,e.props.source,a),2),i=n[0],o=n[1];return e.setState({localTabs:i,isFromSource:o}),!1}}}),c("design:paramtypes",[Object,Object])],l),l}(we);export{Fe as TabsRenderer,we as default};
|