@legit-sdk/react 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @legit-sdk/react bundle (ESM)
2
2
  // Generated by esbuild
3
3
 
4
- var O=Object.defineProperty;var s=(r,o)=>O(r,"name",{value:o,configurable:!0});import{createContext as S,useContext as z,useEffect as H,useState as L,useRef as A}from"react";import{openLegitFs as T}from"@legit-sdk/core";import V from"memfs";import{jsx as M}from"react/jsx-runtime";var I=S({legitFs:null,loading:!0,head:null,rollback:s(async()=>{},"rollback")}),x=s(()=>z(I),"useLegitContext"),K={gitRoot:"/"},_=100,J=s(({children:r,config:o=K})=>{let[t,F]=L(!0),[i,f]=L(null),u=A(null),[y,d]=L(),[p,h]=L(null);H(()=>{if(!t)return;s(async()=>{try{let e=await T({storageFs:V,gitRoot:o.gitRoot,serverUrl:o.serverUrl,publicKey:o.publicKey});e&&f(e)}catch(e){d(e)}},"init")(),F(!1)},[]),H(()=>{if(!i)return;window.legitFs=i;let l=setInterval(async()=>{let e=await i.getCurrentBranch();try{let c=await i.promises.readFile(`/.legit/branches/${e}/.legit/head`,"utf8");c!==u.current&&(u.current=c,h(c))}catch{}},_);return()=>{clearInterval(l)}},[i]);let w=s(async l=>{if(!i){console.error("No legitFs instance available");return}try{let e=await i.getCurrentBranch();await i.promises.writeFile(`/.legit/branches/${e}/.legit/head`,l,"utf8")}catch(e){d(e)}},"rollback");return M(I.Provider,{value:{legitFs:i,loading:i===null,head:p,rollback:w,error:y},children:r})},"LegitProvider");import{useEffect as U,useState as m,useRef as P,useCallback as $,useMemo as W}from"react";function q(r,o){let{legitFs:t,error:F,head:i}=x(),[f,u]=m(null),[y,d]=m([]),[p,h]=m(!0),[w,l]=m(),e=P(null),c=P(!1),C=P(!1);U(()=>{if(!t)return;let n=!1;return s(async()=>{h(!0);try{let g=await t.getCurrentBranch(),D=`/.legit/branches/${g}${r}`,N=`/.legit/branches/${g}/.legit/history`,v=await t.promises.readFile(D,"utf8"),k=await t.promises.readFile(N,"utf8").catch(()=>"");if(n)return;let E=[],b=k;b&&(E=JSON.parse(b)),e.current===v&&(e.current=null),u(v),d(E),l(void 0)}catch(g){g?.code!=="ENOENT"?l(g):(u(null),d([]))}finally{n||h(!1)}},"load")(),()=>{n=!0}},[t,r,i]);let R=$(async n=>{if(t)try{e.current=n;let a=await t.getCurrentBranch();await t.promises.writeFile(`/.legit/branches/${a}${r}`,n,"utf8"),u(n)}catch(a){throw e.current=null,l(a),a}},[t,r]);U(()=>{c.current||C.current||!p&&f===null&&t&&o?.initialData&&(C.current=!0,c.current=!0,s(async()=>{try{await R(o.initialData)}catch(a){console.error("Failed to initialize file:",a),c.current=!1}finally{C.current=!1}},"initialize")())},[p,f,t,o?.initialData,R]);let B=$(async n=>{if(!t)return"";try{let a=r.startsWith("/")?r.slice(1):r;return await t.promises.readFile(`/.legit/commits/${n.slice(0,2)}/${n.slice(2)}/${a}`,"utf8")}catch{return""}},[t,r]);return{data:f,setData:R,history:W(()=>y,[y]),getPastState:B,loading:p,error:w??F,legitFs:t}}s(q,"useLegitFile");export{J as LegitProvider,x as useLegitContext,q as useLegitFile};
4
+ var A=Object.defineProperty;var o=(r,n)=>A(r,"name",{value:n,configurable:!0});import{createContext as O,useContext as S,useEffect as H,useState as L,useRef as T}from"react";import{openLegitFs as z}from"@legit-sdk/core";import K from"memfs";import{jsx as M}from"react/jsx-runtime";var I=O({legitFs:null,loading:!0,head:null,rollback:o(async()=>{},"rollback")}),x=o(()=>S(I),"useLegitContext"),V={gitRoot:"/"},_=100,J=o(({children:r,config:n=V})=>{let[t,F]=L(!0),[i,f]=L(null),u=T(null),[y,d]=L(),[p,h]=L(null);H(()=>{if(!t)return;o(async()=>{try{let e=await z({storageFs:K,gitRoot:n.gitRoot,serverUrl:n.serverUrl,publicKey:n.publicKey});n.publicKey&&(await e.auth.addAccessToken(n.publicKey),e.sync.start()),e&&f(e)}catch(e){d(e)}},"init")(),F(!1)},[]),H(()=>{if(!i)return;window.legitFs=i;let l=setInterval(async()=>{let e=await i.getCurrentBranch();try{let c=await i.promises.readFile(`/.legit/branches/${e}/.legit/head`,"utf8");c!==u.current&&(u.current=c,h(c))}catch{}},_);return()=>{clearInterval(l)}},[i]);let w=o(async l=>{if(!i){console.error("No legitFs instance available");return}try{let e=await i.getCurrentBranch();await i.promises.writeFile(`/.legit/branches/${e}/.legit/head`,l,"utf8")}catch(e){d(e)}},"rollback");return M(I.Provider,{value:{legitFs:i,loading:i===null,head:p,rollback:w,error:y},children:r})},"LegitProvider");import{useEffect as U,useState as m,useRef as P,useCallback as $,useMemo as W}from"react";function q(r,n){let{legitFs:t,error:F,head:i}=x(),[f,u]=m(null),[y,d]=m([]),[p,h]=m(!0),[w,l]=m(),e=P(null),c=P(!1),C=P(!1);U(()=>{if(!t)return;let s=!1;return o(async()=>{h(!0);try{let g=await t.getCurrentBranch(),D=`/.legit/branches/${g}${r}`,k=`/.legit/branches/${g}/.legit/history`,v=await t.promises.readFile(D,"utf8"),N=await t.promises.readFile(k,"utf8").catch(()=>"");if(s)return;let b=[],E=N;E&&(b=JSON.parse(E)),e.current===v&&(e.current=null),u(v),d(b),l(void 0)}catch(g){g?.code!=="ENOENT"?l(g):(u(null),d([]))}finally{s||h(!1)}},"load")(),()=>{s=!0}},[t,r,i]);let R=$(async s=>{if(t)try{e.current=s;let a=await t.getCurrentBranch();await t.promises.writeFile(`/.legit/branches/${a}${r}`,s,"utf8"),u(s)}catch(a){throw e.current=null,l(a),a}},[t,r]);U(()=>{c.current||C.current||!p&&f===null&&t&&n?.initialData&&(C.current=!0,c.current=!0,o(async()=>{try{await R(n.initialData)}catch(a){console.error("Failed to initialize file:",a),c.current=!1}finally{C.current=!1}},"initialize")())},[p,f,t,n?.initialData,R]);let B=$(async s=>{if(!t)return"";try{let a=r.startsWith("/")?r.slice(1):r;return await t.promises.readFile(`/.legit/commits/${s.slice(0,2)}/${s.slice(2)}/${a}`,"utf8")}catch{return""}},[t,r]);return{data:f,setData:R,history:W(()=>y,[y]),getPastState:B,loading:p,error:w??F,legitFs:t}}o(q,"useLegitFile");export{J as LegitProvider,x as useLegitContext,q as useLegitFile};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legit-sdk/react",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "React wrapper for @legit-sdk/core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "vitest": "^3.1.1"
36
36
  },
37
37
  "dependencies": {
38
- "@legit-sdk/core": "0.2.1"
38
+ "@legit-sdk/core": "0.2.2"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"