@yookue/react-condition
Version:
Render components conditionally for react
1 lines • 11.3 kB
JavaScript
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.ReactCondition=r():e.ReactCondition=r()}(self,(function(){return function(){var e={2:function(e,r,t){"use strict";var n=t(978),o=Symbol.for("react.element"),u=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,c=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function a(e,r,t){var n,u={},a=null,f=null;for(n in void 0!==t&&(a=""+t),void 0!==r.key&&(a=""+r.key),void 0!==r.ref&&(f=r.ref),r)i.call(r,n)&&!l.hasOwnProperty(n)&&(u[n]=r[n]);if(e&&e.defaultProps)for(n in r=e.defaultProps)void 0===u[n]&&(u[n]=r[n]);return{$$typeof:o,type:e,key:a,ref:f,props:u,_owner:c.current}}r.jsx=a},352:function(e,r,t){"use strict";var n=t(944).default,o=Symbol.for("react.element"),u=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),f=Symbol.for("react.context"),s=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),h=Symbol.iterator;var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},m=Object.assign,_={};function b(e,r,t){this.props=e,this.context=r,this.refs=_,this.updater=t||v}function S(){}function E(e,r,t){this.props=e,this.context=r,this.refs=_,this.updater=t||v}b.prototype.isReactComponent={},b.prototype.setState=function(e,r){if("object"!==n(e)&&"function"!=typeof e&&null!=e)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,r,"setState")},b.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},S.prototype=b.prototype;var x=E.prototype=new S;x.constructor=E,m(x,b.prototype),x.isPureReactComponent=!0;var w=Array.isArray,j=Object.prototype.hasOwnProperty,C={current:null},R={key:!0,ref:!0,__self:!0,__source:!0};function O(e,r,t){var n,u={},i=null,c=null;if(null!=r)for(n in void 0!==r.ref&&(c=r.ref),void 0!==r.key&&(i=""+r.key),r)j.call(r,n)&&!R.hasOwnProperty(n)&&(u[n]=r[n]);var l=arguments.length-2;if(1===l)u.children=t;else if(1<l){for(var a=Array(l),f=0;f<l;f++)a[f]=arguments[f+2];u.children=a}if(e&&e.defaultProps)for(n in l=e.defaultProps)void 0===u[n]&&(u[n]=l[n]);return{$$typeof:o,type:e,key:i,ref:c,props:u,_owner:C.current}}function k(e){return"object"===n(e)&&null!==e&&e.$$typeof===o}var g=/\/+/g;function $(e,r){return"object"===n(e)&&null!==e&&null!=e.key?function(e){var r={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,(function(e){return r[e]}))}(""+e.key):r.toString(36)}function I(e,r,t,i,c){var l=n(e);"undefined"!==l&&"boolean"!==l||(e=null);var a=!1;if(null===e)a=!0;else switch(l){case"string":case"number":a=!0;break;case"object":switch(e.$$typeof){case o:case u:a=!0}}if(a)return c=c(a=e),e=""===i?"."+$(a,0):i,w(c)?(t="",null!=e&&(t=e.replace(g,"$&/")+"/"),I(c,r,t,"",(function(e){return e}))):null!=c&&(k(c)&&(c=function(e,r){return{$$typeof:o,type:e.type,key:r,ref:e.ref,props:e.props,_owner:e._owner}}(c,t+(!c.key||a&&a.key===c.key?"":(""+c.key).replace(g,"$&/")+"/")+e)),r.push(c)),1;if(a=0,i=""===i?".":i+":",w(e))for(var f=0;f<e.length;f++){var s=i+$(l=e[f],f);a+=I(l,r,t,s,c)}else if(s=function(e){return null===e||"object"!==n(e)?null:"function"==typeof(e=h&&e[h]||e["@@iterator"])?e:null}(e),"function"==typeof s)for(e=s.call(e),f=0;!(l=e.next()).done;)a+=I(l=l.value,r,t,s=i+$(l,f++),c);else if("object"===l)throw r=String(e),Error("Objects are not valid as a React child (found: "+("[object Object]"===r?"object with keys {"+Object.keys(e).join(", ")+"}":r)+"). If you meant to render a collection of children, use an array instead.");return a}function P(e,r,t){if(null==e)return e;var n=[],o=0;return I(e,n,"","",(function(e){return r.call(t,e,o++)})),n}function T(e){if(-1===e._status){var r=e._result;(r=r()).then((function(r){0!==e._status&&-1!==e._status||(e._status=1,e._result=r)}),(function(r){0!==e._status&&-1!==e._status||(e._status=2,e._result=r)})),-1===e._status&&(e._status=0,e._result=r)}if(1===e._status)return e._result.default;throw e._result}var D={current:null},N={transition:null},A={ReactCurrentDispatcher:D,ReactCurrentBatchConfig:N,ReactCurrentOwner:C};function M(){throw Error("act(...) is not supported in production builds of React.")}r.Children={map:P,forEach:function(e,r,t){P(e,(function(){r.apply(this,arguments)}),t)},count:function(e){var r=0;return P(e,(function(){r++})),r},toArray:function(e){return P(e,(function(e){return e}))||[]},only:function(e){if(!k(e))throw Error("React.Children.only expected to receive a single React element child.");return e}},r.Component=b,r.Fragment=i,r.Profiler=l,r.PureComponent=E,r.StrictMode=c,r.Suspense=d,r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=A,r.act=M,r.cloneElement=function(e,r,t){if(null==e)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var n=m({},e.props),u=e.key,i=e.ref,c=e._owner;if(null!=r){if(void 0!==r.ref&&(i=r.ref,c=C.current),void 0!==r.key&&(u=""+r.key),e.type&&e.type.defaultProps)var l=e.type.defaultProps;for(a in r)j.call(r,a)&&!R.hasOwnProperty(a)&&(n[a]=void 0===r[a]&&void 0!==l?l[a]:r[a])}var a=arguments.length-2;if(1===a)n.children=t;else if(1<a){l=Array(a);for(var f=0;f<a;f++)l[f]=arguments[f+2];n.children=l}return{$$typeof:o,type:e.type,key:u,ref:i,props:n,_owner:c}},r.createContext=function(e){return(e={$$typeof:f,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null}).Provider={$$typeof:a,_context:e},e.Consumer=e},r.createElement=O,r.createFactory=function(e){var r=O.bind(null,e);return r.type=e,r},r.createRef=function(){return{current:null}},r.forwardRef=function(e){return{$$typeof:s,render:e}},r.isValidElement=k,r.lazy=function(e){return{$$typeof:y,_payload:{_status:-1,_result:e},_init:T}},r.memo=function(e,r){return{$$typeof:p,type:e,compare:void 0===r?null:r}},r.startTransition=function(e){var r=N.transition;N.transition={};try{e()}finally{N.transition=r}},r.unstable_act=M,r.useCallback=function(e,r){return D.current.useCallback(e,r)},r.useContext=function(e){return D.current.useContext(e)},r.useDebugValue=function(){},r.useDeferredValue=function(e){return D.current.useDeferredValue(e)},r.useEffect=function(e,r){return D.current.useEffect(e,r)},r.useId=function(){return D.current.useId()},r.useImperativeHandle=function(e,r,t){return D.current.useImperativeHandle(e,r,t)},r.useInsertionEffect=function(e,r){return D.current.useInsertionEffect(e,r)},r.useLayoutEffect=function(e,r){return D.current.useLayoutEffect(e,r)},r.useMemo=function(e,r){return D.current.useMemo(e,r)},r.useReducer=function(e,r,t){return D.current.useReducer(e,r,t)},r.useRef=function(e){return D.current.useRef(e)},r.useState=function(e){return D.current.useState(e)},r.useSyncExternalStore=function(e,r,t){return D.current.useSyncExternalStore(e,r,t)},r.useTransition=function(){return D.current.useTransition()},r.version="18.3.1"},978:function(e,r,t){"use strict";e.exports=t(352)},107:function(e,r,t){"use strict";e.exports=t(2)},944:function(e){function r(t){return e.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,r(t)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var u=r[n]={exports:{}};return e[n](u,u.exports,t),u.exports}t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){"use strict";t.r(n),t.d(n,{Do:function(){return o},For:function(){return u},If:function(){return i},MapIterator:function(){return c},ObjectIterator:function(){return l},SetIterator:function(){return a},Switch:function(){return f},While:function(){return s}});var e=t(978),r=t(107),o=function(e){var t=[],n=0;do{e.render?t.push(null==e?void 0:e.render(n)):!e.render&&e.children&&t.push((0,r.jsx)("div",{className:"condition-do",children:e.children},n)),n++}while(e.condition());return t},u=function(e){return e.of.map((function(t,n){return e.render?e.render(t,n):!e.render&&e.children?(0,r.jsx)("div",{className:"condition-for",children:e.children},n):void 0}))},i=function r(t){if(t.children){if(!1!==t.validation){var n=0,o=0;if(e.Children.forEach(t.children,(function(e){var t=null==e?void 0:e.type;t===r.Then&&n++,t===r.Else&&o++})),n>1||o>1)throw SyntaxError("Each statement of 'If.Then/If.Else' for [If condition='".concat(t.condition,"'] must be a single one!"))}return e.Children.map(t.children,(function(e){var n=(null==e?void 0:e.type)===r.Else;return t.condition&&!n||!t.condition&&n?e:void 0}))}};i.Then=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children},i.Else=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children};var c=function(e){return Array.from(e.of).map((function(t,n){return e.render?(null==t?void 0:t.length)>1?e.render(t[1],t[0],n):void 0:!e.render&&e.children?(0,r.jsx)("div",{className:"condition-map-iterator",children:e.children},n):void 0}))},l=function(e){if(e.of)return Object.keys(e.of).map((function(t,n){return e.render?e.render(e.of[t],t,n):!e.render&&e.children?(0,r.jsx)("div",{className:"condition-object-iterator",children:e.children},n):void 0}))},a=function(e){return Array.from(e.of).map((function(t,n){return e.render?e.render(t,n):!e.render&&e.children?(0,r.jsx)("div",{className:"condition-set-iterator",children:e.children},n):void 0}))},f=function r(t){var n;if(null!=t&&t.children){if(!1!==(null==t?void 0:t.validation)){var o=0,u=0;if(e.Children.forEach(t.children,(function(e){var t=null==e?void 0:e.type;t===r.Case&&o++,t===r.Default&&u++})),0===o&&0===u)throw SyntaxError("[Switch] must has any statements of 'Switch.Case/Switch.Default' at least!");if(u>1)throw SyntaxError("Statement of 'Switch.Default' for [Switch] must be a single one at most!")}var i=void 0,c=void 0;return e.Children.forEach(t.children,(function(e){var t,n,o,u=null==e?void 0:e.type;u===r.Case&&null!==(t=e.props)&&void 0!==t&&t.condition&&(i=null===(n=e.props)||void 0===n?void 0:n.children);u===r.Default&&(c=null===(o=e.props)||void 0===o?void 0:o.children)})),null!==(n=i)&&void 0!==n?n:c}};f.Case=function(e){return e.condition?null!=e&&e.render?e.render():e.children:void 0},f.Default=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children};var s=function(e){for(var t=[],n=0;e.condition();)e.render?t.push(null==e?void 0:e.render(n)):!e.render&&e.children&&t.push((0,r.jsx)("div",{className:"condition-while",children:e.children},n)),n++;return t}}(),n}()}));