This commit is contained in:
nik
2025-10-03 22:27:28 +03:00
parent 829fad0e17
commit 871cf7e792
16520 changed files with 2967597 additions and 3 deletions

View File

@@ -0,0 +1,4 @@
import babel from '@babel/core';
import type { PluginObj } from '@babel/core';
import type { PluginOptions } from './utils.mjs';
export default function debugLabelPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;

100
node_modules/jotai/esm/babel/plugin-debug-label.mjs generated vendored Normal file
View File

@@ -0,0 +1,100 @@
import '@babel/core';
import _templateBuilder from '@babel/template';
function isAtom(t, callee, customAtomNames = []) {
const atomNames = [...atomFunctionNames, ...customAtomNames];
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
return true;
}
if (t.isMemberExpression(callee)) {
const { property } = callee;
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
return true;
}
}
return false;
}
const atomFunctionNames = [
// Core
"atom",
"atomFamily",
"atomWithDefault",
"atomWithObservable",
"atomWithReducer",
"atomWithReset",
"atomWithStorage",
"freezeAtom",
"loadable",
"selectAtom",
"splitAtom",
"unwrap",
// jotai-xstate
"atomWithMachine",
// jotai-immer
"atomWithImmer",
// jotai-valtio
"atomWithProxy",
// jotai-trpc + jotai-relay
"atomWithQuery",
"atomWithMutation",
"atomWithSubscription",
// jotai-redux + jotai-zustand
"atomWithStore",
// jotai-location
"atomWithHash",
"atomWithLocation",
// jotai-optics
"focusAtom",
// jotai-form
"atomWithValidate",
"validateAtoms",
// jotai-cache
"atomWithCache",
// jotai-recoil
"atomWithRecoilValue"
];
const templateBuilder = _templateBuilder.default || _templateBuilder;
function debugLabelPlugin({ types: t }, options) {
return {
visitor: {
ExportDefaultDeclaration(nodePath, state) {
const { node } = nodePath;
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
const filename = (state.filename || "unknown").replace(/\.\w+$/, "");
let displayName = filename.split("/").pop();
if (displayName === "index") {
displayName = filename.slice(0, -"/index".length).split("/").pop() || "unknown";
}
const buildExport = templateBuilder(`
const %%atomIdentifier%% = %%atom%%;
export default %%atomIdentifier%%
`);
const ast = buildExport({
atomIdentifier: t.identifier(displayName),
atom: node.declaration
});
nodePath.replaceWithMultiple(ast);
}
},
VariableDeclarator(path) {
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
path.parentPath.insertAfter(
t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(
t.identifier(path.node.id.name),
t.identifier("debugLabel")
),
t.stringLiteral(path.node.id.name)
)
)
);
}
}
}
};
}
export { debugLabelPlugin as default };

View File

@@ -0,0 +1,4 @@
import babel from '@babel/core';
import type { PluginObj } from '@babel/core';
import type { PluginOptions } from './utils.mjs';
export default function reactRefreshPlugin({ types: t }: typeof babel, options?: PluginOptions): PluginObj;

118
node_modules/jotai/esm/babel/plugin-react-refresh.mjs generated vendored Normal file
View File

@@ -0,0 +1,118 @@
import '@babel/core';
import _templateBuilder from '@babel/template';
function isAtom(t, callee, customAtomNames = []) {
const atomNames = [...atomFunctionNames, ...customAtomNames];
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
return true;
}
if (t.isMemberExpression(callee)) {
const { property } = callee;
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
return true;
}
}
return false;
}
const atomFunctionNames = [
// Core
"atom",
"atomFamily",
"atomWithDefault",
"atomWithObservable",
"atomWithReducer",
"atomWithReset",
"atomWithStorage",
"freezeAtom",
"loadable",
"selectAtom",
"splitAtom",
"unwrap",
// jotai-xstate
"atomWithMachine",
// jotai-immer
"atomWithImmer",
// jotai-valtio
"atomWithProxy",
// jotai-trpc + jotai-relay
"atomWithQuery",
"atomWithMutation",
"atomWithSubscription",
// jotai-redux + jotai-zustand
"atomWithStore",
// jotai-location
"atomWithHash",
"atomWithLocation",
// jotai-optics
"focusAtom",
// jotai-form
"atomWithValidate",
"validateAtoms",
// jotai-cache
"atomWithCache",
// jotai-recoil
"atomWithRecoilValue"
];
const templateBuilder = _templateBuilder.default || _templateBuilder;
function reactRefreshPlugin({ types: t }, options) {
return {
pre({ opts }) {
if (!opts.filename) {
throw new Error("Filename must be available");
}
},
visitor: {
Program: {
exit(path) {
const jotaiAtomCache = templateBuilder(`
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
cache: new Map(),
get(name, inst) {
if (this.cache.has(name)) {
return this.cache.get(name)
}
this.cache.set(name, inst)
return inst
},
}`)();
path.unshiftContainer("body", jotaiAtomCache);
}
},
ExportDefaultDeclaration(nodePath, state) {
const { node } = nodePath;
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
const filename = state.filename || "unknown";
const atomKey = `${filename}/defaultExport`;
const buildExport = templateBuilder(
`export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
);
const ast = buildExport({
atomKey: t.stringLiteral(atomKey),
atom: node.declaration
});
nodePath.replaceWith(ast);
}
},
VariableDeclarator(nodePath, state) {
var _a, _b;
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && // Make sure atom declaration is in module scope
(((_a = nodePath.parentPath.parentPath) == null ? void 0 : _a.isProgram()) || ((_b = nodePath.parentPath.parentPath) == null ? void 0 : _b.isExportNamedDeclaration()))) {
const filename = state.filename || "unknown";
const atomKey = `${filename}/${nodePath.node.id.name}`;
const buildAtomDeclaration = templateBuilder(
`const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
);
const ast = buildAtomDeclaration({
atomIdentifier: t.identifier(nodePath.node.id.name),
atomKey: t.stringLiteral(atomKey),
atom: nodePath.node.init
});
nodePath.parentPath.replaceWith(ast);
}
}
}
};
}
export { reactRefreshPlugin as default };

5
node_modules/jotai/esm/babel/preset.d.mts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import babel from '@babel/core';
import type { PluginOptions } from './utils.mjs';
export default function jotaiPreset(_: typeof babel, options?: PluginOptions): {
plugins: babel.PluginItem[];
};

170
node_modules/jotai/esm/babel/preset.mjs generated vendored Normal file
View File

