@yakocloud/state-vocab 2.0.2 → 2.0.3
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/dist/types/constants.d.ts +2 -0
- package/dist/types/context.d.ts +11 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/setup.d.ts +1 -0
- package/dist/types/state.d.ts +22 -0
- package/dist/types/state.utils.d.ts +11 -0
- package/dist/types/utils.d.ts +7 -0
- package/package.json +3 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SetStateAction, type PropsWithChildren, type Dispatch } from "react";
|
|
2
|
+
export type Vocab<T = unknown> = Record<string, T | null>;
|
|
3
|
+
type Context<V extends Vocab = Vocab> = {
|
|
4
|
+
stateVocab: V;
|
|
5
|
+
setStateVocab: Dispatch<SetStateAction<V>>;
|
|
6
|
+
};
|
|
7
|
+
export declare function useStateVocabContext<T>(): Context<Vocab<T>>;
|
|
8
|
+
export declare const StateVocabContextProvider: (props: PropsWithChildren<{
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupStorage<T extends object>(nativeRouter: T): T;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { STATE_DEFINITION, STATE_PATH } from "./constants";
|
|
2
|
+
export declare function defineState<T>(definitionOptions?: {
|
|
3
|
+
storage?: Storage;
|
|
4
|
+
defaultValue?: T;
|
|
5
|
+
bidirectional?: true;
|
|
6
|
+
serialize?: (v: T) => string;
|
|
7
|
+
deserialize?: (v: string) => T;
|
|
8
|
+
}): {
|
|
9
|
+
[STATE_DEFINITION]: boolean;
|
|
10
|
+
[STATE_PATH]: string;
|
|
11
|
+
useState<D = T>(this: {
|
|
12
|
+
[STATE_PATH]: string;
|
|
13
|
+
}, defaultValue?: D | (() => D), options?: {
|
|
14
|
+
delayedSet?: number;
|
|
15
|
+
bidirectional?: true;
|
|
16
|
+
onSet?(nextValue: NoInfer<D>, prevValue: NoInfer<D>): void;
|
|
17
|
+
}): readonly [D, (nextValue: D | ((prev: D) => D)) => void, () => void];
|
|
18
|
+
/** Returns the fully qualified job name (dot-separated path). */
|
|
19
|
+
toString(this: {
|
|
20
|
+
[STATE_PATH]: string;
|
|
21
|
+
}): string;
|
|
22
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Vocab } from "./context";
|
|
2
|
+
export declare const embed: <D>(statePath: string, value: D) => (vocab: Vocab<D>) => {
|
|
3
|
+
[x: string]: D;
|
|
4
|
+
};
|
|
5
|
+
export declare const genDefaultValue: <D>(defaultValue: D | (() => D), superDefaltValue: unknown) => D;
|
|
6
|
+
export declare const genStoredValue: <D>(options: {
|
|
7
|
+
serialized: string | null;
|
|
8
|
+
defaultValue: D | (() => D);
|
|
9
|
+
superDefaultValue: unknown;
|
|
10
|
+
deserialize: (v: string) => D;
|
|
11
|
+
}) => D;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type DependencyList } from "react";
|
|
2
|
+
export declare function get<T, Default = undefined>(obj: T, path: string, defaultValue?: Default): unknown | Default;
|
|
3
|
+
export declare function set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;
|
|
4
|
+
export declare function debounce<T extends (...args: never[]) => unknown>(func: T, wait?: number): (...args: Parameters<T>) => void;
|
|
5
|
+
export declare function useDebounce<T extends (...args: never[]) => unknown>(effect: T, wait: number | undefined, deps?: DependencyList): (...args: Parameters<T>) => void;
|
|
6
|
+
export declare const isJsonValid: (input: string) => boolean;
|
|
7
|
+
export declare function logStyled(obj: object): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakocloud/state-vocab",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"main": "dist/state-vocab.cjs.js",
|
|
5
5
|
"module": "dist/state-vocab.es.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -18,10 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "vite",
|
|
21
|
-
"build": "tsc -b && vite build",
|
|
21
|
+
"build": "tsc -b && vite build ; tsc --project tsconfig.types.json",
|
|
22
22
|
"lint": "eslint .",
|
|
23
|
-
"type-check": "tsc --project tsconfig.types.json"
|
|
24
|
-
"build:types": "tsc --project tsconfig.types.json"
|
|
23
|
+
"type-check": "tsc --project tsconfig.types.json"
|
|
25
24
|
},
|
|
26
25
|
"peerDependencies": {
|
|
27
26
|
"react": "^19.2.1",
|