bansa 0.0.23 → 0.0.25
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/.oxfmtrc.jsonc +3 -0
- package/README.ko.md +134 -130
- package/README.md +117 -113
- package/dist/atom.d.mts +83 -0
- package/dist/atom.d.mts.map +1 -0
- package/dist/atom.mjs +349 -0
- package/dist/atom.mjs.map +1 -0
- package/dist/browser/index.d.ts +96 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/react.d.mts +25 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.mjs +33 -0
- package/dist/react.mjs.map +1 -0
- package/dist/utils.d.mts +17 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +68 -0
- package/dist/utils.mjs.map +1 -0
- package/oxlint.config.ts +17 -0
- package/package.json +41 -34
- package/tsconfig.app.json +39 -0
- package/tsconfig.json +29 -18
- package/tsconfig.lib.json +35 -0
- package/dist/atom.d.ts +0 -80
- package/dist/atom.js +0 -419
- package/dist/index.browser.js +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/react.d.ts +0 -15
- package/dist/react.js +0 -40
- package/dist/utils.d.ts +0 -19
- package/dist/utils.js +0 -80
- package/tests/bansa.test.ts +0 -1319
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createScope } from "./atom.mjs";
|
|
2
|
+
import { createContext, use, useContext, useMemo, useSyncExternalStore } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react.tsx
|
|
5
|
+
const ScopeContext = createContext((x) => x);
|
|
6
|
+
const ScopeProvider = ({ value, children }) => {
|
|
7
|
+
const parentScope = value && useContext(ScopeContext);
|
|
8
|
+
const scope = useMemo(() => createScope(parentScope, value), [parentScope]);
|
|
9
|
+
return /* @__PURE__ */ jsx(ScopeContext.Provider, {
|
|
10
|
+
value: scope,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const useAtomValue = (atom) => (atom = useContext(ScopeContext)(atom), useSyncExternalStore((watcher) => atom.watch(watcher), () => {
|
|
15
|
+
try {
|
|
16
|
+
return atom.get();
|
|
17
|
+
} catch (_) {
|
|
18
|
+
if (atom.state.promise) use(Promise.resolve(atom.state.promise));
|
|
19
|
+
throw atom.state.error;
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
const useAtomState = (atom) => (atom = useContext(ScopeContext)(atom), useSyncExternalStore((watcher) => atom.watch(watcher), () => {
|
|
23
|
+
try {
|
|
24
|
+
atom.get();
|
|
25
|
+
} catch (_) {}
|
|
26
|
+
return atom.state;
|
|
27
|
+
}));
|
|
28
|
+
const useScopedAtom = ((atom) => useContext(ScopeContext)(atom));
|
|
29
|
+
const useAtom = (atom) => (atom = useScopedAtom(atom), [useAtomValue(atom), (newState) => atom.set(newState)]);
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ScopeContext, ScopeProvider, useAtom, useAtomState, useAtomValue, useScopedAtom };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import { createContext, use, useContext, useMemo, useSyncExternalStore } from \"react\";\nimport { createScope } from \"./atom.ts\";\nimport type { Atom, AtomScope, AtomValuePair, DerivedAtom, PrimitiveAtom } from \"./atom.ts\";\n\nexport const ScopeContext = createContext<AtomScope>((x) => x as any);\n\nexport const ScopeProvider = ({\n value,\n children,\n}: {\n value?: AtomValuePair<unknown>[];\n children: React.ReactNode;\n}) => {\n const parentScope = value && useContext(ScopeContext);\n const scope = useMemo(() => createScope(parentScope, value), [parentScope]);\n return <ScopeContext.Provider value={scope}>{children}</ScopeContext.Provider>;\n};\n\nexport const useAtomValue = <Value,>(atom: Atom<Value>) => (\n (atom = useContext(ScopeContext)(atom)),\n useSyncExternalStore(\n (watcher) => atom.watch(watcher),\n () => {\n // https://github.com/facebook/react/pull/34032\n try {\n return atom.get();\n } catch (_) {\n if (atom.state.promise) use(Promise.resolve(atom.state.promise));\n throw atom.state.error;\n }\n },\n )\n);\n\nexport const useAtomState = <Value,>(atom: DerivedAtom<Value>) => (\n (atom = useContext(ScopeContext)(atom)),\n useSyncExternalStore(\n (watcher) => atom.watch(watcher),\n () => {\n // avoid https://github.com/facebook/react/issues/31730\n try {\n atom.get();\n } catch (_) {}\n return atom.state;\n },\n )\n);\n\nexport const useScopedAtom = (<Value,>(atom: Atom<Value>) =>\n useContext(ScopeContext)(atom)) as UseScopedAtom;\n\nexport const useAtom = <Value,>(atom: PrimitiveAtom<Value>) => (\n (atom = useScopedAtom(atom)),\n [useAtomValue(atom), (newState: Value) => atom.set(newState)] as const\n);\n\nexport type UseScopedAtom = {\n <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;\n <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;\n <Value>(baseAtom: Atom<Value>): Atom<Value>;\n};\n"],"mappings":";;;;AAIA,MAAa,eAAe,eAA0B,MAAM,EAAS;AAErE,MAAa,iBAAiB,EAC5B,OACA,eAII;CACJ,MAAM,cAAc,SAAS,WAAW,aAAa;CACrD,MAAM,QAAQ,cAAc,YAAY,aAAa,MAAM,EAAE,CAAC,YAAY,CAAC;AAC3E,QAAO,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAQ;EAAiC,CAAA;;AAGhF,MAAa,gBAAwB,UAClC,OAAO,WAAW,aAAa,CAAC,KAAK,EACtC,sBACG,YAAY,KAAK,MAAM,QAAQ,QAC1B;AAEJ,KAAI;AACF,SAAO,KAAK,KAAK;UACV,GAAG;AACV,MAAI,KAAK,MAAM,QAAS,KAAI,QAAQ,QAAQ,KAAK,MAAM,QAAQ,CAAC;AAChE,QAAM,KAAK,MAAM;;EAGtB;AAGH,MAAa,gBAAwB,UAClC,OAAO,WAAW,aAAa,CAAC,KAAK,EACtC,sBACG,YAAY,KAAK,MAAM,QAAQ,QAC1B;AAEJ,KAAI;AACF,OAAK,KAAK;UACH,GAAG;AACZ,QAAO,KAAK;EAEf;AAGH,MAAa,kBAA0B,SACrC,WAAW,aAAa,CAAC,KAAK;AAEhC,MAAa,WAAmB,UAC7B,OAAO,cAAc,KAAK,EAC3B,CAAC,aAAa,KAAK,GAAG,aAAoB,KAAK,IAAI,SAAS,CAAC"}
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Atom, AtomGetter, DerivedAtom, PrimitiveAtom } from "./atom.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.d.ts
|
|
4
|
+
type Atomized<T> = T extends object ? { [K in keyof T]: Atomized<T[K]> } : PrimitiveAtom<T>;
|
|
5
|
+
type CollectedAtoms<T> = T extends Atom<infer U> ? U : T extends object ? { [K in keyof T]: CollectedAtoms<T[K]> } : T;
|
|
6
|
+
type CollectAtom = {
|
|
7
|
+
<Value>(init: AtomGetter<Value>): DerivedAtom<Value>;
|
|
8
|
+
<Value>(init: Value): DerivedAtom<CollectedAtoms<Value>>;
|
|
9
|
+
};
|
|
10
|
+
type RecursiveOptional<T> = T | (T extends object ? { [P in keyof T]: RecursiveOptional<T[P]> } : never);
|
|
11
|
+
declare const atomize: <T>(tree: T) => Atomized<T>;
|
|
12
|
+
declare const collectAtoms: <T>(tree: T, get?: <T_1>(atom: Atom<T_1>) => T_1) => CollectedAtoms<T>;
|
|
13
|
+
declare const setAtoms: <T>(tree: T, values: RecursiveOptional<CollectedAtoms<T>>) => void;
|
|
14
|
+
declare const $$: CollectAtom;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { $$, Atomized, CollectedAtoms, RecursiveOptional, atomize, collectAtoms, setAtoms };
|
|
17
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";;;KAGY,QAAA,MAAc,CAAA,gCAAiC,CAAA,GAAI,QAAA,CAAS,CAAA,CAAE,CAAA,OAAQ,aAAA,CAAc,CAAA;AAAA,KAEpF,cAAA,MACV,CAAA,SAAU,IAAA,YAAgB,CAAA,GAAI,CAAA,gCAAiC,CAAA,GAAI,cAAA,CAAe,CAAA,CAAE,CAAA,OAAQ,CAAA;AAAA,KAEzF,WAAA;EAAA,QACK,IAAA,EAAM,UAAA,CAAW,KAAA,IAAS,WAAA,CAAY,KAAA;EAAA,QACtC,IAAA,EAAM,KAAA,GAAQ,WAAA,CAAY,cAAA,CAAe,KAAA;AAAA;AAAA,KAGvC,iBAAA,MACR,CAAA,IACC,CAAA,gCAEiB,CAAA,GAAI,iBAAA,CAAkB,CAAA,CAAE,CAAA;AAAA,cAajC,OAAA,MAAc,IAAA,EAAM,CAAA,KAAI,QAAA,CAAS,CAAA;AAAA,cASjC,YAAA,MAAmB,IAAA,EAAM,CAAA,EAAG,GAAA,SAAA,IAAA,EADf,IAAA,CAAK,GAAA,MAAK,GAAA,KACqB,cAAA,CAAe,CAAA;AAAA,cAY3D,QAAA,MAAe,IAAA,EAAM,CAAA,EAAG,MAAA,EAAQ,iBAAA,CAAkB,cAAA,CAAe,CAAA;AAAA,cAajE,EAAA,EAAI,WAAA"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { $, isAtom, isPrimitiveAtom } from "./atom.mjs";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const ouroboros = () => ouroboros;
|
|
4
|
+
const toUndefined = () => void 0;
|
|
5
|
+
Object.setPrototypeOf(ouroboros, new Proxy(ouroboros, { get: (_, k) => k === Symbol.toPrimitive ? toUndefined : ouroboros }));
|
|
6
|
+
const atomize = (tree) => {
|
|
7
|
+
if (typeof tree !== "object" || tree === null) return $(tree);
|
|
8
|
+
if (Array.isArray(tree)) return tree.map(atomize);
|
|
9
|
+
const result = Object.create(null);
|
|
10
|
+
for (const k in tree) result[k] = atomize(tree[k]);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
const getAtom = (atom) => atom.get();
|
|
14
|
+
const collectAtoms = (tree, get = getAtom) => {
|
|
15
|
+
const recurse = (t) => {
|
|
16
|
+
if (typeof t !== "object" || t === null) return t;
|
|
17
|
+
if (isAtom(t)) return get(t);
|
|
18
|
+
if (Array.isArray(t)) return t.map(recurse);
|
|
19
|
+
const result = Object.create(null);
|
|
20
|
+
for (const k in t) result[k] = recurse(t[k]);
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
return recurse(tree);
|
|
24
|
+
};
|
|
25
|
+
const setAtoms = (tree, values) => {
|
|
26
|
+
const recurse = (t, v) => {
|
|
27
|
+
if (typeof t === "object" && t !== null) if (isAtom(t)) {
|
|
28
|
+
if (isPrimitiveAtom(t)) t.set(v);
|
|
29
|
+
} else for (const k in v) recurse(t[k], v[k]);
|
|
30
|
+
};
|
|
31
|
+
recurse(tree, values);
|
|
32
|
+
};
|
|
33
|
+
const $$ = (init) => init instanceof Function ? $((get, options) => {
|
|
34
|
+
let promises;
|
|
35
|
+
let error;
|
|
36
|
+
const result = init((atom) => {
|
|
37
|
+
const state = get(atom, false);
|
|
38
|
+
if (state.error) error = state.error;
|
|
39
|
+
else if (state.promise) (promises ||= []).push(state.promise);
|
|
40
|
+
else return state.value;
|
|
41
|
+
return ouroboros;
|
|
42
|
+
}, options);
|
|
43
|
+
if (error) throw error;
|
|
44
|
+
if (promises) throw Promise.all(promises);
|
|
45
|
+
return result;
|
|
46
|
+
}, { equals: shallowEquals }) : $$((get) => collectAtoms(init, get));
|
|
47
|
+
const shallowEquals = (a, b) => {
|
|
48
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
|
|
49
|
+
const c = a.constructor;
|
|
50
|
+
if (c !== b.constructor) return false;
|
|
51
|
+
if (c === Array) {
|
|
52
|
+
let i = a.length;
|
|
53
|
+
if (i !== b.length) return false;
|
|
54
|
+
while ((i = i - 1 | 0) >= 0) if (!Object.is(a[i], b[i])) return false;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
let n = 0;
|
|
58
|
+
for (const k in a) {
|
|
59
|
+
if (!(k in b && Object.is(a[k], b[k]))) return false;
|
|
60
|
+
n = n + 1 | 0;
|
|
61
|
+
}
|
|
62
|
+
for (const _ in b) if ((n = n - 1 | 0) < 0) return false;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { $$, atomize, collectAtoms, setAtoms };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { $, isAtom, isPrimitiveAtom } from \"./atom.ts\";\nimport type { PrimitiveAtom, Atom, AtomGetter, DerivedAtom } from \"./atom.ts\";\n\nexport type Atomized<T> = T extends object ? { [K in keyof T]: Atomized<T[K]> } : PrimitiveAtom<T>;\n\nexport type CollectedAtoms<T> =\n T extends Atom<infer U> ? U : T extends object ? { [K in keyof T]: CollectedAtoms<T[K]> } : T;\n\ntype CollectAtom = {\n <Value>(init: AtomGetter<Value>): DerivedAtom<Value>;\n <Value>(init: Value): DerivedAtom<CollectedAtoms<Value>>;\n};\n\nexport type RecursiveOptional<T> =\n | T\n | (T extends object\n ? {\n [P in keyof T]: RecursiveOptional<T[P]>;\n }\n : never);\n\nconst ouroboros: any = () => ouroboros;\nconst toUndefined = () => undefined;\nObject.setPrototypeOf(\n ouroboros,\n new Proxy(ouroboros, {\n get: (_, k) => (k === Symbol.toPrimitive ? toUndefined : ouroboros),\n }),\n);\n\nexport const atomize = <T>(tree: T): Atomized<T> => {\n if (typeof tree !== \"object\" || tree === null) return $(tree) as any;\n if (Array.isArray(tree)) return tree.map(atomize) as any;\n const result = Object.create(null);\n for (const k in tree) result[k] = atomize(tree[k]);\n return result;\n};\n\nconst getAtom = <T>(atom: Atom<T>): T => atom.get();\nexport const collectAtoms = <T>(tree: T, get = getAtom): CollectedAtoms<T> => {\n const recurse = <T>(t: T): CollectedAtoms<T> => {\n if (typeof t !== \"object\" || t === null) return t as any;\n if (isAtom(t)) return get(t) as any;\n if (Array.isArray(t)) return t.map(recurse) as any;\n const result = Object.create(null);\n for (const k in t) result[k] = recurse(t[k] as any);\n return result;\n };\n return recurse(tree);\n};\n\nexport const setAtoms = <T>(tree: T, values: RecursiveOptional<CollectedAtoms<T>>): void => {\n const recurse = (t: any, v: any) => {\n if (typeof t === \"object\" && t !== null) {\n if (isAtom(t)) {\n if (isPrimitiveAtom(t)) t.set(v);\n } else {\n for (const k in v) recurse(t[k], v[k]);\n }\n }\n };\n recurse(tree, values);\n};\n\nexport const $$: CollectAtom = <Value>(init: Value | AtomGetter<Value>) =>\n init instanceof Function\n ? $(\n (get, options) => {\n let promises: PromiseLike<unknown>[] | undefined;\n let error: unknown;\n const result = init((atom) => {\n const state = get(atom, false);\n if (state.error) error = state.error;\n else if (state.promise) (promises ||= []).push(state.promise);\n else return state.value;\n return ouroboros;\n }, options);\n if (error) throw error;\n if (promises) throw Promise.all(promises);\n return result;\n },\n {\n equals: shallowEquals,\n },\n )\n : $$((get) => collectAtoms(init, get));\n\nconst shallowEquals = (a: any, b: any): boolean => {\n if (typeof a !== \"object\" || typeof b !== \"object\" || !a || !b) return false;\n const c = a.constructor;\n if (c !== b.constructor) return false;\n\n if (c === Array) {\n let i = a.length;\n if (i !== b.length) return false;\n while ((i = (i - 1) | 0) >= 0) if (!Object.is(a[i], b[i])) return false;\n return true;\n }\n\n let n = 0;\n for (const k in a) {\n if (!(k in b && Object.is(a[k], b[k]))) return false;\n n = (n + 1) | 0;\n }\n for (const _ in b) if ((n = (n - 1) | 0) < 0) return false;\n return true;\n};\n"],"mappings":";;AAqBA,MAAM,kBAAuB;AAC7B,MAAM,oBAAoB,KAAA;AAC1B,OAAO,eACL,WACA,IAAI,MAAM,WAAW,EACnB,MAAM,GAAG,MAAO,MAAM,OAAO,cAAc,cAAc,WAC1D,CAAC,CACH;AAED,MAAa,WAAc,SAAyB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO,EAAE,KAAK;AAC7D,KAAI,MAAM,QAAQ,KAAK,CAAE,QAAO,KAAK,IAAI,QAAQ;CACjD,MAAM,SAAS,OAAO,OAAO,KAAK;AAClC,MAAK,MAAM,KAAK,KAAM,QAAO,KAAK,QAAQ,KAAK,GAAG;AAClD,QAAO;;AAGT,MAAM,WAAc,SAAqB,KAAK,KAAK;AACnD,MAAa,gBAAmB,MAAS,MAAM,YAA+B;CAC5E,MAAM,WAAc,MAA4B;AAC9C,MAAI,OAAO,MAAM,YAAY,MAAM,KAAM,QAAO;AAChD,MAAI,OAAO,EAAE,CAAE,QAAO,IAAI,EAAE;AAC5B,MAAI,MAAM,QAAQ,EAAE,CAAE,QAAO,EAAE,IAAI,QAAQ;EAC3C,MAAM,SAAS,OAAO,OAAO,KAAK;AAClC,OAAK,MAAM,KAAK,EAAG,QAAO,KAAK,QAAQ,EAAE,GAAU;AACnD,SAAO;;AAET,QAAO,QAAQ,KAAK;;AAGtB,MAAa,YAAe,MAAS,WAAuD;CAC1F,MAAM,WAAW,GAAQ,MAAW;AAClC,MAAI,OAAO,MAAM,YAAY,MAAM,KACjC,KAAI,OAAO,EAAE;OACP,gBAAgB,EAAE,CAAE,GAAE,IAAI,EAAE;QAEhC,MAAK,MAAM,KAAK,EAAG,SAAQ,EAAE,IAAI,EAAE,GAAG;;AAI5C,SAAQ,MAAM,OAAO;;AAGvB,MAAa,MAA0B,SACrC,gBAAgB,WACZ,GACG,KAAK,YAAY;CAChB,IAAI;CACJ,IAAI;CACJ,MAAM,SAAS,MAAM,SAAS;EAC5B,MAAM,QAAQ,IAAI,MAAM,MAAM;AAC9B,MAAI,MAAM,MAAO,SAAQ,MAAM;WACtB,MAAM,QAAS,EAAC,aAAa,EAAE,EAAE,KAAK,MAAM,QAAQ;MACxD,QAAO,MAAM;AAClB,SAAO;IACN,QAAQ;AACX,KAAI,MAAO,OAAM;AACjB,KAAI,SAAU,OAAM,QAAQ,IAAI,SAAS;AACzC,QAAO;GAET,EACE,QAAQ,eACT,CACF,GACD,IAAI,QAAQ,aAAa,MAAM,IAAI,CAAC;AAE1C,MAAM,iBAAiB,GAAQ,MAAoB;AACjD,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,CAAC,KAAK,CAAC,EAAG,QAAO;CACvE,MAAM,IAAI,EAAE;AACZ,KAAI,MAAM,EAAE,YAAa,QAAO;AAEhC,KAAI,MAAM,OAAO;EACf,IAAI,IAAI,EAAE;AACV,MAAI,MAAM,EAAE,OAAQ,QAAO;AAC3B,UAAQ,IAAK,IAAI,IAAK,MAAM,EAAG,KAAI,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,CAAE,QAAO;AAClE,SAAO;;CAGT,IAAI,IAAI;AACR,MAAK,MAAM,KAAK,GAAG;AACjB,MAAI,EAAE,KAAK,KAAK,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAG,QAAO;AAC/C,MAAK,IAAI,IAAK;;AAEhB,MAAK,MAAM,KAAK,EAAG,MAAK,IAAK,IAAI,IAAK,KAAK,EAAG,QAAO;AACrD,QAAO"}
|
package/oxlint.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from "oxlint";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
plugins: ["react", "jsx-a11y"],
|
|
5
|
+
rules: {
|
|
6
|
+
"no-ex-assign": ["off"],
|
|
7
|
+
"no-unused-vars": [
|
|
8
|
+
"warn",
|
|
9
|
+
{
|
|
10
|
+
args: "none",
|
|
11
|
+
vars: "all",
|
|
12
|
+
varsIgnorePattern: "^_",
|
|
13
|
+
caughtErrors: "none",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
});
|
package/package.json
CHANGED
|
@@ -1,28 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bansa",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bansa",
|
|
7
|
+
"react",
|
|
8
|
+
"state"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/cgiosy/bansa",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "cgiosy",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/cgiosy/bansa.git"
|
|
16
|
+
},
|
|
5
17
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
7
|
-
"types": "./dist/index.d.
|
|
18
|
+
"main": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
8
20
|
"exports": {
|
|
9
21
|
"./package.json": "./package.json",
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"default": "./dist/index.mjs"
|
|
25
|
+
},
|
|
10
26
|
"./react": {
|
|
11
|
-
"types": "./dist/react.d.
|
|
12
|
-
"default": "./dist/react.
|
|
27
|
+
"types": "./dist/react.d.mts",
|
|
28
|
+
"default": "./dist/react.mjs"
|
|
13
29
|
},
|
|
14
|
-
"
|
|
15
|
-
"types": "./dist/
|
|
16
|
-
"default": "./dist/
|
|
30
|
+
"./atom": {
|
|
31
|
+
"types": "./dist/atom.d.mts",
|
|
32
|
+
"default": "./dist/atom.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./utils": {
|
|
35
|
+
"types": "./dist/utils.d.mts",
|
|
36
|
+
"default": "./dist/utils.mjs"
|
|
17
37
|
}
|
|
18
38
|
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
19
42
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@types/react": "^19.2.7",
|
|
43
|
+
"@types/react": "^19.2.14",
|
|
22
44
|
"@types/react-dom": "^19.2.3",
|
|
23
|
-
"
|
|
45
|
+
"oxfmt": "^0.36.0",
|
|
46
|
+
"oxlint": "^1.51.0",
|
|
47
|
+
"tsdown": "^0.21.0",
|
|
24
48
|
"typescript": "^5.9.3",
|
|
25
|
-
"vitest": "^4.0.
|
|
49
|
+
"vitest": "^4.0.18"
|
|
26
50
|
},
|
|
27
51
|
"peerDependencies": {
|
|
28
52
|
"@types/react": ">=17.0.0",
|
|
@@ -36,30 +60,13 @@
|
|
|
36
60
|
"optional": true
|
|
37
61
|
}
|
|
38
62
|
},
|
|
39
|
-
"author": "cgiosy",
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "git://github.com/cgiosy/bansa.git"
|
|
44
|
-
},
|
|
45
|
-
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
47
|
-
},
|
|
48
|
-
"homepage": "https://github.com/cgiosy/bansa",
|
|
49
|
-
"keywords": [
|
|
50
|
-
"bansa",
|
|
51
|
-
"state",
|
|
52
|
-
"react"
|
|
53
|
-
],
|
|
54
63
|
"scripts": {
|
|
55
64
|
"build": "pnpm run \"/^build:.*/\"",
|
|
56
|
-
"build:
|
|
57
|
-
"build:
|
|
58
|
-
"build:index-browser": "esbuild src/index.ts --bundle --mangle-props=^_ --minify --bundle --format=esm --target=es2022 --platform=browser --outfile=dist/index.browser.js",
|
|
59
|
-
"build:atom": "esbuild src/atom.ts --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/atom.js",
|
|
60
|
-
"build:utils": "esbuild src/utils.ts --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/utils.js",
|
|
61
|
-
"build:react": "esbuild src/react.tsx --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/react.js",
|
|
65
|
+
"build:bundler": "tsdown src/index.ts src/react.tsx src/atom.ts src/utils.ts --dts --mangle-props=^_ --target=es2022",
|
|
66
|
+
"build:browser": "tsdown src/index.ts --dts --mangle-props=^_ --minify --target=es2022 --platform=browser --out-dir=dist/browser",
|
|
62
67
|
"test": "vitest",
|
|
63
|
-
"
|
|
68
|
+
"lint": "pnpm check",
|
|
69
|
+
"check": "tsc -b --noEmit && oxlint && oxfmt --check",
|
|
70
|
+
"format": "oxlint --fix && oxfmt"
|
|
64
71
|
}
|
|
65
72
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["**/*.tsx"],
|
|
3
|
+
"exclude": ["node_modules", "dist"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"moduleResolution": "Bundler",
|
|
13
|
+
"target": "ES2022",
|
|
14
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
15
|
+
"types": ["react", "react-dom", "vitest/globals"],
|
|
16
|
+
"moduleDetection": "force",
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"allowImportingTsExtensions": true,
|
|
22
|
+
"allowArbitraryExtensions": true,
|
|
23
|
+
"rewriteRelativeImportExtensions": true,
|
|
24
|
+
|
|
25
|
+
"emitDeclarationOnly": true,
|
|
26
|
+
"noEmit": true,
|
|
27
|
+
"sourceMap": true,
|
|
28
|
+
"declaration": true,
|
|
29
|
+
"declarationMap": true,
|
|
30
|
+
"verbatimModuleSyntax": true, // Enforce keyword `type` for type imports etc. implies "isolatedModules"
|
|
31
|
+
|
|
32
|
+
"noFallthroughCasesInSwitch": true,
|
|
33
|
+
"noImplicitOverride": true,
|
|
34
|
+
"noImplicitReturns": false,
|
|
35
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
36
|
+
"noUncheckedIndexedAccess": true,
|
|
37
|
+
"strict": true
|
|
38
|
+
}
|
|
39
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
+
"include": ["**/*.tsx"],
|
|
3
|
+
"exclude": ["node_modules", "dist"],
|
|
2
4
|
"compilerOptions": {
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"moduleResolution": "Bundler",
|
|
3
13
|
"target": "ES2022",
|
|
4
14
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
-
"types": ["
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"useDefineForClassFields": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
|
|
11
|
-
/* Bundler mode */
|
|
12
|
-
"moduleResolution": "bundler",
|
|
15
|
+
"types": ["react", "react-dom", "vitest/globals"],
|
|
13
16
|
"moduleDetection": "force",
|
|
14
|
-
"
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
|
|
19
|
+
"skipLibCheck": true,
|
|
15
20
|
"resolveJsonModule": true,
|
|
16
|
-
"
|
|
21
|
+
"allowImportingTsExtensions": true,
|
|
22
|
+
"allowArbitraryExtensions": true,
|
|
23
|
+
"rewriteRelativeImportExtensions": true,
|
|
24
|
+
|
|
25
|
+
"emitDeclarationOnly": true,
|
|
17
26
|
"noEmit": true,
|
|
18
|
-
"
|
|
27
|
+
"sourceMap": true,
|
|
28
|
+
"declaration": true,
|
|
29
|
+
"declarationMap": true,
|
|
30
|
+
"verbatimModuleSyntax": true, // Enforce keyword `type` for type imports etc. implies "isolatedModules"
|
|
19
31
|
|
|
20
|
-
/* Linting */
|
|
21
|
-
"strict": true,
|
|
22
|
-
"noUnusedLocals": true,
|
|
23
|
-
"noUnusedParameters": true,
|
|
24
32
|
"noFallthroughCasesInSwitch": true,
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
"noImplicitOverride": true,
|
|
34
|
+
"noImplicitReturns": false,
|
|
35
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
36
|
+
"noUncheckedIndexedAccess": true,
|
|
37
|
+
"strict": true
|
|
38
|
+
}
|
|
28
39
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["**/*.ts"],
|
|
3
|
+
"exclude": ["node_modules", "dist"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"rootDir": ".",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"target": "ESNext",
|
|
11
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
12
|
+
"types": ["react", "react-dom", "vitest/globals"],
|
|
13
|
+
// "moduleDetection": "force",
|
|
14
|
+
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"allowImportingTsExtensions": true,
|
|
18
|
+
"rewriteRelativeImportExtensions": true,
|
|
19
|
+
|
|
20
|
+
"emitDeclarationOnly": true,
|
|
21
|
+
"noEmit": true,
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"declaration": true,
|
|
24
|
+
"declarationMap": true,
|
|
25
|
+
"erasableSyntaxOnly": true, // No JSX, enums, constructor parameter properties, namespaces
|
|
26
|
+
"verbatimModuleSyntax": true, // Enforce keyword `type` for type imports etc. implies "isolatedModules"
|
|
27
|
+
|
|
28
|
+
"noFallthroughCasesInSwitch": true,
|
|
29
|
+
"noImplicitOverride": true,
|
|
30
|
+
"noImplicitReturns": false,
|
|
31
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
32
|
+
"noUncheckedIndexedAccess": true,
|
|
33
|
+
"strict": true
|
|
34
|
+
}
|
|
35
|
+
}
|
package/dist/atom.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
export type Atom<Value> = PrimitiveAtom<Value> | DerivedAtom<Value>;
|
|
2
|
-
export type CommonAtom<Value> = {
|
|
3
|
-
readonly get: () => Value;
|
|
4
|
-
readonly watch: (watcher: AtomWatcher) => () => void;
|
|
5
|
-
readonly subscribe: (subscriber: AtomSubscribe<Value>) => () => void;
|
|
6
|
-
readonly state: AtomState<Value>;
|
|
7
|
-
};
|
|
8
|
-
export type PrimitiveAtom<Value> = CommonAtom<Value> & {
|
|
9
|
-
readonly set: (value: AtomUpdater<Value>) => void;
|
|
10
|
-
readonly state: AtomSuccessState<Value>;
|
|
11
|
-
};
|
|
12
|
-
export type DerivedAtom<Value> = CommonAtom<Value>;
|
|
13
|
-
export type AtomWatcher = () => void;
|
|
14
|
-
export type AtomSubscribe<Value> = (value: Value, options: AtomSubscriberOptions) => void;
|
|
15
|
-
export type AtomInit<Value> = Value | AtomGetter<Value>;
|
|
16
|
-
export type AtomUpdater<Value> = Value | AtomReducer<Value>;
|
|
17
|
-
export type AtomInactiveState<Value> = {
|
|
18
|
-
promise: typeof inactive;
|
|
19
|
-
error: any;
|
|
20
|
-
value?: Value;
|
|
21
|
-
};
|
|
22
|
-
export type AtomPromiseState<Value> = {
|
|
23
|
-
promise: PromiseLike<Value>;
|
|
24
|
-
error: any;
|
|
25
|
-
value?: Value;
|
|
26
|
-
};
|
|
27
|
-
export type AtomSuccessState<Value> = {
|
|
28
|
-
promise: undefined;
|
|
29
|
-
error: undefined;
|
|
30
|
-
value: Value;
|
|
31
|
-
};
|
|
32
|
-
export type AtomErrorState<Value> = {
|
|
33
|
-
promise: undefined;
|
|
34
|
-
error: any;
|
|
35
|
-
value?: Value;
|
|
36
|
-
};
|
|
37
|
-
export type AtomState<Value> = AtomInactiveState<Value> | AtomPromiseState<Value> | AtomSuccessState<Value> | AtomErrorState<Value>;
|
|
38
|
-
export type AtomSubscriberOptions = {
|
|
39
|
-
readonly signal: ThenableSignal;
|
|
40
|
-
};
|
|
41
|
-
export type AtomGetter<Value> = (get: GetAtom, options: AtomGetOptions) => Value | PromiseLike<Value>;
|
|
42
|
-
export type AtomReducer<Value> = (value: Value) => Value;
|
|
43
|
-
export type AtomGetOptions = {
|
|
44
|
-
readonly signal: ThenableSignal;
|
|
45
|
-
};
|
|
46
|
-
export type ThenableSignal = AbortSignal & {
|
|
47
|
-
then: (f: () => void) => void;
|
|
48
|
-
};
|
|
49
|
-
export type GetAtom = {
|
|
50
|
-
<Value>(anotherAtom: Atom<Value>, unwrap?: true): Value;
|
|
51
|
-
<Value>(anotherAtom: Atom<Value>, unwrap: false): AtomState<Value>;
|
|
52
|
-
};
|
|
53
|
-
type CreateAtom = {
|
|
54
|
-
<Value>(init: AtomGetter<Value>, options?: AtomOptions<Value>): DerivedAtom<Value>;
|
|
55
|
-
<Value>(init: Value, options?: AtomOptions<Value>): PrimitiveAtom<Value>;
|
|
56
|
-
<Value>(init: Value | AtomGetter<Value>, options?: AtomOptions<Value>): Atom<Value>;
|
|
57
|
-
};
|
|
58
|
-
export type AtomOptions<Value> = {
|
|
59
|
-
equals?: AtomEquals<Value>;
|
|
60
|
-
persist?: boolean;
|
|
61
|
-
eager?: boolean;
|
|
62
|
-
};
|
|
63
|
-
export type AtomEquals<Value> = (value: Value, prevValue: Value) => boolean;
|
|
64
|
-
export type AtomScope = {
|
|
65
|
-
<Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;
|
|
66
|
-
<Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;
|
|
67
|
-
<Value>(baseAtom: Atom<Value>): Atom<Value>;
|
|
68
|
-
<Value>(baseAtom: PrimitiveAtom<Value>, strict: true): PrimitiveAtom<Value> | undefined;
|
|
69
|
-
<Value>(baseAtom: DerivedAtom<Value>, strict: true): DerivedAtom<Value> | undefined;
|
|
70
|
-
<Value>(baseAtom: Atom<Value>, strict: true): Atom<Value> | undefined;
|
|
71
|
-
};
|
|
72
|
-
export type SetLike<Key> = Key[] | Set<Key> | (Key extends object ? WeakSet<Key> : never);
|
|
73
|
-
export type MapLike<Key, Value> = Map<Key, Value> | (Key extends object ? WeakMap<Key, Value> : never) | (Key extends string | number | symbol ? Record<Key, Value> : never);
|
|
74
|
-
export declare const inactive: Promise<never>;
|
|
75
|
-
export declare const $: CreateAtom;
|
|
76
|
-
export declare const isAtom: (x: unknown) => x is Atom<unknown>;
|
|
77
|
-
export declare const isPrimitiveAtom: (x: unknown) => x is PrimitiveAtom<unknown>;
|
|
78
|
-
export type AtomValuePair<Value> = [Atom<Value>, Value | PrimitiveAtom<Value>] | [DerivedAtom<Value>, Value | Atom<Value>];
|
|
79
|
-
export declare const createScope: <T extends AtomValuePair<unknown>[]>(parentScope?: AtomScope | null, atomValuePairs?: T) => AtomScope;
|
|
80
|
-
export {};
|