UNPKG

@dudulu/autolist

Version:

支持虚拟列表的自动滚动消息框

3 lines 3.2 kB
/*! For license information please see index.js.LICENSE.txt */ !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("react"));else if("function"==typeof define&&define.amd)define(["react"],r);else{var t="object"==typeof exports?r(require("react")):r(e.react);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(self,(e=>(()=>{"use strict";var r={251:(e,r,t)=>{var n=t(156),o=Symbol.for("react.element"),u=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,c=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function i(e,r,t){var n,u={},i=null,f=null;for(n in void 0!==t&&(i=""+t),void 0!==r.key&&(i=""+r.key),void 0!==r.ref&&(f=r.ref),r)a.call(r,n)&&!l.hasOwnProperty(n)&&(u[n]=r[n]);if(e&&e.defaultProps)for(n in r=e.defaultProps)void 0===u[n]&&(u[n]=r[n]);return{$$typeof:o,type:e,key:i,ref:f,props:u,_owner:c.current}}r.jsx=i},893:(e,r,t)=>{e.exports=t(251)},156:r=>{r.exports=e}},t={};function n(e){var o=t[e];if(void 0!==o)return o.exports;var u=t[e]={exports:{}};return r[e](u,u.exports,n),u.exports}n.d=(e,r)=>{for(var t in r)n.o(r,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);var o={};return(()=>{n.d(o,{default:()=>f});var e=n(893),r=n(156);const t="l3TY_oc_ypOF2IC16YjL",u="WMrzprCBMwZlQc10KV5b",a="_3HUvalhJbL7nzrx2vQns";var c=function(){return c=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},c.apply(this,arguments)},l={startIndex:0,endIndex:0,bufferNum:4,limit:0,currentIndex:0};function i(e,r){return"set"===r.type?c(c({},e),r.payload):c({},e)}function f(n){var o=n.data,f=n.itemHeight,s=n.height,d=n.isAuto,p=void 0!==d&&d,v=n.style,y=n.className,h=(0,r.useRef)(null),x=(0,r.useRef)(null),m=(0,r.useRef)(0),_=(0,r.useReducer)(i,l),b=_[0],g=_[1];function j(e,r){x.current&&(x.current.style.overflowY=r)}return(0,r.useEffect)((function(){if(x.current){var e=x.current.clientHeight,r=Math.ceil(e/f);g({type:"set",payload:{endIndex:Math.min(b.startIndex+b.bufferNum+r,o.length-1),limit:r}})}}),[]),(0,r.useEffect)((function(){var e,r=null===(e=x.current)||void 0===e?void 0:e.style.overflowY,t=!r||"hidden"===r;if(p&&x.current&&t){var n=x.current,o=n.scrollHeight,u=n.scrollTop;m.current;m.current=u,x.current.scrollTo({top:o})}}),[o]),(0,e.jsx)("div",{children:(0,e.jsx)("div",c({className:"".concat(t," ").concat(null!=y?y:""),ref:x,onScroll:function(e){if(e.target===x.current){var r=e.target.scrollTop,t=Math.floor(r/f);if(t!==b.currentIndex){var n=b.bufferNum,u=b.limit,a=Math.min(t+n+u,o.length-1);g({type:"set",payload:{startIndex:Math.max(t-n,0),endIndex:a,currentIndex:t}})}}e.preventDefault()},style:c({height:s},v),onMouseEnter:function(e){return j(0,"auto")},onMouseLeave:function(e){return j(0,"hidden")}},{children:(0,e.jsx)("div",c({className:u,ref:h,style:{height:o.length*f}},{children:o.map((function(r,t){return(0,e.jsx)("div",c({className:a,style:{top:t*f,height:f}},{children:r}),t)}))}))}))})}})(),o=o.default})())); //# sourceMappingURL=index.js.map