UNPKG

@ndriadev/react-tools

Version:

A React library of hooks, components, utils and types ready to use

2 lines (1 loc) 3.38 kB
"use strict";var y=Object.defineProperty;var z=(s,r,t)=>r in s?y(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t;var E=(s,r,t)=>z(s,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime-DUg93gSO.cjs"),n=require("react"),R=[],M=({factory:s,componentName:r,beforeLoad:t,afterLoad:i})=>{const a=s.toString();for(const o of R)if(o.factorySerialized===a){if(o.response)return i&&i(),o.response&&o.response();throw o.error?o.error:o.promise}const u={factorySerialized:String.raw`${a}`,promise:(t&&t(),s().then(o=>{"default"in o&&(u.response=o.default),r&&r in o&&(u.response=o[r]);const c=Reflect.ownKeys(o).filter(p=>p!=="__esModule");throw c.length>0&&(u.response=o[c[0]]),Error("Invalid import")}).catch(o=>u.error=o))};throw R.push(u),u.promise},b=({factory:s,componentName:r,fallback:t,beforeLoad:i,afterLoad:a})=>e.jsxRuntimeExports.jsx(n.Suspense,{fallback:t,children:e.jsxRuntimeExports.jsx(M,{factory:s,componentName:r,beforeLoad:i,afterLoad:a})});function S({when:s,fallback:r,children:t}){return s?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:t}):r?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:r}):null}const v=n.memo(S),w=({children:s,when:r})=>r?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:s}):null,g=({children:s,fallback:r})=>{const t=n.Children.toArray(s).find(i=>n.isValidElement(i)&&i.props.when);return t?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:t}):r!==void 0?e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[" ",r]}):null},k={Switch:g,Case:w},V={Switch:n.memo(g),Case:n.memo(w)};function l({of:s,elementKey:r,fallback:t,filter:i,sort:a,map:u,children:o}){if(s.length===0)return t!==void 0?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:t}):null;let c=a?a===!0?s.sort():s.sort(a):s;return c=i?c.filter(i):c,c.map((p,m,F)=>{if(u!==void 0){const h=u(p,m,F),f=r?typeof r=="function"?r(h):typeof h=="object"&&h!==null&&r in h?h[r]:r:m,j=o(h,m,f);return n.isValidElement(j)?n.cloneElement(j,{key:f}):null}const x=r?typeof r=="function"?r(p):typeof p=="object"&&p!==null&&r in p?p[r]:r:m,d=o(p,m,x);return n.isValidElement(d)?n.cloneElement(d,{key:x}):null})}l.displayName="For";const C=n.memo(l);C.displayName="ForMemoized";class q extends n.Component{constructor(){super(...arguments);E(this,"state",{hasError:!1})}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,i){this.props.onCatch&&this.props.onCatch(t,i),this.setState({hasError:!0,error:t,info:i})}retry(){this.setState({hasError:!1,error:void 0,info:void 0})}render(){if(this.state.hasError&&this.props.fallback){if(typeof this.props.fallback=="function")if(n.isValidElement(this.props.fallback)){const t=this.props.fallback;return e.jsxRuntimeExports.jsx(t,{error:this.state.error,info:this.state.info,retry:this.retry.bind(this)})}else return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:this.props.fallback(this.state.error,this.state.info,this.retry.bind(this))});return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:this.props.fallback})}return this.props.children}}exports.ErrorBoundary=q;exports.For=l;exports.ForMemoized=C;exports.LazyComponent=b;exports.Show=S;exports.ShowMemoized=v;exports.SwitchCase=k;exports.SwitchCaseMemoized=V;