cogsbox-state 0.5.3 → 0.5.4
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/CogsState.d.ts +25 -21
- package/dist/CogsState.jsx +491 -442
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.jsx +175 -0
- package/dist/Functions.jsx.map +1 -0
- package/dist/store.d.ts +4 -0
- package/dist/store.js.map +1 -1
- package/package.json +7 -4
- package/dist/examples/index.d.ts +0 -1
- package/dist/updaterFunctions.jsx +0 -177
- package/dist/updaterFunctions.jsx.map +0 -1
- /package/dist/{updaterFunctions.d.ts → Functions.d.ts} +0 -0
package/dist/CogsState.d.ts
CHANGED
|
@@ -31,15 +31,8 @@ export type FormElementParmas<T> = {
|
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
export type StateKeys = string;
|
|
34
|
-
type findWithFuncType<U> = (thisKey: keyof U, thisValue: U[keyof U]) => EndType<U> &
|
|
35
|
-
|
|
36
|
-
} & StateObject<U>;
|
|
37
|
-
export type PushArgs<U> = (update: Prettify<U> | ((prevState: NonNullable<Prettify<U>>[]) => NonNullable<Prettify<U>>), opts?: UpdateOpts) => void;
|
|
38
|
-
export interface GlobalState<T, K extends keyof T = keyof T> {
|
|
39
|
-
getKeyState: () => T;
|
|
40
|
-
setState: (newState: T | ((previousState: T) => T)) => void;
|
|
41
|
-
key: K;
|
|
42
|
-
}
|
|
34
|
+
type findWithFuncType<U> = (thisKey: keyof U, thisValue: U[keyof U]) => EndType<U> & StateObject<U>;
|
|
35
|
+
export type PushArgs<U> = (update: Prettify<U> | ((prevState: NonNullable<Prettify<U>>[]) => NonNullable<Prettify<U>>), opts?: UpdateOpts<U>) => void;
|
|
43
36
|
type CutFunctionType = (index?: number, options?: {
|
|
44
37
|
waitForSync?: boolean;
|
|
45
38
|
}) => void;
|
|
@@ -53,13 +46,16 @@ export type ArrayEndType<TShape extends unknown> = {
|
|
|
53
46
|
} & EndType<InferArrayElement<TShape>>;
|
|
54
47
|
insert: PushArgs<InferArrayElement<TShape>>;
|
|
55
48
|
cut: CutFunctionType;
|
|
56
|
-
|
|
49
|
+
stateMap: (callbackfn: (value: InferArrayElement<TShape>, setter: StateObject<InferArrayElement<TShape>>, index: number, array: TShape, arraySetter: StateObject<TShape>) => void) => any;
|
|
50
|
+
$stateMap: (callbackfn: (value: InferArrayElement<TShape>, setter: StateObject<InferArrayElement<TShape>>, index: number, array: TShape, arraySetter: StateObject<TShape>) => void) => any;
|
|
57
51
|
stateFlattenOn: <K extends keyof InferArrayElement<TShape>>(field: K) => StateObject<InferArrayElement<InferArrayElement<TShape>[K]>[]>;
|
|
58
52
|
uniqueInsert: (payload: UpdateArg<InferArrayElement<TShape>>, fields?: (keyof InferArrayElement<TShape>)[]) => void;
|
|
59
53
|
stateFilter: (callbackfn: (value: InferArrayElement<TShape>, index: number) => void) => ArrayEndType<TShape>;
|
|
60
54
|
getSelected: () => StateObject<InferArrayElement<TShape>> | undefined;
|
|
61
|
-
} & EndType<TShape
|
|
62
|
-
|
|
55
|
+
} & EndType<TShape> & {
|
|
56
|
+
[K in keyof (any[] extends infer T ? T : never)]: never;
|
|
57
|
+
};
|
|
58
|
+
export type UpdateType<T> = (payload: UpdateArg<Prettify<T>>, opts?: UpdateOpts<T>) => void;
|
|
63
59
|
export type FormOptsType = {
|
|
64
60
|
key?: string;
|
|
65
61
|
validation?: {
|
|
@@ -74,10 +70,8 @@ export type FormOptsType = {
|
|
|
74
70
|
};
|
|
75
71
|
export type FormControl<T> = (obj: FormElementParmas<T>) => JSX.Element;
|
|
76
72
|
export type UpdateArg<S> = S | ((prevState: S) => S);
|
|
77
|
-
export type UpdateOpts = {
|
|
78
|
-
|
|
79
|
-
timeLineMessage?: string;
|
|
80
|
-
validate?: boolean;
|
|
73
|
+
export type UpdateOpts<T> = {
|
|
74
|
+
afterUpdate?: (state: T) => void;
|
|
81
75
|
};
|
|
82
76
|
export type ObjectEndType<T> = EndType<T> & {
|
|
83
77
|
[K in keyof T]-?: ObjectEndType<T[K]>;
|
|
@@ -85,13 +79,15 @@ export type ObjectEndType<T> = EndType<T> & {
|
|
|
85
79
|
stateObject: (callbackfn: (value: T, setter: StateObject<T>) => void) => any;
|
|
86
80
|
delete: () => void;
|
|
87
81
|
};
|
|
88
|
-
|
|
82
|
+
type EffectFunction<T, R> = (state: T) => R;
|
|
83
|
+
export type EndType<T, IsArrayElement = false> = {
|
|
89
84
|
update: UpdateType<T>;
|
|
90
85
|
_path: string[];
|
|
91
86
|
_stateKey: string;
|
|
92
87
|
formElement: (validationKey: string, control: FormControl<T>, opts?: FormOptsType) => JSX.Element;
|
|
93
88
|
get: () => T;
|
|
94
89
|
$get: () => T;
|
|
90
|
+
$effect: <R>(fn: EffectFunction<T, R>) => R;
|
|
95
91
|
_status: "fresh" | "stale" | "synced";
|
|
96
92
|
showValidationErrors: (ctx: string) => string[];
|
|
97
93
|
setValidation: (ctx: string) => void;
|
|
@@ -104,10 +100,14 @@ export type EndType<T> = {
|
|
|
104
100
|
hideMessage?: boolean;
|
|
105
101
|
}) => JSX.Element;
|
|
106
102
|
lastSynced?: SyncInfo;
|
|
103
|
+
} & (IsArrayElement extends true ? {
|
|
104
|
+
cut: () => void;
|
|
105
|
+
} : {}) & {
|
|
106
|
+
[K in keyof (any extends infer T ? T : never)]: never;
|
|
107
107
|
};
|
|
108
108
|
export type StateObject<T> = (T extends any[] ? ArrayEndType<T> : T extends Record<string, unknown> | object ? {
|
|
109
109
|
[K in keyof T]-?: StateObject<T[K]>;
|
|
110
|
-
} & ObjectEndType<T> : T extends string | number | boolean | null ? T : never) & EndType<T> & {
|
|
110
|
+
} & ObjectEndType<T> : T extends string | number | boolean | null ? T : never) & EndType<T, true> & {
|
|
111
111
|
_componentId: string | null;
|
|
112
112
|
_initialState: T;
|
|
113
113
|
updateInitialState: (newState: T | null) => {
|
|
@@ -128,7 +128,7 @@ export type StateObject<T> = (T extends any[] ? ArrayEndType<T> : T extends Reco
|
|
|
128
128
|
export type CogsUpdate<T extends unknown> = UpdateType<T>;
|
|
129
129
|
export type EffectiveSetState<TStateObject> = (newStateOrFunction: TStateObject | ((prevState: TStateObject) => TStateObject), path: string[], updateObj: {
|
|
130
130
|
updateType: "update" | "insert" | "cut";
|
|
131
|
-
}, validationKey?: string, opts?: UpdateOpts) => void;
|
|
131
|
+
}, validationKey?: string, opts?: UpdateOpts<TStateObject>) => void;
|
|
132
132
|
export type UpdateTypeDetail = {
|
|
133
133
|
timeStamp: number;
|
|
134
134
|
stateKey: string;
|
|
@@ -249,8 +249,10 @@ export type TransformedStateType<T> = {
|
|
|
249
249
|
[P in keyof T]: T[P] extends CogsInitialState<infer U> ? U : T[P];
|
|
250
250
|
};
|
|
251
251
|
export declare function addStateOptions<T extends unknown>(initialState: T, { formElements, zodSchema }: OptionsType<T>): T;
|
|
252
|
-
export declare const createCogsState: <State extends Record<string, unknown>>(initialState: State
|
|
253
|
-
|
|
252
|
+
export declare const createCogsState: <State extends Record<string, unknown>>(initialState: State, opts?: {
|
|
253
|
+
reRenderType?: "get" | "state" | "none";
|
|
254
|
+
}) => {
|
|
255
|
+
useCogsState: <StateKey extends keyof State>(stateKey: StateKey, options?: OptionsType<TransformedStateType<State>[StateKey]>) => StateObject<TransformedStateType<State>[StateKey]>;
|
|
254
256
|
setCogsOptions: <StateKey extends keyof State>(stateKey: StateKey, options: OptionsType<TransformedStateType<State>[StateKey]>) => void;
|
|
255
257
|
};
|
|
256
258
|
type LocalStorageData<T> = {
|
|
@@ -266,10 +268,12 @@ export declare function useCogsStateFn<TStateObject extends unknown>(stateObject
|
|
|
266
268
|
export declare function $cogsSignal(proxy: {
|
|
267
269
|
_path: string[];
|
|
268
270
|
_stateKey: string;
|
|
271
|
+
_effect?: string;
|
|
269
272
|
}): import('react').FunctionComponentElement<{
|
|
270
273
|
proxy: {
|
|
271
274
|
_path: string[];
|
|
272
275
|
_stateKey: string;
|
|
276
|
+
_effect?: string;
|
|
273
277
|
};
|
|
274
278
|
}>;
|
|
275
279
|
export declare function $cogsSignalStore(proxy: {
|