UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ 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) 5.03 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("primereact/api"),t=require("primereact/hooks"),n=require("primereact/utils");function l(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var o=l(e);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 a(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 c(e){if(Array.isArray(e))return a(e)}function i(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function s(e,r){if(e){if("string"==typeof e)return a(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)?a(e,r):void 0}}function f(){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 c(e)||i(e)||s(e)||f()}function m(e){if(Array.isArray(e))return e}function p(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,l,o,u,a=[],c=!0,i=!1;try{if(o=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;c=!1}else for(;!(c=(n=o.call(t)).done)&&(a.push(n.value),a.length!==r);c=!0);}catch(e){i=!0,l=e}finally{try{if(!c&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(i)throw l}}return a}}function y(){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 v={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,children:void 0},getProps:function(e){return n.ObjectUtils.getMergedProps(e,v.defaultProps)},getOtherProps:function(e){return n.ObjectUtils.getDiffProps(e,v.defaultProps)}},g=o.memo(o.forwardRef((function(e,l){var a,c,i=v.getProps(e),f=o.useState([]),g=(c=2,m(a=f)||p(a,c)||s(a,c)||y()),h=g[0],b=g[1],E=o.useRef(null),O=o.useRef(null),w=o.useRef(i.value),j=o.useRef([]),P=o.useRef(0),S=o.useRef(null),H=function(){if(i.lazy)i.onLazyLoad&&i.onLazyLoad(N()),P.current+=i.rows;else if(w.current){for(var e=P.current;e<P.current+i.rows&&!(e>=w.current.length);e++)j.current.push(w.current[e]);0!==w.current.length&&(P.current+=i.rows),b(d(j.current))}},L=function(){P.current=0,j.current=[],b(d(j.current)),H()},N=function(){return{first:P.current,rows:i.rows}},A=function(){S.current&&(i.inline&&O.current?O.current.removeEventListener("scroll",S.current):i.loader||window.removeEventListener("scroll",S.current)),S.current=null};t.useMountEffect((function(){H(),i.loader||(i.inline?(S.current=function(){O.current.scrollTop>=O.current.scrollHeight*i.buffer-O.current.clientHeight&&H()},O.current.addEventListener("scroll",S.current)):(S.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)*i.buffer-n&&H()},window.addEventListener("scroll",S.current)))})),t.useUpdateEffect((function(){i.value&&(w.current=i.value,i.lazy||(P.current=0),j.current=[],i.lazy?(j.current=w.current,b(d(j.current))):H())}),[i.value]),t.useUpdateEffect((function(){i.loader&&A()}),[i.loader]),t.useUnmountEffect((function(){S.current&&A()})),o.useImperativeHandle(l,(function(){return{props:i,load:H,reset:L,getElement:function(){return E.current},getContent:function(){return O.current}}}));var M=function(e,r){var t=i.itemTemplate?i.itemTemplate(e):e;return o.createElement("li",{key:r+"_datascrollitem"},t)},z=function(){var e=n.ObjectUtils.getJSXElement(i.emptyMessage,i)||r.localeOption("emptyMessage");return o.createElement("li",null,e)},T=v.getOtherProps(i),U=n.classNames("p-datascroller p-component",i.className,{"p-datascroller-inline":i.inline}),R=i.header?o.createElement("div",{className:"p-datascroller-header"},i.header):null,_=i.footer?o.createElement("div",{className:"p-datascroller-footer"},i.footer):null,I=function(){var e=n.ObjectUtils.isNotEmpty(h)?h.map(M):z();return o.createElement("div",{ref:O,className:"p-datascroller-content",style:{maxHeight:i.scrollHeight}},o.createElement("ul",{className:"p-datascroller-list"},e))}();return o.createElement("div",u({id:i.id,ref:E,className:U},T),R,I,_)})));g.displayName="DataScroller",exports.DataScroller=g;