UNPKG

react-infinite-tree

Version:
7 lines 27.1 kB
/*! react-infinite-tree v1.0.0-alpha.5 | (c) 2018 Cheton Wu <cheton@gmail.com> | MIT | https://github.com/cheton/react-infinite-tree */ exports.InfiniteTree=function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=7)}([function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(e){if(f===setTimeout)return setTimeout(e,0);if((f===n||!f)&&setTimeout)return f=setTimeout,setTimeout(e,0);try{return f(e,0)}catch(t){try{return f.call(null,e,0)}catch(t){return f.call(this,e,0)}}}function i(e){if(c===clearTimeout)return clearTimeout(e);if((c===r||!c)&&clearTimeout)return c=clearTimeout,clearTimeout(e);try{return c(e)}catch(t){try{return c.call(null,e)}catch(t){return c.call(this,e)}}}function s(){y&&p&&(y=!1,p.length?h=p.concat(h):v=-1,h.length&&a())}function a(){if(!y){var e=o(s);y=!0;for(var t=h.length;t;){for(p=h,h=[];++v<t;)p&&p[v].run();v=-1,t=h.length}p=null,y=!1,i(e)}}function u(e,t){this.fun=e,this.array=t}function l(){}var f,c,d=e.exports={};!function(){try{f="function"==typeof setTimeout?setTimeout:n}catch(e){f=n}try{c="function"==typeof clearTimeout?clearTimeout:r}catch(e){c=r}}();var p,h=[],y=!1,v=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];h.push(new u(e,t)),1!==h.length||y||o(a)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=l,d.addListener=l,d.once=l,d.off=l,d.removeListener=l,d.removeAllListeners=l,d.emit=l,d.prependListener=l,d.prependOnceListener=l,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,t,n){"use strict";function r(e){return function(){return e}}var o=function(){};o.thatReturns=r,o.thatReturnsFalse=r(!1),o.thatReturnsTrue=r(!0),o.thatReturnsNull=r(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,n){"use strict";(function(t){function n(e,t,n,o,i,s,a,u){if(r(t),!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[n,o,i,s,a,u],c=0;l=new Error(t.replace(/%s/g,function(){return f[c++]})),l.name="Invariant Violation"}throw l.framesToPop=1,l}}var r=function(e){};"production"!==t.env.NODE_ENV&&(r=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")}),e.exports=n}).call(t,n(0))},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){(function(t){if("production"!==t.env.NODE_ENV){var r="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,o=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===r};e.exports=n(9)(o,!0)}else e.exports=n(12)()}).call(t,n(0))},function(e,t,n){"use strict";(function(t){var r=n(1),o=r;if("production"!==t.env.NODE_ENV){var i=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=0,i="Warning: "+e.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.error(i);try{throw new Error(i)}catch(e){}};o=function(e,t){if(void 0===t)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(0!==t.indexOf("Failed Composite propType: ")&&!e){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];i.apply(void 0,[t].concat(r))}}}e.exports=o}).call(t,n(0))},function(e,t){e.exports=require("react")},function(e,t,n){"use strict";var r=n(8),o=function(e){return e&&e.__esModule?e:{default:e}}(r);e.exports=o.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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}function a(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)}Object.defineProperty(t,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=n(4),c=r(f),d=n(6),p=r(d),h=n(13),y=r(h),v=n(14),m=r(v),g=function(e){return e+="",e.charAt(0).toLowerCase()+e.substr(1)},b=function(e){function t(){var e,n,r,o;i(this,t);for(var a=arguments.length,u=Array(a),l=0;l<a;l++)u[l]=arguments[l];return n=r=s(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(u))),r.tree=null,r.state={nodes:[]},r.eventHandlers={onContentWillUpdate:null,onContentDidUpdate:null,onOpenNode:null,onCloseNode:null,onSelectNode:null,onWillOpenNode:null,onWillCloseNode:null,onWillSelectNode:null},o=n,s(r,o)}return a(t,e),l(t,[{key:"componentDidMount",value:function(){var e=this,t=this.props,n=(t.children,t.className,t.style,o(t,["children","className","style"]));void 0!==n.el&&delete n.el,n.rowRenderer=function(){return""},this.tree=new y.default(n);var r=this.tree.filter.bind(this.tree);this.tree.filter=function(){return setTimeout(function(){e.virtualList.recomputeSizes(0)},0),r.apply(void 0,arguments)};var i=this.tree.unfilter.bind(this.tree);this.tree.unfilter=function(){return setTimeout(function(){e.virtualList.recomputeSizes(0)},0),i.apply(void 0,arguments)},this.tree.scrollToNode=function(t){if(!e.tree||!e.virtualList)return!1;var n=e.tree.nodes.indexOf(t);if(n<0)return!1;var r=e.virtualList.getOffsetForIndex(n);return e.virtualList.scrollTo(r),!0},this.tree.scrollTop=function(t){if(e.tree&&e.virtualList)return void 0!==t&&e.virtualList.scrollTo(Number(t)),e.virtualList.getNodeOffset()},this.tree.update=function(){e.tree.emit("contentWillUpdate"),e.setState(function(t){return{nodes:e.tree.nodes}},function(){e.tree.emit("contentDidUpdate")})},Object.keys(this.eventHandlers).forEach(function(t){if(e.props[t]){var n=g(t.substr(2));e.eventHandlers[t]=e.props[t],e.tree.on(n,e.eventHandlers[t])}})}},{key:"componentWillUnmount",value:function(){var e=this;Object.keys(this.eventHandlers).forEach(function(t){if(e.eventHandlers[t]){var n=g(t.substr(2));e.tree.removeListener(n,e.eventHandlers[t]),e.eventHandlers[t]=null}}),this.tree.destroy(),this.tree=null}},{key:"render",value:function(){var e=this,t=this.props,n=(t.autoOpen,t.selectable,t.tabIndex),r=(t.data,t.width),i=t.height,s=t.rowHeight,a=t.rowRenderer,l=(t.loadNodes,t.shouldSelectNode,t.scrollOffset),f=t.scrollToIndex,c=t.onScroll,d=(t.onContentWillUpdate,t.onContentDidUpdate,t.onOpenNode,t.onCloseNode,t.onSelectNode,t.onWillOpenNode,t.onWillCloseNode,t.onWillSelectNode,t.style),h=t.children,y=o(t,["autoOpen","selectable","tabIndex","data","width","height","rowHeight","rowRenderer","loadNodes","shouldSelectNode","scrollOffset","scrollToIndex","onScroll","onContentWillUpdate","onContentDidUpdate","onOpenNode","onCloseNode","onSelectNode","onWillOpenNode","onWillCloseNode","onWillSelectNode","style","children"]),v="function"==typeof h?h:a,g=this.tree?this.tree.nodes.length:0,b={};return void 0!==l&&g>0&&(b.scrollOffset=l),void 0!==f&&f>=0&&f<g&&(b.scrollToIndex=f),"function"==typeof c&&(b.onScroll=c),p.default.createElement("div",u({},y,{style:u({outline:"none"},d),tabIndex:n}),p.default.createElement(m.default,u({ref:function(t){e.virtualList=t},width:r,height:i,itemCount:g,itemSize:function(t){var n=e.tree.nodes[t];return n&&!1===n.state.filtered?0:"function"==typeof s?s({node:e.tree.nodes[t],tree:e.tree}):s},renderItem:function(t){var n=t.index,r=t.style,o=null;if("function"==typeof v){var i=e.tree.nodes[n];i&&!1!==i.state.filtered&&(o=v({node:e.tree.nodes[n],tree:e.tree}))}return p.default.createElement("div",{key:n,style:r},o)}},b)))}}]),t}(d.Component);b.displayName="InfiniteTree",b.propTypes={autoOpen:c.default.bool,selectable:c.default.bool,tabIndex:c.default.number,data:c.default.oneOfType([c.default.array,c.default.object]),width:c.default.oneOfType([c.default.string,c.default.number]).isRequired,height:c.default.oneOfType([c.default.string,c.default.number]).isRequired,rowHeight:c.default.oneOfType([c.default.number,c.default.array,c.default.func]).isRequired,rowRenderer:c.default.func,loadNodes:c.default.func,shouldSelectNode:c.default.func,scrollOffset:c.default.number,scrollToIndex:c.default.number,onScroll:c.default.func,onContentWillUpdate:c.default.func,onContentDidUpdate:c.default.func,onOpenNode:c.default.func,onCloseNode:c.default.func,onSelectNode:c.default.func,onWillOpenNode:c.default.func,onWillCloseNode:c.default.func,onWillSelectNode:c.default.func},b.defaultProps={autoOpen:!1,selectable:!0,tabIndex:0,data:[],width:"100%"},t.default=b},function(e,t,n){"use strict";(function(t){var r=n(1),o=n(2),i=n(5),s=n(10),a=n(3),u=n(11);e.exports=function(e,n){function l(e){var t=e&&(N&&e[N]||e[C]);if("function"==typeof t)return t}function f(e,t){return e===t?0!==e||1/e==1/t:e!==e&&t!==t}function c(e){this.message=e,this.stack=""}function d(e){function r(r,l,f,d,p,h,y){if(d=d||j,h=h||f,y!==a)if(n)o(!1,"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");else if("production"!==t.env.NODE_ENV&&"undefined"!=typeof console){var v=d+":"+f;!s[v]&&u<3&&(i(!1,"You are manually calling a React.PropTypes validation function for the `%s` prop on `%s`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.",h,d),s[v]=!0,u++)}return null==l[f]?r?new c(null===l[f]?"The "+p+" `"+h+"` is marked as required in `"+d+"`, but its value is `null`.":"The "+p+" `"+h+"` is marked as required in `"+d+"`, but its value is `undefined`."):null:e(l,f,d,p,h)}if("production"!==t.env.NODE_ENV)var s={},u=0;var l=r.bind(null,!1);return l.isRequired=r.bind(null,!0),l}function p(e){function t(t,n,r,o,i,s){var a=t[n];if(w(a)!==e)return new c("Invalid "+o+" `"+i+"` of type `"+I(a)+"` supplied to `"+r+"`, expected `"+e+"`.");return null}return d(t)}function h(e){function t(t,n,r,o,i){if("function"!=typeof e)return new c("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var s=t[n];if(!Array.isArray(s)){return new c("Invalid "+o+" `"+i+"` of type `"+w(s)+"` supplied to `"+r+"`, expected an array.")}for(var u=0;u<s.length;u++){var l=e(s,u,r,o,i+"["+u+"]",a);if(l instanceof Error)return l}return null}return d(t)}function y(e){function t(t,n,r,o,i){if(!(t[n]instanceof e)){var s=e.name||j;return new c("Invalid "+o+" `"+i+"` of type `"+z(t[n])+"` supplied to `"+r+"`, expected instance of `"+s+"`.")}return null}return d(t)}function v(e){function n(t,n,r,o,i){for(var s=t[n],a=0;a<e.length;a++)if(f(s,e[a]))return null;return new c("Invalid "+o+" `"+i+"` of value `"+s+"` supplied to `"+r+"`, expected one of "+JSON.stringify(e)+".")}return Array.isArray(e)?d(n):("production"!==t.env.NODE_ENV&&i(!1,"Invalid argument supplied to oneOf, expected an instance of array."),r.thatReturnsNull)}function m(e){function t(t,n,r,o,i){if("function"!=typeof e)return new c("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var s=t[n],u=w(s);if("object"!==u)return new c("Invalid "+o+" `"+i+"` of type `"+u+"` supplied to `"+r+"`, expected an object.");for(var l in s)if(s.hasOwnProperty(l)){var f=e(s,l,r,o,i+"."+l,a);if(f instanceof Error)return f}return null}return d(t)}function g(e){function n(t,n,r,o,i){for(var s=0;s<e.length;s++){if(null==(0,e[s])(t,n,r,o,i,a))return null}return new c("Invalid "+o+" `"+i+"` supplied to `"+r+"`.")}if(!Array.isArray(e))return"production"!==t.env.NODE_ENV&&i(!1,"Invalid argument supplied to oneOfType, expected an instance of array."),r.thatReturnsNull;for(var o=0;o<e.length;o++){var s=e[o];if("function"!=typeof s)return i(!1,"Invalid argument supplied to oneOfType. Expected an array of check functions, but received %s at index %s.",T(s),o),r.thatReturnsNull}return d(n)}function b(e){function t(t,n,r,o,i){var s=t[n],u=w(s);if("object"!==u)return new c("Invalid "+o+" `"+i+"` of type `"+u+"` supplied to `"+r+"`, expected `object`.");for(var l in e){var f=e[l];if(f){var d=f(s,l,r,o,i+"."+l,a);if(d)return d}}return null}return d(t)}function O(e){function t(t,n,r,o,i){var u=t[n],l=w(u);if("object"!==l)return new c("Invalid "+o+" `"+i+"` of type `"+l+"` supplied to `"+r+"`, expected `object`.");var f=s({},t[n],e);for(var d in f){var p=e[d];if(!p)return new c("Invalid "+o+" `"+i+"` key `"+d+"` supplied to `"+r+"`.\nBad object: "+JSON.stringify(t[n],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var h=p(u,d,r,o,i+"."+d,a);if(h)return h}return null}return d(t)}function S(t){switch(typeof t){case"number":case"string":case"undefined":return!0;case"boolean":return!t;case"object":if(Array.isArray(t))return t.every(S);if(null===t||e(t))return!0;var n=l(t);if(!n)return!1;var r,o=n.call(t);if(n!==t.entries){for(;!(r=o.next()).done;)if(!S(r.value))return!1}else for(;!(r=o.next()).done;){var i=r.value;if(i&&!S(i[1]))return!1}return!0;default:return!1}}function x(e,t){return"symbol"===e||("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}function w(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":x(t,e)?"symbol":t}function I(e){if(void 0===e||null===e)return""+e;var t=w(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function T(e){var t=I(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}function z(e){return e.constructor&&e.constructor.name?e.constructor.name:j}var N="function"==typeof Symbol&&Symbol.iterator,C="@@iterator",j="<<anonymous>>",P={array:p("array"),bool:p("boolean"),func:p("function"),number:p("number"),object:p("object"),string:p("string"),symbol:p("symbol"),any:function(){return d(r.thatReturnsNull)}(),arrayOf:h,element:function(){function t(t,n,r,o,i){var s=t[n];if(!e(s)){return new c("Invalid "+o+" `"+i+"` of type `"+w(s)+"` supplied to `"+r+"`, expected a single ReactElement.")}return null}return d(t)}(),instanceOf:y,node:function(){function e(e,t,n,r,o){return S(e[t])?null:new c("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")}return d(e)}(),objectOf:m,oneOf:v,oneOfType:g,shape:b,exact:O};return c.prototype=Error.prototype,P.checkPropTypes=u,P.PropTypes=P,P}}).call(t,n(0))},function(e,t,n){"use strict";function r(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}/* object-assign (c) Sindre Sorhus @license MIT */ var o=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable;e.exports=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;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,a,u=r(e),l=1;l<arguments.length;l++){n=Object(arguments[l]);for(var f in n)i.call(n,f)&&(u[f]=n[f]);if(o){a=o(n);for(var c=0;c<a.length;c++)s.call(n,a[c])&&(u[a[c]]=n[a[c]])}}return u}},function(e,t,n){"use strict";(function(t){function r(e,n,r,u,l){if("production"!==t.env.NODE_ENV)for(var f in e)if(e.hasOwnProperty(f)){var c;try{o("function"==typeof e[f],"%s: %s type `%s` is invalid; it must be a function, usually from the `prop-types` package, but received `%s`.",u||"React class",r,f,typeof e[f]),c=e[f](n,f,u,r,null,s)}catch(e){c=e}if(i(!c||c instanceof Error,"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",u||"React class",r,f,typeof c),c instanceof Error&&!(c.message in a)){a[c.message]=!0;var d=l?l():"";i(!1,"Failed %s type: %s%s",r,c.message,null!=d?d:"")}}}if("production"!==t.env.NODE_ENV)var o=n(2),i=n(5),s=n(3),a={};e.exports=r}).call(t,n(0))},function(e,t,n){"use strict";var r=n(1),o=n(2),i=n(3);e.exports=function(){function e(e,t,n,r,s,a){a!==i&&o(!1,"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")}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=r,n.PropTypes=n,n}},function(e,t){e.exports=require("infinite-tree")},function(e,t,n){"use strict";function r(e,t){function n(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function o(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&(n[r[o]]=e[r[o]]);return n}Object.defineProperty(t,"__esModule",{value:!0});var i,s,a,u=n(6),l=(n.n(u),n(4)),f=(n.n(l),Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}),c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},d="observed",p="requested",h=(i={},i.vertical="scrollTop",i.horizontal="scrollLeft",i),y=(s={},s.vertical="height",s.horizontal="width",s),v=(a={},a.vertical="top",a.horizontal="left",a),m=function(){function e(e){var t=e.itemCount,n=e.itemSizeGetter,r=e.estimatedItemSize;this.itemSizeGetter=n,this.itemCount=t,this.estimatedItemSize=r,this.itemSizeAndPositionData={},this.lastMeasuredIndex=-1}return e.prototype.updateConfig=function(e){var t=e.itemCount,n=e.estimatedItemSize;this.itemCount=t,this.estimatedItemSize=n},e.prototype.getLastMeasuredIndex=function(){return this.lastMeasuredIndex},e.prototype.getSizeAndPositionForIndex=function(e){if(e<0||e>=this.itemCount)throw Error("Requested index "+e+" is outside of range 0.."+this.itemCount);if(e>this.lastMeasuredIndex){for(var t=this.getSizeAndPositionOfLastMeasuredItem(),n=t.offset+t.size,r=this.lastMeasuredIndex+1;r<=e;r++){var o=this.itemSizeGetter(r);if(null==o||isNaN(o))throw Error("Invalid size returned for index "+r+" of value "+o);this.itemSizeAndPositionData[r]={offset:n,size:o},n+=o}this.lastMeasuredIndex=e}return this.itemSizeAndPositionData[e]},e.prototype.getSizeAndPositionOfLastMeasuredItem=function(){return this.lastMeasuredIndex>=0?this.itemSizeAndPositionData[this.lastMeasuredIndex]:{offset:0,size:0}},e.prototype.getTotalSize=function(){var e=this.getSizeAndPositionOfLastMeasuredItem();return e.offset+e.size+(this.itemCount-this.lastMeasuredIndex-1)*this.estimatedItemSize},e.prototype.getUpdatedOffsetForIndex=function(e){var t=e.align,n=void 0===t?"start":t,r=e.containerSize,o=e.currentOffset,i=e.targetIndex;if(r<=0)return 0;var s,a=this.getSizeAndPositionForIndex(i),u=a.offset,l=u-r+a.size;switch(n){case"end":s=l;break;case"center":s=u-(r-a.size)/2;break;case"start":s=u;break;default:s=Math.max(l,Math.min(u,o))}var f=this.getTotalSize();return Math.max(0,Math.min(f-r,s))},e.prototype.getVisibleRange=function(e){var t=e.containerSize,n=e.offset,r=e.overscanCount;if(0===this.getTotalSize())return{};var o=n+t,i=this.findNearestItem(n);if(void 0===i)throw Error("Invalid offset "+n+" specified");var s=this.getSizeAndPositionForIndex(i);n=s.offset+s.size;for(var a=i;n<o&&a<this.itemCount-1;)a++,n+=this.getSizeAndPositionForIndex(a).size;return r&&(i=Math.max(0,i-r),a=Math.min(a+r,this.itemCount-1)),{start:i,stop:a}},e.prototype.resetItem=function(e){this.lastMeasuredIndex=Math.min(this.lastMeasuredIndex,e-1)},e.prototype.findNearestItem=function(e){if(isNaN(e))throw Error("Invalid offset "+e+" specified");e=Math.max(0,e);var t=this.getSizeAndPositionOfLastMeasuredItem(),n=Math.max(0,this.lastMeasuredIndex);return t.offset>=e?this.binarySearch({high:n,low:0,offset:e}):this.exponentialSearch({index:n,offset:e})},e.prototype.binarySearch=function(e){for(var t=e.low,n=e.high,r=e.offset,o=0,i=0;t<=n;){if(o=t+Math.floor((n-t)/2),(i=this.getSizeAndPositionForIndex(o).offset)===r)return o;i<r?t=o+1:i>r&&(n=o-1)}return t>0?t-1:0},e.prototype.exponentialSearch=function(e){for(var t=e.index,n=e.offset,r=1;t<this.itemCount&&this.getSizeAndPositionForIndex(t).offset<n;)t+=r,r*=2;return this.binarySearch({high:Math.min(t,this.itemCount-1),low:Math.floor(t/2),offset:n})},e}(),g={overflow:"auto",willChange:"transform",WebkitOverflowScrolling:"touch"},b={position:"relative",overflow:"hidden",width:"100%",minHeight:"100%"},O={position:"absolute",left:0,width:"100%"},S=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.sizeAndPositionManager=new m({itemCount:t.props.itemCount,itemSizeGetter:function(e){return t.getSize(e)},estimatedItemSize:t.getEstimatedItemSize()}),t.state={offset:t.props.scrollOffset||null!=t.props.scrollToIndex&&t.getOffsetForIndex(t.props.scrollToIndex)||0,scrollChangeReason:p},t.styleCache={},t.handleScroll=function(e){var n=t.props.onScroll,r=t.getNodeOffset();r<0||t.state.offset===r||e.target!==t.rootNode||(t.setState({offset:r,scrollChangeReason:d}),"function"==typeof n&&n(r,e))},t.getRef=function(e){t.rootNode=e},t}return r(t,e),t.prototype.componentDidMount=function(){var e=this.props,t=e.scrollOffset,n=e.scrollToIndex;null!=t?this.scrollTo(t):null!=n&&this.scrollTo(this.getOffsetForIndex(n))},t.prototype.componentWillReceiveProps=function(e){var t=this.props,n=t.estimatedItemSize,r=t.itemCount,o=t.itemSize,i=t.scrollOffset,s=t.scrollToAlignment,a=t.scrollToIndex,u=e.scrollToIndex!==a||e.scrollToAlignment!==s,l=e.itemCount!==r||e.itemSize!==o||e.estimatedItemSize!==n;e.itemCount===r&&e.estimatedItemSize===n||this.sizeAndPositionManager.updateConfig({itemCount:e.itemCount,estimatedItemSize:this.getEstimatedItemSize(e)}),l&&this.recomputeSizes(),e.scrollOffset!==i?this.setState({offset:e.scrollOffset||0,scrollChangeReason:p}):"number"==typeof e.scrollToIndex&&(u||l)&&this.setState({offset:this.getOffsetForIndex(e.scrollToIndex,e.scrollToAlignment,e.itemCount),scrollChangeReason:p})},t.prototype.componentDidUpdate=function(e,t){var n=this.state,r=n.offset,o=n.scrollChangeReason;t.offset!==r&&o===p&&this.scrollTo(r)},t.prototype.getEstimatedItemSize=function(e){return void 0===e&&(e=this.props),e.estimatedItemSize||"number"==typeof e.itemSize&&e.itemSize||50},t.prototype.getNodeOffset=function(){var e=this.props.scrollDirection,t=void 0===e?"vertical":e;return this.rootNode[h[t]]},t.prototype.scrollTo=function(e){var t=this.props.scrollDirection,n=void 0===t?"vertical":t;this.rootNode[h[n]]=e},t.prototype.getOffsetForIndex=function(e,t,n){void 0===t&&(t=this.props.scrollToAlignment),void 0===n&&(n=this.props.itemCount);var r=this.props.scrollDirection,o=void 0===r?"vertical":r;return(e<0||e>=n)&&(e=0),this.sizeAndPositionManager.getUpdatedOffsetForIndex({align:t,containerSize:this.props[y[o]],currentOffset:this.state&&this.state.offset||0,targetIndex:e})},t.prototype.getSize=function(e){var t=this.props.itemSize;return"function"==typeof t?t(e):Array.isArray(t)?t[e]:t},t.prototype.getStyle=function(e){var t=this.styleCache[e];if(t)return t;var n=this.props.scrollDirection,r=void 0===n?"vertical":n,o=this.sizeAndPositionManager.getSizeAndPositionForIndex(e),i=o.size,s=o.offset;return this.styleCache[e]=c({},O,(a={},a[y[r]]=i,a[v[r]]=s,a));var a},t.prototype.recomputeSizes=function(e){void 0===e&&(e=0),this.styleCache={},this.sizeAndPositionManager.resetItem(e)},t.prototype.render=function(){var e=this.props,t=(e.estimatedItemSize,e.height),n=e.overscanCount,r=void 0===n?3:n,i=e.renderItem,s=(e.itemCount,e.itemSize,e.onItemsRendered),a=(e.onScroll,e.scrollDirection),l=void 0===a?"vertical":a,f=(e.scrollOffset,e.scrollToIndex,e.scrollToAlignment,e.style),d=e.width,p=o(e,["estimatedItemSize","height","overscanCount","renderItem","itemCount","itemSize","onItemsRendered","onScroll","scrollDirection","scrollOffset","scrollToIndex","scrollToAlignment","style","width"]),h=this.state.offset,v=this.sizeAndPositionManager.getVisibleRange({containerSize:this.props[y[l]]||0,offset:h,overscanCount:r}),m=v.start,O=v.stop,S=[];if(void 0!==m&&void 0!==O){for(var x=m;x<=O;x++)S.push(i({index:x,style:this.getStyle(x)}));"function"==typeof s&&s({startIndex:m,stopIndex:O})}return Object(u.createElement)("div",c({ref:this.getRef},p,{onScroll:this.handleScroll,style:c({},g,f,{height:t,width:d})}),Object(u.createElement)("div",{style:c({},b,(w={},w[y[l]]=this.sizeAndPositionManager.getTotalSize(),w))},S));var w},t.defaultProps={overscanCount:3,scrollDirection:"vertical",width:"100%"},t.propTypes={estimatedItemSize:l.number,height:Object(l.oneOfType)([l.number,l.string]).isRequired,itemCount:l.number.isRequired,itemSize:Object(l.oneOfType)([l.number,l.array,l.func]).isRequired,onItemsRendered:l.func,overscanCount:l.number,renderItem:l.func.isRequired,scrollOffset:l.number,scrollToIndex:l.number,scrollToAlignment:Object(l.oneOf)(["auto","start","center","end"]),scrollDirection:Object(l.oneOf)(["horizontal","vertical"]).isRequired,width:Object(l.oneOfType)([l.number,l.string]).isRequired},t}(u.PureComponent);t.default=S}]);