@@ -0,0 +1,170 @@
import '@babel/core';
import _templateBuilder from '@babel/template';
function isAtom(t, callee, customAtomNames = []) {
const atomNames = [...atomFunctionNames, ...customAtomNames];
if (t.isIdentifier(callee) && atomNames.includes(callee.name)) {
return true;
}
if (t.isMemberExpression(callee)) {
const { property } = callee;
if (t.isIdentifier(property) && atomNames.includes(property.name)) {
return true;
}
}
return false;
}
const atomFunctionNames = [
// Core
"atom",
"atomFamily",
"atomWithDefault",
"atomWithObservable",
"atomWithReducer",
"atomWithReset",
"atomWithStorage",
"freezeAtom",
"loadable",
"selectAtom",
"splitAtom",
"unwrap",
// jotai-xstate
"atomWithMachine",
// jotai-immer
"atomWithImmer",
// jotai-valtio
"atomWithProxy",
// jotai-trpc + jotai-relay
"atomWithQuery",
"atomWithMutation",
"atomWithSubscription",
// jotai-redux + jotai-zustand
"atomWithStore",
// jotai-location
"atomWithHash",
"atomWithLocation",
// jotai-optics
"focusAtom",
// jotai-form
"atomWithValidate",
"validateAtoms",
// jotai-cache
"atomWithCache",
// jotai-recoil
"atomWithRecoilValue"
];
const templateBuilder$1 = _templateBuilder.default || _templateBuilder;
function debugLabelPlugin({ types: t }, options) {
return {
visitor: {
ExportDefaultDeclaration(nodePath, state) {
const { node } = nodePath;
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
const filename = (state.filename || "unknown").replace(/\.\w+$/, "");
let displayName = filename.split("/").pop();
if (displayName === "index") {
displayName = filename.slice(0, -"/index".length).split("/").pop() || "unknown";
}
const buildExport = templateBuilder$1(`
const %%atomIdentifier%% = %%atom%%;
export default %%atomIdentifier%%
`);
const ast = buildExport({
atomIdentifier: t.identifier(displayName),
atom: node.declaration
});
nodePath.replaceWithMultiple(ast);
}
},
VariableDeclarator(path) {
if (t.isIdentifier(path.node.id) && t.isCallExpression(path.node.init) && isAtom(t, path.node.init.callee, options == null ? void 0 : options.customAtomNames)) {
path.parentPath.insertAfter(
t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(
t.identifier(path.node.id.name),
t.identifier("debugLabel")
),
t.stringLiteral(path.node.id.name)
)
)
);
}
}
}
};
}
const templateBuilder = _templateBuilder.default || _templateBuilder;
function reactRefreshPlugin({ types: t }, options) {
return {
pre({ opts }) {
if (!opts.filename) {
throw new Error("Filename must be available");
}
},
visitor: {
Program: {
exit(path) {
const jotaiAtomCache = templateBuilder(`
globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || {
cache: new Map(),
get(name, inst) {
if (this.cache.has(name)) {
return this.cache.get(name)
}
this.cache.set(name, inst)
return inst
},
}`)();
path.unshiftContainer("body", jotaiAtomCache);
}
},
ExportDefaultDeclaration(nodePath, state) {
const { node } = nodePath;
if (t.isCallExpression(node.declaration) && isAtom(t, node.declaration.callee, options == null ? void 0 : options.customAtomNames)) {
const filename = state.filename || "unknown";
const atomKey = `${filename}/defaultExport`;
const buildExport = templateBuilder(
`export default globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
);
const ast = buildExport({
atomKey: t.stringLiteral(atomKey),
atom: node.declaration
});
nodePath.replaceWith(ast);
}
},
VariableDeclarator(nodePath, state) {
var _a, _b;
if (t.isIdentifier(nodePath.node.id) && t.isCallExpression(nodePath.node.init) && isAtom(t, nodePath.node.init.callee, options == null ? void 0 : options.customAtomNames) && // Make sure atom declaration is in module scope
(((_a = nodePath.parentPath.parentPath) == null ? void 0 : _a.isProgram()) || ((_b = nodePath.parentPath.parentPath) == null ? void 0 : _b.isExportNamedDeclaration()))) {
const filename = state.filename || "unknown";
const atomKey = `${filename}/${nodePath.node.id.name}`;
const buildAtomDeclaration = templateBuilder(
`const %%atomIdentifier%% = globalThis.jotaiAtomCache.get(%%atomKey%%, %%atom%%)`
);
const ast = buildAtomDeclaration({
atomIdentifier: t.identifier(nodePath.node.id.name),
atomKey: t.stringLiteral(atomKey),
atom: nodePath.node.init
});
nodePath.parentPath.replaceWith(ast);
}
}
}
};
}
function jotaiPreset(_, options) {
return {
plugins: [
[debugLabelPlugin, options],
[reactRefreshPlugin, options]
]
};
}
export { jotaiPreset as default };

5
node_modules/jotai/esm/babel/utils.d.mts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import { types } from '@babel/core';
export interface PluginOptions {
customAtomNames?: string[];
}
export declare function isAtom(t: typeof types, callee: babel.types.Expression | babel.types.V8IntrinsicIdentifier, customAtomNames?: PluginOptions['customAtomNames']): boolean;

2
node_modules/jotai/esm/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from 'jotai/vanilla';
export * from 'jotai/react';

2
node_modules/jotai/esm/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from 'jotai/vanilla';
export * from 'jotai/react';

4
node_modules/jotai/esm/react.d.mts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export { Provider, useStore } from './react/Provider.mjs';
export { useAtomValue } from './react/useAtomValue.mjs';
export { useSetAtom } from './react/useSetAtom.mjs';
export { useAtom } from './react/useAtom.mjs';

171
node_modules/jotai/esm/react.mjs generated vendored Normal file
View File

@@ -0,0 +1,171 @@
'use client';
import React, { createContext, useContext, useRef, createElement, useReducer, useEffect, useDebugValue, useCallback } from 'react';
import { getDefaultStore, createStore } from 'jotai/vanilla';
import { INTERNAL_registerAbortHandler } from 'jotai/vanilla/internals';
const StoreContext = createContext(
void 0
);
function useStore(options) {
const store = useContext(StoreContext);
return (options == null ? void 0 : options.store) || store || getDefaultStore();
}
function Provider({
children,
store
}) {
const storeRef = useRef(void 0);
if (!store && !storeRef.current) {
storeRef.current = createStore();
}
return createElement(
StoreContext.Provider,
{
value: store || storeRef.current
},
children
);
}
const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
const attachPromiseStatus = (promise) => {
if (!promise.status) {
promise.status = "pending";
promise.then(
(v) => {
promise.status = "fulfilled";
promise.value = v;
},
(e) => {
promise.status = "rejected";
promise.reason = e;
}
);
}
};
const use = React.use || // A shim for older React versions
((promise) => {
if (promise.status === "pending") {
throw promise;
} else if (promise.status === "fulfilled") {
return promise.value;
} else if (promise.status === "rejected") {
throw promise.reason;
} else {
attachPromiseStatus(promise);
throw promise;
}
});
const continuablePromiseMap = /* @__PURE__ */ new WeakMap();
const createContinuablePromise = (promise, getValue) => {
let continuablePromise = continuablePromiseMap.get(promise);
if (!continuablePromise) {
continuablePromise = new Promise((resolve, reject) => {
let curr = promise;
const onFulfilled = (me) => (v) => {
if (curr === me) {
resolve(v);
}
};
const onRejected = (me) => (e) => {
if (curr === me) {
reject(e);
}
};
const onAbort = () => {
try {
const nextValue = getValue();
if (isPromiseLike(nextValue)) {
continuablePromiseMap.set(nextValue, continuablePromise);
curr = nextValue;
nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
INTERNAL_registerAbortHandler(nextValue, onAbort);
} else {
resolve(nextValue);
}
} catch (e) {
reject(e);
}
};
promise.then(onFulfilled(promise), onRejected(promise));
INTERNAL_registerAbortHandler(promise, onAbort);
});
continuablePromiseMap.set(promise, continuablePromise);
}
return continuablePromise;
};
function useAtomValue(atom, options) {
const { delay, unstable_promiseStatus: promiseStatus = !React.use } = options || {};
const store = useStore(options);
const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = useReducer(
(prev) => {
const nextValue = store.get(atom);
if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
return prev;
}
return [nextValue, store, atom];
},
void 0,
() => [store.get(atom), store, atom]
);
let value = valueFromReducer;
if (storeFromReducer !== store || atomFromReducer !== atom) {
rerender();
value = store.get(atom);
}
useEffect(() => {
const unsub = store.sub(atom, () => {
if (promiseStatus) {
try {
const value2 = store.get(atom);
if (isPromiseLike(value2)) {
attachPromiseStatus(
createContinuablePromise(value2, () => store.get(atom))
);
}
} catch (e) {
}
}
if (typeof delay === "number") {
setTimeout(rerender, delay);
return;
}
rerender();
});
rerender();
return unsub;
}, [store, atom, delay, promiseStatus]);
useDebugValue(value);
if (isPromiseLike(value)) {
const promise = createContinuablePromise(value, () => store.get(atom));
if (promiseStatus) {
attachPromiseStatus(promise);
}
return use(promise);
}
return value;
}
function useSetAtom(atom, options) {
const store = useStore(options);
const setAtom = useCallback(
(...args) => {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !("write" in atom)) {
throw new Error("not writable atom");
}
return store.set(atom, ...args);
},
[store, atom]
);
return setAtom;
}
function useAtom(atom, options) {
return [
useAtomValue(atom, options),
// We do wrong type assertion here, which results in throwing an error.
useSetAtom(atom, options)
];
}
export { Provider, useAtom, useAtomValue, useSetAtom, useStore };

16
node_modules/jotai/esm/react/Provider.d.mts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import type { FunctionComponent, ReactElement, ReactNode } from 'react';
import { createStore } from 'jotai/vanilla';
type Store = ReturnType<typeof createStore>;
type Options = {
store?: Store;
};
export declare function useStore(options?: Options): Store;
export declare function Provider({ children, store, }: {
children?: ReactNode;
store?: Store;
}): ReactElement<{
value: Store | undefined;
}, FunctionComponent<{
value: Store | undefined;
}>>;
export {};

13
node_modules/jotai/esm/react/useAtom.d.mts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import type { Atom, ExtractAtomArgs, ExtractAtomResult, ExtractAtomValue, PrimitiveAtom, SetStateAction, WritableAtom } from 'jotai/vanilla';
import { useAtomValue } from './useAtomValue.mjs';
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
type Options = Parameters<typeof useAtomValue>[1];
export declare function useAtom<Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, options?: Options): [Awaited<Value>, SetAtom<Args, Result>];
export declare function useAtom<Value>(atom: PrimitiveAtom<Value>, options?: Options): [Awaited<Value>, SetAtom<[SetStateAction<Value>], void>];
export declare function useAtom<Value>(atom: Atom<Value>, options?: Options): [Awaited<Value>, never];
export declare function useAtom<AtomType extends WritableAtom<unknown, never[], unknown>>(atom: AtomType, options?: Options): [
Awaited<ExtractAtomValue<AtomType>>,
SetAtom<ExtractAtomArgs<AtomType>, ExtractAtomResult<AtomType>>
];
export declare function useAtom<AtomType extends Atom<unknown>>(atom: AtomType, options?: Options): [Awaited<ExtractAtomValue<AtomType>>, never];
export {};

9
node_modules/jotai/esm/react/useAtomValue.d.mts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { Atom, ExtractAtomValue } from 'jotai/vanilla';
import { useStore } from './Provider.mjs';
type Options = Parameters<typeof useStore>[0] & {
delay?: number;
unstable_promiseStatus?: boolean;
};
export declare function useAtomValue<Value>(atom: Atom<Value>, options?: Options): Awaited<Value>;
export declare function useAtomValue<AtomType extends Atom<unknown>>(atom: AtomType, options?: Options): Awaited<ExtractAtomValue<AtomType>>;
export {};

7
node_modules/jotai/esm/react/useSetAtom.d.mts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
import type { ExtractAtomArgs, ExtractAtomResult, WritableAtom } from 'jotai/vanilla';
import { useStore } from './Provider.mjs';
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
type Options = Parameters<typeof useStore>[0];
export declare function useSetAtom<Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, options?: Options): SetAtom<Args, Result>;
export declare function useSetAtom<AtomType extends WritableAtom<unknown, never[], unknown>>(atom: AtomType, options?: Options): SetAtom<ExtractAtomArgs<AtomType>, ExtractAtomResult<AtomType>>;
export {};

4
node_modules/jotai/esm/react/utils.d.mts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export { useResetAtom } from './utils/useResetAtom.mjs';
export { useReducerAtom } from './utils/useReducerAtom.mjs';
export { useAtomCallback } from './utils/useAtomCallback.mjs';
export { useHydrateAtoms } from './utils/useHydrateAtoms.mjs';

57
node_modules/jotai/esm/react/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,57 @@
'use client';
import { useCallback, useMemo } from 'react';
import { useSetAtom, useAtom, useStore } from 'jotai/react';
import { RESET } from 'jotai/vanilla/utils';
import { atom } from 'jotai/vanilla';
function useResetAtom(anAtom, options) {
const setAtom = useSetAtom(anAtom, options);
const resetAtom = useCallback(() => setAtom(RESET), [setAtom]);
return resetAtom;
}
function useReducerAtom(anAtom, reducer, options) {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
console.warn(
"[DEPRECATED] useReducerAtom is deprecated and will be removed in the future. Please create your own version using the recipe. https://github.com/pmndrs/jotai/pull/2467"
);
}
const [state, setState] = useAtom(anAtom, options);
const dispatch = useCallback(
(action) => {
setState((prev) => reducer(prev, action));
},
[setState, reducer]
);
return [state, dispatch];
}
function useAtomCallback(callback, options) {
const anAtom = useMemo(
() => atom(null, (get, set, ...args) => callback(get, set, ...args)),
[callback]
);
return useSetAtom(anAtom, options);
}
const hydratedMap = /* @__PURE__ */ new WeakMap();
function useHydrateAtoms(values, options) {
const store = useStore(options);
const hydratedSet = getHydratedSet(store);
for (const [atom, ...args] of values) {
if (!hydratedSet.has(atom) || (options == null ? void 0 : options.dangerouslyForceHydrate)) {
hydratedSet.add(atom);
store.set(atom, ...args);
}
}
}
const getHydratedSet = (store) => {
let hydratedSet = hydratedMap.get(store);
if (!hydratedSet) {
hydratedSet = /* @__PURE__ */ new WeakSet();
hydratedMap.set(store, hydratedSet);
}
return hydratedSet;
};
export { useAtomCallback, useHydrateAtoms, useReducerAtom, useResetAtom };

View File

@@ -0,0 +1,5 @@
import { useSetAtom } from 'jotai/react';
import type { Getter, Setter } from 'jotai/vanilla';
type Options = Parameters<typeof useSetAtom>[1];
export declare function useAtomCallback<Result, Args extends unknown[]>(callback: (get: Getter, set: Setter, ...arg: Args) => Result, options?: Options): (...args: Args) => Result;
export {};

View File

@@ -0,0 +1,14 @@
import { useStore } from 'jotai/react';
import { type WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useStore>[0] & {
dangerouslyForceHydrate?: boolean;
};
type AnyWritableAtom = WritableAtom<any, any[], any>;
type InferAtomTuples<T> = {
[K in keyof T]: T[K] extends readonly [infer A, ...infer Rest] ? A extends WritableAtom<unknown, infer Args, unknown> ? Rest extends Args ? readonly [A, ...Rest] : never : T[K] : never;
};
export type INTERNAL_InferAtomTuples<T> = InferAtomTuples<T>;
export declare function useHydrateAtoms<T extends (readonly [AnyWritableAtom, ...unknown[]])[]>(values: InferAtomTuples<T>, options?: Options): void;
export declare function useHydrateAtoms<T extends Map<AnyWritableAtom, unknown>>(values: T, options?: Options): void;
export declare function useHydrateAtoms<T extends Iterable<readonly [AnyWritableAtom, ...unknown[]]>>(values: InferAtomTuples<T>, options?: Options): void;
export {};

View File

@@ -0,0 +1,14 @@
import { useAtom } from 'jotai/react';
import type { PrimitiveAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useAtom>[1];
/**
* @deprecated please use a recipe instead
* https://github.com/pmndrs/jotai/pull/2467
*/
export declare function useReducerAtom<Value, Action>(anAtom: PrimitiveAtom<Value>, reducer: (v: Value, a?: Action) => Value, options?: Options): [Value, (action?: Action) => void];
/**
* @deprecated please use a recipe instead
* https://github.com/pmndrs/jotai/pull/2467
*/
export declare function useReducerAtom<Value, Action>(anAtom: PrimitiveAtom<Value>, reducer: (v: Value, a: Action) => Value, options?: Options): [Value, (action: Action) => void];
export {};

View File

@@ -0,0 +1,6 @@
import { useSetAtom } from 'jotai/react';
import { RESET } from 'jotai/vanilla/utils';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useSetAtom>[1];
export declare function useResetAtom<T>(anAtom: WritableAtom<unknown, [typeof RESET], T>, options?: Options): () => T;
export {};

2
node_modules/jotai/esm/utils.d.mts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from 'jotai/vanilla/utils';
export * from 'jotai/react/utils';

2
node_modules/jotai/esm/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from 'jotai/vanilla/utils';
export * from 'jotai/react/utils';

4
node_modules/jotai/esm/vanilla.d.mts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export { atom } from './vanilla/atom.mjs';
export type { Atom, WritableAtom, PrimitiveAtom } from './vanilla/atom.mjs';
export { createStore, getDefaultStore, INTERNAL_overrideCreateStore, } from './vanilla/store.mjs';
export type { Getter, Setter, ExtractAtomValue, ExtractAtomArgs, ExtractAtomResult, SetStateAction, } from './vanilla/typeUtils.mjs';

59
node_modules/jotai/esm/vanilla.mjs generated vendored Normal file
View File

@@ -0,0 +1,59 @@
import { INTERNAL_buildStoreRev2 } from 'jotai/vanilla/internals';
let keyCount = 0;
function atom(read, write) {
const key = `atom${++keyCount}`;
const config = {
toString() {
return (import.meta.env ? import.meta.env.MODE : void 0) !== "production" && this.debugLabel ? key + ":" + this.debugLabel : key;
}
};
if (typeof read === "function") {
config.read = read;
} else {
config.init = read;
config.read = defaultRead;
config.write = defaultWrite;
}
if (write) {
config.write = write;
}
return config;
}
function defaultRead(get) {
return get(this);
}
function defaultWrite(get, set, arg) {
return set(
this,
typeof arg === "function" ? arg(get(this)) : arg
);
}
let overiddenCreateStore;
function INTERNAL_overrideCreateStore(fn) {
overiddenCreateStore = fn(overiddenCreateStore);
}
function createStore() {
if (overiddenCreateStore) {
return overiddenCreateStore();
}
return INTERNAL_buildStoreRev2();
}
let defaultStore;
function getDefaultStore() {
if (!defaultStore) {
defaultStore = createStore();
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = defaultStore);
if (globalThis.__JOTAI_DEFAULT_STORE__ !== defaultStore) {
console.warn(
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
);
}
}
}
return defaultStore;
}
export { INTERNAL_overrideCreateStore, atom, createStore, getDefaultStore };

47
node_modules/jotai/esm/vanilla/atom.d.mts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import type { Store } from './store.mjs';
type Getter = <Value>(atom: Atom<Value>) => Value;
type Setter = <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
type SetAtom<Args extends unknown[], Result> = <A extends Args>(...args: A) => Result;
/**
* setSelf is for internal use only and subject to change without notice.
*/
type Read<Value, SetSelf = never> = (get: Getter, options: {
readonly signal: AbortSignal;
readonly setSelf: SetSelf;
}) => Value;
type Write<Args extends unknown[], Result> = (get: Getter, set: Setter, ...args: Args) => Result;
type WithInitialValue<Value> = {
init: Value;
};
type OnUnmount = () => void;
type OnMount<Args extends unknown[], Result> = <S extends SetAtom<Args, Result>>(setAtom: S) => OnUnmount | void;
export interface Atom<Value> {
toString: () => string;
read: Read<Value>;
debugLabel?: string;
/**
* To ONLY be used by Jotai libraries to mark atoms as private. Subject to change.
* @private
*/
debugPrivate?: boolean;
/**
* Fires after atom is referenced by the store for the first time
* This is still an experimental API and subject to change without notice.
*/
unstable_onInit?: (store: Store) => void;
}
export interface WritableAtom<Value, Args extends unknown[], Result> extends Atom<Value> {
read: Read<Value, SetAtom<Args, Result>>;
write: Write<Args, Result>;
onMount?: OnMount<Args, Result>;
}
type SetStateAction<Value> = Value | ((prev: Value) => Value);
export type PrimitiveAtom<Value> = WritableAtom<Value, [
SetStateAction<Value>
], void>;
export declare function atom<Value, Args extends unknown[], Result>(read: Read<Value, SetAtom<Args, Result>>, write: Write<Args, Result>): WritableAtom<Value, Args, Result>;
export declare function atom<Value>(read: Read<Value>): Atom<Value>;
export declare function atom<Value, Args extends unknown[], Result>(initialValue: Value, write: Write<Args, Result>): WritableAtom<Value, Args, Result> & WithInitialValue<Value>;
export declare function atom<Value>(): PrimitiveAtom<Value | undefined> & WithInitialValue<Value | undefined>;
export declare function atom<Value>(initialValue: Value): PrimitiveAtom<Value> & WithInitialValue<Value>;
export {};

173
node_modules/jotai/esm/vanilla/internals.d.mts generated vendored Normal file
View File

@@ -0,0 +1,173 @@
import type { Atom, WritableAtom } from './atom.mjs';
type AnyValue = unknown;
type AnyError = unknown;
type AnyAtom = Atom<AnyValue>;
type AnyWritableAtom = WritableAtom<AnyValue, unknown[], unknown>;
type OnUnmount = () => void;
type EpochNumber = number;
/**
* Mutable atom state,
* tracked for both mounted and unmounted atoms in a store.
*
* This should be garbage collectable.
* We can mutate it during atom read. (except for fields with TODO)
*/
type AtomState<Value = AnyValue> = {
/**
* Map of atoms that the atom depends on.
* The map value is the epoch number of the dependency.
*/
readonly d: Map<AnyAtom, EpochNumber>;
/**
* Set of atoms with pending promise that depend on the atom.
*
* This may cause memory leaks, but it's for the capability to continue promises
* TODO(daishi): revisit how to handle this
*/
readonly p: Set<AnyAtom>;
/** The epoch number of the atom. */
n: EpochNumber;
/** Atom value */
v?: Value;
/** Atom error */
e?: AnyError;
};
/**
* State tracked for mounted atoms. An atom is considered "mounted" if it has a
* subscriber, or is a transitive dependency of another atom that has a
* subscriber.
* The mounted state of an atom is freed once it is no longer mounted.
*/
type Mounted = {
/** Set of listeners to notify when the atom value changes. */
readonly l: Set<() => void>;
/** Set of mounted atoms that the atom depends on. */
readonly d: Set<AnyAtom>;
/** Set of mounted atoms that depends on the atom. */
readonly t: Set<AnyAtom>;
/** Function to run when the atom is unmounted. */
u?: () => void;
};
type AtomStateMap = {
get(atom: AnyAtom): AtomState | undefined;
set(atom: AnyAtom, atomState: AtomState): void;
};
type MountedMap = {
get(atom: AnyAtom): Mounted | undefined;
has(atom: AnyAtom): boolean;
set(atom: AnyAtom, mounted: Mounted): void;
delete(atom: AnyAtom): void;
};
type InvalidatedAtoms = {
get(atom: AnyAtom): EpochNumber | undefined;
has(atom: AnyAtom): boolean;
set(atom: AnyAtom, n: EpochNumber): void;
delete(atom: AnyAtom): void;
};
type ChangedAtoms = {
readonly size: number;
add(atom: AnyAtom): void;
has(atom: AnyAtom): boolean;
clear(): void;
forEach(callback: (atom: AnyAtom) => void): void;
[Symbol.iterator](): IterableIterator<AnyAtom>;
};
type Callbacks = {
readonly size: number;
add(fn: () => void): void;
clear(): void;
forEach(callback: (fn: () => void) => void): void;
};
type AtomRead = <Value>(store: Store, atom: Atom<Value>, ...params: Parameters<Atom<Value>['read']>) => Value;
type AtomWrite = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...params: Parameters<WritableAtom<Value, Args, Result>['write']>) => Result;
type AtomOnInit = <Value>(store: Store, atom: Atom<Value>) => void;
type AtomOnMount = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, setAtom: (...args: Args) => Result) => OnUnmount | void;
type EnsureAtomState = <Value>(store: Store, atom: Atom<Value>) => AtomState<Value>;
type FlushCallbacks = (store: Store) => void;
type RecomputeInvalidatedAtoms = (store: Store) => void;
type ReadAtomState = <Value>(store: Store, atom: Atom<Value>) => AtomState<Value>;
type InvalidateDependents = (store: Store, atom: AnyAtom) => void;
type WriteAtomState = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
type MountDependencies = (store: Store, atom: AnyAtom) => void;
type MountAtom = <Value>(store: Store, atom: Atom<Value>) => Mounted;
type UnmountAtom = <Value>(store: Store, atom: Atom<Value>) => Mounted | undefined;
type SetAtomStateValueOrPromise = <Value>(store: Store, atom: Atom<Value>, valueOrPromise: Value) => void;
type StoreGet = <Value>(store: Store, atom: Atom<Value>) => Value;
type StoreSet = <Value, Args extends unknown[], Result>(store: Store, atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
type StoreSub = (store: Store, atom: AnyAtom, listener: () => void) => () => void;
type EnhanceBuildingBlocks = (buildingBlocks: Readonly<BuildingBlocks>) => Readonly<BuildingBlocks>;
type Store = {
get: <Value>(atom: Atom<Value>) => Value;
set: <Value, Args extends unknown[], Result>(atom: WritableAtom<Value, Args, Result>, ...args: Args) => Result;
sub: (atom: AnyAtom, listener: () => void) => () => void;
};
type BuildingBlocks = [
atomStateMap: AtomStateMap,
mountedMap: MountedMap,
invalidatedAtoms: InvalidatedAtoms,
changedAtoms: ChangedAtoms,
mountCallbacks: Callbacks,
unmountCallbacks: Callbacks,
storeHooks: StoreHooks,
atomRead: AtomRead,
atomWrite: AtomWrite,
atomOnInit: AtomOnInit,
atomOnMount: AtomOnMount,
ensureAtomState: EnsureAtomState,
flushCallbacks: FlushCallbacks,
recomputeInvalidatedAtoms: RecomputeInvalidatedAtoms,
readAtomState: ReadAtomState,
invalidateDependents: InvalidateDependents,
writeAtomState: WriteAtomState,
mountDependencies: MountDependencies,
mountAtom: MountAtom,
unmountAtom: UnmountAtom,
setAtomStateValueOrPromise: SetAtomStateValueOrPromise,
storeGet: StoreGet,
storeSet: StoreSet,
storeSub: StoreSub,
enhanceBuildingBlocks: EnhanceBuildingBlocks | undefined
];
export type { AtomState as INTERNAL_AtomState, Mounted as INTERNAL_Mounted, AtomStateMap as INTERNAL_AtomStateMap, MountedMap as INTERNAL_MountedMap, InvalidatedAtoms as INTERNAL_InvalidatedAtoms, ChangedAtoms as INTERNAL_ChangedAtoms, Callbacks as INTERNAL_Callbacks, AtomRead as INTERNAL_AtomRead, AtomWrite as INTERNAL_AtomWrite, AtomOnInit as INTERNAL_AtomOnInit, AtomOnMount as INTERNAL_AtomOnMount, EnsureAtomState as INTERNAL_EnsureAtomState, FlushCallbacks as INTERNAL_FlushCallbacks, RecomputeInvalidatedAtoms as INTERNAL_RecomputeInvalidatedAtoms, ReadAtomState as INTERNAL_ReadAtomState, InvalidateDependents as INTERNAL_InvalidateDependents, WriteAtomState as INTERNAL_WriteAtomState, MountDependencies as INTERNAL_MountDependencies, MountAtom as INTERNAL_MountAtom, UnmountAtom as INTERNAL_UnmountAtom, Store as INTERNAL_Store, BuildingBlocks as INTERNAL_BuildingBlocks, StoreHooks as INTERNAL_StoreHooks, };
declare function hasInitialValue<T extends Atom<AnyValue>>(atom: T): atom is T & (T extends Atom<infer Value> ? {
init: Value;
} : never);
declare function isActuallyWritableAtom(atom: AnyAtom): atom is AnyWritableAtom;
declare function isAtomStateInitialized<Value>(atomState: AtomState<Value>): boolean;
declare function returnAtomValue<Value>(atomState: AtomState<Value>): Value;
declare const promiseStateMap: WeakMap<PromiseLike<unknown>, [
pending: boolean,
abortHandlers: Set<() => void>
]>;
declare function isPendingPromise(value: unknown): value is PromiseLike<unknown>;
declare function abortPromise<T>(promise: PromiseLike<T>): void;
declare function registerAbortHandler<T>(promise: PromiseLike<T>, abortHandler: () => void): void;
declare function isPromiseLike(p: unknown): p is PromiseLike<unknown>;
declare function addPendingPromiseToDependency(atom: AnyAtom, promise: PromiseLike<AnyValue>, dependencyAtomState: AtomState): void;
declare function getMountedOrPendingDependents(atom: AnyAtom, atomState: AtomState, mountedMap: MountedMap): Set<AnyAtom>;
type StoreHook = {
(): void;
add(callback: () => void): () => void;
};
type StoreHookForAtoms = {
(atom: AnyAtom): void;
add(atom: AnyAtom, callback: () => void): () => void;
add(atom: undefined, callback: (atom: AnyAtom) => void): () => void;
};
/** StoreHooks are an experimental API. */
type StoreHooks = {
/** Listener to notify when the atom is read. */
readonly r?: StoreHookForAtoms;
/** Listener to notify when the atom value is changed. */
readonly c?: StoreHookForAtoms;
/** Listener to notify when the atom is mounted. */
readonly m?: StoreHookForAtoms;
/** Listener to notify when the atom is unmounted. */
readonly u?: StoreHookForAtoms;
/** Listener to notify when callbacks are being flushed. */
readonly f?: StoreHook;
};
declare function initializeStoreHooks(storeHooks: StoreHooks): Required<StoreHooks>;
declare function getBuildingBlocks(store: Store): Readonly<BuildingBlocks>;
declare function buildStore(...buildArgs: Partial<BuildingBlocks>): Store;
export { buildStore as INTERNAL_buildStoreRev2, getBuildingBlocks as INTERNAL_getBuildingBlocksRev2, initializeStoreHooks as INTERNAL_initializeStoreHooksRev2, hasInitialValue as INTERNAL_hasInitialValue, isActuallyWritableAtom as INTERNAL_isActuallyWritableAtom, isAtomStateInitialized as INTERNAL_isAtomStateInitialized, returnAtomValue as INTERNAL_returnAtomValue, promiseStateMap as INTERNAL_promiseStateMap, isPendingPromise as INTERNAL_isPendingPromise, abortPromise as INTERNAL_abortPromise, registerAbortHandler as INTERNAL_registerAbortHandler, isPromiseLike as INTERNAL_isPromiseLike, addPendingPromiseToDependency as INTERNAL_addPendingPromiseToDependency, getMountedOrPendingDependents as INTERNAL_getMountedOrPendingDependents, };

656
node_modules/jotai/esm/vanilla/internals.mjs generated vendored Normal file
View File

@@ -0,0 +1,656 @@
function hasInitialValue(atom) {
return "init" in atom;
}
function isActuallyWritableAtom(atom) {
return !!atom.write;
}
function isAtomStateInitialized(atomState) {
return "v" in atomState || "e" in atomState;
}
function returnAtomValue(atomState) {
if ("e" in atomState) {
throw atomState.e;
}
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !("v" in atomState)) {
throw new Error("[Bug] atom state is not initialized");
}
return atomState.v;
}
const promiseStateMap = /* @__PURE__ */ new WeakMap();
function isPendingPromise(value) {
var _a;
return isPromiseLike(value) && !!((_a = promiseStateMap.get(value)) == null ? void 0 : _a[0]);
}
function abortPromise(promise) {
const promiseState = promiseStateMap.get(promise);
if (promiseState == null ? void 0 : promiseState[0]) {
promiseState[0] = false;
promiseState[1].forEach((fn) => fn());
}
}
function registerAbortHandler(promise, abortHandler) {
let promiseState = promiseStateMap.get(promise);
if (!promiseState) {
promiseState = [true, /* @__PURE__ */ new Set()];
promiseStateMap.set(promise, promiseState);
const settle = () => {
promiseState[0] = false;
};
promise.then(settle, settle);
}
promiseState[1].add(abortHandler);
}
function isPromiseLike(p) {
return typeof (p == null ? void 0 : p.then) === "function";
}
function addPendingPromiseToDependency(atom, promise, dependencyAtomState) {
if (!dependencyAtomState.p.has(atom)) {
dependencyAtomState.p.add(atom);
const cleanup = () => dependencyAtomState.p.delete(atom);
promise.then(cleanup, cleanup);
}
}
function getMountedOrPendingDependents(atom, atomState, mountedMap) {
var _a;
const dependents = /* @__PURE__ */ new Set();
for (const a of ((_a = mountedMap.get(atom)) == null ? void 0 : _a.t) || []) {
if (mountedMap.has(a)) {
dependents.add(a);
}
}
for (const atomWithPendingPromise of atomState.p) {
dependents.add(atomWithPendingPromise);
}
return dependents;
}
const createStoreHook = () => {
const callbacks = /* @__PURE__ */ new Set();
const notify = () => callbacks.forEach((fn) => fn());
notify.add = (fn) => {
callbacks.add(fn);
return () => callbacks.delete(fn);
};
return notify;
};
const createStoreHookForAtoms = () => {
const all = {};
const callbacks = /* @__PURE__ */ new WeakMap();
const notify = (atom) => {
var _a, _b;
(_a = callbacks.get(all)) == null ? void 0 : _a.forEach((fn) => fn(atom));
(_b = callbacks.get(atom)) == null ? void 0 : _b.forEach((fn) => fn());
};
notify.add = (atom, fn) => {
const key = atom || all;
const fns = (callbacks.has(key) ? callbacks : callbacks.set(key, /* @__PURE__ */ new Set())).get(key);
fns.add(fn);
return () => {
fns == null ? void 0 : fns.delete(fn);
if (!fns.size) {
callbacks.delete(key);
}
};
};
return notify;
};
function initializeStoreHooks(storeHooks) {
storeHooks.r || (storeHooks.r = createStoreHookForAtoms());
storeHooks.c || (storeHooks.c = createStoreHookForAtoms());
storeHooks.m || (storeHooks.m = createStoreHookForAtoms());
storeHooks.u || (storeHooks.u = createStoreHookForAtoms());
storeHooks.f || (storeHooks.f = createStoreHook());
return storeHooks;
}
const atomRead = (_store, atom, ...params) => atom.read(...params);
const atomWrite = (_store, atom, ...params) => atom.write(...params);
const atomOnInit = (store, atom) => {
var _a;
return (_a = atom.unstable_onInit) == null ? void 0 : _a.call(atom, store);
};
const atomOnMount = (_store, atom, setAtom) => {
var _a;
return (_a = atom.onMount) == null ? void 0 : _a.call(atom, setAtom);
};
const ensureAtomState = (store, atom) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const atomStateMap = buildingBlocks[0];
const atomOnInit2 = buildingBlocks[9];
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !atom) {
throw new Error("Atom is undefined or null");
}
let atomState = atomStateMap.get(atom);
if (!atomState) {
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
atomStateMap.set(atom, atomState);
atomOnInit2 == null ? void 0 : atomOnInit2(store, atom);
}
return atomState;
};
const flushCallbacks = (store) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const changedAtoms = buildingBlocks[3];
const mountCallbacks = buildingBlocks[4];
const unmountCallbacks = buildingBlocks[5];
const storeHooks = buildingBlocks[6];
const recomputeInvalidatedAtoms2 = buildingBlocks[13];
const errors = [];
const call = (fn) => {
try {
fn();
} catch (e) {
errors.push(e);
}
};
do {
if (storeHooks.f) {
call(storeHooks.f);
}
const callbacks = /* @__PURE__ */ new Set();
const add = callbacks.add.bind(callbacks);
changedAtoms.forEach((atom) => {
var _a;
return (_a = mountedMap.get(atom)) == null ? void 0 : _a.l.forEach(add);
});
changedAtoms.clear();
unmountCallbacks.forEach(add);
unmountCallbacks.clear();
mountCallbacks.forEach(add);
mountCallbacks.clear();
callbacks.forEach(call);
if (changedAtoms.size) {
recomputeInvalidatedAtoms2(store);
}
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
if (errors.length) {
throw new AggregateError(errors);
}
};
const recomputeInvalidatedAtoms = (store) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const invalidatedAtoms = buildingBlocks[2];
const changedAtoms = buildingBlocks[3];
const ensureAtomState2 = buildingBlocks[11];
const readAtomState2 = buildingBlocks[14];
const mountDependencies2 = buildingBlocks[17];
const topSortedReversed = [];
const visiting = /* @__PURE__ */ new WeakSet();
const visited = /* @__PURE__ */ new WeakSet();
const stack = Array.from(changedAtoms);
while (stack.length) {
const a = stack[stack.length - 1];
const aState = ensureAtomState2(store, a);
if (visited.has(a)) {
stack.pop();
continue;
}
if (visiting.has(a)) {
if (invalidatedAtoms.get(a) === aState.n) {
topSortedReversed.push([a, aState]);
} else if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
throw new Error("[Bug] invalidated atom exists");
}
visited.add(a);
stack.pop();
continue;
}
visiting.add(a);
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
if (!visiting.has(d)) {
stack.push(d);
}
}
}
for (let i = topSortedReversed.length - 1; i >= 0; --i) {
const [a, aState] = topSortedReversed[i];
let hasChangedDeps = false;
for (const dep of aState.d.keys()) {
if (dep !== a && changedAtoms.has(dep)) {
hasChangedDeps = true;
break;
}
}
if (hasChangedDeps) {
readAtomState2(store, a);
mountDependencies2(store, a);
}
invalidatedAtoms.delete(a);
}
};
const readAtomState = (store, atom) => {
var _a, _b;
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const invalidatedAtoms = buildingBlocks[2];
const changedAtoms = buildingBlocks[3];
const storeHooks = buildingBlocks[6];
const atomRead2 = buildingBlocks[7];
const ensureAtomState2 = buildingBlocks[11];
const flushCallbacks2 = buildingBlocks[12];
const recomputeInvalidatedAtoms2 = buildingBlocks[13];
const readAtomState2 = buildingBlocks[14];
const writeAtomState2 = buildingBlocks[16];
const mountDependencies2 = buildingBlocks[17];
const atomState = ensureAtomState2(store, atom);
if (isAtomStateInitialized(atomState)) {
if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
return atomState;
}
if (Array.from(atomState.d).every(
([a, n]) => (
// Recursively, read the atom state of the dependency, and
// check if the atom epoch number is unchanged
readAtomState2(store, a).n === n
)
)) {
return atomState;
}
}
atomState.d.clear();
let isSync = true;
function mountDependenciesIfAsync() {
if (mountedMap.has(atom)) {
mountDependencies2(store, atom);
recomputeInvalidatedAtoms2(store);
flushCallbacks2(store);
}
}
function getter(a) {
var _a2;
if (a === atom) {
const aState2 = ensureAtomState2(store, a);
if (!isAtomStateInitialized(aState2)) {
if (hasInitialValue(a)) {
setAtomStateValueOrPromise(store, a, a.init);
} else {
throw new Error("no atom init");
}
}
return returnAtomValue(aState2);
}
const aState = readAtomState2(store, a);
try {
return returnAtomValue(aState);
} finally {
atomState.d.set(a, aState.n);
if (isPendingPromise(atomState.v)) {
addPendingPromiseToDependency(atom, atomState.v, aState);
}
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom);
if (!isSync) {
mountDependenciesIfAsync();
}
}
}
let controller;
let setSelf;
const options = {
get signal() {
if (!controller) {
controller = new AbortController();
}
return controller.signal;
},
get setSelf() {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom)) {
console.warn("setSelf function cannot be used with read-only atom");
}
if (!setSelf && isActuallyWritableAtom(atom)) {
setSelf = (...args) => {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && isSync) {
console.warn("setSelf function cannot be called in sync");
}
if (!isSync) {
try {
return writeAtomState2(store, atom, ...args);
} finally {
recomputeInvalidatedAtoms2(store);
flushCallbacks2(store);
}
}
};
}
return setSelf;
}
};
const prevEpochNumber = atomState.n;
try {
const valueOrPromise = atomRead2(store, atom, getter, options);
setAtomStateValueOrPromise(store, atom, valueOrPromise);
if (isPromiseLike(valueOrPromise)) {
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
valueOrPromise.then(mountDependenciesIfAsync, mountDependenciesIfAsync);
}
(_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
return atomState;
} catch (error) {
delete atomState.v;
atomState.e = error;
++atomState.n;
return atomState;
} finally {
isSync = false;
if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
invalidatedAtoms.set(atom, atomState.n);
changedAtoms.add(atom);
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
}
}
};
const invalidateDependents = (store, atom) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const invalidatedAtoms = buildingBlocks[2];
const ensureAtomState2 = buildingBlocks[11];
const stack = [atom];
while (stack.length) {
const a = stack.pop();
const aState = ensureAtomState2(store, a);
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
const dState = ensureAtomState2(store, d);
invalidatedAtoms.set(d, dState.n);
stack.push(d);
}
}
};
const writeAtomState = (store, atom, ...args) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const changedAtoms = buildingBlocks[3];
const storeHooks = buildingBlocks[6];
const atomWrite2 = buildingBlocks[8];
const ensureAtomState2 = buildingBlocks[11];
const flushCallbacks2 = buildingBlocks[12];
const recomputeInvalidatedAtoms2 = buildingBlocks[13];
const readAtomState2 = buildingBlocks[14];
const invalidateDependents2 = buildingBlocks[15];
const mountDependencies2 = buildingBlocks[17];
let isSync = true;
const getter = (a) => returnAtomValue(readAtomState2(store, a));
const setter = (a, ...args2) => {
var _a;
const aState = ensureAtomState2(store, a);
try {
if (a === atom) {
if (!hasInitialValue(a)) {
throw new Error("atom not writable");
}
const prevEpochNumber = aState.n;
const v = args2[0];
setAtomStateValueOrPromise(store, a, v);
mountDependencies2(store, a);
if (prevEpochNumber !== aState.n) {
changedAtoms.add(a);
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
invalidateDependents2(store, a);
}
return void 0;
} else {
return writeAtomState(store, a, ...args2);
}
} finally {
if (!isSync) {
recomputeInvalidatedAtoms2(store);
flushCallbacks2(store);
}
}
};
try {
return atomWrite2(store, atom, getter, setter, ...args);
} finally {
isSync = false;
}
};
const mountDependencies = (store, atom) => {
var _a;
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const changedAtoms = buildingBlocks[3];
const storeHooks = buildingBlocks[6];
const ensureAtomState2 = buildingBlocks[11];
const invalidateDependents2 = buildingBlocks[15];
const mountAtom2 = buildingBlocks[18];
const unmountAtom2 = buildingBlocks[19];
const atomState = ensureAtomState2(store, atom);
const mounted = mountedMap.get(atom);
if (mounted && !isPendingPromise(atomState.v)) {
for (const [a, n] of atomState.d) {
if (!mounted.d.has(a)) {
const aState = ensureAtomState2(store, a);
const aMounted = mountAtom2(store, a);
aMounted.t.add(atom);
mounted.d.add(a);
if (n !== aState.n) {
changedAtoms.add(a);
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
invalidateDependents2(store, a);
}
}
}
for (const a of mounted.d || []) {
if (!atomState.d.has(a)) {
mounted.d.delete(a);
const aMounted = unmountAtom2(store, a);
aMounted == null ? void 0 : aMounted.t.delete(atom);
}
}
}
};
const mountAtom = (store, atom) => {
var _a;
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const mountCallbacks = buildingBlocks[4];
const storeHooks = buildingBlocks[6];
const atomOnMount2 = buildingBlocks[10];
const ensureAtomState2 = buildingBlocks[11];
const flushCallbacks2 = buildingBlocks[12];
const recomputeInvalidatedAtoms2 = buildingBlocks[13];
const readAtomState2 = buildingBlocks[14];
const writeAtomState2 = buildingBlocks[16];
const atomState = ensureAtomState2(store, atom);
let mounted = mountedMap.get(atom);
if (!mounted) {
readAtomState2(store, atom);
for (const a of atomState.d.keys()) {
const aMounted = mountAtom(store, a);
aMounted.t.add(atom);
}
mounted = {
l: /* @__PURE__ */ new Set(),
d: new Set(atomState.d.keys()),
t: /* @__PURE__ */ new Set()
};
mountedMap.set(atom, mounted);
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
if (isActuallyWritableAtom(atom)) {
const processOnMount = () => {
let isSync = true;
const setAtom = (...args) => {
try {
return writeAtomState2(store, atom, ...args);
} finally {
if (!isSync) {
recomputeInvalidatedAtoms2(store);
flushCallbacks2(store);
}
}
};
try {
const onUnmount = atomOnMount2(store, atom, setAtom);
if (onUnmount) {
mounted.u = () => {
isSync = true;
try {
onUnmount();
} finally {
isSync = false;
}
};
}
} finally {
isSync = false;
}
};
mountCallbacks.add(processOnMount);
}
}
return mounted;
};
const unmountAtom = (store, atom) => {
var _a;
const buildingBlocks = getInternalBuildingBlocks(store);
const mountedMap = buildingBlocks[1];
const unmountCallbacks = buildingBlocks[5];
const storeHooks = buildingBlocks[6];
const ensureAtomState2 = buildingBlocks[11];
const unmountAtom2 = buildingBlocks[19];
const atomState = ensureAtomState2(store, atom);
let mounted = mountedMap.get(atom);
if (mounted && !mounted.l.size && !Array.from(mounted.t).some((a) => {
var _a2;
return (_a2 = mountedMap.get(a)) == null ? void 0 : _a2.d.has(atom);
})) {
if (mounted.u) {
unmountCallbacks.add(mounted.u);
}
mounted = void 0;
mountedMap.delete(atom);
(_a = storeHooks.u) == null ? void 0 : _a.call(storeHooks, atom);
for (const a of atomState.d.keys()) {
const aMounted = unmountAtom2(store, a);
aMounted == null ? void 0 : aMounted.t.delete(atom);
}
return void 0;
}
return mounted;
};
const setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
const ensureAtomState2 = getInternalBuildingBlocks(store)[11];
const atomState = ensureAtomState2(store, atom);
const hasPrevValue = "v" in atomState;
const prevValue = atomState.v;
if (isPromiseLike(valueOrPromise)) {
for (const a of atomState.d.keys()) {
addPendingPromiseToDependency(
atom,
valueOrPromise,
ensureAtomState2(store, a)
);
}
}
atomState.v = valueOrPromise;
delete atomState.e;
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
++atomState.n;
if (isPromiseLike(prevValue)) {
abortPromise(prevValue);
}
}
};
const storeGet = (store, atom) => {
const readAtomState2 = getInternalBuildingBlocks(store)[14];
return returnAtomValue(readAtomState2(store, atom));
};
const storeSet = (store, atom, ...args) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const flushCallbacks2 = buildingBlocks[12];
const recomputeInvalidatedAtoms2 = buildingBlocks[13];
const writeAtomState2 = buildingBlocks[16];
try {
return writeAtomState2(store, atom, ...args);
} finally {
recomputeInvalidatedAtoms2(store);
flushCallbacks2(store);
}
};
const storeSub = (store, atom, listener) => {
const buildingBlocks = getInternalBuildingBlocks(store);
const flushCallbacks2 = buildingBlocks[12];
const mountAtom2 = buildingBlocks[18];
const unmountAtom2 = buildingBlocks[19];
const mounted = mountAtom2(store, atom);
const listeners = mounted.l;
listeners.add(listener);
flushCallbacks2(store);
return () => {
listeners.delete(listener);
unmountAtom2(store, atom);
flushCallbacks2(store);
};
};
const buildingBlockMap = /* @__PURE__ */ new WeakMap();
const getInternalBuildingBlocks = (store) => {
const buildingBlocks = buildingBlockMap.get(store);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && !buildingBlocks) {
throw new Error(
"Store must be created by buildStore to read its building blocks"
);
}
return buildingBlocks;
};
function getBuildingBlocks(store) {
const buildingBlocks = getInternalBuildingBlocks(store);
const enhanceBuildingBlocks = buildingBlocks[24];
if (enhanceBuildingBlocks) {
return enhanceBuildingBlocks(buildingBlocks);
}
return buildingBlocks;
}
function buildStore(...buildArgs) {
const store = {
get(atom) {
const storeGet2 = getInternalBuildingBlocks(store)[21];
return storeGet2(store, atom);
},
set(atom, ...args) {
const storeSet2 = getInternalBuildingBlocks(store)[22];
return storeSet2(store, atom, ...args);
},
sub(atom, listener) {
const storeSub2 = getInternalBuildingBlocks(store)[23];
return storeSub2(store, atom, listener);
}
};
const buildingBlocks = [
// store state
/* @__PURE__ */ new WeakMap(),
// atomStateMap
/* @__PURE__ */ new WeakMap(),
// mountedMap
/* @__PURE__ */ new WeakMap(),
// invalidatedAtoms
/* @__PURE__ */ new Set(),
// changedAtoms
/* @__PURE__ */ new Set(),
// mountCallbacks
/* @__PURE__ */ new Set(),
// unmountCallbacks
{},
// storeHooks
// atom interceptors
atomRead,
atomWrite,
atomOnInit,
atomOnMount,
// building-block functions
ensureAtomState,
flushCallbacks,
recomputeInvalidatedAtoms,
readAtomState,
invalidateDependents,
writeAtomState,
mountDependencies,
mountAtom,
unmountAtom,
setAtomStateValueOrPromise,
storeGet,
storeSet,
storeSub,
void 0
].map((fn, i) => buildArgs[i] || fn);
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
return store;
}
export { abortPromise as INTERNAL_abortPromise, addPendingPromiseToDependency as INTERNAL_addPendingPromiseToDependency, buildStore as INTERNAL_buildStoreRev2, getBuildingBlocks as INTERNAL_getBuildingBlocksRev2, getMountedOrPendingDependents as INTERNAL_getMountedOrPendingDependents, hasInitialValue as INTERNAL_hasInitialValue, initializeStoreHooks as INTERNAL_initializeStoreHooksRev2, isActuallyWritableAtom as INTERNAL_isActuallyWritableAtom, isAtomStateInitialized as INTERNAL_isAtomStateInitialized, isPendingPromise as INTERNAL_isPendingPromise, isPromiseLike as INTERNAL_isPromiseLike, promiseStateMap as INTERNAL_promiseStateMap, registerAbortHandler as INTERNAL_registerAbortHandler, returnAtomValue as INTERNAL_returnAtomValue };

5
node_modules/jotai/esm/vanilla/store.d.mts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import type { INTERNAL_Store } from 'jotai/vanilla/internals';
export type Store = INTERNAL_Store;
export declare function INTERNAL_overrideCreateStore(fn: (prev: typeof createStore | undefined) => typeof createStore): void;
export declare function createStore(): Store;
export declare function getDefaultStore(): Store;

7
node_modules/jotai/esm/vanilla/typeUtils.d.mts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
import type { Atom, PrimitiveAtom, WritableAtom } from './atom.mjs';
export type Getter = Parameters<Atom<unknown>['read']>[0];
export type Setter = Parameters<WritableAtom<unknown, unknown[], unknown>['write']>[1];
export type ExtractAtomValue<AtomType> = AtomType extends Atom<infer Value> ? Value : never;
export type ExtractAtomArgs<AtomType> = AtomType extends WritableAtom<unknown, infer Args, infer _Result> ? Args : never;
export type ExtractAtomResult<AtomType> = AtomType extends WritableAtom<unknown, infer _Args, infer Result> ? Result : never;
export type SetStateAction<Value> = ExtractAtomArgs<PrimitiveAtom<Value>>[0];

14
node_modules/jotai/esm/vanilla/utils.d.mts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
export { RESET } from './utils/constants.mjs';
export { atomWithReset } from './utils/atomWithReset.mjs';
export { atomWithReducer } from './utils/atomWithReducer.mjs';
export { atomFamily } from './utils/atomFamily.mjs';
export { selectAtom } from './utils/selectAtom.mjs';
export { freezeAtom, freezeAtomCreator } from './utils/freezeAtom.mjs';
export { splitAtom } from './utils/splitAtom.mjs';
export { atomWithDefault } from './utils/atomWithDefault.mjs';
export { atomWithStorage, createJSONStorage, withStorageValidator as unstable_withStorageValidator, } from './utils/atomWithStorage.mjs';
export { atomWithObservable } from './utils/atomWithObservable.mjs';
export { loadable } from './utils/loadable.mjs';
export { unwrap } from './utils/unwrap.mjs';
export { atomWithRefresh } from './utils/atomWithRefresh.mjs';
export { atomWithLazy } from './utils/atomWithLazy.mjs';

750
node_modules/jotai/esm/vanilla/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,750 @@
import { atom } from 'jotai/vanilla';
const RESET = Symbol(
(import.meta.env ? import.meta.env.MODE : void 0) !== "production" ? "RESET" : ""
);
function atomWithReset(initialValue) {
const anAtom = atom(
initialValue,
(get, set, update) => {
const nextValue = typeof update === "function" ? update(get(anAtom)) : update;
set(anAtom, nextValue === RESET ? initialValue : nextValue);
}
);
return anAtom;
}
function atomWithReducer(initialValue, reducer) {
return atom(initialValue, function(get, set, action) {
set(this, reducer(get(this), action));
});
}
function atomFamily(initializeAtom, areEqual) {
let shouldRemove = null;
const atoms = /* @__PURE__ */ new Map();
const listeners = /* @__PURE__ */ new Set();
const createAtom = (param) => {
let item;
if (areEqual === void 0) {
item = atoms.get(param);
} else {
for (const [key, value] of atoms) {
if (areEqual(key, param)) {
item = value;
break;
}
}
}
if (item !== void 0) {
if (shouldRemove == null ? void 0 : shouldRemove(item[1], param)) {
createAtom.remove(param);
} else {
return item[0];
}
}
const newAtom = initializeAtom(param);
atoms.set(param, [newAtom, Date.now()]);
notifyListeners("CREATE", param, newAtom);
return newAtom;
};
const notifyListeners = (type, param, atom) => {
for (const listener of listeners) {
listener({ type, param, atom });
}
};
createAtom.unstable_listen = (callback) => {
listeners.add(callback);
return () => {
listeners.delete(callback);
};
};
createAtom.getParams = () => atoms.keys();
createAtom.remove = (param) => {
if (areEqual === void 0) {
if (!atoms.has(param)) return;
const [atom] = atoms.get(param);
atoms.delete(param);
notifyListeners("REMOVE", param, atom);
} else {
for (const [key, [atom]] of atoms) {
if (areEqual(key, param)) {
atoms.delete(key);
notifyListeners("REMOVE", key, atom);
break;
}
}
}
};
createAtom.setShouldRemove = (fn) => {
shouldRemove = fn;
if (!shouldRemove) return;
for (const [key, [atom, createdAt]] of atoms) {
if (shouldRemove(createdAt, key)) {
atoms.delete(key);
notifyListeners("REMOVE", key, atom);
}
}
};
return createAtom;
}
const getCached$2 = (c, m, k) => (m.has(k) ? m : m.set(k, c())).get(k);
const cache1$3 = /* @__PURE__ */ new WeakMap();
const memo3 = (create, dep1, dep2, dep3) => {
const cache2 = getCached$2(() => /* @__PURE__ */ new WeakMap(), cache1$3, dep1);
const cache3 = getCached$2(() => /* @__PURE__ */ new WeakMap(), cache2, dep2);
return getCached$2(create, cache3, dep3);
};
function selectAtom(anAtom, selector, equalityFn = Object.is) {
return memo3(
() => {
const EMPTY = Symbol();
const selectValue = ([value, prevSlice]) => {
if (prevSlice === EMPTY) {
return selector(value);
}
const slice = selector(value, prevSlice);
return equalityFn(prevSlice, slice) ? prevSlice : slice;
};
const derivedAtom = atom((get) => {
const prev = get(derivedAtom);
const value = get(anAtom);
return selectValue([value, prev]);
});
derivedAtom.init = EMPTY;
return derivedAtom;
},
anAtom,
selector,
equalityFn
);
}
const frozenAtoms = /* @__PURE__ */ new WeakSet();
const deepFreeze = (value) => {
if (typeof value !== "object" || value === null) {
return value;
}
Object.freeze(value);
const propNames = Object.getOwnPropertyNames(value);
for (const name of propNames) {
deepFreeze(value[name]);
}
return value;
};
function freezeAtom(anAtom) {
if (frozenAtoms.has(anAtom)) {
return anAtom;
}
frozenAtoms.add(anAtom);
const origRead = anAtom.read;
anAtom.read = function(get, options) {
return deepFreeze(origRead.call(this, get, options));
};
if ("write" in anAtom) {
const origWrite = anAtom.write;
anAtom.write = function(get, set, ...args) {
return origWrite.call(
this,
get,
(...setArgs) => {
if (setArgs[0] === anAtom) {
setArgs[1] = deepFreeze(setArgs[1]);
}
return set(...setArgs);
},
...args
);
};
}
return anAtom;
}
function freezeAtomCreator(createAtom) {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
console.warn(
"[DEPRECATED] freezeAtomCreator is deprecated, define it on users end"
);
}
return ((...args) => freezeAtom(createAtom(...args)));
}
const getCached$1 = (c, m, k) => (m.has(k) ? m : m.set(k, c())).get(k);
const cache1$2 = /* @__PURE__ */ new WeakMap();
const memo2$1 = (create, dep1, dep2) => {
const cache2 = getCached$1(() => /* @__PURE__ */ new WeakMap(), cache1$2, dep1);
return getCached$1(create, cache2, dep2);
};
const cacheKeyForEmptyKeyExtractor = {};
const isWritable = (atom2) => !!atom2.write;
const isFunction = (x) => typeof x === "function";
function splitAtom(arrAtom, keyExtractor) {
return memo2$1(
() => {
const mappingCache = /* @__PURE__ */ new WeakMap();
const getMapping = (arr, prev) => {
let mapping = mappingCache.get(arr);
if (mapping) {
return mapping;
}
const prevMapping = prev && mappingCache.get(prev);
const atomList = [];
const keyList = [];
arr.forEach((item, index) => {
const key = keyExtractor ? keyExtractor(item) : index;
keyList[index] = key;
const cachedAtom = prevMapping && prevMapping.atomList[prevMapping.keyList.indexOf(key)];
if (cachedAtom) {
atomList[index] = cachedAtom;
return;
}
const read = (get) => {
const prev2 = get(mappingAtom);
const currArr = get(arrAtom);
const mapping2 = getMapping(currArr, prev2 == null ? void 0 : prev2.arr);
const index2 = mapping2.keyList.indexOf(key);
if (index2 < 0 || index2 >= currArr.length) {
const prevItem = arr[getMapping(arr).keyList.indexOf(key)];
if (prevItem) {
return prevItem;
}
throw new Error("splitAtom: index out of bounds for read");
}
return currArr[index2];
};
const write = (get, set, update) => {
const prev2 = get(mappingAtom);
const arr2 = get(arrAtom);
const mapping2 = getMapping(arr2, prev2 == null ? void 0 : prev2.arr);
const index2 = mapping2.keyList.indexOf(key);
if (index2 < 0 || index2 >= arr2.length) {
throw new Error("splitAtom: index out of bounds for write");
}
const nextItem = isFunction(update) ? update(arr2[index2]) : update;
if (!Object.is(arr2[index2], nextItem)) {
set(arrAtom, [
...arr2.slice(0, index2),
nextItem,
...arr2.slice(index2 + 1)
]);
}
};
atomList[index] = isWritable(arrAtom) ? atom(read, write) : atom(read);
});
if (prevMapping && prevMapping.keyList.length === keyList.length && prevMapping.keyList.every((x, i) => x === keyList[i])) {
mapping = prevMapping;
} else {
mapping = { arr, atomList, keyList };
}
mappingCache.set(arr, mapping);
return mapping;
};
const mappingAtom = atom((get) => {
const prev = get(mappingAtom);
const arr = get(arrAtom);
const mapping = getMapping(arr, prev == null ? void 0 : prev.arr);
return mapping;
});
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
mappingAtom.debugPrivate = true;
}
mappingAtom.init = void 0;
const splittedAtom = isWritable(arrAtom) ? atom(
(get) => get(mappingAtom).atomList,
(get, set, action) => {
switch (action.type) {
case "remove": {
const index = get(splittedAtom).indexOf(action.atom);
if (index >= 0) {
const arr = get(arrAtom);
set(arrAtom, [
...arr.slice(0, index),
...arr.slice(index + 1)
]);
}
break;
}
case "insert": {
const index = action.before ? get(splittedAtom).indexOf(action.before) : get(splittedAtom).length;
if (index >= 0) {
const arr = get(arrAtom);
set(arrAtom, [
...arr.slice(0, index),
action.value,
...arr.slice(index)
]);
}
break;
}
case "move": {
const index1 = get(splittedAtom).indexOf(action.atom);
const index2 = action.before ? get(splittedAtom).indexOf(action.before) : get(splittedAtom).length;
if (index1 >= 0 && index2 >= 0) {
const arr = get(arrAtom);
if (index1 < index2) {
set(arrAtom, [
...arr.slice(0, index1),
...arr.slice(index1 + 1, index2),
arr[index1],
...arr.slice(index2)
]);
} else {
set(arrAtom, [
...arr.slice(0, index2),
arr[index1],
...arr.slice(index2, index1),
...arr.slice(index1 + 1)
]);
}
}
break;
}
}
}
) : atom((get) => get(mappingAtom).atomList);
return splittedAtom;
},
arrAtom,
keyExtractor || cacheKeyForEmptyKeyExtractor
);
}
function atomWithDefault(getDefault) {
const EMPTY = Symbol();
const overwrittenAtom = atom(EMPTY);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
overwrittenAtom.debugPrivate = true;
}
const anAtom = atom(
(get, options) => {
const overwritten = get(overwrittenAtom);
if (overwritten !== EMPTY) {
return overwritten;
}
return getDefault(get, options);
},
(get, set, update) => {
const newValue = typeof update === "function" ? update(get(anAtom)) : update;
set(overwrittenAtom, newValue === RESET ? EMPTY : newValue);
}
);
return anAtom;
}
const isPromiseLike$3 = (x) => typeof (x == null ? void 0 : x.then) === "function";
function withStorageValidator(validator) {
return (unknownStorage) => {
const storage = {
...unknownStorage,
getItem: (key, initialValue) => {
const validate = (value2) => {
if (!validator(value2)) {
return initialValue;
}
return value2;
};
const value = unknownStorage.getItem(key, initialValue);
if (isPromiseLike$3(value)) {
return value.then(validate);
}
return validate(value);
}
};
return storage;
};
}
function createJSONStorage(getStringStorage = () => {
try {
return window.localStorage;
} catch (e) {
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
if (typeof window !== "undefined") {
console.warn(e);
}
}
return void 0;
}
}, options) {
var _a;
let lastStr;
let lastValue;
const storage = {
getItem: (key, initialValue) => {
var _a2, _b;
const parse = (str2) => {
str2 = str2 || "";
if (lastStr !== str2) {
try {
lastValue = JSON.parse(str2, options == null ? void 0 : options.reviver);
} catch (e) {
return initialValue;
}
lastStr = str2;
}
return lastValue;
};
const str = (_b = (_a2 = getStringStorage()) == null ? void 0 : _a2.getItem(key)) != null ? _b : null;
if (isPromiseLike$3(str)) {
return str.then(parse);
}
return parse(str);
},
setItem: (key, newValue) => {
var _a2;
return (_a2 = getStringStorage()) == null ? void 0 : _a2.setItem(
key,
JSON.stringify(newValue, options == null ? void 0 : options.replacer)
);
},
removeItem: (key) => {
var _a2;
return (_a2 = getStringStorage()) == null ? void 0 : _a2.removeItem(key);
}
};
const createHandleSubscribe = (subscriber2) => (key, callback, initialValue) => subscriber2(key, (v) => {
let newValue;
try {
newValue = JSON.parse(v || "");
} catch (e) {
newValue = initialValue;
}
callback(newValue);
});
let subscriber;
try {
subscriber = (_a = getStringStorage()) == null ? void 0 : _a.subscribe;
} catch (e) {
}
if (!subscriber && typeof window !== "undefined" && typeof window.addEventListener === "function" && window.Storage) {
subscriber = (key, callback) => {
if (!(getStringStorage() instanceof window.Storage)) {
return () => {
};
}
const storageEventCallback = (e) => {
if (e.storageArea === getStringStorage() && e.key === key) {
callback(e.newValue);
}
};
window.addEventListener("storage", storageEventCallback);
return () => {
window.removeEventListener("storage", storageEventCallback);
};
};
}
if (subscriber) {
storage.subscribe = createHandleSubscribe(subscriber);
}
return storage;
}
const defaultStorage = createJSONStorage();
function atomWithStorage(key, initialValue, storage = defaultStorage, options) {
const getOnInit = options == null ? void 0 : options.getOnInit;
const baseAtom = atom(
getOnInit ? storage.getItem(key, initialValue) : initialValue
);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
baseAtom.debugPrivate = true;
}
baseAtom.onMount = (setAtom) => {
setAtom(storage.getItem(key, initialValue));
let unsub;
if (storage.subscribe) {
unsub = storage.subscribe(key, setAtom, initialValue);
}
return unsub;
};
const anAtom = atom(
(get) => get(baseAtom),
(get, set, update) => {
const nextValue = typeof update === "function" ? update(get(baseAtom)) : update;
if (nextValue === RESET) {
set(baseAtom, initialValue);
return storage.removeItem(key);
}
if (isPromiseLike$3(nextValue)) {
return nextValue.then((resolvedValue) => {
set(baseAtom, resolvedValue);
return storage.setItem(key, resolvedValue);
});
}
set(baseAtom, nextValue);
return storage.setItem(key, nextValue);
}
);
return anAtom;
}
const isPromiseLike$2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
function atomWithObservable(getObservable, options) {
const returnResultData = (result) => {
if ("e" in result) {
throw result.e;
}
return result.d;
};
const observableResultAtom = atom((get) => {
var _a;
let observable = getObservable(get);
const itself = (_a = observable[Symbol.observable]) == null ? void 0 : _a.call(observable);
if (itself) {
observable = itself;
}
let resolve;
const makePending = () => new Promise((r) => {
resolve = r;
});
const initialResult = options && "initialValue" in options ? {
d: typeof options.initialValue === "function" ? options.initialValue() : options.initialValue
} : makePending();
let setResult;
let lastResult;
const listener = (result) => {
lastResult = result;
resolve == null ? void 0 : resolve(result);
setResult == null ? void 0 : setResult(result);
};
let subscription;
let timer;
const isNotMounted = () => !setResult;
const unsubscribe = () => {
if (subscription) {
subscription.unsubscribe();
subscription = void 0;
}
};
const start = () => {
if (subscription) {
clearTimeout(timer);
subscription.unsubscribe();
}
subscription = observable.subscribe({
next: (d) => listener({ d }),
error: (e) => listener({ e }),
complete: () => {
}
});
if (isNotMounted() && (options == null ? void 0 : options.unstable_timeout)) {
timer = setTimeout(unsubscribe, options.unstable_timeout);
}
};
start();
const resultAtom = atom(lastResult || initialResult);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
resultAtom.debugPrivate = true;
}
resultAtom.onMount = (update) => {
setResult = update;
if (lastResult) {
update(lastResult);
}
if (subscription) {
clearTimeout(timer);
} else {
start();
}
return () => {
setResult = void 0;
if (options == null ? void 0 : options.unstable_timeout) {
timer = setTimeout(unsubscribe, options.unstable_timeout);
} else {
unsubscribe();
}
};
};
return [resultAtom, observable, makePending, start, isNotMounted];
});
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
observableResultAtom.debugPrivate = true;
}
const observableAtom = atom(
(get) => {
const [resultAtom] = get(observableResultAtom);
const result = get(resultAtom);
if (isPromiseLike$2(result)) {
return result.then(returnResultData);
}
return returnResultData(result);
},
(get, set, data) => {
const [resultAtom, observable, makePending, start, isNotMounted] = get(observableResultAtom);
if ("next" in observable) {
if (isNotMounted()) {
set(resultAtom, makePending());
start();
}
observable.next(data);
} else {
throw new Error("observable is not subject");
}
}
);
return observableAtom;
}
const cache1$1 = /* @__PURE__ */ new WeakMap();
const memo1 = (create, dep1) => (cache1$1.has(dep1) ? cache1$1 : cache1$1.set(dep1, create())).get(dep1);
const isPromiseLike$1 = (p) => typeof (p == null ? void 0 : p.then) === "function";
const LOADING = { state: "loading" };
function loadable(anAtom) {
return memo1(() => {
const loadableCache = /* @__PURE__ */ new WeakMap();
const refreshAtom = atom(0);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
refreshAtom.debugPrivate = true;
}
const derivedAtom = atom(
(get, { setSelf }) => {
get(refreshAtom);
let value;
try {
value = get(anAtom);
} catch (error) {
return { state: "hasError", error };
}
if (!isPromiseLike$1(value)) {
return { state: "hasData", data: value };
}
const promise = value;
const cached1 = loadableCache.get(promise);
if (cached1) {
return cached1;
}
promise.then(
(data) => {
loadableCache.set(promise, { state: "hasData", data });
setSelf();
},
(error) => {
loadableCache.set(promise, { state: "hasError", error });
setSelf();
}
);
const cached2 = loadableCache.get(promise);
if (cached2) {
return cached2;
}
loadableCache.set(promise, LOADING);
return LOADING;
},
(_get, set) => {
set(refreshAtom, (c) => c + 1);
}
);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
derivedAtom.debugPrivate = true;
}
return atom((get) => get(derivedAtom));
}, anAtom);
}
const getCached = (c, m, k) => (m.has(k) ? m : m.set(k, c())).get(k);
const cache1 = /* @__PURE__ */ new WeakMap();
const memo2 = (create, dep1, dep2) => {
const cache2 = getCached(() => /* @__PURE__ */ new WeakMap(), cache1, dep1);
return getCached(create, cache2, dep2);
};
const isPromiseLike = (p) => typeof (p == null ? void 0 : p.then) === "function";
const defaultFallback = () => void 0;
function unwrap(anAtom, fallback = defaultFallback) {
return memo2(
() => {
const promiseErrorCache = /* @__PURE__ */ new WeakMap();
const promiseResultCache = /* @__PURE__ */ new WeakMap();
const refreshAtom = atom(0);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
refreshAtom.debugPrivate = true;
}
const promiseAndValueAtom = atom(
(get, { setSelf }) => {
get(refreshAtom);
const prev = get(promiseAndValueAtom);
const promise = get(anAtom);
if (!isPromiseLike(promise)) {
return { v: promise };
}
if (promise !== (prev == null ? void 0 : prev.p)) {
promise.then(
(v) => {
promiseResultCache.set(promise, v);
setSelf();
},
(e) => {
promiseErrorCache.set(promise, e);
setSelf();
}
);
}
if (promiseErrorCache.has(promise)) {
throw promiseErrorCache.get(promise);
}
if (promiseResultCache.has(promise)) {
return {
p: promise,
v: promiseResultCache.get(promise)
};
}
if (prev && "v" in prev) {
return { p: promise, f: fallback(prev.v), v: prev.v };
}
return { p: promise, f: fallback() };
},
(_get, set) => {
set(refreshAtom, (c) => c + 1);
}
);
promiseAndValueAtom.init = void 0;
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
promiseAndValueAtom.debugPrivate = true;
}
return atom(
(get) => {
const state = get(promiseAndValueAtom);
if ("f" in state) {
return state.f;
}
return state.v;
},
(_get, set, ...args) => set(anAtom, ...args)
);
},
anAtom,
fallback
);
}
function atomWithRefresh(read, write) {
const refreshAtom = atom(0);
if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
refreshAtom.debugPrivate = true;
}
return atom(
(get, options) => {
get(refreshAtom);
return read(get, options);
},
(get, set, ...args) => {
if (args.length === 0) {
set(refreshAtom, (c) => c + 1);
} else if (write) {
return write(get, set, ...args);
} else if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
throw new Error("refresh must be called without arguments");
}
}
);
}
function atomWithLazy(makeInitial) {
const a = atom(void 0);
delete a.init;
Object.defineProperty(a, "init", {
get() {
return makeInitial();
}
});
return a;
}
export { RESET, atomFamily, atomWithDefault, atomWithLazy, atomWithObservable, atomWithReducer, atomWithRefresh, atomWithReset, atomWithStorage, createJSONStorage, freezeAtom, freezeAtomCreator, loadable, selectAtom, splitAtom, withStorageValidator as unstable_withStorageValidator, unwrap };

25
node_modules/jotai/esm/vanilla/utils/atomFamily.d.mts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import { type Atom } from 'jotai/vanilla';
/**
* in milliseconds
*/
type CreatedAt = number;
type ShouldRemove<Param> = (createdAt: CreatedAt, param: Param) => boolean;
type Cleanup = () => void;
type Callback<Param, AtomType> = (event: {
type: 'CREATE' | 'REMOVE';
param: Param;
atom: AtomType;
}) => void;
export interface AtomFamily<Param, AtomType> {
(param: Param): AtomType;
getParams(): Iterable<Param>;
remove(param: Param): void;
setShouldRemove(shouldRemove: ShouldRemove<Param> | null): void;
/**
* fires when a atom is created or removed
* This API is for advanced use cases, and can change without notice.
*/
unstable_listen(callback: Callback<Param, AtomType>): Cleanup;
}
export declare function atomFamily<Param, AtomType extends Atom<unknown>>(initializeAtom: (param: Param) => AtomType, areEqual?: (a: Param, b: Param) => boolean): AtomFamily<Param, AtomType>;
export {};

View File

@@ -0,0 +1,6 @@
import type { WritableAtom } from 'jotai/vanilla';
import { RESET } from './constants.mjs';
type Read<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['read'];
type DefaultSetStateAction<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
export declare function atomWithDefault<Value>(getDefault: Read<Value, [DefaultSetStateAction<Value>], void>): WritableAtom<Value, [DefaultSetStateAction<Value>], void>;
export {};

View File

@@ -0,0 +1,2 @@
import type { PrimitiveAtom } from 'jotai/vanilla';
export declare function atomWithLazy<Value>(makeInitial: () => Value): PrimitiveAtom<Value>;

View File

@@ -0,0 +1,32 @@
import type { Atom, Getter, WritableAtom } from 'jotai/vanilla';
type AnyError = unknown;
type Subscription = {
unsubscribe: () => void;
};
type Observer<T> = {
next: (value: T) => void;
error: (error: AnyError) => void;
complete: () => void;
};
type ObservableLike<T> = {
subscribe(observer: Observer<T>): Subscription;
} | {
subscribe(observer: Partial<Observer<T>>): Subscription;
} | {
subscribe(observer: Partial<Observer<T>>): Subscription;
subscribe(next: (value: T) => void): Subscription;
};
type SubjectLike<T> = ObservableLike<T> & Observer<T>;
type Options<Data> = {
initialValue?: Data | (() => Data);
unstable_timeout?: number;
};
type OptionsWithInitialValue<Data> = {
initialValue: Data | (() => Data);
unstable_timeout?: number;
};
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options: OptionsWithInitialValue<Data>): WritableAtom<Data, [Data], void>;
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => SubjectLike<Data>, options?: Options<Data>): WritableAtom<Data | Promise<Data>, [Data], void>;
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options: OptionsWithInitialValue<Data>): Atom<Data>;
export declare function atomWithObservable<Data>(getObservable: (get: Getter) => ObservableLike<Data>, options?: Options<Data>): Atom<Data | Promise<Data>>;
export {};

View File

@@ -0,0 +1,3 @@
import type { WritableAtom } from 'jotai/vanilla';
export declare function atomWithReducer<Value, Action>(initialValue: Value, reducer: (value: Value, action?: Action) => Value): WritableAtom<Value, [Action?], void>;
export declare function atomWithReducer<Value, Action>(initialValue: Value, reducer: (value: Value, action: Action) => Value): WritableAtom<Value, [Action], void>;

View File

@@ -0,0 +1,6 @@
import type { WritableAtom } from 'jotai/vanilla';
type Read<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['read'];
type Write<Value, Args extends unknown[], Result> = WritableAtom<Value, Args, Result>['write'];
export declare function atomWithRefresh<Value, Args extends unknown[], Result>(read: Read<Value, Args, Result>, write: Write<Value, Args, Result>): WritableAtom<Value, Args | [], Result | void>;
export declare function atomWithRefresh<Value>(read: Read<Value, [], void>): WritableAtom<Value, [], void>;
export {};

View File

@@ -0,0 +1,8 @@
import type { WritableAtom } from 'jotai/vanilla';
import { RESET } from './constants.mjs';
type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
type WithInitialValue<Value> = {
init: Value;
};
export declare function atomWithReset<Value>(initialValue: Value): WritableAtom<Value, [SetStateActionWithReset<Value>], void> & WithInitialValue<Value>;
export {};

View File

@@ -0,0 +1,50 @@
import type { WritableAtom } from 'jotai/vanilla';
import { RESET } from './constants.mjs';
type Unsubscribe = () => void;
type Subscribe<Value> = (key: string, callback: (value: Value) => void, initialValue: Value) => Unsubscribe | undefined;
type StringSubscribe = (key: string, callback: (value: string | null) => void) => Unsubscribe | undefined;
type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET);
export interface AsyncStorage<Value> {
getItem: (key: string, initialValue: Value) => PromiseLike<Value>;
setItem: (key: string, newValue: Value) => PromiseLike<void>;
removeItem: (key: string) => PromiseLike<void>;
subscribe?: Subscribe<Value>;
}
export interface SyncStorage<Value> {
getItem: (key: string, initialValue: Value) => Value;
setItem: (key: string, newValue: Value) => void;
removeItem: (key: string) => void;
subscribe?: Subscribe<Value>;
}
export interface AsyncStringStorage {
getItem: (key: string) => PromiseLike<string | null>;
setItem: (key: string, newValue: string) => PromiseLike<void>;
removeItem: (key: string) => PromiseLike<void>;
subscribe?: StringSubscribe;
}
export interface SyncStringStorage {
getItem: (key: string) => string | null;
setItem: (key: string, newValue: string) => void;
removeItem: (key: string) => void;
subscribe?: StringSubscribe;
}
export declare function withStorageValidator<Value>(validator: (value: unknown) => value is Value): {
(storage: AsyncStorage<unknown>): AsyncStorage<Value>;
(storage: SyncStorage<unknown>): SyncStorage<Value>;
};
type JsonStorageOptions = {
reviver?: (key: string, value: unknown) => unknown;
replacer?: (key: string, value: unknown) => unknown;
};
export declare function createJSONStorage<Value>(): SyncStorage<Value>;
export declare function createJSONStorage<Value>(getStringStorage: () => AsyncStringStorage, options?: JsonStorageOptions): AsyncStorage<Value>;
export declare function createJSONStorage<Value>(getStringStorage: () => SyncStringStorage, options?: JsonStorageOptions): SyncStorage<Value>;
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage: AsyncStorage<Value>, options?: {
getOnInit?: boolean;
}): WritableAtom<Value | Promise<Value>, [
SetStateActionWithReset<Value | Promise<Value>>
], Promise<void>>;
export declare function atomWithStorage<Value>(key: string, initialValue: Value, storage?: SyncStorage<Value>, options?: {
getOnInit?: boolean;
}): WritableAtom<Value, [SetStateActionWithReset<Value>], void>;
export {};

1
node_modules/jotai/esm/vanilla/utils/constants.d.mts generated vendored Normal file
View File

@@ -0,0 +1 @@
export declare const RESET: unique symbol;

View File

@@ -0,0 +1,6 @@
import type { Atom } from 'jotai/vanilla';
export declare function freezeAtom<AtomType extends Atom<unknown>>(anAtom: AtomType): AtomType;
/**
* @deprecated Define it on users end
*/
export declare function freezeAtomCreator<CreateAtom extends (...args: unknown[]) => Atom<unknown>>(createAtom: CreateAtom): CreateAtom;

11
node_modules/jotai/esm/vanilla/utils/loadable.d.mts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import type { Atom } from 'jotai/vanilla';
export type Loadable<Value> = {
state: 'loading';
} | {
state: 'hasError';
error: unknown;
} | {
state: 'hasData';
data: Awaited<Value>;
};
export declare function loadable<Value>(anAtom: Atom<Value>): Atom<Loadable<Value>>;

View File

@@ -0,0 +1,2 @@
import type { Atom } from 'jotai/vanilla';
export declare function selectAtom<Value, Slice>(anAtom: Atom<Value>, selector: (v: Value, prevSlice?: Slice) => Slice, equalityFn?: (a: Slice, b: Slice) => boolean): Atom<Slice>;

16
node_modules/jotai/esm/vanilla/utils/splitAtom.d.mts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import type { Atom, PrimitiveAtom, WritableAtom } from 'jotai/vanilla';
type SplitAtomAction<Item> = {
type: 'remove';
atom: PrimitiveAtom<Item>;
} | {
type: 'insert';
value: Item;
before?: PrimitiveAtom<Item>;
} | {
type: 'move';
atom: PrimitiveAtom<Item>;
before?: PrimitiveAtom<Item>;
};
export declare function splitAtom<Item, Key>(arrAtom: WritableAtom<Item[], [Item[]], void>, keyExtractor?: (item: Item) => Key): WritableAtom<PrimitiveAtom<Item>[], [SplitAtomAction<Item>], void>;
export declare function splitAtom<Item, Key>(arrAtom: Atom<Item[]>, keyExtractor?: (item: Item) => Key): Atom<Atom<Item>[]>;
export {};

5
node_modules/jotai/esm/vanilla/utils/unwrap.d.mts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import type { Atom, WritableAtom } from 'jotai/vanilla';
export declare function unwrap<Value, Args extends unknown[], Result>(anAtom: WritableAtom<Value, Args, Result>): WritableAtom<Awaited<Value> | undefined, Args, Result>;
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>;
export declare function unwrap<Value>(anAtom: Atom<Value>): Atom<Awaited<Value> | undefined>;
export declare function unwrap<Value, PendingValue>(anAtom: Atom<Value>, fallback: (prev?: Awaited<Value>) => PendingValue): Atom<Awaited<Value> | PendingValue>;