UNPKG

react-activation-hyy

Version:

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

2 lines (1 loc) 26.4 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("create-react-context"),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","create-react-context","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.createContext$1,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,u,c,l,o,a,s,r,i,f,T,p,n,t,d,h,v,y,m,b,g){u=u&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u,c=c&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c,l=l&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var w="default"in a?a.default:a;function q(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 D(e){if(Array.isArray(e))return e}function S(e,t,r){return t=$(t),W(e,L()?Reflect.construct(t,r||[],$(e).constructor):t.apply(e,r))}function O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function U(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,Y(n.key),n)}}function E(e,t,r){return t&&U(e.prototype,t),r&&U(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function C(e,t,r){return(t=Y(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function P(){return(P=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 $(e){return($=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function j(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&&V(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 F(){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 K(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 k(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?K(Object(r),!0).forEach(function(e){C(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):K(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(t.includes(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],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(n[r]=e[r]);return n}function W(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 V(e,t){return(V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function H(e,t){return D(e)||((e,t)=>{var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],c=!0,l=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw o}}return a}})(e,t)||G(e,t)||F()}function z(e){return(e=>{if(Array.isArray(e))return q(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 Y(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?q(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)?q(e,t):void 0}s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,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;function J(){var e,t,r;return s(a.useContext)?a.useContext(A)||(t=(e=H(a.useState(I.currentContextValue),2))[0],r=e[1],a.useEffect(function(){var e=o(r);return N.on("update",e),function(){return N.off("update",e)}},[]),t):{}}function Q(e){var t=e.children,e=x(e,ue);return w.createElement(te,e,w.createElement(I,e,t))}function X(e){var t=e.children;return w.createElement(re,null,function(e){return e?l(t,void 0,e):w.createElement(ie,null,t)})}function Z(e){e.forEach(function(e){var e=D(e=e)||M(e)||G(e)||F(),t=e[0];e.slice(1).forEach(function(e){var o;s(c(t,e))&&!c(t,[e,"_overridden"])&&(o=t[e].bind(t),t[e]=function(e){p(e)||fe(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)})})}function ee(){try{for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];Z(t)}catch(e){console.warn("activation override failed:",e)}}var A=r(),te=A.Provider,re=A.Consumer,ne=r(),oe=(ne.Provider,ne.Consumer),N=new i,I=(()=>{function r(e){var t;return O(this,r),t=S(this,r,[e]),r.currentContextValue=e.value,t}return j(r,a.Component),E(r,[{key:"shouldComponentUpdate",value:function(e){return e.value!==this.props.value&&(r.currentContextValue=e.value,N.emit("update",e.value)),e.children!==this.props.children||e.value!==this.props.value}},{key:"render",value:function(){return this.props.children}}])})(),ie=(C(I,"eventBus",N),C(I,"currentContextValue",void 0),(()=>{function r(e){var t;return O(this,r),C(t=S(this,r,[e]),"state",{context:I.currentContextValue}),C(t,"updateListener",o(function(e){t.setState({context:e})})),N.on("update",t.updateListener),t}return j(r,a.PureComponent),E(r,[{key:"componentWillUnmount",value:function(){N.off("update",this.updateListener)}},{key:"render",value:function(){var e=this.props.children,t=this.state.context;return l(e,void 0,t)}}])})()),ue=["children"],ae=[],ce=new Map,le=new i,se=t(function(r){n(r)&&![A,ne].includes(r)&&(n(r.Consumer)||(r.Consumer=function(e){var e=e.children,t=l(a.useContext,void 0,r);return w.createElement(a.Fragment,null,l(e,void 0,t))}),ae.push(r),setTimeout(function(){return le.emit("update")}))}),fe=t(function(e){e=c(e,"_context")||c(e,"context");c(e,"$$typeof")===c(A,"$$typeof")&&se(e)}),pe=(ee([w,"createElement"]),(()=>{function o(e){O(this,o),C(t=S(this,o,[e]),"updateListener",null),C(t,"ctxInfo",null);var t,r=e.value,n=e.ctx,e=e.id;return d(r)?W(t):(t.updateListener=c(ce.get(n),e,new Map),l(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 j(o,a.Component),E(o,[{key:"componentWillUnmount",value:function(){var e=this.props,t=e.value,r=e.ctx,e=e.id;d(t)||ce.set(r,k(k({},c(ce.get(r),void 0,{})),{},C({},e,this.updateListener)))}},{key:"shouldComponentUpdate",value:function(e){var t=e.value;return this.props.value!==t&&l(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(z(e),[t.ctxInfo]))})}}])})()),de={},he=(()=>{function r(e){O(this,r),C(t=S(this,r,[e]),"renderWrapper",function(e){var o=t.props.id;return de[o].reduce(function(r,n){var e=n.Consumer;return function(t){return w.createElement(e,null,function(e){return w.createElement(pe,{value:e,ctx:n,renderWrapper:r,renderContent:t,id:o})})}},function(e){return e([])})(e)});var t,e=e.id;return de[e]||(de[e]=z(ae).filter(function(e){return n(e.Consumer)})),t}return j(r,a.PureComponent),E(r,[{key:"render",value:function(){var e=this.props.children;return this.renderWrapper(e)}}])})(),t=s(a.lazy)&&!d(a.Suspense),ve=t?a.lazy(function(){return new Promise(function(){return null})}):function(){return null},ye=t?(()=>{function o(){var e;O(this,o);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return C(e=S(this,o,[].concat(r)),"state",{suspense:!1}),C(e,"onSuspenseStart",function(){e.setState({suspense:!0})}),C(e,"onSuspenseEnd",function(){e.setState({suspense:!1})}),C(e,"sus$$",{onSuspenseStart:e.onSuspenseStart,onSuspenseEnd:e.onSuspenseEnd}),e}return j(o,a.Component),E(o,[{key:"render",value:function(){var e=this.props.children;return w.createElement(a.Fragment,null,l(e,void 0,this.sus$$),this.state.suspense&&w.createElement(ve,null))}}])})():function(e){e=e.children;return l(e)},me=(C((()=>{function e(){return O(this,e),S(this,e,arguments)}return j(e,a.Component),E(e,[{key:"componentDidCatch",value:function(e){var t=this.props.error$$;l(t,void 0,e,function(){l(t,void 0,null)})}},{key:"render",value:function(){return this.props.children}}])})(),"getDerivedStateFromError",function(){return null}),(()=>{function o(){var r;O(this,o);for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return C(r=S(this,o,[].concat(t)),"state",{error:null}),C(r,"throwError",function(e,t){return r.setState({error:e},t)}),r}return j(o,a.Component),E(o,[{key:"render",value:function(){if(this.state.error)throw this.state.error;return l(this.props.children,void 0,this.throwError)}}])})());function be(e){var n=e.id,o=e.children;return w.createElement(me,null,function(r){return w.createElement(ye,null,function(t){return w.createElement(he,{id:n},function(e){return l(o,void 0,{bridgeProps:{sus$$:t,ctx$$:e,error$$:r}})})})})}function ge(i){var r=(()=>{function o(){var e;O(this,o);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return C(e=S(this,o,[].concat(r)),"drop",null),e}return j(o,a.Component),E(o,[{key:"componentWillUnmount",value:function(){l(this.drop)}},{key:"render",value:function(){var r=this,e=this.props,n=e.forwardedRef,t=x(e,Oe);return w.createElement(oe,null,function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).attach;return w.createElement(i,P({ref:function(t){[_,B].every(function(e){return!s(c(t,e))})||(r.drop=l(e,void 0,t),d(n))||(h(n)&&"current"in n?n.current=t:l(n,void 0,t))}},t))})}}])})();return s(i.prototype.componentDidMount)&&(i.prototype._componentDidMount=i.prototype.componentDidMount,i.prototype.componentDidMount=function(){var e=this;f(function(){return i.prototype._componentDidMount.call(e)})}),s(a.forwardRef)?v(a.forwardRef(function(e,t){return w.createElement(r,P({},e,{forwardedRef:t}))}),i):v(r,i)}function we(e,t){var r,n;[a.useRef,a.useContext,a.useEffect].some(function(e){return!s(e)})||(n=a.useContext(ne))&&(r=a.useRef({}).current,n=n.attach,r[e]=t,r.drop=n(r),a.useEffect(function(){return function(){return l(r.drop)}},[]))}function Se(e){return e.children}var Oe=["forwardedRef"],_="componentDidActivate",B="componentWillUnactivate",t=we.bind(null,_),Ee=we.bind(null,B),Ce=["id","autoFreeze","contentProps"],Pe=(()=>{function o(e){var a;O(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 C(a=S(this,o,[e].concat(r)),"eventBus",new i),C(a,"listeners",new Map),C(a,"wrapper",null),C(a,"timeStampRef",null),C(a,"cache",void 0),C(a,"unmounted",!1),C(a,"safeSetState",function(e,t){a.unmounted||a.setState(e,t)}),C(a,"freezeTimeout",null),C(a,"attach",function(r){var e=a.listeners;return r?(r.isKeepAlive&&f(function(){var e=a.props,t=e.id,e=e.store.get(t);e.aliveNodesId=new Set([].concat(z(e.aliveNodesId),[r.id]))}),e.set(r,C(C({},_,function(){return l(r,_)}),B,function(){return l(r,B)})),function(){e.delete(r)}):function(){return null}}),C(a,"contextValue",{id:a.props.id,attach:a.attach}),C(a,"drop",function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).delay,u=void 0===e?1200:e;return new Promise(function(e){var t,r=a.props,n=r.scope,o=r.id,i=function(){clearTimeout(t),a.eventBus.off(B,i),a.cache.willDrop=!0,n.nodes.delete(o),n.helpers=k({},n.helpers),n.smartForceUpdate(function(){return e(!0)})};c(a.cache,"cached")||c(a.cache,"willDrop")?i():(a.eventBus.on(B,i),t=setTimeout(function(){a.eventBus.off(B,i),e(!1)},u))})}),C(a,"refresh",function(){return new Promise(function(e){c(a.cache,"cached")&&e(!1),a.safeSetState({key:Math.random()},function(){return e(!0)})})}),a.state={children:e.children,bridgeProps:e.bridgeProps,key:Math.random(),freeze:!1},a}return j(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=z(i.children)}catch(e){t=[i.children]}this.cache=C(C({listeners:o,aliveNodesId:[],inited:!1,cached:!1,wrapper:i,nodes:t},_,function(){return e[_]()}),B,function(){return e[B]()}),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:_,value:function(){clearTimeout(this.freezeTimeout),this.safeSetState({freeze:!1}),this.eventBus.emit(_),this.listeners.forEach(function(e){return l(e,[_])})}},{key:B,value:function(){var e=this;this.eventBus.emit(B),z(this.listeners).reverse().forEach(function(e){e=H(e,2)[1];return l(e,[B])}),clearTimeout(this.freezeTimeout),this.freezeTimeout=setTimeout(function(){T.flushSync(function(){e.safeSetState({freeze:!0})})},1e3)}},{key:"render",value:function(){var t=this,e=this.props,r=(e.id,e.autoFreeze),r=void 0===r||r,n=e.contentProps,n=void 0===n?{}:n,e=(x(e,Ce),this.state),o=e.children,e=e.freeze,i=Date.now();return console.log("this.timeStampRef",this.timeStampRef),w.createElement(Se,{freeze:r&&e},w.createElement("div",{ref:function(e){t.wrapper=e}},w.createElement("div",P({},n,{className:"ka-content ".concat(n.className||"")}),w.createElement("div",{ref:function(e){t.timeStampRef=e}},"时间戳:",i),w.Children.map(o,function(e,t){return e}))))}}])})(),je=["children"],R="drop",ke="refresh",xe=(()=>{function n(){var a;O(this,n);for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return C(a=S(this,n,[].concat(t)),"store",new Map),C(a,"nodes",new Map),C(a,"keepers",new Map),C(a,"debouncedForceUpdate",o(function(e){return a.forceUpdate(e)})),C(a,"updateCallbackList",[]),C(a,"smartForceUpdate",function(e){a.updateCallbackList.push(e),a.debouncedForceUpdate(function(){a.updateCallbackList.forEach(function(e){return l(e)}),a.updateCallbackList=[]})}),C(a,"update",function(i,u){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,k(k({id:i,createTime:n,updateTime:n},o),u)),r?(a.helpers=k({},a.helpers),a.forceUpdate(e)):(n=u.children,t.setState({children:n,bridgeProps:u.bridgeProps},e))})}),C(a,"keep",function(t,r){return new Promise(function(e){a.update(t,k({id:t},r)).then(function(){e(a.store.get(t))})})}),C(a,"getCachingNodesByName",function(t){return a.getCachingNodes().filter(function(e){return t instanceof RegExp?t.test(e.name):e.name===t})}),C(a,"getScopeIds",function(e){var r=function(e){var t=c(a.getCache(e),"aliveNodesId",[]);return 0<t.size?[e,z(t).map(r)]:[e].concat(z(t))};return u(e.map(function(e){return r(e)}))}),C(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],R].concat(r))}),C(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),R].concat(r))}),C(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}),R].concat(r))}),C(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))}),C(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],ke].concat(r))}),C(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),ke].concat(r))}),C(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}),ke].concat(r))}),C(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))}),C(a,"handleNodes",function(e){for(var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:R,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 l.apply(void 0,[e,n].concat(o))})).then(function(e){return t(e.every(Boolean))})})}),C(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}),R].concat(t))}),C(a,"getCache",function(e){return a.store.get(e)}),C(a,"getNode",function(e){return a.nodes.get(e)}),C(a,"getCachingNodes",function(){return z(a.nodes.values())}),C(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 j(n,a.Component),E(n,[{key:"render",value:function(){var n=this,e=this.props.children;return w.createElement(Q,{value:this.helpers},void 0===e?null:e,w.createElement("div",{style:{display:"none"}},z(this.nodes.values()).map(function(e){var t=e.children,r=x(e,je);return w.createElement(Pe,P({},r,{nodes:n.nodes.values(),scope:n,store:n.store,keepers:n.keepers,ref:function(e){n.keepers.set(r.id,e)}}),t)})))}}])})(),ze=["id"],Ae=["id"],Ne=["forwardedRef"],Ie=["forwardedRef"];function _e(e){return{drop:e.drop,dropScope:e.dropScope,refresh:e.refresh,refreshScope:e.refreshScope,clear:e.clear,getCachingNodes:e.getCachingNodes}}function Be(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return!!n(e)&&(e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight)}function Re(e){return s(c(b,"document.querySelectorAll"))?[].concat(z(y(l(e,"querySelectorAll","*"),[])),[e]).filter(Be):[]}var Te=["_helpers","id","children"],qe=["_helpers","id","name"],De=c(b,"document.body"),Ue=c(b,"document.scrollingElement",c(b,"document.documentElement",{})),$e=(()=>{function t(e){var i;return O(this,t),C(i=S(this,t,[e]),"id",null),C(i,"isKeepAlive",!0),C(i,"cached",!1),C(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&&l(t.revertScrollPos)}catch(e){console.error(e)}}),C(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=u(u([i.props.saveScrollPosition]).map(function(e){return!0===e?o.nodes:"screen"===e?[Ue,De]:z(y(l(b,"document.querySelectorAll",e),[]))})).filter(Boolean);try{t&&0<r.length&&(o.revertScrollPos=(e=z(new Set(z(u(r.map(Re))))).map(function(e){return[e,{x:e.scrollLeft,y:e.scrollTop}]}),function(){e.forEach(function(e){var e=H(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){}}),C(i,"init",function(){var e=i.props,t=e._helpers,r=e.id,n=e.children,e=x(e,Te);t.keep(r,k({children:n,getInstance:function(){return i}},e)).then(function(e){e&&(i.inject(),e.inited?l(i,_):e.inited=!0,i.cached=!1)})}),C(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,qe);t&&!i.cached&&t.update(r,k({name:n,getInstance:function(){return i}},e))}),i.id=e.id,i.init(),[_,B].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===_&&(e.updateTime=Date.now()),n===B);!r||r.willDrop?i.cached&&!t&&i.init():(l(r,n),r.cached=t,i.cached=t)}}),i}return j(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=l(e);var e=H(m(e)?e:[e],2),o=e[0],e=e[1];n&&(this.eject(),delete n.getInstance,o||(e?([n].concat(z(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)}))),l(this,B))}},{key:"render",value:function(){var t=this,e=(this.props||{}).wrapperProps,e=void 0===e?{}:e;return w.createElement("div",P({},e,{key:"keep-alive-placeholder",nodeKeyIgnore:!0,className:"ka-wrapper ".concat(e.className||""),ref:function(e){t.placeholder=e}}))}}])})();C($e,"defaultProps",{saveScrollPosition:!0});var Le,$e=s(c(b,"document.getElementById"))?(Le=ge($e),s(a.useContext)?function(e){var t=e.id,e=x(e,ze);return Me({idPrefix:t,helpers:J(),props:e})}:function(e){var t=e.id,r=x(e,Ae);return w.createElement(X,null,function(e){return Me({idPrefix:t,helpers:e,props:r})})}):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",P({},r,{key:"keep-alive-placeholder",nodeKeyIgnore:!0,className:"ka-wrapper ".concat(r.className||"")}),w.createElement("div",P({},t,{key:"keeper-container",nodeKeyIgnore:!0,className:"ka-content ".concat(t.className||"")}),e))};function Me(e){var t=e.idPrefix,r=e.helpers,n=e.props;return(e=d(r))&&console.error("You should not use <KeepAlive /> outside a <AliveScope>"),e?c(n,"children",null):w.createElement(g,{prefix:t,key:n._nk,manualKey:n.cacheKey},function(e){var t=n.cacheKey||e;return w.createElement(be,{key:t,id:t},function(e){return w.createElement(Le,P({key:t},n,e,{id:t,_helpers:r}))})})}e.AliveScope=xe,e.KeepAlive=$e,e.NodeKey=g,e.autoFixContext=ee,e.createContext=function(e,t){e=r(e,t);return se(e),e},e.default=$e,e.fixContext=se,e.useActivate=t,e.useAliveController=function(){var e;return s(a.useContext)&&(e=J())?_e(e):{}},e.useUnactivate=Ee,e.withActivation=ge,e.withAliveScope=function(r){function n(e){var t=e.helpers;return w.createElement(r,P({},e.props,t,{ref:e.forwardedRef}))}var o=s(a.useContext)?function(e){var t=e.forwardedRef,e=x(e,Ne);return n({helpers:_e(J()||{}),props:e,forwardedRef:t})}:function(e){var t=e.forwardedRef,r=x(e,Ie);return w.createElement(X,null,function(){return n({helpers:_e(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}),props:r,forwardedRef:t})})};return s(a.forwardRef)?v(a.forwardRef(function(e,t){return w.createElement(o,P({},e,{forwardedRef:t}))}),r):v(o,r)},Object.defineProperty(e,"__esModule",{value:!0})});