UNPKG

react-if-render

Version:

Conditional Rendering of React Components.

684 lines (680 loc) 22.8 kB
import * as dr from "react"; import { Fragment as N, Children as vr, isValidElement as pr } from "react"; function yr(s) { if (s.__esModule) return s; var d = s.default; if (typeof d == "function") { var m = function c() { return this instanceof c ? Reflect.construct(d, arguments, this.constructor) : d.apply(this, arguments); }; m.prototype = d.prototype; } else m = {}; return Object.defineProperty(m, "__esModule", { value: !0 }), Object.keys(s).forEach(function(c) { var g = Object.getOwnPropertyDescriptor(s, c); Object.defineProperty(m, c, g.get ? g : { enumerable: !0, get: function() { return s[c]; } }); }), m; } var Q = { exports: {} }, A = {}; const je = /* @__PURE__ */ yr(dr); /** * @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 Ce; function hr() { if (Ce) return A; Ce = 1; var s = je, d = Symbol.for("react.element"), m = Symbol.for("react.fragment"), c = Object.prototype.hasOwnProperty, g = s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 }; function O(b, v, w) { var h, _ = {}, C = null, $ = null; w !== void 0 && (C = "" + w), v.key !== void 0 && (C = "" + v.key), v.ref !== void 0 && ($ = v.ref); for (h in v) c.call(v, h) && !S.hasOwnProperty(h) && (_[h] = v[h]); if (b && b.defaultProps) for (h in v = b.defaultProps, v) _[h] === void 0 && (_[h] = v[h]); return { $$typeof: d, type: b, key: C, ref: $, props: _, _owner: g.current }; } return A.Fragment = m, A.jsx = O, A.jsxs = O, A; } var I = {}; /** * @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 Pe; function Er() { return Pe || (Pe = 1, process.env.NODE_ENV !== "production" && function() { var s = je, d = Symbol.for("react.element"), m = Symbol.for("react.portal"), c = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), O = Symbol.for("react.provider"), b = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), _ = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), $ = Symbol.for("react.offscreen"), ee = Symbol.iterator, ke = "@@iterator"; function De(e) { if (e === null || typeof e != "object") return null; var r = ee && e[ee] || e[ke]; return typeof r == "function" ? r : null; } var j = s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function p(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++) t[n - 1] = arguments[n]; Fe("error", e, t); } } function Fe(e, r, t) { { var n = j.ReactDebugCurrentFrame, i = n.getStackAddendum(); i !== "" && (r += "%s", t = t.concat([i])); var u = t.map(function(o) { return String(o); }); u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u); } } var Ae = !1, Ie = !1, Ne = !1, We = !1, $e = !1, re; re = Symbol.for("react.module.reference"); function Ye(e) { return !!(typeof e == "string" || typeof e == "function" || e === c || e === S || $e || e === g || e === w || e === h || We || e === $ || Ae || Ie || Ne || typeof e == "object" && e !== null && (e.$$typeof === C || e.$$typeof === _ || e.$$typeof === O || e.$$typeof === b || e.$$typeof === v || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === re || e.getModuleId !== void 0)); } function Le(e, r, t) { var n = e.displayName; if (n) return n; var i = r.displayName || r.name || ""; return i !== "" ? t + "(" + i + ")" : t; } function te(e) { return e.displayName || "Context"; } function R(e) { if (e == null) return null; if (typeof e.tag == "number" && p("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 c: return "Fragment"; case m: return "Portal"; case S: return "Profiler"; case g: return "StrictMode"; case w: return "Suspense"; case h: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case b: var r = e; return te(r) + ".Consumer"; case O: var t = e; return te(t._context) + ".Provider"; case v: return Le(e, e.render, "ForwardRef"); case _: var n = e.displayName || null; return n !== null ? n : R(e.type) || "Memo"; case C: { var i = e, u = i._payload, o = i._init; try { return R(o(u)); } catch { return null; } } } return null; } var P = Object.assign, D = 0, ne, ae, oe, ie, ue, se, fe; function le() { } le.__reactDisabledLog = !0; function Me() { { if (D === 0) { ne = console.log, ae = console.info, oe = console.warn, ie = console.error, ue = console.group, se = console.groupCollapsed, fe = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: le, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } D++; } } function Ve() { { if (D--, D === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: P({}, e, { value: ne }), info: P({}, e, { value: ae }), warn: P({}, e, { value: oe }), error: P({}, e, { value: ie }), group: P({}, e, { value: ue }), groupCollapsed: P({}, e, { value: se }), groupEnd: P({}, e, { value: fe }) }); } D < 0 && p("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var q = j.ReactCurrentDispatcher, G; function Y(e, r, t) { { if (G === void 0) try { throw Error(); } catch (i) { var n = i.stack.trim().match(/\n( *(at )?)/); G = n && n[1] || ""; } return ` ` + G + e; } } var J = !1, L; { var Ue = typeof WeakMap == "function" ? WeakMap : Map; L = new Ue(); } function ce(e, r) { if (!e || J) return ""; { var t = L.get(e); if (t !== void 0) return t; } var n; J = !0; var i = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var u; u = q.current, q.current = null, Me(); try { if (r) { var o = function() { throw Error(); }; if (Object.defineProperty(o.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(o, []); } catch (T) { n = T; } Reflect.construct(e, [], o); } else { try { o.call(); } catch (T) { n = T; } e.call(o.prototype); } } else { try { throw Error(); } catch (T) { n = T; } e(); } } catch (T) { if (T && n && typeof T.stack == "string") { for (var a = T.stack.split(` `), y = n.stack.split(` `), f = a.length - 1, l = y.length - 1; f >= 1 && l >= 0 && a[f] !== y[l]; ) l--; for (; f >= 1 && l >= 0; f--, l--) if (a[f] !== y[l]) { if (f !== 1 || l !== 1) do if (f--, l--, l < 0 || a[f] !== y[l]) { var E = ` ` + a[f].replace(" at new ", " at "); return e.displayName && E.includes("<anonymous>") && (E = E.replace("<anonymous>", e.displayName)), typeof e == "function" && L.set(e, E), E; } while (f >= 1 && l >= 0); break; } } } finally { J = !1, q.current = u, Ve(), Error.prepareStackTrace = i; } var k = e ? e.displayName || e.name : "", Oe = k ? Y(k) : ""; return typeof e == "function" && L.set(e, Oe), Oe; } function Be(e, r, t) { return ce(e, !1); } function qe(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function M(e, r, t) { if (e == null) return ""; if (typeof e == "function") return ce(e, qe(e)); if (typeof e == "string") return Y(e); switch (e) { case w: return Y("Suspense"); case h: return Y("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case v: return Be(e.render); case _: return M(e.type, r, t); case C: { var n = e, i = n._payload, u = n._init; try { return M(u(i), r, t); } catch { } } } return ""; } var V = Object.prototype.hasOwnProperty, de = {}, ve = j.ReactDebugCurrentFrame; function U(e) { if (e) { var r = e._owner, t = M(e.type, e._source, r ? r.type : null); ve.setExtraStackFrame(t); } else ve.setExtraStackFrame(null); } function Ge(e, r, t, n, i) { { var u = Function.call.bind(V); for (var o in e) if (u(e, o)) { var a = void 0; try { if (typeof e[o] != "function") { var y = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw y.name = "Invariant Violation", y; } a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (f) { a = f; } a && !(a instanceof Error) && (U(i), p("%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).", n || "React class", t, o, typeof a), U(null)), a instanceof Error && !(a.message in de) && (de[a.message] = !0, U(i), p("Failed %s type: %s", t, a.message), U(null)); } } } var Je = Array.isArray; function z(e) { return Je(e); } function ze(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function He(e) { try { return pe(e), !1; } catch { return !0; } } function pe(e) { return "" + e; } function ye(e) { if (He(e)) return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), pe(e); } var F = j.ReactCurrentOwner, Ke = { key: !0, ref: !0, __self: !0, __source: !0 }, he, Ee, H; H = {}; function Xe(e) { if (V.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function Ze(e) { if (V.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function Qe(e, r) { if (typeof e.ref == "string" && F.current && r && F.current.stateNode !== r) { var t = R(F.current.type); H[t] || (p('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', R(F.current.type), e.ref), H[t] = !0); } } function er(e, r) { { var t = function() { he || (he = !0, p("%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 rr(e, r) { { var t = function() { Ee || (Ee = !0, p("%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 tr = function(e, r, t, n, i, u, o) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: d, // Built-in properties that belong on the element type: e, key: r, ref: t, props: o, // Record the component responsible for creating this element. _owner: u }; return a._store = {}, Object.defineProperty(a._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(a, "_self", { configurable: !1, enumerable: !1, writable: !1, value: n }), Object.defineProperty(a, "_source", { configurable: !1, enumerable: !1, writable: !1, value: i }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a; }; function nr(e, r, t, n, i) { { var u, o = {}, a = null, y = null; t !== void 0 && (ye(t), a = "" + t), Ze(r) && (ye(r.key), a = "" + r.key), Xe(r) && (y = r.ref, Qe(r, i)); for (u in r) V.call(r, u) && !Ke.hasOwnProperty(u) && (o[u] = r[u]); if (e && e.defaultProps) { var f = e.defaultProps; for (u in f) o[u] === void 0 && (o[u] = f[u]); } if (a || y) { var l = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && er(o, l), y && rr(o, l); } return tr(e, a, y, i, n, F.current, o); } } var K = j.ReactCurrentOwner, me = j.ReactDebugCurrentFrame; function x(e) { if (e) { var r = e._owner, t = M(e.type, e._source, r ? r.type : null); me.setExtraStackFrame(t); } else me.setExtraStackFrame(null); } var X; X = !1; function Z(e) { return typeof e == "object" && e !== null && e.$$typeof === d; } function ge() { { if (K.current) { var e = R(K.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function ar(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var be = {}; function or(e) { { var r = ge(); 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 _e(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = or(r); if (be[t]) return; be[t] = !0; var n = ""; e && e._owner && e._owner !== K.current && (n = " It was passed a child from " + R(e._owner.type) + "."), x(e), p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), x(null); } } function Re(e, r) { { if (typeof e != "object") return; if (z(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; Z(n) && _e(n, r); } else if (Z(e)) e._store && (e._store.validated = !0); else if (e) { var i = De(e); if (typeof i == "function" && i !== e.entries) for (var u = i.call(e), o; !(o = u.next()).done; ) Z(o.value) && _e(o.value, r); } } } function ir(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 === v || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === _)) t = r.propTypes; else return; if (t) { var n = R(r); Ge(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !X) { X = !0; var i = R(r); p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function ur(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { x(e), p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), x(null); break; } } e.ref !== null && (x(e), p("Invalid attribute `ref` supplied to `React.Fragment`."), x(null)); } } function Te(e, r, t, n, i, u) { { var o = Ye(e); if (!o) { var a = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " 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 y = ar(i); y ? a += y : a += ge(); var f; e === null ? f = "null" : z(e) ? f = "array" : e !== void 0 && e.$$typeof === d ? (f = "<" + (R(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : f = typeof e, p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", f, a); } var l = nr(e, r, t, i, u); if (l == null) return l; if (o) { var E = r.children; if (E !== void 0) if (n) if (z(E)) { for (var k = 0; k < E.length; k++) Re(E[k], e); Object.freeze && Object.freeze(E); } else p("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 Re(E, e); } return e === c ? ur(l) : ir(l), l; } } function sr(e, r, t) { return Te(e, r, t, !0); } function fr(e, r, t) { return Te(e, r, t, !1); } var lr = fr, cr = sr; I.Fragment = c, I.jsx = lr, I.jsxs = cr; }()), I; } process.env.NODE_ENV === "production" ? Q.exports = hr() : Q.exports = Er(); var W = Q.exports; const Se = "Then", we = "Else", xe = "If the component's children should be Then and Else"; function _r({ condition: s, children: d }) { const m = (c) => { if (!pr(c) || typeof c.type == "string" || !("displayName" in c.type) || typeof c.type.displayName != "string") return B(); const { displayName: g } = c.type, S = s && g === Se, O = !s && g === we, b = ![Se, we].includes(g); return S || O ? c : (b && console.warn(xe), null); }; return /* @__PURE__ */ W.jsx(N, { children: vr.map(d, m) }); } const B = () => (console.warn(xe), null); function mr({ children: s }) { return /* @__PURE__ */ W.jsx(N, { children: s }); } mr.displayName = "Then"; function gr({ children: s }) { return /* @__PURE__ */ W.jsx(N, { children: s }); } gr.displayName = "Else"; function Rr({ condition: s, children: d }) { return /* @__PURE__ */ W.jsx(N, { children: s && d }); } function Tr({ condition: s, children: d }) { return /* @__PURE__ */ W.jsx(N, { children: !s && d }); } export { gr as Else, _r as If, mr as Then, Tr as Unless, Rr as When };