cogsbox-state 0.5.5 → 0.5.7
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 +30 -13
- package/dist/CogsState.jsx +544 -480
- package/dist/CogsState.jsx.map +1 -1
- package/dist/CogsStateClient.jsx +6 -6
- package/dist/CogsStateClient.jsx.map +1 -1
- package/dist/Functions.d.ts +3 -4
- package/dist/Functions.jsx +173 -128
- package/dist/Functions.jsx.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +21 -17
- package/dist/index.js.map +1 -1
- package/dist/node_modules/zustand/esm/react.js +1 -1
- package/dist/store.d.ts +19 -9
- package/dist/store.js +77 -60
- package/dist/store.js.map +1 -1
- package/dist/useValidateZodPath.d.ts +34 -0
- package/dist/useValidateZodPath.js +60 -0
- package/dist/useValidateZodPath.js.map +1 -0
- package/dist/utility.d.ts +6 -0
- package/dist/utility.js +90 -80
- package/dist/utility.js.map +1 -1
- package/package.json +68 -64
- package/dist/_virtual/_commonjsHelpers.js +0 -7
- package/dist/_virtual/_commonjsHelpers.js.map +0 -1
- package/dist/_virtual/index.js +0 -5
- package/dist/_virtual/index.js.map +0 -1
- package/dist/_virtual/jsx-runtime.jsx +0 -5
- package/dist/_virtual/jsx-runtime.jsx.map +0 -1
- package/dist/_virtual/react-jsx-runtime.jsx +0 -5
- package/dist/_virtual/react-jsx-runtime.jsx.map +0 -1
- package/dist/_virtual/react-jsx-runtime.production.jsx +0 -5
- package/dist/_virtual/react-jsx-runtime.production.jsx.map +0 -1
- package/dist/_virtual/react.js +0 -5
- package/dist/_virtual/react.js.map +0 -1
- package/dist/_virtual/react.production.js +0 -5
- package/dist/_virtual/react.production.js.map +0 -1
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx +0 -605
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx.map +0 -1
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx +0 -29
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx.map +0 -1
- package/dist/node_modules/react/cjs/react.js +0 -1274
- package/dist/node_modules/react/cjs/react.js.map +0 -1
- package/dist/node_modules/react/cjs/react.production.js +0 -209
- package/dist/node_modules/react/cjs/react.production.js.map +0 -1
- package/dist/node_modules/react/index.js +0 -12
- package/dist/node_modules/react/index.js.map +0 -1
- package/dist/node_modules/react/jsx-runtime.jsx +0 -9
- package/dist/node_modules/react/jsx-runtime.jsx.map +0 -1
package/dist/Functions.jsx
CHANGED
|
@@ -1,175 +1,220 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { jsx as V, Fragment as G } from "react/jsx-runtime";
|
|
2
|
+
import "./CogsState.jsx";
|
|
3
|
+
import { getNestedValue as R, isFunction as M, updateNestedProperty as E } from "./utility.js";
|
|
4
|
+
import B, { useState as b, useRef as j, useEffect as F } from "react";
|
|
5
|
+
import { getGlobalStore as a, formRefStore as W } from "./store.js";
|
|
6
|
+
import { validateZodPathFunc as Y } from "./useValidateZodPath.js";
|
|
7
|
+
function Z(r, e, n, o) {
|
|
8
|
+
r(
|
|
9
|
+
(t) => {
|
|
10
|
+
if (M(e)) {
|
|
11
|
+
const s = e(R(t, n));
|
|
12
|
+
let i = E(n, t, s);
|
|
13
|
+
return typeof i == "string" && (i = i.trim()), i;
|
|
12
14
|
} else {
|
|
13
|
-
let
|
|
14
|
-
return typeof
|
|
15
|
+
let s = !n || n.length == 0 ? e : E(n, t, e);
|
|
16
|
+
return typeof s == "string" && (s = s.trim()), s;
|
|
15
17
|
}
|
|
16
18
|
},
|
|
17
|
-
|
|
19
|
+
n,
|
|
18
20
|
{ updateType: "update" },
|
|
19
|
-
|
|
21
|
+
o
|
|
20
22
|
);
|
|
21
23
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
let
|
|
27
|
-
return
|
|
28
|
-
Number(
|
|
24
|
+
function ee(r, e, n, o, t) {
|
|
25
|
+
const s = a.getState().getNestedState(o, n);
|
|
26
|
+
r(
|
|
27
|
+
(i) => {
|
|
28
|
+
let l = !n || n.length == 0 ? i : R(i, [...n]), u = [...l];
|
|
29
|
+
return u.splice(
|
|
30
|
+
Number(t) == 0 ? t : l.length,
|
|
29
31
|
0,
|
|
30
|
-
|
|
31
|
-
),
|
|
32
|
+
M(e) ? e(l) : e
|
|
33
|
+
), n.length == 0 ? u : E([...n], i, u);
|
|
32
34
|
},
|
|
33
35
|
[
|
|
34
|
-
...
|
|
35
|
-
(
|
|
36
|
+
...n,
|
|
37
|
+
(s.length - 1).toString()
|
|
36
38
|
],
|
|
37
39
|
{
|
|
38
40
|
updateType: "insert"
|
|
39
41
|
}
|
|
40
42
|
);
|
|
41
43
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
(
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
throw new Error(`Index ${
|
|
49
|
-
const
|
|
50
|
-
...
|
|
51
|
-
...
|
|
44
|
+
function te(r, e, n, o) {
|
|
45
|
+
const t = a.getState().getNestedState(n, e);
|
|
46
|
+
r(
|
|
47
|
+
(s) => {
|
|
48
|
+
const i = R(s, [...e]);
|
|
49
|
+
if (o < 0 || o >= i?.length)
|
|
50
|
+
throw new Error(`Index ${o} does not exist in the array.`);
|
|
51
|
+
const l = o || Number(o) == 0 ? o : i.length - 1, u = [
|
|
52
|
+
...i.slice(0, l),
|
|
53
|
+
...i.slice(l + 1)
|
|
52
54
|
];
|
|
53
|
-
return console.log(
|
|
55
|
+
return console.log(o), e.length == 0 ? u : E([...e], s, u);
|
|
54
56
|
},
|
|
55
57
|
[
|
|
56
|
-
...
|
|
57
|
-
|
|
58
|
+
...e,
|
|
59
|
+
o || o === 0 ? o?.toString() : (t.length - 1).toString()
|
|
58
60
|
],
|
|
59
61
|
{ updateType: "cut" }
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
|
-
const
|
|
63
|
-
const [
|
|
64
|
-
() =>
|
|
65
|
-
),
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
e(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
const T = (r, e, n = (o, t) => JSON.stringify(o) === JSON.stringify(t)) => {
|
|
65
|
+
const [o, t] = b(
|
|
66
|
+
() => e(a.getState(), r)
|
|
67
|
+
), s = j(o), i = j(r);
|
|
68
|
+
return F(() => {
|
|
69
|
+
i.current = r, t(e(a.getState(), r));
|
|
70
|
+
const l = (d) => {
|
|
71
|
+
const g = e(d, i.current);
|
|
72
|
+
n(s.current, g) || (s.current = g, t(g));
|
|
73
|
+
}, u = a.subscribe(l);
|
|
74
|
+
return () => {
|
|
75
|
+
u();
|
|
76
|
+
};
|
|
77
|
+
}, [r]), o;
|
|
78
|
+
}, _ = (r, e, n) => {
|
|
79
|
+
const o = r + "." + (e.length > 0 ? [e.join(".")] : []) + (n && n.length > 0 ? "." + n : "");
|
|
80
|
+
return n?.length === 0 ? [] : T(
|
|
81
|
+
o,
|
|
82
|
+
(t, s) => t.getValidationErrors(s) || []
|
|
78
83
|
);
|
|
79
|
-
},
|
|
80
|
-
const
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
(
|
|
84
|
+
}, q = (r, e) => {
|
|
85
|
+
const n = `${r}:${e.join(".")}`;
|
|
86
|
+
return T(
|
|
87
|
+
n,
|
|
88
|
+
(o, t) => o.getSyncInfo(t)
|
|
84
89
|
);
|
|
85
|
-
},
|
|
86
|
-
`${
|
|
87
|
-
(
|
|
88
|
-
),
|
|
89
|
-
setState:
|
|
90
|
-
validationKey: t,
|
|
90
|
+
}, H = (r, e) => T(
|
|
91
|
+
`${r}:${e.join(".")}`,
|
|
92
|
+
(n, o) => n.getNestedState(r, e)
|
|
93
|
+
), ne = ({
|
|
94
|
+
setState: r,
|
|
91
95
|
path: e,
|
|
92
96
|
child: n,
|
|
93
97
|
formOpts: o,
|
|
94
|
-
stateKey:
|
|
98
|
+
stateKey: t
|
|
95
99
|
}) => {
|
|
96
|
-
const {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
const [s, i] = b({}), { registerFormRef: l, getFormRef: u } = W.getState(), d = t + "." + e.join("."), g = j(null), S = u(d);
|
|
101
|
+
S || l(t + "." + e.join("."), g);
|
|
102
|
+
const z = S || g, {
|
|
103
|
+
getValidationErrors: I,
|
|
104
|
+
addValidationError: U,
|
|
105
|
+
getInitialOptions: A,
|
|
106
|
+
removeValidationError: w
|
|
107
|
+
} = a.getState(), y = H(t, e), [k, C] = b(
|
|
108
|
+
a.getState().getNestedState(t, e)
|
|
109
|
+
), m = A(t);
|
|
110
|
+
if (!m?.validation?.key)
|
|
111
|
+
throw new Error(
|
|
112
|
+
"Validation key not found. You need to set it in the options for the createCogsState function"
|
|
113
|
+
);
|
|
114
|
+
const f = m.validation.key;
|
|
115
|
+
m.validation.onBlur, F(() => {
|
|
116
|
+
C(y);
|
|
117
|
+
}, [t, e.join("."), y]);
|
|
118
|
+
const v = j();
|
|
119
|
+
let $ = (c, O) => {
|
|
120
|
+
C(c), v.current && clearTimeout(v.current), v.current = setTimeout(
|
|
121
|
+
() => {
|
|
122
|
+
console.log(typeof y), Z(r, c, e, f);
|
|
123
|
+
},
|
|
124
|
+
o?.debounceTime ?? (typeof y == "boolean" ? 20 : 200)
|
|
125
|
+
);
|
|
107
126
|
};
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
const J = async () => {
|
|
128
|
+
if (m.validation?.zodSchema) {
|
|
129
|
+
w(f + "." + e.join("."));
|
|
130
|
+
try {
|
|
131
|
+
const c = a.getState().getNestedState(t, e);
|
|
132
|
+
await Y(
|
|
133
|
+
f,
|
|
134
|
+
m.validation.zodSchema,
|
|
135
|
+
e,
|
|
136
|
+
c
|
|
137
|
+
), console.log(
|
|
138
|
+
"Validation",
|
|
139
|
+
t,
|
|
140
|
+
m.validation.zodSchema,
|
|
141
|
+
e,
|
|
142
|
+
c
|
|
143
|
+
), i({});
|
|
144
|
+
} catch (c) {
|
|
145
|
+
console.error("Validation error:", c);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
F(() => () => {
|
|
150
|
+
v.current && clearTimeout(v.current);
|
|
110
151
|
}, []);
|
|
111
|
-
const
|
|
112
|
-
...
|
|
113
|
-
date: new Date(
|
|
114
|
-
} : null,
|
|
115
|
-
get: () =>
|
|
116
|
-
set:
|
|
117
|
-
syncStatus:
|
|
152
|
+
const N = q(t, e), P = N ? {
|
|
153
|
+
...N,
|
|
154
|
+
date: new Date(N.timeStamp)
|
|
155
|
+
} : null, D = n({
|
|
156
|
+
get: () => k || a.getState().getNestedState(t, e),
|
|
157
|
+
set: $,
|
|
158
|
+
syncStatus: P,
|
|
118
159
|
path: e,
|
|
119
|
-
validationErrors: () =>
|
|
120
|
-
|
|
160
|
+
validationErrors: () => I(f + "." + e.join(".")),
|
|
161
|
+
addValidationError: (c) => {
|
|
162
|
+
w(f + "." + e.join(".")), U(f + "." + e.join("."), c ?? "");
|
|
163
|
+
},
|
|
121
164
|
inputProps: {
|
|
122
|
-
value:
|
|
123
|
-
onChange: (
|
|
165
|
+
value: k || a.getState().getNestedState(t, e) || "",
|
|
166
|
+
onChange: (c) => $(c.target.value),
|
|
167
|
+
onBlur: J,
|
|
168
|
+
ref: z
|
|
124
169
|
}
|
|
125
170
|
});
|
|
126
|
-
return /* @__PURE__ */
|
|
127
|
-
|
|
171
|
+
return /* @__PURE__ */ V(G, { children: /* @__PURE__ */ V(
|
|
172
|
+
L,
|
|
128
173
|
{
|
|
129
174
|
formOpts: o,
|
|
130
175
|
path: e,
|
|
131
|
-
validationKey:
|
|
132
|
-
stateKey:
|
|
133
|
-
children:
|
|
176
|
+
validationKey: f,
|
|
177
|
+
stateKey: t,
|
|
178
|
+
children: D
|
|
134
179
|
}
|
|
135
180
|
) });
|
|
136
181
|
};
|
|
137
|
-
function
|
|
138
|
-
formOpts:
|
|
139
|
-
path:
|
|
140
|
-
validationKey:
|
|
141
|
-
stateKey:
|
|
142
|
-
children:
|
|
143
|
-
validIndices:
|
|
182
|
+
function L({
|
|
183
|
+
formOpts: r,
|
|
184
|
+
path: e,
|
|
185
|
+
validationKey: n,
|
|
186
|
+
stateKey: o,
|
|
187
|
+
children: t,
|
|
188
|
+
validIndices: s
|
|
144
189
|
}) {
|
|
145
|
-
const { getInitialOptions:
|
|
190
|
+
const { getInitialOptions: i } = a.getState(), l = _(
|
|
191
|
+
n,
|
|
146
192
|
e,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
g.includes(m) || g.push(m);
|
|
193
|
+
s
|
|
194
|
+
), u = [];
|
|
195
|
+
if (l) {
|
|
196
|
+
const S = l.join(", ");
|
|
197
|
+
u.includes(S) || u.push(S);
|
|
153
198
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return /* @__PURE__ */
|
|
157
|
-
children: /* @__PURE__ */
|
|
158
|
-
active:
|
|
159
|
-
message:
|
|
160
|
-
path:
|
|
161
|
-
...
|
|
162
|
-
}) : /* @__PURE__ */
|
|
199
|
+
const d = i(o);
|
|
200
|
+
let g = d?.validation?.onBlur ? u?.length > 0 ? u?.join(", ") : r?.validation?.message ? r?.validation?.message : "" : "";
|
|
201
|
+
return /* @__PURE__ */ V(G, { children: d?.formElements?.validation && !r?.validation?.disable ? d.formElements.validation({
|
|
202
|
+
children: /* @__PURE__ */ V(B.Fragment, { children: t }, e.toString()),
|
|
203
|
+
active: g != "",
|
|
204
|
+
message: r?.validation?.hideMessage ? "" : g,
|
|
205
|
+
path: e,
|
|
206
|
+
...r?.key && { key: r?.key }
|
|
207
|
+
}) : /* @__PURE__ */ V(B.Fragment, { children: t }, e.toString()) });
|
|
163
208
|
}
|
|
164
209
|
export {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
210
|
+
ne as FormControlComponent,
|
|
211
|
+
L as ValidationWrapper,
|
|
212
|
+
te as cutFunc,
|
|
213
|
+
ee as pushFunc,
|
|
214
|
+
Z as updateFn,
|
|
215
|
+
H as useGetKeyState,
|
|
216
|
+
q as useGetSyncInfo,
|
|
217
|
+
_ as useGetValidationErrors,
|
|
218
|
+
T as useStoreSubscription
|
|
174
219
|
};
|
|
175
220
|
//# sourceMappingURL=Functions.jsx.map
|
package/dist/Functions.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Functions.jsx","sources":["../src/Functions.tsx"],"sourcesContent":["import type {\r\n EffectiveSetState,\r\n FormElementParmas,\r\n FormOptsType,\r\n UpdateArg,\r\n UpdateOpts,\r\n} from \"./CogsState\";\r\n\r\nimport { getNestedValue, isFunction, updateNestedProperty } from \"./utility\";\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport React from \"react\";\r\nimport { getGlobalStore } from \"./store\";\r\n\r\nexport function updateFn<U>(\r\n setState: EffectiveSetState<U>,\r\n payload: UpdateArg<U>,\r\n path: string[],\r\n validationKey?: string,\r\n): void {\r\n setState(\r\n (prevState) => {\r\n if (isFunction<U>(payload)) {\r\n const nestedValue = payload(getNestedValue(prevState, path));\r\n let value = updateNestedProperty(path, prevState, nestedValue);\r\n if (typeof value == \"string\") {\r\n value = value.trim();\r\n }\r\n return value;\r\n } else {\r\n let value =\r\n !path || path.length == 0\r\n ? payload\r\n : updateNestedProperty(path, prevState, payload);\r\n if (typeof value == \"string\") {\r\n value = value.trim();\r\n }\r\n return value;\r\n }\r\n },\r\n path,\r\n { updateType: \"update\" },\r\n validationKey,\r\n );\r\n}\r\n\r\nexport function pushFunc<U>(\r\n setState: EffectiveSetState<U>,\r\n payload: UpdateArg<U>,\r\n path: string[],\r\n stateKey: string,\r\n index?: number,\r\n): void {\r\n const array = getGlobalStore\r\n .getState()\r\n .getNestedState(stateKey, path) as U[];\r\n setState(\r\n (prevState) => {\r\n let arrayToUpdate =\r\n !path || path.length == 0\r\n ? prevState\r\n : getNestedValue(prevState, [...path]);\r\n let returnedArray = [...arrayToUpdate];\r\n\r\n returnedArray.splice(\r\n index || Number(index) == 0 ? index : arrayToUpdate.length,\r\n 0,\r\n isFunction<U>(payload)\r\n ? payload(index == -1 ? undefined : arrayToUpdate)\r\n : payload,\r\n );\r\n const value =\r\n path.length == 0\r\n ? returnedArray\r\n : updateNestedProperty([...path], prevState, returnedArray);\r\n\r\n return value as U;\r\n },\r\n [\r\n ...path,\r\n index || index === 0\r\n ? index?.toString()\r\n : (array!.length - 1).toString(),\r\n ],\r\n {\r\n updateType: \"insert\",\r\n },\r\n );\r\n}\r\n\r\nexport function cutFunc<U>(\r\n setState: EffectiveSetState<U>,\r\n path: string[],\r\n stateKey: string,\r\n index: number,\r\n): void {\r\n const array = getGlobalStore\r\n .getState()\r\n .getNestedState(stateKey, path) as U[];\r\n setState(\r\n (prevState) => {\r\n const arrayToUpdate = getNestedValue(prevState, [...path]);\r\n if (index < 0 || index >= arrayToUpdate?.length) {\r\n throw new Error(`Index ${index} does not exist in the array.`);\r\n }\r\n const indexToCut =\r\n index || Number(index) == 0 ? index : arrayToUpdate.length - 1;\r\n\r\n const updatedArray = [\r\n ...arrayToUpdate.slice(0, indexToCut),\r\n ...arrayToUpdate.slice(indexToCut + 1),\r\n ] as U;\r\n\r\n console.log(index);\r\n return path.length == 0\r\n ? updatedArray\r\n : updateNestedProperty([...path], prevState, updatedArray);\r\n },\r\n [\r\n ...path,\r\n index || index === 0\r\n ? index?.toString()\r\n : (array!.length - 1).toString(),\r\n ],\r\n { updateType: \"cut\" },\r\n );\r\n}\r\n\r\nexport const useStoreSubscription = <T,>(\r\n fullPath: string,\r\n selector: (\r\n store: ReturnType<typeof getGlobalStore.getState>,\r\n path: string,\r\n ) => T,\r\n compare: (a: T, b: T) => boolean = (a, b) =>\r\n JSON.stringify(a) === JSON.stringify(b),\r\n) => {\r\n const [value, setValue] = useState<T>(() =>\r\n selector(getGlobalStore.getState(), fullPath),\r\n );\r\n const previousValueRef = useRef<T>(value);\r\n\r\n useEffect(() => {\r\n const unsubscribe = getGlobalStore.subscribe((store) => {\r\n const newValue = selector(store, fullPath);\r\n if (!compare(previousValueRef.current, newValue)) {\r\n previousValueRef.current = newValue;\r\n setValue(newValue);\r\n }\r\n });\r\n\r\n return () => unsubscribe();\r\n }, [fullPath]);\r\n\r\n return value;\r\n};\r\nexport const useGetValidationErrors = (\r\n validationKey: string,\r\n path: string[],\r\n validIndices?: number[],\r\n) => {\r\n // Construct the full path the same way as ValidationWrapper\r\n const fullPath =\r\n validationKey +\r\n \".\" +\r\n (path.length > 0 ? [path.join(\".\")] : []) +\r\n (validIndices && validIndices.length > 0 ? \".\" + validIndices : \"\");\r\n\r\n // Skip subscription if we have empty indices\r\n if (validIndices?.length === 0) {\r\n return [];\r\n }\r\n\r\n return useStoreSubscription(\r\n fullPath,\r\n (store, path) => store.getValidationErrors(path) || [],\r\n );\r\n};\r\n\r\nexport const useGetSyncInfo = (key: string, path: string[]) => {\r\n const syncKey = `${key}:${path.join(\".\")}`;\r\n return useStoreSubscription(syncKey, (store, path) =>\r\n store.getSyncInfo(path),\r\n );\r\n};\r\nexport const useGetKeyState = (key: string, path: string[]) => {\r\n return useStoreSubscription(`${key}:${path.join(\".\")}`, (store, fullPath) =>\r\n store.getNestedState(key, path),\r\n );\r\n};\r\ninterface FormControlComponentProps<TStateObject> {\r\n setState: EffectiveSetState<TStateObject>;\r\n validationKey: string;\r\n path: string[];\r\n child: (obj: FormElementParmas<TStateObject>) => JSX.Element;\r\n formOpts?: FormOptsType;\r\n stateKey: string;\r\n}\r\nexport const FormControlComponent = <TStateObject,>({\r\n setState,\r\n validationKey,\r\n path,\r\n child,\r\n formOpts,\r\n stateKey,\r\n}: FormControlComponentProps<TStateObject>) => {\r\n const { getValidationErrors } = getGlobalStore.getState();\r\n\r\n const stateValue = useGetKeyState(stateKey, path);\r\n const [inputValue, setInputValue] = useState<any>(\r\n getGlobalStore.getState().getNestedState(stateKey, path),\r\n );\r\n\r\n useEffect(() => {\r\n setInputValue(stateValue);\r\n }, [stateKey, path.join(\".\"), stateValue]);\r\n\r\n const timeoutRef = useRef<NodeJS.Timeout>();\r\n\r\n let updater = (\r\n payload: UpdateArg<TStateObject>,\r\n opts?: UpdateOpts<TStateObject>,\r\n ) => {\r\n setInputValue(payload);\r\n\r\n if (timeoutRef.current) {\r\n clearTimeout(timeoutRef.current);\r\n }\r\n\r\n timeoutRef.current = setTimeout(() => {\r\n updateFn(setState, payload, path, validationKey);\r\n }, formOpts?.debounceTime ?? 300);\r\n };\r\n\r\n // Clear timeout on unmount\r\n useEffect(() => {\r\n return () => {\r\n if (timeoutRef.current) {\r\n clearTimeout(timeoutRef.current);\r\n }\r\n };\r\n }, []);\r\n\r\n const rawSyncStatus = useGetSyncInfo(stateKey, path);\r\n const syncStatus = rawSyncStatus\r\n ? {\r\n ...rawSyncStatus,\r\n date: new Date(rawSyncStatus.timeStamp),\r\n }\r\n : null;\r\n const childElement = child({\r\n get: () =>\r\n inputValue ||\r\n getGlobalStore.getState().getNestedState(stateKey, path),\r\n set: updater,\r\n syncStatus,\r\n path: path,\r\n validationErrors: () =>\r\n getValidationErrors(validationKey + \".\" + path.join(\".\")),\r\n\r\n // Add default input props\r\n inputProps: {\r\n value:\r\n inputValue ||\r\n getGlobalStore.getState().getNestedState(stateKey, path) ||\r\n \"\",\r\n onChange: (e: any) => updater(e.target.value),\r\n },\r\n });\r\n\r\n return (\r\n <>\r\n <ValidationWrapper\r\n {...{\r\n formOpts,\r\n path,\r\n validationKey,\r\n stateKey,\r\n }}\r\n >\r\n {childElement}\r\n </ValidationWrapper>\r\n </>\r\n );\r\n};\r\n\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n validationKey,\r\n stateKey,\r\n children,\r\n validIndices,\r\n}: {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n validationKey: string;\r\n stateKey?: string;\r\n children: React.ReactNode;\r\n validIndices?: number[];\r\n}) {\r\n const { getInitialOptions, getValidationErrors } =\r\n getGlobalStore.getState();\r\n const validationErrors = useGetValidationErrors(\r\n validationKey,\r\n path,\r\n validIndices,\r\n );\r\n const thesMessages: string[] = [];\r\n\r\n if (validationErrors) {\r\n const newMessage = validationErrors!.join(\", \");\r\n if (!thesMessages.includes(newMessage)) {\r\n thesMessages.push(newMessage);\r\n }\r\n }\r\n let fullMessageString =\r\n thesMessages?.length > 0 ? thesMessages?.join(\", \") : \"\";\r\n\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>\r\n {children}\r\n </React.Fragment>\r\n ),\r\n active: fullMessageString != \"\" ? true : false,\r\n message: formOpts?.validation?.message\r\n ? formOpts?.validation?.message\r\n : formOpts?.validation?.message == \"\"\r\n ? \"\"\r\n : fullMessageString,\r\n path,\r\n\r\n ...(formOpts?.key && { key: formOpts?.key }),\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>\r\n {children}\r\n </React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\n"],"names":["updateFn","setState","payload","path","validationKey","prevState","isFunction","nestedValue","getNestedValue","value","updateNestedProperty","pushFunc","stateKey","index","array","getGlobalStore","arrayToUpdate","returnedArray","cutFunc","indexToCut","updatedArray","useStoreSubscription","fullPath","selector","compare","a","b","setValue","useState","previousValueRef","useRef","useEffect","unsubscribe","store","newValue","useGetValidationErrors","validIndices","useGetSyncInfo","key","syncKey","useGetKeyState","FormControlComponent","child","formOpts","getValidationErrors","stateValue","inputValue","setInputValue","timeoutRef","updater","opts","rawSyncStatus","syncStatus","childElement","e","jsx","Fragment","ValidationWrapper","children","getInitialOptions","validationErrors","thesMessages","newMessage","fullMessageString","thisStateOpts","React"],"mappings":";;;;AAaO,SAASA,EACZC,GACAC,GACAC,GACAC,GACI;AACJ,EAAAH;AAAA,IACI,CAACI,MAAc;AACP,UAAAC,EAAcJ,CAAO,GAAG;AACxB,cAAMK,IAAcL,EAAQM,EAAeH,GAAWF,CAAI,CAAC;AAC3D,YAAIM,IAAQC,EAAqBP,GAAME,GAAWE,CAAW;AACzD,eAAA,OAAOE,KAAS,aAChBA,IAAQA,EAAM,KAAK,IAEhBA;AAAA,MAAA,OACJ;AACC,YAAAA,IACA,CAACN,KAAQA,EAAK,UAAU,IAClBD,IACAQ,EAAqBP,GAAME,GAAWH,CAAO;AACnD,eAAA,OAAOO,KAAS,aAChBA,IAAQA,EAAM,KAAK,IAEhBA;AAAA,MAAA;AAAA,IAEf;AAAA,IACAN;AAAA,IACA,EAAE,YAAY,SAAS;AAAA,IACvBC;AAAA,EACJ;AACJ;AAEO,SAASO,EACZV,GACAC,GACAC,GACAS,GACAC,GACI;AACJ,QAAMC,IAAQC,EACT,SACA,EAAA,eAAeH,GAAUT,CAAI;AAClC,EAAAF;AAAA,IACI,CAACI,MAAc;AACX,UAAIW,IACA,CAACb,KAAQA,EAAK,UAAU,IAClBE,IACAG,EAAeH,GAAW,CAAC,GAAGF,CAAI,CAAC,GACzCc,IAAgB,CAAC,GAAGD,CAAa;AAEvB,aAAAC,EAAA;AAAA,QACD,OAAOJ,CAAK,KAAK,IAAIA,IAAQG,EAAc;AAAA,QACpD;AAAA,QACAV,EAAcJ,CAAO,IACfA,EAAkCc,CAAa,IAC/Cd;AAAA,MACV,GAEIC,EAAK,UAAU,IACTc,IACAP,EAAqB,CAA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\n notifyComponent,\r\n type EffectiveSetState,\r\n type FormElementParams,\r\n type FormOptsType,\r\n type UpdateArg,\r\n type UpdateOpts,\r\n} from \"./CogsState\";\r\n\r\nimport { getNestedValue, isFunction, updateNestedProperty } from \"./utility\";\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport React from \"react\";\r\nimport { getGlobalStore, formRefStore } from \"./store\";\r\nimport { validateZodPathFunc } from \"./useValidateZodPath\";\r\n\r\nexport function updateFn<U>(\r\n setState: EffectiveSetState<U>,\r\n payload: UpdateArg<U>,\r\n path: string[],\r\n validationKey?: string\r\n): void {\r\n setState(\r\n (prevState) => {\r\n if (isFunction<U>(payload)) {\r\n const nestedValue = payload(getNestedValue(prevState, path));\r\n let value = updateNestedProperty(path, prevState, nestedValue);\r\n if (typeof value == \"string\") {\r\n value = value.trim();\r\n }\r\n return value;\r\n } else {\r\n let value =\r\n !path || path.length == 0\r\n ? payload\r\n : updateNestedProperty(path, prevState, payload);\r\n if (typeof value == \"string\") {\r\n value = value.trim();\r\n }\r\n return value;\r\n }\r\n },\r\n path,\r\n { updateType: \"update\" },\r\n validationKey\r\n );\r\n}\r\n\r\nexport function pushFunc<U>(\r\n setState: EffectiveSetState<U>,\r\n payload: UpdateArg<U>,\r\n path: string[],\r\n stateKey: string,\r\n index?: number\r\n): void {\r\n const array = getGlobalStore.getState().getNestedState(stateKey, path) as U[];\r\n setState(\r\n (prevState) => {\r\n let arrayToUpdate =\r\n !path || path.length == 0\r\n ? prevState\r\n : getNestedValue(prevState, [...path]);\r\n let returnedArray = [...arrayToUpdate];\r\n\r\n returnedArray.splice(\r\n index || Number(index) == 0 ? index : arrayToUpdate.length,\r\n 0,\r\n isFunction<U>(payload)\r\n ? payload(index == -1 ? undefined : arrayToUpdate)\r\n : payload\r\n );\r\n const value =\r\n path.length == 0\r\n ? returnedArray\r\n : updateNestedProperty([...path], prevState, returnedArray);\r\n\r\n return value as U;\r\n },\r\n [\r\n ...path,\r\n index || index === 0 ? index?.toString() : (array!.length - 1).toString(),\r\n ],\r\n {\r\n updateType: \"insert\",\r\n }\r\n );\r\n}\r\n\r\nexport function cutFunc<U>(\r\n setState: EffectiveSetState<U>,\r\n path: string[],\r\n stateKey: string,\r\n index: number\r\n): void {\r\n const array = getGlobalStore.getState().getNestedState(stateKey, path) as U[];\r\n setState(\r\n (prevState) => {\r\n const arrayToUpdate = getNestedValue(prevState, [...path]);\r\n if (index < 0 || index >= arrayToUpdate?.length) {\r\n throw new Error(`Index ${index} does not exist in the array.`);\r\n }\r\n const indexToCut =\r\n index || Number(index) == 0 ? index : arrayToUpdate.length - 1;\r\n\r\n const updatedArray = [\r\n ...arrayToUpdate.slice(0, indexToCut),\r\n ...arrayToUpdate.slice(indexToCut + 1),\r\n ] as U;\r\n\r\n console.log(index);\r\n return path.length == 0\r\n ? updatedArray\r\n : updateNestedProperty([...path], prevState, updatedArray);\r\n },\r\n [\r\n ...path,\r\n index || index === 0 ? index?.toString() : (array!.length - 1).toString(),\r\n ],\r\n { updateType: \"cut\" }\r\n );\r\n}\r\n\r\nexport const useStoreSubscription = <T,>(\r\n fullPath: string,\r\n selector: (\r\n store: ReturnType<typeof getGlobalStore.getState>,\r\n path: string\r\n ) => T,\r\n compare: (a: T, b: T) => boolean = (a, b) =>\r\n JSON.stringify(a) === JSON.stringify(b)\r\n) => {\r\n const [value, setValue] = useState<T>(() =>\r\n selector(getGlobalStore.getState(), fullPath)\r\n );\r\n const previousValueRef = useRef<T>(value);\r\n const fullPathRef = useRef(fullPath);\r\n useEffect(() => {\r\n fullPathRef.current = fullPath; // Ensure latest fullPath is always used\r\n\r\n setValue(selector(getGlobalStore.getState(), fullPath));\r\n\r\n const callback = (store: any) => {\r\n const newValue = selector(store, fullPathRef.current);\r\n\r\n if (!compare(previousValueRef.current, newValue)) {\r\n previousValueRef.current = newValue;\r\n setValue(newValue);\r\n }\r\n };\r\n const unsubscribe = getGlobalStore.subscribe(callback);\r\n return () => {\r\n unsubscribe();\r\n };\r\n }, [fullPath]);\r\n return value;\r\n};\r\nexport const useGetValidationErrors = (\r\n validationKey: string,\r\n path: string[],\r\n validIndices?: number[]\r\n) => {\r\n // Construct the full path the same way as ValidationWrapper\r\n const fullPath =\r\n validationKey +\r\n \".\" +\r\n (path.length > 0 ? [path.join(\".\")] : []) +\r\n (validIndices && validIndices.length > 0 ? \".\" + validIndices : \"\");\r\n\r\n // Skip subscription if we have empty indices\r\n if (validIndices?.length === 0) {\r\n return [];\r\n }\r\n\r\n return useStoreSubscription(\r\n fullPath,\r\n (store, path) => store.getValidationErrors(path) || []\r\n );\r\n};\r\n\r\nexport const useGetSyncInfo = (key: string, path: string[]) => {\r\n const syncKey = `${key}:${path.join(\".\")}`;\r\n return useStoreSubscription(syncKey, (store, path) =>\r\n store.getSyncInfo(path)\r\n );\r\n};\r\nexport const useGetKeyState = (key: string, path: string[]) => {\r\n return useStoreSubscription(`${key}:${path.join(\".\")}`, (store, fullPath) =>\r\n store.getNestedState(key, path)\r\n );\r\n};\r\ninterface FormControlComponentProps<TStateObject> {\r\n setState: EffectiveSetState<TStateObject>;\r\n\r\n path: string[];\r\n child: (obj: FormElementParams<TStateObject>) => JSX.Element;\r\n formOpts?: FormOptsType;\r\n stateKey: string;\r\n}\r\n\r\nexport const FormControlComponent = <TStateObject,>({\r\n setState,\r\n path,\r\n child,\r\n formOpts,\r\n stateKey,\r\n}: FormControlComponentProps<TStateObject>) => {\r\n const [_, forceUpdate] = useState({});\r\n const { registerFormRef, getFormRef } = formRefStore.getState();\r\n const refKey = stateKey + \".\" + path.join(\".\");\r\n\r\n // Create a local ref\r\n const localFormRef = useRef<HTMLInputElement>(null);\r\n\r\n // Get existing ref from the store (if any)\r\n const existingRef = getFormRef(refKey);\r\n if (!existingRef) {\r\n registerFormRef(stateKey + \".\" + path.join(\".\"), localFormRef);\r\n }\r\n // Use the existing ref if available, otherwise use the local one\r\n const formRef = existingRef || localFormRef;\r\n\r\n const {\r\n getValidationErrors,\r\n addValidationError,\r\n getInitialOptions,\r\n removeValidationError,\r\n } = getGlobalStore.getState();\r\n const stateValue = useGetKeyState(stateKey, path);\r\n const [inputValue, setInputValue] = useState<any>(\r\n getGlobalStore.getState().getNestedState(stateKey, path)\r\n );\r\n\r\n const initialOptions = getInitialOptions(stateKey);\r\n if (!initialOptions?.validation?.key) {\r\n throw new Error(\r\n \"Validation key not found. You need to set it in the options for the createCogsState function\"\r\n );\r\n }\r\n const validationKey = initialOptions.validation.key;\r\n const validateOnBlur = initialOptions.validation.onBlur === true;\r\n initialOptions;\r\n useEffect(() => {\r\n setInputValue(stateValue);\r\n }, [stateKey, path.join(\".\"), stateValue]);\r\n\r\n const timeoutRef = useRef<NodeJS.Timeout>();\r\n\r\n // Standard updater function (unchanged)\r\n let updater = (\r\n payload: UpdateArg<TStateObject>,\r\n opts?: UpdateOpts<TStateObject>\r\n ) => {\r\n setInputValue(payload);\r\n\r\n if (timeoutRef.current) {\r\n clearTimeout(timeoutRef.current);\r\n }\r\n\r\n timeoutRef.current = setTimeout(\r\n () => {\r\n console.log(typeof stateValue);\r\n updateFn(setState, payload, path, validationKey);\r\n },\r\n formOpts?.debounceTime ?? (typeof stateValue == \"boolean\" ? 20 : 200)\r\n );\r\n };\r\n\r\n // Handle blur event\r\n const handleBlur = async () => {\r\n if (!initialOptions.validation?.zodSchema) return;\r\n removeValidationError(validationKey + \".\" + path.join(\".\"));\r\n try {\r\n // Get the current field value\r\n const fieldValue = getGlobalStore\r\n .getState()\r\n .getNestedState(stateKey, path);\r\n\r\n // Use your existing validateZodPathFunc\r\n await validateZodPathFunc(\r\n validationKey,\r\n initialOptions.validation.zodSchema,\r\n path,\r\n fieldValue\r\n );\r\n console.log(\r\n \"Validation\",\r\n stateKey,\r\n initialOptions.validation.zodSchema,\r\n path,\r\n fieldValue\r\n );\r\n forceUpdate({});\r\n } catch (error) {\r\n console.error(\"Validation error:\", error);\r\n }\r\n };\r\n\r\n // Clear timeout on unmount\r\n useEffect(() => {\r\n return () => {\r\n if (timeoutRef.current) {\r\n clearTimeout(timeoutRef.current);\r\n }\r\n };\r\n }, []);\r\n\r\n const rawSyncStatus = useGetSyncInfo(stateKey, path);\r\n const syncStatus = rawSyncStatus\r\n ? {\r\n ...rawSyncStatus,\r\n date: new Date(rawSyncStatus.timeStamp),\r\n }\r\n : null;\r\n\r\n const childElement = child({\r\n get: () =>\r\n inputValue || getGlobalStore.getState().getNestedState(stateKey, path),\r\n set: updater,\r\n syncStatus,\r\n path: path,\r\n validationErrors: () =>\r\n getValidationErrors(validationKey + \".\" + path.join(\".\")),\r\n addValidationError: (message?: string) => {\r\n removeValidationError(validationKey + \".\" + path.join(\".\"));\r\n addValidationError(validationKey + \".\" + path.join(\".\"), message ?? \"\");\r\n },\r\n\r\n inputProps: {\r\n value:\r\n inputValue ||\r\n getGlobalStore.getState().getNestedState(stateKey, path) ||\r\n \"\",\r\n onChange: (e: any) => updater(e.target.value),\r\n onBlur: handleBlur,\r\n ref: formRef,\r\n },\r\n });\r\n\r\n return (\r\n <>\r\n <ValidationWrapper\r\n {...{\r\n formOpts,\r\n path,\r\n validationKey,\r\n stateKey,\r\n }}\r\n >\r\n {childElement}\r\n </ValidationWrapper>\r\n </>\r\n );\r\n};\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n validationKey,\r\n stateKey,\r\n children,\r\n validIndices,\r\n}: {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n validationKey: string;\r\n stateKey?: string;\r\n children: React.ReactNode;\r\n validIndices?: number[];\r\n}) {\r\n const { getInitialOptions } = getGlobalStore.getState();\r\n\r\n const validationErrors = useGetValidationErrors(\r\n validationKey,\r\n path,\r\n validIndices\r\n );\r\n\r\n const thesMessages: string[] = [];\r\n\r\n if (validationErrors) {\r\n const newMessage = validationErrors!.join(\", \");\r\n if (!thesMessages.includes(newMessage)) {\r\n thesMessages.push(newMessage);\r\n }\r\n }\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n let fullMessageString = thisStateOpts?.validation?.onBlur\r\n ? thesMessages?.length > 0\r\n ? thesMessages?.join(\", \")\r\n : formOpts?.validation?.message\r\n ? formOpts?.validation?.message\r\n : \"\"\r\n : \"\";\r\n\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n ),\r\n active: fullMessageString != \"\" ? true : false,\r\n message: formOpts?.validation?.hideMessage ? \"\" : fullMessageString,\r\n path,\r\n\r\n ...(formOpts?.key && { key: formOpts?.key }),\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\n"],"names":["updateFn","setState","payload","path","validationKey","prevState","isFunction","nestedValue","getNestedValue","value","updateNestedProperty","pushFunc","stateKey","index","array","getGlobalStore","arrayToUpdate","returnedArray","cutFunc","indexToCut","updatedArray","useStoreSubscription","fullPath","selector","compare","a","b","setValue","useState","previousValueRef","useRef","fullPathRef","useEffect","callback","store","newValue","unsubscribe","useGetValidationErrors","validIndices","useGetSyncInfo","key","syncKey","useGetKeyState","FormControlComponent","child","formOpts","_","forceUpdate","registerFormRef","getFormRef","formRefStore","refKey","localFormRef","existingRef","formRef","getValidationErrors","addValidationError","getInitialOptions","removeValidationError","stateValue","inputValue","setInputValue","initialOptions","timeoutRef","updater","opts","handleBlur","fieldValue","validateZodPathFunc","error","rawSyncStatus","syncStatus","childElement","message","e","jsx","Fragment","ValidationWrapper","children","validationErrors","thesMessages","newMessage","thisStateOpts","fullMessageString","React"],"mappings":";;;;;;AAeO,SAASA,EACdC,GACAC,GACAC,GACAC,GACM;AACN,EAAAH;AAAA,IACE,CAACI,MAAc;AACT,UAAAC,EAAcJ,CAAO,GAAG;AAC1B,cAAMK,IAAcL,EAAQM,EAAeH,GAAWF,CAAI,CAAC;AAC3D,YAAIM,IAAQC,EAAqBP,GAAME,GAAWE,CAAW;AACzD,eAAA,OAA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AAmB,EAAA,IAAsB1C,EAAe,SAAS,GAEhDgE,IAAmB1C;AAAA,IACvBjC;AAAA,IACAD;AAAA,IACAmC;AAAA,EACF,GAEM0C,IAAyB,CAAC;AAEhC,MAAID,GAAkB;AACd,UAAAE,IAAaF,EAAkB,KAAK,IAAI;AAC9C,IAAKC,EAAa,SAASC,CAAU,KACnCD,EAAa,KAAKC,CAAU;AAAA,EAC9B;AAEI,QAAAC,IAAgBzB,EAAkB7C,CAAS;AACjD,MAAIuE,IAAoBD,GAAe,YAAY,SAC/CF,GAAc,SAAS,IACrBA,GAAc,KAAK,IAAI,IACvBnC,GAAU,YAAY,UACpBA,GAAU,YAAY,UACtB,KACJ;AAGF,SAAA,gBAAA8B,EAAAC,GAAA,EACG,UAAeM,GAAA,cAAc,cAC9B,CAACrC,GAAU,YAAY,UACrBqC,EAAc,aAAc,WAAY;AAAA,IACtC,4BACGE,EAAM,UAAN,EAAsC,UAAAN,KAAlB3E,EAAK,UAAsB;AAAA,IAElD,QAAQgF,KAAqB;AAAA,IAC7B,SAAStC,GAAU,YAAY,cAAc,KAAKsC;AAAA,IAClD,MAAAhF;AAAA,IAEA,GAAI0C,GAAU,OAAO,EAAE,KAAKA,GAAU,IAAI;AAAA,EAAA,CAC3C,IAED,gBAAA8B,EAACS,EAAM,UAAN,EAAsC,UAAAN,EAAlB,GAAA3E,EAAK,SAAsB,CAAA,GAEpD;AAEJ;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import { $cogsSignal as r, $cogsSignalStore as
|
|
2
|
-
import {
|
|
1
|
+
import { $cogsSignal as r, $cogsSignalStore as o, createCogsState as n, notifyComponent as s, useCogsStateFn as g } from "./CogsState.jsx";
|
|
2
|
+
import { config as f, useCogsConfig as i } from "./CogsStateClient.jsx";
|
|
3
|
+
import { debounce as p, deleteNestedProperty as u, getArrayLengthDifferences as y, getArrayLengthDifferencesArray as d, getDifferences as S, getDifferencesArray as l, getNestedValue as m, isArray as A, isDeepEqual as C, isFunction as D, isObject as x, transformStateFunc as F, updateNestedProperty as N } from "./utility.js";
|
|
3
4
|
export {
|
|
4
5
|
r as $cogsSignal,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
o as $cogsSignalStore,
|
|
7
|
+
f as config,
|
|
7
8
|
n as createCogsState,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
d as
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
p as debounce,
|
|
10
|
+
u as deleteNestedProperty,
|
|
11
|
+
y as getArrayLengthDifferences,
|
|
12
|
+
d as getArrayLengthDifferencesArray,
|
|
13
|
+
S as getDifferences,
|
|
14
|
+
l as getDifferencesArray,
|
|
15
|
+
m as getNestedValue,
|
|
16
|
+
A as isArray,
|
|
17
|
+
C as isDeepEqual,
|
|
18
|
+
D as isFunction,
|
|
19
|
+
x as isObject,
|
|
20
|
+
s as notifyComponent,
|
|
21
|
+
F as transformStateFunc,
|
|
22
|
+
N as updateNestedProperty,
|
|
23
|
+
i as useCogsConfig,
|
|
24
|
+
g as useCogsStateFn
|
|
21
25
|
};
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionsType, StateKeys, SyncActionsType, SyncInfo, UpdateTypeDetail } from './CogsState.js';
|
|
1
|
+
import { OptionsType, ReactivityType, StateKeys, SyncActionsType, SyncInfo, UpdateTypeDetail } from './CogsState.js';
|
|
2
2
|
|
|
3
3
|
type StateUpdater<StateValue> = StateValue | ((prevValue: StateValue) => StateValue);
|
|
4
4
|
export type FreshValuesObject = {
|
|
@@ -11,6 +11,23 @@ type SyncLogType = {
|
|
|
11
11
|
timeStamp: number;
|
|
12
12
|
};
|
|
13
13
|
type StateValue = any;
|
|
14
|
+
export type ComponentsType = {
|
|
15
|
+
components: Map<string, {
|
|
16
|
+
forceUpdate: () => void;
|
|
17
|
+
paths: Set<string>;
|
|
18
|
+
deps?: any[];
|
|
19
|
+
depsFunction?: (state: any) => any[] | true;
|
|
20
|
+
reactiveType: ReactivityType[] | ReactivityType;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export type FormRefStoreState = {
|
|
24
|
+
formRefs: Map<string, React.RefObject<any>>;
|
|
25
|
+
registerFormRef: (id: string, ref: React.RefObject<any>) => void;
|
|
26
|
+
getFormRef: (id: string) => React.RefObject<any> | undefined;
|
|
27
|
+
removeFormRef: (id: string) => void;
|
|
28
|
+
getFormRefsByStateKey: (stateKey: string) => Map<string, React.RefObject<any>>;
|
|
29
|
+
};
|
|
30
|
+
export declare const formRefStore: import('zustand').UseBoundStore<import('zustand').StoreApi<FormRefStoreState>>;
|
|
14
31
|
export type CogsGlobalState = {
|
|
15
32
|
updaterState: {
|
|
16
33
|
[key: string]: any;
|
|
@@ -91,14 +108,7 @@ export type CogsGlobalState = {
|
|
|
91
108
|
}) => void;
|
|
92
109
|
deleteReactiveDeps: (key: string) => void;
|
|
93
110
|
subscribe: (listener: () => void) => () => void;
|
|
94
|
-
stateComponents: Map<string,
|
|
95
|
-
components: Map<string, {
|
|
96
|
-
forceUpdate: () => void;
|
|
97
|
-
paths: Set<string>;
|
|
98
|
-
deps?: any[];
|
|
99
|
-
depsFunction?: (state: any) => any[] | true;
|
|
100
|
-
}>;
|
|
101
|
-
}>;
|
|
111
|
+
stateComponents: Map<string, ComponentsType>;
|
|
102
112
|
syncInfoStore: Map<string, SyncInfo>;
|
|
103
113
|
setSyncInfo: (key: string, syncInfo: SyncInfo) => void;
|
|
104
114
|
getSyncInfo: (key: string) => SyncInfo | null;
|