cogsbox-state 0.5.125 → 0.5.127
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.jsx +274 -265
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.jsx +130 -141
- package/dist/Functions.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as le } from "react/jsx-runtime";
|
|
3
|
-
import { useState as ne, useRef as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as ee, updateFn as
|
|
3
|
+
import { useState as ne, useRef as H, useEffect as re, useLayoutEffect as _e, useMemo as Ee, createElement as Q, useSyncExternalStore as we, startTransition as $e } from "react";
|
|
4
|
+
import { transformStateFunc as he, isFunction as L, getDifferences as Ae, getNestedValue as D, isDeepEqual as U, debounce as Ne } from "./utility.js";
|
|
5
|
+
import { pushFunc as ee, updateFn as J, cutFunc as Z, ValidationWrapper as Te, FormControlComponent as Ve } from "./Functions.jsx";
|
|
6
6
|
import "zod";
|
|
7
7
|
import { getGlobalStore as r, formRefStore as de } from "./store.js";
|
|
8
|
-
import { useCogsConfig as
|
|
9
|
-
import
|
|
8
|
+
import { useCogsConfig as pe } from "./CogsStateClient.jsx";
|
|
9
|
+
import ae from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
10
|
function ue(e, i) {
|
|
11
11
|
const v = r.getState().getInitialOptions, S = r.getState().setInitialStateOptions, d = v(e) || {};
|
|
12
12
|
S(e, {
|
|
@@ -19,19 +19,19 @@ function ge({
|
|
|
19
19
|
options: i,
|
|
20
20
|
initialOptionsPart: v
|
|
21
21
|
}) {
|
|
22
|
-
const S =
|
|
22
|
+
const S = B(e) || {}, d = v[e] || {}, E = r.getState().setInitialStateOptions, _ = { ...d, ...S };
|
|
23
23
|
let m = !1;
|
|
24
24
|
if (i)
|
|
25
25
|
for (const c in i)
|
|
26
26
|
_.hasOwnProperty(c) ? (c == "localStorage" && i[c] && _[c].key !== i[c]?.key && (m = !0, _[c] = i[c]), c == "initialState" && i[c] && _[c] !== i[c] && (m = !0, _[c] = i[c])) : (m = !0, _[c] = i[c]);
|
|
27
27
|
m && E(e, _);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function Je(e, { formElements: i, validation: v }) {
|
|
30
30
|
return { initialState: e, formElements: i, validation: v };
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const Ze = (e, i) => {
|
|
33
33
|
let v = e;
|
|
34
|
-
const [S, d] =
|
|
34
|
+
const [S, d] = he(v);
|
|
35
35
|
(Object.keys(d).length > 0 || i && Object.keys(i).length > 0) && Object.keys(d).forEach((m) => {
|
|
36
36
|
d[m] = d[m] || {}, d[m].formElements = {
|
|
37
37
|
...i?.formElements,
|
|
@@ -39,16 +39,16 @@ const ze = (e, i) => {
|
|
|
39
39
|
...i?.validation,
|
|
40
40
|
...d[m].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
|
-
},
|
|
42
|
+
}, B(m) || r.getState().setInitialStateOptions(m, d[m]);
|
|
43
43
|
}), r.getState().setInitialStates(S), r.getState().setCreatedState(S);
|
|
44
44
|
const E = (m, c) => {
|
|
45
|
-
const [f] = ne(c?.componentId ??
|
|
45
|
+
const [f] = ne(c?.componentId ?? ae());
|
|
46
46
|
ge({
|
|
47
47
|
stateKey: m,
|
|
48
48
|
options: c,
|
|
49
49
|
initialOptionsPart: d
|
|
50
50
|
});
|
|
51
|
-
const t = r.getState().cogsStateStore[m] || S[m], y = c?.modifyState ? c.modifyState(t) : t, [
|
|
51
|
+
const t = r.getState().cogsStateStore[m] || S[m], y = c?.modifyState ? c.modifyState(t) : t, [C, T] = je(
|
|
52
52
|
y,
|
|
53
53
|
{
|
|
54
54
|
stateKey: m,
|
|
@@ -70,16 +70,16 @@ const ze = (e, i) => {
|
|
|
70
70
|
}
|
|
71
71
|
return { useCogsState: E, setCogsOptions: _ };
|
|
72
72
|
}, {
|
|
73
|
-
setUpdaterState:
|
|
74
|
-
setState:
|
|
75
|
-
getInitialOptions:
|
|
73
|
+
setUpdaterState: Y,
|
|
74
|
+
setState: G,
|
|
75
|
+
getInitialOptions: B,
|
|
76
76
|
getKeyState: fe,
|
|
77
|
-
getValidationErrors:
|
|
78
|
-
setStateLog:
|
|
79
|
-
updateInitialStateGlobal:
|
|
80
|
-
addValidationError:
|
|
81
|
-
removeValidationError:
|
|
82
|
-
setServerSyncActions:
|
|
77
|
+
getValidationErrors: ke,
|
|
78
|
+
setStateLog: Ce,
|
|
79
|
+
updateInitialStateGlobal: oe,
|
|
80
|
+
addValidationError: xe,
|
|
81
|
+
removeValidationError: R,
|
|
82
|
+
setServerSyncActions: be
|
|
83
83
|
} = r.getState(), Se = (e) => {
|
|
84
84
|
if (!e) return null;
|
|
85
85
|
try {
|
|
@@ -88,7 +88,7 @@ const ze = (e, i) => {
|
|
|
88
88
|
} catch (i) {
|
|
89
89
|
return console.error("Error loading from localStorage:", i), null;
|
|
90
90
|
}
|
|
91
|
-
},
|
|
91
|
+
}, Oe = (e, i, v, S) => {
|
|
92
92
|
v?.log && console.log(
|
|
93
93
|
"saving to localstorage",
|
|
94
94
|
i,
|
|
@@ -105,10 +105,10 @@ const ze = (e, i) => {
|
|
|
105
105
|
}, _ = `${S}-${i}-${d}`;
|
|
106
106
|
window.localStorage.setItem(_, JSON.stringify(E));
|
|
107
107
|
}
|
|
108
|
-
},
|
|
108
|
+
}, Pe = (e, i, v, S, d, E) => {
|
|
109
109
|
const _ = {
|
|
110
110
|
initialState: i,
|
|
111
|
-
updaterState:
|
|
111
|
+
updaterState: X(
|
|
112
112
|
e,
|
|
113
113
|
S,
|
|
114
114
|
d,
|
|
@@ -116,7 +116,7 @@ const ze = (e, i) => {
|
|
|
116
116
|
),
|
|
117
117
|
state: v
|
|
118
118
|
};
|
|
119
|
-
|
|
119
|
+
oe(e, _.initialState), Y(e, _.updaterState), G(e, _.state);
|
|
120
120
|
}, ie = (e) => {
|
|
121
121
|
const i = r.getState().stateComponents.get(e);
|
|
122
122
|
if (!i) return;
|
|
@@ -126,7 +126,7 @@ const ze = (e, i) => {
|
|
|
126
126
|
}), queueMicrotask(() => {
|
|
127
127
|
v.forEach((S) => S());
|
|
128
128
|
});
|
|
129
|
-
},
|
|
129
|
+
}, He = (e, i) => {
|
|
130
130
|
const v = r.getState().stateComponents.get(e);
|
|
131
131
|
if (v) {
|
|
132
132
|
const S = `${e}////${i}`, d = v.components.get(S);
|
|
@@ -135,7 +135,7 @@ const ze = (e, i) => {
|
|
|
135
135
|
d && d.forceUpdate();
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
|
-
function
|
|
138
|
+
function je(e, {
|
|
139
139
|
stateKey: i,
|
|
140
140
|
serverSync: v,
|
|
141
141
|
localStorage: S,
|
|
@@ -148,13 +148,13 @@ function Oe(e, {
|
|
|
148
148
|
syncUpdate: t,
|
|
149
149
|
dependencies: y
|
|
150
150
|
} = {}) {
|
|
151
|
-
const [
|
|
152
|
-
let
|
|
153
|
-
const [g] = ne(i ??
|
|
154
|
-
|
|
151
|
+
const [C, T] = ne({}), { sessionId: x } = pe();
|
|
152
|
+
let M = !i;
|
|
153
|
+
const [g] = ne(i ?? ae()), s = r.getState().stateLog[g], W = H(/* @__PURE__ */ new Set()), P = H(c ?? ae()), p = H(null);
|
|
154
|
+
p.current = B(g), re(() => {
|
|
155
155
|
if (t && t.stateKey === g && t.path?.[0]) {
|
|
156
|
-
|
|
157
|
-
...
|
|
156
|
+
G(g, (a) => ({
|
|
157
|
+
...a,
|
|
158
158
|
[t.path[0]]: t.newValue
|
|
159
159
|
}));
|
|
160
160
|
const l = `${t.stateKey}:${t.path.join(".")}`;
|
|
@@ -167,189 +167,198 @@ function Oe(e, {
|
|
|
167
167
|
f && ue(g, {
|
|
168
168
|
initialState: f
|
|
169
169
|
});
|
|
170
|
-
const l =
|
|
171
|
-
let
|
|
170
|
+
const l = p.current;
|
|
171
|
+
let a = null;
|
|
172
172
|
const u = L(l?.localStorage?.key) ? l?.localStorage?.key(f) : l?.localStorage?.key;
|
|
173
|
-
console.log("newoptions", l), console.log("localkey", u), console.log("initialState", f), u &&
|
|
174
|
-
|
|
173
|
+
console.log("newoptions", l), console.log("localkey", u), console.log("initialState", f), u && x && (a = Se(
|
|
174
|
+
x + "-" + g + "-" + u
|
|
175
175
|
));
|
|
176
|
-
const
|
|
177
|
-
console.log("createdState - intiual",
|
|
178
|
-
let
|
|
176
|
+
const w = r.getState().iniitialCreatedState[g];
|
|
177
|
+
console.log("createdState - intiual", w, f);
|
|
178
|
+
let N = null;
|
|
179
179
|
if (f) {
|
|
180
|
-
|
|
180
|
+
N = f, a && a.lastUpdated > (a.lastSyncedWithServer || 0) && (N = a.state, l?.localStorage?.onChange && l?.localStorage?.onChange(N)), console.log("newState thius is newstate", N), Pe(
|
|
181
181
|
g,
|
|
182
182
|
f,
|
|
183
|
-
|
|
183
|
+
N,
|
|
184
184
|
n,
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
P.current,
|
|
186
|
+
x
|
|
187
187
|
), ie(g);
|
|
188
|
-
const
|
|
189
|
-
console.log("reactiveTypes.............................",
|
|
188
|
+
const h = Array.isArray(m) ? m : [m || "component"];
|
|
189
|
+
console.log("reactiveTypes.............................", h), h.includes("none") || T({});
|
|
190
190
|
}
|
|
191
|
-
}, [f, ...y || []]),
|
|
192
|
-
|
|
191
|
+
}, [f, ...y || []]), _e(() => {
|
|
192
|
+
M && ue(g, {
|
|
193
193
|
serverSync: v,
|
|
194
194
|
formElements: d,
|
|
195
195
|
initialState: f,
|
|
196
196
|
localStorage: S,
|
|
197
197
|
middleware: E
|
|
198
198
|
});
|
|
199
|
-
const l = `${g}////${
|
|
199
|
+
const l = `${g}////${P.current}`, a = r.getState().stateComponents.get(g) || {
|
|
200
200
|
components: /* @__PURE__ */ new Map()
|
|
201
201
|
};
|
|
202
|
-
return
|
|
202
|
+
return a.components.set(l, {
|
|
203
203
|
forceUpdate: () => T({}),
|
|
204
204
|
paths: /* @__PURE__ */ new Set(),
|
|
205
205
|
deps: [],
|
|
206
206
|
depsFunction: _ || void 0,
|
|
207
207
|
reactiveType: m ?? ["component", "deps"]
|
|
208
|
-
}), r.getState().stateComponents.set(g,
|
|
209
|
-
const u = `${g}////${
|
|
210
|
-
|
|
208
|
+
}), r.getState().stateComponents.set(g, a), T({}), () => {
|
|
209
|
+
const u = `${g}////${P.current}`;
|
|
210
|
+
a && (a.components.delete(u), a.components.size === 0 && r.getState().stateComponents.delete(g));
|
|
211
211
|
};
|
|
212
212
|
}, []);
|
|
213
|
-
const n = (l,
|
|
214
|
-
if (Array.isArray(
|
|
215
|
-
const
|
|
216
|
-
|
|
213
|
+
const n = (l, a, u, w) => {
|
|
214
|
+
if (Array.isArray(a)) {
|
|
215
|
+
const N = `${g}-${a.join(".")}`;
|
|
216
|
+
W.current.add(N);
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
let
|
|
218
|
+
G(g, (N) => {
|
|
219
|
+
const h = L(l) ? l(N) : l, j = Ae(N, h), O = new Set(j), q = `${g}-${a.join(".")}`;
|
|
220
|
+
if (q) {
|
|
221
|
+
let F = !1, I = r.getState().signalDomElements.get(q);
|
|
222
222
|
if ((!I || I.size === 0) && (u.updateType === "insert" || u.updateType === "cut")) {
|
|
223
|
-
const
|
|
223
|
+
const A = a.slice(0, -1), V = D(h, A);
|
|
224
224
|
if (Array.isArray(V)) {
|
|
225
|
-
|
|
226
|
-
const $ = `${g}-${
|
|
225
|
+
F = !0;
|
|
226
|
+
const $ = `${g}-${A.join(".")}`;
|
|
227
227
|
I = r.getState().signalDomElements.get($);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
if (I) {
|
|
231
|
-
const
|
|
232
|
-
I.forEach(({ parentId: V, position: $, effect:
|
|
233
|
-
const
|
|
231
|
+
const A = F ? D(h, a.slice(0, -1)) : D(h, a);
|
|
232
|
+
I.forEach(({ parentId: V, position: $, effect: k }) => {
|
|
233
|
+
const b = document.querySelector(
|
|
234
234
|
`[data-parent-id="${V}"]`
|
|
235
235
|
);
|
|
236
|
-
if (
|
|
237
|
-
const ce = Array.from(
|
|
236
|
+
if (b) {
|
|
237
|
+
const ce = Array.from(b.childNodes);
|
|
238
238
|
if (ce[$]) {
|
|
239
|
-
const
|
|
240
|
-
ce[$].textContent = String(
|
|
239
|
+
const Ie = k ? new Function("state", `return (${k})(state)`)(A) : A;
|
|
240
|
+
ce[$].textContent = String(Ie);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
u.updateType === "update" && (
|
|
247
|
-
(
|
|
246
|
+
u.updateType === "update" && (w || p.current?.validationKey) && a && R(
|
|
247
|
+
(w || p.current?.validationKey) + "." + a.join(".")
|
|
248
248
|
);
|
|
249
|
-
const
|
|
250
|
-
u.updateType === "cut" &&
|
|
251
|
-
|
|
252
|
-
), u.updateType === "insert" &&
|
|
253
|
-
|
|
254
|
-
).filter(([I,
|
|
249
|
+
const z = a.slice(0, a.length - 1);
|
|
250
|
+
u.updateType === "cut" && p.current?.validationKey && R(
|
|
251
|
+
p.current?.validationKey + "." + z.join(".")
|
|
252
|
+
), u.updateType === "insert" && p.current?.validationKey && ke(
|
|
253
|
+
p.current?.validationKey + "." + z.join(".")
|
|
254
|
+
).filter(([I, A]) => {
|
|
255
255
|
let V = I?.split(".").length;
|
|
256
|
-
if (I ==
|
|
257
|
-
let $ = I + "." +
|
|
258
|
-
|
|
256
|
+
if (I == z.join(".") && V == z.length - 1) {
|
|
257
|
+
let $ = I + "." + z;
|
|
258
|
+
R(I), xe($, A);
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
|
-
const
|
|
261
|
+
const me = D(N, a), ye = D(h, a), ve = u.updateType === "update" ? a.join(".") : [...a].slice(0, -1).join("."), K = r.getState().stateComponents.get(g);
|
|
262
262
|
if (console.log(
|
|
263
263
|
"pathetocaheck.............................",
|
|
264
|
+
a,
|
|
264
265
|
u,
|
|
265
|
-
|
|
266
|
+
ve ?? "NONE",
|
|
266
267
|
K
|
|
267
268
|
), K)
|
|
268
|
-
for (const [
|
|
269
|
-
|
|
269
|
+
for (const [
|
|
270
|
+
F,
|
|
271
|
+
I
|
|
272
|
+
] of K.components.entries()) {
|
|
273
|
+
let A = !1;
|
|
270
274
|
const V = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
|
|
271
|
-
if (
|
|
275
|
+
if (!V.includes("none")) {
|
|
272
276
|
if (V.includes("all")) {
|
|
273
277
|
I.forceUpdate();
|
|
274
278
|
continue;
|
|
275
279
|
}
|
|
276
|
-
if (V.includes("component")
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
280
|
+
if (V.includes("component")) {
|
|
281
|
+
for (const $ of O) {
|
|
282
|
+
if (I.paths.has($)) {
|
|
283
|
+
A = !0;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
let k = $;
|
|
287
|
+
for (; k.includes("."); )
|
|
288
|
+
if (k = k.substring(
|
|
289
|
+
0,
|
|
290
|
+
k.lastIndexOf(".")
|
|
291
|
+
), I.paths.has(k)) {
|
|
292
|
+
A = !0;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
if (A) break;
|
|
296
|
+
if (I.paths.has("")) {
|
|
297
|
+
A = !0;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!A && V.includes("deps") && I.depsFunction) {
|
|
302
|
+
const $ = I.depsFunction(h);
|
|
303
|
+
typeof $ == "boolean" ? $ && (A = !0) : U(I.deps, $) || (I.deps = $, A = !0);
|
|
304
|
+
}
|
|
305
|
+
A && I.forceUpdate();
|
|
296
306
|
}
|
|
297
|
-
N && I.forceUpdate();
|
|
298
307
|
}
|
|
299
308
|
}
|
|
300
309
|
const se = {
|
|
301
310
|
timeStamp: Date.now(),
|
|
302
311
|
stateKey: g,
|
|
303
|
-
path:
|
|
312
|
+
path: a,
|
|
304
313
|
updateType: u.updateType,
|
|
305
314
|
status: "new",
|
|
306
|
-
oldValue:
|
|
307
|
-
newValue:
|
|
315
|
+
oldValue: me,
|
|
316
|
+
newValue: ye
|
|
308
317
|
};
|
|
309
|
-
if (
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
return
|
|
318
|
+
if (Ce(g, (F) => {
|
|
319
|
+
const A = [...F ?? [], se].reduce((V, $) => {
|
|
320
|
+
const k = `${$.stateKey}:${JSON.stringify($.path)}`, b = V.get(k);
|
|
321
|
+
return b ? (b.timeStamp = Math.max(b.timeStamp, $.timeStamp), b.newValue = $.newValue, b.oldValue = b.oldValue ?? $.oldValue, b.updateType = $.updateType) : V.set(k, { ...$ }), V;
|
|
313
322
|
}, /* @__PURE__ */ new Map());
|
|
314
|
-
return Array.from(
|
|
315
|
-
}),
|
|
316
|
-
|
|
323
|
+
return Array.from(A.values());
|
|
324
|
+
}), Oe(
|
|
325
|
+
h,
|
|
317
326
|
g,
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
p.current,
|
|
328
|
+
x
|
|
320
329
|
), E && E({
|
|
321
330
|
updateLog: s,
|
|
322
331
|
update: se
|
|
323
|
-
}),
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state:
|
|
327
|
-
rollBackState:
|
|
332
|
+
}), p.current?.serverSync) {
|
|
333
|
+
const F = r.getState().serverState[g], I = p.current?.serverSync;
|
|
334
|
+
be(g, {
|
|
335
|
+
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: h }),
|
|
336
|
+
rollBackState: F,
|
|
328
337
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
329
338
|
status: "waiting"
|
|
330
339
|
});
|
|
331
340
|
}
|
|
332
|
-
return
|
|
341
|
+
return h;
|
|
333
342
|
});
|
|
334
343
|
};
|
|
335
|
-
r.getState().updaterState[g] || (
|
|
344
|
+
r.getState().updaterState[g] || (Y(
|
|
336
345
|
g,
|
|
337
|
-
|
|
346
|
+
X(
|
|
338
347
|
g,
|
|
339
348
|
n,
|
|
340
|
-
|
|
341
|
-
|
|
349
|
+
P.current,
|
|
350
|
+
x
|
|
342
351
|
)
|
|
343
|
-
), r.getState().cogsStateStore[g] ||
|
|
344
|
-
const
|
|
352
|
+
), r.getState().cogsStateStore[g] || G(g, e), r.getState().initialStateGlobal[g] || oe(g, e));
|
|
353
|
+
const o = Ee(() => X(
|
|
345
354
|
g,
|
|
346
355
|
n,
|
|
347
|
-
|
|
348
|
-
|
|
356
|
+
P.current,
|
|
357
|
+
x
|
|
349
358
|
), [g]);
|
|
350
|
-
return [fe(g),
|
|
359
|
+
return [fe(g), o];
|
|
351
360
|
}
|
|
352
|
-
function
|
|
361
|
+
function X(e, i, v, S) {
|
|
353
362
|
const d = /* @__PURE__ */ new Map();
|
|
354
363
|
let E = 0;
|
|
355
364
|
const _ = (f) => {
|
|
@@ -359,15 +368,15 @@ function Y(e, i, v, S) {
|
|
|
359
368
|
E++;
|
|
360
369
|
}, m = {
|
|
361
370
|
removeValidation: (f) => {
|
|
362
|
-
f?.validationKey &&
|
|
371
|
+
f?.validationKey && R(f.validationKey);
|
|
363
372
|
},
|
|
364
373
|
revertToInitialState: (f) => {
|
|
365
374
|
const t = r.getState().getInitialOptions(e)?.validation;
|
|
366
|
-
t?.key &&
|
|
375
|
+
t?.key && R(t?.key), f?.validationKey && R(f.validationKey);
|
|
367
376
|
const y = r.getState().initialStateGlobal[e];
|
|
368
377
|
r.getState().clearSelectedIndexesForState(e), d.clear(), E++;
|
|
369
|
-
const
|
|
370
|
-
|
|
378
|
+
const C = c(y, []), T = B(e), x = L(T?.localStorage?.key) ? T?.localStorage?.key(y) : T?.localStorage?.key, M = `${S}-${e}-${x}`;
|
|
379
|
+
M && localStorage.removeItem(M), Y(e, C), G(e, y);
|
|
371
380
|
const g = r.getState().stateComponents.get(e);
|
|
372
381
|
return g && g.components.forEach((s) => {
|
|
373
382
|
s.forceUpdate();
|
|
@@ -375,17 +384,17 @@ function Y(e, i, v, S) {
|
|
|
375
384
|
},
|
|
376
385
|
updateInitialState: (f) => {
|
|
377
386
|
d.clear(), E++;
|
|
378
|
-
const t =
|
|
387
|
+
const t = X(
|
|
379
388
|
e,
|
|
380
389
|
i,
|
|
381
390
|
v,
|
|
382
391
|
S
|
|
383
392
|
);
|
|
384
|
-
return
|
|
385
|
-
|
|
393
|
+
return $e(() => {
|
|
394
|
+
oe(e, f), Y(e, t), G(e, f);
|
|
386
395
|
const y = r.getState().stateComponents.get(e);
|
|
387
|
-
y && y.components.forEach((
|
|
388
|
-
|
|
396
|
+
y && y.components.forEach((C) => {
|
|
397
|
+
C.forceUpdate();
|
|
389
398
|
});
|
|
390
399
|
}), {
|
|
391
400
|
fetchId: (y) => t.get()[y]
|
|
@@ -396,48 +405,48 @@ function Y(e, i, v, S) {
|
|
|
396
405
|
_isLoading: r.getState().isLoadingGlobal[e],
|
|
397
406
|
_isServerSynced: () => {
|
|
398
407
|
const f = r.getState().serverState[e];
|
|
399
|
-
return !!(f &&
|
|
408
|
+
return !!(f && U(f, fe(e)));
|
|
400
409
|
}
|
|
401
410
|
};
|
|
402
411
|
function c(f, t = [], y) {
|
|
403
|
-
const
|
|
404
|
-
d.get(
|
|
412
|
+
const C = t.map(String).join(".");
|
|
413
|
+
d.get(C);
|
|
405
414
|
const T = function() {
|
|
406
415
|
return r().getNestedState(e, t);
|
|
407
416
|
};
|
|
408
417
|
Object.keys(m).forEach((g) => {
|
|
409
418
|
T[g] = m[g];
|
|
410
419
|
});
|
|
411
|
-
const
|
|
412
|
-
apply(g, s,
|
|
420
|
+
const x = {
|
|
421
|
+
apply(g, s, W) {
|
|
413
422
|
return console.log(
|
|
414
423
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${t.join(".")}`
|
|
415
424
|
), console.trace("Apply trap stack trace"), r().getNestedState(e, t);
|
|
416
425
|
},
|
|
417
426
|
get(g, s) {
|
|
418
427
|
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
419
|
-
const n = t.join("."),
|
|
428
|
+
const n = t.join("."), o = `${e}////${v}`, l = r.getState().stateComponents.get(e);
|
|
420
429
|
if (l) {
|
|
421
|
-
const
|
|
422
|
-
|
|
430
|
+
const a = l.components.get(o);
|
|
431
|
+
a && (t.length > 0 || s === "get") && a.paths.add(n);
|
|
423
432
|
}
|
|
424
433
|
}
|
|
425
434
|
if (s === "_status") {
|
|
426
|
-
const n = r.getState().getNestedState(e, t),
|
|
427
|
-
return
|
|
435
|
+
const n = r.getState().getNestedState(e, t), o = r.getState().initialStateGlobal[e], l = D(o, t);
|
|
436
|
+
return U(n, l) ? "fresh" : "stale";
|
|
428
437
|
}
|
|
429
438
|
if (s === "getStatus")
|
|
430
439
|
return function() {
|
|
431
440
|
const n = r().getNestedState(
|
|
432
441
|
e,
|
|
433
442
|
t
|
|
434
|
-
),
|
|
435
|
-
return
|
|
443
|
+
), o = r.getState().initialStateGlobal[e], l = D(o, t);
|
|
444
|
+
return U(n, l) ? "fresh" : "stale";
|
|
436
445
|
};
|
|
437
446
|
if (s === "removeStorage")
|
|
438
447
|
return () => {
|
|
439
|
-
const n = r.getState().initialStateGlobal[e],
|
|
440
|
-
console.log("removing storage",
|
|
448
|
+
const n = r.getState().initialStateGlobal[e], o = B(e), l = L(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key, a = `${S}-${e}-${l}`;
|
|
449
|
+
console.log("removing storage", a), a && localStorage.removeItem(a);
|
|
441
450
|
};
|
|
442
451
|
if (s === "showValidationErrors")
|
|
443
452
|
return () => {
|
|
@@ -461,31 +470,31 @@ function Y(e, i, v, S) {
|
|
|
461
470
|
return () => r.getState().getSelectedIndex(e, t.join(".")) ?? -1;
|
|
462
471
|
if (s === "stateSort")
|
|
463
472
|
return (n) => {
|
|
464
|
-
const
|
|
473
|
+
const a = [...r.getState().getNestedState(e, t).map((u, w) => ({
|
|
465
474
|
...u,
|
|
466
|
-
__origIndex:
|
|
475
|
+
__origIndex: w.toString()
|
|
467
476
|
}))].sort(n);
|
|
468
|
-
return d.clear(), E++, c(
|
|
477
|
+
return d.clear(), E++, c(a, t, {
|
|
469
478
|
filtered: [...y?.filtered || [], t],
|
|
470
|
-
validIndices:
|
|
479
|
+
validIndices: a.map(
|
|
471
480
|
(u) => parseInt(u.__origIndex)
|
|
472
481
|
)
|
|
473
482
|
});
|
|
474
483
|
};
|
|
475
484
|
if (s === "stateMap" || s === "stateMapNoRender")
|
|
476
485
|
return (n) => {
|
|
477
|
-
const
|
|
478
|
-
(
|
|
479
|
-
), l =
|
|
480
|
-
return s !== "stateMapNoRender" && (d.clear(), E++), l.map((
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
[...t,
|
|
486
|
+
const o = y?.filtered?.some(
|
|
487
|
+
(a) => a.join(".") === t.join(".")
|
|
488
|
+
), l = o ? f : r.getState().getNestedState(e, t);
|
|
489
|
+
return s !== "stateMapNoRender" && (d.clear(), E++), l.map((a, u) => {
|
|
490
|
+
const w = o && a.__origIndex ? a.__origIndex : u, N = c(
|
|
491
|
+
a,
|
|
492
|
+
[...t, w.toString()],
|
|
484
493
|
y
|
|
485
494
|
);
|
|
486
495
|
return n(
|
|
487
|
-
|
|
488
|
-
|
|
496
|
+
a,
|
|
497
|
+
N,
|
|
489
498
|
u,
|
|
490
499
|
f,
|
|
491
500
|
c(f, t, y)
|
|
@@ -493,7 +502,7 @@ function Y(e, i, v, S) {
|
|
|
493
502
|
});
|
|
494
503
|
};
|
|
495
504
|
if (s === "$stateMap")
|
|
496
|
-
return (n) =>
|
|
505
|
+
return (n) => Q(Fe, {
|
|
497
506
|
proxy: {
|
|
498
507
|
_stateKey: e,
|
|
499
508
|
_path: t,
|
|
@@ -508,28 +517,28 @@ function Y(e, i, v, S) {
|
|
|
508
517
|
(u) => u.join(".") === t.join(".")
|
|
509
518
|
) ? f : r.getState().getNestedState(e, t);
|
|
510
519
|
d.clear(), E++;
|
|
511
|
-
const
|
|
512
|
-
(u,
|
|
520
|
+
const a = l.flatMap(
|
|
521
|
+
(u, w) => u[n] ?? []
|
|
513
522
|
);
|
|
514
523
|
return c(
|
|
515
|
-
|
|
524
|
+
a,
|
|
516
525
|
[...t, "[*]", n],
|
|
517
526
|
y
|
|
518
527
|
);
|
|
519
528
|
};
|
|
520
529
|
if (s === "findWith")
|
|
521
|
-
return (n,
|
|
530
|
+
return (n, o) => {
|
|
522
531
|
const l = f.findIndex(
|
|
523
|
-
(
|
|
532
|
+
(w) => w[n] === o
|
|
524
533
|
);
|
|
525
534
|
if (l === -1) return;
|
|
526
|
-
const
|
|
527
|
-
return d.clear(), E++, d.clear(), E++, c(
|
|
535
|
+
const a = f[l], u = [...t, l.toString()];
|
|
536
|
+
return d.clear(), E++, d.clear(), E++, c(a, u);
|
|
528
537
|
};
|
|
529
538
|
if (s === "index")
|
|
530
539
|
return (n) => {
|
|
531
|
-
const
|
|
532
|
-
return c(
|
|
540
|
+
const o = f[n];
|
|
541
|
+
return c(o, [...t, n.toString()]);
|
|
533
542
|
};
|
|
534
543
|
if (s === "insert")
|
|
535
544
|
return (n) => (_(t), ee(i, n, t, e), c(
|
|
@@ -537,65 +546,65 @@ function Y(e, i, v, S) {
|
|
|
537
546
|
[]
|
|
538
547
|
));
|
|
539
548
|
if (s === "uniqueInsert")
|
|
540
|
-
return (n,
|
|
541
|
-
const
|
|
542
|
-
let
|
|
543
|
-
if (!
|
|
544
|
-
if (
|
|
545
|
-
const
|
|
546
|
-
(
|
|
549
|
+
return (n, o, l) => {
|
|
550
|
+
const a = r.getState().getNestedState(e, t), u = L(n) ? n(a) : n;
|
|
551
|
+
let w = null;
|
|
552
|
+
if (!a.some((h) => {
|
|
553
|
+
if (o) {
|
|
554
|
+
const O = o.every(
|
|
555
|
+
(q) => U(h[q], u[q])
|
|
547
556
|
);
|
|
548
|
-
return
|
|
557
|
+
return O && (w = h), O;
|
|
549
558
|
}
|
|
550
|
-
const
|
|
551
|
-
return
|
|
559
|
+
const j = U(h, u);
|
|
560
|
+
return j && (w = h), j;
|
|
552
561
|
}))
|
|
553
562
|
_(t), ee(i, u, t, e);
|
|
554
|
-
else if (l &&
|
|
555
|
-
const
|
|
556
|
-
(
|
|
563
|
+
else if (l && w) {
|
|
564
|
+
const h = l(w), j = a.map(
|
|
565
|
+
(O) => U(O, w) ? h : O
|
|
557
566
|
);
|
|
558
|
-
_(t),
|
|
567
|
+
_(t), J(i, j, t);
|
|
559
568
|
}
|
|
560
569
|
};
|
|
561
570
|
if (s === "cut")
|
|
562
|
-
return (n,
|
|
563
|
-
|
|
571
|
+
return (n, o) => {
|
|
572
|
+
o?.waitForSync || (_(t), Z(i, t, e, n));
|
|
564
573
|
};
|
|
565
574
|
if (s === "cutByValue")
|
|
566
575
|
return (n) => {
|
|
567
|
-
for (let
|
|
568
|
-
f[
|
|
576
|
+
for (let o = 0; o < f.length; o++)
|
|
577
|
+
f[o] === n && Z(i, t, e, o);
|
|
569
578
|
};
|
|
570
579
|
if (s === "toggleByValue")
|
|
571
580
|
return (n) => {
|
|
572
|
-
const
|
|
573
|
-
|
|
581
|
+
const o = f.findIndex((l) => l === n);
|
|
582
|
+
o > -1 ? Z(i, t, e, o) : ee(i, n, t, e);
|
|
574
583
|
};
|
|
575
584
|
if (s === "stateFilter")
|
|
576
585
|
return (n) => {
|
|
577
|
-
const
|
|
586
|
+
const o = f.map((u, w) => ({
|
|
578
587
|
...u,
|
|
579
|
-
__origIndex:
|
|
580
|
-
})), l = [],
|
|
581
|
-
for (let u = 0; u <
|
|
582
|
-
n(
|
|
583
|
-
return d.clear(), E++, c(
|
|
588
|
+
__origIndex: w.toString()
|
|
589
|
+
})), l = [], a = [];
|
|
590
|
+
for (let u = 0; u < o.length; u++)
|
|
591
|
+
n(o[u], u) && (l.push(u), a.push(o[u]));
|
|
592
|
+
return d.clear(), E++, c(a, t, {
|
|
584
593
|
filtered: [...y?.filtered || [], t],
|
|
585
594
|
validIndices: l
|
|
586
595
|
// Always pass validIndices, even if empty
|
|
587
596
|
});
|
|
588
597
|
};
|
|
589
598
|
}
|
|
590
|
-
const
|
|
591
|
-
if (!isNaN(Number(
|
|
592
|
-
const n = t.slice(0, -1),
|
|
593
|
-
if (Array.isArray(
|
|
594
|
-
return () =>
|
|
599
|
+
const W = t[t.length - 1];
|
|
600
|
+
if (!isNaN(Number(W))) {
|
|
601
|
+
const n = t.slice(0, -1), o = r.getState().getNestedState(e, n);
|
|
602
|
+
if (Array.isArray(o) && s === "cut")
|
|
603
|
+
return () => Z(
|
|
595
604
|
i,
|
|
596
605
|
n,
|
|
597
606
|
e,
|
|
598
|
-
Number(
|
|
607
|
+
Number(W)
|
|
599
608
|
);
|
|
600
609
|
}
|
|
601
610
|
if (s === "get")
|
|
@@ -624,38 +633,38 @@ function Y(e, i, v, S) {
|
|
|
624
633
|
if (s == "getLocalStorage")
|
|
625
634
|
return (n) => Se(S + "-" + e + "-" + n);
|
|
626
635
|
if (s === "_selected") {
|
|
627
|
-
const n = t.slice(0, -1),
|
|
628
|
-
return Array.isArray(l) ? Number(t[t.length - 1]) === r.getState().getSelectedIndex(e,
|
|
636
|
+
const n = t.slice(0, -1), o = n.join("."), l = r.getState().getNestedState(e, n);
|
|
637
|
+
return Array.isArray(l) ? Number(t[t.length - 1]) === r.getState().getSelectedIndex(e, o) : void 0;
|
|
629
638
|
}
|
|
630
639
|
if (s === "setSelected")
|
|
631
640
|
return (n) => {
|
|
632
|
-
const
|
|
633
|
-
n ? r.getState().setSelectedIndex(e,
|
|
634
|
-
const u = r.getState().getNestedState(e, [...
|
|
635
|
-
|
|
641
|
+
const o = t.slice(0, -1), l = Number(t[t.length - 1]), a = o.join(".");
|
|
642
|
+
n ? r.getState().setSelectedIndex(e, a, l) : r.getState().setSelectedIndex(e, a, void 0);
|
|
643
|
+
const u = r.getState().getNestedState(e, [...o]);
|
|
644
|
+
J(i, u, o), _(o);
|
|
636
645
|
};
|
|
637
646
|
if (t.length == 0) {
|
|
638
647
|
if (s === "validateZodSchema")
|
|
639
648
|
return () => {
|
|
640
|
-
const n = r.getState().getInitialOptions(e)?.validation,
|
|
649
|
+
const n = r.getState().getInitialOptions(e)?.validation, o = r.getState().addValidationError;
|
|
641
650
|
if (!n?.zodSchema)
|
|
642
651
|
throw new Error("Zod schema not found");
|
|
643
652
|
if (!n?.key)
|
|
644
653
|
throw new Error("Validation key not found");
|
|
645
|
-
|
|
654
|
+
R(n.key);
|
|
646
655
|
const l = r.getState().cogsStateStore[e];
|
|
647
656
|
try {
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
657
|
+
const a = r.getState().getValidationErrors(n.key);
|
|
658
|
+
a && a.length > 0 && a.forEach(([w]) => {
|
|
659
|
+
w && w.startsWith(n.key) && R(w);
|
|
651
660
|
});
|
|
652
661
|
const u = n.zodSchema.safeParse(l);
|
|
653
|
-
return u.success ? !0 : (u.error.errors.forEach((
|
|
654
|
-
const
|
|
655
|
-
|
|
662
|
+
return u.success ? !0 : (u.error.errors.forEach((N) => {
|
|
663
|
+
const h = N.path, j = N.message, O = [n.key, ...h].join(".");
|
|
664
|
+
o(O, j);
|
|
656
665
|
}), ie(e), !1);
|
|
657
|
-
} catch (
|
|
658
|
-
return console.error("Zod schema validation failed",
|
|
666
|
+
} catch (a) {
|
|
667
|
+
return console.error("Zod schema validation failed", a), !1;
|
|
659
668
|
}
|
|
660
669
|
};
|
|
661
670
|
if (s === "_componentId") return v;
|
|
@@ -679,11 +688,11 @@ function Y(e, i, v, S) {
|
|
|
679
688
|
if (s === "validationWrapper")
|
|
680
689
|
return ({
|
|
681
690
|
children: n,
|
|
682
|
-
hideMessage:
|
|
691
|
+
hideMessage: o
|
|
683
692
|
}) => /* @__PURE__ */ le(
|
|
684
|
-
|
|
693
|
+
Te,
|
|
685
694
|
{
|
|
686
|
-
formOpts:
|
|
695
|
+
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
687
696
|
path: t,
|
|
688
697
|
validationKey: r.getState().getInitialOptions(e)?.validation?.key || "",
|
|
689
698
|
stateKey: e,
|
|
@@ -695,48 +704,48 @@ function Y(e, i, v, S) {
|
|
|
695
704
|
if (s === "_path") return t;
|
|
696
705
|
if (s === "_isServerSynced") return m._isServerSynced;
|
|
697
706
|
if (s === "update")
|
|
698
|
-
return (n,
|
|
699
|
-
if (
|
|
700
|
-
|
|
701
|
-
|
|
707
|
+
return (n, o) => {
|
|
708
|
+
if (o?.debounce)
|
|
709
|
+
Ne(() => {
|
|
710
|
+
J(i, n, t, "");
|
|
702
711
|
const l = r.getState().getNestedState(e, t);
|
|
703
|
-
|
|
704
|
-
},
|
|
712
|
+
o?.afterUpdate && o.afterUpdate(l);
|
|
713
|
+
}, o.debounce);
|
|
705
714
|
else {
|
|
706
|
-
|
|
715
|
+
J(i, n, t, "");
|
|
707
716
|
const l = r.getState().getNestedState(e, t);
|
|
708
|
-
|
|
717
|
+
o?.afterUpdate && o.afterUpdate(l);
|
|
709
718
|
}
|
|
710
719
|
_(t);
|
|
711
720
|
};
|
|
712
721
|
if (s === "formElement")
|
|
713
|
-
return (n,
|
|
714
|
-
|
|
722
|
+
return (n, o) => /* @__PURE__ */ le(
|
|
723
|
+
Ve,
|
|
715
724
|
{
|
|
716
725
|
setState: i,
|
|
717
726
|
stateKey: e,
|
|
718
727
|
path: t,
|
|
719
728
|
child: n,
|
|
720
|
-
formOpts:
|
|
729
|
+
formOpts: o
|
|
721
730
|
}
|
|
722
731
|
);
|
|
723
|
-
const
|
|
724
|
-
return c(
|
|
732
|
+
const P = [...t, s], p = r.getState().getNestedState(e, P);
|
|
733
|
+
return c(p, P, y);
|
|
725
734
|
}
|
|
726
|
-
},
|
|
727
|
-
return d.set(
|
|
728
|
-
proxy:
|
|
735
|
+
}, M = new Proxy(T, x);
|
|
736
|
+
return d.set(C, {
|
|
737
|
+
proxy: M,
|
|
729
738
|
stateVersion: E
|
|
730
|
-
}),
|
|
739
|
+
}), M;
|
|
731
740
|
}
|
|
732
741
|
return c(
|
|
733
742
|
r.getState().getNestedState(e, [])
|
|
734
743
|
);
|
|
735
744
|
}
|
|
736
745
|
function te(e) {
|
|
737
|
-
return
|
|
746
|
+
return Q(Re, { proxy: e });
|
|
738
747
|
}
|
|
739
|
-
function
|
|
748
|
+
function Fe({
|
|
740
749
|
proxy: e,
|
|
741
750
|
rebuildStateShape: i
|
|
742
751
|
}) {
|
|
@@ -748,10 +757,10 @@ function je({
|
|
|
748
757
|
(d, E, _, m, c) => e._mapFn(d, E, _, m, c)
|
|
749
758
|
) : null;
|
|
750
759
|
}
|
|
751
|
-
function
|
|
760
|
+
function Re({
|
|
752
761
|
proxy: e
|
|
753
762
|
}) {
|
|
754
|
-
const i =
|
|
763
|
+
const i = H(null), v = `${e._stateKey}-${e._path.join(".")}`;
|
|
755
764
|
return re(() => {
|
|
756
765
|
const S = i.current;
|
|
757
766
|
if (!S || !S.parentElement) return;
|
|
@@ -779,16 +788,16 @@ function Fe({
|
|
|
779
788
|
else
|
|
780
789
|
y = t;
|
|
781
790
|
y !== null && typeof y == "object" && (y = JSON.stringify(y));
|
|
782
|
-
const
|
|
783
|
-
S.replaceWith(
|
|
784
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
791
|
+
const C = document.createTextNode(String(y));
|
|
792
|
+
S.replaceWith(C);
|
|
793
|
+
}, [e._stateKey, e._path.join("."), e._effect]), Q("span", {
|
|
785
794
|
ref: i,
|
|
786
795
|
style: { display: "none" },
|
|
787
796
|
"data-signal-id": v
|
|
788
797
|
});
|
|
789
798
|
}
|
|
790
|
-
function
|
|
791
|
-
const i =
|
|
799
|
+
function Ye(e) {
|
|
800
|
+
const i = we(
|
|
792
801
|
(v) => {
|
|
793
802
|
const S = r.getState().stateComponents.get(e._stateKey) || {
|
|
794
803
|
components: /* @__PURE__ */ new Map()
|
|
@@ -800,14 +809,14 @@ function Je(e) {
|
|
|
800
809
|
},
|
|
801
810
|
() => r.getState().getNestedState(e._stateKey, e._path)
|
|
802
811
|
);
|
|
803
|
-
return
|
|
812
|
+
return Q("text", {}, String(i));
|
|
804
813
|
}
|
|
805
814
|
export {
|
|
806
815
|
te as $cogsSignal,
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
816
|
+
Ye as $cogsSignalStore,
|
|
817
|
+
Je as addStateOptions,
|
|
818
|
+
Ze as createCogsState,
|
|
819
|
+
He as notifyComponent,
|
|
820
|
+
je as useCogsStateFn
|
|
812
821
|
};
|
|
813
822
|
//# sourceMappingURL=CogsState.jsx.map
|