@654356282/react-keepalive
Version:
React Keepalive Component
28 lines (24 loc) • 17.5 kB
JavaScript
(function(O,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],s):(O=typeof globalThis<"u"?globalThis:O||self,s(O.ReactKeepalive={},O.React))})(this,function(O,s){"use strict";const le=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(s);var Y=function(){return Y=Object.assign||function(o){for(var i,l=1,v=arguments.length;l<v;l++){i=arguments[l];for(var p in i)Object.prototype.hasOwnProperty.call(i,p)&&(o[p]=i[p])}return o},Y.apply(this,arguments)};function Me(n,o,i){if(i||arguments.length===2)for(var l=0,v=o.length,p;l<v;l++)(p||!(l in o))&&(p||(p=Array.prototype.slice.call(o,0,l)),p[l]=o[l]);return n.concat(p||Array.prototype.slice.call(o))}var fe={exports:{}},L={};/**
* @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 se;function Ne(){if(se)return L;se=1;var n=le.default,o=Symbol.for("react.element"),i=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,v=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function T(y,h,w){var m,S={},P=null,I=null;w!==void 0&&(P=""+w),h.key!==void 0&&(P=""+h.key),h.ref!==void 0&&(I=h.ref);for(m in h)l.call(h,m)&&!p.hasOwnProperty(m)&&(S[m]=h[m]);if(y&&y.defaultProps)for(m in h=y.defaultProps,h)S[m]===void 0&&(S[m]=h[m]);return{$$typeof:o,type:y,key:P,ref:I,props:S,_owner:v.current}}return L.Fragment=i,L.jsx=T,L.jsxs=T,L}var M={};/**
* @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 Ue(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){var n=le.default,o=Symbol.for("react.element"),i=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),y=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),N=Symbol.iterator,q="@@iterator";function $(e){if(e===null||typeof e!="object")return null;var r=N&&e[N]||e[q];return typeof r=="function"?r:null}var j=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];g("error",e,t)}}function g(e,r,t){{var a=j.ReactDebugCurrentFrame,f=a.getStackAddendum();f!==""&&(r+="%s",t=t.concat([f]));var d=t.map(function(c){return String(c)});d.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,d)}}var b=!1,D=!1,U=!1,ee=!1,qe=!1,he;he=Symbol.for("react.module.reference");function $e(e){return!!(typeof e=="string"||typeof e=="function"||e===l||e===p||qe||e===v||e===w||e===m||ee||e===I||b||D||U||typeof e=="object"&&e!==null&&(e.$$typeof===P||e.$$typeof===S||e.$$typeof===T||e.$$typeof===y||e.$$typeof===h||e.$$typeof===he||e.getModuleId!==void 0))}function er(e,r,t){var a=e.displayName;if(a)return a;var f=r.displayName||r.name||"";return f!==""?t+"("+f+")":t}function ge(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 p:return"Profiler";case v:return"StrictMode";case w:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case y:var r=e;return ge(r)+".Consumer";case T:var t=e;return ge(t._context)+".Provider";case h:return er(e,e.render,"ForwardRef");case S:var a=e.displayName||null;return a!==null?a:A(e.type)||"Memo";case P:{var f=e,d=f._payload,c=f._init;try{return A(c(d))}catch{return null}}}return null}var F=Object.assign,V=0,_e,Ee,be,me,Re,Ce,Te;function Se(){}Se.__reactDisabledLog=!0;function rr(){{if(V===0){_e=console.log,Ee=console.info,be=console.warn,me=console.error,Re=console.group,Ce=console.groupCollapsed,Te=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Se,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}V++}}function tr(){{if(V--,V===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:_e}),info:F({},e,{value:Ee}),warn:F({},e,{value:be}),error:F({},e,{value:me}),group:F({},e,{value:Re}),groupCollapsed:F({},e,{value:Ce}),groupEnd:F({},e,{value:Te})})}V<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var re=j.ReactCurrentDispatcher,te;function G(e,r,t){{if(te===void 0)try{throw Error()}catch(f){var a=f.stack.trim().match(/\n( *(at )?)/);te=a&&a[1]||""}return`
`+te+e}}var ne=!1,z;{var nr=typeof WeakMap=="function"?WeakMap:Map;z=new nr}function xe(e,r){if(!e||ne)return"";{var t=z.get(e);if(t!==void 0)return t}var a;ne=!0;var f=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var d;d=re.current,re.current=null,rr();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(k){a=k}Reflect.construct(e,[],c)}else{try{c.call()}catch(k){a=k}e.call(c.prototype)}}else{try{throw Error()}catch(k){a=k}e()}}catch(k){if(k&&a&&typeof k.stack=="string"){for(var u=k.stack.split(`
`),C=a.stack.split(`
`),_=u.length-1,E=C.length-1;_>=1&&E>=0&&u[_]!==C[E];)E--;for(;_>=1&&E>=0;_--,E--)if(u[_]!==C[E]){if(_!==1||E!==1)do if(_--,E--,E<0||u[_]!==C[E]){var x=`
`+u[_].replace(" at new "," at ");return e.displayName&&x.includes("<anonymous>")&&(x=x.replace("<anonymous>",e.displayName)),typeof e=="function"&&z.set(e,x),x}while(_>=1&&E>=0);break}}}finally{ne=!1,re.current=d,tr(),Error.prepareStackTrace=f}var W=e?e.displayName||e.name:"",Le=W?G(W):"";return typeof e=="function"&&z.set(e,Le),Le}function ar(e,r,t){return xe(e,!1)}function ir(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function H(e,r,t){if(e==null)return"";if(typeof e=="function")return xe(e,ir(e));if(typeof e=="string")return G(e);switch(e){case w:return G("Suspense");case m:return G("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return ar(e.render);case S:return H(e.type,r,t);case P:{var a=e,f=a._payload,d=a._init;try{return H(d(f),r,t)}catch{}}}return""}var X=Object.prototype.hasOwnProperty,Oe={},we=j.ReactDebugCurrentFrame;function Z(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);we.setExtraStackFrame(t)}else we.setExtraStackFrame(null)}function or(e,r,t,a,f){{var d=Function.call.bind(X);for(var c in e)if(d(e,c)){var u=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}u=e[c](r,c,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(_){u=_}u&&!(u instanceof Error)&&(Z(f),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 u),Z(null)),u instanceof Error&&!(u.message in Oe)&&(Oe[u.message]=!0,Z(f),R("Failed %s type: %s",t,u.message),Z(null))}}}var ur=Array.isArray;function ae(e){return ur(e)}function cr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function lr(e){try{return Pe(e),!1}catch{return!0}}function Pe(e){return""+e}function je(e){if(lr(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",cr(e)),Pe(e)}var B=j.ReactCurrentOwner,fr={key:!0,ref:!0,__self:!0,__source:!0},Ae,ke,ie;ie={};function sr(e){if(X.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function dr(e){if(X.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function vr(e,r){if(typeof e.ref=="string"&&B.current&&r&&B.current.stateNode!==r){var t=A(B.current.type);ie[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(B.current.type),e.ref),ie[t]=!0)}}function pr(e,r){{var t=function(){Ae||(Ae=!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 yr(e,r){{var t=function(){ke||(ke=!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 hr=function(e,r,t,a,f,d,c){var u={$$typeof:o,type:e,key:r,ref:t,props:c,_owner:d};return u._store={},Object.defineProperty(u._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(u,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(u,"_source",{configurable:!1,enumerable:!1,writable:!1,value:f}),Object.freeze&&(Object.freeze(u.props),Object.freeze(u)),u};function gr(e,r,t,a,f){{var d,c={},u=null,C=null;t!==void 0&&(je(t),u=""+t),dr(r)&&(je(r.key),u=""+r.key),sr(r)&&(C=r.ref,vr(r,f));for(d in r)X.call(r,d)&&!fr.hasOwnProperty(d)&&(c[d]=r[d]);if(e&&e.defaultProps){var _=e.defaultProps;for(d in _)c[d]===void 0&&(c[d]=_[d])}if(u||C){var E=typeof e=="function"?e.displayName||e.name||"Unknown":e;u&&pr(c,E),C&&yr(c,E)}return hr(e,u,C,f,a,B.current,c)}}var oe=j.ReactCurrentOwner,De=j.ReactDebugCurrentFrame;function K(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);De.setExtraStackFrame(t)}else De.setExtraStackFrame(null)}var ue;ue=!1;function ce(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function Fe(){{if(oe.current){var e=A(oe.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function _r(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var Ie={};function Er(e){{var r=Fe();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 Ke(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=Er(r);if(Ie[t])return;Ie[t]=!0;var a="";e&&e._owner&&e._owner!==oe.current&&(a=" It was passed a child from "+A(e._owner.type)+"."),K(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),K(null)}}function We(e,r){{if(typeof e!="object")return;if(ae(e))for(var t=0;t<e.length;t++){var a=e[t];ce(a)&&Ke(a,r)}else if(ce(e))e._store&&(e._store.validated=!0);else if(e){var f=$(e);if(typeof f=="function"&&f!==e.entries)for(var d=f.call(e),c;!(c=d.next()).done;)ce(c.value)&&Ke(c.value,r)}}}function br(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===h||r.$$typeof===S))t=r.propTypes;else return;if(t){var a=A(r);or(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!ue){ue=!0;var f=A(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",f||"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 mr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var a=r[t];if(a!=="children"&&a!=="key"){K(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),K(null);break}}e.ref!==null&&(K(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),K(null))}}function Ye(e,r,t,a,f,d){{var c=$e(e);if(!c){var u="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(u+=" 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=_r(f);C?u+=C:u+=Fe();var _;e===null?_="null":ae(e)?_="array":e!==void 0&&e.$$typeof===o?(_="<"+(A(e.type)||"Unknown")+" />",u=" 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",_,u)}var E=gr(e,r,t,f,d);if(E==null)return E;if(c){var x=r.children;if(x!==void 0)if(a)if(ae(x)){for(var W=0;W<x.length;W++)We(x[W],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 We(x,e)}return e===l?mr(E):br(E),E}}function Rr(e,r,t){return Ye(e,r,t,!0)}function Cr(e,r,t){return Ye(e,r,t,!1)}var Tr=Cr,Sr=Rr;M.Fragment=l,M.jsx=Tr,M.jsxs=Sr}()),M}(function(n){process.env.NODE_ENV==="production"?n.exports=Ne():n.exports=Ue()})(fe);const Q=fe.exports.jsx;var J=s.createContext(null);function Ve(n,o){var i=s.useRef(o);function l(v,p){return v.length!==p.length?!1:v.every(function(T,y){return Object.is(T,p[y])})}s.useEffect(function(){l(o,i.current)||(n(o,i.current),i.current=o)},o)}function Be(n){var o="pending",i=n.then(function(){return o="success"});return function(){switch(o){case"pending":throw i;case"success":return null}}}var ve=function(){return function(){}}(),Je=function(){return Be(new Promise(function(){}))}();function pe(n){return Array.isArray(n)}function Ge(n){return n==null}function ye(n){try{n()}catch{}}var ze=function(n){var o=n.resource,i=n.children;return o==null||o(),i},He=s.forwardRef(function(n,o){if(!s.isValidElement(n.children))throw Error("Please use valid ReactElement!");var i=Ge(n.children.key)?n.children.type.toString():n.children.key;if(pe(n.includes)&&pe(n.excludes))throw Error("excludes and includes can't exist at the same time");var l=n.children,v=s.useMemo(function(){return new Map},[]),p=s.useState([]),T=p[0],y=p[1],h=s.useState(null),w=h[0],m=h[1],S=s.useState(null),P=S[0],I=S[1];s.useEffect(function(){m(i)},[i]),Ve(function(g,b){var D=b[0];if(D!==null){var U=v.get(D).unAnctivedCallbacks;U.forEach(function(ee){return ye(ee)})}},[i]);var N={drop:function(g){v.has(g)&&(v.delete(g),y(function(b){var D=b.findIndex(function(U){return U===g});return b.splice(D,1),Me([],b,!0)}))}};s.useImperativeHandle(o,function(){return{controller:N}});function q(g){return n.excludes?typeof n.excludes=="function"?n.excludes(g):n.excludes instanceof RegExp?n.excludes.test(g.toString()):n.excludes.includes(g):!1}function $(g){return n.includes?typeof n.includes=="function"?n.includes(g):n.includes instanceof RegExp?n.includes.test(g.toString()):n.includes.includes(g):!0}function j(g){return!q(g)&&$(g)}if(v.has(i)){var R=v.get(i);R.component=l}else v.set(i,{component:l,actived:!1,key:i,resource:ve,isKeepAlive:!0,activedCallbacks:[],unAnctivedCallbacks:[]}),y(T.concat(i));return P!==i&&I(i),Q(J.Provider,Y({value:{store:v,activedKey:j(i)?i:null,deferActivedKey:w,controller:N}},{children:T.map(function(g){var b=v.get(g);if(b.isKeepAlive=j(g),!b.isKeepAlive){b.actived=!1;var D=b.key===i;return D?l:null}return i===b.key?(b.actived=!0,b.resource=ve):(b.actived=!1,b.resource=Je),Q(s.Suspense,Y({fallback:null},{children:Q(ze,Y({resource:b.resource},{children:b.component}))}),g)})}))});function Xe(n){var o=s.useContext(J)||{},i=o.activedKey,l=o.deferActivedKey,v=s.useState(i)[0];s.useLayoutEffect(function(){i===l&&i===v&&n()},[l])}function Ze(n){var o=s.useContext(J)||{},i=o.activedKey,l=o.store,v=s.useState(i)[0],p=s.useRef(n);p.current=n;var T=s.useCallback(function(){ye(p.current)},[]);s.useEffect(function(){if(l){var y=l.get(v);y&&y.isKeepAlive&&y.unAnctivedCallbacks.push(T)}},[l]),s.useEffect(function(){return function(){var y=l==null?void 0:l.get(v);if(y&&y.isKeepAlive&&y.actived){T();var h=y.unAnctivedCallbacks,w=h.findIndex(function(m){return m===T});h.splice(w,1)}}},[])}function Qe(){var n=(s.useContext(J)||{}).controller;return n}O.KeepAlive=He,O.useActived=Xe,O.useController=Qe,O.useUnactived=Ze,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});