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) 2.06 kB
import*as t from"react";import{PrimeReactContext as r}from"primereact/api";import{useMergeProps as e,useEventListener as n,useMountEffect as o}from"primereact/hooks";import{ComponentBase as a}from"primereact/componentbase";function i(t){if(Array.isArray(t))return t}function u(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,a,i,u=[],l=!0,c=!1;try{if(a=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;l=!1}else for(;!(l=(n=a.call(e)).done)&&(u.push(n.value),u.length!==r);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}function l(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function c(t,r){if(t){if("string"==typeof t)return l(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?l(t,r):void 0}}function f(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(t,r){return i(t)||u(t,r)||c(t,r)||f()}var s=a.extend({defaultProps:{__TYPE:"DeferredContent",onload:null,children:void 0}}),d=t.forwardRef((function(a,i){var u=e(),l=t.useContext(r),c=s.getProps(a,l),f=m(t.useState(!1),2),d=f[0],p=f[1],y=t.useRef(null),v=m(n({target:"window",type:"scroll",listener:function(){w()&&(A(),g())}}),2),h=v[0],g=v[1],b=s.setMetaData({props:c,state:{loaded:d}}).ptm,w=function(){if(d)return!1;var t=y.current.getBoundingClientRect();return document.documentElement.clientHeight>=t.top},A=function(t){p(!0),c.onLoad&&c.onLoad(t)};t.useImperativeHandle(i,(function(){return{props:c,getElement:function(){return y.current}}})),o((function(){d||(w()?A():h())}));var S=u({ref:y},s.getOtherProps(c),b("root"));return t.createElement("div",S,d&&c.children)}));d.displayName="DeferredContent";export{d as DeferredContent};