cogsbox-state 0.5.115 → 0.5.117
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 +160 -158
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.js +60 -43
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -8,9 +8,9 @@ import { getGlobalStore as r, formRefStore as ct } from "./store.js";
|
|
|
8
8
|
import { useCogsConfig as At } from "./CogsStateClient.jsx";
|
|
9
9
|
import nt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
10
|
function lt(t, i) {
|
|
11
|
-
const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions,
|
|
11
|
+
const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, g = m(t) || {};
|
|
12
12
|
y(t, {
|
|
13
|
-
...
|
|
13
|
+
...g,
|
|
14
14
|
...i
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -19,36 +19,36 @@ function dt({
|
|
|
19
19
|
options: i,
|
|
20
20
|
initialOptionsPart: m
|
|
21
21
|
}) {
|
|
22
|
-
const y = q(t) || {},
|
|
22
|
+
const y = q(t) || {}, g = m[t] || {}, E = r.getState().setInitialStateOptions, _ = { ...g, ...y };
|
|
23
23
|
let v = !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 && (v = !0, _[c] = i[c]), c == "initialState" && i[c] && _[c] !== i[c] && (v = !0, _[c] = i[c])) : (v = !0, _[c] = i[c]);
|
|
27
|
-
v &&
|
|
27
|
+
v && E(t, _);
|
|
28
28
|
}
|
|
29
29
|
function qt(t, { formElements: i, validation: m }) {
|
|
30
30
|
return { initialState: t, formElements: i, validation: m };
|
|
31
31
|
}
|
|
32
32
|
const zt = (t, i) => {
|
|
33
33
|
let m = t;
|
|
34
|
-
const [y,
|
|
35
|
-
(Object.keys(
|
|
36
|
-
|
|
34
|
+
const [y, g] = wt(m);
|
|
35
|
+
(Object.keys(g).length > 0 || i && Object.keys(i).length > 0) && Object.keys(g).forEach((v) => {
|
|
36
|
+
g[v] = g[v] || {}, g[v].formElements = {
|
|
37
37
|
...i?.formElements,
|
|
38
38
|
// Global defaults first
|
|
39
39
|
...i?.validation,
|
|
40
|
-
...
|
|
40
|
+
...g[v].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
|
-
}, q(v) || r.getState().setInitialStateOptions(v,
|
|
43
|
-
}), r.getState().setInitialStates(y);
|
|
44
|
-
const
|
|
42
|
+
}, q(v) || r.getState().setInitialStateOptions(v, g[v]);
|
|
43
|
+
}), r.getState().setInitialStates(y), r.getState().setCreatedState(y);
|
|
44
|
+
const E = (v, c) => {
|
|
45
45
|
const [f] = tt(c?.componentId ?? nt());
|
|
46
46
|
dt({
|
|
47
47
|
stateKey: v,
|
|
48
48
|
options: c,
|
|
49
|
-
initialOptionsPart:
|
|
49
|
+
initialOptionsPart: g
|
|
50
50
|
});
|
|
51
|
-
const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [
|
|
51
|
+
const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [T, C] = jt(
|
|
52
52
|
S,
|
|
53
53
|
{
|
|
54
54
|
stateKey: v,
|
|
@@ -63,19 +63,19 @@ const zt = (t, i) => {
|
|
|
63
63
|
dependencies: c?.dependencies
|
|
64
64
|
}
|
|
65
65
|
);
|
|
66
|
-
return
|
|
66
|
+
return C;
|
|
67
67
|
};
|
|
68
68
|
function _(v, c) {
|
|
69
|
-
dt({ stateKey: v, options: c, initialOptionsPart:
|
|
69
|
+
dt({ stateKey: v, options: c, initialOptionsPart: g });
|
|
70
70
|
}
|
|
71
|
-
return { useCogsState:
|
|
71
|
+
return { useCogsState: E, setCogsOptions: _ };
|
|
72
72
|
}, {
|
|
73
73
|
setUpdaterState: H,
|
|
74
74
|
setState: D,
|
|
75
75
|
getInitialOptions: q,
|
|
76
76
|
getKeyState: ut,
|
|
77
|
-
getValidationErrors:
|
|
78
|
-
setStateLog:
|
|
77
|
+
getValidationErrors: Ct,
|
|
78
|
+
setStateLog: ht,
|
|
79
79
|
updateInitialStateGlobal: rt,
|
|
80
80
|
addValidationError: kt,
|
|
81
81
|
removeValidationError: P,
|
|
@@ -95,24 +95,24 @@ const zt = (t, i) => {
|
|
|
95
95
|
m.localStorage?.key,
|
|
96
96
|
y
|
|
97
97
|
);
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
const
|
|
98
|
+
const g = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
99
|
+
if (g && y) {
|
|
100
|
+
const E = {
|
|
101
101
|
state: t,
|
|
102
102
|
lastUpdated: Date.now(),
|
|
103
103
|
lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
|
|
104
104
|
baseServerState: r.getState().serverState[i]
|
|
105
|
-
}, _ = `${y}-${i}-${
|
|
106
|
-
window.localStorage.setItem(_, JSON.stringify(
|
|
105
|
+
}, _ = `${y}-${i}-${g}`;
|
|
106
|
+
window.localStorage.setItem(_, JSON.stringify(E));
|
|
107
107
|
}
|
|
108
|
-
}, Ot = (t, i, m, y,
|
|
108
|
+
}, Ot = (t, i, m, y, g, E) => {
|
|
109
109
|
const _ = {
|
|
110
110
|
initialState: i,
|
|
111
111
|
updaterState: Y(
|
|
112
112
|
t,
|
|
113
113
|
y,
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
g,
|
|
115
|
+
E
|
|
116
116
|
),
|
|
117
117
|
state: m
|
|
118
118
|
};
|
|
@@ -129,16 +129,16 @@ const zt = (t, i) => {
|
|
|
129
129
|
}, Bt = (t, i) => {
|
|
130
130
|
const m = r.getState().stateComponents.get(t);
|
|
131
131
|
if (m) {
|
|
132
|
-
const y = `${t}////${i}`,
|
|
133
|
-
|
|
132
|
+
const y = `${t}////${i}`, g = m.components.get(y);
|
|
133
|
+
g && g.forceUpdate();
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
function jt(t, {
|
|
137
137
|
stateKey: i,
|
|
138
138
|
serverSync: m,
|
|
139
139
|
localStorage: y,
|
|
140
|
-
formElements:
|
|
141
|
-
middleware:
|
|
140
|
+
formElements: g,
|
|
141
|
+
middleware: E,
|
|
142
142
|
reactiveDeps: _,
|
|
143
143
|
reactiveType: v,
|
|
144
144
|
componentId: c,
|
|
@@ -146,12 +146,12 @@ function jt(t, {
|
|
|
146
146
|
syncUpdate: e,
|
|
147
147
|
dependencies: S
|
|
148
148
|
} = {}) {
|
|
149
|
-
const [
|
|
149
|
+
const [T, C] = tt({}), { sessionId: O } = At();
|
|
150
150
|
let R = !i;
|
|
151
|
-
const [
|
|
152
|
-
|
|
153
|
-
if (e && e.stateKey ===
|
|
154
|
-
D(
|
|
151
|
+
const [u] = tt(i ?? nt()), s = r.getState().stateLog[u], G = Z(/* @__PURE__ */ new Set()), b = Z(c ?? nt()), k = Z(null);
|
|
152
|
+
k.current = q(u), et(() => {
|
|
153
|
+
if (e && e.stateKey === u && e.path?.[0]) {
|
|
154
|
+
D(u, (o) => ({
|
|
155
155
|
...o,
|
|
156
156
|
[e.path[0]]: e.newValue
|
|
157
157
|
}));
|
|
@@ -162,65 +162,67 @@ function jt(t, {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
}, [e]), et(() => {
|
|
165
|
-
f && lt(
|
|
165
|
+
f && lt(u, {
|
|
166
166
|
initialState: f
|
|
167
167
|
});
|
|
168
|
-
const l =
|
|
168
|
+
const l = k.current;
|
|
169
169
|
let o = null;
|
|
170
170
|
const d = L(l?.localStorage?.key) ? l?.localStorage?.key(f) : l?.localStorage?.key;
|
|
171
|
-
console.log("newoptions", l), console.log("localkey", d), console.log("initialState", f), d &&
|
|
172
|
-
|
|
171
|
+
console.log("newoptions", l), console.log("localkey", d), console.log("initialState", f), d && O && (o = gt(
|
|
172
|
+
O + "-" + u + "-" + d
|
|
173
173
|
));
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
const w = r.getState().iniitialCreatedState[u];
|
|
175
|
+
console.log("createdState - intiual", w, f);
|
|
176
|
+
let V = null;
|
|
177
|
+
f && (V = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (V = o.state, l?.localStorage?.onChange && l?.localStorage?.onChange(V)), console.log("newState thius is newstate", V), Ot(
|
|
178
|
+
u,
|
|
177
179
|
f,
|
|
178
|
-
|
|
180
|
+
V,
|
|
179
181
|
n,
|
|
180
182
|
b.current,
|
|
181
|
-
|
|
182
|
-
), ft(
|
|
183
|
+
O
|
|
184
|
+
), ft(u), C({}));
|
|
183
185
|
}, [f, ...S || []]), vt(() => {
|
|
184
|
-
R && lt(
|
|
186
|
+
R && lt(u, {
|
|
185
187
|
serverSync: m,
|
|
186
|
-
formElements:
|
|
188
|
+
formElements: g,
|
|
187
189
|
initialState: f,
|
|
188
190
|
localStorage: y,
|
|
189
|
-
middleware:
|
|
191
|
+
middleware: E
|
|
190
192
|
});
|
|
191
|
-
const l = `${
|
|
193
|
+
const l = `${u}////${b.current}`, o = r.getState().stateComponents.get(u) || {
|
|
192
194
|
components: /* @__PURE__ */ new Map()
|
|
193
195
|
};
|
|
194
196
|
return o.components.set(l, {
|
|
195
|
-
forceUpdate: () =>
|
|
197
|
+
forceUpdate: () => C({}),
|
|
196
198
|
paths: /* @__PURE__ */ new Set(),
|
|
197
199
|
deps: [],
|
|
198
200
|
depsFunction: _ || void 0,
|
|
199
201
|
reactiveType: v ?? ["component", "deps"]
|
|
200
|
-
}), r.getState().stateComponents.set(
|
|
201
|
-
const d = `${
|
|
202
|
-
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(
|
|
202
|
+
}), r.getState().stateComponents.set(u, o), C({}), () => {
|
|
203
|
+
const d = `${u}////${b.current}`;
|
|
204
|
+
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(u));
|
|
203
205
|
};
|
|
204
206
|
}, []);
|
|
205
|
-
const n = (l, o, d,
|
|
207
|
+
const n = (l, o, d, w) => {
|
|
206
208
|
if (Array.isArray(o)) {
|
|
207
|
-
const
|
|
208
|
-
G.current.add(
|
|
209
|
+
const V = `${u}-${o.join(".")}`;
|
|
210
|
+
G.current.add(V);
|
|
209
211
|
}
|
|
210
|
-
D(
|
|
211
|
-
const N = L(l) ? l(
|
|
212
|
+
D(u, (V) => {
|
|
213
|
+
const N = L(l) ? l(V) : l, p = `${u}-${o.join(".")}`;
|
|
212
214
|
if (p) {
|
|
213
215
|
let F = !1, I = r.getState().signalDomElements.get(p);
|
|
214
216
|
if ((!I || I.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
|
|
215
|
-
const
|
|
217
|
+
const A = o.slice(0, -1), h = U(N, A);
|
|
216
218
|
if (Array.isArray(h)) {
|
|
217
219
|
F = !0;
|
|
218
|
-
const $ = `${
|
|
220
|
+
const $ = `${u}-${A.join(".")}`;
|
|
219
221
|
I = r.getState().signalDomElements.get($);
|
|
220
222
|
}
|
|
221
223
|
}
|
|
222
224
|
if (I) {
|
|
223
|
-
const
|
|
225
|
+
const A = F ? U(N, o.slice(0, -1)) : U(N, o);
|
|
224
226
|
I.forEach(({ parentId: h, position: $, effect: W }) => {
|
|
225
227
|
const j = document.querySelector(
|
|
226
228
|
`[data-parent-id="${h}"]`
|
|
@@ -228,71 +230,71 @@ function jt(t, {
|
|
|
228
230
|
if (j) {
|
|
229
231
|
const it = Array.from(j.childNodes);
|
|
230
232
|
if (it[$]) {
|
|
231
|
-
const yt = W ? new Function("state", `return (${W})(state)`)(
|
|
233
|
+
const yt = W ? new Function("state", `return (${W})(state)`)(A) : A;
|
|
232
234
|
it[$].textContent = String(yt);
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
|
-
d.updateType === "update" && (
|
|
239
|
-
(
|
|
240
|
+
d.updateType === "update" && (w || k.current?.validationKey) && o && P(
|
|
241
|
+
(w || k.current?.validationKey) + "." + o.join(".")
|
|
240
242
|
);
|
|
241
|
-
const
|
|
242
|
-
d.updateType === "cut" &&
|
|
243
|
-
|
|
244
|
-
), d.updateType === "insert" &&
|
|
245
|
-
|
|
246
|
-
).filter(([I,
|
|
243
|
+
const x = o.slice(0, o.length - 1);
|
|
244
|
+
d.updateType === "cut" && k.current?.validationKey && P(
|
|
245
|
+
k.current?.validationKey + "." + x.join(".")
|
|
246
|
+
), d.updateType === "insert" && k.current?.validationKey && Ct(
|
|
247
|
+
k.current?.validationKey + "." + x.join(".")
|
|
248
|
+
).filter(([I, A]) => {
|
|
247
249
|
let h = I?.split(".").length;
|
|
248
|
-
if (I ==
|
|
249
|
-
let $ = I + "." +
|
|
250
|
-
P(I), kt($,
|
|
250
|
+
if (I == x.join(".") && h == x.length - 1) {
|
|
251
|
+
let $ = I + "." + x;
|
|
252
|
+
P(I), kt($, A);
|
|
251
253
|
}
|
|
252
254
|
});
|
|
253
|
-
const z = U(
|
|
255
|
+
const z = U(V, o), St = U(N, o), mt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), ot = r.getState().stateComponents.get(u);
|
|
254
256
|
if (ot)
|
|
255
257
|
for (const [F, I] of ot.components.entries()) {
|
|
256
|
-
let
|
|
258
|
+
let A = !1;
|
|
257
259
|
const h = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
|
|
258
260
|
if (!h.includes("none")) {
|
|
259
261
|
if (h.includes("all")) {
|
|
260
262
|
I.forceUpdate();
|
|
261
263
|
continue;
|
|
262
264
|
}
|
|
263
|
-
if (h.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (
|
|
265
|
+
if (h.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (A = !0), !A && h.includes("deps") && I.depsFunction) {
|
|
264
266
|
const $ = I.depsFunction(N);
|
|
265
|
-
typeof $ == "boolean" ? $ && (
|
|
267
|
+
typeof $ == "boolean" ? $ && (A = !0) : M(I.deps, $) || (I.deps = $, A = !0);
|
|
266
268
|
}
|
|
267
|
-
|
|
269
|
+
A && I.forceUpdate();
|
|
268
270
|
}
|
|
269
271
|
}
|
|
270
272
|
const at = {
|
|
271
273
|
timeStamp: Date.now(),
|
|
272
|
-
stateKey:
|
|
274
|
+
stateKey: u,
|
|
273
275
|
path: o,
|
|
274
276
|
updateType: d.updateType,
|
|
275
277
|
status: "new",
|
|
276
278
|
oldValue: z,
|
|
277
279
|
newValue: St
|
|
278
280
|
};
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
+
if (ht(u, (F) => {
|
|
282
|
+
const A = [...F ?? [], at].reduce((h, $) => {
|
|
281
283
|
const W = `${$.stateKey}:${JSON.stringify($.path)}`, j = h.get(W);
|
|
282
284
|
return j ? (j.timeStamp = Math.max(j.timeStamp, $.timeStamp), j.newValue = $.newValue, j.oldValue = j.oldValue ?? $.oldValue, j.updateType = $.updateType) : h.set(W, { ...$ }), h;
|
|
283
285
|
}, /* @__PURE__ */ new Map());
|
|
284
|
-
return Array.from(
|
|
286
|
+
return Array.from(A.values());
|
|
285
287
|
}), Tt(
|
|
286
288
|
N,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
),
|
|
289
|
+
u,
|
|
290
|
+
k.current,
|
|
291
|
+
O
|
|
292
|
+
), E && E({
|
|
291
293
|
updateLog: s,
|
|
292
294
|
update: at
|
|
293
|
-
}),
|
|
294
|
-
const F = r.getState().serverState[
|
|
295
|
-
xt(
|
|
295
|
+
}), k.current?.serverSync) {
|
|
296
|
+
const F = r.getState().serverState[u], I = k.current?.serverSync;
|
|
297
|
+
xt(u, {
|
|
296
298
|
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: N }),
|
|
297
299
|
rollBackState: F,
|
|
298
300
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
@@ -302,31 +304,31 @@ function jt(t, {
|
|
|
302
304
|
return N;
|
|
303
305
|
});
|
|
304
306
|
};
|
|
305
|
-
r.getState().updaterState[
|
|
306
|
-
|
|
307
|
+
r.getState().updaterState[u] || (H(
|
|
308
|
+
u,
|
|
307
309
|
Y(
|
|
308
|
-
|
|
310
|
+
u,
|
|
309
311
|
n,
|
|
310
312
|
b.current,
|
|
311
|
-
|
|
313
|
+
O
|
|
312
314
|
)
|
|
313
|
-
), r.getState().cogsStateStore[
|
|
315
|
+
), r.getState().cogsStateStore[u] || D(u, t), r.getState().initialStateGlobal[u] || rt(u, t));
|
|
314
316
|
const a = It(() => Y(
|
|
315
|
-
|
|
317
|
+
u,
|
|
316
318
|
n,
|
|
317
319
|
b.current,
|
|
318
|
-
|
|
319
|
-
), [
|
|
320
|
-
return [ut(
|
|
320
|
+
O
|
|
321
|
+
), [u]);
|
|
322
|
+
return [ut(u), a];
|
|
321
323
|
}
|
|
322
324
|
function Y(t, i, m, y) {
|
|
323
|
-
const
|
|
324
|
-
let
|
|
325
|
+
const g = /* @__PURE__ */ new Map();
|
|
326
|
+
let E = 0;
|
|
325
327
|
const _ = (f) => {
|
|
326
328
|
const e = f.join(".");
|
|
327
|
-
for (const [S] of
|
|
328
|
-
(S === e || S.startsWith(e + ".")) &&
|
|
329
|
-
|
|
329
|
+
for (const [S] of g)
|
|
330
|
+
(S === e || S.startsWith(e + ".")) && g.delete(S);
|
|
331
|
+
E++;
|
|
330
332
|
}, v = {
|
|
331
333
|
removeValidation: (f) => {
|
|
332
334
|
f?.validationKey && P(f.validationKey);
|
|
@@ -335,16 +337,16 @@ function Y(t, i, m, y) {
|
|
|
335
337
|
const e = r.getState().getInitialOptions(t)?.validation;
|
|
336
338
|
e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
|
|
337
339
|
const S = r.getState().initialStateGlobal[t];
|
|
338
|
-
r.getState().clearSelectedIndexesForState(t),
|
|
339
|
-
const
|
|
340
|
-
R && localStorage.removeItem(R), H(t,
|
|
341
|
-
const
|
|
342
|
-
return
|
|
340
|
+
r.getState().clearSelectedIndexesForState(t), g.clear(), E++;
|
|
341
|
+
const T = c(S, []), C = q(t), O = L(C?.localStorage?.key) ? C?.localStorage?.key(S) : C?.localStorage?.key, R = `${y}-${t}-${O}`;
|
|
342
|
+
R && localStorage.removeItem(R), H(t, T), D(t, S);
|
|
343
|
+
const u = r.getState().stateComponents.get(t);
|
|
344
|
+
return u && u.components.forEach((s) => {
|
|
343
345
|
s.forceUpdate();
|
|
344
346
|
}), S;
|
|
345
347
|
},
|
|
346
348
|
updateInitialState: (f) => {
|
|
347
|
-
|
|
349
|
+
g.clear(), E++;
|
|
348
350
|
const e = Y(
|
|
349
351
|
t,
|
|
350
352
|
i,
|
|
@@ -354,8 +356,8 @@ function Y(t, i, m, y) {
|
|
|
354
356
|
return Et(() => {
|
|
355
357
|
rt(t, f), H(t, e), D(t, f);
|
|
356
358
|
const S = r.getState().stateComponents.get(t);
|
|
357
|
-
S && S.components.forEach((
|
|
358
|
-
|
|
359
|
+
S && S.components.forEach((T) => {
|
|
360
|
+
T.forceUpdate();
|
|
359
361
|
});
|
|
360
362
|
}), {
|
|
361
363
|
fetchId: (S) => e.get()[S]
|
|
@@ -370,21 +372,21 @@ function Y(t, i, m, y) {
|
|
|
370
372
|
}
|
|
371
373
|
};
|
|
372
374
|
function c(f, e = [], S) {
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const
|
|
375
|
+
const T = e.map(String).join(".");
|
|
376
|
+
g.get(T);
|
|
377
|
+
const C = function() {
|
|
376
378
|
return r().getNestedState(t, e);
|
|
377
379
|
};
|
|
378
|
-
Object.keys(v).forEach((
|
|
379
|
-
|
|
380
|
+
Object.keys(v).forEach((u) => {
|
|
381
|
+
C[u] = v[u];
|
|
380
382
|
});
|
|
381
|
-
const
|
|
382
|
-
apply(
|
|
383
|
+
const O = {
|
|
384
|
+
apply(u, s, G) {
|
|
383
385
|
return console.log(
|
|
384
386
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
|
|
385
387
|
), console.trace("Apply trap stack trace"), r().getNestedState(t, e);
|
|
386
388
|
},
|
|
387
|
-
get(
|
|
389
|
+
get(u, s) {
|
|
388
390
|
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
389
391
|
const n = e.join("."), a = `${t}////${m}`, l = r.getState().stateComponents.get(t);
|
|
390
392
|
if (l) {
|
|
@@ -431,11 +433,11 @@ function Y(t, i, m, y) {
|
|
|
431
433
|
return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
|
|
432
434
|
if (s === "stateSort")
|
|
433
435
|
return (n) => {
|
|
434
|
-
const o = [...r.getState().getNestedState(t, e).map((d,
|
|
436
|
+
const o = [...r.getState().getNestedState(t, e).map((d, w) => ({
|
|
435
437
|
...d,
|
|
436
|
-
__origIndex:
|
|
438
|
+
__origIndex: w.toString()
|
|
437
439
|
}))].sort(n);
|
|
438
|
-
return
|
|
440
|
+
return g.clear(), E++, c(o, e, {
|
|
439
441
|
filtered: [...S?.filtered || [], e],
|
|
440
442
|
validIndices: o.map(
|
|
441
443
|
(d) => parseInt(d.__origIndex)
|
|
@@ -447,15 +449,15 @@ function Y(t, i, m, y) {
|
|
|
447
449
|
const a = S?.filtered?.some(
|
|
448
450
|
(o) => o.join(".") === e.join(".")
|
|
449
451
|
), l = a ? f : r.getState().getNestedState(t, e);
|
|
450
|
-
return s !== "stateMapNoRender" && (
|
|
451
|
-
const
|
|
452
|
+
return s !== "stateMapNoRender" && (g.clear(), E++), l.map((o, d) => {
|
|
453
|
+
const w = a && o.__origIndex ? o.__origIndex : d, V = c(
|
|
452
454
|
o,
|
|
453
|
-
[...e,
|
|
455
|
+
[...e, w.toString()],
|
|
454
456
|
S
|
|
455
457
|
);
|
|
456
458
|
return n(
|
|
457
459
|
o,
|
|
458
|
-
|
|
460
|
+
V,
|
|
459
461
|
d,
|
|
460
462
|
f,
|
|
461
463
|
c(f, e, S)
|
|
@@ -477,9 +479,9 @@ function Y(t, i, m, y) {
|
|
|
477
479
|
const l = S?.filtered?.some(
|
|
478
480
|
(d) => d.join(".") === e.join(".")
|
|
479
481
|
) ? f : r.getState().getNestedState(t, e);
|
|
480
|
-
|
|
482
|
+
g.clear(), E++;
|
|
481
483
|
const o = l.flatMap(
|
|
482
|
-
(d,
|
|
484
|
+
(d, w) => d[n] ?? []
|
|
483
485
|
);
|
|
484
486
|
return c(
|
|
485
487
|
o,
|
|
@@ -490,11 +492,11 @@ function Y(t, i, m, y) {
|
|
|
490
492
|
if (s === "findWith")
|
|
491
493
|
return (n, a) => {
|
|
492
494
|
const l = f.findIndex(
|
|
493
|
-
(
|
|
495
|
+
(w) => w[n] === a
|
|
494
496
|
);
|
|
495
497
|
if (l === -1) return;
|
|
496
498
|
const o = f[l], d = [...e, l.toString()];
|
|
497
|
-
return
|
|
499
|
+
return g.clear(), E++, g.clear(), E++, c(o, d);
|
|
498
500
|
};
|
|
499
501
|
if (s === "index")
|
|
500
502
|
return (n) => {
|
|
@@ -509,21 +511,21 @@ function Y(t, i, m, y) {
|
|
|
509
511
|
if (s === "uniqueInsert")
|
|
510
512
|
return (n, a, l) => {
|
|
511
513
|
const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
|
|
512
|
-
let
|
|
514
|
+
let w = null;
|
|
513
515
|
if (!o.some((N) => {
|
|
514
516
|
if (a) {
|
|
515
|
-
const
|
|
517
|
+
const x = a.every(
|
|
516
518
|
(z) => M(N[z], d[z])
|
|
517
519
|
);
|
|
518
|
-
return
|
|
520
|
+
return x && (w = N), x;
|
|
519
521
|
}
|
|
520
522
|
const p = M(N, d);
|
|
521
|
-
return p && (
|
|
523
|
+
return p && (w = N), p;
|
|
522
524
|
}))
|
|
523
525
|
_(e), Q(i, d, e, t);
|
|
524
|
-
else if (l &&
|
|
525
|
-
const N = l(
|
|
526
|
-
(
|
|
526
|
+
else if (l && w) {
|
|
527
|
+
const N = l(w), p = o.map(
|
|
528
|
+
(x) => M(x, w) ? N : x
|
|
527
529
|
);
|
|
528
530
|
_(e), B(i, p, e);
|
|
529
531
|
}
|
|
@@ -544,13 +546,13 @@ function Y(t, i, m, y) {
|
|
|
544
546
|
};
|
|
545
547
|
if (s === "stateFilter")
|
|
546
548
|
return (n) => {
|
|
547
|
-
const a = f.map((d,
|
|
549
|
+
const a = f.map((d, w) => ({
|
|
548
550
|
...d,
|
|
549
|
-
__origIndex:
|
|
551
|
+
__origIndex: w.toString()
|
|
550
552
|
})), l = [], o = [];
|
|
551
553
|
for (let d = 0; d < a.length; d++)
|
|
552
554
|
n(a[d], d) && (l.push(d), o.push(a[d]));
|
|
553
|
-
return
|
|
555
|
+
return g.clear(), E++, c(o, e, {
|
|
554
556
|
filtered: [...S?.filtered || [], e],
|
|
555
557
|
validIndices: l
|
|
556
558
|
// Always pass validIndices, even if empty
|
|
@@ -616,13 +618,13 @@ function Y(t, i, m, y) {
|
|
|
616
618
|
const l = r.getState().cogsStateStore[t];
|
|
617
619
|
try {
|
|
618
620
|
const o = r.getState().getValidationErrors(n.key);
|
|
619
|
-
o && o.length > 0 && o.forEach(([
|
|
620
|
-
|
|
621
|
+
o && o.length > 0 && o.forEach(([w]) => {
|
|
622
|
+
w && w.startsWith(n.key) && P(w);
|
|
621
623
|
});
|
|
622
624
|
const d = n.zodSchema.safeParse(l);
|
|
623
|
-
return d.success ? !0 : (d.error.errors.forEach((
|
|
624
|
-
const N =
|
|
625
|
-
a(
|
|
625
|
+
return d.success ? !0 : (d.error.errors.forEach((V) => {
|
|
626
|
+
const N = V.path, p = V.message, x = [n.key, ...N].join(".");
|
|
627
|
+
a(x, p);
|
|
626
628
|
}), ft(t), !1);
|
|
627
629
|
} catch (o) {
|
|
628
630
|
return console.error("Zod schema validation failed", o), !1;
|
|
@@ -690,13 +692,13 @@ function Y(t, i, m, y) {
|
|
|
690
692
|
formOpts: a
|
|
691
693
|
}
|
|
692
694
|
);
|
|
693
|
-
const b = [...e, s],
|
|
694
|
-
return c(
|
|
695
|
+
const b = [...e, s], k = r.getState().getNestedState(t, b);
|
|
696
|
+
return c(k, b, S);
|
|
695
697
|
}
|
|
696
|
-
}, R = new Proxy(
|
|
697
|
-
return
|
|
698
|
+
}, R = new Proxy(C, O);
|
|
699
|
+
return g.set(T, {
|
|
698
700
|
proxy: R,
|
|
699
|
-
stateVersion:
|
|
701
|
+
stateVersion: E
|
|
700
702
|
}), R;
|
|
701
703
|
}
|
|
702
704
|
return c(
|
|
@@ -715,7 +717,7 @@ function pt({
|
|
|
715
717
|
m,
|
|
716
718
|
t._path
|
|
717
719
|
).stateMapNoRender(
|
|
718
|
-
(
|
|
720
|
+
(g, E, _, v, c) => t._mapFn(g, E, _, v, c)
|
|
719
721
|
) : null;
|
|
720
722
|
}
|
|
721
723
|
function bt({
|
|
@@ -725,9 +727,9 @@ function bt({
|
|
|
725
727
|
return et(() => {
|
|
726
728
|
const y = i.current;
|
|
727
729
|
if (!y || !y.parentElement) return;
|
|
728
|
-
const
|
|
729
|
-
let v =
|
|
730
|
-
v || (v = `parent-${crypto.randomUUID()}`,
|
|
730
|
+
const g = y.parentElement, _ = Array.from(g.childNodes).indexOf(y);
|
|
731
|
+
let v = g.getAttribute("data-parent-id");
|
|
732
|
+
v || (v = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", v));
|
|
731
733
|
const f = {
|
|
732
734
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
733
735
|
parentId: v,
|
|
@@ -743,14 +745,14 @@ function bt({
|
|
|
743
745
|
"state",
|
|
744
746
|
`return (${t._effect})(state)`
|
|
745
747
|
)(e);
|
|
746
|
-
} catch (
|
|
747
|
-
console.error("Error evaluating effect function during mount:",
|
|
748
|
+
} catch (C) {
|
|
749
|
+
console.error("Error evaluating effect function during mount:", C), S = e;
|
|
748
750
|
}
|
|
749
751
|
else
|
|
750
752
|
S = e;
|
|
751
753
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
752
|
-
const
|
|
753
|
-
y.replaceWith(
|
|
754
|
+
const T = document.createTextNode(String(S));
|
|
755
|
+
y.replaceWith(T);
|
|
754
756
|
}, [t._stateKey, t._path.join("."), t._effect]), X("span", {
|
|
755
757
|
ref: i,
|
|
756
758
|
style: { display: "none" },
|