UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 4.41 kB
import*as e from"react";import{localeOption as r}from"primereact/api";import{useMountEffect as t,useUpdateEffect as n,useUnmountEffect as l}from"primereact/hooks";import{ObjectUtils as o,classNames as a}from"primereact/utils";function u(){return u=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},u.apply(this,arguments)}function c(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function i(e){if(Array.isArray(e))return c(e)}function s(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function f(e,r){if(e){if("string"==typeof e)return c(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?c(e,r):void 0}}function m(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(e){return i(e)||s(e)||f(e)||m()}function p(e){if(Array.isArray(e))return e}function y(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,l,o=[],a=!0,u=!1;try{for(t=t.call(e);!(a=(n=t.next()).done)&&(o.push(n.value),!r||o.length!==r);a=!0);}catch(e){u=!0,l=e}finally{try{a||null==t.return||t.return()}finally{if(u)throw l}}return o}}function v(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var h=e.memo(e.forwardRef((function(c,i){var s,m,g=e.useState([]),b=(m=2,p(s=g)||y(s,m)||f(s,m)||v()),w=b[0],E=b[1],S=e.useRef(null),H=e.useRef(null),L=e.useRef(c.value),A=e.useRef([]),N=e.useRef(0),T=e.useRef(null),j=function(){if(c.lazy)c.onLazyLoad&&c.onLazyLoad(O()),N.current+=c.rows;else if(L.current){for(var e=N.current;e<N.current+c.rows&&!(e>=L.current.length);e++)A.current.push(L.current[e]);0!==L.current.length&&(N.current+=c.rows),E(d(A.current))}},z=function(){N.current=0,A.current=[],E(d(A.current)),j()},O=function(){return{first:N.current,rows:c.rows}},R=function(){T.current&&(c.inline&&H.current?H.current.removeEventListener("scroll",T.current):c.loader||window.removeEventListener("scroll",T.current)),T.current=null};t((function(){j(),c.loader||(c.inline?(T.current=function(){H.current.scrollTop>=H.current.scrollHeight*c.buffer-H.current.clientHeight&&j()},H.current.addEventListener("scroll",T.current)):(T.current=function(){var e=document.body,r=document.documentElement,t=window.pageYOffset||document.documentElement.scrollTop,n=r.clientHeight;t>=Math.max(e.scrollHeight,e.offsetHeight,n,r.scrollHeight,r.offsetHeight)*c.buffer-n&&j()},window.addEventListener("scroll",T.current)))})),n((function(){c.value&&(L.current=c.value,c.lazy||(N.current=0),A.current=[],c.lazy?(A.current=L.current,E(d(A.current))):j())}),[c.value]),n((function(){c.loader&&R()}),[c.loader]),l((function(){T.current&&R()})),e.useImperativeHandle(i,(function(){return{props:c,load:j,reset:z,getElement:function(){return S.current},getContent:function(){return H.current}}}));var I=function(r,t){var n=c.itemTemplate?c.itemTemplate(r):r;return e.createElement("li",{key:t+"_datascrollitem"},n)},M=function(){var t=o.getJSXElement(c.emptyMessage,c)||r("emptyMessage");return e.createElement("li",null,t)},x=o.findDiffKeys(c,h.defaultProps),P=a("p-datascroller p-component",c.className,{"p-datascroller-inline":c.inline}),D=c.header?e.createElement("div",{className:"p-datascroller-header"},c.header):null,_=c.footer?e.createElement("div",{className:"p-datascroller-footer"},c.footer):null,k=function(){var r=o.isNotEmpty(w)?w.map(I):M();return e.createElement("div",{ref:H,className:"p-datascroller-content",style:{maxHeight:c.scrollHeight}},e.createElement("ul",{className:"p-datascroller-list"},r))}();return e.createElement("div",u({id:c.id,ref:S,className:P},x),D,k,_)})));h.displayName="DataScroller",h.defaultProps={__TYPE:"DataScroller",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};export{h as DataScroller};