Comparing version 3.0.6 to 3.0.7
@@ -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){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)}})); | ||
!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}();var l=1;function f(t){return"string"==typeof t&&t?t:"".concat(Math.random().toString(16).substring(2,8),"_").concat(l++)}var h="undefined"!=typeof window&&"object"==typeof window&&window.window===window,d={},p={getItem:function(t){return d[t]||null},setItem:function(t,e){d[t]=e},removeItem:function(t){delete d[t]}},v=function(){function t(t,e){this.isSupported=!!t&&function(t){try{var e="object"==typeof t&&null!==t&&!!t.setItem&&!!t.getItem&&!!t.removeItem;if(e){var n=f();if(t.setItem(n,"1"),"1"!==t.getItem(n))return!1;t.removeItem(n)}return e}catch(e){return console.error("[cache2] ".concat(t," is not supported. The default memory cache will be used.")),!1}}(t),this.keyPrefix=(null==e?void 0:e.prefix)||(this.isSupported?"":f()),this.storage=this.isSupported?t:p,this.isMemoryStorage=!this.isSupported||t===p,this.options=r({needParsed:!this.isMemoryStorage},e),this._keys={}}return t.prototype.getKey=function(t){return this.keyPrefix+t},t.prototype.get=function(t){var e=this.getKey(t),n=this.storage.getItem(e);return this.options.needParsed?function(t,e){try{return JSON.parse(t,e)}catch(e){return t}}(n,this.options.reviver):n},t.prototype.set=function(t,e){var n,r,o=this.getKey(t);this.storage.setItem(o,this.options.needParsed?(n=e,r=this.options.replacer,JSON.stringify(n,r)):e),this.isMemoryStorage&&(this._keys[t]=1)},t.prototype.del=function(t){var e=this.getKey(t);this.storage.removeItem(e),this.isMemoryStorage&&delete this._keys[t]},t.prototype.clear=function(){var t=this;if("function"==typeof this.storage.clear)this.storage.clear();else if(this.isMemoryStorage){Object.keys(this._keys).forEach((function(e){t.del(e)}))}},t}(),y=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,maxStrategy:"limited",checkperiod:0,prefix:"cache2_"},i),u.storage=new v(u.options.storage,u.options),u.storage.isMemoryStorage||o||(o="default"),u.cacheKey=f(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},Object.defineProperty(e.prototype,"cacheValues",{get:function(){return this.storage.get(this.cacheKey)||{}},enumerable:!1,configurable:!0}),e.prototype.setCacheValues=function(t){this.storage.set(this.cacheKey,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.storage.del(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.getLastModified=function(t){var e=this.cacheValues,n=e[t];if(n&&this._check(t,n))return e[t].n},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);new v(h?window.localStorage:void 0),new v(h?window.sessionStorage:void 0);var g=new y({stdTTL:3e5}),m=function(t){return g.get(t)},b=Object.prototype.toString,w="[object Symbol]";function k(t){return b.call(t)}var S=/^0b[01]+$/i,T=/^0o[0-7]+$/i,E=/^[-+]0x[0-9a-f]+$/i;function _(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||k(t)===w}(t))return NaN;if(function(t){var e=typeof t;return"function"===e||"object"===e&&!!t}(t)&&(t=Number(t)),"string"!=typeof t)return 0===t?t:+t;t=t.trim();var e=S.test(t);return e||T.test(t)?parseInt(t.slice(2),e?2:8):E.test(t)?NaN:+t}k(function(){return arguments}());var O="Expected a function";function C(t,e,n,r){if(void 0===r&&(r=!1),"function"!=typeof t)throw new TypeError(O);var o,i,u,c,a,s,l,f;function h(e){return u=e,s=t.apply(a,c),a=c=void 0,s}function d(){for(var t=[],l=0;l<arguments.length;l++)t[l]=arguments[l];a=this,c=t;var f=Date.now(),d=function(t){if(void 0===i)return!0;var n=t-i;return n>=e||n<0||r&&t-u>=e}(f),p=r?d||void 0===i||void 0!==o?e:e-(f-i):e;return i=f,d&&n&&void 0===o?h(f):(void 0===o||r||(clearTimeout(o),o=void 0),void 0===o&&(o=setTimeout((function(){o=void 0,h(Date.now())}),p)),s)}return l=_(e),f=0,e=null==l||l!=l?f:l,d.cancel=function(){void 0!==o&&(clearTimeout(o),o=void 0),i=o=c=a=void 0},d.flush=function(){return void 0!==o&&(clearTimeout(o),o=void 0,c)?h(Date.now()):s},d.pending=function(){return void 0!==o},d}function R(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!1),C(t,e,n)}function L(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!0),C(t,e,n,!0)}function I(t){return arguments.length?function(t){return Array.isArray(t)}(t)?t:[t]:[]}function P(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var j=[];var A=!1;if("undefined"!=typeof window&&window.addEventListener&&!A){window.addEventListener("visibilitychange",(function(){if(P())for(var t=0;t<j.length;t++){(0,j[t])()}}),!1),A=!0}var M=[];var x=!1;if("undefined"!=typeof window&&window.addEventListener&&!x){var V=function(){if(P()&&("undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine))for(var t=0;t<M.length;t++){(0,M[t])()}};window.addEventListener("visibilitychange",V,!1),window.addEventListener("focus",V,!1),x=!0}var N={},F=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),j.push(t),function(){var e=j.indexOf(t);j.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 M.push(t),function(){var e=M.indexOf(t);M.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?R(this._run,e):void 0,this.throttle="number"==typeof n&&n>0?L(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,h=o.onBefore,d=o.pollingWhenHidden,p=o.pollingInterval;return null==h||h(e),new Promise((function(n,o){if(i&&c){var h=m(i);if(h&&r===t.counter)return void Promise.resolve().then((function(){null==s||s(h,e),n(h)})).finally((function(){null==f||f()}))}var v,y;(v=function(){return t.async.apply(t,e)},y=i,y&&N[y]?N[y]:y?(N[y]=v().then((function(t){return delete N[y],t})).catch((function(t){return delete N[y],Promise.reject(t)})),N[y]):v()).then((function(o){if(r===t.counter){var c="function"==typeof a?a(o,e):o;i&&function(t,e,n){g.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(),p)){if(!P()&&!d)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout((function(){t.run.apply(t,e)}),p)}}))}))},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}(),D=function(){};function W(t,n){var o=n||{},s=o.autoRun,l=void 0===s||s,f=o.refreshDeps,h=void 0===f?[]:f,d=o.defaultParams,p=o.loadingDelay,v=o.__INTERNAL_FORMAT__,y=o.defaultLoading,g=void 0!==y&&y,b=o.initialData,w=o.cacheKey,k=void 0===w?"":w,S=o.cacheTime,T=void 0===S?3e5:S,E=o.persisted,_=void 0!==E&&E,O=o.onSuccess,C=void 0===O?D:O,R=o.onError,L=void 0===R?D:R,I=o.onFinally,P=void 0===I?D:I,j=o.onBefore,A=void 0===j?D:j,M=o.pollingInterval,x=void 0===M?0:M,V=o.pollingWhenHidden,N=void 0===V||V,W=o.refreshOnWindowFocus,z=void 0!==W&&W,K=o.focusTimespan,H=void 0===K?5e3:K,U=o.debounceInterval,B=o.throttleInterval,$=i(e.useState({params:[],loading:g,error:null,data:k?m(k):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(v),nt=e.useCallback((function(t){tt(t),Y.current&&clearTimeout(Y.current),(k?m(k):void 0)&&_||(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)))}),[k,p,tt,_]),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 F(G,{cacheKey:k,cacheTime:T,persisted:_,formatResult:et.current,onSuccess:rt,onError:ot,onFinally:Z,onBefore:nt,debounceInterval:U,throttleInterval:B,pollingInterval:x,pollingWhenHidden:N,refreshOnWindowFocus:z,focusTimespan:H})),a((function(){it.current.updateOptions({cacheKey:k,cacheTime:T,persisted:_,formatResult:et.current,onSuccess:rt,onError:ot,onFinally:Z,onBefore:nt,debounceInterval:U,throttleInterval:B,pollingInterval:x,pollingWhenHidden:N,refreshOnWindowFocus:z,focusTimespan:H})}),[Q,X,k,T,_,U,B,Z,tt,x,N,z,H,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(h)&&h.length>0&&ct()}),[l].concat(h)),e.useEffect((function(){if(l){var t=Array.isArray(d)?d:void 0!==d?[d]:[];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 z=function(t){return null!=t&&t===(null==t?void 0:t.window)};function K(t){return"function"==typeof t?t():t}var H=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=K(r);if(e)void 0===(t=e)&&(t=window),("undefined"==typeof window?0:z(t)?document.documentElement.scrollHeight:t.scrollHeight)-function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:z(t)?window.scrollY:(null==t?void 0:t.scrollTop)||0}(e)<=function(t){return void 0===t&&(t=window),"undefined"==typeof window?0:z(t)?document.documentElement.clientHeight:t.clientHeight}(e)+i&&a()}}),[a,r,i]);e.useEffect((function(){if(r){var t=K(r);if(t)return t.addEventListener("scroll",s),function(){t.removeEventListener("scroll",s)}}}),[r,s])};var U=function(t){var n=u(t);e.useEffect((function(){return function(){return n.current()}}),[])};function B(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=u(t),i=e.useRef(R((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return U((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}function $(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=u(t),i=e.useRef(L((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)}),n,r));return U((function(){i.current.cancel()})),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}var J=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!0,function(){t.current=!1}}),[]),t};var q=function(){var t=e.useRef(!1);return e.useEffect((function(){return t.current=!1,function(){t.current=!0}}),[]),t};function Y(t){var n=q(),r=i(e.useState(t),2),o=r[0],u=r[1];return[o,e.useCallback((function(t){n.current||u(t)}),[])]}function G(t){return"function"==typeof t?t():"object"==typeof t&&t&&"current"in t?t.current:t}var Q="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,X=["top","right","bottom","left","width","height","size","weight"],Z={characterData:!0,childList:!0,attributes:!0,subtree:!0},tt=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;X.some((function(t){return r.indexOf(t)>-1}))&&e.throttleRefresh()},this.observe=function(t,n){Q&&(e.targetNode=t,document.addEventListener("transitionend",e.onTransitionEnd_),window.addEventListener("resize",e.throttleRefresh),e.observer.observe(document,r(r({},Z),n)))},this.disconnect=function(){Q&&(e.throttleRefresh.cancel(),e.targetNode=null,document.removeEventListener("transitionend",e.onTransitionEnd_),window.removeEventListener("resize",e.throttleRefresh),e.observer.disconnect())},this.throttleRefresh=L(this.refresh,50),this.targetNode=null,this.callback=t,this.observer=new MutationObserver(this.throttleRefresh)};t.clearCache=function(t){t?g.del(t):g.clear()},t.useAsync=W,t.useClickAway=function(t,n,r){void 0===r&&(r="click");var o=I(t),i=u(o),c=o.every((function(t){return"function"==typeof t})),a=c?i:o,s=u(n),l=I(r),f=u(l),h=l.join("");e.useEffect((function(){var t=function(t){var e;(c?a.current:a).some((function(e){var n=G(e);return!n||(null==n?void 0:n.contains(t.target))}))||null===(e=s.current)||void 0===e||e.call(s,t)},e=I(f.current);return e.forEach((function(e){document.addEventListener(e,t)})),function(){e.forEach((function(e){document.removeEventListener(e,t)}))}}),[a,c,h])},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,h=s in t,d=t[s],p=i(e.useState((function(){return h?d:u in t?t[u]:r})),2),v=p[0],y=p[1];a((function(){h&&y(d)}),[d,h]);var g=e.useCallback((function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];h||y(e),t[f]&&t[f].apply(t,[e].concat(n))}),[h,t,f]);return[h?d: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=B(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useDebounceFn=B,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]),h=e.useMemo((function(){return l.length>f}),[f,l.length]),d=i(e.useState((function(){return h&&a?l.slice(0,f):l})),2),p=d[0],v=d[1];return e.useEffect((function(){v(s.current?l.slice(0,f):l)}),[f,l]),{canLimit:h,limited:s.current,data:p,toggle:function(){h&&(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,h=void 0===f?function(){return!1}:f,d=u.refreshDeps,p=void 0===d?[]:d,v=u.autoRun,y=void 0===v||v,g=o(u,["threshold","target","isNoMore","refreshDeps","autoRun"]),m=e.useRef([]),b=e.useRef(1),w=W(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})}})),k=w.run,S=w.data,T=w.loading,E=w.cancel,_=w.params,O=w.mutate,C=o(w,["run","data","loading","cancel","params","mutate"]),R=!!h&&(!T&&h(S)),L=i(_||[]),I=L[0],P=L.slice(1),j=e.useCallback((function(){return k.apply(void 0,[{current:b.current}].concat(P))}),[P,k]),A=e.useCallback((function(){T&&b.current>1&&(b.current-=1),E()}),[E,T]),M=e.useCallback((function(){T||R||(b.current+=1,j())}),[T,R,j]),x=e.useCallback((function(t){var e="function"==typeof t?t(S):t;m.current=(null==e?void 0:e.list)||[],O(e)}),[S,O]),V=e.useCallback((function(){return A(),b.current=1,x((function(t){return r(r({},t),{list:[]})})),j()}),[A,j,x]),N=e.useCallback((function(){if(!T&&l)return M()}),[M,l,T]);return H({target:l,threshold:s,onScrollLower:N}),a((function(){y&&Array.isArray(p)&&p.length>0&&V()}),p),r(r({},C),{loading:T,data:S,run:k,refresh:V,cancel:A,mutate:x,params:[r(r({},I),{current:b.current})].concat(P),loadMore:M,loadingMore:T&&b.current>1,noMore:R})},t.useMount=function(t){e.useEffect((function(){t()}),[])},t.useMountedRef=J,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,h=u.defaultParams,d=u.autoRun,p=void 0===d||d,v=o(u,["defaultPageSize","refreshDeps","defaultParams","autoRun"]),y=e.useMemo((function(){return h||[{current:1,pageSize:s}]}),[s,h]),g=W(t,r({defaultParams:y,autoRun:p},v)),m=g.run,b=g.data,w=g.params,k=g.loading,S=o(g,["run","data","params","loading"]),T=w&&w[0]?w[0]:y[0],E=T.current,_=T.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:E,pageSize:_})}),[C,E,_]),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,_)}),[L,_]),P=e.useCallback((function(t){L(E,t)}),[E,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({},S),{data:b,run:m,refresh:R,loading:k,params:w,pagination:{current:E,pageSize:_,total:O,onChange:L,changeCurrent:I,changePageSize:P},tableProps:{dataSource:(null==b?void 0:b.list)||[],loading:k,onChange:j,pagination:{total:O,current:E,pageSize:_}}})},t.usePersistFn=c,t.usePrevious=function(t){var n=J(),r=e.useRef(),o=e.useRef(t);return n.current&&o.current!==t&&(r.current=o.current,o.current=t),r.current},t.useSafeState=Y,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=G(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=G(r?o.current:o);function e(t){t&&s({width:t.clientWidth,height:t.clientHeight})}if(!t)return function(){};e(t);var n=new tt((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=$(o[1],n,r).run;return e.useEffect((function(){c(t)}),[c,t]),u},t.useThrottleFn=$,t.useUnmount=U,t.useUnmountedRef=q,t.useUpdate=function(){var t=i(Y(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 |
@@ -11,5 +11,5 @@ import { __assign } from "tslib"; | ||
var defaultObserverOptions = { | ||
characterData: true, | ||
childList: true, | ||
attributes: true, | ||
characterData: true, // 监视指定目标节点或子节点树中节点所包含的字符数据的变化 | ||
childList: true, // 观察目标子节点的变化,是否有添加或者删除 | ||
attributes: true, // 观察属性变动 | ||
subtree: true // 观察后代节点,默认为 false | ||
@@ -16,0 +16,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
import Cache2 from 'cache2'; | ||
var memoryCache = new Cache2({ stdTTL: 5 * 60 * 1000 }); | ||
import { Cache } from 'cache2'; | ||
var memoryCache = new Cache({ stdTTL: 5 * 60 * 1000 }); | ||
var getCache = function (key) { | ||
@@ -4,0 +4,0 @@ return memoryCache.get(key); |
@@ -13,5 +13,5 @@ "use strict"; | ||
var defaultObserverOptions = { | ||
characterData: true, | ||
childList: true, | ||
attributes: true, | ||
characterData: true, // 监视指定目标节点或子节点树中节点所包含的字符数据的变化 | ||
childList: true, // 观察目标子节点的变化,是否有添加或者删除 | ||
attributes: true, // 观察属性变动 | ||
subtree: true // 观察后代节点,默认为 false | ||
@@ -18,0 +18,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clearCache = exports.setCache = exports.getCache = void 0; | ||
var tslib_1 = require("tslib"); | ||
var cache2_1 = tslib_1.__importDefault(require("cache2")); | ||
var memoryCache = new cache2_1.default({ stdTTL: 5 * 60 * 1000 }); | ||
var cache2_1 = require("cache2"); | ||
var memoryCache = new cache2_1.Cache({ stdTTL: 5 * 60 * 1000 }); | ||
var getCache = function (key) { | ||
@@ -8,0 +7,0 @@ return memoryCache.get(key); |
{ | ||
"name": "rc-hooks", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"description": "React Hooks Library.", | ||
@@ -56,40 +56,40 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"cache2": "^1.0.4", | ||
"tslib": "^2.6.0", | ||
"ut2": "^1.4.9" | ||
"cache2": "^2.0.1", | ||
"tslib": "^2.6.2", | ||
"ut2": "^1.5.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.5", | ||
"@babel/core": "^7.23.3", | ||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11", | ||
"@babel/preset-env": "^7.22.5", | ||
"@babel/preset-react": "^7.22.5", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@commitlint/cli": "^17.6.6", | ||
"@commitlint/config-conventional": "^17.6.6", | ||
"@rollup/plugin-commonjs": "^25.0.2", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@rollup/plugin-typescript": "^11.1.1", | ||
"@testing-library/react": "^14.0.0", | ||
"@types/jest": "^29.5.2", | ||
"@types/mockjs": "^1.0.7", | ||
"@types/node": "^20.3.2", | ||
"@types/react": "^18.2.21", | ||
"@typescript-eslint/eslint-plugin": "^5.60.1", | ||
"@typescript-eslint/parser": "^5.60.1", | ||
"antd": "^5.9.4", | ||
"babel-jest": "^29.5.0", | ||
"@babel/preset-env": "^7.23.3", | ||
"@babel/preset-react": "^7.23.3", | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@commitlint/cli": "^17.8.1", | ||
"@commitlint/config-conventional": "^17.8.1", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@testing-library/react": "^14.1.2", | ||
"@types/jest": "^29.5.10", | ||
"@types/mockjs": "^1.0.10", | ||
"@types/node": "^20.9.4", | ||
"@types/react": "^18.2.38", | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"antd": "^5.11.3", | ||
"babel-jest": "^29.7.0", | ||
"cross-env": "^7.0.3", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"dayjs": "^1.11.9", | ||
"dumi": "^1.1.50", | ||
"dayjs": "^1.11.10", | ||
"dumi": "^1.1.54", | ||
"dumi-theme-default": "^1.1.24", | ||
"element-remove": "^1.0.4", | ||
"eslint": "^8.43.0", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint": "^8.54.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.6.1", | ||
"jest-environment-jsdom": "^29.6.1", | ||
"lint-staged": "^13.2.2", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"lint-staged": "^13.3.0", | ||
"mockjs": "^1.1.0", | ||
@@ -99,5 +99,5 @@ "prettier": "^2.8.8", | ||
"react-dom": "^18.2.0", | ||
"rollup": "^3.25.3", | ||
"rollup": "^3.29.4", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6" | ||
"typescript": "^5.3.2" | ||
}, | ||
@@ -104,0 +104,0 @@ "peerDependencies": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
528358
5131
+ Addedcache2@2.0.7(transitive)
- Removedcache2@1.1.1(transitive)
Updatedcache2@^2.0.1
Updatedtslib@^2.6.2
Updatedut2@^1.5.5