mtxuilib 0.0.516 → 0.0.518

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.
@@ -18,7 +18,7 @@ export declare const useMtmBackendUrl: () => string | null | undefined;
18
18
  export declare const useHostname: () => string;
19
19
  export declare const useExtInfo: () => (key: string) => string | null | undefined;
20
20
  export declare const useToken: () => {
21
- token: any;
21
+ token: string;
22
22
  setToken: (newToken: string) => void;
23
23
  };
24
24
  export {};
@@ -1 +1 @@
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};
1
+ "use client";import{Fragment as h,jsx as c}from"react/jsx-runtime";import{createContext as p,useCallback as u,useContext as d,useState as a}from"react";import{ExtKey_Hostname as l,ExtKey_SelfBackend as f,ExtKey_mtmaccessToken as x,MtM_TOKEN_NAME as i}from"../../consts";import{getCookie as k}from"../clientlib/clientlib";const s=p(void 0);function A(t){const{children:e,initExtKv:o}=t;return c(h,{children:c(s.Provider,{value:{extKv:o},children:e})})}function n(){const t=d(s);if(t===void 0)throw new Error("useTrpcApp must be used within a TrpcAppProvider");return t}const E=()=>{const{backendUrl:t}=n();return t},m=()=>{const{hostname:t}=n();return t||window.location.host},y=()=>{const t=m(),{token:e}=n();return u(r=>{switch(r){case l:return t;case x:return e;case f:return;default:throw new Error(`extinfo key error: ${r}`)}},[t,e])},K=()=>{const[t]=a(typeof window!="undefined"?k(i):"");return{token:t||"",setToken:e=>{typeof window!="undefined"&&(document.cookie=`${i}=${e}`)}}};export{A as TrpcAppProvider,y as useExtInfo,m as useHostname,E as useMtmBackendUrl,K as useToken,n as useTrpcApp};