rc-hooks
Version:
React Hooks Library.
3 lines (2 loc) • 28.4 kB
JavaScript
!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,n,r){return new(n||(n=Promise))(function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(u,c)}a((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return u.next=c(0),u.throw=c(1),u.return=c(2),"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function c(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"==typeof SuppressedError&&SuppressedError;var a=void 0,s="undefined",l=Object.prototype,f=l.toString,h=l.hasOwnProperty,p="[object ",d=p+"String]",v=p+"Symbol]",y=p+"Window]";function g(t){return Array.isArray(t)}function m(t){return null!==t&&"object"==typeof t}function b(t){return f.call(t)}var w=/^0b[01]+$/i,k=/^0o[0-7]+$/i,T=/^[-+]0x[0-9a-f]+$/i;function S(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||b(t)===v}(t))return NaN;if(function(t){return"function"==typeof t||m(t)}(t)&&(t=Number(t)),"string"!=typeof t)return 0===t?t:+t;t=t.trim();var e=w.test(t);return e||k.test(t)?parseInt(t.slice(2),e?2:8):T.test(t)?NaN:+t}function _(t,e,n){return void 0===n&&(n=!1),t===e?!n||(0!==t||1/t==1/e):t!=t&&e!=e}var E=typeof window!==s&&m(window)&&typeof document!==s&&m(document)&&window.document===document;b(function(){return arguments}());function O(t){return t===a}function C(t,e,n,r){if(void 0===r&&(r=!1),"function"!=typeof t)throw new TypeError("Expected a function");var o,i,u,c,s,l,f,h;function p(e){return u=e,l=t.apply(s,c),s=c=a,l}function d(){for(var t=[],f=0;f<arguments.length;f++)t[f]=arguments[f];s=this,c=t;var h=Date.now(),d=function(t){if(i===a)return!0;var n=t-i;return n>=e||n<0||r&&t-u>=e}(h),v=r?d||i===a||o!==a?e:e-(h-i):e;return i=h,d&&n&&o===a?p(h):(o===a||r||(clearTimeout(o),o=a),o===a&&(o=setTimeout(function(){o=a,p(Date.now())},v)),l)}return f=S(e),h=0,e=null==f||f!=f?h:f,d.cancel=function(){o!==a&&(clearTimeout(o),o=a),i=o=c=s=a},d.flush=function(){return o!==a?(clearTimeout(o),o=a,p(Date.now())):l},d.pending=function(){return o!==a},d}function L(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!1),C(t,e,n)}function I(t,e){var n=!1;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n||(n=!0,t.apply(void 0,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],c(r),!1)),setTimeout(function(){n=!1},e))}}function R(t,e,n){return void 0===e&&(e=0),void 0===n&&(n=!0),C(t,e,n,!0)}function P(t){return m(t)&&b(t)===y}function j(t){return arguments.length?g(t)?t:[t]:[]}var x=function(t,e,n){if(void 0===n&&(n=!0),_(t,e,n))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),o=Object.keys(e);if(r.length!==o.length)return!1;for(var i=0;i<r.length;i++){var u=r[i];if(!h.call(e,u)||!_(t[u],e[u],n))return!1}return!0};function V(){}function N(t){var n=e.useRef(t);return n.current=t,n}function F(t){var n=N(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}var D=function(t,n){var r=e.useRef(!1);e.useEffect(function(){if(r.current)return t();r.current=!0},n)},A=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!1,function(){t.current=!0}},[]),t},M=function(){function t(){this.handlers={}}return t.prototype.eventNames=function(){var t,e=(null===(t=Object.getOwnPropertySymbols)||void 0===t?void 0:t.call(Object,this.handlers))||[];return Object.keys(this.handlers).concat(e)},t.prototype.rawListeners=function(t){var e=this.handlers[t];return e?e.map(function(t){return t.raw}):[]},t.prototype.listeners=function(t){var e=this.handlers[t];return e?e.map(function(t){return t.wrap}):[]},t.prototype.hasListener=function(t,e){return this.rawListeners(t).some(function(t){return t===e})},t.prototype._on=function(t,e,n,r,o){void 0===r&&(r=null),void 0===o&&(o=1);var i={raw:e,wrap:n,context:r};if(this.handlers[t]){var u=1===o?"push":"unshift";this.handlers[t][u](i)}else this.handlers[t]=[i];return this},t.prototype.prependListener=function(t,e,n){return this._on(t,e,e,n,0)},t.prototype.on=function(t,e,n){return this._on(t,e,e,n)},t.prototype._wrapOnce=function(t,e,n){var r=this;void 0===n&&(n=null);var o=function(){for(var i=[],u=0;u<arguments.length;u++)i[u]=arguments[u];e.apply(n,i),r.off(t,o)};return o},t.prototype.once=function(t,e,n){var r=this._wrapOnce(t,e,n);return this._on(t,e,r,n)},t.prototype.prependOnceListener=function(t,e,n){var r=this._wrapOnce(t,e,n);return this._on(t,e,r,n,0)},t.prototype.off=function(t,e){var n=this.handlers[t];if(n)if(e){var r=n.findIndex(function(t){return t.wrap===e||t.raw===e});-1!==r&&n.splice(r,1)}else delete this.handlers[t];return this},t.prototype.offAll=function(){return this.handlers={},this},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this.handlers[t];return!!(r&&r.length>0)&&(r.forEach(function(t){t.wrap.apply(t.context,e)}),!0)},t}(),W={},z=function(){function t(t){void 0===t&&(t="default"),this.scope=t,W[this.scope]||(W[this.scope]={}),this.data=W[this.scope]}return t.prototype.getItem=function(t){return t in this.data?this.data[t]:null},t.prototype.setItem=function(t,e){this.data[t]=e},t.prototype.removeItem=function(t){delete this.data[t]},t.prototype.clear=function(){W[this.scope]={},this.data=W[this.scope]},t}();function K(t){try{var e="object"==typeof t&&null!==t&&!!t.setItem&&!!t.getItem&&!!t.removeItem;if(e){var n=Math.random().toString(16).substring(2,8)+(new Date).getTime();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}}var H=function(){function t(t,e){void 0===e&&(e={});var n=!!t&&K(t);this.options=r({needParsed:n,prefix:""},e),this.storage=n?t:new z(this.options.memoryScope)}return t.prototype.getKey=function(t){return this.options.prefix+t},t.prototype.get=function(t){var e=this.storage.getItem(this.getKey(t));return this.options.needParsed?function(t,e){try{return JSON.parse(t,e)}catch(e){return t}}(e,this.options.reviver):e},t.prototype.set=function(t,e){this.storage.setItem(this.getKey(t),this.options.needParsed?function(t,e){return JSON.stringify(t,e)}(e,this.options.replacer):e)},t.prototype.del=function(t){this.storage.removeItem(this.getKey(t))},t.prototype.clear=function(){"function"==typeof this.storage.clear&&this.storage.clear()},t}(),U="default",B=function(t){function e(e,n){var o,i=t.call(this)||this,u=U;return"string"==typeof e?u=e||U:"object"==typeof e&&(o=e),o||"object"!=typeof n||(o=n),i.options=r({max:-1,stdTTL:0,maxStrategy:"limited",checkperiod:0,prefix:"cache2_"},o),i.storage=new H(i.options.storage,r({memoryScope:u},i.options)),i.cacheKey=u,i.startCheckperiod(),i}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}(M),$=function(){function t(t,e){void 0===e&&(e="uh_async_memo"),this.promiseCache={},this.cache=new B(e,t)}return t.prototype.run=function(t,e,n){var o,i=this;if(!e||"string"!=typeof(o=e)&&b(o)!==d)return t();var u=r({persisted:!0},n);if(u.persisted){var c=this.cache.get(e);if(c)return Promise.resolve(c)}return this.promiseCache[e]||(this.promiseCache[e]=t().then(function(t){return delete i.promiseCache[e],i.cache.set(e,t,u.ttl),t}).catch(function(t){return delete i.promiseCache[e],Promise.reject(t)})),this.promiseCache[e]},t}();function J(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var q=[];var G=!1;if("undefined"!=typeof window&&window.addEventListener&&!G){window.addEventListener("visibilitychange",function(){if(J())for(var t=0;t<q.length;t++){(0,q[t])()}},!1),G=!0}var Y=[];var Q=!1;if("undefined"!=typeof window&&window.addEventListener&&!Q){var X=function(){if(J()&&("undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine))for(var t=0;t<Y.length;t++){(0,Y[t])()}};window.addEventListener("visibilitychange",X,!1),window.addEventListener("focus",X,!1),Q=!0}var Z="rc-hooks",tt=new $({prefix:Z,stdTTL:3e5});function et(t){return tt.cache.get(t)}var nt=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=this.options,n=e.pollingInterval,r=e.refreshOnWindowFocus,o=e.focusTimespan;if(this.updateDebounce(),n&&this.unsubscribes.push((t=this.rePolling.bind(this),q.push(t),function(){var e=q.indexOf(t);q.splice(e,1)})),r){var i=I(this.refresh.bind(this),o);this.unsubscribes.push(function(t){return Y.push(t),function(){var e=Y.indexOf(t);Y.splice(e,1)}}(i))}},t.prototype.updateDebounce=function(){var t=this.options,e=t.debounceInterval,n=t.throttleInterval;this.debounce="number"==typeof e&&e>0?L(this._run,e):void 0,this.throttle="number"==typeof n&&n>0?R(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,p=o.pollingWhenHidden,d=o.pollingInterval;return null==h||h(e),new Promise(function(n,o){tt.run(function(){return t.async.apply(t,e).then(function(t){return"function"==typeof a?a(t,e):t})},i,{persisted:c,ttl:u}).then(function(o){r===t.counter&&(null==s||s(o,e),n(o))}).catch(function(n){r===t.counter&&(null==l||l(n,e),o(n))}).finally(function(){if(r===t.counter&&(null==f||f(),d)){if(!J()&&!p)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout(function(){t.run.apply(t,e)},d)}})})},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}(),rt=function(t,n){var o=n||{},i=o.autoRun,u=void 0===i||i,a=o.refreshDeps,s=void 0===a?[]:a,l=o.defaultParams,f=o.loadingDelay,h=o.__INTERNAL_FORMAT__,p=o.defaultLoading,d=o.initialData,v=o.cacheKey,y=void 0===v?"":v,m=o.cacheTime,b=void 0===m?3e5:m,w=o.persisted,k=void 0!==w&&w,T=o.onSuccess,S=void 0===T?V:T,_=o.onError,E=void 0===_?V:_,C=o.onFinally,L=void 0===C?V:C,I=o.onBefore,R=void 0===I?V:I,P=o.pollingInterval,j=void 0===P?0:P,M=o.pollingWhenHidden,W=void 0===M||M,z=o.refreshOnWindowFocus,K=void 0!==z&&z,H=o.focusTimespan,U=void 0===H?5e3:H,B=o.debounceInterval,$=o.throttleInterval,J=c(e.useState(function(){return{params:[],loading:!!(O(p)?u&&!f:p),error:null,data:y?et(y):d}}),2),q=J[0],G=J[1],Y=N(q),Q=A(),X=e.useRef(null),Z=F(t),tt=F(S),rt=F(E),ot=F(L),it=F(R),ut=N(h),ct=e.useCallback(function(t){it(t),X.current&&clearTimeout(X.current),(y?et(y):void 0)&&k||(Y.current.loading===!f&&x(Y.current.params,t)||G(function(e){return r(r({},e),{loading:!f,params:t})}),f&&(X.current=setTimeout(function(){Q.current||G(function(t){return r(r({},t),{loading:!0})})},f)))},[y,Y,f,it,k,Q]),at=e.useCallback(function(t,e){X.current&&clearTimeout(X.current),G(function(e){return r(r({},e),{data:t,error:null,loading:!1})}),tt(t,e)},[tt]),st=e.useCallback(function(t,e){X.current&&clearTimeout(X.current),G(function(e){return r(r({},e),{error:t,loading:!1})}),rt(t,e)},[rt]),lt=e.useRef();lt.current||(lt.current=new nt(Z,{cacheKey:y,cacheTime:b,persisted:k,formatResult:ut.current,onSuccess:at,onError:st,onFinally:ot,onBefore:ct,debounceInterval:B,throttleInterval:$,pollingInterval:j,pollingWhenHidden:W,refreshOnWindowFocus:K,focusTimespan:U})),D(function(){lt.current.updateOptions({cacheKey:y,cacheTime:b,persisted:k,formatResult:ut.current,onSuccess:at,onError:st,onFinally:ot,onBefore:ct,debounceInterval:B,throttleInterval:$,pollingInterval:j,pollingWhenHidden:W,refreshOnWindowFocus:K,focusTimespan:U})},[tt,rt,y,b,k,B,$,ot,it,j,W,K,U,at,st,ct]);var ft=e.useCallback(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return lt.current.run.apply(lt.current,t)},[]),ht=e.useCallback(function(){return lt.current.refresh()},[]),pt=e.useCallback(function(){lt.current.cancel(),X.current&&clearTimeout(X.current),G(function(t){return r(r({},t),{loading:!1})})},[]);return D(function(){u&&g(s)&&s.length>0&&ht()},[u].concat(s)),e.useEffect(function(){if(u){var t=g(l)?l:void 0!==l?[l]:[];ft.apply(void 0,t)}return lt.current.resume(),function(){pt(),lt.current.destroy(!1)}},[]),r(r({},q),{run:ft,cancel:pt,mutate:function(t){G("function"==typeof t?function(e){return r(r({},e),{data:t(q.data)})}:function(e){return r(r({},e),{data:t})})},refresh:ht})};function ot(t){return"function"==typeof t?t():t}var it=function(t){var n=void 0===t?{}:t,r=n.target,o=n.threshold,i=void 0===o?100:o,u=n.onScrollLower,c=F(void 0===u?function(){}:u),a=e.useCallback(function(){if(r){var t,e=ot(r);if(e)void 0===(t=e)&&(t=window),(E&&t?P(t)?document.documentElement.scrollHeight:t.scrollHeight:0)-function(t){return void 0===t&&(t=window),E&&t?P(t)?window.scrollY:t.scrollTop:0}(e)<=function(t){return void 0===t&&(t=window),E&&t?P(t)?document.documentElement.clientHeight:t.clientHeight:0}(e)+i&&c()}},[c,r,i]);e.useEffect(function(){if(r){var t=ot(r);if(t)return t.addEventListener("scroll",a),function(){t.removeEventListener("scroll",a)}}},[r,a])};var ut=function(t){var n=N(t);e.useEffect(function(){return function(){return n.current()}},[])};function ct(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=N(t),i=e.useRef(null);return null===i.current&&(i.current=L(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)},n,r)),ut(function(){i.current.cancel()}),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}function at(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=N(t),i=e.useRef(null);return null===i.current&&(i.current=R(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.current.apply(void 0,t)},n,r)),ut(function(){i.current.cancel()}),{run:i.current,cancel:i.current.cancel,flush:i.current.flush}}var st=Z+"_useCacheState";function lt(t){return new B(st,{storage:t})}var ft=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),t};function ht(t){var n=A(),r=c(e.useState(t),2),o=r[0],i=r[1];return[o,e.useCallback(function(t){n.current||i(t)},[])]}function pt(t){return"function"==typeof t?t():"object"==typeof t&&t&&"current"in t?t.current:t}var dt=Object.prototype.hasOwnProperty;var vt=["top","right","bottom","left","width","height","size","weight"],yt={characterData:!0,childList:!0,attributes:!0,subtree:!0},gt=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;vt.some(function(t){return r.indexOf(t)>-1})&&e.throttleRefresh()},this.observe=function(t,n){E&&(e.targetNode=t,document.addEventListener("transitionend",e.onTransitionEnd_),window.addEventListener("resize",e.throttleRefresh),e.observer.observe(document,r(r({},yt),n)))},this.disconnect=function(){E&&(e.throttleRefresh.cancel(),e.targetNode=null,document.removeEventListener("transitionend",e.onTransitionEnd_),window.removeEventListener("resize",e.throttleRefresh),e.observer.disconnect())},this.throttleRefresh=R(this.refresh,50),this.targetNode=null,this.callback=t,this.observer=new MutationObserver(this.throttleRefresh)};t.clearCache=function(t){t?tt.cache.del(t):tt.cache.clear()},t.clearCacheState=function(t,e){var n=lt(t);e?n.del(e):n.clear()},t.useAsync=rt,t.useCacheState=function(t,n,r){void 0===r&&(r={});var o=r.ttl,i=r.storage,u=e.useMemo(function(){return lt(i)},[i]),a=c(e.useState(function(){var e=u.get(t);return O(e)?n:e}),2),s=a[0],l=a[1];return[s,e.useCallback(function(e){l(function(n){var r=e instanceof Function?e(n):e;return u.set(t,r,o),r})},[u,t,o])]},t.useClickAway=function(t,n,r){void 0===r&&(r="click");var o=j(t),i=N(o),u=o.every(function(t){return"function"==typeof t}),c=u?i:o,a=N(n),s=j(r),l=N(s),f=s.join("");e.useEffect(function(){var t=function(t){var e;(u?c.current:c).some(function(e){var n=pt(e);return!n||(null==n?void 0:n.contains(t.target))})||null===(e=a.current)||void 0===e||e.call(a,t)},e=j(l.current);return e.forEach(function(e){document.addEventListener(e,t)}),function(){e.forEach(function(e){document.removeEventListener(e,t)})}},[c,u,f])},t.useControllableValue=function(t,n){void 0===t&&(t={}),void 0===n&&(n={});var r=n.defaultValue,o=n.defaultValuePropName,i=void 0===o?"defaultValue":o,u=n.valuePropName,a=void 0===u?"value":u,s=n.trigger,l=void 0===s?"onChange":s,f=dt.call(t,a),h=c(e.useState(function(){return f?t[a]:dt.call(t,i)?t[i]:r}),2),p=h[0],d=h[1],v=e.useCallback(function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];f||d(e),t[l]&&t[l].apply(t,[e].concat(n))},[f,t,l]);return[f?t[a]:p,v]},t.useDebounce=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!1);var o=c(e.useState(t),2),i=o[0],u=ct(o[1],n,r).run;return e.useEffect(function(){u(t)},[u,t]),i},t.useDebounceFn=ct,t.useLatest=N,t.useLimitList=function(t,n){void 0===n&&(n={});var r=n||{},o=r.count,i=void 0===o?3:o,u=r.defaultLimited,a=void 0===u||u,s=c(e.useState(a),2),l=s[0],f=s[1],h=e.useMemo(function(){return g(t)&&t.length>i?l?t.slice(0,i):t:t||[]},[l,t,i]);return{limited:l,canLimit:g(t)&&t.length>i,data:h,toggle:function(){f(!l)}}},t.useLoadMore=function(t,n){var a=this,s=n||{},l=s.threshold,f=void 0===l?100:l,h=s.target,p=s.isNoMore,d=void 0===p?function(){return!1}:p,v=s.refreshDeps,y=void 0===v?[]:v,m=s.autoRun,b=void 0===m||m,w=o(s,["threshold","target","isNoMore","refreshDeps","autoRun"]),k=e.useRef([]),T=e.useRef(1),S=rt(t,r(r({defaultParams:[{current:T.current}],autoRun:b},w),{onError:function(t,e){var n;T.current>1&&(T.current-=1),null===(n=null==w?void 0:w.onError)||void 0===n||n.call(w,t,e)},__INTERNAL_FORMAT__:function(t){return k.current=1===T.current?t.list:k.current.concat(t.list),r(r({},t),{list:k.current})}})),_=S.run,E=S.data,O=S.loading,C=S.cancel,L=S.params,I=S.mutate,R=o(S,["run","data","loading","cancel","params","mutate"]),P=!!d&&(!O&&d(E)),j=c(L||[]),x=j[0],V=j.slice(1),N=e.useCallback(function(){return _.apply(void 0,[{current:T.current}].concat(V))},[V,_]),F=e.useCallback(function(){O&&T.current>1&&(T.current-=1),C()},[C,O]),A=e.useCallback(function(){return i(a,void 0,void 0,function(){return u(this,function(t){return O||P?[2]:(T.current+=1,[2,N()])})})},[O,P,N]),M=e.useCallback(function(t){var e="function"==typeof t?t(E):t;k.current=(null==e?void 0:e.list)||[],I(e)},[E,I]),W=e.useCallback(function(){return F(),T.current=1,M(function(t){return r(r({},t),{list:[]})}),N()},[F,N,M]),z=e.useCallback(function(){if(!O&&h)return A()},[A,h,O]);return it({target:h,threshold:f,onScrollLower:z}),D(function(){b&&g(y)&&y.length>0&&W()},y),r(r({},R),{loading:O,data:E,run:_,refresh:W,cancel:F,mutate:M,params:[r(r({},x),{current:T.current})].concat(V),loadMore:A,loadingMore:O&&T.current>1,noMore:P})},t.useMount=function(t){e.useEffect(function(){t()},[])},t.useMountedRef=ft,t.usePagination=function(t,n){var i=n||{},u=i.defaultPageSize,a=void 0===u?10:u,s=i.refreshDeps,l=void 0===s?[]:s,f=i.defaultParams,h=i.autoRun,p=void 0===h||h,d=o(i,["defaultPageSize","refreshDeps","defaultParams","autoRun"]),v=e.useMemo(function(){return f||[{current:1,pageSize:a}]},[a,f]),y=rt(t,r({defaultParams:v,autoRun:p},d)),m=y.run,b=y.data,w=y.params,k=y.loading,T=o(y,["run","data","params","loading"]),S=w&&w[0]?w[0]:v[0],_=S.current,E=S.pageSize,O=(null==b?void 0:b.total)||0,C=e.useCallback(function(t){var e=c(w),n=e[0],o=e.slice(1);return m.apply(void 0,[r(r({},n),t)].concat(o))},[w,m]),L=e.useCallback(function(){return C({current:_,pageSize:E})},[C,_,E]),I=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]),R=e.useCallback(function(t){I(t,E)},[I,E]),P=e.useCallback(function(t){I(_,t)},[_,I]),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 D(function(){p&&g(l)&&l.length>0&&R(1)},l),r(r({},T),{data:b,run:m,refresh:L,loading:k,params:w,pagination:{current:_,pageSize:E,total:O,onChange:I,changeCurrent:R,changePageSize:P},tableProps:{dataSource:(null==b?void 0:b.list)||[],loading:k,onChange:j,pagination:{total:O,current:_,pageSize:E}}})},t.usePersistFn=F,t.usePrevious=function(t){var n=ft(),r=e.useRef(void 0),o=e.useRef(t);return n.current&&o.current!==t&&(r.current=o.current,o.current=t),r.current},t.useSafeState=ht,t.useSetState=function(t){var n=c(e.useState(t),2),o=n[0],i=n[1];return[o,e.useCallback(function(t){i(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=N(t),r=c(e.useState(function(){var e=pt(t);return{width:null==e?void 0:e.clientWidth,height:null==e?void 0:e.clientHeight}}),2),o=r[0],i=r[1],u=N(o);return e.useEffect(function(){var t=pt(n.current);function e(t){var e=null==t?void 0:t.clientWidth,n=null==t?void 0:t.clientHeight;e===u.current.width&&n===u.current.height||i({width:e,height:n})}if(!t)return function(){};e(t);var r=new gt(function(t){t.forEach(function(t){e(t.target)})});return r.observe(t),function(){r.disconnect()}},[n,u]),o},t.useThrottle=function(t,n,r){void 0===n&&(n=0),void 0===r&&(r=!0);var o=c(e.useState(t),2),i=o[0],u=at(o[1],n,r).run;return e.useEffect(function(){u(t)},[u,t]),i},t.useThrottleFn=at,t.useUnmount=ut,t.useUnmountedRef=A,t.useUpdate=function(){var t=c(ht(0),2)[1];return e.useCallback(function(){t(function(t){return t+1})},[])},t.useUpdateEffect=D,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