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.06 kB
this.primereact=this.primereact||{},this.primereact.datascroller=function(e,r,t,n,l){"use strict";function o(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 a=o(r);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 d(){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 m(e){return i(e)||s(e)||f(e)||d()}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,u=[],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)&&(u.push(n.value),u.length!==r);c=!0);}catch(e){i=!0,l=e}finally{try{if(!c&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(i)throw l}}return u}}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={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 l.ObjectUtils.getMergedProps(e,h.defaultProps)},getOtherProps:function(e){return l.ObjectUtils.getDiffProps(e,h.defaultProps)}},g=a.memo(a.forwardRef((function(e,r){var o,c,i=h.getProps(e),s=a.useState([]),d=(c=2,p(o=s)||y(o,c)||f(o,c)||v()),g=d[0],b=d[1],E=a.useRef(null),O=a.useRef(null),w=a.useRef(i.value),j=a.useRef([]),P=a.useRef(0),S=a.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(m(j.current))}},L=function(){P.current=0,j.current=[],b(m(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};n.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)))})),n.useUpdateEffect((function(){i.value&&(w.current=i.value,i.lazy||(P.current=0),j.current=[],i.lazy?(j.current=w.current,b(m(j.current))):H())}),[i.value]),n.useUpdateEffect((function(){i.loader&&A()}),[i.loader]),n.useUnmountEffect((function(){S.current&&A()})),a.useImperativeHandle(r,(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 a.createElement("li",{key:r+"_datascrollitem"},t)},z=function(){var e=l.ObjectUtils.getJSXElement(i.emptyMessage,i)||t.localeOption("emptyMessage");return a.createElement("li",null,e)},R=h.getOtherProps(i),T=l.classNames("p-datascroller p-component",i.className,{"p-datascroller-inline":i.inline}),U=i.header?a.createElement("div",{className:"p-datascroller-header"},i.header):null,_=i.footer?a.createElement("div",{className:"p-datascroller-footer"},i.footer):null,I=function(){var e=l.ObjectUtils.isNotEmpty(g)?g.map(M):z();return a.createElement("div",{ref:O,className:"p-datascroller-content",style:{maxHeight:i.scrollHeight}},a.createElement("ul",{className:"p-datascroller-list"},e))}();return a.createElement("div",u({id:i.id,ref:E,className:T},R),U,I,_)})));return g.displayName="DataScroller",e.DataScroller=g,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.api,primereact.hooks,primereact.utils);