UNPKG

@654356282/react-keepalive

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