UNPKG

react-activation

Version:

<KeepAlive /> for React like <keep-alive /> in vue

2 lines (1 loc) 31.5 kB
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("szfe-tools/lib/flatten"),require("szfe-tools/lib/get"),require("szfe-tools/lib/run"),require("szfe-tools/lib/debounce"),require("react"),require("szfe-tools/lib/isFunction"),require("szfe-tools/lib/random"),require("szfe-tools/lib/EventBus"),require("szfe-tools/lib/nextTick"),require("react-dom"),require("szfe-tools/lib/isString"),require("szfe-tools/lib/isExist"),require("szfe-tools/lib/memoize"),require("szfe-tools/lib/isUndefined"),require("szfe-tools/lib/isObject"),require("hoist-non-react-statics"),require("szfe-tools/lib/value"),require("szfe-tools/lib/isArray"),require("szfe-tools/lib/globalThis"),require("react-node-key")):"function"==typeof define&&define.amd?define(["exports","szfe-tools/lib/flatten","szfe-tools/lib/get","szfe-tools/lib/run","szfe-tools/lib/debounce","react","szfe-tools/lib/isFunction","szfe-tools/lib/random","szfe-tools/lib/EventBus","szfe-tools/lib/nextTick","react-dom","szfe-tools/lib/isString","szfe-tools/lib/isExist","szfe-tools/lib/memoize","szfe-tools/lib/isUndefined","szfe-tools/lib/isObject","hoist-non-react-statics","szfe-tools/lib/value","szfe-tools/lib/isArray","szfe-tools/lib/globalThis","react-node-key"],t):t((e=e||self).ReactActivation={},e._flatten,e._get,e._run,e._debounce,e.React,e._isFunction,e._random,e._EventBus,e._nextTick,e.reactDom,e._isString,e._isExist,e._memoize,e._isUndefined,e._isObject,e.hoistStatics,e._value,e._isArray,e._globalThis,e.NodeKey)})(this,function(e,c,l,s,o,a,u,r,i,f,U,p,n,t,d,h,v,y,m,b,g){c=c&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c,l=l&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var w="default"in a?a.default:a;function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function $(e){if(Array.isArray(e))return e}function k(e,t,r){return t=D(t),F(e,L()?Reflect.construct(t,r||[],D(e).constructor):t.apply(e,r))}function S(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function q(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,X(n.key),n)}}function E(e,t,r){return t&&q(e.prototype,t),r&&q(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function O(e,t,r){return(t=X(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(){return(_=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r,n=arguments[t];for(r in n)!{}.hasOwnProperty.call(n,r)||(e[r]=n[r])}return e}).apply(null,arguments)}function D(e){return(D=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function C(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&K(e,t)}function L(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(L=function(){return!!e})()}function M(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function W(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function V(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function P(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?V(Object(r),!0).forEach(function(e){O(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function x(e,t){if(null==e)return{};var r,n=((e,t)=>{if(null==e)return{};var r,n={};for(r in e)if({}.hasOwnProperty.call(e,r)){if(-1!==t.indexOf(r))continue;n[r]=e[r]}return n})(e,t);if(Object.getOwnPropertySymbols)for(var o=Object.getOwnPropertySymbols(e),i=0;i<o.length;i++)r=o[i],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(n[r]=e[r]);return n}function F(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");t=e;if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function K(e,t){return(K=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function j(e,t){return $(e)||((e,t)=>{var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,c,a=[],u=!0,l=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){l=!0,o=e}finally{try{if(!u&&null!=r.return&&(c=r.return(),Object(c)!==c))return}finally{if(l)throw o}}return a}})(e,t)||G(e,t)||W()}function H(e){return $(e)||M(e)||G(e)||W()}function B(e){return(e=>{if(Array.isArray(e))return T(e)})(e)||M(e)||G(e)||(()=>{throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})()}function X(e){e=((e,t)=>{if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);if("object"!=typeof(r=r.call(e,t||"default")))return r;throw new TypeError("@@toPrimitive must return a primitive value.")})(e,"string");return"symbol"==typeof e?e:e+""}function G(e,t){var r;if(e)return"string"==typeof e?T(e,t):"Map"===(r="Object"===(r={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,t):void 0}u=u&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i,f=f&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f,p=p&&Object.prototype.hasOwnProperty.call(p,"default")?p.default:p,n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,d=d&&Object.prototype.hasOwnProperty.call(d,"default")?d.default:d,h=h&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h,v=v&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v,y=y&&Object.prototype.hasOwnProperty.call(y,"default")?y.default:y,m=m&&Object.prototype.hasOwnProperty.call(m,"default")?m.default:m,b=b&&Object.prototype.hasOwnProperty.call(b,"default")?b.default:b,g=g&&Object.prototype.hasOwnProperty.call(g,"default")?g.default:g;var Y=1073741823;function J(){var e,t,r;return u(a.useContext)?a.useContext(te)||(t=(e=j(a.useState(ae.currentContextValue),2))[0],r=e[1],a.useEffect(function(){var e=o(r);return z.on("update",e),function(){return z.off("update",e)}},[]),t):{}}function Q(e){var t=e.children,e=x(e,le);return w.createElement(re,_({},e,{_nk:"".concat(se,"11")}),w.createElement(ae,_({},e,{_nk:"".concat(se,"21")}),t))}function Z(e){var t=e.children;return w.createElement(ne,{_nk:"".concat(se,"31")},function(e){return e?s(t,void 0,e):w.createElement(ue,{_nk:"".concat(se,"41")},t)})}var ee=w.createContext||function(e,n){var t="__create-react-context-"+r()+"__";return{Provider:(()=>{function c(){var e;S(this,c);for(var r,n,t=arguments.length,o=new Array(t),i=0;i<t;i++)o[i]=arguments[i];return O(e=k(this,c,[].concat(o)),"emitter",(r=e.props.value,n=[],{on:function(e){n.push(e)},off:function(t){n=n.filter(function(e){return e!==t})},get:function(){return r},set:function(e,t){r=e,n.forEach(function(e){return e(r,t)})}})),e}return C(c,a.Component),E(c,[{key:"getChildContext",value:function(){return O({},t,this.emitter)}},{key:"componentWillReceiveProps",value:function(e){var t,r;this.props.value!==e.value&&(r=this.props.value,t=e.value,r="function"==typeof n?n(r,t):Y,0!==(r|=0))&&this.emitter.set(e.value,r)}},{key:"render",value:function(){return this.props.children}}])})(),Consumer:(()=>{function o(){var r;S(this,o);for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return O(r=k(this,o,[].concat(t)),"observedBits",void 0),O(r,"state",{value:r.getValue()}),O(r,"onUpdate",function(e,t){0!=((0|r.observedBits)&t)&&r.setState({value:r.getValue()})}),r}return C(o,a.Component),E(o,[{key:"componentWillReceiveProps",value:function(e){e=e.observedBits;this.observedBits=null==e?Y:e}},{key:"componentDidMount",value:function(){this.context[t]&&this.context[t].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?Y:e}},{key:"componentWillUnmount",value:function(){this.context[t]&&this.context[t].off(this.onUpdate)}},{key:"getValue",value:function(){return this.context[t]?this.context[t].get():e}},{key:"render",value:function(){return e=this.props.children,(Array.isArray(e)?e[0]:e)(this.state.value);var e}}])})()}},te=ee(),re=te.Provider,ne=te.Consumer,oe=ee(),ie=oe.Provider,ce=oe.Consumer,z=new i,ae=(()=>{function r(e){var t;return S(this,r),t=k(this,r,[e]),r.currentContextValue=e.value,t}return C(r,a.Component),E(r,[{key:"shouldComponentUpdate",value:function(e){return e.value!==this.props.value&&(r.currentContextValue=e.value,z.emit("update",e.value)),e.children!==this.props.children||e.value!==this.props.value}},{key:"render",value:function(){return this.props.children}}])})(),ue=(O(ae,"eventBus",z),O(ae,"currentContextValue",void 0),(()=>{function r(e){var t;return S(this,r),O(t=k(this,r,[e]),"state",{context:ae.currentContextValue}),O(t,"updateListener",o(function(e){t.setState({context:e})})),z.on("update",t.updateListener),t}return C(r,a.PureComponent),E(r,[{key:"componentWillUnmount",value:function(){z.off("update",this.updateListener)}},{key:"render",value:function(){var e=this.props.children,t=this.state.context;return s(e,void 0,t)}}])})()),le=["children"],se="qj9A",fe=(()=>{function o(){var e;S(this,o);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return O(e=k(this,o,[].concat(r)),"promiseCache",{}),e}return C(o,a.Component),E(o,[{key:"render",value:function(){var e=this.props,t=e.freeze,e=e.children,r=this.promiseCache;if(t&&!r.promise)throw r.promise=new Promise(function(e){r.resolve=e}),r.promise;if(t)throw r.promise;return r.promise&&(r.resolve(),r.promise=void 0),w.createElement(a.Fragment,null,e)}}])})();function pe(){try{for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];t.forEach(function(e){var e=H(e),t=e[0];e.slice(1).forEach(function(e){var o;u(l(t,e))&&!l(t,[e,"_overridden"])&&(o=t[e].bind(t),t[e]=function(e){p(e)||be(e);for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return o.apply(void 0,[e].concat(r))},t[e]._overridden=!0)})})}catch(e){console.warn("activation override failed:",e)}}function de(e){return e=e.children,s(e)}var he=[],ve=new Map,ye=new i,me=t(function(r){n(r)&&![te,oe].includes(r)&&(n(r.Consumer)||(r.Consumer=function(e){var e=e.children,t=s(a.useContext,void 0,r);return w.createElement(a.Fragment,null,s(e,void 0,t))}),he.push(r),setTimeout(function(){return ye.emit("update")}))}),be=t(function(e){e=l(e,"_context")||l(e,"context");l(e,"$$typeof")===l(te,"$$typeof")&&me(e)}),ge=(pe([w,"createElement"]),(()=>{function o(e){S(this,o),O(t=k(this,o,[e]),"unmount",null);var t,r,e=e.value;return 0===e.length?(t.state={ctxValue:null},F(t)):((e=j(e,1)[0]).ctx,r=e.onUpdate,t.state={ctxValue:e.value},t.unmount=r(function(e){t.setState({ctxValue:e})}),t)}return C(o,a.PureComponent),E(o,[{key:"componentWillUnmount",value:function(){s(this.unmount)}},{key:"render",value:function(){var e,t,r=this.props,n=r.value,r=r.children,n=n.filter(Boolean);return 0===n.length?r:(e=this.state.ctxValue,t=(n=H(n))[0].ctx,n=n.slice(1),t=t.Provider,t=d(e)?r:w.createElement(t,{value:e,_nk:"".concat("lqEk","11")},r),0<n.length?w.createElement(o,{value:n,_nk:"".concat("lqEk","21")},t):t)}}])})()),we=(()=>{function o(e){S(this,o),O(t=k(this,o,[e]),"updateListener",null),O(t,"ctxInfo",null);var t,r=e.value,n=e.ctx,e=e.id;return d(r)?F(t):(t.updateListener=l(ve.get(n),e,new Map),s(t.updateListener,"forEach",function(e){return e(r)}),t.ctxInfo={ctx:n,value:r,onUpdate:function(e){return t.updateListener.set(e,e),function(){return t.updateListener.delete(e)}}},t)}return C(o,a.Component),E(o,[{key:"componentWillUnmount",value:function(){var e=this.props,t=e.value,r=e.ctx,e=e.id;d(t)||ve.set(r,P(P({},l(ve.get(r),void 0,{})),{},O({},e,this.updateListener)))}},{key:"shouldComponentUpdate",value:function(e){var t=e.value;return this.props.value!==t&&s(this.updateListener,"forEach",function(e){return e(t)}),!0}},{key:"render",value:function(){var t=this,e=this.props,r=e.value,n=e.renderWrapper,o=e.renderContent;return n(function(e){return o(d(r)?e:[].concat(B(e),[t.ctxInfo]))})}}])})(),ke={},Se=(()=>{function r(e){S(this,r),O(t=k(this,r,[e]),"renderWrapper",function(e){var o=t.props.id;return ke[o].reduce(function(r,n){var e=n.Consumer;return function(t){return w.createElement(e,{_nk:"".concat("SsUr","11")},function(e){return w.createElement(we,{value:e,ctx:n,renderWrapper:r,renderContent:t,id:o,_nk:"".concat("SsUr","21")})})}},function(e){return e([])})(e)});var t,e=e.id;return ke[e]||(ke[e]=B(he).filter(function(e){return n(e.Consumer)})),t}return C(r,a.PureComponent),E(r,[{key:"render",value:function(){var e=this.props.children;return this.renderWrapper(e)}}])})(),Ee="46lG",t=u(a.lazy)&&!d(a.Suspense),Oe=t?a.lazy(function(){return new Promise(function(){return null})}):function(){return null},_e=(()=>{function e(){return S(this,e),k(this,e,arguments)}return C(e,a.Component),E(e,[{key:"componentDidMount",value:function(){s(this.props,"onStart")}},{key:"componentWillUnmount",value:function(){s(this.props,"onEnd")}},{key:"render",value:function(){return null}}])})();var Ce=t?(()=>{function o(){var e;S(this,o);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return O(e=k(this,o,[].concat(r)),"state",{suspense:!1}),O(e,"onSuspenseStart",function(){e.setState({suspense:!0})}),O(e,"onSuspenseEnd",function(){e.setState({suspense:!1})}),O(e,"sus$$",{onSuspenseStart:e.onSuspenseStart,onSuspenseEnd:e.onSuspenseEnd}),e}return C(o,a.Component),E(o,[{key:"render",value:function(){var e=this.props.children;return w.createElement(a.Fragment,null,s(e,void 0,this.sus$$),this.state.suspense&&w.createElement(Oe,{_nk:"".concat(Ee,"31")}))}}])})():de,Pe=t?function(e){var t=e.children,e=e.sus$$;return w.createElement(a.Suspense,{fallback:w.createElement(_e,{onStart:e.onSuspenseStart,onEnd:e.onSuspenseEnd,_nk:"".concat(Ee,"21")}),_nk:"".concat(Ee,"11")},t)}:de,xe=(()=>{function e(){return S(this,e),k(this,e,arguments)}return C(e,a.Component),E(e,[{key:"componentDidCatch",value:function(e){var t=this.props.error$$;s(t,void 0,e,function(){s(t,void 0,null)})}},{key:"render",value:function(){return this.props.children}}])})(),je=(O(xe,"getDerivedStateFromError",function(){return null}),(()=>{function o(){var r;S(this,o);for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return O(r=k(this,o,[].concat(t)),"state",{error:null}),O(r,"throwError",function(e,t){return r.setState({error:e},t)}),r}return C(o,a.Component),E(o,[{key:"render",value:function(){if(this.state.error)throw this.state.error;return s(this.props.children,void 0,this.throwError)}}])})()),A="lajT";function Be(e){var t=e.id,r=e.children,e=e.bridgeProps,n=e.sus$$,o=e.ctx$$;return w.createElement(xe,{error$$:e.error$$,_nk:"".concat(A,"11")},w.createElement(Pe,{sus$$:n,_nk:"".concat(A,"21")},w.createElement(ge,{id:t,value:o,_nk:"".concat(A,"31")},r)))}function ze(e){var n=e.id,o=e.children;return w.createElement(je,{_nk:"".concat(A,"41")},function(r){return w.createElement(Ce,{_nk:"".concat(A,"51")},function(t){return w.createElement(Se,{id:n,_nk:"".concat(A,"61")},function(e){return s(o,void 0,{bridgeProps:{sus$$:t,ctx$$:e,error$$:r}})})})})}function Ae(i){var r=(()=>{function o(){var e;S(this,o);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return O(e=k(this,o,[].concat(r)),"drop",null),e}return C(o,a.Component),E(o,[{key:"componentWillUnmount",value:function(){s(this.drop)}},{key:"render",value:function(){var r=this,e=this.props,n=e.forwardedRef,t=x(e,Ne);return w.createElement(ce,{_nk:"".concat(Re,"11")},function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).attach;return w.createElement(i,_({ref:function(t){[I,N].every(function(e){return!u(l(t,e))})||(r.drop=s(e,void 0,t),d(n))||(h(n)&&"current"in n?n.current=t:s(n,void 0,t))}},t,{_nk:"".concat(Re,"21")}))})}}])})();return u(i.prototype.componentDidMount)&&(i.prototype._componentDidMount=i.prototype.componentDidMount,i.prototype.componentDidMount=function(){var e=this;f(function(){return i.prototype._componentDidMount.call(e)})}),u(a.forwardRef)?v(a.forwardRef(function(e,t){return w.createElement(r,_({},e,{forwardedRef:t,_nk:"".concat(Re,"31")}))}),i):v(r,i)}function Ie(e,t){var r,n;[a.useRef,a.useContext,a.useEffect].some(function(e){return!u(e)})||(n=a.useContext(oe))&&(r=a.useRef({}).current,n=n.attach,r[e]=t,r.drop=n(r),a.useEffect(function(){return function(){return s(r.drop)}},[]))}var Ne=["forwardedRef"],Re="XKTv",I="componentDidActivate",N="componentWillUnactivate",t=Ie.bind(null,I),Ue=Ie.bind(null,N),Te=["id","autoFreeze","contentProps"],$e="bNyU",qe=a.Suspense?function(e){var t=e.freeze,r=e.children,e=e.placeholder;return w.createElement(a.Suspense,{fallback:void 0===e?null:e,_nk:"".concat("Leb+","11")},w.createElement(fe,{freeze:t,_nk:"".concat("Leb+","21")},r))}:function(e){return e.children},De=(()=>{function o(e){var u;S(this,o);for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return O(u=k(this,o,[e].concat(r)),"eventBus",new i),O(u,"listeners",new Map),O(u,"wrapper",null),O(u,"cache",void 0),O(u,"unmounted",!1),O(u,"safeSetState",function(e,t){u.unmounted||u.setState(e,t)}),O(u,"freezeTimeout",null),O(u,"attach",function(r){var e=u.listeners;return r?(r.isKeepAlive&&f(function(){var e=u.props,t=e.id,e=e.store.get(t);e.aliveNodesId=new Set([].concat(B(e.aliveNodesId),[r.id]))}),e.set(r,O(O({},I,function(){return s(r,I)}),N,function(){return s(r,N)})),function(){e.delete(r)}):function(){return null}}),O(u,"contextValue",{id:u.props.id,attach:u.attach}),O(u,"drop",function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.delay,c=void 0===t?1200:t,t=e.refreshIfDropFailed,a=void 0===t||t;return new Promise(function(t){var e,r=u.props,n=r.scope,o=r.id,i=function(){clearTimeout(e),u.eventBus.off(N,i),u.cache.willDrop=!0,n.nodes.delete(o),n.helpers=P({},n.helpers),n.smartForceUpdate(function(){return t(!0)})};l(u.cache,"cached")||l(u.cache,"willDrop")?i():(u.eventBus.on(N,i),e=setTimeout(function(){u.eventBus.off(N,i),a?u.refresh().then(function(e){return t(e)}):t(!1)},c))})}),O(u,"refresh",function(){return new Promise(function(e){l(u.cache,"cached")&&e(!1),u.safeSetState({key:Math.random()},function(){return e(!0)})})}),u.state={children:e.children,bridgeProps:e.bridgeProps,key:Math.random(),freeze:!1},u}return C(o,a.PureComponent),E(o,[{key:"componentDidMount",value:function(){var t,e=this,r=this.props,n=r.store,r=r.id,o=this.listeners,i=this.wrapper;if(!n.has(r)){try{t=B(i.children)}catch(e){t=[i.children]}this.cache=O(O({listeners:o,aliveNodesId:[],inited:!1,cached:!1,wrapper:i,nodes:t},I,function(){return e[I]()}),N,function(){return e[N]()}),n.set(r,this.cache)}}},{key:"componentWillUnmount",value:function(){var e=this.props,t=e.store,r=e.keepers,e=e.id;try{var n=t.get(e);n.nodes.forEach(function(e){n.wrapper.appendChild(e)})}catch(e){}t.delete(e),r.delete(e),this.unmounted=!0}},{key:I,value:function(){clearTimeout(this.freezeTimeout),this.safeSetState({freeze:!1}),this.eventBus.emit(I),this.listeners.forEach(function(e){return s(e,[I])})}},{key:N,value:function(){var e=this;this.eventBus.emit(N),B(this.listeners).reverse().forEach(function(e){e=j(e,2)[1];return s(e,[N])}),clearTimeout(this.freezeTimeout),this.freezeTimeout=setTimeout(function(){U.flushSync(function(){e.safeSetState({freeze:!0})})},1e3)}},{key:"render",value:function(){var t=this,e=this.props,r=e.id,n=e.autoFreeze,n=void 0===n||n,o=e.contentProps,o=void 0===o?{}:o,e=(x(e,Te),this.state),i=e.children,c=e.bridgeProps,a=e.key;return w.createElement(qe,{freeze:n&&e.freeze,_nk:"".concat($e,"11")},w.createElement("div",{ref:function(e){t.wrapper=e},_nk:"".concat($e,"21")},w.createElement("div",_({},o,{key:"keeper-container",className:"ka-content ".concat(o.className||"")}),w.createElement(Be,{id:r,bridgeProps:c,_nk:"".concat($e,"31")},w.createElement(ie,{value:this.contextValue,_nk:"".concat($e,"41")},w.Children.map(i,function(e,t){return w.cloneElement(e,{key:"".concat(e.key||"",":").concat(a,":").concat(t)})}))))))}}])})(),Le=["children"],Me="UVSV",We="drop",Ve="refresh",Fe=(()=>{function n(){var a;S(this,n);for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return O(a=k(this,n,[].concat(t)),"store",new Map),O(a,"nodes",new Map),O(a,"keepers",new Map),O(a,"debouncedForceUpdate",o(function(e){return a.forceUpdate(e)})),O(a,"updateCallbackList",[]),O(a,"smartForceUpdate",function(e){a.updateCallbackList.push(e),a.debouncedForceUpdate(function(){a.updateCallbackList.forEach(function(e){return s(e)}),a.updateCallbackList=[]})}),O(a,"update",function(i,c){return new Promise(function(e){var t=a.keepers.get(i),r=!t,n=Date.now(),o=a.nodes.get(i)||null;a.nodes.set(i,P(P({id:i,createTime:n,updateTime:n},o),c)),r?(a.helpers=P({},a.helpers),a.forceUpdate(e)):(n=c.children,t.setState({children:n,bridgeProps:c.bridgeProps},e))})}),O(a,"keep",function(t,r){return new Promise(function(e){a.update(t,P({id:t},r)).then(function(){e(a.store.get(t))})})}),O(a,"getCachingNodesByName",function(t){return a.getCachingNodes().filter(function(e){return t instanceof RegExp?t.test(e.name):e.name===t})}),O(a,"getScopeIds",function(e){var r=function(e){var t=l(a.getCache(e),"aliveNodesId",[]);return 0<t.size?[e,B(t).map(r)]:[e].concat(B(t))};return c(e.map(function(e){return r(e)}))}),O(a,"dropById",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[[e],We].concat(r))}),O(a,"dropScopeByIds",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[a.getScopeIds(e),We].concat(r))}),O(a,"drop",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[a.getCachingNodesByName(e).map(function(e){return e.id}),We].concat(r))}),O(a,"dropScope",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.dropScopeByIds.apply(a,[a.getCachingNodesByName(e).map(function(e){return e.id})].concat(r))}),O(a,"refreshById",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[[e],Ve].concat(r))}),O(a,"refreshScopeByIds",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[a.getScopeIds(e),Ve].concat(r))}),O(a,"refresh",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.handleNodes.apply(a,[a.getCachingNodesByName(e).map(function(e){return e.id}),Ve].concat(r))}),O(a,"refreshScope",function(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return a.refreshScopeByIds.apply(a,[a.getCachingNodesByName(e).map(function(e){return e.id})].concat(r))}),O(a,"handleNodes",function(e){for(var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:We,t=arguments.length,o=new Array(2<t?t-2:0),r=2;r<t;r++)o[r-2]=arguments[r];return new Promise(function(t){var r=[];e.forEach(function(e){a.store.get(e)&&(e=a.keepers.get(e),r.push(e))}),0===r.length?t(!1):Promise.all(r.map(function(e){return s.apply(void 0,[e,n].concat(o))})).then(function(e){return t(e.every(Boolean))})})}),O(a,"clear",function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return a.handleNodes.apply(a,[a.getCachingNodes().map(function(e){return e.id}),We].concat(t))}),O(a,"getCache",function(e){return a.store.get(e)}),O(a,"getNode",function(e){return a.nodes.get(e)}),O(a,"getCachingNodes",function(){return B(a.nodes.values())}),O(a,"helpers",{keep:a.keep,update:a.update,drop:a.drop,dropScope:a.dropScope,dropById:a.dropById,dropScopeByIds:a.dropScopeByIds,refresh:a.refresh,refreshScope:a.refreshScope,refreshById:a.refreshById,refreshScopeByIds:a.refreshScopeByIds,getScopeIds:a.getScopeIds,clear:a.clear,getCache:a.getCache,getNode:a.getNode,getCachingNodes:a.getCachingNodes}),a}return C(n,a.Component),E(n,[{key:"render",value:function(){var n=this,e=this.props.children,e=void 0===e?null:e;return w.createElement(Q,{value:this.helpers,_nk:"".concat(Me,"11")},e,w.createElement("div",{style:{display:"none"},_nk:"".concat(Me,"21")},B(this.nodes.values()).map(function(e){var t=e.children,r=x(e,Le);return w.createElement(De,_({key:r.id},r,{scope:n,store:n.store,keepers:n.keepers,ref:function(e){n.keepers.set(r.id,e)},_nk:"iAr".concat(Me,"31")}),t)})))}}])})(),Ke=["id","forwardedRef"],He=["id","forwardedRef"],Xe=["forwardedRef"],Ge=["forwardedRef"],R="X7Aa";function Ye(e){return{drop:e.drop,dropScope:e.dropScope,refresh:e.refresh,refreshScope:e.refreshScope,clear:e.clear,getCachingNodes:e.getCachingNodes,dropById:e.dropById,dropScopeByIds:e.dropScopeByIds,refreshById:e.refreshById,refreshScopeByIds:e.refreshScopeByIds}}function Je(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return!!n(e)&&(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight)}function Qe(e){return u(l(b,"document.querySelectorAll"))?[].concat(B(y(s(e,"querySelectorAll","*"),[])),[e]).filter(Je):[]}var Ze=["_helpers","id","children"],et=["_helpers","id","name"],tt=l(b,"document.body"),rt=l(b,"document.scrollingElement",l(b,"document.documentElement",{})),nt=(()=>{function t(e){var i;return S(this,t),O(i=k(this,t,[e]),"id",null),O(i,"isKeepAlive",!0),O(i,"cached",!1),O(i,"inject",function(){var e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],t=i.props,r=t.id,n=t.saveScrollPosition,t=t._helpers.getCache(r);try{t.nodes.forEach(function(e){i.placeholder.appendChild(e)}),e&&n&&s(t.revertScrollPos)}catch(e){}}),O(i,"eject",function(){var e,t=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],r=i.props,n=r.id,o=r._helpers.getCache(n),r=c(c([i.props.saveScrollPosition]).map(function(e){return!0===e?o.nodes:"screen"===e?[rt,tt]:B(y(s(b,"document.querySelectorAll",e),[]))})).filter(Boolean);try{t&&0<r.length&&(o.revertScrollPos=(e=B(new Set(B(c(r.map(Qe))))).map(function(e){return[e,{x:e.scrollLeft,y:e.scrollTop}]}),function(){e.forEach(function(e){var e=j(e,2),t=e[0],e=e[1],r=e.x,e=e.y;t.scrollLeft=r,t.scrollTop=e})})),o.nodes.forEach(function(e){t?i.placeholder.removeChild(e):o.wrapper.appendChild(e)})}catch(e){}}),O(i,"refresh",function(){var e=i.props;return e._helpers.refreshById(e.id)}),O(i,"drop",function(e){var t=i.props;return t._helpers.dropById(t.id,e)}),O(i,"init",function(){var e=i.props,t=e._helpers,r=e.id,n=e.children,e=x(e,Ze);t.keep(r,P({children:n,getInstance:function(){return i}},e)).then(function(e){e&&(i.inject(),e.inited?s(i,I):e.inited=!0,i.cached=!1)})}),O(i,"update",function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e._helpers,r=e.id,n=e.name,e=x(e,et);t&&!i.cached&&t.update(r,P({name:n,getInstance:function(){return i}},e))}),i.id=e.id,i.init(),[I,N].forEach(function(n){i[n]=function(){var e=i.props,t=e.id,e=e._helpers,r=e.getCache(t),e=e.getNode(t),t=(e&&n===I&&(e.updateTime=Date.now()),n===N);!r||r.willDrop?i.cached&&!t&&i.init():(s(r,n),r.cached=t,i.cached=t)}}),i}return C(t,a.Component),E(t,[{key:"shouldComponentUpdate",value:function(e){return this.update(e),!1}},{key:"componentWillUnmount",value:function(){var e=this.props,t=e.id,r=e._helpers,e=e.when,e=void 0===e||e,n=r.getCache(t);e=s(e);var e=j(m(e)?e:[e],2),o=e[0],e=e[1];n&&(this.eject(),delete n.getInstance,o||(e?([n].concat(B(r.getScopeIds([t]).map(function(e){return r.getCache(e)}))).filter(Boolean).forEach(function(e){e.willDrop=!0}),f(function(){return r.dropScopeByIds([t])})):(n.willDrop=!0,f(function(){return r.dropById(t)}))),s(this,N))}},{key:"render",value:function(){var t=this,e=(this.props||{}).wrapperProps,e=void 0===e?{}:e;return w.createElement("div",_({},e,{key:"keep-alive-placeholder",className:"ka-wrapper ".concat(e.className||""),ref:function(e){t.placeholder=e}}))}}])})();O(nt,"defaultProps",{saveScrollPosition:!0});var ot,it,nt=u(l(b,"document.getElementById"))?(ot=Ae(nt),it=u(a.useContext)?function(e){var t=e.id,r=e.forwardedRef,e=x(e,Ke);return ct({idPrefix:t,helpers:J(),props:e,forwardedRef:r})}:function(e){var t=e.id,r=e.forwardedRef,n=x(e,He);return w.createElement(Z,{_nk:"".concat(R,"41")},function(e){return ct({idPrefix:t,helpers:e,props:n,forwardedRef:r})})},u(a.forwardRef)?v(a.forwardRef(function(e,t){return w.createElement(it,_({},e,{forwardedRef:t,_nk:"".concat(R,"51")}))}),ot):v(it,ot)):function(e){var e=e.children,t=this.props||{},r=void 0===(r=t.wrapperProps)?{}:r,t=void 0===(t=t.contentProps)?{}:t;return w.createElement("div",_({},r,{key:"keep-alive-placeholder",className:"ka-wrapper ".concat(r.className||"")}),w.createElement("div",_({},t,{key:"keeper-container",className:"ka-content ".concat(t.className||"")}),e))};function ct(e){var t=e.idPrefix,r=e.helpers,n=e.props,o=e.forwardedRef;return(e=d(r))&&console.error("You should not use <KeepAlive /> outside a <AliveScope>"),e?l(n,"children",null):w.createElement(g,{prefix:t,key:n._nk,manualKey:n.cacheKey,_nk:"".concat(R,"11")},function(e){var t=n.cacheKey||e;return w.createElement(ze,{key:t,id:t,_nk:"".concat(R,"21")},function(e){return w.createElement(ot,_({key:t},n,e,{id:t,ref:o,_helpers:r,_nk:"".concat(R,"31")}))})})}e.AliveScope=Fe,e.KeepAlive=nt,e.NodeKey=g,e.autoFixContext=pe,e.createContext=function(e,t){e=ee(e,t);return me(e),e},e.default=nt,e.fixContext=me,e.useActivate=t,e.useAliveController=function(){var e;return u(a.useContext)&&(e=J())?Ye(e):{}},e.useUnactivate=Ue,e.withActivation=Ae,e.withAliveScope=function(r){function n(e){var t=e.helpers;return w.createElement(r,_({},e.props,t,{ref:e.forwardedRef,_nk:"".concat(R,"61")}))}var o=u(a.useContext)?function(e){var t=e.forwardedRef,e=x(e,Xe);return n({helpers:Ye(J()||{}),props:e,forwardedRef:t})}:function(e){var t=e.forwardedRef,r=x(e,Ge);return w.createElement(Z,{_nk:"".concat(R,"42")},function(){return n({helpers:Ye(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}),props:r,forwardedRef:t})})};return u(a.forwardRef)?v(a.forwardRef(function(e,t){return w.createElement(o,_({},e,{forwardedRef:t,_nk:"".concat(R,"71")}))}),r):v(o,r)},Object.defineProperty(e,"__esModule",{value:!0})});