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.4 to 3.0.5

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=u(t),i=u(n),c=u(r);e.useEffect((function(){var t=function(t){var e;(Array.isArray(o.current)?o.current:[o.current]).some((function(e){var n=wt(e);return!n||(null==n?void 0:n.contains(t.target))}))||null===(e=i.current)||void 0===e||e.call(i,t)},e=tt(c.current);return e.forEach((function(e){document.addEventListener(e,t)})),function(){e.forEach((function(e){document.removeEventListener(e,t)}))}}),[])},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=i(e.useState((function(){var e=wt(t);return{width:(e||{}).clientWidth,height:(e||{}).clientHeight}})),2),o=r[0],c=r[1];return e.useEffect((function(){var t=wt(n.current);function e(t){t&&c({width:t.clientWidth,height:t.clientHeight})}if(!t)return function(){};e(t);var r=new Et((function(t){t.forEach((function(t){e(t.target)}))}));return r.observe(t),function(){r.disconnect()}}),[]),o},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,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)}}));
//# sourceMappingURL=rcHooks.min.js.map

@@ -7,9 +7,14 @@ import { useEffect } from 'react';

if (events === void 0) { events = 'click'; }
var latestRef = useLatest(ref);
var refs = castArray(ref);
var latestRefs = useLatest(refs);
var refsIsFunc = refs.every(function (item) { return typeof item === 'function'; });
var wrapperRefs = refsIsFunc ? latestRefs : refs;
var onClickAwayRef = useLatest(onClickAway);
var eventsRef = useLatest(events);
var eventsArr = castArray(events);
var eventsRef = useLatest(eventsArr);
var eventsStr = eventsArr.join('');
useEffect(function () {
var handler = function (event) {
var _a;
var targets = Array.isArray(latestRef.current) ? latestRef.current : [latestRef.current];
var targets = refsIsFunc ? wrapperRefs.current : wrapperRefs;
if (!targets.some(function (targetItem) {

@@ -32,4 +37,4 @@ var target = getRef(targetItem);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [wrapperRefs, refsIsFunc, eventsStr]);
}
export default useClickAway;

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

var latestRef = useLatest(ref);
var refIsFunc = typeof ref === 'function';
var wrapperRef = refIsFunc ? latestRef : ref;
var _a = __read(useState(function () {

@@ -17,3 +19,3 @@ var target = getRef(ref);

useEffect(function () {
var target = getRef(latestRef.current);
var target = getRef(refIsFunc ? wrapperRef.current : wrapperRef);
function refresh(target) {

@@ -40,6 +42,5 @@ if (target) {

};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [wrapperRef, refIsFunc]);
return size;
}
export default useSize;

@@ -10,9 +10,14 @@ "use strict";

if (events === void 0) { events = 'click'; }
var latestRef = (0, useLatest_1.default)(ref);
var refs = (0, ut2_1.castArray)(ref);
var latestRefs = (0, useLatest_1.default)(refs);
var refsIsFunc = refs.every(function (item) { return typeof item === 'function'; });
var wrapperRefs = refsIsFunc ? latestRefs : refs;
var onClickAwayRef = (0, useLatest_1.default)(onClickAway);
var eventsRef = (0, useLatest_1.default)(events);
var eventsArr = (0, ut2_1.castArray)(events);
var eventsRef = (0, useLatest_1.default)(eventsArr);
var eventsStr = eventsArr.join('');
(0, react_1.useEffect)(function () {
var handler = function (event) {
var _a;
var targets = Array.isArray(latestRef.current) ? latestRef.current : [latestRef.current];
var targets = refsIsFunc ? wrapperRefs.current : wrapperRefs;
if (!targets.some(function (targetItem) {

@@ -35,4 +40,4 @@ var target = (0, getRef_1.default)(targetItem);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [wrapperRefs, refsIsFunc, eventsStr]);
}
exports.default = useClickAway;

@@ -10,2 +10,4 @@ "use strict";

var latestRef = (0, useLatest_1.default)(ref);
var refIsFunc = typeof ref === 'function';
var wrapperRef = refIsFunc ? latestRef : ref;
var _a = tslib_1.__read((0, react_1.useState)(function () {

@@ -19,3 +21,3 @@ var target = (0, getRef_1.default)(ref);

(0, react_1.useEffect)(function () {
var target = (0, getRef_1.default)(latestRef.current);
var target = (0, getRef_1.default)(refIsFunc ? wrapperRef.current : wrapperRef);
function refresh(target) {

@@ -42,6 +44,5 @@ if (target) {

};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [wrapperRef, refIsFunc]);
return size;
}
exports.default = useSize;
{
"name": "rc-hooks",
"version": "3.0.4",
"version": "3.0.5",
"description": "React Hooks Library.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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