Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rc-hooks

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-hooks - npm Package Compare versions

Comparing version 3.0.5 to 3.0.6

2

dist/rcHooks.min.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).rcHooks={},t.React)}(this,(function(t,e){"use strict";var n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};var r=function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function o(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function u(t){var n=e.useRef(t);return n.current=t,n}function c(t){var n=u(t),r=e.useCallback((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.current;return null==r?void 0:r.apply(void 0,t)}),[]);return r}"function"==typeof SuppressedError&&SuppressedError;var a=function(t,n){var r=e.useRef(!1);e.useEffect((function(){if(r.current)return t();r.current=!0}),n)},s=function(){function t(){this.handler={}}return t.prototype.eventNames=function(){return Object.keys(this.handler)},t.prototype.listeners=function(t){return this.handler[t]||[]},t.prototype.hasListener=function(t,e){return this.listeners(t).some((function(t){return t===e}))},t.prototype.on=function(t,e){return this.handler[t]?this.hasListener(t,e)||this.handler[t].push(e):this.handler[t]=[e],this},t.prototype.off=function(t,e){return this.handler[t]&&("function"==typeof e?this.handler[t]=this.handler[t].filter((function(t){return t!==e})):delete this.handler[t]),this},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this.listeners(t);return r.length>0&&(r.forEach((function(t){t.apply(void 0,e)})),!0)},t.prototype.once=function(t,e){var n=this,r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e.apply(void 0,o),n.off(t,r)};return this.on(t,r)},t.prototype.offAll=function(){return this.handler={},this},t}(),l={},f={getItem:function(t){return l[t]||null},setItem:function(t,e){l[t]=e},removeItem:function(t){delete l[t]}};var d=1;function h(t,e){void 0===t&&(t=""),void 0===e&&(e="cache2");var n="string"==typeof t&&t?t:"".concat(Math.random().toString(16).substring(2,8),"_").concat(d++);return"".concat(e,"_").concat(n)}var p=new(function(t){function e(e,n){var o,i,u=t.call(this)||this;return"string"==typeof e?o=e:"object"==typeof e&&(i=e),i||"object"!=typeof n||(i=n),u.options=r({max:-1,stdTTL:0,storage:f,maxStrategy:"limited",checkperiod:0,needParsed:"boolean"==typeof(null==i?void 0:i.needParsed)?i.needParsed:!!(null==i?void 0:i.storage)},i),u.options.storage===f||function(t){try{var e="object"==typeof t&&null!==t&&!!t.setItem&&!!t.getItem&&!!t.removeItem;if(e){var n=h();t.setItem(n,"1"),t.removeItem(n)}return e}catch(t){return console.error("[cache2] The current custom storage is not supported. The default memory cache will be used."),!1}}(u.options.storage)||(u.options.storage=f,u.options.needParsed=!1),u.cacheKey=h(o),u.startCheckperiod(),u}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e.prototype._check=function(t,e){var n=!0;return 0!==e.t&&e.t<Date.now()&&(n=!1,this.del(t),this.emit("expired",t,e.v)),n},e.prototype._wrap=function(t,e){var n=Date.now(),r="number"==typeof e?e:this.options.stdTTL;return{v:t,t:r>0?n+r:0,n:n}},e.prototype._isLimited=function(t){return this.options.max>-1&&t>=this.options.max},e.prototype._getReplaceKey=function(t,e){var n=t[0];return t.forEach((function(t){(e[t].t<e[n].t||e[t].t===e[n].t&&e[t].n<e[n].n)&&(n=t)})),n},e.prototype._parse=function(t){if(!this.options.needParsed)return t;try{return JSON.parse(t,this.options.reviver)}catch(e){return t}},e.prototype._stringify=function(t){return this.options.needParsed?JSON.stringify(t,this.options.replacer):t},Object.defineProperty(e.prototype,"cacheValues",{get:function(){return this._parse(this.options.storage.getItem(this.cacheKey))||{}},enumerable:!1,configurable:!0}),e.prototype.setCacheValues=function(t){this.options.storage.setItem(this.cacheKey,this._stringify(t))},e.prototype.get=function(t){var e=this.cacheValues[t];if(e&&this._check(t,e))return e.v},e.prototype.mget=function(t){var e=this,n={};if(!Array.isArray(t))return n;var r=this.cacheValues;return t.forEach((function(t){var o=r[t];o&&e._check(t,o)&&(n[t]=o.v)})),n},e.prototype.getAll=function(){var t=Object.keys(this.cacheValues);return this.mget(t)},e.prototype.set=function(t,e,n){if(0===this.options.max)return!1;var r=this.cacheValues,o=Object.keys(r);if(!r[t]&&this._isLimited(o.length)){var i=this.keys();if(this._isLimited(i.length)){if("replaced"!==this.options.maxStrategy)return!1;var u=this._getReplaceKey(i,r);this.del(u)}}return r[t]=this._wrap(e,n),this.setCacheValues(r),this.emit("set",t,r[t].v),!0},e.prototype.mset=function(t){var e=this,n=!0;return t.forEach((function(t){var r=e.set(t.key,t.value,t.ttl);n&&!r&&(n=!1)})),n},e.prototype.del=function(t){var e=this,n=this.cacheValues,r=0;return(Array.isArray(t)?t:[t]).forEach((function(t){if(n[t]){r++;var o=n[t];delete n[t],e.emit("del",t,o.v)}})),r>0&&this.setCacheValues(n),r},e.prototype.clear=function(){this.options.storage.removeItem(this.cacheKey)},e.prototype.keys=function(){var t=this,e=this.cacheValues;return Object.keys(e).filter((function(n){return t._check(n,e[n])}))},e.prototype.has=function(t){var e=this.cacheValues[t];return!(!e||!this._check(t,e))},e.prototype.take=function(t){var e,n=this.cacheValues[t];return n&&this._check(t,n)&&(e=n.v,this.del(t)),e},e.prototype.ttl=function(t,e){var n=this.cacheValues,r=n[t];return!(!r||!this._check(t,r))&&(n[t]=this._wrap(r.v,e),!0)},e.prototype.getTtl=function(t){var e=this.cacheValues,n=e[t];if(n&&this._check(t,n))return e[t].t},e.prototype.startCheckperiod=function(){var t=this;this.keys(),this.options.checkperiod>0&&(clearTimeout(this._checkTimeout),this._checkTimeout=setTimeout((function(){t.startCheckperiod()}),this.options.checkperiod))},e.prototype.stopCheckperiod=function(){clearTimeout(this._checkTimeout)},e}(s))({stdTTL:3e5}),v=function(t){return p.get(t)};var y="object"==typeof globalThis&&globalThis&&globalThis.Object===Object&&globalThis,g="object"==typeof global&&global&&global.Object===Object&&global,m="object"==typeof self&&self&&self.Object===Object&&self;y||g||m||Function("return this")();var b=Object.prototype,w=b.toString,T=b.hasOwnProperty,k=Function.prototype.toString;k.call(Object);var S=Symbol?Symbol.prototype:void 0;S&&S.valueOf,S&&S.toString;var E=Symbol?Symbol.toStringTag:void 0;function O(t){if(null!==t){try{return k.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var _="[object DataView]",j="[object Map]",C="[object Promise]",P="[object Set]",R="[object WeakMap]",L="undefined"!=typeof DataView,I="undefined"!=typeof Map,A="undefined"!=typeof Promise,M="undefined"!=typeof Set,V="undefined"!=typeof WeakMap,D=function(t,e){return t?e:""},N=D(L,O(DataView)),F=D(I,O(Map)),x=D(A,O(Promise)),W=D(M,O(Set)),z=D(V,O(WeakMap));function H(t){return E&&E in Object(t)?function(t){var e=T.call(t,E),n=t[E],r=!1;try{t[E]=void 0,r=!0}catch(t){}var o=w.call(t);return r&&(e?t[E]=n:delete t[E]),o}(t):w.call(t)}var K=H;(L&&w.call(new DataView(new ArrayBuffer(1)))!==_||I&&w.call(new Map)!==j||A&&w.call(Promise.resolve())!==C||M&&w.call(new Set)!==P||V&&w.call(new WeakMap)!==R)&&(K=function(t){var e=H(t),n="[object Object]"===e?t.constructor:void 0,r=n?O(n):"";if(r)switch(r){case N:return _;case F:return j;case x:return C;case W:return P;case z:return R}return e});var U=K;function B(t,e){var n=U(t);return"string"==typeof e?n==="[object "+e+"]":e.some((function(t){return n==="[object "+t+"]"}))}var $=/^0b[01]+$/i,J=/^0o[0-7]+$/i,q=/^[-+]0x[0-9a-f]+$/i;function Y(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return null!=t&&"object"==typeof t}(t)&&B(t,"Symbol")}(t))return NaN;if(function(t){var e=typeof t;return null!=t&&("object"===e||"function"===e)}(t)&&(t=Number(t)),"string"!=typeof t)return 0===t?t:+t;t=t.trim();var e=$.test(t);return e||J.test(t)?parseInt(t.slice(2),e?2:8):q.test(t)?NaN:+t}B(function(){return arguments}(),"Arguments");var G="Expected a function";function Q(t,e,n,r){if(void 0===r&&(r=!1),"function"!=typeof t)throw new TypeError(G);var o,i,u,c,a,s,l,f;function d(e){return u=e,s=t.apply(a,c),a=c=void 0,s}function h(){for(var t=[],l=0;l<arguments.length;l++)t[l]=arguments[l];a=this,c=t;var f=Date.now(),h=function(t){if(void 0===i)return!0;var n=t-i;return n>=e||n<0||r&&t-u>=e}(f),p=r?h||void 0===i||void 0!==o?e:e-(f-i):e;return i=f,h&&n&&void 0===o?d(f):(void 0===o||r||(clearTimeout(o),o=void 0),void 0===o&&(o=setTimeout((function(){o=void 0,d(Date.now())}),p)),s)}return l=Y(e),f=0,e=null==l||l!=l?f:l,h.cancel=function(){void 0!==o&&(clearTimeout(o),o=void 0),i=o=c=a=void 0},h.flush=function(){return void 0!==o&&(clearTimeout(o),o=void 0,c)?d(Date.now()):s},h.pending=function(){return void 0!==o},h}function X(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!1),Q(t,e,n)}function Z(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!0),Q(t,e,n,!0)}function tt(t){return arguments.length?function(t){return Array.isArray(t)}(t)?t:[t]:[]}function et(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var nt=[];var rt=!1;if("undefined"!=typeof window&&window.addEventListener&&!rt){window.addEventListener("visibilitychange",(function(){if(et())for(var t=0;t<nt.length;t++){(0,nt[t])()}}),!1),rt=!0}var ot=[];var it=!1;if("undefined"!=typeof window&&window.addEventListener&&!it){var ut=function(){if(et()&&("undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine))for(var t=0;t<ot.length;t++){(0,ot[t])()}};window.addEventListener("visibilitychange",ut,!1),window.addEventListener("focus",ut,!1),it=!0}var ct={},at=function(){function t(t,e){this.params=[],this.pollingWhenVisibleFlag=!1,this.pollingTimer=null,this.counter=1,this.destroyed=!1,this.async=t,this.options=r({cacheTime:3e5,persisted:!1,pollingWhenHidden:!0,refreshOnWindowFocus:!1,focusTimespan:5e3},e),this.unsubscribes=[],this.init()}return t.prototype.init=function(){var t,e,n,r,o=this.options,i=o.pollingInterval,u=o.refreshOnWindowFocus,c=o.focusTimespan;if(this.updateDebounce(),i&&this.unsubscribes.push((t=this.rePolling.bind(this),nt.push(t),function(){var e=nt.indexOf(t);nt.splice(e,1)})),u){var a=(e=this.refresh.bind(this),n=c,r=!1,function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];r||(r=!0,e.apply(void 0,t),setTimeout((function(){r=!1}),n))});this.unsubscribes.push(function(t){return ot.push(t),function(){var e=ot.indexOf(t);ot.splice(e,1)}}(a))}},t.prototype.updateDebounce=function(){var t=this.options,e=t.debounceInterval,n=t.throttleInterval;this.debounce="number"==typeof e&&e>0?X(this._run,e):void 0,this.throttle="number"==typeof n&&n>0?Z(this._run,n):void 0},t.prototype.rePolling=function(){this.pollingWhenVisibleFlag&&(this.pollingWhenVisibleFlag=!1,this.refresh())},t.prototype.afterUpdateOptions=function(t,e){void 0===e&&(e={}),("debounceInterval"in e&&e.debounceInterval!==t.debounceInterval||"throttleInterval"in e&&e.throttleInterval!==t.throttleInterval)&&this.updateDebounce()},t.prototype.updateOptions=function(t){var e=this.options,n=r(r({},this.options),t);this.options=n,this.afterUpdateOptions(e,n)},t.prototype._run=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.pollingTimer&&clearTimeout(this.pollingTimer);var r=this.counter;this.params=e;var o=this.options,i=o.cacheKey,u=o.cacheTime,c=o.persisted,a=o.formatResult,s=o.onSuccess,l=o.onError,f=o.onFinally,d=o.onBefore,h=o.pollingWhenHidden,y=o.pollingInterval;return null==d||d(e),new Promise((function(n,o){if(i&&c){var d=v(i);if(d&&r===t.counter)return void Promise.resolve().then((function(){null==s||s(d,e),n(d)})).finally((function(){null==f||f()}))}var g,m;(g=function(){return t.async.apply(t,e)},m=i,m&&ct[m]?ct[m]:m?(ct[m]=g().then((function(t){return delete ct[m],t})).catch((function(t){return delete ct[m],Promise.reject(t)})),ct[m]):g()).then((function(o){if(r===t.counter){var c="function"==typeof a?a(o,e):o;i&&function(t,e,n){p.set(t,e,n)}(i,c,u),null==s||s(c,e),n(c)}})).catch((function(n){r===t.counter&&(null==l||l(n,e),o(n))})).finally((function(){if(r===t.counter&&(null==f||f(),y)){if(!et()&&!h)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout((function(){t.run.apply(t,e)}),y)}}))}))},t.prototype.run=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this.debounce?(this.debounce.apply(this,t),Promise.resolve(null)):this.throttle?(this.throttle.apply(this,t),Promise.resolve(null)):(this.counter+=1,this._run.apply(this,t))},t.prototype.refresh=function(){return this.run.apply(this,this.params)},t.prototype.cancel=function(){this.debounce&&this.debounce.cancel(),this.throttle&&this.throttle.cancel(),this.pollingTimer&&(clearTimeout(this.pollingTimer),this.pollingTimer=null),this.counter+=1},t.prototype.destroy=function(t){void 0===t&&(t=!0),t&&this.cancel(),this.destroyed||(this.destroyed=!0,this.unsubscribes.forEach((function(t){return t()})),this.unsubscribes=[])},t.prototype.resume=function(){this.destroyed&&(this.destroyed=!1,this.init())},t}(),st=function(){};function lt(t,n){var o=n||{},s=o.autoRun,l=void 0===s||s,f=o.refreshDeps,d=void 0===f?[]:f,h=o.defaultParams,p=o.loadingDelay,y=o.__INTERNAL_FORMAT__,g=o.defaultLoading,m=void 0!==g&&g,b=o.initialData,w=o.cacheKey,T=void 0===w?"":w,k=o.cacheTime,S=void 0===k?3e5:k,E=o.persisted,O=void 0!==E&&E,_=o.onSuccess,j=void 0===_?st:_,C=o.onError,P=void 0===C?st:C,R=o.onFinally,L=void 0===R?st:R,I=o.onBefore,A=void 0===I?st:I,M=o.pollingInterval,V=void 0===M?0:M,D=o.pollingWhenHidden,N=void 0===D||D,F=o.refreshOnWindowFocus,x=void 0!==F&&F,W=o.focusTimespan,z=void 0===W?5e3:W,H=o.debounceInterval,K=o.throttleInterval,U=i(e.useState({params:[],loading:m,error:null,data:T?v(T):b}),2),B=U[0],$=U[1],J=e.useRef(null),q=c(t),Y=c(j),G=c(P),Q=c(L),X=c(A),Z=u(y),tt=e.useCallback((function(t){X(t),J.current&&clearTimeout(J.current),(T?v(T):void 0)&&O||($((function(e){return r(r({},e),{loading:!p,params:t})})),p&&(J.current=setTimeout((function(){$((function(t){return r(r({},t),{loading:!0})}))}),p)))}),[T,p,X,O]),et=e.useCallback((function(t,e){J.current&&clearTimeout(J.current),$((function(e){return r(r({},e),{data:t,error:null,loading:!1})})),Y(t,e)}),[Y]),nt=e.useCallback((function(t,e){J.current&&clearTimeout(J.current),$((function(e){return r(r({},e),{error:t,loading:!1})})),G(t,e)}),[G]),rt=e.useRef();rt.current||(rt.current=new at(q,{cacheKey:T,cacheTime:S,persisted:O,formatResult:Z.current,onSuccess:et,onError:nt,onFinally:Q,onBefore:tt,debounceInterval:H,throttleInterval:K,pollingInterval:V,pollingWhenHidden:N,refreshOnWindowFocus:x,focusTimespan:z})),a((function(){rt.current.updateOptions({cacheKey:T,cacheTime:S,persisted:O,formatResult:Z.current,onSuccess:et,onError:nt,onFinally:Q,onBefore:tt,debounceInterval:H,throttleInterval:K,pollingInterval:V,pollingWhenHidden:N,refreshOnWindowFocus:x,focusTimespan:z})}),[Y,G,T,S,O,H,K,Q,X,V,N,x,z,et,nt,tt]);var ot=e.useCallback((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return rt.current.run.apply(rt.current,t)}),[]),it=e.useCallback((function(){return rt.current.refresh()}),[]),ut=e.useCallback((function(){rt.current.cancel(),J.current&&clearTimeout(J.current),$((function(t){return r(r({},t),{loading:!1})}))}),[]);return a((function(){l&&Array.isArray(d)&&d.length>0&&it()}),[l].concat(d)),e.useEffect((function(){if(l){var t=Array.isArray(h)?h:void 0!==h?[h]:[];ot.apply(void 0,t)}return rt.current.resume(),function(){ut(),rt.current.destroy(!1)}}),[]),r(r({},B),{run:ot,cancel:ut,mutate:function(t){$("function"==typeof t?function(e){return r(r({},e),{data:t(B.data)})}:function(e){return r(r({},e),{data:t})})},refresh:it})}var ft=function(t){return null!=t&&t===(null==t?void 0:t.window)};function dt(t){return"function"==typeof t?t():t}var ht=function(t){var n=void 0===t?{}:t,r=n.target,o=n.threshold,i=void 0===o?100:o,u=n.onScrollLower,a=c(void 0===u?function(){}:u),s=e.useCallback((function(){if(r){var t,e=dt(r);if(e)void 0===(t=e)&&(t=window),("undefined"==typeof window?0:ft(t)?document.documentElement.scrollHeight:t.scrollHeight)-function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:ft(t)?window.scrollY:(null==t?void 0:t.scrollTop)||0}(e)<=function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:ft(t)?document.documentElement.clientHeight:t.clientHeight}(e)+i&&a()}}),[a,r,i]);e.useEffect((function(){if(r){var t=dt(r);if(t)return t.addEventListener("scroll",s),function(){t.removeEventListener("scroll",s)}}}),[r,s])};var pt=function(t){var n=u(t);e.useEffect((function(){return function(){return n.current()}}),[])};function vt(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=u(t),i=e.useRef(X((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return pt((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}function yt(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=u(t),i=e.useRef(Z((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return pt((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}var gt=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!0,function(){t.current=!1}}),[]),t};var mt=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!1,function(){t.current=!0}}),[]),t};function bt(t){var n=mt(),r=i(e.useState(t),2),o=r[0],u=r[1];return[o,e.useCallback((function(t){n.current||u(t)}),[])]}function wt(t){return"function"==typeof t?t():"object"==typeof t&&t&&"current"in t?t.current:t}var Tt="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,kt=["top","right","bottom","left","width","height","size","weight"],St={characterData:!0,childList:!0,attributes:!0,subtree:!0},Et=function(t){var e=this;this.refresh=function(){e.targetNode&&e.callback([{target:e.targetNode}],{})},this.onTransitionEnd_=function(t){var n=t.propertyName,r=void 0===n?"":n;kt.some((function(t){return r.indexOf(t)>-1}))&&e.throttleRefresh()},this.observe=function(t,n){Tt&&(e.targetNode=t,document.addEventListener("transitionend",e.onTransitionEnd_),window.addEventListener("resize",e.throttleRefresh),e.observer.observe(document,r(r({},St),n)))},this.disconnect=function(){Tt&&(e.throttleRefresh.cancel(),e.targetNode=null,document.removeEventListener("transitionend",e.onTransitionEnd_),window.removeEventListener("resize",e.throttleRefresh),e.observer.disconnect())},this.throttleRefresh=Z(this.refresh,50),this.targetNode=null,this.callback=t,this.observer=new MutationObserver(this.throttleRefresh)};t.clearCache=function(t){t?p.del(t):p.clear()},t.useAsync=lt,t.useClickAway=function(t,n,r){void 0===r&&(r="click");var o=tt(t),i=u(o),c=o.every((function(t){return"function"==typeof t})),a=c?i:o,s=u(n),l=tt(r),f=u(l),d=l.join("");e.useEffect((function(){var t=function(t){var e;(c?a.current:a).some((function(e){var n=wt(e);return!n||(null==n?void 0:n.contains(t.target))}))||null===(e=s.current)||void 0===e||e.call(s,t)},e=tt(f.current);return e.forEach((function(e){document.addEventListener(e,t)})),function(){e.forEach((function(e){document.removeEventListener(e,t)}))}}),[a,c,d])},t.useControllableValue=function(t,n){void 0===t&&(t={}),void 0===n&&(n={});var r=n.defaultValue,o=n.defaultValuePropName,u=void 0===o?"defaultValue":o,c=n.valuePropName,s=void 0===c?"value":c,l=n.trigger,f=void 0===l?"onChange":l,d=s in t,h=t[s],p=i(e.useState((function(){return d?h:u in t?t[u]:r})),2),v=p[0],y=p[1];a((function(){d&&y(h)}),[h,d]);var g=e.useCallback((function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];d||y(e),t[f]&&t[f].apply(t,[e].concat(n))}),[d,t,f]);return[d?h:v,g]},t.useDebounce=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=i(e.useState(t),2),u=o[0],c=vt(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useDebounceFn=vt,t.useLatest=u,t.useLimitList=function(t,n){void 0===t&&(t=[]),void 0===n&&(n={});var r=n||{},o=r.count,u=void 0===o?3:o,c=r.defaultLimited,a=void 0===c||c,s=e.useRef(a),l=e.useMemo((function(){return Array.isArray(t)?t:[]}),[t]),f=e.useMemo((function(){return u>0?Math.ceil(u):0}),[u]),d=e.useMemo((function(){return l.length>f}),[f,l.length]),h=i(e.useState((function(){return d&&a?l.slice(0,f):l})),2),p=h[0],v=h[1];return e.useEffect((function(){v(s.current?l.slice(0,f):l)}),[f,l]),{canLimit:d,limited:s.current,data:p,toggle:function(){d&&(s.current=!s.current),v(s.current?l.slice(0,f):l)}}},t.useLoadMore=function(t,n){var u=n||{},c=u.threshold,s=void 0===c?100:c,l=u.target,f=u.isNoMore,d=void 0===f?function(){return!1}:f,h=u.refreshDeps,p=void 0===h?[]:h,v=u.autoRun,y=void 0===v||v,g=o(u,["threshold","target","isNoMore","refreshDeps","autoRun"]),m=e.useRef([]),b=e.useRef(1),w=lt(t,r(r({defaultParams:[{current:b.current}],autoRun:y},g),{onError:function(t,e){var n;b.current>1&&(b.current-=1),null===(n=null==g?void 0:g.onError)||void 0===n||n.call(g,t,e)},__INTERNAL_FORMAT__:function(t){return m.current=1===b.current?t.list:m.current.concat(t.list),r(r({},t),{list:m.current})}})),T=w.run,k=w.data,S=w.loading,E=w.cancel,O=w.params,_=w.mutate,j=o(w,["run","data","loading","cancel","params","mutate"]),C=!!d&&(!S&&d(k)),P=i(O||[]),R=P[0],L=P.slice(1),I=e.useCallback((function(){return T.apply(void 0,[{current:b.current}].concat(L))}),[L,T]),A=e.useCallback((function(){S&&b.current>1&&(b.current-=1),E()}),[E,S]),M=e.useCallback((function(){S||C||(b.current+=1,I())}),[S,C,I]),V=e.useCallback((function(t){var e="function"==typeof t?t(k):t;m.current=(null==e?void 0:e.list)||[],_(e)}),[k,_]),D=e.useCallback((function(){return A(),b.current=1,V((function(t){return r(r({},t),{list:[]})})),I()}),[A,I,V]),N=e.useCallback((function(){if(!S&&l)return M()}),[M,l,S]);return ht({target:l,threshold:s,onScrollLower:N}),a((function(){y&&Array.isArray(p)&&p.length>0&&D()}),p),r(r({},j),{loading:S,data:k,run:T,refresh:D,cancel:A,mutate:V,params:[r(r({},R),{current:b.current})].concat(L),loadMore:M,loadingMore:S&&b.current>1,noMore:C})},t.useMount=function(t){e.useEffect((function(){t()}),[])},t.useMountedRef=gt,t.usePagination=function(t,n){var u=n||{},c=u.defaultPageSize,s=void 0===c?10:c,l=u.refreshDeps,f=void 0===l?[]:l,d=u.defaultParams,h=u.autoRun,p=void 0===h||h,v=o(u,["defaultPageSize","refreshDeps","defaultParams","autoRun"]),y=e.useMemo((function(){return d||[{current:1,pageSize:s}]}),[s,d]),g=lt(t,r({defaultParams:y,autoRun:p},v)),m=g.run,b=g.data,w=g.params,T=g.loading,k=o(g,["run","data","params","loading"]),S=w&&w[0]?w[0]:y[0],E=S.current,O=S.pageSize,_=(null==b?void 0:b.total)||0,j=e.useCallback((function(t){var e=i(w),n=e[0],o=e.slice(1);m.apply(void 0,[r(r({},n),t)].concat(o))}),[w,m]),C=e.useCallback((function(){j({current:E,pageSize:O})}),[j,E,O]),P=e.useCallback((function(t,e){var n=t<=0?1:t,r=e<=0?1:e,o=Math.ceil(_/r);n>o&&o>0&&(n=o),j({current:n,pageSize:r})}),[j,_]),R=e.useCallback((function(t){P(t,O)}),[P,O]),L=e.useCallback((function(t){P(E,t)}),[E,P]),I=e.useCallback((function(t,e,n,r){j({current:null==t?void 0:t.current,pageSize:null==t?void 0:t.pageSize,filters:e,sorter:n,extra:r})}),[j]);return a((function(){p&&Array.isArray(f)&&f.length>0&&R(1)}),f),r(r({},k),{data:b,run:m,refresh:C,loading:T,params:w,pagination:{current:E,pageSize:O,total:_,onChange:P,changeCurrent:R,changePageSize:L},tableProps:{dataSource:(null==b?void 0:b.list)||[],loading:T,onChange:I,pagination:{total:_,current:E,pageSize:O}}})},t.usePersistFn=c,t.usePrevious=function(t){var n=gt(),r=e.useRef(),o=e.useRef(t);return n.current&&o.current!==t&&(r.current=o.current,o.current=t),r.current},t.useSafeState=bt,t.useSetState=function(t){var n=i(e.useState(t),2),o=n[0],u=n[1];return[o,e.useCallback((function(t){u((function(e){var n=t instanceof Function?t(e):t;return n instanceof Object?r(r({},e),n):e}))}),[])]},t.useSize=function(t){var n=u(t),r="function"==typeof t,o=r?n:t,c=i(e.useState((function(){var e=wt(t);return{width:(e||{}).clientWidth,height:(e||{}).clientHeight}})),2),a=c[0],s=c[1];return e.useEffect((function(){var t=wt(r?o.current:o);function e(t){t&&s({width:t.clientWidth,height:t.clientHeight})}if(!t)return function(){};e(t);var n=new Et((function(t){t.forEach((function(t){e(t.target)}))}));return n.observe(t),function(){n.disconnect()}}),[o,r]),a},t.useThrottle=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=i(e.useState(t),2),u=o[0],c=yt(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useThrottleFn=yt,t.useUnmount=pt,t.useUnmountedRef=mt,t.useUpdate=function(){var t=i(bt(0),2)[1];return e.useCallback((function(){t((function(t){return t+1}))}),[])},t.useUpdateEffect=a,t.useUpdateLayoutEffect=function(t,n){var r=e.useRef(!1);e.useLayoutEffect((function(){if(r.current)return t();r.current=!0}),n)}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).rcHooks={},t.React)}(this,(function(t,e){"use strict";var n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};var r=function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function o(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function u(t){var n=e.useRef(t);return n.current=t,n}function c(t){var n=u(t),r=e.useCallback((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.current;return null==r?void 0:r.apply(void 0,t)}),[]);return r}"function"==typeof SuppressedError&&SuppressedError;var a=function(t,n){var r=e.useRef(!1);e.useEffect((function(){if(r.current)return t();r.current=!0}),n)},s=function(){function t(){this.handler={}}return t.prototype.eventNames=function(){return Object.keys(this.handler)},t.prototype.listeners=function(t){return this.handler[t]||[]},t.prototype.hasListener=function(t,e){return this.listeners(t).some((function(t){return t===e}))},t.prototype.on=function(t,e){return this.handler[t]?this.hasListener(t,e)||this.handler[t].push(e):this.handler[t]=[e],this},t.prototype.off=function(t,e){return this.handler[t]&&("function"==typeof e?this.handler[t]=this.handler[t].filter((function(t){return t!==e})):delete this.handler[t]),this},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this.listeners(t);return r.length>0&&(r.forEach((function(t){t.apply(void 0,e)})),!0)},t.prototype.once=function(t,e){var n=this,r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e.apply(void 0,o),n.off(t,r)};return this.on(t,r)},t.prototype.offAll=function(){return this.handler={},this},t}(),l={},f={getItem:function(t){return l[t]||null},setItem:function(t,e){l[t]=e},removeItem:function(t){delete l[t]}};var d=1;function h(t){return void 0===t&&(t=""),"cache2_"+("string"==typeof t&&t?t:"".concat(Math.random().toString(16).substring(2,8),"_").concat(d++))}var p=new(function(t){function e(e,n){var o,i,u=t.call(this)||this;return"string"==typeof e?o=e:"object"==typeof e&&(i=e),i||"object"!=typeof n||(i=n),u.options=r({max:-1,stdTTL:0,storage:f,maxStrategy:"limited",checkperiod:0,needParsed:"boolean"==typeof(null==i?void 0:i.needParsed)?i.needParsed:!!(null==i?void 0:i.storage)},i),u.options.storage===f||function(t){try{var e="object"==typeof t&&null!==t&&!!t.setItem&&!!t.getItem&&!!t.removeItem;if(e){var n=h();if(t.setItem(n,"1"),"1"!==t.getItem(n))return!1;t.removeItem(n)}return e}catch(t){return console.error("[cache2] The current custom storage is not supported. The default memory cache will be used."),!1}}(u.options.storage)||(u.options.storage=f,u.options.needParsed=!1),u.cacheKey=h(o),u.startCheckperiod(),u}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e.prototype._check=function(t,e){var n=!0;return 0!==e.t&&e.t<Date.now()&&(n=!1,this.del(t),this.emit("expired",t,e.v)),n},e.prototype._wrap=function(t,e){var n=Date.now(),r="number"==typeof e?e:this.options.stdTTL;return{v:t,t:r>0?n+r:0,n:n}},e.prototype._isLimited=function(t){return this.options.max>-1&&t>=this.options.max},e.prototype._getReplaceKey=function(t,e){var n=t[0];return t.forEach((function(t){(e[t].t<e[n].t||e[t].t===e[n].t&&e[t].n<e[n].n)&&(n=t)})),n},e.prototype._parse=function(t){if(!this.options.needParsed)return t;try{return JSON.parse(t,this.options.reviver)}catch(e){return t}},e.prototype._stringify=function(t){return this.options.needParsed?JSON.stringify(t,this.options.replacer):t},Object.defineProperty(e.prototype,"cacheValues",{get:function(){return this._parse(this.options.storage.getItem(this.cacheKey))||{}},enumerable:!1,configurable:!0}),e.prototype.setCacheValues=function(t){this.options.storage.setItem(this.cacheKey,this._stringify(t))},e.prototype.get=function(t){var e=this.cacheValues[t];if(e&&this._check(t,e))return e.v},e.prototype.mget=function(t){var e=this,n={};if(!Array.isArray(t))return n;var r=this.cacheValues;return t.forEach((function(t){var o=r[t];o&&e._check(t,o)&&(n[t]=o.v)})),n},e.prototype.getAll=function(){var t=Object.keys(this.cacheValues);return this.mget(t)},e.prototype.set=function(t,e,n){if(0===this.options.max)return!1;var r=this.cacheValues,o=Object.keys(r);if(!r[t]&&this._isLimited(o.length)){var i=this.keys();if(this._isLimited(i.length)){if("replaced"!==this.options.maxStrategy)return!1;var u=this._getReplaceKey(i,r);this.del(u)}}return r[t]=this._wrap(e,n),this.setCacheValues(r),this.emit("set",t,r[t].v),!0},e.prototype.mset=function(t){var e=this,n=!0;return t.forEach((function(t){var r=e.set(t.key,t.value,t.ttl);n&&!r&&(n=!1)})),n},e.prototype.del=function(t){var e=this,n=this.cacheValues,r=0;return(Array.isArray(t)?t:[t]).forEach((function(t){if(n[t]){r++;var o=n[t];delete n[t],e.emit("del",t,o.v)}})),r>0&&this.setCacheValues(n),r},e.prototype.clear=function(){this.options.storage.removeItem(this.cacheKey)},e.prototype.keys=function(){var t=this,e=this.cacheValues;return Object.keys(e).filter((function(n){return t._check(n,e[n])}))},e.prototype.has=function(t){var e=this.cacheValues[t];return!(!e||!this._check(t,e))},e.prototype.take=function(t){var e,n=this.cacheValues[t];return n&&this._check(t,n)&&(e=n.v,this.del(t)),e},e.prototype.ttl=function(t,e){var n=this.cacheValues,r=n[t];return!(!r||!this._check(t,r))&&(n[t]=this._wrap(r.v,e),!0)},e.prototype.getTtl=function(t){var e=this.cacheValues,n=e[t];if(n&&this._check(t,n))return e[t].t},e.prototype.startCheckperiod=function(){var t=this;this.keys(),this.options.checkperiod>0&&(clearTimeout(this._checkTimeout),this._checkTimeout=setTimeout((function(){t.startCheckperiod()}),this.options.checkperiod))},e.prototype.stopCheckperiod=function(){clearTimeout(this._checkTimeout)},e}(s))({stdTTL:3e5}),v=function(t){return p.get(t)};var y=Object.prototype.toString,g="[object Symbol]";var m=/^0b[01]+$/i,b=/^0o[0-7]+$/i,w=/^[-+]0x[0-9a-f]+$/i;function T(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||y.call(t)===g}(t))return NaN;if(function(t){var e=typeof t;return null!=t&&("object"===e||"function"===e)}(t)&&(t=Number(t)),"string"!=typeof t)return 0===t?t:+t;t=t.trim();var e=m.test(t);return e||b.test(t)?parseInt(t.slice(2),e?2:8):w.test(t)?NaN:+t}y.call(function(){return arguments}());var k="Expected a function";function E(t,e,n,r){if(void 0===r&&(r=!1),"function"!=typeof t)throw new TypeError(k);var o,i,u,c,a,s,l,f;function d(e){return u=e,s=t.apply(a,c),a=c=void 0,s}function h(){for(var t=[],l=0;l<arguments.length;l++)t[l]=arguments[l];a=this,c=t;var f=Date.now(),h=function(t){if(void 0===i)return!0;var n=t-i;return n>=e||n<0||r&&t-u>=e}(f),p=r?h||void 0===i||void 0!==o?e:e-(f-i):e;return i=f,h&&n&&void 0===o?d(f):(void 0===o||r||(clearTimeout(o),o=void 0),void 0===o&&(o=setTimeout((function(){o=void 0,d(Date.now())}),p)),s)}return l=T(e),f=0,e=null==l||l!=l?f:l,h.cancel=function(){void 0!==o&&(clearTimeout(o),o=void 0),i=o=c=a=void 0},h.flush=function(){return void 0!==o&&(clearTimeout(o),o=void 0,c)?d(Date.now()):s},h.pending=function(){return void 0!==o},h}function _(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!1),E(t,e,n)}function S(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!0),E(t,e,n,!0)}function O(t){return arguments.length?function(t){return Array.isArray(t)}(t)?t:[t]:[]}function C(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var R=[];var L=!1;if("undefined"!=typeof window&&window.addEventListener&&!L){window.addEventListener("visibilitychange",(function(){if(C())for(var t=0;t<R.length;t++){(0,R[t])()}}),!1),L=!0}var I=[];var P=!1;if("undefined"!=typeof window&&window.addEventListener&&!P){var j=function(){if(C()&&("undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine))for(var t=0;t<I.length;t++){(0,I[t])()}};window.addEventListener("visibilitychange",j,!1),window.addEventListener("focus",j,!1),P=!0}var A={},N=function(){function t(t,e){this.params=[],this.pollingWhenVisibleFlag=!1,this.pollingTimer=null,this.counter=1,this.destroyed=!1,this.async=t,this.options=r({cacheTime:3e5,persisted:!1,pollingWhenHidden:!0,refreshOnWindowFocus:!1,focusTimespan:5e3},e),this.unsubscribes=[],this.init()}return t.prototype.init=function(){var t,e,n,r,o=this.options,i=o.pollingInterval,u=o.refreshOnWindowFocus,c=o.focusTimespan;if(this.updateDebounce(),i&&this.unsubscribes.push((t=this.rePolling.bind(this),R.push(t),function(){var e=R.indexOf(t);R.splice(e,1)})),u){var a=(e=this.refresh.bind(this),n=c,r=!1,function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];r||(r=!0,e.apply(void 0,t),setTimeout((function(){r=!1}),n))});this.unsubscribes.push(function(t){return I.push(t),function(){var e=I.indexOf(t);I.splice(e,1)}}(a))}},t.prototype.updateDebounce=function(){var t=this.options,e=t.debounceInterval,n=t.throttleInterval;this.debounce="number"==typeof e&&e>0?_(this._run,e):void 0,this.throttle="number"==typeof n&&n>0?S(this._run,n):void 0},t.prototype.rePolling=function(){this.pollingWhenVisibleFlag&&(this.pollingWhenVisibleFlag=!1,this.refresh())},t.prototype.afterUpdateOptions=function(t,e){void 0===e&&(e={}),("debounceInterval"in e&&e.debounceInterval!==t.debounceInterval||"throttleInterval"in e&&e.throttleInterval!==t.throttleInterval)&&this.updateDebounce()},t.prototype.updateOptions=function(t){var e=this.options,n=r(r({},this.options),t);this.options=n,this.afterUpdateOptions(e,n)},t.prototype._run=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.pollingTimer&&clearTimeout(this.pollingTimer);var r=this.counter;this.params=e;var o=this.options,i=o.cacheKey,u=o.cacheTime,c=o.persisted,a=o.formatResult,s=o.onSuccess,l=o.onError,f=o.onFinally,d=o.onBefore,h=o.pollingWhenHidden,y=o.pollingInterval;return null==d||d(e),new Promise((function(n,o){if(i&&c){var d=v(i);if(d&&r===t.counter)return void Promise.resolve().then((function(){null==s||s(d,e),n(d)})).finally((function(){null==f||f()}))}var g,m;(g=function(){return t.async.apply(t,e)},m=i,m&&A[m]?A[m]:m?(A[m]=g().then((function(t){return delete A[m],t})).catch((function(t){return delete A[m],Promise.reject(t)})),A[m]):g()).then((function(o){if(r===t.counter){var c="function"==typeof a?a(o,e):o;i&&function(t,e,n){p.set(t,e,n)}(i,c,u),null==s||s(c,e),n(c)}})).catch((function(n){r===t.counter&&(null==l||l(n,e),o(n))})).finally((function(){if(r===t.counter&&(null==f||f(),y)){if(!C()&&!h)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout((function(){t.run.apply(t,e)}),y)}}))}))},t.prototype.run=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this.debounce?(this.debounce.apply(this,t),Promise.resolve(null)):this.throttle?(this.throttle.apply(this,t),Promise.resolve(null)):(this.counter+=1,this._run.apply(this,t))},t.prototype.refresh=function(){return this.run.apply(this,this.params)},t.prototype.cancel=function(){this.debounce&&this.debounce.cancel(),this.throttle&&this.throttle.cancel(),this.pollingTimer&&(clearTimeout(this.pollingTimer),this.pollingTimer=null),this.counter+=1},t.prototype.destroy=function(t){void 0===t&&(t=!0),t&&this.cancel(),this.destroyed||(this.destroyed=!0,this.unsubscribes.forEach((function(t){return t()})),this.unsubscribes=[])},t.prototype.resume=function(){this.destroyed&&(this.destroyed=!1,this.init())},t}(),V=function(){};function x(t,n){var o=n||{},s=o.autoRun,l=void 0===s||s,f=o.refreshDeps,d=void 0===f?[]:f,h=o.defaultParams,p=o.loadingDelay,y=o.__INTERNAL_FORMAT__,g=o.defaultLoading,m=void 0!==g&&g,b=o.initialData,w=o.cacheKey,T=void 0===w?"":w,k=o.cacheTime,E=void 0===k?3e5:k,_=o.persisted,S=void 0!==_&&_,O=o.onSuccess,C=void 0===O?V:O,R=o.onError,L=void 0===R?V:R,I=o.onFinally,P=void 0===I?V:I,j=o.onBefore,A=void 0===j?V:j,x=o.pollingInterval,F=void 0===x?0:x,D=o.pollingWhenHidden,M=void 0===D||D,W=o.refreshOnWindowFocus,z=void 0!==W&&W,H=o.focusTimespan,K=void 0===H?5e3:H,U=o.debounceInterval,B=o.throttleInterval,$=i(e.useState({params:[],loading:m,error:null,data:T?v(T):b}),2),J=$[0],q=$[1],Y=e.useRef(null),G=c(t),Q=c(C),X=c(L),Z=c(P),tt=c(A),et=u(y),nt=e.useCallback((function(t){tt(t),Y.current&&clearTimeout(Y.current),(T?v(T):void 0)&&S||(q((function(e){return r(r({},e),{loading:!p,params:t})})),p&&(Y.current=setTimeout((function(){q((function(t){return r(r({},t),{loading:!0})}))}),p)))}),[T,p,tt,S]),rt=e.useCallback((function(t,e){Y.current&&clearTimeout(Y.current),q((function(e){return r(r({},e),{data:t,error:null,loading:!1})})),Q(t,e)}),[Q]),ot=e.useCallback((function(t,e){Y.current&&clearTimeout(Y.current),q((function(e){return r(r({},e),{error:t,loading:!1})})),X(t,e)}),[X]),it=e.useRef();it.current||(it.current=new N(G,{cacheKey:T,cacheTime:E,persisted:S,formatResult:et.current,onSuccess:rt,onError:ot,onFinally:Z,onBefore:nt,debounceInterval:U,throttleInterval:B,pollingInterval:F,pollingWhenHidden:M,refreshOnWindowFocus:z,focusTimespan:K})),a((function(){it.current.updateOptions({cacheKey:T,cacheTime:E,persisted:S,formatResult:et.current,onSuccess:rt,onError:ot,onFinally:Z,onBefore:nt,debounceInterval:U,throttleInterval:B,pollingInterval:F,pollingWhenHidden:M,refreshOnWindowFocus:z,focusTimespan:K})}),[Q,X,T,E,S,U,B,Z,tt,F,M,z,K,rt,ot,nt]);var ut=e.useCallback((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return it.current.run.apply(it.current,t)}),[]),ct=e.useCallback((function(){return it.current.refresh()}),[]),at=e.useCallback((function(){it.current.cancel(),Y.current&&clearTimeout(Y.current),q((function(t){return r(r({},t),{loading:!1})}))}),[]);return a((function(){l&&Array.isArray(d)&&d.length>0&&ct()}),[l].concat(d)),e.useEffect((function(){if(l){var t=Array.isArray(h)?h:void 0!==h?[h]:[];ut.apply(void 0,t)}return it.current.resume(),function(){at(),it.current.destroy(!1)}}),[]),r(r({},J),{run:ut,cancel:at,mutate:function(t){q("function"==typeof t?function(e){return r(r({},e),{data:t(J.data)})}:function(e){return r(r({},e),{data:t})})},refresh:ct})}var F=function(t){return null!=t&&t===(null==t?void 0:t.window)};function D(t){return"function"==typeof t?t():t}var M=function(t){var n=void 0===t?{}:t,r=n.target,o=n.threshold,i=void 0===o?100:o,u=n.onScrollLower,a=c(void 0===u?function(){}:u),s=e.useCallback((function(){if(r){var t,e=D(r);if(e)void 0===(t=e)&&(t=window),("undefined"==typeof window?0:F(t)?document.documentElement.scrollHeight:t.scrollHeight)-function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:F(t)?window.scrollY:(null==t?void 0:t.scrollTop)||0}(e)<=function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:F(t)?document.documentElement.clientHeight:t.clientHeight}(e)+i&&a()}}),[a,r,i]);e.useEffect((function(){if(r){var t=D(r);if(t)return t.addEventListener("scroll",s),function(){t.removeEventListener("scroll",s)}}}),[r,s])};var W=function(t){var n=u(t);e.useEffect((function(){return function(){return n.current()}}),[])};function z(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=u(t),i=e.useRef(_((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return W((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}function H(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=u(t),i=e.useRef(S((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return W((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}var K=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!0,function(){t.current=!1}}),[]),t};var U=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!1,function(){t.current=!0}}),[]),t};function B(t){var n=U(),r=i(e.useState(t),2),o=r[0],u=r[1];return[o,e.useCallback((function(t){n.current||u(t)}),[])]}function $(t){return"function"==typeof t?t():"object"==typeof t&&t&&"current"in t?t.current:t}var J="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,q=["top","right","bottom","left","width","height","size","weight"],Y={characterData:!0,childList:!0,attributes:!0,subtree:!0},G=function(t){var e=this;this.refresh=function(){e.targetNode&&e.callback([{target:e.targetNode}],{})},this.onTransitionEnd_=function(t){var n=t.propertyName,r=void 0===n?"":n;q.some((function(t){return r.indexOf(t)>-1}))&&e.throttleRefresh()},this.observe=function(t,n){J&&(e.targetNode=t,document.addEventListener("transitionend",e.onTransitionEnd_),window.addEventListener("resize",e.throttleRefresh),e.observer.observe(document,r(r({},Y),n)))},this.disconnect=function(){J&&(e.throttleRefresh.cancel(),e.targetNode=null,document.removeEventListener("transitionend",e.onTransitionEnd_),window.removeEventListener("resize",e.throttleRefresh),e.observer.disconnect())},this.throttleRefresh=S(this.refresh,50),this.targetNode=null,this.callback=t,this.observer=new MutationObserver(this.throttleRefresh)};t.clearCache=function(t){t?p.del(t):p.clear()},t.useAsync=x,t.useClickAway=function(t,n,r){void 0===r&&(r="click");var o=O(t),i=u(o),c=o.every((function(t){return"function"==typeof t})),a=c?i:o,s=u(n),l=O(r),f=u(l),d=l.join("");e.useEffect((function(){var t=function(t){var e;(c?a.current:a).some((function(e){var n=$(e);return!n||(null==n?void 0:n.contains(t.target))}))||null===(e=s.current)||void 0===e||e.call(s,t)},e=O(f.current);return e.forEach((function(e){document.addEventListener(e,t)})),function(){e.forEach((function(e){document.removeEventListener(e,t)}))}}),[a,c,d])},t.useControllableValue=function(t,n){void 0===t&&(t={}),void 0===n&&(n={});var r=n.defaultValue,o=n.defaultValuePropName,u=void 0===o?"defaultValue":o,c=n.valuePropName,s=void 0===c?"value":c,l=n.trigger,f=void 0===l?"onChange":l,d=s in t,h=t[s],p=i(e.useState((function(){return d?h:u in t?t[u]:r})),2),v=p[0],y=p[1];a((function(){d&&y(h)}),[h,d]);var g=e.useCallback((function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];d||y(e),t[f]&&t[f].apply(t,[e].concat(n))}),[d,t,f]);return[d?h:v,g]},t.useDebounce=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=i(e.useState(t),2),u=o[0],c=z(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useDebounceFn=z,t.useLatest=u,t.useLimitList=function(t,n){void 0===t&&(t=[]),void 0===n&&(n={});var r=n||{},o=r.count,u=void 0===o?3:o,c=r.defaultLimited,a=void 0===c||c,s=e.useRef(a),l=e.useMemo((function(){return Array.isArray(t)?t:[]}),[t]),f=e.useMemo((function(){return u>0?Math.ceil(u):0}),[u]),d=e.useMemo((function(){return l.length>f}),[f,l.length]),h=i(e.useState((function(){return d&&a?l.slice(0,f):l})),2),p=h[0],v=h[1];return e.useEffect((function(){v(s.current?l.slice(0,f):l)}),[f,l]),{canLimit:d,limited:s.current,data:p,toggle:function(){d&&(s.current=!s.current),v(s.current?l.slice(0,f):l)}}},t.useLoadMore=function(t,n){var u=n||{},c=u.threshold,s=void 0===c?100:c,l=u.target,f=u.isNoMore,d=void 0===f?function(){return!1}:f,h=u.refreshDeps,p=void 0===h?[]:h,v=u.autoRun,y=void 0===v||v,g=o(u,["threshold","target","isNoMore","refreshDeps","autoRun"]),m=e.useRef([]),b=e.useRef(1),w=x(t,r(r({defaultParams:[{current:b.current}],autoRun:y},g),{onError:function(t,e){var n;b.current>1&&(b.current-=1),null===(n=null==g?void 0:g.onError)||void 0===n||n.call(g,t,e)},__INTERNAL_FORMAT__:function(t){return m.current=1===b.current?t.list:m.current.concat(t.list),r(r({},t),{list:m.current})}})),T=w.run,k=w.data,E=w.loading,_=w.cancel,S=w.params,O=w.mutate,C=o(w,["run","data","loading","cancel","params","mutate"]),R=!!d&&(!E&&d(k)),L=i(S||[]),I=L[0],P=L.slice(1),j=e.useCallback((function(){return T.apply(void 0,[{current:b.current}].concat(P))}),[P,T]),A=e.useCallback((function(){E&&b.current>1&&(b.current-=1),_()}),[_,E]),N=e.useCallback((function(){E||R||(b.current+=1,j())}),[E,R,j]),V=e.useCallback((function(t){var e="function"==typeof t?t(k):t;m.current=(null==e?void 0:e.list)||[],O(e)}),[k,O]),F=e.useCallback((function(){return A(),b.current=1,V((function(t){return r(r({},t),{list:[]})})),j()}),[A,j,V]),D=e.useCallback((function(){if(!E&&l)return N()}),[N,l,E]);return M({target:l,threshold:s,onScrollLower:D}),a((function(){y&&Array.isArray(p)&&p.length>0&&F()}),p),r(r({},C),{loading:E,data:k,run:T,refresh:F,cancel:A,mutate:V,params:[r(r({},I),{current:b.current})].concat(P),loadMore:N,loadingMore:E&&b.current>1,noMore:R})},t.useMount=function(t){e.useEffect((function(){t()}),[])},t.useMountedRef=K,t.usePagination=function(t,n){var u=n||{},c=u.defaultPageSize,s=void 0===c?10:c,l=u.refreshDeps,f=void 0===l?[]:l,d=u.defaultParams,h=u.autoRun,p=void 0===h||h,v=o(u,["defaultPageSize","refreshDeps","defaultParams","autoRun"]),y=e.useMemo((function(){return d||[{current:1,pageSize:s}]}),[s,d]),g=x(t,r({defaultParams:y,autoRun:p},v)),m=g.run,b=g.data,w=g.params,T=g.loading,k=o(g,["run","data","params","loading"]),E=w&&w[0]?w[0]:y[0],_=E.current,S=E.pageSize,O=(null==b?void 0:b.total)||0,C=e.useCallback((function(t){var e=i(w),n=e[0],o=e.slice(1);m.apply(void 0,[r(r({},n),t)].concat(o))}),[w,m]),R=e.useCallback((function(){C({current:_,pageSize:S})}),[C,_,S]),L=e.useCallback((function(t,e){var n=t<=0?1:t,r=e<=0?1:e,o=Math.ceil(O/r);n>o&&o>0&&(n=o),C({current:n,pageSize:r})}),[C,O]),I=e.useCallback((function(t){L(t,S)}),[L,S]),P=e.useCallback((function(t){L(_,t)}),[_,L]),j=e.useCallback((function(t,e,n,r){C({current:null==t?void 0:t.current,pageSize:null==t?void 0:t.pageSize,filters:e,sorter:n,extra:r})}),[C]);return a((function(){p&&Array.isArray(f)&&f.length>0&&I(1)}),f),r(r({},k),{data:b,run:m,refresh:R,loading:T,params:w,pagination:{current:_,pageSize:S,total:O,onChange:L,changeCurrent:I,changePageSize:P},tableProps:{dataSource:(null==b?void 0:b.list)||[],loading:T,onChange:j,pagination:{total:O,current:_,pageSize:S}}})},t.usePersistFn=c,t.usePrevious=function(t){var n=K(),r=e.useRef(),o=e.useRef(t);return n.current&&o.current!==t&&(r.current=o.current,o.current=t),r.current},t.useSafeState=B,t.useSetState=function(t){var n=i(e.useState(t),2),o=n[0],u=n[1];return[o,e.useCallback((function(t){u((function(e){var n=t instanceof Function?t(e):t;return n instanceof Object?r(r({},e),n):e}))}),[])]},t.useSize=function(t){var n=u(t),r="function"==typeof t,o=r?n:t,c=i(e.useState((function(){var e=$(t);return{width:null==e?void 0:e.clientWidth,height:null==e?void 0:e.clientHeight}})),2),a=c[0],s=c[1];return e.useEffect((function(){var t=$(r?o.current:o);function e(t){t&&s({width:t.clientWidth,height:t.clientHeight})}if(!t)return function(){};e(t);var n=new G((function(t){t.forEach((function(t){e(t.target)}))}));return n.observe(t),function(){n.disconnect()}}),[o,r]),a},t.useThrottle=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=i(e.useState(t),2),u=o[0],c=H(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useThrottleFn=H,t.useUnmount=W,t.useUnmountedRef=U,t.useUpdate=function(){var t=i(B(0),2)[1];return e.useCallback((function(){t((function(t){return t+1}))}),[])},t.useUpdateEffect=a,t.useUpdateLayoutEffect=function(t,n){var r=e.useRef(!1);e.useLayoutEffect((function(){if(r.current)return t();r.current=!0}),n)}}));
//# sourceMappingURL=rcHooks.min.js.map

@@ -13,3 +13,3 @@ import type { AsyncOptions } from '.';

];
export interface LoadMoreOptions<R extends LoadMoreAsyncReturn = any> extends Omit<AsyncOptions<R, LoadMoreParams>, 'cacheKey' | 'cacheTime' | 'persisted' | 'pollingInterval' | 'pollingWhenHidden'> {
export interface LoadMoreOptions<DataItem = any, R extends LoadMoreAsyncReturn<DataItem> = any> extends Omit<AsyncOptions<R, LoadMoreParams>, 'cacheKey' | 'cacheTime' | 'persisted' | 'pollingInterval' | 'pollingWhenHidden'> {
threshold?: number;

@@ -19,3 +19,3 @@ target?: TargetType;

}
declare function useLoadMore<R extends LoadMoreAsyncReturn = any>(asyncFn: (...args: LoadMoreParams) => Promise<R>, options?: LoadMoreOptions<R>): {
declare function useLoadMore<DataItem = any, R extends LoadMoreAsyncReturn<DataItem> = any>(asyncFn: (...args: LoadMoreParams) => Promise<R>, options?: LoadMoreOptions<R>): {
loading: boolean;

@@ -22,0 +22,0 @@ data: R | undefined;

@@ -15,6 +15,6 @@ import type { AsyncOptions } from '.';

];
export interface PaginationOptions<R extends PaginationAsyncReturn = any> extends AsyncOptions<R, PaginationParams> {
export interface PaginationOptions<DataItem = any, R extends PaginationAsyncReturn<DataItem> = any> extends AsyncOptions<R, PaginationParams> {
defaultPageSize?: number;
}
export declare function usePagination<R extends PaginationAsyncReturn = any>(asyncFn: (...args: PaginationParams) => Promise<R>, options?: PaginationOptions<R>): {
export declare function usePagination<D = any, R extends PaginationAsyncReturn<D> = any>(asyncFn: (...args: PaginationParams) => Promise<R>, options?: PaginationOptions<R>): {
data: R | undefined;

@@ -38,3 +38,3 @@ run: (param1: {

tableProps: {
dataSource: any[];
dataSource: R["list"];
loading: boolean;

@@ -41,0 +41,0 @@ onChange: (pagination: {

@@ -58,3 +58,3 @@ import { __assign, __read, __rest } from "tslib";

}, tableProps: {
dataSource: (data === null || data === void 0 ? void 0 : data.list) || [],
dataSource: ((data === null || data === void 0 ? void 0 : data.list) || []),
loading: loading,

@@ -61,0 +61,0 @@ onChange: changeTable,

@@ -13,4 +13,4 @@ import { __read } from "tslib";

return {
width: (target || {}).clientWidth,
height: (target || {}).clientHeight
width: target === null || target === void 0 ? void 0 : target.clientWidth,
height: target === null || target === void 0 ? void 0 : target.clientHeight
};

@@ -20,7 +20,7 @@ }), 2), size = _a[0], setSize = _a[1];

var target = getRef(refIsFunc ? wrapperRef.current : wrapperRef);
function refresh(target) {
if (target) {
function refresh(el) {
if (el) {
setSize({
width: target.clientWidth,
height: target.clientHeight
width: el.clientWidth,
height: el.clientHeight
});

@@ -27,0 +27,0 @@ }

@@ -13,3 +13,3 @@ import type { AsyncOptions } from '.';

];
export interface LoadMoreOptions<R extends LoadMoreAsyncReturn = any> extends Omit<AsyncOptions<R, LoadMoreParams>, 'cacheKey' | 'cacheTime' | 'persisted' | 'pollingInterval' | 'pollingWhenHidden'> {
export interface LoadMoreOptions<DataItem = any, R extends LoadMoreAsyncReturn<DataItem> = any> extends Omit<AsyncOptions<R, LoadMoreParams>, 'cacheKey' | 'cacheTime' | 'persisted' | 'pollingInterval' | 'pollingWhenHidden'> {
threshold?: number;

@@ -19,3 +19,3 @@ target?: TargetType;

}
declare function useLoadMore<R extends LoadMoreAsyncReturn = any>(asyncFn: (...args: LoadMoreParams) => Promise<R>, options?: LoadMoreOptions<R>): {
declare function useLoadMore<DataItem = any, R extends LoadMoreAsyncReturn<DataItem> = any>(asyncFn: (...args: LoadMoreParams) => Promise<R>, options?: LoadMoreOptions<R>): {
loading: boolean;

@@ -22,0 +22,0 @@ data: R | undefined;

@@ -15,6 +15,6 @@ import type { AsyncOptions } from '.';

];
export interface PaginationOptions<R extends PaginationAsyncReturn = any> extends AsyncOptions<R, PaginationParams> {
export interface PaginationOptions<DataItem = any, R extends PaginationAsyncReturn<DataItem> = any> extends AsyncOptions<R, PaginationParams> {
defaultPageSize?: number;
}
export declare function usePagination<R extends PaginationAsyncReturn = any>(asyncFn: (...args: PaginationParams) => Promise<R>, options?: PaginationOptions<R>): {
export declare function usePagination<D = any, R extends PaginationAsyncReturn<D> = any>(asyncFn: (...args: PaginationParams) => Promise<R>, options?: PaginationOptions<R>): {
data: R | undefined;

@@ -38,3 +38,3 @@ run: (param1: {

tableProps: {
dataSource: any[];
dataSource: R["list"];
loading: boolean;

@@ -41,0 +41,0 @@ onChange: (pagination: {

@@ -61,3 +61,3 @@ "use strict";

}, tableProps: {
dataSource: (data === null || data === void 0 ? void 0 : data.list) || [],
dataSource: ((data === null || data === void 0 ? void 0 : data.list) || []),
loading: loading,

@@ -64,0 +64,0 @@ onChange: changeTable,

@@ -15,4 +15,4 @@ "use strict";

return {
width: (target || {}).clientWidth,
height: (target || {}).clientHeight
width: target === null || target === void 0 ? void 0 : target.clientWidth,
height: target === null || target === void 0 ? void 0 : target.clientHeight
};

@@ -22,7 +22,7 @@ }), 2), size = _a[0], setSize = _a[1];

var target = (0, getRef_1.default)(refIsFunc ? wrapperRef.current : wrapperRef);
function refresh(target) {
if (target) {
function refresh(el) {
if (el) {
setSize({
width: target.clientWidth,
height: target.clientHeight
width: el.clientWidth,
height: el.clientHeight
});

@@ -29,0 +29,0 @@ }

{
"name": "rc-hooks",
"version": "3.0.5",
"version": "3.0.6",
"description": "React Hooks Library.",

@@ -19,3 +19,2 @@ "main": "lib/index.js",

"prettier": "prettier --write **/*",
"precommit": "lint-staged",
"lint": "eslint src --ext ts,tsx",

@@ -58,5 +57,5 @@ "lint:fix": "npm run lint -- --fix",

"dependencies": {
"cache2": "^1.0.3",
"cache2": "^1.0.4",
"tslib": "^2.6.0",
"ut2": "^1.3.0"
"ut2": "^1.4.9"
},

@@ -79,7 +78,7 @@ "devDependencies": {

"@types/node": "^20.3.2",
"@types/react": "^18.2.21",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"antd": "^4.24.10",
"antd": "^5.9.4",
"babel-jest": "^29.5.0",
"babel-plugin-import": "^1.13.6",
"cross-env": "^7.0.3",

@@ -86,0 +85,0 @@ "cz-conventional-changelog": "^3.3.0",

@@ -13,6 +13,12 @@ # rc-hooks

npm install rc-hooks
# or
```
```shell
yarn add rc-hooks
```
```shell
pnpm add rc-hooks
```
## 使用

@@ -19,0 +25,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc