mtxuilib 0.0.504 → 0.0.505
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{Fragment as
|
|
1
|
+
"use client";import{Fragment as g,jsx as i}from"react/jsx-runtime";import{createContext as m,useCallback as k,useContext as h,useMemo as o,useState as v}from"react";import{getCookie as w}from"gomtm/clientlib";import{ExtKey_Hostname as c,ExtKey_SelfBackend as u,ExtKey_mtmaccessToken as p,ExtKey_mtmbackend as y,MtM_TOKEN_NAME as d}from"gomtm/consts";import{MtReactQueryProvider as C}from"gomtm/providers/ReactQueryProvider";const a=m(void 0);function b(t){const{children:n,initExtKv:e}=t,r=o(()=>e[u],[e]),l=o(()=>e[y],[e]),f=o(()=>e[c],[e]),x=o(()=>e[p],[e]);return i(g,{children:i(a.Provider,{value:{extKv:e,token:x,hostname:f,backendUrl:l,trpcBackendUrl:r},children:i(C,{children:n})})})}function s(){const t=h(a);if(t===void 0)throw new Error("useTrpcApp must be used within a TrpcAppProvider");return t}const U=()=>{const{backendUrl:t}=s();return t},E=()=>{const{hostname:t}=s();return t||window.location.host},_=()=>{const t=E(),{token:n}=s();return k(r=>{switch(r){case c:return t;case p:return n;case u:return;default:throw new Error(`extinfo key error: ${r}`)}},[t,n])},B=()=>{const[t]=v(typeof window!="undefined"?w(d):"");return{token:t||"",setToken:n=>{typeof window!="undefined"&&(document.cookie=`${d}=${n}`)}}};export{b as TrpcAppProvider,_ as useExtInfo,E as useHostname,U as useMtmBackendUrl,B as useToken,s as useTrpcApp};
|