katoikia-app/web-ui/web-react/node_modules/primereact/virtualscroller/virtualscroller.cjs.min.js

2 lines
15 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("primereact/utils");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=o(t);function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var o=0;o<e.length;o++){var s=e[o];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function n(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},l(t,e)}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function u(t,e){if(e&&("object"===c(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return n(t)}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function p(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function f(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,s)}return o}function d(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?f(Object(o),!0).forEach((function(e){p(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):f(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function m(){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(t){return!1}}var v=function(o){a(y,t.Component);var l,c,p,f,v,g=(l=y,c=m(),function(){var t,e=h(l);if(c){var o=h(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return u(this,t)});function y(t){var e;r(this,y);var o=(e=g.call(this,t)).isBoth();return e.state={first:o?{rows:0,cols:0}:0,last:o?{rows:0,cols:0}:0,numItemsInViewport:o?{rows:0,cols:0}:0,numToleratedItems:t.numToleratedItems,loading:t.loading,loaderArr:[]},e.onScroll=e.onScroll.bind(n(e)),e.lastScrollPos=o?{top:0,left:0}:0,e}return p=y,f=[{key:"scrollTo",value:function(t){this.el&&this.el.scrollTo(t)}},{key:"scrollToIndex",value:function(t){var e=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auto",s=this.isBoth(),r=this.isHorizontal(),i=this.state.first,n=this.calculateNumItems(),l=n.numToleratedItems,a=this.props.itemSize,c=this.getContentPosition(),u=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1?arguments[1]:void 0;return t<=e?0:t},h=function(t,e,o){return t*e+o},p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.scrollTo({left:t,top:s,behavior:o})};if(s){var f={rows:u(t[0],l[0]),cols:u(t[1],l[1])};f.rows===i.rows&&f.cols===i.cols||(p(h(f.cols,a[1],c.left),h(f.rows,a[0],c.top)),this.setState({first:f}))}else{var d=u(t,l);d!==i&&(r?p(h(d,a,c.left),0):p(0,h(d,a,c.top)),this.setState({first:d}))}}},{key:"scrollInView",value:function(t,e){var o=this,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"auto";if(e){var r=this.isBoth(),i=this.isHorizontal(),n=this.getRenderedRange(),l=n.first,a=n.viewport,c=this.props.itemSize,u=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return o.scrollTo({left:t,top:e,behavior:s})},h="to-start"===e,p="to-end"===e;if(h){if(r)a.first.rows-l.rows>t[0]?u(a.first.cols*c,(a.first.rows-1)*c):a.first.cols-l.cols>t[1]&&u((a.first.cols-1)*c,a.first.rows*c);else if(a.first-l>t){var f=(a.first-1)*c;i?u(f,0):u(0,f)}}else if(p)if(r)a.last.rows-l.rows<=t[0]+1?u(a.first.cols*c,(a.first.rows+1)*c):a.last.cols-l.cols<=t[1]+1&&u((a.first.cols+1)*c,a.first.rows*c);else if(a.last-l<=t+1){var d=(a.first+1)*c;i?u(d,0):u(0,d)}}else this.scrollToIndex(t,s)}},{key:"getRows",value:function(){return this.state.loading?this.props.loaderDisabled?this.state.loaderArr:[]:this.loadedItems()}},{key:"getColumns",value:function(){if(this.props.columns){var t=this.isBoth(),e=this.isHorizontal();if(t||e)return this.state.loading&&this.props.loaderDisabled?t?this.state.loaderArr[0]:this.state.loaderArr:this.props.columns.slice(t?this.state.first.cols:this.state.first,t?this.state.last.cols:this.state.last)}return this.props.columns}},{key:"getRenderedRange",value:function(){var t=this.isBoth(),e=this.isHorizontal(),o=this.state,s=o.first,r=o.last,i=o.numItemsInViewport,n=this.props.itemSize,l=function(t,e){return Math.floor(t/(e||t))},a=s,c=0;if(this.el){var u=this.el.scrollTop,h=this.el.scrollLeft;c=t?{rows:(a={rows:l(u,n[0]),cols:l(h,n[1])}).rows+i.rows,cols:a.cols+i.cols}:(a=l(e?h:u,n))+i}return{first:s,last:r,viewport:{first:a,last:c}}}},{key:"isVertical",value:function(){return"vertical"===this.props.orientation}},{key:"isHorizontal",value:function(){return"horizontal"===this.props.orientation}},{key:"isBoth",value:function(){return"both"===this.props.orientation}},{key:"calculateNumItems",value:function(){var t=this.isBoth(),e=this.isHorizontal(),o=this.props.itemSize,s=this.getContentPosition(),r=this.el?this.el.offsetWidth-s.left:0,i=this.el?this.el.offsetHeight-s.top:0,n=function(t,e){return Math.ceil(t/(e||t))},l=function(t){return Math.ceil(t/2)},a=t?{rows:n(i,o[0]),cols:n(r,o[1])}:n(e?r:i,o);return{numItemsInViewport:a,numToleratedItems:this.state.numToleratedItems||(t?[l(a.rows),l(a.cols)]:l(a))}}},{key:"calculateOptions",value:function(){var t=this,e=this.isBoth(),o=this.state.first,s=this.calculateNumItems(),r=s.numItemsInViewport,i=s.numToleratedItems,n=function(e,o,s,r){return t.getLast(e+o+(e<s?2:3)*s,r)},l=e?{rows:n(o.rows,r.rows,i[0]),cols:n(o.cols,r.cols,i[1],!0)}:n(o,r,i),a={numItemsInViewport:r,last:l,numToleratedItems:i};this.props.showLoader&&(a.loaderArr=e?Array.from({length:r.rows}).map((function(){return Array.from({length:r.cols})})):Array.from({length:r})),this.setState(a,(function(){t.props.lazy&&t.props.onLazyLoad&&t.props.onLazyLoad({first:t.state.first,last:t.state.last})}))}},{key:"getLast",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1?arguments[1]:void 0;return this.props.items?Math.min(e?(this.props.columns||this.props.items[0]).length:this.props.items.length,t):0}},{key:"getContentPosition",value:function(){if(this.content){var t=getComputedStyle(this.content),e=parseInt(t.paddingLeft,10)+Math.max(parseInt(t.left,10),0),o=parseInt(t.paddingRight,10)+Math.max(parseInt(t.right,10),0),s=parseInt(t.paddingTop,10)+Math.max(parseInt(t.top,10),0),r=parseInt(t.paddingBottom,10)+Math.max(parseInt(t.bottom,10),0);return{left:e,right:o,top:s,bottom:r,x:e+o,y:s+r}}return{left:0,right:0,top:0,bottom:0,x:0,y:0}}},{key:"setSize",value:function(){var t=this;if(this.el){var e=this.isBoth(),o=this.isHorizontal(),s=this.el.parentElement,r=this.props.scrollWidth||"".concat(this.el.offsetWidth||s.offsetWidth,"px"),i=this.props.scrollHeight||"".concat(this.el.offsetHeight||s.offsetHeight,"px"),n=function(e,o){return t.el.style[e]=o};e||o?(n("height",i),n("width",r)):n("height",i)}}},{key:"setSpacerSize",value:function(){var t=this,e=this.props.items;if(this.spacer&&e){var o=this.isBoth(),s=this.isHorizontal(),r=this.props.itemSize,i=this.getContentPosition(),n=function(e,o,s){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return t.spacer.style[e]=(o||[]).length*s+r+"px"};o?(n("height",e,r[0],i.y),n("width",this.props.columns||e[1],r[1],i.x)):s?n("width",this.props.columns||e,r,i.x):n("height",e,r,i.y)}}},{key:"setContentPosition",value:function(t){var e=this;if(this.content){var o=this.isBoth(),s=this.isHorizontal(),r=t?t.first:this.state.first,i=this.props.itemSize,n=function(t,e){return t*e},l=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;e.sticky&&(e.sticky.style.top="-".concat(o,"px")),e.content.style.transform="translate3d(".concat(t,"px, ").concat(o,"px, 0)")};if(o)l(n(r.cols,i[1]),n(r.rows,i[0]));else{var a=n(r,i);s?l(a,0):l(0,a)}}}},{key:"onScrollPositionChange",value:function(t){var e=this,o=t.target,s=this.isBoth(),r=this.isHorizontal(),i=this.state,n=i.first,l=i.last,a=i.numItemsInViewport,c=i.numToleratedItems,u=this.props.itemSize,h=this.getContentPosition(),p=function(t,e){return t?t>e?t-e:t:0},f=function(t,e){return Math.floor(t/(e||t))},d=function(t,e,o,s,r,i){return t<=r?r:i?o-s-r:e+r-1},m=function(t,e,o,s,r,i,n){return t<=i?0:Math.max(0,n?t<e?o:t-i:t>e?o:t-2*i)},v=function(t,o,s,r,i,n){var l=o+r+2*i;return t>=i&&(l+=i+1),e.getLast(l,n)},g=p(o.scrollTop,h.top),y=p(o.scrollLeft,h.left),w=0,b=l,S=!1;if(s){var I=this.lastScrollPos.top<=g,O=this.lastScrollPos.left<=y,k={rows:f(g,u[0]),cols:f(y,u[1])},z={rows:d(k.rows,n.rows,l.rows,a.rows,c[0],I),cols:d(k.cols,n.cols,l.cols,a.cols,c[1],O)};w={rows:m(k.rows,z.rows,n.rows,0,0,c[0],I),cols:m(k.cols,z.cols,n.cols,0,0,c[1],O)},b={rows:v(k.rows,w.rows,0,a.rows,c[0]),cols:v(k.cols,w.cols,0,a.cols,c[1],!0)},S=w.rows!==n.rows&&b.rows!==l.rows||w.cols!==n.cols&&b.cols!==l.cols,this.lastScrollPos={top:g,left:y}}else{var P=r?y:g,T=this.lastScrollPos<=P,j=f(P,u);b=v(j,w=m(j,d(j,n,l,a,c,T),n,0,0,c,T),0,a,c),S=w!==n&&b!==l,this.lastScrollPos=P}return{first:w,last:b,isRangeChanged:S}}},{key:"onScrollChange",value:function(t){var e=this,o=this.onScrollPositionChange(t);if(o.isRangeChanged){var s={first:o.first,last:o.last};this.setContentPosition(s),this.setState(s,(function(){e.props.onScrollIndexChange&&e.props.onScrollIndexChange(s),e.props.lazy&&e.props.onLazyLoad&&e.props.onLazyLoad(s)}))}}},{key:"onScroll",value:function(t){var e=this;this.props.onScroll&&this.props.onScroll(t),this.props.delay?(this.scrollTimeout&&clearTimeout(this.scrollTimeout),!this.state.loading&&this.props.showLoader&&this.onScrollPositionChange(t).isRangeChanged&&this.setState({loading:!0}),this.scrollTimeout=setTimeout((function(){e.onScrollChange(t),e.state.loading&&e.props.showLoader&&!e.props.lazy&&e.setState({loading:!1})}),this.props.delay)):this.onScrollChange(t)}},{key:"getOptions",value:function(t){var e=this.state.first,o=(this.props.items||[]).length,s=this.isBoth()?e.rows+t:e+t;return{index:s,count:o,first:0===s,last:s===o-1,even:s%2==0,odd:s%2!=0,props:this.props}}},{key:"loaderOptions",value:function(t,e){var o=this.state.loaderArr.length;return d({index:t,count:o,first:0===t,last:t===o-1,even:t%2==0,odd:t%2!=0,props:this.props},e)}},{key:"loadedItems",value:function(){var t=this,e=this.props.items;if(e&&!this.state.loading){var o=this.isBoth(),s=this.isHorizontal(),r=this.state,i=r.first,n=r.last;return o?e.slice(i.rows,n.rows).map((function(e){return t.props.columns?e:e.slice(i.cols,n.cols)})):s&&this.props.columns?e:e.slice(i,n)}return[]}},{key:"isPropChanged",value:function(t){var o=this;return["itemSize","scrollHeight"].some((function(s){return!e.ObjectUtils.equals(t[s],o.props[s])}))}},{key:"init",value:function(){this.setSize(),this.calculateOptions(),this.setSpacerSize()}},{key:"componentDidMount",value:function(){this.init()}},{key:"componentDidUpdate",value:function(t,e){t.items&&t.items.length===(this.props.items||[]).length&&!this.isPropChanged(t)||this.init(),this.props.lazy&&t.loading!==this.props.loading&&this.state.loading!==this.props.loading&&this.setState({loading:this.props.loading}),t.orientation!==this.props.orientation&&(this.lastScrollPos=this.isBoth()?{top:0,left:0}:0)}},{key:"renderLoaderItem",value:function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.loaderOptions(t,o),i=e.ObjectUtils.getJSXElement(this.props.loadingTemplate,r);return s.default.createElement(s.default.Fragment,{key:t},i)}},{key:"renderLoader",value:function(){var t=this;if(!this.props.loaderDisabled&&this.props.showLoader&&this.state.loading){var o=e.classNames("p-virtualscroller-loader",{"p-component-overlay":!this.props.loadingTemplate}),r=s.default.createElement("i",{className:"p-virtualscroller-loading-icon pi pi-spinner pi-spin"});if(this.props.loadingTemplate){var i=this.isBoth(),n=this.state.numItemsInViewport;r=this.state.loaderArr.map((function(e,o){return t.renderLoaderItem(o,i&&{numCols:n.cols})}))}return s.default.createElement("div",{className:o},r)}return null}},{key:"renderSpacer",value:function(){var t=this;return this.props.showSpacer?s.default.createElement("div",{ref:function(e){return t.spacer=e},className:"p-virtualscroller-spacer"}):null}},{key:"renderItem",value:function(t,o){var r=this.getOptions(o),i=e.ObjectUtils.getJSXElement(this.props.itemTemplate,t,r);return s.default.createElement(s.default.Fragment,{key:r.index},i)}},{key:"renderItems",value:function(t){var e=this;return t.map((function(t,o){return e.renderItem(t,o)}))}},{key:"renderContent",value:function(){var t=this,o=this.loadedItems(),r=this.renderItems(o),i=e.classNames("p-virtualscroller-content",{"p-virtualscroller-loading":this.state.loading}),n=s.default.createElement("div",{className:i,ref:function(e){return t.content=e}},r);if(this.props.contentTemplate){var l={className:i,contentRef:function(e){return t.content=e},spacerRef:function(e){return t.spacer=e},stickyRef:function(e){return t.sticky=e},items:o,getItemOptions:function(e){return t.getOptions(e)},children:r,element:n,props:this.props,loading:this.state.loading,getLoaderOptions:function(e,o){return t.loaderOptions(e,o)},loadingTemplate:this.props.loadingTemplate,itemSize:this.props.itemSize,rows:this.getRows(),columns:this.getColumns(),vertical:this.isVertical(),horizontal:this.isHorizontal(),both:this.isBoth()};return e.ObjectUtils.getJSXElement(this.props.contentTemplate,l)}return n}},{key:"render",value:function(){var t=this;if(this.props.disabled){var o=e.ObjectUtils.getJSXElement(this.props.contentTemplate,{items:this.props.items,rows:this.props.items,columns:this.props.columns});return s.default.createElement(s.default.Fragment,null,this.props.children,o)}var r=this.isBoth(),i=this.isHorizontal(),n=e.classNames("p-virtualscroller",{"p-both-scroll":r,"p-horizontal-scroll":i},this.props.className),l=this.renderLoader(),a=this.renderContent(),c=this.renderSpacer();return s.default.createElement("div",{ref:function(e){return t.el=e},className:n,tabIndex:0,style:this.props.style,onScroll:this.onScroll},a,c,l)}}],f&&i(p.prototype,f),v&&i(p,v),Object.defineProperty(p,"prototype",{writable:!1}),y}();p(v,"defaultProps",{id:null,style:null,className:null,items:null,itemSize:0,scrollHeight:null,scrollWidth:null,orientation:"vertical",numToleratedItems:null,delay:0,lazy:!1,disabled:!1,loaderDisabled:!1,columns:null,loading:!1,showSpacer:!0,showLoader:!1,loadingTemplate:null,itemTemplate:null,contentTemplate:null,onScroll:null,onScrollIndexChange:null,onLazyLoad:null}),exports.VirtualScroller=v;