UNPKG

@654356282/react-keepalive

Version:
28 lines (24 loc) 17.3 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("react"),vr=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},Ke=vr(p);var U=function(){return U=Object.assign||function(u){for(var i,l=1,d=arguments.length;l<d;l++){i=arguments[l];for(var v in i)Object.prototype.hasOwnProperty.call(i,v)&&(u[v]=i[v])}return u},U.apply(this,arguments)};function pr(n,u,i){if(i||arguments.length===2)for(var l=0,d=u.length,v;l<d;l++)(v||!(l in u))&&(v||(v=Array.prototype.slice.call(u,0,l)),v[l]=u[l]);return n.concat(v||Array.prototype.slice.call(u))}var $e={exports:{}},M={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ke;function gr(){if(ke)return M;ke=1;var n=Ke.default,u=Symbol.for("react.element"),i=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,d=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,v={key:!0,ref:!0,__self:!0,__source:!0};function T(g,y,O){var m,S={},w=null,F=null;O!==void 0&&(w=""+O),y.key!==void 0&&(w=""+y.key),y.ref!==void 0&&(F=y.ref);for(m in y)l.call(y,m)&&!v.hasOwnProperty(m)&&(S[m]=y[m]);if(g&&g.defaultProps)for(m in y=g.defaultProps,y)S[m]===void 0&&(S[m]=y[m]);return{$$typeof:u,type:g,key:w,ref:F,props:S,_owner:d.current}}return M.Fragment=i,M.jsx=T,M.jsxs=T,M}var N={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var De;function yr(){return De||(De=1,process.env.NODE_ENV!=="production"&&function(){var n=Ke.default,u=Symbol.for("react.element"),i=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),g=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),F=Symbol.for("react.offscreen"),$=Symbol.iterator,H="@@iterator";function X(e){if(e===null||typeof e!="object")return null;var r=$&&e[$]||e[H];return typeof r=="function"?r:null}var P=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),a=1;a<r;a++)t[a-1]=arguments[a];h("error",e,t)}}function h(e,r,t){{var a=P.ReactDebugCurrentFrame,s=a.getStackAddendum();s!==""&&(r+="%s",t=t.concat([s]));var f=t.map(function(c){return String(c)});f.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,f)}}var b=!1,k=!1,W=!1,Z=!1,Ye=!1,ce;ce=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===l||e===v||Ye||e===d||e===O||e===m||Z||e===F||b||k||W||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===S||e.$$typeof===T||e.$$typeof===g||e.$$typeof===y||e.$$typeof===ce||e.getModuleId!==void 0))}function Me(e,r,t){var a=e.displayName;if(a)return a;var s=r.displayName||r.name||"";return s!==""?t+"("+s+")":t}function le(e){return e.displayName||"Context"}function A(e){if(e==null)return null;if(typeof e.tag=="number"&&R("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case i:return"Portal";case v:return"Profiler";case d:return"StrictMode";case O:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case g:var r=e;return le(r)+".Consumer";case T:var t=e;return le(t._context)+".Provider";case y:return Me(e,e.render,"ForwardRef");case S:var a=e.displayName||null;return a!==null?a:A(e.type)||"Memo";case w:{var s=e,f=s._payload,c=s._init;try{return A(c(f))}catch{return null}}}return null}var D=Object.assign,Y=0,se,fe,de,ve,pe,ge,ye;function he(){}he.__reactDisabledLog=!0;function Ne(){{if(Y===0){se=console.log,fe=console.info,de=console.warn,ve=console.error,pe=console.group,ge=console.groupCollapsed,ye=console.groupEnd;var e={configurable:!0,enumerable:!0,value:he,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Y++}}function Ue(){{if(Y--,Y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:se}),info:D({},e,{value:fe}),warn:D({},e,{value:de}),error:D({},e,{value:ve}),group:D({},e,{value:pe}),groupCollapsed:D({},e,{value:ge}),groupEnd:D({},e,{value:ye})})}Y<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Q=P.ReactCurrentDispatcher,ee;function V(e,r,t){{if(ee===void 0)try{throw Error()}catch(s){var a=s.stack.trim().match(/\n( *(at )?)/);ee=a&&a[1]||""}return` `+ee+e}}var re=!1,q;{var Ve=typeof WeakMap=="function"?WeakMap:Map;q=new Ve}function _e(e,r){if(!e||re)return"";{var t=q.get(e);if(t!==void 0)return t}var a;re=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var f;f=Q.current,Q.current=null,Ne();try{if(r){var c=function(){throw Error()};if(Object.defineProperty(c.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(c,[])}catch(j){a=j}Reflect.construct(e,[],c)}else{try{c.call()}catch(j){a=j}e.call(c.prototype)}}else{try{throw Error()}catch(j){a=j}e()}}catch(j){if(j&&a&&typeof j.stack=="string"){for(var o=j.stack.split(` `),C=a.stack.split(` `),_=o.length-1,E=C.length-1;_>=1&&E>=0&&o[_]!==C[E];)E--;for(;_>=1&&E>=0;_--,E--)if(o[_]!==C[E]){if(_!==1||E!==1)do if(_--,E--,E<0||o[_]!==C[E]){var x=` `+o[_].replace(" at new "," at ");return e.displayName&&x.includes("<anonymous>")&&(x=x.replace("<anonymous>",e.displayName)),typeof e=="function"&&q.set(e,x),x}while(_>=1&&E>=0);break}}}finally{re=!1,Q.current=f,Ue(),Error.prepareStackTrace=s}var K=e?e.displayName||e.name:"",je=K?V(K):"";return typeof e=="function"&&q.set(e,je),je}function qe(e,r,t){return _e(e,!1)}function Be(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function B(e,r,t){if(e==null)return"";if(typeof e=="function")return _e(e,Be(e));if(typeof e=="string")return V(e);switch(e){case O:return V("Suspense");case m:return V("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case y:return qe(e.render);case S:return B(e.type,r,t);case w:{var a=e,s=a._payload,f=a._init;try{return B(f(s),r,t)}catch{}}}return""}var J=Object.prototype.hasOwnProperty,Ee={},be=P.ReactDebugCurrentFrame;function G(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}function Je(e,r,t,a,s){{var f=Function.call.bind(J);for(var c in e)if(f(e,c)){var o=void 0;try{if(typeof e[c]!="function"){var C=Error((a||"React class")+": "+t+" type `"+c+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[c]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw C.name="Invariant Violation",C}o=e[c](r,c,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(_){o=_}o&&!(o instanceof Error)&&(G(s),R("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",a||"React class",t,c,typeof o),G(null)),o instanceof Error&&!(o.message in Ee)&&(Ee[o.message]=!0,G(s),R("Failed %s type: %s",t,o.message),G(null))}}}var Ge=Array.isArray;function te(e){return Ge(e)}function ze(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return me(e),!1}catch{return!0}}function me(e){return""+e}function Re(e){if(He(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ze(e)),me(e)}var L=P.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Ce,Te,ne;ne={};function Ze(e){if(J.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Qe(e){if(J.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function er(e,r){if(typeof e.ref=="string"&&L.current&&r&&L.current.stateNode!==r){var t=A(L.current.type);ne[t]||(R('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',A(L.current.type),e.ref),ne[t]=!0)}}function rr(e,r){{var t=function(){Ce||(Ce=!0,R("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function tr(e,r){{var t=function(){Te||(Te=!0,R("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var nr=function(e,r,t,a,s,f,c){var o={$$typeof:u,type:e,key:r,ref:t,props:c,_owner:f};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function ar(e,r,t,a,s){{var f,c={},o=null,C=null;t!==void 0&&(Re(t),o=""+t),Qe(r)&&(Re(r.key),o=""+r.key),Ze(r)&&(C=r.ref,er(r,s));for(f in r)J.call(r,f)&&!Xe.hasOwnProperty(f)&&(c[f]=r[f]);if(e&&e.defaultProps){var _=e.defaultProps;for(f in _)c[f]===void 0&&(c[f]=_[f])}if(o||C){var E=typeof e=="function"?e.displayName||e.name||"Unknown":e;o&&rr(c,E),C&&tr(c,E)}return nr(e,o,C,s,a,L.current,c)}}var ae=P.ReactCurrentOwner,Se=P.ReactDebugCurrentFrame;function I(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Se.setExtraStackFrame(t)}else Se.setExtraStackFrame(null)}var ie;ie=!1;function ue(e){return typeof e=="object"&&e!==null&&e.$$typeof===u}function xe(){{if(ae.current){var e=A(ae.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ir(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Oe={};function ur(e){{var r=xe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function we(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ur(r);if(Oe[t])return;Oe[t]=!0;var a="";e&&e._owner&&e._owner!==ae.current&&(a=" It was passed a child from "+A(e._owner.type)+"."),I(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,a),I(null)}}function Pe(e,r){{if(typeof e!="object")return;if(te(e))for(var t=0;t<e.length;t++){var a=e[t];ue(a)&&we(a,r)}else if(ue(e))e._store&&(e._store.validated=!0);else if(e){var s=X(e);if(typeof s=="function"&&s!==e.entries)for(var f=s.call(e),c;!(c=f.next()).done;)ue(c.value)&&we(c.value,r)}}}function or(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===y||r.$$typeof===S))t=r.propTypes;else return;if(t){var a=A(r);Je(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!ie){ie=!0;var s=A(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",s||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function cr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var a=r[t];if(a!=="children"&&a!=="key"){I(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),I(null);break}}e.ref!==null&&(I(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}function Ae(e,r,t,a,s,f){{var c=Le(e);if(!c){var o="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var C=ir(s);C?o+=C:o+=xe();var _;e===null?_="null":te(e)?_="array":e!==void 0&&e.$$typeof===u?(_="<"+(A(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,o)}var E=ar(e,r,t,s,f);if(E==null)return E;if(c){var x=r.children;if(x!==void 0)if(a)if(te(x)){for(var K=0;K<x.length;K++)Pe(x[K],e);Object.freeze&&Object.freeze(x)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Pe(x,e)}return e===l?cr(E):or(E),E}}function lr(e,r,t){return Ae(e,r,t,!0)}function sr(e,r,t){return Ae(e,r,t,!1)}var fr=sr,dr=lr;N.Fragment=l,N.jsx=fr,N.jsxs=dr}()),N}(function(n){process.env.NODE_ENV==="production"?n.exports=gr():n.exports=yr()})($e);const oe=$e.exports.jsx;var z=p.createContext(null);function hr(n,u){var i=p.useRef(u);function l(d,v){return d.length!==v.length?!1:d.every(function(T,g){return Object.is(T,v[g])})}p.useEffect(function(){l(u,i.current)||(n(u,i.current),i.current=u)},u)}function _r(n){var u="pending",i=n.then(function(){return u="success"});return function(){switch(u){case"pending":throw i;case"success":return null}}}var Fe=function(){return function(){}}(),Er=function(){return _r(new Promise(function(){}))}();function Ie(n){return Array.isArray(n)}function br(n){return n==null}function We(n){try{n()}catch{}}var mr=function(n){var u=n.resource,i=n.children;return u==null||u(),i},Rr=p.forwardRef(function(n,u){if(!p.isValidElement(n.children))throw Error("Please use valid ReactElement!");var i=br(n.children.key)?n.children.type.toString():n.children.key;if(Ie(n.includes)&&Ie(n.excludes))throw Error("excludes and includes can't exist at the same time");var l=n.children,d=p.useMemo(function(){return new Map},[]),v=p.useState([]),T=v[0],g=v[1],y=p.useState(null),O=y[0],m=y[1],S=p.useState(null),w=S[0],F=S[1];p.useEffect(function(){m(i)},[i]),hr(function(h,b){var k=b[0];if(k!==null){var W=d.get(k).unAnctivedCallbacks;W.forEach(function(Z){return We(Z)})}},[i]);var $={drop:function(h){d.has(h)&&(d.delete(h),g(function(b){var k=b.findIndex(function(W){return W===h});return b.splice(k,1),pr([],b,!0)}))}};p.useImperativeHandle(u,function(){return{controller:$}});function H(h){return n.excludes?typeof n.excludes=="function"?n.excludes(h):n.excludes instanceof RegExp?n.excludes.test(h.toString()):n.excludes.includes(h):!1}function X(h){return n.includes?typeof n.includes=="function"?n.includes(h):n.includes instanceof RegExp?n.includes.test(h.toString()):n.includes.includes(h):!0}function P(h){return!H(h)&&X(h)}if(d.has(i)){var R=d.get(i);R.component=l}else d.set(i,{component:l,actived:!1,key:i,resource:Fe,isKeepAlive:!0,activedCallbacks:[],unAnctivedCallbacks:[]}),g(T.concat(i));return w!==i&&F(i),oe(z.Provider,U({value:{store:d,activedKey:P(i)?i:null,deferActivedKey:O,controller:$}},{children:T.map(function(h){var b=d.get(h);if(b.isKeepAlive=P(h),!b.isKeepAlive){b.actived=!1;var k=b.key===i;return k?l:null}return i===b.key?(b.actived=!0,b.resource=Fe):(b.actived=!1,b.resource=Er),oe(p.Suspense,U({fallback:null},{children:oe(mr,U({resource:b.resource},{children:b.component}))}),h)})}))});function Cr(n){var u=p.useContext(z)||{},i=u.activedKey,l=u.deferActivedKey,d=p.useState(i)[0];p.useLayoutEffect(function(){i===l&&i===d&&n()},[l])}function Tr(n){var u=p.useContext(z)||{},i=u.activedKey,l=u.store,d=p.useState(i)[0],v=p.useRef(n);v.current=n;var T=p.useCallback(function(){We(v.current)},[]);p.useEffect(function(){if(l){var g=l.get(d);g&&g.isKeepAlive&&g.unAnctivedCallbacks.push(T)}},[l]),p.useEffect(function(){return function(){var g=l==null?void 0:l.get(d);if(g&&g.isKeepAlive&&g.actived){T();var y=g.unAnctivedCallbacks,O=y.findIndex(function(m){return m===T});y.splice(O,1)}}},[])}function Sr(){var n=(p.useContext(z)||{}).controller;return n}exports.KeepAlive=Rr;exports.useActived=Cr;exports.useController=Sr;exports.useUnactived=Tr;