2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.datascroller=function(e,t,r,n){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(t);function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){if(t&&("object"===c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var y,m,v,b=function(e){u(m,e);var t,o,a,c,p,y=(t=m,o=h(),function(){var e,r=f(t);if(o){var n=f(this).constructor;e=Reflect.construct(r,arguments,n)}else e=r.apply(this,arguments);return d(this,e)});function m(e){var t;return l(this,m),(t=y.call(this,e)).state={},t.dataToRender=[],t.value=t.props.value,t.first=0,t}return a=m,(c=[{key:"handleDataChange",value:function(){this.props.lazy?(this.dataToRender=this.value,this.setState({dataToRender:this.dataToRender})):this.load()}},{key:"load",value:function(){if(this.props.lazy)this.props.onLazyLoad&&this.props.onLazyLoad(this.createLazyLoadMetadata()),this.first=this.first+this.props.rows;else if(this.value){for(var e=this.first;e<this.first+this.props.rows&&!(e>=this.value.length);e++)this.dataToRender.push(this.value[e]);0!==this.value.length&&(this.first=this.first+this.props.rows),this.setState({dataToRender:this.dataToRender})}}},{key:"reset",value:function(){this.first=0,this.dataToRender=[],this.setState({dataToRender:this.dataToRender}),this.load()}},{key:"isEmpty",value:function(){return!this.dataToRender||0===this.dataToRender.length}},{key:"createLazyLoadMetadata",value:function(){return{first:this.first,rows:this.props.rows}}},{key:"bindScrollListener",value:function(){var e=this;this.props.inline?(this.scrollFunction=function(){e.contentElement.scrollTop>=e.contentElement.scrollHeight*e.props.buffer-e.contentElement.clientHeight&&e.load()},this.contentElement.addEventListener("scroll",this.scrollFunction)):(this.scrollFunction=function(){var t=document.body,r=document.documentElement,n=window.pageYOffset||document.documentElement.scrollTop,o=r.clientHeight;n>=Math.max(t.scrollHeight,t.offsetHeight,o,r.scrollHeight,r.offsetHeight)*e.props.buffer-o&&e.load()},window.addEventListener("scroll",this.scrollFunction))}},{key:"unbindScrollListener",value:function(){this.scrollFunction&&(this.props.inline?(this.contentElement.removeEventListener("scroll",this.scrollFunction),this.contentElement=null):this.props.loader||window.removeEventListener("scroll",this.scrollFunction)),this.scrollFunction=null}},{key:"componentDidMount",value:function(){this.load(),this.props.loader||this.bindScrollListener()}},{key:"componentDidUpdate",value:function(e,t){var r=this.props.value;r&&this.value!==r&&(this.value=r,this.first=0,this.dataToRender=[],this.handleDataChange()),e.loader!==this.props.loader&&this.props.loader&&this.unbindScrollListener()}},{key:"componentWillUnmount",value:function(){this.scrollFunction&&this.unbindScrollListener()}},{key:"renderHeader",value:function(){return this.props.header?i.default.createElement("div",{className:"p-datascroller-header"},this.props.header):null}},{key:"renderFooter",value:function(){return this.props.footer?i.default.createElement("div",{className:"p-datascroller-footer"},this.props.footer):null}},{key:"renderItem",value:function(e,t){var r=this.props.itemTemplate?this.props.itemTemplate(e):e;return i.default.createElement("li",{key:t+"_datascrollitem"},r)}},{key:"renderEmptyMessage",value:function(){var e=r.ObjectUtils.getJSXElement(this.props.emptyMessage,this.props)||n.localeOption("emptyMessage");return i.default.createElement("li",null,e)}},{key:"renderContent",value:function(){var e=this,t=this.state.dataToRender&&this.state.dataToRender.length?this.state.dataToRender.map((function(t,r){return e.renderItem(t,r)})):this.renderEmptyMessage();return i.default.createElement("div",{ref:function(t){return e.contentElement=t},className:"p-datascroller-content",style:{maxHeight:this.props.scrollHeight}},i.default.createElement("ul",{className:"p-datascroller-list"},t))}},{key:"render",value:function(){var e=r.classNames("p-datascroller p-component",this.props.className,{"p-datascroller-inline":this.props.inline}),t=this.renderHeader(),n=this.renderFooter(),o=this.renderContent();return i.default.createElement("div",{id:this.props.id,className:e},t,o,n)}}])&&s(a.prototype,c),p&&s(a,p),Object.defineProperty(a,"prototype",{writable:!1}),m}(t.Component);return v={id:null,value:null,rows:0,inline:!1,scrollHeight:null,loader:!1,buffer:.9,style:null,className:null,onLazyLoad:null,emptyMessage:null,itemTemplate:null,header:null,footer:null,lazy:!1},(m="defaultProps")in(y=b)?Object.defineProperty(y,m,{value:v,enumerable:!0,configurable:!0,writable:!0}):y[m]=v,e.DataScroller=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.api);
|