Comparing version 1.0.4 to 1.0.5
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.RBTable=t(e.React)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;10>r;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}();var o="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function i(){}var l,a,s,d,c,u,f,h,p,m,b,y,w,v,_,g,x=(function(e){e.exports=function(){function e(e,t,r,n,i,l){if(l!==o){var a=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=i,r.PropTypes=r,r}()}(l={exports:{}},l.exports),l.exports),E=!1;function M(){if(!E){E=!0;var e=navigator.userAgent,t=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(e),r=/(Mac OS X)|(Windows)|(Linux)/.exec(e);if(w=/\b(iPhone|iP[ao]d)/.exec(e),v=/\b(iP[ao]d)/.exec(e),b=/Android/i.exec(e),_=/FBAN\/\w+;/i.exec(e),g=/Mobile/i.exec(e),y=!!/Win64/.exec(e),t){(a=t[1]?parseFloat(t[1]):t[5]?parseFloat(t[5]):NaN)&&document&&document.documentMode&&(a=document.documentMode);var n=/(?:Trident\/(\d+.\d+))/.exec(e);f=n?parseFloat(n[1])+4:a,s=t[2]?parseFloat(t[2]):NaN,d=t[3]?parseFloat(t[3]):NaN,(c=t[4]?parseFloat(t[4]):NaN)?(t=/(?:Chrome\/(\d+\.\d+))/.exec(e),u=t&&t[1]?parseFloat(t[1]):NaN):u=NaN}else a=s=d=u=c=NaN;if(r){if(r[1]){var o=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(e);h=!o||parseFloat(o[1].replace("_","."))}else h=!1;p=!!r[2],m=!!r[3]}else h=p=m=!1}}var S,O={ie:function(){return M()||a},ieCompatibilityMode:function(){return M()||f>a},ie64:function(){return O.ie()&&y},firefox:function(){return M()||s},opera:function(){return M()||d},webkit:function(){return M()||c},safari:function(){return O.webkit()},chrome:function(){return M()||u},windows:function(){return M()||p},osx:function(){return M()||h},linux:function(){return M()||m},iphone:function(){return M()||w},mobile:function(){return M()||w||v||b||g},nativeApp:function(){return M()||_},android:function(){return M()||b},ipad:function(){return M()||v}},C=O,N=!("undefined"==typeof window||!window.document||!window.document.createElement),R={canUseDOM:N,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:N&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:N&&!!window.screen,isInWorker:!N};R.canUseDOM&&(S=document.implementation&&document.implementation.hasFeature&&!0!==document.implementation.hasFeature("",""));var k=function(e,t){if(!R.canUseDOM||t&&!("addEventListener"in document))return!1;var r="on"+e,n=r in document;if(!n){var o=document.createElement("div");o.setAttribute(r,"return;"),n="function"==typeof o[r]}return!n&&S&&"wheel"===e&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n},D=10,T=40,W=800;function L(e){var t=0,r=0,n=0,o=0;return"detail"in e&&(r=e.detail),"wheelDelta"in e&&(r=-e.wheelDelta/120),"wheelDeltaY"in e&&(r=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=r,r=0),n=t*D,o=r*D,"deltaY"in e&&(o=e.deltaY),"deltaX"in e&&(n=e.deltaX),(n||o)&&e.deltaMode&&(1==e.deltaMode?(n*=T,o*=T):(n*=W,o*=W)),n&&!t&&(t=1>n?-1:1),o&&!r&&(r=1>o?-1:1),{spinX:t,spinY:r,pixelX:n,pixelY:o}}L.getEventType=function(){return C.firefox()?"DOMMouseScroll":k("wheel")?"wheel":"mousewheel"};var B,z,P=L,A=navigator.userAgent.match(/Trident/),F=(B=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,20)},function(e){return B(e)}),q=(z=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.clearTimeout,function(e){return z(e)});function H(e){var t=e.target||e.srcElement;t.__resizeRAF__&&q(t.__resizeRAF__),t.__resizeRAF__=F(function(){var r=t.__resizeTrigger__;r.__resizeListeners__.forEach(function(t){t.call(r,e)})})}function j(){this.contentDocument.defaultView.__resizeTrigger__=this.__resizeElement__,this.contentDocument.defaultView.addEventListener("resize",H)}function I(e,t){if(!e.__resizeListeners__){e.__resizeListeners__=[];var r=e.__resizeTrigger__=document.createElement("object");r.setAttribute("style","display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"),r.__resizeElement__=e,r.onload=j,r.type="text/html",A&&e.appendChild(r),r.data="about:blank",A||e.appendChild(r)}e.__resizeListeners__.push(t)}function X(e,t){var r={};for(var n in e)0>t.indexOf(n)&&Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function U(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;r>o;o++)n[o-1]=arguments[o];if(t)return"string"==typeof t||"number"==typeof t?t:"function"==typeof t?t.apply(void 0,n):e.isValidElement(t)?e.cloneElement(t,{tableContext:n}):void 0}function Y(e){return e.width?{width:e.width}:null}function V(e){return e?e+"px":e}function G(e,t){e.style.height=t}function K(e,t,r){return e.width&&e[t]?Error(r+".column."+t+" will not take effect when column.width is set."):"maxWidth"===t&&e.minWidth>e.maxWidth?Error(r+".column.maxWidth is smaller then column.minWidth"):void 0}var Z=function(t){function r(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,t.call(this,e));return n.setTableRef=n.setTableRef.bind(n),n.handleResize=n.handleResize.bind(n),n.handleScroll=n.handleScroll.bind(n),n.handleClickRow=n.handleClickRow.bind(n),n.handleWindowMouseUp=n.handleWindowMouseUp.bind(n),n.handleWindowMouseMove=n.handleWindowMouseMove.bind(n),n.hScrollPanelMouseDown=n.hScrollPanelMouseDown.bind(n),n.vScrollPanelMouseDown=n.vScrollPanelMouseDown.bind(n),n.hScrollBarMouseDown=n.hScrollBarMouseDown.bind(n),n.vScrollBarMouseDown=n.vScrollBarMouseDown.bind(n),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(r,t),r.prototype.componentWillUnmount=function(){I(this.table,this.handleResize),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("mousemove",this.handleWindowMouseMove)},r.prototype.componentDidMount=function(){var e=this;window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("mousemove",this.handleWindowMouseMove),setTimeout(function(){e.reflow()})},r.prototype.setTableRef=function(e){var t,r;e&&(this.table&&(r=this.handleResize,(t=this.table).__resizeListeners__&&(t.__resizeListeners__.splice(t.__resizeListeners__.indexOf(r),1),t.__resizeListeners__.length||(t.__resizeTrigger__.contentDocument.defaultView.removeEventListener("resize",H),t.__resizeTrigger__=!t.removeChild(t.__resizeTrigger__)))),this.table=e,I(e,this.handleResize))},r.prototype.componentDidUpdate=function(){this.reflow()},r.prototype.handleResize=function(){this.reflow()},r.prototype.reflow=function(){this.alignTable(),this.scrollByOffset(0,0)},r.prototype.handleScroll=function(e){var t=P(e),r=t.pixelY,n=t.pixelX;r=Math.round(.5*r);var o=this.scrollByOffset(n=Math.round(.5*n),r).hasOffset;e.preventDefault(),o&&e.stopPropagation()},r.prototype.handleClickRow=function(e,t){this.props.onRowClick&&this.props.onRowClick(e,t)},r.prototype.setLocation=function(e,t){this.x=e,this.y=t},r.prototype.handleWindowMouseUp=function(){this.mouseIsDownRight=!1,this.mouseIsDownBottom=!1},r.prototype.handleWindowMouseMove=function(e){var t=e.clientY;this.mouseIsDownBottom?this.handleMouseMove(e.clientX,0):this.mouseIsDownRight&&this.handleMouseMove(0,t)},r.prototype.hScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientX-this.refs.hScrollBar.getBoundingClientRect().left;this.scrollByOffset(t,0)},r.prototype.vScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientY-this.refs.vScrollBar.getBoundingClientRect().top;this.scrollByOffset(0,t)},r.prototype.hScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownBottom=!0,this.setLocation(e)},r.prototype.vScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownRight=!0,this.setLocation(e)},r.prototype.handleMouseMove=function(e,t){var r=e-this.x,n=t-this.y;this.setLocation(e,t),this.scrollByOffset(r,n)},r.prototype.getHoverClass=function(){var e=this.props.prefixCls,t=" "+e+"-row--hover";return this.props.onRowClick&&(t+=e+"-row--clickable"),t},r.prototype.bodies=function(){var e=this.refs;return[e.bodyMiddleContent,e.bodyLeftContent,e.bodyRightContent].filter(function(e){return!!e})},r.prototype.handleRowEnter=function(e){var t=this;this.bodies().forEach(function(r){return r.children[e].className+=t.getHoverClass()})},r.prototype.handleRowLeave=function(e){var t=this;this.bodies().forEach(function(r){return r.children[e].className=r.children[e].className.replace(t.getHoverClass(),"")})},r.prototype.getTableWidthHeight=function(){var e=this.refs.virtualTable,t=[],r=[],n=e.querySelector("thead > tr"),o=e.querySelector("colgroup");function i(){for(var e=0;n.children.length>e;e++)t[e]=n.children[e].offsetWidth+1}return this.props.columns.forEach(function(e,t){o.children[t].style.width=V(e.width||"")}),i(),this.props.columns.forEach(function(e,r){var n=e.width,i=e.minWidth,l=e.maxWidth;(l||i)&&(n=t[r],n=Math.min(l||n,n),o.children[r].style.width=V(n=Math.max(i||n,n)))}),i(),e.querySelectorAll("tbody > tr").forEach(function(e,t){r[t]=e.offsetHeight}),{columnWs:t,rowHs:r}},r.prototype.alignTable=function(){var e=this,t=this.refs,r=t.headerLeft,n=t.headerRight,o=t.body,i=this.props.columns,l=[r,n].filter(function(e){return!!e});l.forEach(function(e){G(e.querySelector("tr"),"")});var a,s,d=this.getTableWidthHeight(),c=d.columnWs,u=d.rowHs,f=this.refs.virtualTable.querySelector("thead > tr").clientHeight,h=this.table.clientHeight,p=this.refs.hScrollPanel.offsetHeight,m=this.refs.bodyMiddle.querySelector("colgroup"),b=this.refs.headerMiddle.querySelector("colgroup"),y=0,w=0;c.forEach(function(t,o){var l=V(t);y+=t,m.children[o].style.width=l,b.children[o].style.width=l,i[o].width||("left"===i[o].fixed?(r.querySelector("colgroup").children[o].style.width=l,e.refs.bodyLeft.querySelector("colgroup").children[o].style.width=l):"right"===i[o].fixed&&(n.querySelector("colgroup").children[w].style.width=l,e.refs.bodyRight.querySelector("colgroup").children[w].style.width=l,w++))}),a=this.refs.header,s=V(y=Math.max(y,this.refs.scrollX.clientWidth)),a.style.width=s,o.style.width=V(this.refs.header.clientWidth+300+o.offsetWidth-o.clientWidth);var v=this.refs.header.offsetHeight;l.forEach(function(e){G(e.querySelector("tr"),V(f)),G(e.parentElement,V(v))}),this.bodies().forEach(function(e){!function(e,t){for(var r=0;e.children.length>r;r++)t(e.children[r],r)}(e,function(e,t){return G(e,V(u[t]))})}),this.refs.body.style.height=V(h-v-p)},r.prototype.scrollByOffset=function(e,t){if(this.table){var r=this.refs,n=r.bodyMiddle,o=r.hScrollBar,i=r.hScrollPanel,l=r.vScrollBar,a=r.vScrollPanel;if(n){var s=this.refs.scrollX.offsetWidth,d=this.refs.body.clientHeight,c=n.offsetWidth,u=n.offsetHeight,f=1,h=1;if(u>d||(a.style.visibility="hidden",l=null,a=null),c>s||(i.style.visibility="hidden",o=null,i=null),o){var p=i.offsetWidth,m=p*s/c;f=(c-s)/(p-m)}if(l){var b=a.offsetHeight,y=b*d/u;h=(u-d)/(b-y)}t*=h;var w=Math.round(this.refs.scrollX.scrollLeft+(e*=f)),v=Math.round(this.refs.body.scrollTop+t),_=!0;if(w>c-s&&(w=c-s,_=!1),0>w&&(w=0,_=!1),v>u-d&&(v=u-d,_=!1),0>v&&(v=0,_=!1),this.refs.body.scrollTop=v,this.refs.scrollX.scrollLeft=w,o)i.style.visibility="visible",o.style.width=Math.round(m)+"px",o.style.transform="translateX("+Math.round(w/f)+"px)";if(x(this.refs.bodyLeft,w),x(this.refs.bodyRight,w-c+s),l){var g=Math.round(v/h);a.style.visibility="visible",l.style.height=Math.round(y)+"px",l.style.transform="translateY("+g+"px)"}return{hasOffset:_}}}function x(e,t){e&&(0===t&&e?e.parentElement.parentElement.style.display="none":(e.parentElement.parentElement.style.display="block",e.style.transform="translateY("+-v+"px)"))}},r.prototype.renderHeaderSideOf=function(t){var r=t.side,n=X(t,["side"]),o=r.toLowerCase(),i=n[o+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"header"+r},e.createElement("colgroup",null,i.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:l+"-row "+l+"-row--header"},i.map(function(t,r){return e.createElement("td",{key:t.dataIndex||r,className:l+"-cell "+l+"-cell--header",style:t.headerStyle},U(t.header,n.data,t))}))))},r.prototype.renderBodySideOf=function(t){var r=this,n=t.side,o=t.data,i=X(t,["side","data"])[n.toLowerCase()+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"body"+n},e.createElement("colgroup",null,i.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("tbody",{ref:"body"+n+"Content"},o.map(function(t,n){return e.createElement("tr",{key:n,className:l+"-row "+l+"-row--body",onMouseEnter:function(){return r.handleRowEnter(n)},onMouseLeave:function(){return r.handleRowLeave(n)},onClick:function(){return r.handleClickRow(t,n)}},i.map(function(r,n){return e.createElement("td",{key:n,style:r.cellStyle,className:l+"-cell "+l+"-cell--body "+(r.cellClassName||"")},U(r.cell,t,o,r))}))})))},r.prototype.renderVirtualTable=function(t){var r=t.data,n=t.columns,o=this.props.prefixCls;return e.createElement("table",{className:o+"-hidden-layout",ref:"virtualTable"},e.createElement("colgroup",null,n.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:o+"-row "+o+"-row--header"},n.map(function(r,n){return e.createElement("td",{key:r.dataIndex||n,className:o+"-cell "+o+"-cell--header",style:r.headerStyle},U(r.header,t.data,r))}))),e.createElement("tbody",{ref:"virtualTableBody"},r.map(function(t,i){return e.createElement("tr",{key:i,className:o+"-row "+o+"-row--body"},n.map(function(n,i){return e.createElement("td",{key:i,style:n.cellStyle,className:o+"-cell "+o+"-cell--body "+(n.cellClassName||"")},U(n.cell,t,r,n))}))})))},r.prototype.render=function(){var t=this,r=this.props,n=r.data,o=r.columns,i=r.prefixCls,l=r.style,a=r.className,s=o.slice(),d=o.filter(function(e){return"left"===e.fixed}),c=o.filter(function(e){return"right"===e.fixed}),u=function(e){return{side:e,columns:o,leftColumns:d,rightColumns:c,middleColumns:s,data:n}};return e.createElement("div",{className:i+" "+(a||""),key:"rb-table",ref:this.setTableRef,onWheel:this.handleScroll,style:l},e.createElement("div",{ref:"scrollX",className:i+"-scrollx",onScroll:function(){return t.scrollByOffset(0,0)}},e.createElement("div",{className:i+"__header",ref:"header"},this.renderHeaderSideOf(u("Middle"))),e.createElement("div",{className:i+"__body",ref:"body",onScroll:function(){return t.scrollByOffset(0,0)}},this.renderBodySideOf(u("Middle")),this.renderVirtualTable(u("virtual")))),d.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--left"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Left"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Left")))),c.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--right"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Right"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Right")))),e.createElement("div",{className:i+"__vscroll",ref:"vScrollPanel",onMouseDown:this.vScrollPanelMouseDown},e.createElement("div",{ref:"vScrollBar",onMouseDown:this.vScrollBarMouseDown,className:i+"__vscroll__bar"})),e.createElement("div",{className:i+"__hscroll",ref:"hScrollPanel",onMouseDown:this.hScrollPanelMouseDown},e.createElement("div",{ref:"hScrollBar",onMouseDown:this.hScrollBarMouseDown,className:i+"__hscroll__bar"})),this.props.children)},r}(e.Component);Z.propTypes={columns:x.arrayOf(x.shape({header:x.oneOfType([x.string,x.number,x.func,x.element]).isRequired,cell:x.oneOfType([x.string,x.number,x.func,x.element]).isRequired,width:x.number,minWidth:K,maxWidth:K,fixed:x.oneOf(["left","right"]),className:x.string,onRowClick:x.func})),data:x.array.isRequired,prefixCls:x.string.isRequired},Z.defaultProps={prefixCls:"rb-table",data:[]};return function(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".rb-table{overflow:hidden;position:relative;padding:0 15px 15px 0;background:#fff;color:#333}.rb-table table{width:100%;border-spacing:0;font-size:12px;table-layout:fixed;border:none;word-break:break-all}.rb-table-scrollx{position:relative;overflow-x:scroll;overflow-y:hidden;padding-bottom:99999px}.rb-table__body{overflow:scroll;overflow-x:hidden;box-sizing:border-box;padding-right:300px}.rb-table__body .rb-table-hidden-layout{position:fixed;visibility:hidden;top:1000000px;width:-webkit-max-content;width:-moz-max-content;width:max-content;table-layout:auto}.rb-table-fixed{overflow:hidden;position:absolute;top:0;background:#fff}.rb-table-fixed table{width:auto}.rb-table-fixed__body{overflow:hidden}.rb-table-fixed--left{left:0;border-right:1px solid #f0f0f0}.rb-table-fixed--right{right:15px;border-left:1px solid #f0f0f0}.rb-table-row--hover{background-color:#fff}.rb-table-row--clickable{cursor:pointer}.rb-table-cell{padding:14px 10px;border-bottom:1px solid #f0f0f0;font-size:12px}.rb-table__hscroll{visibility:hidden;position:absolute;left:0;bottom:0;right:12px;padding:1px 0;background:#eee;height:10px;z-index:1}.rb-table__hscroll__bar{background:#777;border-radius:10px;height:100%}.rb-table__vscroll{visibility:hidden;position:absolute;background:#eee;top:0;bottom:0;right:2px;padding:0 1px;width:10px;z-index:1}.rb-table__vscroll__bar{background:#777;border-radius:10px;width:100%}"),Z}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.RBTable=t(e.React)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;10>r;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}();var o="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function i(){}var l,a,s,d,c,f,u,h,p,b,m,y,w,v,_,g,x=(function(e){e.exports=function(){function e(e,t,r,n,i,l){if(l!==o){var a=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=i,r.PropTypes=r,r}()}(l={exports:{}},l.exports),l.exports),E=!1;function S(){if(!E){E=!0;var e=navigator.userAgent,t=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(e),r=/(Mac OS X)|(Windows)|(Linux)/.exec(e);if(w=/\b(iPhone|iP[ao]d)/.exec(e),v=/\b(iP[ao]d)/.exec(e),m=/Android/i.exec(e),_=/FBAN\/\w+;/i.exec(e),g=/Mobile/i.exec(e),y=!!/Win64/.exec(e),t){(a=t[1]?parseFloat(t[1]):t[5]?parseFloat(t[5]):NaN)&&document&&document.documentMode&&(a=document.documentMode);var n=/(?:Trident\/(\d+.\d+))/.exec(e);u=n?parseFloat(n[1])+4:a,s=t[2]?parseFloat(t[2]):NaN,d=t[3]?parseFloat(t[3]):NaN,(c=t[4]?parseFloat(t[4]):NaN)?(t=/(?:Chrome\/(\d+\.\d+))/.exec(e),f=t&&t[1]?parseFloat(t[1]):NaN):f=NaN}else a=s=d=f=c=NaN;if(r){if(r[1]){var o=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(e);h=!o||parseFloat(o[1].replace("_","."))}else h=!1;p=!!r[2],b=!!r[3]}else h=p=b=!1}}var M,O={ie:function(){return S()||a},ieCompatibilityMode:function(){return S()||u>a},ie64:function(){return O.ie()&&y},firefox:function(){return S()||s},opera:function(){return S()||d},webkit:function(){return S()||c},safari:function(){return O.webkit()},chrome:function(){return S()||f},windows:function(){return S()||p},osx:function(){return S()||h},linux:function(){return S()||b},iphone:function(){return S()||w},mobile:function(){return S()||w||v||m||g},nativeApp:function(){return S()||_},android:function(){return S()||m},ipad:function(){return S()||v}},C=O,N=!("undefined"==typeof window||!window.document||!window.document.createElement),R={canUseDOM:N,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:N&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:N&&!!window.screen,isInWorker:!N};R.canUseDOM&&(M=document.implementation&&document.implementation.hasFeature&&!0!==document.implementation.hasFeature("",""));var k=function(e,t){if(!R.canUseDOM||t&&!("addEventListener"in document))return!1;var r="on"+e,n=r in document;if(!n){var o=document.createElement("div");o.setAttribute(r,"return;"),n="function"==typeof o[r]}return!n&&M&&"wheel"===e&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n},D=10,T=40,z=800;function W(e){var t=0,r=0,n=0,o=0;return"detail"in e&&(r=e.detail),"wheelDelta"in e&&(r=-e.wheelDelta/120),"wheelDeltaY"in e&&(r=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=r,r=0),n=t*D,o=r*D,"deltaY"in e&&(o=e.deltaY),"deltaX"in e&&(n=e.deltaX),(n||o)&&e.deltaMode&&(1==e.deltaMode?(n*=T,o*=T):(n*=z,o*=z)),n&&!t&&(t=1>n?-1:1),o&&!r&&(r=1>o?-1:1),{spinX:t,spinY:r,pixelX:n,pixelY:o}}W.getEventType=function(){return C.firefox()?"DOMMouseScroll":k("wheel")?"wheel":"mousewheel"};var B,L,P=W,q=navigator.userAgent.match(/Trident/),A=(B=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,20)},function(e){return B(e)}),F=(L=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.clearTimeout,function(e){return L(e)});function j(e){var t=e.target||e.srcElement;t.__resizeRAF__&&F(t.__resizeRAF__),t.__resizeRAF__=A(function(){var r=t.__resizeTrigger__;r.__resizeListeners__.forEach(function(t){t.call(r,e)})})}function H(){this.contentDocument.defaultView.__resizeTrigger__=this.__resizeElement__,this.contentDocument.defaultView.addEventListener("resize",j)}function X(e,t){if(!e.__resizeListeners__){e.__resizeListeners__=[];var r=e.__resizeTrigger__=document.createElement("object");r.setAttribute("style","display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"),r.__resizeElement__=e,r.onload=H,r.type="text/html",q&&e.appendChild(r),r.data="about:blank",q||e.appendChild(r)}e.__resizeListeners__.push(t)}function I(e,t){var r={};for(var n in e)0>t.indexOf(n)&&Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function U(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;r>o;o++)n[o-1]=arguments[o];if(t)return"string"==typeof t||"number"==typeof t?t:"function"==typeof t?t.apply(void 0,n):e.isValidElement(t)?e.cloneElement(t,{tableContext:n}):void 0}function Y(e){return e.width?{width:e.width}:null}function V(e){return e?e+"px":e}function G(e,t){e.style.height=t}function K(e,t,r){return e.width&&e[t]?Error(r+".column."+t+" will not take effect when column.width is set."):"maxWidth"===t&&e.minWidth>e.maxWidth?Error(r+".column.maxWidth is smaller then column.minWidth"):void 0}var Z=function(t){function r(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,t.call(this,e));return n.setTableRef=n.setTableRef.bind(n),n.handleResize=n.handleResize.bind(n),n.handleScroll=n.handleScroll.bind(n),n.handleClickRow=n.handleClickRow.bind(n),n.handleWindowMouseUp=n.handleWindowMouseUp.bind(n),n.handleWindowMouseMove=n.handleWindowMouseMove.bind(n),n.hScrollPanelMouseDown=n.hScrollPanelMouseDown.bind(n),n.vScrollPanelMouseDown=n.vScrollPanelMouseDown.bind(n),n.hScrollBarMouseDown=n.hScrollBarMouseDown.bind(n),n.vScrollBarMouseDown=n.vScrollBarMouseDown.bind(n),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(r,t),r.prototype.componentWillUnmount=function(){X(this.table,this.handleResize),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("mousemove",this.handleWindowMouseMove)},r.prototype.componentDidMount=function(){var e=this;window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("mousemove",this.handleWindowMouseMove),setTimeout(function(){e.reflow()})},r.prototype.setTableRef=function(e){var t,r;e&&(this.table&&(r=this.handleResize,(t=this.table).__resizeListeners__&&(t.__resizeListeners__.splice(t.__resizeListeners__.indexOf(r),1),t.__resizeListeners__.length||(t.__resizeTrigger__.contentDocument.defaultView.removeEventListener("resize",j),t.__resizeTrigger__=!t.removeChild(t.__resizeTrigger__)))),this.table=e,X(e,this.handleResize))},r.prototype.componentDidUpdate=function(){this.reflow()},r.prototype.handleResize=function(){this.reflow()},r.prototype.reflow=function(){this.alignTable(),this.scrollByOffset(0,0)},r.prototype.handleScroll=function(e){if(!this.autoSize){var t=P(e),r=t.pixelY,n=t.pixelX;r=Math.round(.5*r),this.scrollByOffset(n=Math.round(.5*n),r).hasOffset&&(e.preventDefault(),e.stopPropagation())}},r.prototype.handleClickRow=function(e,t){this.props.onRowClick&&this.props.onRowClick(e,t)},r.prototype.setLocation=function(e,t){this.x=e,this.y=t},r.prototype.handleWindowMouseUp=function(){this.mouseIsDownRight=!1,this.mouseIsDownBottom=!1},r.prototype.handleWindowMouseMove=function(e){var t=e.clientY;this.mouseIsDownBottom?this.handleMouseMove(e.clientX,0):this.mouseIsDownRight&&this.handleMouseMove(0,t)},r.prototype.hScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientX-this.refs.hScrollBar.getBoundingClientRect().left;this.scrollByOffset(t,0)},r.prototype.vScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientY-this.refs.vScrollBar.getBoundingClientRect().top;this.scrollByOffset(0,t)},r.prototype.hScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownBottom=!0,this.setLocation(e)},r.prototype.vScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownRight=!0,this.setLocation(e)},r.prototype.handleMouseMove=function(e,t){var r=e-this.x,n=t-this.y;this.setLocation(e,t),this.scrollByOffset(r,n)},r.prototype.getHoverClass=function(){var e=this.props.prefixCls,t=" "+e+"-row--hover";return this.props.onRowClick&&(t+=e+"-row--clickable"),t},r.prototype.bodies=function(){var e=this.refs;return[e.bodyMiddleContent,e.bodyLeftContent,e.bodyRightContent].filter(function(e){return!!e})},r.prototype.handleRowEnter=function(e){var t=this;this.bodies().forEach(function(r){return r.children[e].className+=t.getHoverClass()})},r.prototype.handleRowLeave=function(e){var t=this;this.bodies().forEach(function(r){return r.children[e].className=r.children[e].className.replace(t.getHoverClass(),"")})},r.prototype.getTableWidthHeight=function(){var e=this.refs.virtualTable,t=[],r=[],n=e.querySelector("thead > tr"),o=e.querySelector("colgroup");function i(){for(var e=0;n.children.length>e;e++)t[e]=n.children[e].offsetWidth+1}return this.props.columns.forEach(function(e,t){o.children[t].style.width=V(e.width||"")}),i(),this.props.columns.forEach(function(e,r){var n=e.width,i=e.minWidth,l=e.maxWidth;(l||i)&&(n=t[r],n=Math.min(l||n,n),o.children[r].style.width=V(n=Math.max(i||n,n)))}),i(),e.querySelectorAll("tbody > tr").forEach(function(e,t){r[t]=e.offsetHeight}),{columnWs:t,rowHs:r}},r.prototype.alignTable=function(){var e=this,t=this.refs,r=t.headerLeft,n=t.headerRight,o=t.body,i=this.props,l=i.columns,a=i.prefixCls,s=[r,n].filter(function(e){return!!e});s.forEach(function(e){G(e.querySelector("tr"),"")});var d,c,f=this.getTableWidthHeight(),u=f.columnWs,h=f.rowHs,p=this.refs.virtualTable.querySelector("thead > tr").clientHeight,b=this.table.clientHeight,m=this.refs.hScrollPanel.offsetHeight,y=this.refs.bodyMiddle.querySelector("colgroup"),w=this.refs.headerMiddle.querySelector("colgroup"),v=0,_=0;u.forEach(function(t,o){var i=V(t);v+=t,y.children[o].style.width=i,w.children[o].style.width=i,l[o].width||("left"===l[o].fixed?(r.querySelector("colgroup").children[o].style.width=i,e.refs.bodyLeft.querySelector("colgroup").children[o].style.width=i):"right"===l[o].fixed&&(n.querySelector("colgroup").children[_].style.width=i,e.refs.bodyRight.querySelector("colgroup").children[_].style.width=i,_++))}),d=this.refs.header,c=V(v=Math.max(v,this.refs.scrollX.clientWidth)),d.style.width=c,o.style.width=V(this.refs.header.clientWidth+(this.autoSize?0:300+o.offsetWidth-o.clientWidth));var g=this.refs.header.offsetHeight;(s.forEach(function(e){G(e.querySelector("tr"),V(p)),G(e.parentElement,V(g))}),this.bodies().forEach(function(e){!function(e,t){for(var r=0;e.children.length>r;r++)t(e.children[r],r)}(e,function(e,t){return G(e,V(h[t]))})}),b>99999||this.autoSize)?(this.autoSize=!0,o.style.width=V(this.refs.header.clientWidth),this.refs.scrollX.style.paddingBottom=0,this.refs.scrollX.style.overflowX="auto",this.refs.body.style.paddingRight=0,this.refs.body.style.overflowY="hidden",this.table.querySelector("."+a+"-fixed--right").style.right=0,this.table.style.height=V(this.refs.scrollX.offsetHeight)):this.refs.body.style.height=V(b-g-m)},r.prototype.scrollByOffset=function(e,t){var r=this.refs,n=r.bodyMiddle,o=r.hScrollBar,i=r.hScrollPanel,l=r.vScrollBar,a=r.vScrollPanel;if(!this.table||this.autoSize)return i.style.visibility="hidden",void(a.style.visibility="hidden");if(n){var s=this.refs.scrollX.offsetWidth,d=this.refs.body.clientHeight,c=n.offsetWidth,f=n.offsetHeight,u=1,h=1;if(f>d||(a.style.visibility="hidden",l=null,a=null),c>s||(i.style.visibility="hidden",o=null,i=null),o){var p=i.offsetWidth,b=p*s/c;u=(c-s)/(p-b)}if(l){var m=a.offsetHeight,y=m*d/f;h=(f-d)/(m-y)}t*=h;var w=Math.round(this.refs.scrollX.scrollLeft+(e*=u)),v=Math.round(this.refs.body.scrollTop+t),_=!0;if(w>c-s&&(w=c-s,_=!1),0>w&&(w=0,_=!1),v>f-d&&(v=f-d,_=!1),0>v&&(v=0,_=!1),this.refs.body.scrollTop=v,this.refs.scrollX.scrollLeft=w,o)i.style.visibility="visible",o.style.width=Math.round(b)+"px",o.style.transform="translateX("+Math.round(w/u)+"px)";if(x(this.refs.bodyLeft,w),x(this.refs.bodyRight,w-c+s),l){var g=Math.round(v/h);a.style.visibility="visible",l.style.height=Math.round(y)+"px",l.style.transform="translateY("+g+"px)"}return{hasOffset:_}}function x(e,t){e&&(0===t&&e?e.parentElement.parentElement.style.display="none":(e.parentElement.parentElement.style.display="block",e.style.transform="translateY("+-v+"px)"))}},r.prototype.renderHeaderSideOf=function(t){var r=t.side,n=I(t,["side"]),o=r.toLowerCase(),i=n[o+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"header"+r},e.createElement("colgroup",null,i.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:l+"-row "+l+"-row--header"},i.map(function(t,r){return e.createElement("td",{key:t.dataIndex||r,className:l+"-cell "+l+"-cell--header "+(t.headerClassName||""),style:t.headerStyle},U(t.header,n.data,t))}))))},r.prototype.renderBodySideOf=function(t){var r=this,n=t.side,o=t.data,i=I(t,["side","data"])[n.toLowerCase()+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"body"+n},e.createElement("colgroup",null,i.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("tbody",{ref:"body"+n+"Content"},o.map(function(t,n){return e.createElement("tr",{key:n,className:l+"-row "+l+"-row--body",onMouseEnter:function(){return r.handleRowEnter(n)},onMouseLeave:function(){return r.handleRowLeave(n)},onClick:function(){return r.handleClickRow(t,n)}},i.map(function(r,n){return e.createElement("td",{key:n,style:r.cellStyle,className:l+"-cell "+l+"-cell--body "+(r.cellClassName||"")},U(r.cell,t,o,r))}))})))},r.prototype.renderVirtualTable=function(t){var r=t.data,n=t.columns,o=this.props.prefixCls;return e.createElement("table",{className:o+"-hidden-layout",ref:"virtualTable"},e.createElement("colgroup",null,n.map(function(t,r){return e.createElement("col",{key:r,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:o+"-row "+o+"-row--header"},n.map(function(r,n){return e.createElement("td",{key:r.dataIndex||n,className:o+"-cell "+o+"-cell--header",style:r.headerStyle},U(r.header,t.data,r))}))),e.createElement("tbody",{ref:"virtualTableBody"},r.map(function(t,i){return e.createElement("tr",{key:i,className:o+"-row "+o+"-row--body"},n.map(function(n,i){return e.createElement("td",{key:i,style:n.cellStyle,className:o+"-cell "+o+"-cell--body "+(n.cellClassName||"")},U(n.cell,t,r,n))}))})))},r.prototype.render=function(){var t=this,r=this.props,n=r.data,o=r.columns,i=r.prefixCls,l=r.style,a=r.className,s=o.slice(),d=o.filter(function(e){return"left"===e.fixed}),c=o.filter(function(e){return"right"===e.fixed}),f=function(e){return{side:e,columns:o,leftColumns:d,rightColumns:c,middleColumns:s,data:n}};return e.createElement("div",{className:i+" "+(a||""),key:"rb-table",ref:this.setTableRef,onWheel:this.handleScroll,style:l},e.createElement("div",{ref:"scrollX",className:i+"-scrollx",onScroll:function(){return t.scrollByOffset(0,0)}},e.createElement("div",{className:i+"__header",ref:"header"},this.renderHeaderSideOf(f("Middle"))),e.createElement("div",{className:i+"__body",ref:"body",onScroll:function(){return t.scrollByOffset(0,0)}},this.renderBodySideOf(f("Middle")),this.renderVirtualTable(f("virtual")))),d.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--left"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(f("Left"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(f("Left")))),c.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--right"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(f("Right"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(f("Right")))),e.createElement("div",{className:i+"__vscroll",ref:"vScrollPanel",onMouseDown:this.vScrollPanelMouseDown},e.createElement("div",{ref:"vScrollBar",onMouseDown:this.vScrollBarMouseDown,className:i+"__vscroll__bar"})),e.createElement("div",{className:i+"__hscroll",ref:"hScrollPanel",onMouseDown:this.hScrollPanelMouseDown},e.createElement("div",{ref:"hScrollBar",onMouseDown:this.hScrollBarMouseDown,className:i+"__hscroll__bar"})),this.props.children)},r}(e.Component);Z.propTypes={columns:x.arrayOf(x.shape({header:x.oneOfType([x.string,x.number,x.func,x.element]).isRequired,cell:x.oneOfType([x.string,x.number,x.func,x.element]).isRequired,width:x.number,minWidth:K,maxWidth:K,fixed:x.oneOf(["left","right"]),headerClassName:x.string,cellClassName:x.string,headerStyle:x.obj,cellStyle:x.obj})),data:x.array.isRequired,prefixCls:x.string.isRequired,onRowClick:x.func},Z.defaultProps={prefixCls:"rb-table",data:[]};return function(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".rb-table{overflow:hidden;position:relative;background:#fff;color:#333}.rb-table table{width:100%;border-spacing:0;font-size:12px;table-layout:fixed;border:none;word-break:break-all}.rb-table-scrollx{position:relative;overflow-x:scroll;overflow-y:hidden;padding-bottom:99999px}.rb-table__body{overflow:scroll;overflow-x:hidden;box-sizing:border-box;padding-right:300px}.rb-table__body .rb-table-hidden-layout{position:fixed;visibility:hidden;top:1000000px;width:-webkit-max-content;width:-moz-max-content;width:max-content;table-layout:auto}.rb-table-fixed{overflow:hidden;position:absolute;top:0;background:#fff}.rb-table-fixed table{width:auto}.rb-table-fixed__body{overflow:hidden}.rb-table-fixed--left{left:0;border-right:1px solid #e8e8e8}.rb-table-fixed--right{right:0;border-left:1px solid #e8e8e8}.rb-table-row--hover{background-color:#fff}.rb-table-row--clickable{cursor:pointer}.rb-table-cell{padding:14px 10px;border-bottom:1px solid #e8e8e8;font-size:12px}.rb-table__hscroll{visibility:hidden;position:absolute;left:0;bottom:0;right:12px;padding:2px 0;background:#f9f9f9;height:12px;z-index:1}.rb-table__hscroll__bar{background:#bfbfbf;border-radius:12px;height:100%}.rb-table__hscroll__bar:hover{background:#7f7f7f}.rb-table__vscroll{visibility:hidden;position:absolute;background:#f9f9f9;top:0;bottom:0;right:0;padding:0 2px;width:12px;z-index:1}.rb-table__vscroll__bar{background:#bfbfbf;border-radius:12px;width:100%}.rb-table__vscroll__bar:hover{background:#7f7f7f}.rb-table-fixed--left .rb-table-cell:first-child,.rb-table-scrollx .rb-table-cell:first-child{padding-left:30px}.rb-table-fixed--right .rb-table-cell:last-child,.rb-table-scrollx .rb-table-cell:last-child{padding-right:30px}"),Z}); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.RBTable=t(e.React)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;10>n;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}();var o="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function i(){}var l,s,a,c,d,u,f,h,p,m,y,w,v,b,_,g,E=(function(e){e.exports=function(){function e(e,t,n,r,i,l){if(l!==o){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=i,n.PropTypes=n,n}()}(l={exports:{}},l.exports),l.exports),M=!1;function x(){if(!M){M=!0;var e=navigator.userAgent,t=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(e),n=/(Mac OS X)|(Windows)|(Linux)/.exec(e);if(v=/\b(iPhone|iP[ao]d)/.exec(e),b=/\b(iP[ao]d)/.exec(e),y=/Android/i.exec(e),_=/FBAN\/\w+;/i.exec(e),g=/Mobile/i.exec(e),w=!!/Win64/.exec(e),t){(s=t[1]?parseFloat(t[1]):t[5]?parseFloat(t[5]):NaN)&&document&&document.documentMode&&(s=document.documentMode);var r=/(?:Trident\/(\d+.\d+))/.exec(e);f=r?parseFloat(r[1])+4:s,a=t[2]?parseFloat(t[2]):NaN,c=t[3]?parseFloat(t[3]):NaN,(d=t[4]?parseFloat(t[4]):NaN)?(t=/(?:Chrome\/(\d+\.\d+))/.exec(e),u=t&&t[1]?parseFloat(t[1]):NaN):u=NaN}else s=a=c=u=d=NaN;if(n){if(n[1]){var o=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(e);h=!o||parseFloat(o[1].replace("_","."))}else h=!1;p=!!n[2],m=!!n[3]}else h=p=m=!1}}var S,O={ie:function(){return x()||s},ieCompatibilityMode:function(){return x()||f>s},ie64:function(){return O.ie()&&w},firefox:function(){return x()||a},opera:function(){return x()||c},webkit:function(){return x()||d},safari:function(){return O.webkit()},chrome:function(){return x()||u},windows:function(){return x()||p},osx:function(){return x()||h},linux:function(){return x()||m},iphone:function(){return x()||v},mobile:function(){return x()||v||b||y||g},nativeApp:function(){return x()||_},android:function(){return x()||y},ipad:function(){return x()||b}},R=O,N=!("undefined"==typeof window||!window.document||!window.document.createElement),C={canUseDOM:N,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:N&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:N&&!!window.screen,isInWorker:!N};C.canUseDOM&&(S=document.implementation&&document.implementation.hasFeature&&!0!==document.implementation.hasFeature("",""));var D=function(e,t){if(!C.canUseDOM||t&&!("addEventListener"in document))return!1;var n="on"+e,r=n in document;if(!r){var o=document.createElement("div");o.setAttribute(n,"return;"),r="function"==typeof o[n]}return!r&&S&&"wheel"===e&&(r=document.implementation.hasFeature("Events.wheel","3.0")),r},T=10,W=40,L=800;function k(e){var t=0,n=0,r=0,o=0;return"detail"in e&&(n=e.detail),"wheelDelta"in e&&(n=-e.wheelDelta/120),"wheelDeltaY"in e&&(n=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=n,n=0),r=t*T,o=n*T,"deltaY"in e&&(o=e.deltaY),"deltaX"in e&&(r=e.deltaX),(r||o)&&e.deltaMode&&(1==e.deltaMode?(r*=W,o*=W):(r*=L,o*=L)),r&&!t&&(t=1>r?-1:1),o&&!n&&(n=1>o?-1:1),{spinX:t,spinY:n,pixelX:r,pixelY:o}}k.getEventType=function(){return R.firefox()?"DOMMouseScroll":D("wheel")?"wheel":"mousewheel"};var B,P,z=k,F=navigator.userAgent.match(/Trident/),q=(B=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,20)},function(e){return B(e)}),A=(P=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.clearTimeout,function(e){return P(e)});function H(e){var t=e.target||e.srcElement;t.__resizeRAF__&&A(t.__resizeRAF__),t.__resizeRAF__=q(function(){var n=t.__resizeTrigger__;n.__resizeListeners__.forEach(function(t){t.call(n,e)})})}function j(){this.contentDocument.defaultView.__resizeTrigger__=this.__resizeElement__,this.contentDocument.defaultView.addEventListener("resize",H)}function I(e,t){if(!e.__resizeListeners__){e.__resizeListeners__=[];var n=e.__resizeTrigger__=document.createElement("object");n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"),n.__resizeElement__=e,n.onload=j,n.type="text/html",F&&e.appendChild(n),n.data="about:blank",F||e.appendChild(n)}e.__resizeListeners__.push(t)}function X(e,t){var n={};for(var r in e)0>t.indexOf(r)&&Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function U(t){for(var n=arguments.length,r=Array(n>1?n-1:0),o=1;n>o;o++)r[o-1]=arguments[o];if(t)return"string"==typeof t||"number"==typeof t?t:"function"==typeof t?t.apply(void 0,r):e.isValidElement(t)?e.cloneElement(t,{tableContext:r}):void 0}function Y(e){return e.width?{width:e.width}:null}function V(e){return e?e+"px":e}function G(e,t){e.style.height=t}function K(e,t,n){return e.width&&e[t]?Error(n+".column."+t+" will not take effect when column.width is set."):"maxWidth"===t&&e.minWidth>e.maxWidth?Error(n+".column.maxWidth is smaller then column.minWidth"):void 0}var Z=function(t){function n(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,t.call(this,e));return r.setTableRef=r.setTableRef.bind(r),r.handleResize=r.handleResize.bind(r),r.handleScroll=r.handleScroll.bind(r),r.handleClickRow=r.handleClickRow.bind(r),r.handleWindowMouseUp=r.handleWindowMouseUp.bind(r),r.handleWindowMouseMove=r.handleWindowMouseMove.bind(r),r.hScrollPanelMouseDown=r.hScrollPanelMouseDown.bind(r),r.vScrollPanelMouseDown=r.vScrollPanelMouseDown.bind(r),r.hScrollBarMouseDown=r.hScrollBarMouseDown.bind(r),r.vScrollBarMouseDown=r.vScrollBarMouseDown.bind(r),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,t),n.prototype.componentWillUnmount=function(){I(this.table,this.handleResize),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("mousemove",this.handleWindowMouseMove)},n.prototype.componentDidMount=function(){var e=this;window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("mousemove",this.handleWindowMouseMove),setTimeout(function(){e.reflow()})},n.prototype.setTableRef=function(e){var t,n;e&&(this.table&&(n=this.handleResize,(t=this.table).__resizeListeners__&&(t.__resizeListeners__.splice(t.__resizeListeners__.indexOf(n),1),t.__resizeListeners__.length||(t.__resizeTrigger__.contentDocument.defaultView.removeEventListener("resize",H),t.__resizeTrigger__=!t.removeChild(t.__resizeTrigger__)))),this.table=e,I(e,this.handleResize))},n.prototype.componentDidUpdate=function(){this.reflow()},n.prototype.handleResize=function(){this.reflow()},n.prototype.reflow=function(){this.alignTable(),this.scrollByOffset(0,0)},n.prototype.handleScroll=function(e){var t=z(e),n=t.pixelY,r=t.pixelX;n=Math.round(.5*n);var o=this.scrollByOffset(r=Math.round(.5*r),n).hasOffset;e.preventDefault(),o&&e.stopPropagation()},n.prototype.handleClickRow=function(e,t){this.props.onRowClick&&this.props.onRowClick(e,t)},n.prototype.setLocation=function(e,t){this.x=e,this.y=t},n.prototype.handleWindowMouseUp=function(){this.mouseIsDownRight=!1,this.mouseIsDownBottom=!1},n.prototype.handleWindowMouseMove=function(e){var t=e.clientY;this.mouseIsDownBottom?this.handleMouseMove(e.clientX,0):this.mouseIsDownRight&&this.handleMouseMove(0,t)},n.prototype.hScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientX-this.refs.hScrollBar.getBoundingClientRect().left;this.scrollByOffset(t,0)},n.prototype.vScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientY-this.refs.vScrollBar.getBoundingClientRect().top;this.scrollByOffset(0,t)},n.prototype.hScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownBottom=!0,this.setLocation(e)},n.prototype.vScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownRight=!0,this.setLocation(e)},n.prototype.handleMouseMove=function(e,t){var n=e-this.x,r=t-this.y;this.setLocation(e,t),this.scrollByOffset(n,r)},n.prototype.getHoverClass=function(){var e=this.props.prefixCls,t=" "+e+"-row--hover";return this.props.onRowClick&&(t+=e+"-row--clickable"),t},n.prototype.bodies=function(){var e=this.refs;return[e.bodyMiddleContent,e.bodyLeftContent,e.bodyRightContent].filter(function(e){return!!e})},n.prototype.handleRowEnter=function(e){var t=this;this.bodies().forEach(function(n){return n.children[e].className+=t.getHoverClass()})},n.prototype.handleRowLeave=function(e){var t=this;this.bodies().forEach(function(n){return n.children[e].className=n.children[e].className.replace(t.getHoverClass(),"")})},n.prototype.getTableWidthHeight=function(){var e=this.refs.virtualTable,t=[],n=[],r=e.querySelector("thead > tr"),o=e.querySelector("colgroup");function i(){for(var e=0;r.children.length>e;e++)t[e]=r.children[e].offsetWidth+1}return this.props.columns.forEach(function(e,t){o.children[t].style.width=V(e.width||"")}),i(),this.props.columns.forEach(function(e,n){var r=e.width,i=e.minWidth,l=e.maxWidth;(l||i)&&(r=t[n],r=Math.min(l||r,r),o.children[n].style.width=V(r=Math.max(i||r,r)))}),i(),e.querySelectorAll("tbody > tr").forEach(function(e,t){n[t]=e.offsetHeight}),{columnWs:t,rowHs:n}},n.prototype.alignTable=function(){var e=this,t=this.refs,n=t.headerLeft,r=t.headerRight,o=t.body,i=this.props.columns,l=[n,r].filter(function(e){return!!e});l.forEach(function(e){G(e.querySelector("tr"),"")});var s,a,c=this.getTableWidthHeight(),d=c.columnWs,u=c.rowHs,f=this.refs.virtualTable.querySelector("thead > tr").clientHeight,h=this.table.clientHeight,p=this.refs.hScrollPanel.offsetHeight,m=this.refs.bodyMiddle.querySelector("colgroup"),y=this.refs.headerMiddle.querySelector("colgroup"),w=0,v=0;d.forEach(function(t,o){var l=V(t);w+=t,m.children[o].style.width=l,y.children[o].style.width=l,i[o].width||("left"===i[o].fixed?(n.querySelector("colgroup").children[o].style.width=l,e.refs.bodyLeft.querySelector("colgroup").children[o].style.width=l):"right"===i[o].fixed&&(r.querySelector("colgroup").children[v].style.width=l,e.refs.bodyRight.querySelector("colgroup").children[v].style.width=l,v++))}),s=this.refs.header,a=V(w=Math.max(w,this.refs.scrollX.clientWidth)),s.style.width=a,o.style.width=V(this.refs.header.clientWidth+300+o.offsetWidth-o.clientWidth);var b=this.refs.header.offsetHeight;l.forEach(function(e){G(e.querySelector("tr"),V(f)),G(e.parentElement,V(b))}),this.bodies().forEach(function(e){!function(e,t){for(var n=0;e.children.length>n;n++)t(e.children[n],n)}(e,function(e,t){return G(e,V(u[t]))})}),this.refs.body.style.height=V(h-b-p)},n.prototype.scrollByOffset=function(e,t){if(this.table){var n=this.refs,r=n.bodyMiddle,o=n.hScrollBar,i=n.hScrollPanel,l=n.vScrollBar,s=n.vScrollPanel;if(r){var a=this.refs.scrollX.offsetWidth,c=this.refs.body.clientHeight,d=r.offsetWidth,u=r.offsetHeight,f=1,h=1;if(u>c||(s.style.visibility="hidden",l=null,s=null),d>a||(i.style.visibility="hidden",o=null,i=null),o){var p=i.offsetWidth,m=p*a/d;f=(d-a)/(p-m)}if(l){var y=s.offsetHeight,w=y*c/u;h=(u-c)/(y-w)}t*=h;var v=Math.round(this.refs.scrollX.scrollLeft+(e*=f)),b=Math.round(this.refs.body.scrollTop+t),_=!0;if(v>d-a&&(v=d-a,_=!1),0>v&&(v=0,_=!1),b>u-c&&(b=u-c,_=!1),0>b&&(b=0,_=!1),this.refs.body.scrollTop=b,this.refs.scrollX.scrollLeft=v,o)i.style.visibility="visible",o.style.width=Math.round(m)+"px",o.style.transform="translateX("+Math.round(v/f)+"px)";if(E(this.refs.bodyLeft,v),E(this.refs.bodyRight,v-d+a),l){var g=Math.round(b/h);s.style.visibility="visible",l.style.height=Math.round(w)+"px",l.style.transform="translateY("+g+"px)"}return{hasOffset:_}}}function E(e,t){e&&(0===t&&e?e.parentElement.parentElement.style.display="none":(e.parentElement.parentElement.style.display="block",e.style.transform="translateY("+-b+"px)"))}},n.prototype.renderHeaderSideOf=function(t){var n=t.side,r=X(t,["side"]),o=n.toLowerCase(),i=r[o+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"header"+n},e.createElement("colgroup",null,i.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:l+"-row "+l+"-row--header"},i.map(function(t,n){return e.createElement("td",{key:t.dataIndex||n,className:l+"-cell "+l+"-cell--header",style:t.headerStyle},U(t.header,r.data,t))}))))},n.prototype.renderBodySideOf=function(t){var n=this,r=t.side,o=t.data,i=X(t,["side","data"])[r.toLowerCase()+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"body"+r},e.createElement("colgroup",null,i.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("tbody",{ref:"body"+r+"Content"},o.map(function(t,r){return e.createElement("tr",{key:r,className:l+"-row "+l+"-row--body",onMouseEnter:function(){return n.handleRowEnter(r)},onMouseLeave:function(){return n.handleRowLeave(r)},onClick:function(){return n.handleClickRow(t,r)}},i.map(function(n,r){return e.createElement("td",{key:r,style:n.cellStyle,className:l+"-cell "+l+"-cell--body "+(n.cellClassName||"")},U(n.cell,t,o,n))}))})))},n.prototype.renderVirtualTable=function(t){var n=t.data,r=t.columns,o=this.props.prefixCls;return e.createElement("table",{className:o+"-hidden-layout",ref:"virtualTable"},e.createElement("colgroup",null,r.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:o+"-row "+o+"-row--header"},r.map(function(n,r){return e.createElement("td",{key:n.dataIndex||r,className:o+"-cell "+o+"-cell--header",style:n.headerStyle},U(n.header,t.data,n))}))),e.createElement("tbody",{ref:"virtualTableBody"},n.map(function(t,i){return e.createElement("tr",{key:i,className:o+"-row "+o+"-row--body"},r.map(function(r,i){return e.createElement("td",{key:i,style:r.cellStyle,className:o+"-cell "+o+"-cell--body "+(r.cellClassName||"")},U(r.cell,t,n,r))}))})))},n.prototype.render=function(){var t=this,n=this.props,r=n.data,o=n.columns,i=n.prefixCls,l=n.style,s=n.className,a=o.slice(),c=o.filter(function(e){return"left"===e.fixed}),d=o.filter(function(e){return"right"===e.fixed}),u=function(e){return{side:e,columns:o,leftColumns:c,rightColumns:d,middleColumns:a,data:r}};return e.createElement("div",{className:i+" "+(s||""),key:"rb-table",ref:this.setTableRef,onWheel:this.handleScroll,style:l},e.createElement("div",{ref:"scrollX",className:i+"-scrollx",onScroll:function(){return t.scrollByOffset(0,0)}},e.createElement("div",{className:i+"__header",ref:"header"},this.renderHeaderSideOf(u("Middle"))),e.createElement("div",{className:i+"__body",ref:"body",onScroll:function(){return t.scrollByOffset(0,0)}},this.renderBodySideOf(u("Middle")),this.renderVirtualTable(u("virtual")))),c.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--left"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Left"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Left")))),d.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--right"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Right"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Right")))),e.createElement("div",{className:i+"__vscroll",ref:"vScrollPanel",onMouseDown:this.vScrollPanelMouseDown},e.createElement("div",{ref:"vScrollBar",onMouseDown:this.vScrollBarMouseDown,className:i+"__vscroll__bar"})),e.createElement("div",{className:i+"__hscroll",ref:"hScrollPanel",onMouseDown:this.hScrollPanelMouseDown},e.createElement("div",{ref:"hScrollBar",onMouseDown:this.hScrollBarMouseDown,className:i+"__hscroll__bar"})),this.props.children)},n}(e.Component);return Z.propTypes={columns:E.arrayOf(E.shape({header:E.oneOfType([E.string,E.number,E.func,E.element]).isRequired,cell:E.oneOfType([E.string,E.number,E.func,E.element]).isRequired,width:E.number,minWidth:K,maxWidth:K,fixed:E.oneOf(["left","right"]),className:E.string,onRowClick:E.func})),data:E.array.isRequired,prefixCls:E.string.isRequired},Z.defaultProps={prefixCls:"rb-table",data:[]},Z}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.RBTable=t(e.React)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;10>n;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}();var o="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function i(){}var l,s,a,c,d,u,h,f,p,m,y,w,v,b,_,g,E=(function(e){e.exports=function(){function e(e,t,n,r,i,l){if(l!==o){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=i,n.PropTypes=n,n}()}(l={exports:{}},l.exports),l.exports),S=!1;function x(){if(!S){S=!0;var e=navigator.userAgent,t=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(e),n=/(Mac OS X)|(Windows)|(Linux)/.exec(e);if(v=/\b(iPhone|iP[ao]d)/.exec(e),b=/\b(iP[ao]d)/.exec(e),y=/Android/i.exec(e),_=/FBAN\/\w+;/i.exec(e),g=/Mobile/i.exec(e),w=!!/Win64/.exec(e),t){(s=t[1]?parseFloat(t[1]):t[5]?parseFloat(t[5]):NaN)&&document&&document.documentMode&&(s=document.documentMode);var r=/(?:Trident\/(\d+.\d+))/.exec(e);h=r?parseFloat(r[1])+4:s,a=t[2]?parseFloat(t[2]):NaN,c=t[3]?parseFloat(t[3]):NaN,(d=t[4]?parseFloat(t[4]):NaN)?(t=/(?:Chrome\/(\d+\.\d+))/.exec(e),u=t&&t[1]?parseFloat(t[1]):NaN):u=NaN}else s=a=c=u=d=NaN;if(n){if(n[1]){var o=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(e);f=!o||parseFloat(o[1].replace("_","."))}else f=!1;p=!!n[2],m=!!n[3]}else f=p=m=!1}}var M,O={ie:function(){return x()||s},ieCompatibilityMode:function(){return x()||h>s},ie64:function(){return O.ie()&&w},firefox:function(){return x()||a},opera:function(){return x()||c},webkit:function(){return x()||d},safari:function(){return O.webkit()},chrome:function(){return x()||u},windows:function(){return x()||p},osx:function(){return x()||f},linux:function(){return x()||m},iphone:function(){return x()||v},mobile:function(){return x()||v||b||y||g},nativeApp:function(){return x()||_},android:function(){return x()||y},ipad:function(){return x()||b}},C=O,R=!("undefined"==typeof window||!window.document||!window.document.createElement),N={canUseDOM:R,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:R&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:R&&!!window.screen,isInWorker:!R};N.canUseDOM&&(M=document.implementation&&document.implementation.hasFeature&&!0!==document.implementation.hasFeature("",""));var D=function(e,t){if(!N.canUseDOM||t&&!("addEventListener"in document))return!1;var n="on"+e,r=n in document;if(!r){var o=document.createElement("div");o.setAttribute(n,"return;"),r="function"==typeof o[n]}return!r&&M&&"wheel"===e&&(r=document.implementation.hasFeature("Events.wheel","3.0")),r},T=10,W=40,L=800;function k(e){var t=0,n=0,r=0,o=0;return"detail"in e&&(n=e.detail),"wheelDelta"in e&&(n=-e.wheelDelta/120),"wheelDeltaY"in e&&(n=-e.wheelDeltaY/120),"wheelDeltaX"in e&&(t=-e.wheelDeltaX/120),"axis"in e&&e.axis===e.HORIZONTAL_AXIS&&(t=n,n=0),r=t*T,o=n*T,"deltaY"in e&&(o=e.deltaY),"deltaX"in e&&(r=e.deltaX),(r||o)&&e.deltaMode&&(1==e.deltaMode?(r*=W,o*=W):(r*=L,o*=L)),r&&!t&&(t=1>r?-1:1),o&&!n&&(n=1>o?-1:1),{spinX:t,spinY:n,pixelX:r,pixelY:o}}k.getEventType=function(){return C.firefox()?"DOMMouseScroll":D("wheel")?"wheel":"mousewheel"};var B,z,P=k,q=navigator.userAgent.match(/Trident/),F=(B=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,20)},function(e){return B(e)}),j=(z=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.clearTimeout,function(e){return z(e)});function A(e){var t=e.target||e.srcElement;t.__resizeRAF__&&j(t.__resizeRAF__),t.__resizeRAF__=F(function(){var n=t.__resizeTrigger__;n.__resizeListeners__.forEach(function(t){t.call(n,e)})})}function H(){this.contentDocument.defaultView.__resizeTrigger__=this.__resizeElement__,this.contentDocument.defaultView.addEventListener("resize",A)}function X(e,t){if(!e.__resizeListeners__){e.__resizeListeners__=[];var n=e.__resizeTrigger__=document.createElement("object");n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"),n.__resizeElement__=e,n.onload=H,n.type="text/html",q&&e.appendChild(n),n.data="about:blank",q||e.appendChild(n)}e.__resizeListeners__.push(t)}function I(e,t){var n={};for(var r in e)0>t.indexOf(r)&&Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function U(t){for(var n=arguments.length,r=Array(n>1?n-1:0),o=1;n>o;o++)r[o-1]=arguments[o];if(t)return"string"==typeof t||"number"==typeof t?t:"function"==typeof t?t.apply(void 0,r):e.isValidElement(t)?e.cloneElement(t,{tableContext:r}):void 0}function Y(e){return e.width?{width:e.width}:null}function V(e){return e?e+"px":e}function G(e,t){e.style.height=t}function K(e,t,n){return e.width&&e[t]?Error(n+".column."+t+" will not take effect when column.width is set."):"maxWidth"===t&&e.minWidth>e.maxWidth?Error(n+".column.maxWidth is smaller then column.minWidth"):void 0}var Z=function(t){function n(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,t.call(this,e));return r.setTableRef=r.setTableRef.bind(r),r.handleResize=r.handleResize.bind(r),r.handleScroll=r.handleScroll.bind(r),r.handleClickRow=r.handleClickRow.bind(r),r.handleWindowMouseUp=r.handleWindowMouseUp.bind(r),r.handleWindowMouseMove=r.handleWindowMouseMove.bind(r),r.hScrollPanelMouseDown=r.hScrollPanelMouseDown.bind(r),r.vScrollPanelMouseDown=r.vScrollPanelMouseDown.bind(r),r.hScrollBarMouseDown=r.hScrollBarMouseDown.bind(r),r.vScrollBarMouseDown=r.vScrollBarMouseDown.bind(r),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,t),n.prototype.componentWillUnmount=function(){X(this.table,this.handleResize),window.removeEventListener("mouseup",this.handleWindowMouseUp),window.removeEventListener("mousemove",this.handleWindowMouseMove)},n.prototype.componentDidMount=function(){var e=this;window.addEventListener("mouseup",this.handleWindowMouseUp),window.addEventListener("mousemove",this.handleWindowMouseMove),setTimeout(function(){e.reflow()})},n.prototype.setTableRef=function(e){var t,n;e&&(this.table&&(n=this.handleResize,(t=this.table).__resizeListeners__&&(t.__resizeListeners__.splice(t.__resizeListeners__.indexOf(n),1),t.__resizeListeners__.length||(t.__resizeTrigger__.contentDocument.defaultView.removeEventListener("resize",A),t.__resizeTrigger__=!t.removeChild(t.__resizeTrigger__)))),this.table=e,X(e,this.handleResize))},n.prototype.componentDidUpdate=function(){this.reflow()},n.prototype.handleResize=function(){this.reflow()},n.prototype.reflow=function(){this.alignTable(),this.scrollByOffset(0,0)},n.prototype.handleScroll=function(e){if(!this.autoSize){var t=P(e),n=t.pixelY,r=t.pixelX;n=Math.round(.5*n),this.scrollByOffset(r=Math.round(.5*r),n).hasOffset&&(e.preventDefault(),e.stopPropagation())}},n.prototype.handleClickRow=function(e,t){this.props.onRowClick&&this.props.onRowClick(e,t)},n.prototype.setLocation=function(e,t){this.x=e,this.y=t},n.prototype.handleWindowMouseUp=function(){this.mouseIsDownRight=!1,this.mouseIsDownBottom=!1},n.prototype.handleWindowMouseMove=function(e){var t=e.clientY;this.mouseIsDownBottom?this.handleMouseMove(e.clientX,0):this.mouseIsDownRight&&this.handleMouseMove(0,t)},n.prototype.hScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientX-this.refs.hScrollBar.getBoundingClientRect().left;this.scrollByOffset(t,0)},n.prototype.vScrollPanelMouseDown=function(e){e.preventDefault();var t=e.clientY-this.refs.vScrollBar.getBoundingClientRect().top;this.scrollByOffset(0,t)},n.prototype.hScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownBottom=!0,this.setLocation(e)},n.prototype.vScrollBarMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.mouseIsDownRight=!0,this.setLocation(e)},n.prototype.handleMouseMove=function(e,t){var n=e-this.x,r=t-this.y;this.setLocation(e,t),this.scrollByOffset(n,r)},n.prototype.getHoverClass=function(){var e=this.props.prefixCls,t=" "+e+"-row--hover";return this.props.onRowClick&&(t+=e+"-row--clickable"),t},n.prototype.bodies=function(){var e=this.refs;return[e.bodyMiddleContent,e.bodyLeftContent,e.bodyRightContent].filter(function(e){return!!e})},n.prototype.handleRowEnter=function(e){var t=this;this.bodies().forEach(function(n){return n.children[e].className+=t.getHoverClass()})},n.prototype.handleRowLeave=function(e){var t=this;this.bodies().forEach(function(n){return n.children[e].className=n.children[e].className.replace(t.getHoverClass(),"")})},n.prototype.getTableWidthHeight=function(){var e=this.refs.virtualTable,t=[],n=[],r=e.querySelector("thead > tr"),o=e.querySelector("colgroup");function i(){for(var e=0;r.children.length>e;e++)t[e]=r.children[e].offsetWidth+1}return this.props.columns.forEach(function(e,t){o.children[t].style.width=V(e.width||"")}),i(),this.props.columns.forEach(function(e,n){var r=e.width,i=e.minWidth,l=e.maxWidth;(l||i)&&(r=t[n],r=Math.min(l||r,r),o.children[n].style.width=V(r=Math.max(i||r,r)))}),i(),e.querySelectorAll("tbody > tr").forEach(function(e,t){n[t]=e.offsetHeight}),{columnWs:t,rowHs:n}},n.prototype.alignTable=function(){var e=this,t=this.refs,n=t.headerLeft,r=t.headerRight,o=t.body,i=this.props,l=i.columns,s=i.prefixCls,a=[n,r].filter(function(e){return!!e});a.forEach(function(e){G(e.querySelector("tr"),"")});var c,d,u=this.getTableWidthHeight(),h=u.columnWs,f=u.rowHs,p=this.refs.virtualTable.querySelector("thead > tr").clientHeight,m=this.table.clientHeight,y=this.refs.hScrollPanel.offsetHeight,w=this.refs.bodyMiddle.querySelector("colgroup"),v=this.refs.headerMiddle.querySelector("colgroup"),b=0,_=0;h.forEach(function(t,o){var i=V(t);b+=t,w.children[o].style.width=i,v.children[o].style.width=i,l[o].width||("left"===l[o].fixed?(n.querySelector("colgroup").children[o].style.width=i,e.refs.bodyLeft.querySelector("colgroup").children[o].style.width=i):"right"===l[o].fixed&&(r.querySelector("colgroup").children[_].style.width=i,e.refs.bodyRight.querySelector("colgroup").children[_].style.width=i,_++))}),c=this.refs.header,d=V(b=Math.max(b,this.refs.scrollX.clientWidth)),c.style.width=d,o.style.width=V(this.refs.header.clientWidth+(this.autoSize?0:300+o.offsetWidth-o.clientWidth));var g=this.refs.header.offsetHeight;(a.forEach(function(e){G(e.querySelector("tr"),V(p)),G(e.parentElement,V(g))}),this.bodies().forEach(function(e){!function(e,t){for(var n=0;e.children.length>n;n++)t(e.children[n],n)}(e,function(e,t){return G(e,V(f[t]))})}),m>99999||this.autoSize)?(this.autoSize=!0,o.style.width=V(this.refs.header.clientWidth),this.refs.scrollX.style.paddingBottom=0,this.refs.scrollX.style.overflowX="auto",this.refs.body.style.paddingRight=0,this.refs.body.style.overflowY="hidden",this.table.querySelector("."+s+"-fixed--right").style.right=0,this.table.style.height=V(this.refs.scrollX.offsetHeight)):this.refs.body.style.height=V(m-g-y)},n.prototype.scrollByOffset=function(e,t){var n=this.refs,r=n.bodyMiddle,o=n.hScrollBar,i=n.hScrollPanel,l=n.vScrollBar,s=n.vScrollPanel;if(!this.table||this.autoSize)return i.style.visibility="hidden",void(s.style.visibility="hidden");if(r){var a=this.refs.scrollX.offsetWidth,c=this.refs.body.clientHeight,d=r.offsetWidth,u=r.offsetHeight,h=1,f=1;if(u>c||(s.style.visibility="hidden",l=null,s=null),d>a||(i.style.visibility="hidden",o=null,i=null),o){var p=i.offsetWidth,m=p*a/d;h=(d-a)/(p-m)}if(l){var y=s.offsetHeight,w=y*c/u;f=(u-c)/(y-w)}t*=f;var v=Math.round(this.refs.scrollX.scrollLeft+(e*=h)),b=Math.round(this.refs.body.scrollTop+t),_=!0;if(v>d-a&&(v=d-a,_=!1),0>v&&(v=0,_=!1),b>u-c&&(b=u-c,_=!1),0>b&&(b=0,_=!1),this.refs.body.scrollTop=b,this.refs.scrollX.scrollLeft=v,o)i.style.visibility="visible",o.style.width=Math.round(m)+"px",o.style.transform="translateX("+Math.round(v/h)+"px)";if(E(this.refs.bodyLeft,v),E(this.refs.bodyRight,v-d+a),l){var g=Math.round(b/f);s.style.visibility="visible",l.style.height=Math.round(w)+"px",l.style.transform="translateY("+g+"px)"}return{hasOffset:_}}function E(e,t){e&&(0===t&&e?e.parentElement.parentElement.style.display="none":(e.parentElement.parentElement.style.display="block",e.style.transform="translateY("+-b+"px)"))}},n.prototype.renderHeaderSideOf=function(t){var n=t.side,r=I(t,["side"]),o=n.toLowerCase(),i=r[o+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"header"+n},e.createElement("colgroup",null,i.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:l+"-row "+l+"-row--header"},i.map(function(t,n){return e.createElement("td",{key:t.dataIndex||n,className:l+"-cell "+l+"-cell--header "+(t.headerClassName||""),style:t.headerStyle},U(t.header,r.data,t))}))))},n.prototype.renderBodySideOf=function(t){var n=this,r=t.side,o=t.data,i=I(t,["side","data"])[r.toLowerCase()+"Columns"];if(0===i.length)return null;var l=this.props.prefixCls;return e.createElement("table",{ref:"body"+r},e.createElement("colgroup",null,i.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("tbody",{ref:"body"+r+"Content"},o.map(function(t,r){return e.createElement("tr",{key:r,className:l+"-row "+l+"-row--body",onMouseEnter:function(){return n.handleRowEnter(r)},onMouseLeave:function(){return n.handleRowLeave(r)},onClick:function(){return n.handleClickRow(t,r)}},i.map(function(n,r){return e.createElement("td",{key:r,style:n.cellStyle,className:l+"-cell "+l+"-cell--body "+(n.cellClassName||"")},U(n.cell,t,o,n))}))})))},n.prototype.renderVirtualTable=function(t){var n=t.data,r=t.columns,o=this.props.prefixCls;return e.createElement("table",{className:o+"-hidden-layout",ref:"virtualTable"},e.createElement("colgroup",null,r.map(function(t,n){return e.createElement("col",{key:n,style:Y(t)})})),e.createElement("thead",null,e.createElement("tr",{className:o+"-row "+o+"-row--header"},r.map(function(n,r){return e.createElement("td",{key:n.dataIndex||r,className:o+"-cell "+o+"-cell--header",style:n.headerStyle},U(n.header,t.data,n))}))),e.createElement("tbody",{ref:"virtualTableBody"},n.map(function(t,i){return e.createElement("tr",{key:i,className:o+"-row "+o+"-row--body"},r.map(function(r,i){return e.createElement("td",{key:i,style:r.cellStyle,className:o+"-cell "+o+"-cell--body "+(r.cellClassName||"")},U(r.cell,t,n,r))}))})))},n.prototype.render=function(){var t=this,n=this.props,r=n.data,o=n.columns,i=n.prefixCls,l=n.style,s=n.className,a=o.slice(),c=o.filter(function(e){return"left"===e.fixed}),d=o.filter(function(e){return"right"===e.fixed}),u=function(e){return{side:e,columns:o,leftColumns:c,rightColumns:d,middleColumns:a,data:r}};return e.createElement("div",{className:i+" "+(s||""),key:"rb-table",ref:this.setTableRef,onWheel:this.handleScroll,style:l},e.createElement("div",{ref:"scrollX",className:i+"-scrollx",onScroll:function(){return t.scrollByOffset(0,0)}},e.createElement("div",{className:i+"__header",ref:"header"},this.renderHeaderSideOf(u("Middle"))),e.createElement("div",{className:i+"__body",ref:"body",onScroll:function(){return t.scrollByOffset(0,0)}},this.renderBodySideOf(u("Middle")),this.renderVirtualTable(u("virtual")))),c.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--left"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Left"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Left")))),d.length&&e.createElement("div",{className:i+"-fixed "+i+"-fixed--right"},e.createElement("div",{className:i+"-fixed__header"},this.renderHeaderSideOf(u("Right"))),e.createElement("div",{className:i+"-fixed__body"},this.renderBodySideOf(u("Right")))),e.createElement("div",{className:i+"__vscroll",ref:"vScrollPanel",onMouseDown:this.vScrollPanelMouseDown},e.createElement("div",{ref:"vScrollBar",onMouseDown:this.vScrollBarMouseDown,className:i+"__vscroll__bar"})),e.createElement("div",{className:i+"__hscroll",ref:"hScrollPanel",onMouseDown:this.hScrollPanelMouseDown},e.createElement("div",{ref:"hScrollBar",onMouseDown:this.hScrollBarMouseDown,className:i+"__hscroll__bar"})),this.props.children)},n}(e.Component);return Z.propTypes={columns:E.arrayOf(E.shape({header:E.oneOfType([E.string,E.number,E.func,E.element]).isRequired,cell:E.oneOfType([E.string,E.number,E.func,E.element]).isRequired,width:E.number,minWidth:K,maxWidth:K,fixed:E.oneOf(["left","right"]),headerClassName:E.string,cellClassName:E.string,headerStyle:E.obj,cellStyle:E.obj})),data:E.array.isRequired,prefixCls:E.string.isRequired,onRowClick:E.func},Z.defaultProps={prefixCls:"rb-table",data:[]},Z}); |
@@ -172,2 +172,4 @@ import React from 'react'; | ||
RBTable.prototype.handleScroll = function handleScroll(e) { | ||
if (this.autoSize) return; | ||
var _normalizeWheel = normalizeWheel(e), | ||
@@ -183,4 +185,4 @@ pixelY = _normalizeWheel.pixelY, | ||
e.preventDefault(); | ||
if (hasOffset) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
@@ -344,3 +346,5 @@ } | ||
body = _refs2.body; | ||
var columns = this.props.columns; | ||
var _props = this.props, | ||
columns = _props.columns, | ||
prefixCls = _props.prefixCls; | ||
@@ -396,3 +400,3 @@ | ||
// 设置 body 宽度,用来隐藏滚动条 | ||
body.style.width = px(this.refs.header.clientWidth + 300 + body.offsetWidth - body.clientWidth); | ||
body.style.width = px(this.refs.header.clientWidth + (this.autoSize ? 0 : 300 + body.offsetWidth - body.clientWidth)); | ||
@@ -413,7 +417,19 @@ var headerHeight = this.refs.header.offsetHeight; | ||
// 设置高度,形成一个上下布局,上部固定高度,底部(body)占满 | ||
this.refs.body.style.height = px(tableClientHeight - headerHeight - hScrollbarHeight); | ||
if (tableClientHeight > 99999 || this.autoSize) { | ||
this.autoSize = true; | ||
body.style.width = px(this.refs.header.clientWidth); | ||
this.refs.scrollX.style.paddingBottom = 0; | ||
this.refs.scrollX.style.overflowX = 'auto'; | ||
this.refs.body.style.paddingRight = 0; | ||
this.refs.body.style.overflowY = 'hidden'; | ||
this.table.querySelector('.' + prefixCls + '-fixed--right').style.right = 0; | ||
this.table.style.height = px(this.refs.scrollX.offsetHeight); | ||
} else { | ||
var height = tableClientHeight - headerHeight - hScrollbarHeight; | ||
this.refs.body.style.height = px(height); | ||
} | ||
}; | ||
RBTable.prototype.scrollByOffset = function scrollByOffset(offsetX, offsetY) { | ||
if (!this.table) return; | ||
var _refs3 = this.refs, | ||
@@ -426,2 +442,7 @@ bodyMiddle = _refs3.bodyMiddle, | ||
if (!this.table || this.autoSize) { | ||
hScrollPanel.style.visibility = 'hidden'; | ||
vScrollPanel.style.visibility = 'hidden'; | ||
return; | ||
} | ||
if (!bodyMiddle) return; | ||
@@ -543,3 +564,3 @@ var bodyWidth = this.refs.scrollX.offsetWidth; | ||
'td', | ||
{ key: column.dataIndex || i, className: prefixCls + '-cell ' + prefixCls + '-cell--header', style: column.headerStyle }, | ||
{ key: column.dataIndex || i, className: prefixCls + '-cell ' + prefixCls + '-cell--header ' + (column.headerClassName || ''), style: column.headerStyle }, | ||
renderSomething(column.header, params.data, column) | ||
@@ -666,8 +687,8 @@ ); | ||
var _props = this.props, | ||
data = _props.data, | ||
columns = _props.columns, | ||
prefixCls = _props.prefixCls, | ||
style = _props.style, | ||
className = _props.className; | ||
var _props2 = this.props, | ||
data = _props2.data, | ||
columns = _props2.columns, | ||
prefixCls = _props2.prefixCls, | ||
style = _props2.style, | ||
className = _props2.className; | ||
@@ -773,7 +794,10 @@ | ||
fixed: PropTypes.oneOf(['left', 'right']), | ||
className: PropTypes.string, | ||
onRowClick: PropTypes.func | ||
headerClassName: PropTypes.string, | ||
cellClassName: PropTypes.string, | ||
headerStyle: PropTypes.obj, | ||
cellStyle: PropTypes.obj | ||
})), | ||
data: PropTypes.array.isRequired, | ||
prefixCls: PropTypes.string.isRequired | ||
prefixCls: PropTypes.string.isRequired, | ||
onRowClick: PropTypes.func | ||
}; | ||
@@ -780,0 +804,0 @@ |
@@ -176,2 +176,4 @@ 'use strict'; | ||
RBTable.prototype.handleScroll = function handleScroll(e) { | ||
if (this.autoSize) return; | ||
var _normalizeWheel = normalizeWheel(e), | ||
@@ -187,4 +189,4 @@ pixelY = _normalizeWheel.pixelY, | ||
e.preventDefault(); | ||
if (hasOffset) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
@@ -348,3 +350,5 @@ } | ||
body = _refs2.body; | ||
var columns = this.props.columns; | ||
var _props = this.props, | ||
columns = _props.columns, | ||
prefixCls = _props.prefixCls; | ||
@@ -400,3 +404,3 @@ | ||
// 设置 body 宽度,用来隐藏滚动条 | ||
body.style.width = px(this.refs.header.clientWidth + 300 + body.offsetWidth - body.clientWidth); | ||
body.style.width = px(this.refs.header.clientWidth + (this.autoSize ? 0 : 300 + body.offsetWidth - body.clientWidth)); | ||
@@ -417,7 +421,19 @@ var headerHeight = this.refs.header.offsetHeight; | ||
// 设置高度,形成一个上下布局,上部固定高度,底部(body)占满 | ||
this.refs.body.style.height = px(tableClientHeight - headerHeight - hScrollbarHeight); | ||
if (tableClientHeight > 99999 || this.autoSize) { | ||
this.autoSize = true; | ||
body.style.width = px(this.refs.header.clientWidth); | ||
this.refs.scrollX.style.paddingBottom = 0; | ||
this.refs.scrollX.style.overflowX = 'auto'; | ||
this.refs.body.style.paddingRight = 0; | ||
this.refs.body.style.overflowY = 'hidden'; | ||
this.table.querySelector('.' + prefixCls + '-fixed--right').style.right = 0; | ||
this.table.style.height = px(this.refs.scrollX.offsetHeight); | ||
} else { | ||
var height = tableClientHeight - headerHeight - hScrollbarHeight; | ||
this.refs.body.style.height = px(height); | ||
} | ||
}; | ||
RBTable.prototype.scrollByOffset = function scrollByOffset(offsetX, offsetY) { | ||
if (!this.table) return; | ||
var _refs3 = this.refs, | ||
@@ -430,2 +446,7 @@ bodyMiddle = _refs3.bodyMiddle, | ||
if (!this.table || this.autoSize) { | ||
hScrollPanel.style.visibility = 'hidden'; | ||
vScrollPanel.style.visibility = 'hidden'; | ||
return; | ||
} | ||
if (!bodyMiddle) return; | ||
@@ -547,3 +568,3 @@ var bodyWidth = this.refs.scrollX.offsetWidth; | ||
'td', | ||
{ key: column.dataIndex || i, className: prefixCls + '-cell ' + prefixCls + '-cell--header', style: column.headerStyle }, | ||
{ key: column.dataIndex || i, className: prefixCls + '-cell ' + prefixCls + '-cell--header ' + (column.headerClassName || ''), style: column.headerStyle }, | ||
renderSomething(column.header, params.data, column) | ||
@@ -670,8 +691,8 @@ ); | ||
var _props = this.props, | ||
data = _props.data, | ||
columns = _props.columns, | ||
prefixCls = _props.prefixCls, | ||
style = _props.style, | ||
className = _props.className; | ||
var _props2 = this.props, | ||
data = _props2.data, | ||
columns = _props2.columns, | ||
prefixCls = _props2.prefixCls, | ||
style = _props2.style, | ||
className = _props2.className; | ||
@@ -777,7 +798,10 @@ | ||
fixed: PropTypes.oneOf(['left', 'right']), | ||
className: PropTypes.string, | ||
onRowClick: PropTypes.func | ||
headerClassName: PropTypes.string, | ||
cellClassName: PropTypes.string, | ||
headerStyle: PropTypes.obj, | ||
cellStyle: PropTypes.obj | ||
})), | ||
data: PropTypes.array.isRequired, | ||
prefixCls: PropTypes.string.isRequired | ||
prefixCls: PropTypes.string.isRequired, | ||
onRowClick: PropTypes.func | ||
}; | ||
@@ -784,0 +808,0 @@ |
{ | ||
"name": "rb-table", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "High performance table with fixed columns and header support", | ||
@@ -5,0 +5,0 @@ "main": "lib/rb-table.js", |
@@ -7,3 +7,3 @@ # rb-table | ||
- Declarative react table component. | ||
- Advanced table layout with width/minWidth/maxWidth support. | ||
- Advanced table layout with width / minWidth / maxWidth support. | ||
- Fixed header and columns support. | ||
@@ -13,2 +13,97 @@ - Seamingless scroll behaviour on fixed header/columns mode. | ||
- Less and Sass with variables defined. | ||
- | ||
## Getting started | ||
For npm: | ||
``` | ||
npm install --save rb-table | ||
``` | ||
Add the default stylesheet, you can choose css/sass/less version by just change the suffix. | ||
```shell | ||
import 'rb-table/dist/rb-table.css'; | ||
``` | ||
For cdn version | ||
```html | ||
<script src="https://unpkg.com/rb-table@1/dist/rb-table.bundle.min.js" crossorigin></script> | ||
``` | ||
Put `<RBTable/>` in your page with props and you are good to go. | ||
```javascript | ||
<RBTable | ||
columns={[ | ||
{ header: () => 'header 1', cell: i => i }, | ||
{ header: 'header 2', cell: i => i }, | ||
{ header: <span>header 3</span>, cell: i => i } | ||
]} | ||
data={[1,2,3]} | ||
/> | ||
``` | ||
## Api | ||
### RBTable Props | ||
| Property | Description | Type | Default | | ||
| ------------ | ------------ | ------------ | ------------ | | ||
| columns | Columns of table | Array<[ColumnProps](#ColumnProps)> | - | | ||
| data | Data to be displayed | Array <any> | - | | ||
| onRowClick | Event callback on row click, if provided an extra class 'rb-table-row--clickable' will append to each body row | function | - | | ||
| prefixCls | Classname prefix, if specified must use with less/sass style and override variable `@prefix-rb-table` with the same value | string | 'rb-table' | | ||
### ColumnProps | ||
| Property | Description | Type | | ||
| ------------ | ------------ | ------------ | | ||
| header | Render column header | string | number | element | function(data, column) | | ||
| cell | Render column cell | string | number | element | function(rowData, data, column) | | ||
| width | Specify column width in `px`, if not specify the width will be auto calculate to fit content in one row, when the total width of table is exceed a horizontal scrollbar will be show | number | | ||
| minWidth | Specify column minimum width in `px` only when width is not set | number | | ||
| maxWidth | Specify column maximum width in `px` only when width is not set | number | | ||
| fixed | Specify column to be fixed on left or right, if not specified will scroll when it is neccessary | 'left' | 'right' | | ||
| cellClassName | Additional cell class | string | | ||
| cellStyle | Additional cell style | object | | ||
| headerClassName | Additional header class | string | | ||
| headerStyle | Additional header style | object | | ||
## Customize Theme | ||
`rb-table` provide the less/scss style file with predefined theme variables, so you can easily customize the look by modifying these variable as well as override the default style. if you are useing wepack, bellow is an example as well as a complete list of variables: | ||
```less | ||
// my-rb-table.less | ||
@import "~rb-table" | ||
@prefix-rb-table: rb-table; | ||
@rb-table-scroll-bar-color: ; @your-primary-color // default #777 | ||
@rb-table-cell-border-color: #f0f0f0; | ||
@rb-table-scroll-bar-background: #eee; | ||
@rb-table-scroll-bar-width: 10px; | ||
@rb-table-scroll-bar-padding: 1px; | ||
@rb-table-scroll-bar-right-offset: 2px; | ||
@prefix-rb-table-padding: (@rb-table-scroll-bar-width + 5px); | ||
@rb-table-background: #FFF; | ||
@rb-table-color: #333; | ||
@rb-table-row-hover-background: lighten(@rb-table-scroll-bar-color, 55%); | ||
``` | ||
Browser Support | ||
------------ | ||
| Chrome | Firefox | IE | Safari | ||
--- | --- | --- | --- | | ||
| Latest | Latest | 11+ | Latest | | ||
Contributions | ||
------------ | ||
Use [GitHub issues](https://github.com/sijiecai/rb-table/issues) for requests. | ||
Pull requests are most welcome; | ||
Changelog | ||
--------- | ||
Changes are tracked as [GitHub releases](https://github.com/sijiecai/rb-table/releases). | ||
License | ||
------- | ||
`rb-table` is [MIT-licensed](https://github.com/SijieCai/rb-table/blob/master/LICENSE). |
@@ -101,2 +101,3 @@ import React from 'react' | ||
handleScroll(e) { | ||
if (this.autoSize) return; | ||
var { pixelY, pixelX } = normalizeWheel(e); | ||
@@ -106,4 +107,4 @@ pixelY = Math.round(pixelY * .5); | ||
const { hasOffset } = this.scrollByOffset(pixelX, pixelY); | ||
e.preventDefault(); | ||
if (hasOffset) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
@@ -182,3 +183,2 @@ } | ||
handleRowEnter(i) { | ||
@@ -237,3 +237,3 @@ this.bodies().forEach(body => body.children[i].className += this.getHoverClass()) | ||
const { headerLeft, headerRight, body } = this.refs; | ||
const { columns } = this.props; | ||
const { columns, prefixCls } = this.props; | ||
@@ -252,3 +252,3 @@ const fixedHeaders = [headerLeft, headerRight].filter(i => !!i); | ||
// 获取 table 高度 | ||
const tableClientHeight = this.table.clientHeight; | ||
let tableClientHeight = this.table.clientHeight; | ||
// 获取 hscrollbar 高度 | ||
@@ -284,3 +284,3 @@ const hScrollbarHeight = this.refs.hScrollPanel.offsetHeight; | ||
// 设置 body 宽度,用来隐藏滚动条 | ||
body.style.width = px(this.refs.header.clientWidth + 300 + body.offsetWidth - body.clientWidth); | ||
body.style.width = px(this.refs.header.clientWidth + (this.autoSize ? 0 : (300 + body.offsetWidth - body.clientWidth))); | ||
@@ -299,11 +299,28 @@ let headerHeight = this.refs.header.offsetHeight; | ||
// 设置高度,形成一个上下布局,上部固定高度,底部(body)占满 | ||
this.refs.body.style.height = px(tableClientHeight - headerHeight - hScrollbarHeight) | ||
if (tableClientHeight > 99999 || this.autoSize) { | ||
this.autoSize = true; | ||
body.style.width = px(this.refs.header.clientWidth); | ||
this.refs.scrollX.style.paddingBottom = 0; | ||
this.refs.scrollX.style.overflowX = 'auto'; | ||
this.refs.body.style.paddingRight = 0; | ||
this.refs.body.style.overflowY = 'hidden'; | ||
this.table.querySelector(`.${prefixCls}-fixed--right`).style.right = 0; | ||
this.table.style.height = px(this.refs.scrollX.offsetHeight); | ||
} else { | ||
let height = tableClientHeight - headerHeight - hScrollbarHeight; | ||
this.refs.body.style.height = px(height); | ||
} | ||
} | ||
scrollByOffset(offsetX, offsetY) { | ||
if (!this.table) return; | ||
var { bodyMiddle, | ||
hScrollBar, hScrollPanel, | ||
vScrollBar, vScrollPanel } = this.refs; | ||
if (!this.table || this.autoSize) { | ||
hScrollPanel.style.visibility = 'hidden'; | ||
vScrollPanel.style.visibility = 'hidden'; | ||
return; | ||
} | ||
if (!bodyMiddle) return; | ||
@@ -411,3 +428,3 @@ const bodyWidth = this.refs.scrollX.offsetWidth; | ||
{columns.map((column, i) => | ||
<td key={column.dataIndex || i} className={`${prefixCls}-cell ${prefixCls}-cell--header`} style={column.headerStyle}> | ||
<td key={column.dataIndex || i} className={`${prefixCls}-cell ${prefixCls}-cell--header ${column.headerClassName || ''}`} style={column.headerStyle}> | ||
{renderSomething(column.header, params.data, column)} | ||
@@ -571,7 +588,10 @@ </td> | ||
fixed: PropTypes.oneOf(['left', 'right']), | ||
className: PropTypes.string, | ||
onRowClick: PropTypes.func | ||
headerClassName: PropTypes.string, | ||
cellClassName: PropTypes.string, | ||
headerStyle: PropTypes.obj, | ||
cellStyle: PropTypes.obj | ||
})), | ||
data: PropTypes.array.isRequired, | ||
prefixCls: PropTypes.string.isRequired, | ||
onRowClick: PropTypes.func | ||
} | ||
@@ -578,0 +598,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
258794
24
4479
107
1