UNPKG

react-qc-iii

Version:

Lightweight react-query wrapper that provides error/loading, and more...

28 lines (24 loc) 17.2 kB
(function(v,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("react-query"),require("react"),require("react-error-boundary")):typeof define=="function"&&define.amd?define(["exports","react-query","react","react-error-boundary"],D):(v=typeof globalThis<"u"?globalThis:v||self,D(v.ReactQC={},v.reactQuery,v.React,v.reactErrorBoundary))})(this,function(v,D,I,Ve){"use strict";var re={exports:{}},Y={};/** * @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 le;function Me(){if(le)return Y;le=1;var a=I,o=Symbol.for("react.element"),c=Symbol.for("react.fragment"),p=Object.prototype.hasOwnProperty,h=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,b={key:!0,ref:!0,__self:!0,__source:!0};function y(d,l,_){var m,P={},x=null,k=null;_!==void 0&&(x=""+_),l.key!==void 0&&(x=""+l.key),l.ref!==void 0&&(k=l.ref);for(m in l)p.call(l,m)&&!b.hasOwnProperty(m)&&(P[m]=l[m]);if(d&&d.defaultProps)for(m in l=d.defaultProps,l)P[m]===void 0&&(P[m]=l[m]);return{$$typeof:o,type:d,key:x,ref:k,props:P,_owner:h.current}}return Y.Fragment=c,Y.jsx=y,Y.jsxs=y,Y}var L={};/** * @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 de;function $e(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){var a=I,o=Symbol.for("react.element"),c=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),y=Symbol.for("react.provider"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),k=Symbol.for("react.offscreen"),N=Symbol.iterator,V="@@iterator";function C(e){if(e===null||typeof e!="object")return null;var r=N&&e[N]||e[V];return typeof r=="function"?r:null}var O=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var r=arguments.length,n=new Array(r>1?r-1:0),t=1;t<r;t++)n[t-1]=arguments[t];Ee("error",e,n)}}function Ee(e,r,n){{var t=O.ReactDebugCurrentFrame,s=t.getStackAddendum();s!==""&&(r+="%s",n=n.concat([s]));var f=n.map(function(u){return String(u)});f.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,f)}}var M=!1,J=!1,G=!1,er=!1,rr=!1,me;me=Symbol.for("react.module.reference");function nr(e){return!!(typeof e=="string"||typeof e=="function"||e===p||e===b||rr||e===h||e===_||e===m||er||e===k||M||J||G||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===P||e.$$typeof===y||e.$$typeof===d||e.$$typeof===l||e.$$typeof===me||e.getModuleId!==void 0))}function tr(e,r,n){var t=e.displayName;if(t)return t;var s=r.displayName||r.name||"";return s!==""?n+"("+s+")":n}function Re(e){return e.displayName||"Context"}function j(e){if(e==null)return null;if(typeof e.tag=="number"&&R("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 p:return"Fragment";case c:return"Portal";case b:return"Profiler";case h:return"StrictMode";case _:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case d:var r=e;return Re(r)+".Consumer";case y:var n=e;return Re(n._context)+".Provider";case l:return tr(e,e.render,"ForwardRef");case P:var t=e.displayName||null;return t!==null?t:j(e.type)||"Memo";case x:{var s=e,f=s._payload,u=s._init;try{return j(u(f))}catch{return null}}}return null}var A=Object.assign,$=0,_e,be,Pe,Te,xe,Ce,we;function Oe(){}Oe.__reactDisabledLog=!0;function ar(){{if($===0){_e=console.log,be=console.info,Pe=console.warn,Te=console.error,xe=console.group,Ce=console.groupCollapsed,we=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Oe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function or(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:A({},e,{value:_e}),info:A({},e,{value:be}),warn:A({},e,{value:Pe}),error:A({},e,{value:Te}),group:A({},e,{value:xe}),groupCollapsed:A({},e,{value:Ce}),groupEnd:A({},e,{value:we})})}$<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var te=O.ReactCurrentDispatcher,ae;function z(e,r,n){{if(ae===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);ae=t&&t[1]||""}return` `+ae+e}}var oe=!1,H;{var ir=typeof WeakMap=="function"?WeakMap:Map;H=new ir}function je(e,r){if(!e||oe)return"";{var n=H.get(e);if(n!==void 0)return n}var t;oe=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var f;f=te.current,te.current=null,ar();try{if(r){var u=function(){throw Error()};if(Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(S){t=S}Reflect.construct(e,[],u)}else{try{u.call()}catch(S){t=S}e.call(u.prototype)}}else{try{throw Error()}catch(S){t=S}e()}}catch(S){if(S&&t&&typeof S.stack=="string"){for(var i=S.stack.split(` `),T=t.stack.split(` `),g=i.length-1,E=T.length-1;g>=1&&E>=0&&i[g]!==T[E];)E--;for(;g>=1&&E>=0;g--,E--)if(i[g]!==T[E]){if(g!==1||E!==1)do if(g--,E--,E<0||i[g]!==T[E]){var w=` `+i[g].replace(" at new "," at ");return e.displayName&&w.includes("<anonymous>")&&(w=w.replace("<anonymous>",e.displayName)),typeof e=="function"&&H.set(e,w),w}while(g>=1&&E>=0);break}}}finally{oe=!1,te.current=f,or(),Error.prepareStackTrace=s}var U=e?e.displayName||e.name:"",Be=U?z(U):"";return typeof e=="function"&&H.set(e,Be),Be}function ur(e,r,n){return je(e,!1)}function sr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function X(e,r,n){if(e==null)return"";if(typeof e=="function")return je(e,sr(e));if(typeof e=="string")return z(e);switch(e){case _:return z("Suspense");case m:return z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case l:return ur(e.render);case P:return X(e.type,r,n);case x:{var t=e,s=t._payload,f=t._init;try{return X(f(s),r,n)}catch{}}}return""}var Z=Object.prototype.hasOwnProperty,Se={},ke=O.ReactDebugCurrentFrame;function ee(e){if(e){var r=e._owner,n=X(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(n)}else ke.setExtraStackFrame(null)}function fr(e,r,n,t,s){{var f=Function.call.bind(Z);for(var u in e)if(f(e,u)){var i=void 0;try{if(typeof e[u]!="function"){var T=Error((t||"React class")+": "+n+" type `"+u+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[u]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw T.name="Invariant Violation",T}i=e[u](r,u,t,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){i=g}i&&!(i instanceof Error)&&(ee(s),R("%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).",t||"React class",n,u,typeof i),ee(null)),i instanceof Error&&!(i.message in Se)&&(Se[i.message]=!0,ee(s),R("Failed %s type: %s",n,i.message),ee(null))}}}var cr=Array.isArray;function ie(e){return cr(e)}function lr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,n=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function dr(e){try{return De(e),!1}catch{return!0}}function De(e){return""+e}function Fe(e){if(dr(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",lr(e)),De(e)}var K=O.ReactCurrentOwner,vr={key:!0,ref:!0,__self:!0,__source:!0},Ae,Ie,ue;ue={};function pr(e){if(Z.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function yr(e){if(Z.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function gr(e,r){if(typeof e.ref=="string"&&K.current&&r&&K.current.stateNode!==r){var n=j(K.current.type);ue[n]||(R('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',j(K.current.type),e.ref),ue[n]=!0)}}function hr(e,r){{var n=function(){Ae||(Ae=!0,R("%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 Er(e,r){{var n=function(){Ie||(Ie=!0,R("%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 mr=function(e,r,n,t,s,f,u){var i={$$typeof:o,type:e,key:r,ref:n,props:u,_owner:f};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:t}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function Rr(e,r,n,t,s){{var f,u={},i=null,T=null;n!==void 0&&(Fe(n),i=""+n),yr(r)&&(Fe(r.key),i=""+r.key),pr(r)&&(T=r.ref,gr(r,s));for(f in r)Z.call(r,f)&&!vr.hasOwnProperty(f)&&(u[f]=r[f]);if(e&&e.defaultProps){var g=e.defaultProps;for(f in g)u[f]===void 0&&(u[f]=g[f])}if(i||T){var E=typeof e=="function"?e.displayName||e.name||"Unknown":e;i&&hr(u,E),T&&Er(u,E)}return mr(e,i,T,s,t,K.current,u)}}var se=O.ReactCurrentOwner,We=O.ReactDebugCurrentFrame;function Q(e){if(e){var r=e._owner,n=X(e.type,e._source,r?r.type:null);We.setExtraStackFrame(n)}else We.setExtraStackFrame(null)}var fe;fe=!1;function ce(e){return typeof e=="object"&&e!==null&&e.$$typeof===o}function Ne(){{if(se.current){var e=j(se.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function _r(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),n=e.lineNumber;return` Check your code at `+r+":"+n+"."}return""}}var Qe={};function br(e){{var r=Ne();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 Ue(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=br(r);if(Qe[n])return;Qe[n]=!0;var t="";e&&e._owner&&e._owner!==se.current&&(t=" It was passed a child from "+j(e._owner.type)+"."),Q(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,t),Q(null)}}function Ye(e,r){{if(typeof e!="object")return;if(ie(e))for(var n=0;n<e.length;n++){var t=e[n];ce(t)&&Ue(t,r)}else if(ce(e))e._store&&(e._store.validated=!0);else if(e){var s=C(e);if(typeof s=="function"&&s!==e.entries)for(var f=s.call(e),u;!(u=f.next()).done;)ce(u.value)&&Ue(u.value,r)}}}function Pr(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===l||r.$$typeof===P))n=r.propTypes;else return;if(n){var t=j(r);fr(n,e.props,"prop",t,e)}else if(r.PropTypes!==void 0&&!fe){fe=!0;var s=j(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",s||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Tr(e){{for(var r=Object.keys(e.props),n=0;n<r.length;n++){var t=r[n];if(t!=="children"&&t!=="key"){Q(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",t),Q(null);break}}e.ref!==null&&(Q(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),Q(null))}}function Le(e,r,n,t,s,f){{var u=nr(e);if(!u){var i="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(i+=" 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 T=_r(s);T?i+=T:i+=Ne();var g;e===null?g="null":ie(e)?g="array":e!==void 0&&e.$$typeof===o?(g="<"+(j(e.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,i)}var E=Rr(e,r,n,s,f);if(E==null)return E;if(u){var w=r.children;if(w!==void 0)if(t)if(ie(w)){for(var U=0;U<w.length;U++)Ye(w[U],e);Object.freeze&&Object.freeze(w)}else R("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 Ye(w,e)}return e===p?Tr(E):Pr(E),E}}function xr(e,r,n){return Le(e,r,n,!0)}function Cr(e,r,n){return Le(e,r,n,!1)}var wr=Cr,Or=xr;L.Fragment=p,L.jsx=wr,L.jsxs=Or}()),L}process.env.NODE_ENV==="production"?re.exports=Me():re.exports=$e();var F=re.exports;const ve=I.createContext({error:({resetErrorBoundary:a})=>F.jsxs("div",{children:[F.jsx("div",{children:"an error occured!"}),F.jsx("button",{onClick:a,children:"resetErrorBoundary"})]}),loading:"loading..."});function q(){return I.useContext(ve)}function Ke({error:a,loading:o,children:c}){return F.jsx(ve.Provider,{value:{error:a,loading:o},children:c})}function qe(a){const o=I.createContext(a);function c(){return I.useContext(o)}function p({extensions:h,children:b}){return F.jsx(o.Provider,{value:h,children:b})}return{useQcExtensions:c,QcExtensionsProvider:p}}const{useQcExtensions:ne,QcExtensionsProvider:Je}=qe({});function pe(a){return typeof a=="function"?o=>a({...o,retry:o.resetErrorBoundary}):()=>a}function ye(a,o=[]){const c=a.length+o.length;return Array.from({length:c},(p,h)=>h%2===0?a[h/2]:o[(h-1)/2])}function Ge(a,...o){return({searchParams:c})=>{const p=o.map(h=>{const[b,y=b]=h.split("!");return c.get(b)||y});return ye(a,p).join("")}}function ze(a,o){if(length<0||typeof length!="number")throw new Error("length must be a positive number");if(!("fetchNextPage"in a))throw new Error("results must be a useInfiniteQuery result");const{status:c,isFetchingNextPage:p,hasNextPage:h,fetchNextPage:b}=a;c==="success"&&!p&&h&&(typeof o=="function"?o(a):o)&&b({cancelRefetch:!1})}function He(a){const{error:o}=q(),c=pe("error"in a?a.error:o);return F.jsx(D.QueryErrorResetBoundary,{children:({reset:p})=>F.jsx(Ve.ErrorBoundary,{onReset:p,fallbackRender:c,children:a.children})})}const B=(a,o)=>typeof a=="function"?a(o):a.map(c=>typeof c=="function"?c(o):c);let W=!1;function Xe(a,o=B){return W=!0,ge(a,o)}function ge(a,o=B){const c=W;W=!1;function p(y){if(!c)return o(y,{});const d=ne();return o(y,(typeof d=="function"?d():d)||{})}function h(y,d){const _={queryKey:p(y),...a,...d};return D.useQuery(_)}function b({path:y,body:d,variables:l,hasLoading:_,loading:m,render:P,children:x,...k}){const{loading:N}=q(),V=[y,d,...Array.isArray(l)?l:[l]].filter(Boolean),C=h(V,{useErrorBoundary:(Ee,M)=>{var J,G;return((G=(J=M==null?void 0:M.data)==null?void 0:J.pages)==null?void 0:G.length)===0},...k}),O=typeof _=="boolean"?_:!0,R=typeof m>"u"?N:m;return O&&C.status==="loading"?R:P?P(C.data,C):x?x(C.data,C):null}return Object.assign(b,{use:h,useKeyFn:p,keyFn:o,defaultOptions:a,_extensions:c})}function Ze(a,o=B){return W=!0,he(a,o)}function he(a,o=B){const c=W;W=!1;function p(y){if(!c)return o(y,{});const d=ne();return o(y,(typeof d=="function"?d():d)||{})}function h(y,d){const _={queryKey:p(y),...a,...d};return D.useInfiniteQuery(_)}function b({path:y,body:d,variables:l,hasLoading:_,loading:m,render:P,children:x,...k}){const{loading:N}=q(),V=[y,d,...Array.isArray(l)?l:[l]].filter(Boolean),C=h(V,{useErrorBoundary:!0,...k}),O=typeof _=="boolean"?_:!0,R=typeof m>"u"?N:m;return O&&C.status==="loading"?R:P?P(C.data,C):x?x(C.data,C):null}return Object.assign(b,{use:h,useKeyFn:p,keyFn:o,defaultOptions:a,_extensions:c})}v.Catch=He,v.QcExtensionsProvider=Je,v.QcProvider=Ke,v.dangerouslyFetchNextPage=ze,v.defaultKeyFn=B,v.errorRender=pe,v.interlace=ye,v.s=Ge,v.useQcDefaults=q,v.useQcExtensions=ne,v.wrapUseInfiniteQuery=he,v.wrapUseInfiniteQueryWithExtensions=Ze,v.wrapUseQuery=ge,v.wrapUseQueryWithExtensions=Xe,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});