@blac/react 0.0.54 → 0.0.56
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.
- package/externalBlocStore.d.ts +1 -1
- package/index.cjs.js +1 -1
- package/index.cjs.js.map +1 -1
- package/index.es.js +44 -43
- package/index.es.js.map +1 -1
- package/package.json +4 -3
package/externalBlocStore.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export interface ExternalStore<B extends BlocGeneric<any, any>, S extends BlocSt
|
|
|
5
5
|
getSnapshot: () => S;
|
|
6
6
|
getServerSnapshot?: () => S;
|
|
7
7
|
}
|
|
8
|
-
declare const externalBlocStore: <B extends BlocGeneric<any, any>, S extends BlocState<B>>(bloc: B, dependencyArray: BlocHookDependencyArrayFn<InstanceType<any
|
|
8
|
+
declare const externalBlocStore: <B extends BlocGeneric<any, any>, S extends BlocState<B>>(bloc: B, dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>, rid: string) => ExternalStore<B, S>;
|
|
9
9
|
export default externalBlocStore;
|
package/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("blac"),r=require("react"),h=(t,s,d)=>({subscribe:c=>{const o=t._observer.subscribe({fn:()=>{try{c(Object.freeze(t.state))}catch(f){console.error({e:f,bloc:t,dependencyArray:s})}},dependencyArray:s,id:d});return()=>{o()}},getSnapshot:()=>Object.freeze(t.state),getServerSnapshot:()=>Object.freeze(t.state)}),E=t=>[t];class O{static useBloc(s,d){let{dependencySelector:c,id:o,props:f}=d??{};const y=r.useId(),u=r.useRef(new Set),a=r.useRef(new Set),p=new Set,S=r.useRef(!1);s.isolated&&(o=y);const l=g.Blac.getInstance().getBloc(s,{id:o,props:f,reconnect:!1});if(!l)throw new Error(`useBloc: could not resolve: ${s.name||s}`);const j=(e,n)=>{if(c)return c(e,n);if(typeof e!="object")return E(e);const B=[];for(const b of u.current)b in e&&B.push(e[b]);return B},{subscribe:v,getSnapshot:I,getServerSnapshot:m}=r.useMemo(()=>h(l,j,y),[l._createdAt]),i=r.useSyncExternalStore(v,I,m),x=r.useMemo(()=>{try{if(typeof i=="object")return new Proxy(i,{get(e,n){return u.current.add(n),a.current.add(n),S.current=!0,Reflect.get(e,n)}})}catch(e){g.Blac.instance.log("useBloc Error",e)}return i},[i,u,a]);return r.useLayoutEffect(()=>(u.current=new Set(a.current),()=>{setTimeout(()=>{S.current&&(a.current.clear(),S.current=!1)})}),[p]),[x,l]}}const R=O.useBloc;exports.externalBlocStore=h;exports.useBloc=R;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n rid: string,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc._observer.subscribe({\n fn: () => {\n try {\n listener(Object.freeze(bloc.state));\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n id: rid,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => Object.freeze(bloc.state),\n getServerSnapshot: (): S => Object.freeze(bloc.state),\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocBaseAbstract,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n BlocState,\n InferPropsFromGeneric,\n} from 'blac';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport externalBlocStore from './externalBlocStore';\n\ntype HookTypes<B extends BlocConstructor<BlocGeneric>> = [\n BlocState<InstanceType<B>>,\n InstanceType<B>,\n];\n\nexport interface BlocHookOptions<B extends BlocGeneric<any, any>> {\n id?: string;\n dependencySelector?: BlocHookDependencyArrayFn<B>;\n props?: InferPropsFromGeneric<B>;\n}\n\nconst defaultDependencySelector: BlocHookDependencyArrayFn<any> = (s) => [s];\n\nexport class UseBlocClass {\n static useBloc<\n B extends BlocConstructor<BlocGeneric>,\n O extends BlocHookOptions<InstanceType<B>>,\n >(bloc: B, options?: O): HookTypes<B> {\n let { dependencySelector, id: blocId, props } = options ?? {};\n const rid = useId();\n const usedKeys = useRef<Set<string>>(new Set());\n const instanceKeys = useRef<Set<string>>(new Set());\n const renderInstance = new Set();\n const shouldClear = useRef(false);\n\n const base = bloc as unknown as BlocBaseAbstract;\n const isIsolated = base.isolated;\n if (isIsolated) {\n blocId = rid;\n }\n\n const resolvedBloc = Blac.getInstance().getBloc(bloc, {\n id: blocId,\n props: props as any,\n reconnect: false,\n }) as InstanceType<B>;\n\n if (!resolvedBloc) {\n throw new Error(`useBloc: could not resolve: ${bloc.name || bloc}`);\n }\n\n // default options\n const dependencyArray: BlocHookDependencyArrayFn<InstanceType<B>> = (\n newState,\n oldState,\n ) => {\n if (dependencySelector) {\n return dependencySelector(newState, oldState);\n }\n if (typeof newState !== 'object') {\n return defaultDependencySelector(newState, oldState);\n }\n\n const used: string[] = [];\n for (const key of usedKeys.current) {\n if (key in newState) {\n used.push(newState[key as keyof typeof newState]);\n }\n }\n\n return used;\n };\n\n const { subscribe, getSnapshot, getServerSnapshot } = useMemo(\n () => externalBlocStore(resolvedBloc, dependencyArray, rid),\n [resolvedBloc._createdAt],\n );\n\n const state = useSyncExternalStore<BlocState<InstanceType<B>>>(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n const returnState: BlocState<InstanceType<B>> = useMemo(() => {\n try {\n if (typeof state === 'object') {\n return new Proxy(state as any, {\n get(target, prop) {\n usedKeys.current.add(prop as string);\n instanceKeys.current.add(prop as string);\n shouldClear.current = true;\n return Reflect.get(target, prop);\n },\n });\n }\n } catch (error) {\n Blac.instance.log('useBloc Error', error);\n }\n return state;\n }, [state, usedKeys, instanceKeys]);\n\n useLayoutEffect(() => {\n usedKeys.current = new Set(instanceKeys.current);\n\n return () => {\n setTimeout(() => {\n if (shouldClear.current) {\n instanceKeys.current.clear();\n shouldClear.current = false;\n }\n });\n };\n }, [renderInstance]);\n\n return [returnState, resolvedBloc];\n }\n}\n\nconst useBloc = UseBlocClass.useBloc;\n\nexport default useBloc;\n"],"names":["externalBlocStore","bloc","dependencyArray","rid","listener","unSub","e","defaultDependencySelector","s","UseBlocClass","options","dependencySelector","blocId","props","useId","usedKeys","useRef","instanceKeys","renderInstance","shouldClear","resolvedBloc","Blac","newState","oldState","used","key","subscribe","getSnapshot","getServerSnapshot","useMemo","state","useSyncExternalStore","returnState","target","prop","error","useLayoutEffect","useBloc"],"mappings":"2HAWMA,EAAoB,CAIxBC,EACAC,EAC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Aa,kBAAAC,CAAsB,EAAAC,EAAA,QACpD,IAAM7B,EAAkBoB,EAAclB,EAAiBC,CAAG,EAC1D,CAACiB,EAAa,UAAU,CAAA,EAGpBU,EAAQC,EAAA,qBACZL,EACAC,EACAC,CAAA,EAGII,EAA0CH,EAAAA,QAAQ,IAAM,CACxD,GAAA,CACE,GAAA,OAAOC,GAAU,SACZ,OAAA,IAAI,MAAMA,EAAc,CAC7B,IAAIG,EAAQC,EAAM,CACP,OAAAnB,EAAA,QAAQ,IAAImB,CAAc,EACtBjB,EAAA,QAAQ,IAAIiB,CAAc,EACvCf,EAAY,QAAU,GACf,QAAQ,IAAIc,EAAQC,CAAI,CACjC,CAAA,CACD,QAEIC,EAAO,CACTd,EAAAA,KAAA,SAAS,IAAI,gBAAiBc,CAAK,CAC1C,CACO,OAAAL,CACN,EAAA,CAACA,EAAOf,EAAUE,CAAY,CAAC,EAElCmB,OAAAA,EAAAA,gBAAgB,KACdrB,EAAS,QAAU,IAAI,IAAIE,EAAa,OAAO,EAExC,IAAM,CACX,WAAW,IAAM,CACXE,EAAY,UACdF,EAAa,QAAQ,QACrBE,EAAY,QAAU,GACxB,CACD,CAAA,GAEF,CAACD,CAAc,CAAC,EAEZ,CAACc,EAAaZ,CAAY,CACnC,CACF,CAEA,MAAMiB,EAAU5B,EAAa"}
|
package/index.es.js
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
import { Blac as
|
|
2
|
-
import { useId as
|
|
3
|
-
const
|
|
4
|
-
subscribe: (
|
|
5
|
-
const
|
|
1
|
+
import { Blac as b } from "blac";
|
|
2
|
+
import { useId as E, useRef as S, useMemo as g, useSyncExternalStore as w, useLayoutEffect as z } from "react";
|
|
3
|
+
const O = (t, r, f) => ({
|
|
4
|
+
subscribe: (n) => {
|
|
5
|
+
const c = t._observer.subscribe({
|
|
6
6
|
fn: () => {
|
|
7
7
|
try {
|
|
8
|
-
|
|
9
|
-
} catch (
|
|
8
|
+
n(Object.freeze(t.state));
|
|
9
|
+
} catch (d) {
|
|
10
10
|
console.error({
|
|
11
|
-
e:
|
|
11
|
+
e: d,
|
|
12
12
|
bloc: t,
|
|
13
13
|
dependencyArray: r
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
dependencyArray: r
|
|
17
|
+
dependencyArray: r,
|
|
18
|
+
id: f
|
|
18
19
|
});
|
|
19
20
|
return () => {
|
|
20
|
-
|
|
21
|
+
c();
|
|
21
22
|
};
|
|
22
23
|
},
|
|
23
|
-
getSnapshot: () => t.state,
|
|
24
|
-
getServerSnapshot: () => t.state
|
|
25
|
-
}),
|
|
26
|
-
class
|
|
27
|
-
static useBloc(r,
|
|
28
|
-
let { dependencySelector: n, id:
|
|
29
|
-
const
|
|
30
|
-
r.isolated && (
|
|
31
|
-
const a =
|
|
32
|
-
id:
|
|
33
|
-
props:
|
|
24
|
+
getSnapshot: () => Object.freeze(t.state),
|
|
25
|
+
getServerSnapshot: () => Object.freeze(t.state)
|
|
26
|
+
}), C = (t) => [t];
|
|
27
|
+
class K {
|
|
28
|
+
static useBloc(r, f) {
|
|
29
|
+
let { dependencySelector: n, id: c, props: d } = f ?? {};
|
|
30
|
+
const y = E(), o = S(/* @__PURE__ */ new Set()), u = S(/* @__PURE__ */ new Set()), h = /* @__PURE__ */ new Set(), i = S(!1);
|
|
31
|
+
r.isolated && (c = y);
|
|
32
|
+
const a = b.getInstance().getBloc(r, {
|
|
33
|
+
id: c,
|
|
34
|
+
props: d,
|
|
34
35
|
reconnect: !1
|
|
35
36
|
});
|
|
36
37
|
if (!a)
|
|
37
38
|
throw new Error(`useBloc: could not resolve: ${r.name || r}`);
|
|
38
|
-
const
|
|
39
|
+
const m = (e, s) => {
|
|
39
40
|
if (n)
|
|
40
41
|
return n(e, s);
|
|
41
42
|
if (typeof e != "object")
|
|
42
|
-
return
|
|
43
|
-
const
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
}, { subscribe:
|
|
48
|
-
() =>
|
|
49
|
-
[a.
|
|
50
|
-
), l =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
),
|
|
43
|
+
return C(e);
|
|
44
|
+
const p = [];
|
|
45
|
+
for (const B of o.current)
|
|
46
|
+
B in e && p.push(e[B]);
|
|
47
|
+
return p;
|
|
48
|
+
}, { subscribe: I, getSnapshot: j, getServerSnapshot: v } = g(
|
|
49
|
+
() => O(a, m, y),
|
|
50
|
+
[a._createdAt]
|
|
51
|
+
), l = w(
|
|
52
|
+
I,
|
|
53
|
+
j,
|
|
54
|
+
v
|
|
55
|
+
), x = g(() => {
|
|
55
56
|
try {
|
|
56
57
|
if (typeof l == "object")
|
|
57
58
|
return new Proxy(l, {
|
|
58
59
|
get(e, s) {
|
|
59
|
-
return
|
|
60
|
+
return o.current.add(s), u.current.add(s), i.current = !0, Reflect.get(e, s);
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
} catch (e) {
|
|
63
|
-
|
|
64
|
+
b.instance.log("useBloc Error", e);
|
|
64
65
|
}
|
|
65
66
|
return l;
|
|
66
|
-
}, [l,
|
|
67
|
-
return
|
|
67
|
+
}, [l, o, u]);
|
|
68
|
+
return z(() => (o.current = new Set(u.current), () => {
|
|
68
69
|
setTimeout(() => {
|
|
69
70
|
i.current && (u.current.clear(), i.current = !1);
|
|
70
71
|
});
|
|
71
|
-
}), [
|
|
72
|
+
}), [h]), [x, a];
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
const
|
|
75
|
+
const D = K.useBloc;
|
|
75
76
|
export {
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
O as externalBlocStore,
|
|
78
|
+
D as useBloc
|
|
78
79
|
};
|
|
79
80
|
//# sourceMappingURL=index.es.js.map
|
package/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n rid: string,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc._observer.subscribe({\n fn: () => {\n try {\n listener(Object.freeze(bloc.state));\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n id: rid,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => Object.freeze(bloc.state),\n getServerSnapshot: (): S => Object.freeze(bloc.state),\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocBaseAbstract,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n BlocState,\n InferPropsFromGeneric,\n} from 'blac';\nimport {\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport externalBlocStore from './externalBlocStore';\n\ntype HookTypes<B extends BlocConstructor<BlocGeneric>> = [\n BlocState<InstanceType<B>>,\n InstanceType<B>,\n];\n\nexport interface BlocHookOptions<B extends BlocGeneric<any, any>> {\n id?: string;\n dependencySelector?: BlocHookDependencyArrayFn<B>;\n props?: InferPropsFromGeneric<B>;\n}\n\nconst defaultDependencySelector: BlocHookDependencyArrayFn<any> = (s) => [s];\n\nexport class UseBlocClass {\n static useBloc<\n B extends BlocConstructor<BlocGeneric>,\n O extends BlocHookOptions<InstanceType<B>>,\n >(bloc: B, options?: O): HookTypes<B> {\n let { dependencySelector, id: blocId, props } = options ?? {};\n const rid = useId();\n const usedKeys = useRef<Set<string>>(new Set());\n const instanceKeys = useRef<Set<string>>(new Set());\n const renderInstance = new Set();\n const shouldClear = useRef(false);\n\n const base = bloc as unknown as BlocBaseAbstract;\n const isIsolated = base.isolated;\n if (isIsolated) {\n blocId = rid;\n }\n\n const resolvedBloc = Blac.getInstance().getBloc(bloc, {\n id: blocId,\n props: props as any,\n reconnect: false,\n }) as InstanceType<B>;\n\n if (!resolvedBloc) {\n throw new Error(`useBloc: could not resolve: ${bloc.name || bloc}`);\n }\n\n // default options\n const dependencyArray: BlocHookDependencyArrayFn<InstanceType<B>> = (\n newState,\n oldState,\n ) => {\n if (dependencySelector) {\n return dependencySelector(newState, oldState);\n }\n if (typeof newState !== 'object') {\n return defaultDependencySelector(newState, oldState);\n }\n\n const used: string[] = [];\n for (const key of usedKeys.current) {\n if (key in newState) {\n used.push(newState[key as keyof typeof newState]);\n }\n }\n\n return used;\n };\n\n const { subscribe, getSnapshot, getServerSnapshot } = useMemo(\n () => externalBlocStore(resolvedBloc, dependencyArray, rid),\n [resolvedBloc._createdAt],\n );\n\n const state = useSyncExternalStore<BlocState<InstanceType<B>>>(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n const returnState: BlocState<InstanceType<B>> = useMemo(() => {\n try {\n if (typeof state === 'object') {\n return new Proxy(state as any, {\n get(target, prop) {\n usedKeys.current.add(prop as string);\n instanceKeys.current.add(prop as string);\n shouldClear.current = true;\n return Reflect.get(target, prop);\n },\n });\n }\n } catch (error) {\n Blac.instance.log('useBloc Error', error);\n }\n return state;\n }, [state, usedKeys, instanceKeys]);\n\n useLayoutEffect(() => {\n usedKeys.current = new Set(instanceKeys.current);\n\n return () => {\n setTimeout(() => {\n if (shouldClear.current) {\n instanceKeys.current.clear();\n shouldClear.current = false;\n }\n });\n };\n }, [renderInstance]);\n\n return [returnState, resolvedBloc];\n }\n}\n\nconst useBloc = UseBlocClass.useBloc;\n\nexport default useBloc;\n"],"names":["externalBlocStore","bloc","dependencyArray","rid","listener","unSub","e","defaultDependencySelector","s","UseBlocClass","options","dependencySelector","blocId","props","useId","usedKeys","useRef","instanceKeys","renderInstance","shouldClear","resolvedBloc","Blac","newState","oldState","used","key","subscribe","getSnapshot","getServerSnapshot","useMemo","state","useSyncExternalStore","returnState","target","prop","error","useLayoutEffect","useBloc"],"mappings":";;AAWA,MAAMA,IAAoB,CAIxBC,GACAC,GACAC,OAEO;AAAA,EACL,WAAW,CAACC,MAAiC;AACrC,UAAAC,IAAQJ,EAAK,UAAU,UAAU;AAAA,MACrC,IAAI,MAAM;AACJ,YAAA;AACF,UAAAG,EAAS,OAAO,OAAOH,EAAK,KAAK,CAAC;AAAA,iBAC3BK,GAAG;AACV,kBAAQ,MAAM;AAAA,YACZ,GAAAA;AAAA,YACA,MAAAL;AAAA,YACA,iBAAAC;AAAA,UAAA,CACD;AAAA,QACH;AAAA,MACF;AAAA,MACA,iBAAAA;AAAA,MACA,IAAIC;AAAA,IAAA,CACL;AAED,WAAO,MAAM;AACL,MAAAE;IAAA;AAAA,EAEV;AAAA,EACA,aAAa,MAAS,OAAO,OAAOJ,EAAK,KAAK;AAAA,EAC9C,mBAAmB,MAAS,OAAO,OAAOA,EAAK,KAAK;AAAA,ICXlDM,IAA4D,CAACC,MAAM,CAACA,CAAC;AAEpE,MAAMC,EAAa;AAAA,EACxB,OAAO,QAGLR,GAASS,GAA2B;AACp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A,UAAA,CACD;AAAA,eAEIC,GAAO;AACT,QAAAd,EAAA,SAAS,IAAI,iBAAiBc,CAAK;AAAA,MAC1C;AACO,aAAAL;AAAA,IACN,GAAA,CAACA,GAAOf,GAAUE,CAAY,CAAC;AAElC,WAAAmB,EAAgB,OACdrB,EAAS,UAAU,IAAI,IAAIE,EAAa,OAAO,GAExC,MAAM;AACX,iBAAW,MAAM;AACf,QAAIE,EAAY,YACdF,EAAa,QAAQ,SACrBE,EAAY,UAAU;AAAA,MACxB,CACD;AAAA,IAAA,IAEF,CAACD,CAAc,CAAC,GAEZ,CAACc,GAAaZ,CAAY;AAAA,EACnC;AACF;AAEA,MAAMiB,IAAU5B,EAAa;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blac/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.56",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "index.cjs.js",
|
|
6
6
|
"module": "index.es.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"pub": "npm run build && npm publish"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"blac": "*",
|
|
31
|
+
"react": "^18.3.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@testing-library/dom": "^10.1.0",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"eslint": "^9.5.0",
|
|
44
44
|
"jsdom": "^24.1.0",
|
|
45
45
|
"prettier": "^3.3.2",
|
|
46
|
+
"react-dom": "^18.3.1",
|
|
46
47
|
"typescript": "^5.4.5",
|
|
47
48
|
"vite-plugin-dts": "^3.9.1",
|
|
48
49
|
"vitest": "^1.6.0"
|