@depup/jotai 2.18.0-depup.0
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/LICENSE +21 -0
- package/README.md +25 -0
- package/babel/plugin-debug-label.d.ts +5 -0
- package/babel/plugin-debug-label.js +54 -0
- package/babel/plugin-react-refresh.d.ts +5 -0
- package/babel/plugin-react-refresh.js +72 -0
- package/babel/preset.d.ts +6 -0
- package/babel/preset.js +110 -0
- package/babel/utils.d.ts +5 -0
- package/benchmarks/simple-read.d.ts +2 -0
- package/benchmarks/simple-write.d.ts +2 -0
- package/benchmarks/subscribe-write.d.ts +2 -0
- package/changes.json +5 -0
- package/esm/babel/plugin-debug-label.d.mts +5 -0
- package/esm/babel/plugin-debug-label.mjs +103 -0
- package/esm/babel/plugin-react-refresh.d.mts +5 -0
- package/esm/babel/plugin-react-refresh.mjs +121 -0
- package/esm/babel/preset.d.mts +6 -0
- package/esm/babel/preset.mjs +179 -0
- package/esm/babel/utils.d.mts +5 -0
- package/esm/index.d.mts +2 -0
- package/esm/index.mjs +2 -0
- package/esm/react/Provider.d.mts +16 -0
- package/esm/react/useAtom.d.mts +13 -0
- package/esm/react/useAtomValue.d.mts +9 -0
- package/esm/react/useSetAtom.d.mts +7 -0
- package/esm/react/utils/useAtomCallback.d.mts +5 -0
- package/esm/react/utils/useHydrateAtoms.d.mts +14 -0
- package/esm/react/utils/useReducerAtom.d.mts +14 -0
- package/esm/react/utils/useResetAtom.d.mts +6 -0
- package/esm/react/utils.d.mts +4 -0
- package/esm/react/utils.mjs +57 -0
- package/esm/react.d.mts +4 -0
- package/esm/react.mjs +182 -0
- package/esm/utils.d.mts +2 -0
- package/esm/utils.mjs +2 -0
- package/esm/vanilla/atom.d.mts +47 -0
- package/esm/vanilla/internals.d.mts +164 -0
- package/esm/vanilla/internals.mjs +715 -0
- package/esm/vanilla/store.d.mts +5 -0
- package/esm/vanilla/typeUtils.d.mts +7 -0
- package/esm/vanilla/utils/atomFamily.d.mts +55 -0
- package/esm/vanilla/utils/atomWithDefault.d.mts +6 -0
- package/esm/vanilla/utils/atomWithLazy.d.mts +2 -0
- package/esm/vanilla/utils/atomWithObservable.d.mts +32 -0
- package/esm/vanilla/utils/atomWithReducer.d.mts +3 -0
- package/esm/vanilla/utils/atomWithRefresh.d.mts +6 -0
- package/esm/vanilla/utils/atomWithReset.d.mts +8 -0
- package/esm/vanilla/utils/atomWithStorage.d.mts +50 -0
- package/esm/vanilla/utils/constants.d.mts +1 -0
- package/esm/vanilla/utils/freezeAtom.d.mts +6 -0
- package/esm/vanilla/utils/loadable.d.mts +33 -0
- package/esm/vanilla/utils/selectAtom.d.mts +2 -0
- package/esm/vanilla/utils/splitAtom.d.mts +16 -0
- package/esm/vanilla/utils/unwrap.d.mts +5 -0
- package/esm/vanilla/utils.d.mts +14 -0
- package/esm/vanilla/utils.mjs +736 -0
- package/esm/vanilla.d.mts +4 -0
- package/esm/vanilla.mjs +59 -0
- package/index.d.ts +2 -0
- package/index.js +19 -0
- package/package.json +125 -0
- package/react/Provider.d.ts +16 -0
- package/react/useAtom.d.ts +13 -0
- package/react/useAtomValue.d.ts +9 -0
- package/react/useSetAtom.d.ts +7 -0
- package/react/utils/useAtomCallback.d.ts +5 -0
- package/react/utils/useHydrateAtoms.d.ts +14 -0
- package/react/utils/useReducerAtom.d.ts +14 -0
- package/react/utils/useResetAtom.d.ts +6 -0
- package/react/utils.d.ts +4 -0
- package/react/utils.js +100 -0
- package/react.d.ts +4 -0
- package/react.js +182 -0
- package/system/babel/plugin-debug-label.development.js +113 -0
- package/system/babel/plugin-debug-label.production.js +4 -0
- package/system/babel/plugin-react-refresh.development.js +131 -0
- package/system/babel/plugin-react-refresh.production.js +11 -0
- package/system/babel/preset.development.js +189 -0
- package/system/babel/preset.production.js +14 -0
- package/system/index.development.js +27 -0
- package/system/index.production.js +1 -0
- package/system/react/utils.development.js +79 -0
- package/system/react/utils.production.js +2 -0
- package/system/react.development.js +210 -0
- package/system/react.production.js +2 -0
- package/system/utils.development.js +27 -0
- package/system/utils.production.js +1 -0
- package/system/vanilla/internals.development.js +735 -0
- package/system/vanilla/internals.production.js +1 -0
- package/system/vanilla/utils.development.js +764 -0
- package/system/vanilla/utils.production.js +1 -0
- package/system/vanilla.development.js +75 -0
- package/system/vanilla.production.js +1 -0
- package/ts3.8/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/babel/preset.d.ts +7 -0
- package/ts3.8/babel/utils.d.ts +6 -0
- package/ts3.8/benchmarks/simple-read.d.ts +3 -0
- package/ts3.8/benchmarks/simple-write.d.ts +3 -0
- package/ts3.8/benchmarks/subscribe-write.d.ts +3 -0
- package/ts3.8/esm/babel/plugin-debug-label.d.ts +6 -0
- package/ts3.8/esm/babel/plugin-react-refresh.d.ts +6 -0
- package/ts3.8/esm/babel/preset.d.ts +7 -0
- package/ts3.8/esm/babel/utils.d.ts +6 -0
- package/ts3.8/esm/index.d.ts +3 -0
- package/ts3.8/esm/react/Provider.d.ts +17 -0
- package/ts3.8/esm/react/useAtom.d.ts +28 -0
- package/ts3.8/esm/react/useAtomValue.d.ts +10 -0
- package/ts3.8/esm/react/useSetAtom.d.ts +8 -0
- package/ts3.8/esm/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/esm/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/esm/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/esm/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/esm/react/utils.d.ts +5 -0
- package/ts3.8/esm/react.d.ts +5 -0
- package/ts3.8/esm/utils.d.ts +3 -0
- package/ts3.8/esm/vanilla/atom.d.ts +48 -0
- package/ts3.8/esm/vanilla/internals.d.ts +165 -0
- package/ts3.8/esm/vanilla/store.d.ts +6 -0
- package/ts3.8/esm/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/esm/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/esm/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/esm/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/esm/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/esm/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/esm/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/esm/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/esm/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/esm/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/esm/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/esm/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/esm/vanilla/utils.d.ts +15 -0
- package/ts3.8/esm/vanilla.d.ts +5 -0
- package/ts3.8/index.d.ts +3 -0
- package/ts3.8/react/Provider.d.ts +17 -0
- package/ts3.8/react/useAtom.d.ts +28 -0
- package/ts3.8/react/useAtomValue.d.ts +10 -0
- package/ts3.8/react/useSetAtom.d.ts +8 -0
- package/ts3.8/react/utils/useAtomCallback.d.ts +6 -0
- package/ts3.8/react/utils/useHydrateAtoms.d.ts +27 -0
- package/ts3.8/react/utils/useReducerAtom.d.ts +21 -0
- package/ts3.8/react/utils/useResetAtom.d.ts +9 -0
- package/ts3.8/react/utils.d.ts +5 -0
- package/ts3.8/react.d.ts +5 -0
- package/ts3.8/utils.d.ts +3 -0
- package/ts3.8/vanilla/atom.d.ts +48 -0
- package/ts3.8/vanilla/internals.d.ts +165 -0
- package/ts3.8/vanilla/store.d.ts +6 -0
- package/ts3.8/vanilla/typeUtils.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomFamily.d.ts +56 -0
- package/ts3.8/vanilla/utils/atomWithDefault.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithLazy.d.ts +3 -0
- package/ts3.8/vanilla/utils/atomWithObservable.d.ts +37 -0
- package/ts3.8/vanilla/utils/atomWithReducer.d.ts +8 -0
- package/ts3.8/vanilla/utils/atomWithRefresh.d.ts +10 -0
- package/ts3.8/vanilla/utils/atomWithReset.d.ts +11 -0
- package/ts3.8/vanilla/utils/atomWithStorage.d.ts +53 -0
- package/ts3.8/vanilla/utils/constants.d.ts +2 -0
- package/ts3.8/vanilla/utils/freezeAtom.d.ts +7 -0
- package/ts3.8/vanilla/utils/loadable.d.ts +34 -0
- package/ts3.8/vanilla/utils/selectAtom.d.ts +3 -0
- package/ts3.8/vanilla/utils/splitAtom.d.ts +21 -0
- package/ts3.8/vanilla/utils/unwrap.d.ts +6 -0
- package/ts3.8/vanilla/utils.d.ts +15 -0
- package/ts3.8/vanilla.d.ts +5 -0
- package/ts_version_3.8_and_above_is_required.d.ts +0 -0
- package/umd/babel/plugin-debug-label.development.js +58 -0
- package/umd/babel/plugin-debug-label.production.js +1 -0
- package/umd/babel/plugin-react-refresh.development.js +76 -0
- package/umd/babel/plugin-react-refresh.production.js +1 -0
- package/umd/babel/preset.development.js +114 -0
- package/umd/babel/preset.production.js +1 -0
- package/umd/index.development.js +20 -0
- package/umd/index.production.js +1 -0
- package/umd/react/utils.development.js +101 -0
- package/umd/react/utils.production.js +1 -0
- package/umd/react.development.js +184 -0
- package/umd/react.production.js +1 -0
- package/umd/utils.development.js +20 -0
- package/umd/utils.production.js +1 -0
- package/umd/vanilla/internals.development.js +785 -0
- package/umd/vanilla/internals.production.js +1 -0
- package/umd/vanilla/utils.development.js +858 -0
- package/umd/vanilla/utils.production.js +1 -0
- package/umd/vanilla.development.js +64 -0
- package/umd/vanilla.production.js +1 -0
- package/utils.d.ts +2 -0
- package/utils.js +19 -0
- package/vanilla/atom.d.ts +47 -0
- package/vanilla/internals.d.ts +164 -0
- package/vanilla/internals.js +779 -0
- package/vanilla/store.d.ts +5 -0
- package/vanilla/typeUtils.d.ts +7 -0
- package/vanilla/utils/atomFamily.d.ts +55 -0
- package/vanilla/utils/atomWithDefault.d.ts +6 -0
- package/vanilla/utils/atomWithLazy.d.ts +2 -0
- package/vanilla/utils/atomWithObservable.d.ts +32 -0
- package/vanilla/utils/atomWithReducer.d.ts +3 -0
- package/vanilla/utils/atomWithRefresh.d.ts +6 -0
- package/vanilla/utils/atomWithReset.d.ts +8 -0
- package/vanilla/utils/atomWithStorage.d.ts +50 -0
- package/vanilla/utils/constants.d.ts +1 -0
- package/vanilla/utils/freezeAtom.d.ts +6 -0
- package/vanilla/utils/loadable.d.ts +33 -0
- package/vanilla/utils/selectAtom.d.ts +2 -0
- package/vanilla/utils/splitAtom.d.ts +16 -0
- package/vanilla/utils/unwrap.d.ts +5 -0
- package/vanilla/utils.d.ts +14 -0
- package/vanilla/utils.js +854 -0
- package/vanilla.d.ts +4 -0
- package/vanilla.js +60 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Atom, PrimitiveAtom, WritableAtom } from './atom';
|
|
2
|
+
export type Getter = Parameters<Atom<unknown>['read']>[0];
|
|
3
|
+
export type Setter = Parameters<WritableAtom<unknown, unknown[], unknown>['write']>[1];
|
|
4
|
+
export type ExtractAtomValue<AtomType> = AtomType extends Atom<infer Value> ? Value : never;
|
|
5
|
+
export type ExtractAtomArgs<AtomType> = AtomType extends WritableAtom<unknown, infer Args, infer _Result> ? Args : never;
|
|
6
|
+
export type ExtractAtomResult<AtomType> = AtomType extends WritableAtom<unknown, infer _Args, infer Result> ? Result : never;
|
|
7
|
+
export type SetStateAction<Value> = ExtractAtomArgs<PrimitiveAtom<Value>>[0];
|
|
8
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Atom } from 'jotai/vanilla';
|
|
2
|
+
/**
|
|
3
|
+
* in milliseconds
|
|
4
|
+
*/
|
|
5
|
+
type CreatedAt = number;
|
|
6
|
+
type ShouldRemove<Param> = (createdAt: CreatedAt, param: Param) => boolean;
|
|
7
|
+
type Cleanup = () => void;
|
|
8
|
+
type Callback<Param, AtomType> = (event: {
|
|
9
|
+
type: 'CREATE' | 'REMOVE';
|
|
10
|
+
param: Param;
|
|
11
|
+
atom: AtomType;
|
|
12
|
+
}) => void;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated atomFamily is deprecated and will be removed in v3.
|
|
15
|
+
* Please use the `jotai-family` package instead: https://github.com/jotaijs/jotai-family
|
|
16
|
+
*
|
|
17
|
+
* Install: `npm install jotai-family`
|
|
18
|
+
*
|
|
19
|
+
* Migration:
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Before
|
|
22
|
+
* import { atomFamily } from 'jotai/utils'
|
|
23
|
+
*
|
|
24
|
+
* // After
|
|
25
|
+
* import { atomFamily } from 'jotai-family'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface AtomFamily<Param, AtomType> {
|
|
29
|
+
(param: Param): AtomType;
|
|
30
|
+
getParams(): Iterable<Param>;
|
|
31
|
+
remove(param: Param): void;
|
|
32
|
+
setShouldRemove(shouldRemove: ShouldRemove<Param> | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* fires when an atom is created or removed
|
|
35
|
+
* This API is for advanced use cases, and can change without notice.
|
|
36
|
+
*/
|
|
37
|
+
unstable_listen(callback: Callback<Param, AtomType>): Cleanup;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated atomFamily is deprecated and will be removed in v3.
|
|
41
|
+
* Please use the `jotai-family` package instead: https://github.com/jotaijs/jotai-family
|
|
42
|
+
*
|
|
43
|
+
* Install: `npm install jotai-family`
|
|
44
|
+
*
|
|
45
|
+
* Migration:
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Before
|
|
48
|
+
* import { atomFamily } from 'jotai/utils'
|
|
49
|
+
*
|
|
50
|
+
* // After
|
|
51
|
+
* import { atomFamily } from 'jotai-family'
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function atomFamily<Param, AtomType extends Atom<unknown>>(initializeAtom: (param: Param) => AtomType, areEqual?: (a: Param, b: Param) => boolean): AtomFamily<Param, AtomType>;
|
|
55
|
+
export {};
|
|
56
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
import { RESET } from './constants';
|
|
3
|
+
type Read<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['read'];
|
|
4
|
+
type DefaultSetStateAction<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
|
|
5
|
+
export declare function atomWithDefault<Value>(getDefault: Read<Value, [
|
|
6
|
+
DefaultSetStateAction<Value>
|
|
7
|
+
], void>): WritableAtom<Value, [
|
|
8
|
+
DefaultSetStateAction<Value>
|
|
9
|
+
], void>;
|
|
10
|
+
export {};
|
|
11
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Atom, Getter, WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
type AnyError = unknown;
|
|
3
|
+
type Subscription = {
|
|
4
|
+
unsubscribe: () => void;
|
|
5
|
+
};
|
|
6
|
+
type Observer<T> = {
|
|
7
|
+
next: (value: T) => void;
|
|
8
|
+
error: (error: AnyError) => void;
|
|
9
|
+
complete: () => void;
|
|
10
|
+
};
|
|
11
|
+
type ObservableLike<T> = {
|
|
12
|
+
subscribe(observer: Observer<T>): Subscription;
|
|
13
|
+
} | {
|
|
14
|
+
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
15
|
+
} | {
|
|
16
|
+
subscribe(observer: Partial<Observer<T>>): Subscription;
|
|
17
|
+
subscribe(next: (value: T) => void): Subscription;
|
|
18
|
+
};
|
|
19
|
+
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
|
|
20
|
+
type Options<Data> = {
|
|
21
|
+
initialValue?: Data | (() => Data);
|
|
22
|
+
unstable_timeout?: number;
|
|
23
|
+
};
|
|
24
|
+
type OptionsWithInitialValue<Data> = {
|
|
25
|
+
initialValue: Data | (() => Data);
|
|
26
|
+
unstable_timeout?: number;
|
|
27
|
+
};
|
|
28
|
+
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options: OptionsWithInitialValue<Data>): WritableAtom<Data, [
|
|
29
|
+
Data
|
|
30
|
+
], void>;
|
|
31
|
+
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options?: Options<Data>): WritableAtom<Data | Promise<Data>, [
|
|
32
|
+
Data
|
|
33
|
+
], void>;
|
|
34
|
+
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options: OptionsWithInitialValue<Data>): Atom<Data>;
|
|
35
|
+
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options?: Options<Data>): Atom<Data | Promise<Data>>;
|
|
36
|
+
export {};
|
|
37
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
export declare function atomWithReducer<Value, Action>(initialValue: Value, reducer: (value: Value, action?: Action) => Value): WritableAtom<Value, [
|
|
3
|
+
Action?
|
|
4
|
+
], void>;
|
|
5
|
+
export declare function atomWithReducer<Value, Action>(initialValue: Value, reducer: (value: Value, action: Action) => Value): WritableAtom<Value, [
|
|
6
|
+
Action
|
|
7
|
+
], void>;
|
|
8
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
type Read<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['read'];
|
|
3
|
+
type Write<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['write'];
|
|
4
|
+
export declare function atomWithRefresh<Value, Args extends unknown[], Result>(read: Read<Value, Args, Result>, write: Write<Value, Args, Result>): WritableAtom<Value, Args | [
|
|
5
|
+
], Result | void>;
|
|
6
|
+
export declare function atomWithRefresh<Value>(read: Read<Value, [
|
|
7
|
+
], void>): WritableAtom<Value, [
|
|
8
|
+
], void>;
|
|
9
|
+
export {};
|
|
10
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
import { RESET } from './constants';
|
|
3
|
+
type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
|
|
4
|
+
type WithInitialValue<Value> = {
|
|
5
|
+
init: Value;
|
|
6
|
+
};
|
|
7
|
+
export declare function atomWithReset<Value>(initialValue: Value): WritableAtom<Value, [
|
|
8
|
+
SetStateActionWithReset<Value>
|
|
9
|
+
], void> & WithInitialValue<Value>;
|
|
10
|
+
export {};
|
|
11
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
import { RESET } from './constants';
|
|
3
|
+
type Unsubscribe = () => void;
|
|
4
|
+
type Subscribe<Value> = (key: string, callback: (value: Value) => void, initialValue: Value) => Unsubscribe | undefined;
|
|
5
|
+
type StringSubscribe = (key: string, callback: (value: string | null) => void) => Unsubscribe | undefined;
|
|
6
|
+
type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
|
|
7
|
+
export interface AsyncStorage<Value> {
|
|
8
|
+
getItem: (key: string, initialValue: Value) => PromiseLike<Value>;
|
|
9
|
+
setItem: (key: string, newValue: Value) => PromiseLike<void>;
|
|
10
|
+
removeItem: (key: string) => PromiseLike<void>;
|
|
11
|
+
subscribe?: Subscribe<Value>;
|
|
12
|
+
}
|
|
13
|
+
export interface SyncStorage<Value> {
|
|
14
|
+
getItem: (key: string, initialValue: Value) => Value;
|
|
15
|
+
setItem: (key: string, newValue: Value) => void;
|
|
16
|
+
removeItem: (key: string) => void;
|
|
17
|
+
subscribe?: Subscribe<Value>;
|
|
18
|
+
}
|
|
19
|
+
export interface AsyncStringStorage {
|
|
20
|
+
getItem: (key: string) => PromiseLike<string | null>;
|
|
21
|
+
setItem: (key: string, newValue: string) => PromiseLike<void>;
|
|
22
|
+
removeItem: (key: string) => PromiseLike<void>;
|
|
23
|
+
subscribe?: StringSubscribe;
|
|
24
|
+
}
|
|
25
|
+
export interface SyncStringStorage {
|
|
26
|
+
getItem: (key: string) => string | null;
|
|
27
|
+
setItem: (key: string, newValue: string) => void;
|
|
28
|
+
removeItem: (key: string) => void;
|
|
29
|
+
subscribe?: StringSubscribe;
|
|
30
|
+
}
|
|
31
|
+
export declare function withStorageValidator<Value>(validator: (value: unknown) => value is Value): {
|
|
32
|
+
(storage: AsyncStorage<unknown>): AsyncStorage<Value>;
|
|
33
|
+
(storage: SyncStorage<unknown>): SyncStorage<Value>;
|
|
34
|
+
};
|
|
35
|
+
type JsonStorageOptions = {
|
|
36
|
+
reviver?: (key: string, value: unknown) => unknown;
|
|
37
|
+
replacer?: (key: string, value: unknown) => unknown;
|
|
38
|
+
};
|
|
39
|
+
export declare function createJSONStorage<Value>(): SyncStorage<Value>;
|
|
40
|
+
export declare function createJSONStorage<Value>(getStringStorage: () => AsyncStringStorage, options?: JsonStorageOptions): AsyncStorage<Value>;
|
|
41
|
+
export declare function createJSONStorage<Value>(getStringStorage: () => SyncStringStorage, options?: JsonStorageOptions): SyncStorage<Value>;
|
|
42
|
+
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: AsyncStorage<Value>, options?: {
|
|
43
|
+
getOnInit?: boolean;
|
|
44
|
+
}): WritableAtom<Value | Promise<Value>, [
|
|
45
|
+
SetStateActionWithReset<Value | Promise<Value>>
|
|
46
|
+
], Promise<void>>;
|
|
47
|
+
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, options?: {
|
|
48
|
+
getOnInit?: boolean;
|
|
49
|
+
}): WritableAtom<Value, [
|
|
50
|
+
SetStateActionWithReset<Value>
|
|
51
|
+
], void>;
|
|
52
|
+
export {};
|
|
53
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Atom } from 'jotai/vanilla';
|
|
2
|
+
export declare function freezeAtom<AtomType extends Atom<unknown>>(anAtom: AtomType): AtomType;
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Define it on users end
|
|
5
|
+
*/
|
|
6
|
+
export declare function freezeAtomCreator<CreateAtom extends (...args: unknown[]) => Atom<unknown>>(createAtom: CreateAtom): CreateAtom;
|
|
7
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Atom } from 'jotai/vanilla';
|
|
2
|
+
export type Loadable<Value> = {
|
|
3
|
+
state: 'loading';
|
|
4
|
+
} | {
|
|
5
|
+
state: 'hasError';
|
|
6
|
+
error: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
state: 'hasData';
|
|
9
|
+
data: Awaited<Value>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated `loadable` is deprecated infavor of `unwrap`.
|
|
13
|
+
*
|
|
14
|
+
* Userland implementation of loadable:
|
|
15
|
+
* ```js
|
|
16
|
+
* function loadable(anAtom) {
|
|
17
|
+
* const LOADING = { state: 'loading' }
|
|
18
|
+
* const unwrappedAtom = unwrap(anAtom, () => LOADING)
|
|
19
|
+
* return atom((get) => {
|
|
20
|
+
* try {
|
|
21
|
+
* const data = get(unwrappedAtom)
|
|
22
|
+
* if (data === LOADING) {
|
|
23
|
+
* return LOADING
|
|
24
|
+
* }
|
|
25
|
+
* return { state: 'hasData', data }
|
|
26
|
+
* } catch (error) {
|
|
27
|
+
* return { state: 'hasError', error }
|
|
28
|
+
* }
|
|
29
|
+
* })
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadable<Value>(anAtom: Atom<Value>): Atom<Loadable<Value>>;
|
|
34
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Atom } from 'jotai/vanilla';
|
|
2
|
+
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Value, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Slice>;
|
|
3
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Atom, PrimitiveAtom, WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
type SplitAtomAction<Item> = {
|
|
3
|
+
type: 'remove';
|
|
4
|
+
atom: PrimitiveAtom<Item>;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'insert';
|
|
7
|
+
value: Item;
|
|
8
|
+
before?: PrimitiveAtom<Item>;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'move';
|
|
11
|
+
atom: PrimitiveAtom<Item>;
|
|
12
|
+
before?: PrimitiveAtom<Item>;
|
|
13
|
+
};
|
|
14
|
+
export declare function splitAtom<Item, Key>(arrAtom: WritableAtom<Item[], [
|
|
15
|
+
Item[]
|
|
16
|
+
], void>, keyExtractor?: (item: Item) => Key): WritableAtom<PrimitiveAtom<Item>[], [
|
|
17
|
+
SplitAtomAction<Item>
|
|
18
|
+
], void>;
|
|
19
|
+
export declare function splitAtom<Item, Key>(arrAtom: Atom<Item[]>, keyExtractor?: (item: Item) => Key): Atom<Atom<Item>[]>;
|
|
20
|
+
export {};
|
|
21
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Atom, WritableAtom } from 'jotai/vanilla';
|
|
2
|
+
export declare function unwrap<Value, Args extends unknown[], Result>(anAtom: WritableAtom<Value, Args, Result>): WritableAtom<Awaited<Value> | undefined, Args, Result>;
|
|
3
|
+
export declare function unwrap<Value, Args extends unknown[], Result, PendingValue>(anAtom: WritableAtom<Value, Args, Result>, fallback: (prev?: Awaited<Value>) => PendingValue): WritableAtom<Awaited<Value> | PendingValue, Args, Result>;
|
|
4
|
+
export declare function unwrap<Value>(anAtom: Atom<Value>): Atom<Awaited<Value> | undefined>;
|
|
5
|
+
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Value>, fallback: (prev?: Awaited<Value>) => PendingValue): Atom<Awaited<Value> | PendingValue>;
|
|
6
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { RESET } from './utils/constants';
|
|
2
|
+
export { atomWithReset } from './utils/atomWithReset';
|
|
3
|
+
export { atomWithReducer } from './utils/atomWithReducer';
|
|
4
|
+
export { atomFamily } from './utils/atomFamily';
|
|
5
|
+
export { selectAtom } from './utils/selectAtom';
|
|
6
|
+
export { freezeAtom, freezeAtomCreator } from './utils/freezeAtom';
|
|
7
|
+
export { splitAtom } from './utils/splitAtom';
|
|
8
|
+
export { atomWithDefault } from './utils/atomWithDefault';
|
|
9
|
+
export { atomWithStorage, createJSONStorage, withStorageValidator as unstable_withStorageValidator, } from './utils/atomWithStorage';
|
|
10
|
+
export { atomWithObservable } from './utils/atomWithObservable';
|
|
11
|
+
export { loadable } from './utils/loadable';
|
|
12
|
+
export { unwrap } from './utils/unwrap';
|
|
13
|
+
export { atomWithRefresh } from './utils/atomWithRefresh';
|
|
14
|
+
export { atomWithLazy } from './utils/atomWithLazy';
|
|
15
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { atom } from './vanilla/atom';
|
|
2
|
+
export type { Atom, WritableAtom, PrimitiveAtom } from './vanilla/atom';
|
|
3
|
+
export { createStore, getDefaultStore, INTERNAL_overrideCreateStore, } from './vanilla/store';
|
|
4
|
+
export type { Getter, Setter, ExtractAtomValue, ExtractAtomArgs, ExtractAtomResult, SetStateAction, } from './vanilla/typeUtils';
|
|
5
|
+
declare type Awaited<T> = T extends Promise<infer V> ? V : T;
|
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@babel/template')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['@babel/template'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.jotaiBabelPluginDebugLabel = factory(global._templateBuilder));
|
|
5
|
+
})(this, (function (_templateBuilder) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function isAtom(t, callee, customAtomNames) {
|
|
8
|
+
if (customAtomNames === void 0) {
|
|
9
|
+
customAtomNames = [];
|
|
10
|
+
}
|
|
11
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
12
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (t.isMemberExpression(callee)) {
|
|
16
|
+
var property = callee.property;
|
|
17
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
24
|
+
|
|
25
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
26
|
+
function debugLabelPlugin(_ref, options) {
|
|
27
|
+
var t = _ref.types;
|
|
28
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
29
|
+
return {
|
|
30
|
+
visitor: {
|
|
31
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
32
|
+
var node = nodePath.node;
|
|
33
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
34
|
+
var filename = (state.filename || 'unknown').replace(/\.\w+$/, '');
|
|
35
|
+
var displayName = filename.split('/').pop();
|
|
36
|
+
if (displayName === 'index') {
|
|
37
|
+
displayName = filename.slice(0, -'/index'.length).split('/').pop() || 'unknown';
|
|
38
|
+
}
|
|
39
|
+
var buildExport = templateBuilder("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ");
|
|
40
|
+
var ast = buildExport({
|
|
41
|
+
atomIdentifier: t.identifier(displayName),
|
|
42
|
+
atom: node.declaration
|
|
43
|
+
});
|
|
44
|
+
nodePath.replaceWithMultiple(ast);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
VariableDeclarator: function VariableDeclarator(path) {
|
|
48
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
49
|
+
path.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(path.node.id.name), t.identifier('debugLabel')), t.stringLiteral(path.node.id.name))));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return debugLabelPlugin;
|
|
57
|
+
|
|
58
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@babel/template")):"function"==typeof define&&define.amd?define(["@babel/template"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).jotaiBabelPluginDebugLabel=t(e._templateBuilder)}(this,function(e){"use strict";function t(e,t,a){void 0===a&&(a=[]);var o=[].concat(i,a);if(e.isIdentifier(t)&&o.includes(t.name))return!0;if(e.isMemberExpression(t)){var n=t.property;if(e.isIdentifier(n)&&o.includes(n.name))return!0}return!1}var i=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],a=e.default||e;return function(e,i){var o=e.types;return console.warn("[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{visitor:{ExportDefaultDeclaration:function(e,n){var r=e.node;if(o.isCallExpression(r.declaration)&&t(o,r.declaration.callee,null==i?void 0:i.customAtomNames)){var l=(n.filename||"unknown").replace(/\.\w+$/,""),s=l.split("/").pop();"index"===s&&(s=l.slice(0,-6).split("/").pop()||"unknown");var m=a("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ")({atomIdentifier:o.identifier(s),atom:r.declaration});e.replaceWithMultiple(m)}},VariableDeclarator:function(e){o.isIdentifier(e.node.id)&&o.isCallExpression(e.node.init)&&t(o,e.node.init.callee,null==i?void 0:i.customAtomNames)&&e.parentPath.insertAfter(o.expressionStatement(o.assignmentExpression("=",o.memberExpression(o.identifier(e.node.id.name),o.identifier("debugLabel")),o.stringLiteral(e.node.id.name))))}}}}});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@babel/template')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['@babel/template'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.jotaiBabelPluginReactRefresh = factory(global._templateBuilder));
|
|
5
|
+
})(this, (function (_templateBuilder) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function isAtom(t, callee, customAtomNames) {
|
|
8
|
+
if (customAtomNames === void 0) {
|
|
9
|
+
customAtomNames = [];
|
|
10
|
+
}
|
|
11
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
12
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (t.isMemberExpression(callee)) {
|
|
16
|
+
var property = callee.property;
|
|
17
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
24
|
+
|
|
25
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
26
|
+
function reactRefreshPlugin(_ref, options) {
|
|
27
|
+
var t = _ref.types;
|
|
28
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
29
|
+
return {
|
|
30
|
+
pre: function pre(_ref2) {
|
|
31
|
+
var opts = _ref2.opts;
|
|
32
|
+
if (!opts.filename) {
|
|
33
|
+
throw new Error('Filename must be available');
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
visitor: {
|
|
37
|
+
Program: {
|
|
38
|
+
exit: function exit(path) {
|
|
39
|
+
var jotaiAtomCache = templateBuilder("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();
|
|
40
|
+
path.unshiftContainer('body', jotaiAtomCache);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
44
|
+
var node = nodePath.node;
|
|
45
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
46
|
+
var filename = state.filename || 'unknown';
|
|
47
|
+
var atomKey = filename + "/defaultExport";
|
|
48
|
+
var buildExport = templateBuilder("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
49
|
+
var ast = buildExport({
|
|
50
|
+
atomKey: t.stringLiteral(atomKey),
|
|
51
|
+
atom: node.declaration
|
|
52
|
+
});
|
|
53
|
+
nodePath.replaceWith(ast);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
VariableDeclarator: function VariableDeclarator(nodePath, state) {
|
|
57
|
+
var _nodePath$parentPath$, _nodePath$parentPath$2;
|
|
58
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && ((_nodePath$parentPath$ = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$.isProgram() || (_nodePath$parentPath$2 = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$2.isExportNamedDeclaration())) {
|
|
59
|
+
var filename = state.filename || 'unknown';
|
|
60
|
+
var atomKey = filename + "/" + nodePath.node.id.name;
|
|
61
|
+
var buildAtomDeclaration = templateBuilder("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
62
|
+
var ast = buildAtomDeclaration({
|
|
63
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
64
|
+
atomKey: t.stringLiteral(atomKey),
|
|
65
|
+
atom: nodePath.node.init
|
|
66
|
+
});
|
|
67
|
+
nodePath.parentPath.replaceWith(ast);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return reactRefreshPlugin;
|
|
75
|
+
|
|
76
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@babel/template")):"function"==typeof define&&define.amd?define(["@babel/template"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).jotaiBabelPluginReactRefresh=t(e._templateBuilder)}(this,function(e){"use strict";function t(e,t,i){void 0===i&&(i=[]);var o=[].concat(a,i);if(e.isIdentifier(t)&&o.includes(t.name))return!0;if(e.isMemberExpression(t)){var n=t.property;if(e.isIdentifier(n)&&o.includes(n.name))return!0}return!1}var a=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],i=e.default||e;return function(e,a){var o=e.types;return console.warn("[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{pre:function(e){if(!e.opts.filename)throw new Error("Filename must be available")},visitor:{Program:{exit:function(e){var t=i("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();e.unshiftContainer("body",t)}},ExportDefaultDeclaration:function(e,n){var r=e.node;if(o.isCallExpression(r.declaration)&&t(o,r.declaration.callee,null==a?void 0:a.customAtomNames)){var l=(n.filename||"unknown")+"/defaultExport",m=i("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:o.stringLiteral(l),atom:r.declaration});e.replaceWith(m)}},VariableDeclarator:function(e,n){var r,l;if(o.isIdentifier(e.node.id)&&o.isCallExpression(e.node.init)&&t(o,e.node.init.callee,null==a?void 0:a.customAtomNames)&&(null!=(r=e.parentPath.parentPath)&&r.isProgram()||null!=(l=e.parentPath.parentPath)&&l.isExportNamedDeclaration())){var m=(n.filename||"unknown")+"/"+e.node.id.name,s=i("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:o.identifier(e.node.id.name),atomKey:o.stringLiteral(m),atom:e.node.init});e.parentPath.replaceWith(s)}}}}}});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@babel/template')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['@babel/template'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.jotaiBabelPreset = factory(global._templateBuilder));
|
|
5
|
+
})(this, (function (_templateBuilder) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function isAtom(t, callee, customAtomNames) {
|
|
8
|
+
if (customAtomNames === void 0) {
|
|
9
|
+
customAtomNames = [];
|
|
10
|
+
}
|
|
11
|
+
var atomNames = [].concat(atomFunctionNames, customAtomNames);
|
|
12
|
+
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (t.isMemberExpression(callee)) {
|
|
16
|
+
var property = callee.property;
|
|
17
|
+
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var atomFunctionNames = ['atom', 'atomFamily', 'atomWithDefault', 'atomWithObservable', 'atomWithReducer', 'atomWithReset', 'atomWithStorage', 'freezeAtom', 'loadable', 'selectAtom', 'splitAtom', 'unwrap', 'atomWithMachine', 'atomWithImmer', 'atomWithProxy', 'atomWithQuery', 'atomWithMutation', 'atomWithSubscription', 'atomWithStore', 'atomWithHash', 'atomWithLocation', 'focusAtom', 'atomWithValidate', 'validateAtoms', 'atomWithCache', 'atomWithRecoilValue'];
|
|
24
|
+
|
|
25
|
+
var templateBuilder$1 = _templateBuilder.default || _templateBuilder;
|
|
26
|
+
function debugLabelPlugin(_ref, options) {
|
|
27
|
+
var t = _ref.types;
|
|
28
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
29
|
+
return {
|
|
30
|
+
visitor: {
|
|
31
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
32
|
+
var node = nodePath.node;
|
|
33
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
34
|
+
var filename = (state.filename || 'unknown').replace(/\.\w+$/, '');
|
|
35
|
+
var displayName = filename.split('/').pop();
|
|
36
|
+
if (displayName === 'index') {
|
|
37
|
+
displayName = filename.slice(0, -'/index'.length).split('/').pop() || 'unknown';
|
|
38
|
+
}
|
|
39
|
+
var buildExport = templateBuilder$1("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ");
|
|
40
|
+
var ast = buildExport({
|
|
41
|
+
atomIdentifier: t.identifier(displayName),
|
|
42
|
+
atom: node.declaration
|
|
43
|
+
});
|
|
44
|
+
nodePath.replaceWithMultiple(ast);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
VariableDeclarator: function VariableDeclarator(path) {
|
|
48
|
+
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
49
|
+
path.parentPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(path.node.id.name), t.identifier('debugLabel')), t.stringLiteral(path.node.id.name))));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var templateBuilder = _templateBuilder.default || _templateBuilder;
|
|
57
|
+
function reactRefreshPlugin(_ref, options) {
|
|
58
|
+
var t = _ref.types;
|
|
59
|
+
console.warn('[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
60
|
+
return {
|
|
61
|
+
pre: function pre(_ref2) {
|
|
62
|
+
var opts = _ref2.opts;
|
|
63
|
+
if (!opts.filename) {
|
|
64
|
+
throw new Error('Filename must be available');
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
visitor: {
|
|
68
|
+
Program: {
|
|
69
|
+
exit: function exit(path) {
|
|
70
|
+
var jotaiAtomCache = templateBuilder("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();
|
|
71
|
+
path.unshiftContainer('body', jotaiAtomCache);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(nodePath, state) {
|
|
75
|
+
var node = nodePath.node;
|
|
76
|
+
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
|
|
77
|
+
var filename = state.filename || 'unknown';
|
|
78
|
+
var atomKey = filename + "/defaultExport";
|
|
79
|
+
var buildExport = templateBuilder("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
80
|
+
var ast = buildExport({
|
|
81
|
+
atomKey: t.stringLiteral(atomKey),
|
|
82
|
+
atom: node.declaration
|
|
83
|
+
});
|
|
84
|
+
nodePath.replaceWith(ast);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
VariableDeclarator: function VariableDeclarator(nodePath, state) {
|
|
88
|
+
var _nodePath$parentPath$, _nodePath$parentPath$2;
|
|
89
|
+
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && ((_nodePath$parentPath$ = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$.isProgram() || (_nodePath$parentPath$2 = nodePath.parentPath.parentPath) != null && _nodePath$parentPath$2.isExportNamedDeclaration())) {
|
|
90
|
+
var filename = state.filename || 'unknown';
|
|
91
|
+
var atomKey = filename + "/" + nodePath.node.id.name;
|
|
92
|
+
var buildAtomDeclaration = templateBuilder("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)");
|
|
93
|
+
var ast = buildAtomDeclaration({
|
|
94
|
+
atomIdentifier: t.identifier(nodePath.node.id.name),
|
|
95
|
+
atomKey: t.stringLiteral(atomKey),
|
|
96
|
+
atom: nodePath.node.init
|
|
97
|
+
});
|
|
98
|
+
nodePath.parentPath.replaceWith(ast);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function jotaiPreset(_, options) {
|
|
106
|
+
console.warn('[DEPRECATED] jotai/babel/preset is deprecated and will be removed in v3.\n' + 'Please use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel');
|
|
107
|
+
return {
|
|
108
|
+
plugins: [[debugLabelPlugin, options], [reactRefreshPlugin, options]]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return jotaiPreset;
|
|
113
|
+
|
|
114
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@babel/template")):"function"==typeof define&&define.amd?define(["@babel/template"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).jotaiBabelPreset=t(e._templateBuilder)}(this,function(e){"use strict";function t(e,t,i){void 0===i&&(i=[]);var n=[].concat(a,i);if(e.isIdentifier(t)&&n.includes(t.name))return!0;if(e.isMemberExpression(t)){var o=t.property;if(e.isIdentifier(o)&&n.includes(o.name))return!0}return!1}var a=["atom","atomFamily","atomWithDefault","atomWithObservable","atomWithReducer","atomWithReset","atomWithStorage","freezeAtom","loadable","selectAtom","splitAtom","unwrap","atomWithMachine","atomWithImmer","atomWithProxy","atomWithQuery","atomWithMutation","atomWithSubscription","atomWithStore","atomWithHash","atomWithLocation","focusAtom","atomWithValidate","validateAtoms","atomWithCache","atomWithRecoilValue"],i=e.default||e;function n(e,a){var n=e.types;return console.warn("[DEPRECATED] jotai/babel/plugin-debug-label is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{visitor:{ExportDefaultDeclaration:function(e,o){var r=e.node;if(n.isCallExpression(r.declaration)&&t(n,r.declaration.callee,null==a?void 0:a.customAtomNames)){var l=(o.filename||"unknown").replace(/\.\w+$/,""),s=l.split("/").pop();"index"===s&&(s=l.slice(0,-6).split("/").pop()||"unknown");var m=i("\n const %%atomIdentifier%% = %%atom%%;\n export default %%atomIdentifier%%\n ")({atomIdentifier:n.identifier(s),atom:r.declaration});e.replaceWithMultiple(m)}},VariableDeclarator:function(e){n.isIdentifier(e.node.id)&&n.isCallExpression(e.node.init)&&t(n,e.node.init.callee,null==a?void 0:a.customAtomNames)&&e.parentPath.insertAfter(n.expressionStatement(n.assignmentExpression("=",n.memberExpression(n.identifier(e.node.id.name),n.identifier("debugLabel")),n.stringLiteral(e.node.id.name))))}}}}var o=e.default||e;function r(e,a){var i=e.types;return console.warn("[DEPRECATED] jotai/babel/plugin-react-refresh is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{pre:function(e){if(!e.opts.filename)throw new Error("Filename must be available")},visitor:{Program:{exit:function(e){var t=o("\n globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {\n cache: new Map(),\n get(name, inst) { \n if (this.cache.has(name)) {\n return this.cache.get(name)\n }\n this.cache.set(name, inst)\n return inst\n },\n }")();e.unshiftContainer("body",t)}},ExportDefaultDeclaration:function(e,n){var r=e.node;if(i.isCallExpression(r.declaration)&&t(i,r.declaration.callee,null==a?void 0:a.customAtomNames)){var l=(n.filename||"unknown")+"/defaultExport",s=o("export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomKey:i.stringLiteral(l),atom:r.declaration});e.replaceWith(s)}},VariableDeclarator:function(e,n){var r,l;if(i.isIdentifier(e.node.id)&&i.isCallExpression(e.node.init)&&t(i,e.node.init.callee,null==a?void 0:a.customAtomNames)&&(null!=(r=e.parentPath.parentPath)&&r.isProgram()||null!=(l=e.parentPath.parentPath)&&l.isExportNamedDeclaration())){var s=(n.filename||"unknown")+"/"+e.node.id.name,m=o("const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)")({atomIdentifier:i.identifier(e.node.id.name),atomKey:i.stringLiteral(s),atom:e.node.init});e.parentPath.replaceWith(m)}}}}}return function(e,t){return console.warn("[DEPRECATED] jotai/babel/preset is deprecated and will be removed in v3.\nPlease use the `jotai-babel` package instead: https://github.com/jotaijs/jotai-babel"),{plugins:[[n,t],[r,t]]}}});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jotai/vanilla'), require('jotai/react')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'jotai/vanilla', 'jotai/react'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotai = {}, global.jotaiVanilla, global.jotaiReact));
|
|
5
|
+
})(this, (function (exports, vanilla, react) { 'use strict';
|
|
6
|
+
|
|
7
|
+
Object.keys(vanilla).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return vanilla[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
Object.keys(react).forEach(function (k) {
|
|
14
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return react[k]; }
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai/vanilla"),require("jotai/react")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla","jotai/react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotai={},e.jotaiVanilla,e.jotaiReact)}(this,function(e,t,o){"use strict";Object.keys(t).forEach(function(o){"default"===o||Object.prototype.hasOwnProperty.call(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[o]}})}),Object.keys(o).forEach(function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return o[t]}})})});
|