cogsbox-state 0.5.393 → 0.5.395
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 +154 -154
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +2 -2
package/dist/CogsState.jsx
CHANGED
|
@@ -11,9 +11,9 @@ import { useCogsConfig as Gt } from "./CogsStateClient.jsx";
|
|
|
11
11
|
import { applyPatch as Yt } from "fast-json-patch";
|
|
12
12
|
import Zt from "react-use-measure";
|
|
13
13
|
function Mt(t, c) {
|
|
14
|
-
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions,
|
|
14
|
+
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
|
|
15
15
|
g(t, {
|
|
16
|
-
...
|
|
16
|
+
...I,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -22,7 +22,7 @@ function xt({
|
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = rt(t) || {},
|
|
25
|
+
const g = rt(t) || {}, I = m[t] || {}, N = o.getState().setInitialStateOptions, p = { ...I, ...g };
|
|
26
26
|
let v = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const s in c)
|
|
@@ -30,34 +30,34 @@ function xt({
|
|
|
30
30
|
!J(p[s], c[s]) && (v = !0, p[s] = c[s])) : (v = !0, p[s] = c[s]);
|
|
31
31
|
v && N(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function Ie(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
35
35
|
}
|
|
36
36
|
const ve = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [g,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
38
|
+
const [g, I] = Bt(m);
|
|
39
|
+
(Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
|
|
40
|
+
I[v] = I[v] || {}, I[v].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...c?.validation,
|
|
44
|
-
...
|
|
44
|
+
...I[v].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
}, rt(v) || o.getState().setInitialStateOptions(v,
|
|
46
|
+
}, rt(v) || o.getState().setInitialStateOptions(v, I[v]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
48
|
const N = (v, s) => {
|
|
49
|
-
const [
|
|
49
|
+
const [T] = K(s?.componentId ?? At());
|
|
50
50
|
xt({
|
|
51
51
|
stateKey: v,
|
|
52
52
|
options: s,
|
|
53
|
-
initialOptionsPart:
|
|
53
|
+
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const r = o.getState().cogsStateStore[v] || g[v],
|
|
56
|
-
|
|
55
|
+
const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = ne(
|
|
56
|
+
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
59
59
|
syncUpdate: s?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: T,
|
|
61
61
|
localStorage: s?.localStorage,
|
|
62
62
|
middleware: s?.middleware,
|
|
63
63
|
enabledSync: s?.enabledSync,
|
|
@@ -71,11 +71,11 @@ const ve = (t, c) => {
|
|
|
71
71
|
return j;
|
|
72
72
|
};
|
|
73
73
|
function p(v, s) {
|
|
74
|
-
xt({ stateKey: v, options: s, initialOptionsPart:
|
|
74
|
+
xt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && te(v, s), dt(v);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
78
|
+
setUpdaterState: Tt,
|
|
79
79
|
setState: nt,
|
|
80
80
|
getInitialOptions: rt,
|
|
81
81
|
getKeyState: Lt,
|
|
@@ -85,7 +85,7 @@ const ve = (t, c) => {
|
|
|
85
85
|
addValidationError: Rt,
|
|
86
86
|
removeValidationError: X,
|
|
87
87
|
setServerSyncActions: Kt
|
|
88
|
-
} = o.getState(), Pt = (t, c, m, g,
|
|
88
|
+
} = o.getState(), Pt = (t, c, m, g, I) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
@@ -103,11 +103,11 @@ const ve = (t, c) => {
|
|
|
103
103
|
const s = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: I ?? v
|
|
107
|
+
}, T = Jt.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
|
-
JSON.stringify(
|
|
110
|
+
JSON.stringify(T.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
}, vt = (t) => {
|
|
@@ -119,27 +119,27 @@ const ve = (t, c) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
121
|
}, te = (t, c) => {
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(),
|
|
123
|
-
if (
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
|
+
if (I && g) {
|
|
124
124
|
const N = vt(
|
|
125
|
-
`${g}-${t}-${
|
|
125
|
+
`${g}-${t}-${I}`
|
|
126
126
|
);
|
|
127
127
|
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
128
|
return nt(t, N.state), dt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, Dt = (t, c, m, g,
|
|
131
|
+
}, Dt = (t, c, m, g, I, N) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: It(
|
|
135
135
|
t,
|
|
136
136
|
g,
|
|
137
|
-
|
|
137
|
+
I,
|
|
138
138
|
N
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
Nt(t, p.initialState),
|
|
142
|
+
Nt(t, p.initialState), Tt(t, p.updaterState), nt(t, p.state);
|
|
143
143
|
}, dt = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
@@ -152,10 +152,10 @@ const ve = (t, c) => {
|
|
|
152
152
|
}, ye = (t, c) => {
|
|
153
153
|
const m = o.getState().stateComponents.get(t);
|
|
154
154
|
if (m) {
|
|
155
|
-
const g = `${t}////${c}`,
|
|
156
|
-
if ((
|
|
155
|
+
const g = `${t}////${c}`, I = m.components.get(g);
|
|
156
|
+
if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
|
-
|
|
158
|
+
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
160
|
}, ee = (t, c, m, g) => {
|
|
161
161
|
switch (t) {
|
|
@@ -184,14 +184,14 @@ function ne(t, {
|
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
|
-
formElements:
|
|
187
|
+
formElements: I,
|
|
188
188
|
reactiveDeps: N,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: v,
|
|
191
191
|
initialState: s,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: T,
|
|
193
193
|
dependencies: r,
|
|
194
|
-
serverState:
|
|
194
|
+
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
196
|
const [W, j] = K({}), { sessionId: U } = Gt();
|
|
197
197
|
let z = !c;
|
|
@@ -199,18 +199,18 @@ function ne(t, {
|
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
201
|
L.current = rt(h) ?? null, ot(() => {
|
|
202
|
-
if (
|
|
202
|
+
if (T && T.stateKey === h && T.path?.[0]) {
|
|
203
203
|
nt(h, (n) => ({
|
|
204
204
|
...n,
|
|
205
|
-
[
|
|
205
|
+
[T.path[0]]: T.newValue
|
|
206
206
|
}));
|
|
207
|
-
const e = `${
|
|
207
|
+
const e = `${T.stateKey}:${T.path.join(".")}`;
|
|
208
208
|
o.getState().setSyncInfo(e, {
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
209
|
+
timeStamp: T.timeStamp,
|
|
210
|
+
userId: T.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [T]), ot(() => {
|
|
214
214
|
if (s) {
|
|
215
215
|
Mt(h, {
|
|
216
216
|
initialState: s
|
|
@@ -234,13 +234,13 @@ function ne(t, {
|
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
S?.status,
|
|
238
|
+
S?.data,
|
|
239
239
|
...r || []
|
|
240
240
|
]), ct(() => {
|
|
241
241
|
z && Mt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
|
-
formElements:
|
|
243
|
+
formElements: I,
|
|
244
244
|
initialState: s,
|
|
245
245
|
localStorage: g,
|
|
246
246
|
middleware: L.current?.middleware
|
|
@@ -263,17 +263,17 @@ function ne(t, {
|
|
|
263
263
|
const u = `${h}-${n.join(".")}`;
|
|
264
264
|
ut.current.add(u);
|
|
265
265
|
}
|
|
266
|
-
const
|
|
266
|
+
const f = o.getState();
|
|
267
267
|
nt(h, (u) => {
|
|
268
268
|
const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
|
|
269
269
|
if (y) {
|
|
270
|
-
let M = !1, $ =
|
|
270
|
+
let M = !1, $ = f.signalDomElements.get(y);
|
|
271
271
|
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
272
|
const R = n.slice(0, -1), V = Z(E, R);
|
|
273
273
|
if (Array.isArray(V)) {
|
|
274
274
|
M = !0;
|
|
275
275
|
const O = `${h}-${R.join(".")}`;
|
|
276
|
-
$ =
|
|
276
|
+
$ = f.signalDomElements.get(O);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if ($) {
|
|
@@ -292,7 +292,7 @@ function ne(t, {
|
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState",
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i || L.current?.validation?.key) && n && X(
|
|
296
296
|
(i || L.current?.validation?.key) + "." + n.join(".")
|
|
297
297
|
);
|
|
298
298
|
const w = n.slice(0, n.length - 1);
|
|
@@ -307,7 +307,7 @@ function ne(t, {
|
|
|
307
307
|
X($), Rt(O, R);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const C =
|
|
310
|
+
const C = f.stateComponents.get(h);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
312
|
const M = _t(u, E), $ = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
@@ -379,15 +379,15 @@ function ne(t, {
|
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
|
|
382
|
+
f.updateShadowAtPath(h, n, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const M = n.slice(0, -1);
|
|
386
|
-
|
|
386
|
+
f.insertShadowArrayElement(h, M, F);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
389
|
const $ = n.slice(0, -1), R = parseInt(n[n.length - 1]);
|
|
390
|
-
|
|
390
|
+
f.removeShadowArrayElement(h, $, R);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
if (Qt(h, (M) => {
|
|
@@ -405,7 +405,7 @@ function ne(t, {
|
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
407
|
}), L.current?.serverSync) {
|
|
408
|
-
const M =
|
|
408
|
+
const M = f.serverState[h], $ = L.current?.serverSync;
|
|
409
409
|
Kt(h, {
|
|
410
410
|
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
@@ -416,16 +416,16 @@ function ne(t, {
|
|
|
416
416
|
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[h] || (
|
|
419
|
+
o.getState().updaterState[h] || (Tt(
|
|
420
420
|
h,
|
|
421
|
-
|
|
421
|
+
It(
|
|
422
422
|
h,
|
|
423
423
|
at,
|
|
424
424
|
et.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
427
|
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Nt(h, t));
|
|
428
|
-
const d = wt(() =>
|
|
428
|
+
const d = wt(() => It(
|
|
429
429
|
h,
|
|
430
430
|
at,
|
|
431
431
|
et.current,
|
|
@@ -433,40 +433,40 @@ function ne(t, {
|
|
|
433
433
|
), [h, U]);
|
|
434
434
|
return [Lt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
437
|
-
const
|
|
436
|
+
function It(t, c, m, g) {
|
|
437
|
+
const I = /* @__PURE__ */ new Map();
|
|
438
438
|
let N = 0;
|
|
439
|
-
const p = (
|
|
440
|
-
const r =
|
|
441
|
-
for (const [
|
|
442
|
-
(
|
|
439
|
+
const p = (T) => {
|
|
440
|
+
const r = T.join(".");
|
|
441
|
+
for (const [S] of I)
|
|
442
|
+
(S === r || S.startsWith(r + ".")) && I.delete(S);
|
|
443
443
|
N++;
|
|
444
444
|
}, v = {
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
445
|
+
removeValidation: (T) => {
|
|
446
|
+
T?.validationKey && X(T.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
448
|
+
revertToInitialState: (T) => {
|
|
449
449
|
const r = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
r?.key && X(r?.key),
|
|
451
|
-
const
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t),
|
|
453
|
-
const W = s(
|
|
454
|
-
z && localStorage.removeItem(z),
|
|
450
|
+
r?.key && X(r?.key), T?.validationKey && X(T.validationKey);
|
|
451
|
+
const S = o.getState().initialStateGlobal[t];
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
|
|
453
|
+
const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
|
|
454
|
+
z && localStorage.removeItem(z), Tt(t, W), nt(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
|
-
}),
|
|
458
|
+
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
462
|
-
const r =
|
|
460
|
+
updateInitialState: (T) => {
|
|
461
|
+
I.clear(), N++;
|
|
462
|
+
const r = It(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
),
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
|
|
468
468
|
return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
|
|
469
|
-
Nt(t,
|
|
469
|
+
Nt(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
|
|
470
470
|
const z = o.getState().stateComponents.get(t);
|
|
471
471
|
z && z.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
@@ -479,13 +479,13 @@ function Tt(t, c, m, g) {
|
|
|
479
479
|
_serverState: o.getState().serverState[t],
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const T = o.getState().serverState[t];
|
|
483
|
+
return !!(T && J(T, Lt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function s(
|
|
486
|
+
function s(T, r = [], S) {
|
|
487
487
|
const W = r.map(String).join(".");
|
|
488
|
-
|
|
488
|
+
I.get(W);
|
|
489
489
|
const j = function() {
|
|
490
490
|
return o().getNestedState(t, r);
|
|
491
491
|
};
|
|
@@ -499,7 +499,7 @@ function Tt(t, c, m, g) {
|
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
|
-
|
|
502
|
+
S?.validIndices && !Array.isArray(T) && (S = { ...S, validIndices: void 0 });
|
|
503
503
|
const ut = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
@@ -530,8 +530,8 @@ function Tt(t, c, m, g) {
|
|
|
530
530
|
if (n && !n.paths.has("")) {
|
|
531
531
|
const a = r.join(".");
|
|
532
532
|
let i = !0;
|
|
533
|
-
for (const
|
|
534
|
-
if (a.startsWith(
|
|
533
|
+
for (const f of n.paths)
|
|
534
|
+
if (a.startsWith(f) && (a === f || a[f.length] === ".")) {
|
|
535
535
|
i = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
@@ -557,8 +557,8 @@ function Tt(t, c, m, g) {
|
|
|
557
557
|
const E = [a, ...u.path].join(".");
|
|
558
558
|
o.getState().addValidationError(E, u.message);
|
|
559
559
|
});
|
|
560
|
-
const
|
|
561
|
-
|
|
560
|
+
const f = o.getState().stateComponents.get(t);
|
|
561
|
+
f && f.components.forEach((u) => {
|
|
562
562
|
u.forceUpdate();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
@@ -591,10 +591,10 @@ function Tt(t, c, m, g) {
|
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + r.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () =>
|
|
594
|
+
if (Array.isArray(T)) {
|
|
595
|
+
const d = () => S?.validIndices ? T.map((n, a) => ({
|
|
596
596
|
item: n,
|
|
597
|
-
originalIndex:
|
|
597
|
+
originalIndex: S.validIndices[a]
|
|
598
598
|
})) : o.getState().getNestedState(t, r).map((n, a) => ({
|
|
599
599
|
item: n,
|
|
600
600
|
originalIndex: a
|
|
@@ -604,9 +604,9 @@ function Tt(t, c, m, g) {
|
|
|
604
604
|
const e = o.getState().getSelectedIndex(t, r.join("."));
|
|
605
605
|
if (e !== void 0)
|
|
606
606
|
return s(
|
|
607
|
-
|
|
607
|
+
T[e],
|
|
608
608
|
[...r, e.toString()],
|
|
609
|
-
|
|
609
|
+
S
|
|
610
610
|
);
|
|
611
611
|
};
|
|
612
612
|
if (l === "clearSelected")
|
|
@@ -621,11 +621,11 @@ function Tt(t, c, m, g) {
|
|
|
621
621
|
itemHeight: n = 50,
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: i = !1,
|
|
624
|
-
dependencies:
|
|
624
|
+
dependencies: f = []
|
|
625
625
|
} = e, u = q(!1), E = q(null), [y, w] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [C, A] = K("IDLE_AT_TOP"), b = q(!1), F = q(0), Y = q(
|
|
628
|
+
}), [C, A] = K("IDLE_AT_TOP"), b = q(!1), F = q(0), Y = q(f), M = q(0), [$, R] = K(0), V = q(null);
|
|
629
629
|
ot(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
630
|
R((x) => x + 1);
|
|
631
631
|
}), [t]);
|
|
@@ -654,7 +654,7 @@ function Tt(t, c, m, g) {
|
|
|
654
654
|
(Q, ft) => k + ft
|
|
655
655
|
), P = H.map((Q) => O[Q]);
|
|
656
656
|
return s(P, r, {
|
|
657
|
-
...
|
|
657
|
+
...S,
|
|
658
658
|
validIndices: H
|
|
659
659
|
});
|
|
660
660
|
}, [y.startIndex, y.endIndex, O, _]);
|
|
@@ -671,7 +671,7 @@ function Tt(t, c, m, g) {
|
|
|
671
671
|
}, 100), V.current = null;
|
|
672
672
|
} else {
|
|
673
673
|
if (!J(
|
|
674
|
-
|
|
674
|
+
f,
|
|
675
675
|
Y.current
|
|
676
676
|
)) {
|
|
677
677
|
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("IDLE_AT_TOP");
|
|
@@ -681,8 +681,8 @@ function Tt(t, c, m, g) {
|
|
|
681
681
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
682
682
|
), A("GETTING_HEIGHTS"));
|
|
683
683
|
}
|
|
684
|
-
F.current = _, Y.current =
|
|
685
|
-
}, [_, ...
|
|
684
|
+
F.current = _, Y.current = f;
|
|
685
|
+
}, [_, ...f]), ct(() => {
|
|
686
686
|
const k = E.current;
|
|
687
687
|
if (!k) return;
|
|
688
688
|
let x;
|
|
@@ -798,31 +798,31 @@ function Tt(t, c, m, g) {
|
|
|
798
798
|
return (e) => {
|
|
799
799
|
const a = [...d()].sort(
|
|
800
800
|
(u, E) => e(u.item, E.item)
|
|
801
|
-
), i = a.map(({ item: u }) => u),
|
|
802
|
-
...
|
|
801
|
+
), i = a.map(({ item: u }) => u), f = {
|
|
802
|
+
...S,
|
|
803
803
|
validIndices: a.map(
|
|
804
804
|
({ originalIndex: u }) => u
|
|
805
805
|
)
|
|
806
806
|
};
|
|
807
|
-
return s(i, r,
|
|
807
|
+
return s(i, r, f);
|
|
808
808
|
};
|
|
809
809
|
if (l === "stateFilter")
|
|
810
810
|
return (e) => {
|
|
811
811
|
const a = d().filter(
|
|
812
812
|
({ item: u }, E) => e(u, E)
|
|
813
|
-
), i = a.map(({ item: u }) => u),
|
|
814
|
-
...
|
|
813
|
+
), i = a.map(({ item: u }) => u), f = {
|
|
814
|
+
...S,
|
|
815
815
|
validIndices: a.map(
|
|
816
816
|
({ originalIndex: u }) => u
|
|
817
817
|
)
|
|
818
818
|
};
|
|
819
|
-
return s(i, r,
|
|
819
|
+
return s(i, r, f);
|
|
820
820
|
};
|
|
821
821
|
if (l === "stateMap")
|
|
822
822
|
return (e) => {
|
|
823
823
|
const n = o.getState().getNestedState(t, r);
|
|
824
|
-
return Array.isArray(n) ? (
|
|
825
|
-
const u = n[i], E = [...r, i.toString()], y = s(u, E,
|
|
824
|
+
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
825
|
+
const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
|
|
826
826
|
return e(u, y, {
|
|
827
827
|
register: () => {
|
|
828
828
|
const [, C] = K({}), A = `${m}-${r.join(".")}-${i}`;
|
|
@@ -839,7 +839,7 @@ function Tt(t, c, m, g) {
|
|
|
839
839
|
};
|
|
840
840
|
}, [t, A]);
|
|
841
841
|
},
|
|
842
|
-
index:
|
|
842
|
+
index: f,
|
|
843
843
|
originalIndex: i
|
|
844
844
|
});
|
|
845
845
|
}) : (console.warn(
|
|
@@ -848,16 +848,16 @@ function Tt(t, c, m, g) {
|
|
|
848
848
|
), null);
|
|
849
849
|
};
|
|
850
850
|
if (l === "stateMapNoRender")
|
|
851
|
-
return (e) =>
|
|
852
|
-
let
|
|
853
|
-
|
|
854
|
-
const u = [...r,
|
|
851
|
+
return (e) => T.map((a, i) => {
|
|
852
|
+
let f;
|
|
853
|
+
S?.validIndices && S.validIndices[i] !== void 0 ? f = S.validIndices[i] : f = i;
|
|
854
|
+
const u = [...r, f.toString()], E = s(a, u, S);
|
|
855
855
|
return e(
|
|
856
856
|
a,
|
|
857
857
|
E,
|
|
858
858
|
i,
|
|
859
|
-
|
|
860
|
-
s(
|
|
859
|
+
T,
|
|
860
|
+
s(T, r, S)
|
|
861
861
|
);
|
|
862
862
|
});
|
|
863
863
|
if (l === "$stateMap")
|
|
@@ -873,8 +873,8 @@ function Tt(t, c, m, g) {
|
|
|
873
873
|
if (l === "stateList")
|
|
874
874
|
return (e) => {
|
|
875
875
|
const n = o.getState().getNestedState(t, r);
|
|
876
|
-
return Array.isArray(n) ? (
|
|
877
|
-
const u = n[i], E = [...r, i.toString()], y = s(u, E,
|
|
876
|
+
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
877
|
+
const u = n[i], E = [...r, i.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${i}`;
|
|
878
878
|
return lt(ae, {
|
|
879
879
|
key: i,
|
|
880
880
|
stateKey: t,
|
|
@@ -883,9 +883,9 @@ function Tt(t, c, m, g) {
|
|
|
883
883
|
children: e(
|
|
884
884
|
u,
|
|
885
885
|
y,
|
|
886
|
-
i,
|
|
886
|
+
{ localIndex: f, originalIndex: i },
|
|
887
887
|
n,
|
|
888
|
-
s(n, r,
|
|
888
|
+
s(n, r, S)
|
|
889
889
|
)
|
|
890
890
|
});
|
|
891
891
|
}) : (console.warn(
|
|
@@ -894,20 +894,20 @@ function Tt(t, c, m, g) {
|
|
|
894
894
|
};
|
|
895
895
|
if (l === "stateFlattenOn")
|
|
896
896
|
return (e) => {
|
|
897
|
-
const n =
|
|
898
|
-
|
|
897
|
+
const n = T;
|
|
898
|
+
I.clear(), N++;
|
|
899
899
|
const a = n.flatMap(
|
|
900
900
|
(i) => i[e] ?? []
|
|
901
901
|
);
|
|
902
902
|
return s(
|
|
903
903
|
a,
|
|
904
904
|
[...r, "[*]", e],
|
|
905
|
-
|
|
905
|
+
S
|
|
906
906
|
);
|
|
907
907
|
};
|
|
908
908
|
if (l === "index")
|
|
909
909
|
return (e) => {
|
|
910
|
-
const n =
|
|
910
|
+
const n = T[e];
|
|
911
911
|
return s(n, [...r, e.toString()]);
|
|
912
912
|
};
|
|
913
913
|
if (l === "last")
|
|
@@ -924,19 +924,19 @@ function Tt(t, c, m, g) {
|
|
|
924
924
|
));
|
|
925
925
|
if (l === "uniqueInsert")
|
|
926
926
|
return (e, n, a) => {
|
|
927
|
-
const i = o.getState().getNestedState(t, r),
|
|
927
|
+
const i = o.getState().getNestedState(t, r), f = tt(e) ? e(i) : e;
|
|
928
928
|
let u = null;
|
|
929
929
|
if (!i.some((y) => {
|
|
930
930
|
if (n) {
|
|
931
931
|
const C = n.every(
|
|
932
|
-
(A) => J(y[A],
|
|
932
|
+
(A) => J(y[A], f[A])
|
|
933
933
|
);
|
|
934
934
|
return C && (u = y), C;
|
|
935
935
|
}
|
|
936
|
-
const w = J(y,
|
|
936
|
+
const w = J(y, f);
|
|
937
937
|
return w && (u = y), w;
|
|
938
938
|
}))
|
|
939
|
-
p(r), Et(c,
|
|
939
|
+
p(r), Et(c, f, r, t);
|
|
940
940
|
else if (a && u) {
|
|
941
941
|
const y = a(u), w = i.map(
|
|
942
942
|
(C) => J(C, u) ? y : C
|
|
@@ -954,22 +954,22 @@ function Tt(t, c, m, g) {
|
|
|
954
954
|
};
|
|
955
955
|
if (l === "cutByValue")
|
|
956
956
|
return (e) => {
|
|
957
|
-
for (let n = 0; n <
|
|
958
|
-
|
|
957
|
+
for (let n = 0; n < T.length; n++)
|
|
958
|
+
T[n] === e && ht(c, r, t, n);
|
|
959
959
|
};
|
|
960
960
|
if (l === "toggleByValue")
|
|
961
961
|
return (e) => {
|
|
962
|
-
const n =
|
|
962
|
+
const n = T.findIndex((a) => a === e);
|
|
963
963
|
n > -1 ? ht(c, r, t, n) : Et(c, e, r, t);
|
|
964
964
|
};
|
|
965
965
|
if (l === "stateFind")
|
|
966
966
|
return (e) => {
|
|
967
967
|
const a = d().find(
|
|
968
|
-
({ item:
|
|
968
|
+
({ item: f }, u) => e(f, u)
|
|
969
969
|
);
|
|
970
970
|
if (!a) return;
|
|
971
971
|
const i = [...r, a.originalIndex.toString()];
|
|
972
|
-
return s(a.item, i,
|
|
972
|
+
return s(a.item, i, S);
|
|
973
973
|
};
|
|
974
974
|
if (l === "findWith")
|
|
975
975
|
return (e, n) => {
|
|
@@ -977,8 +977,8 @@ function Tt(t, c, m, g) {
|
|
|
977
977
|
({ item: u }) => u[e] === n
|
|
978
978
|
);
|
|
979
979
|
if (!i) return;
|
|
980
|
-
const
|
|
981
|
-
return s(i.item,
|
|
980
|
+
const f = [...r, i.originalIndex.toString()];
|
|
981
|
+
return s(i.item, f, S);
|
|
982
982
|
};
|
|
983
983
|
}
|
|
984
984
|
const et = r[r.length - 1];
|
|
@@ -994,9 +994,9 @@ function Tt(t, c, m, g) {
|
|
|
994
994
|
}
|
|
995
995
|
if (l === "get")
|
|
996
996
|
return () => {
|
|
997
|
-
if (
|
|
997
|
+
if (S?.validIndices && Array.isArray(T)) {
|
|
998
998
|
const d = o.getState().getNestedState(t, r);
|
|
999
|
-
return
|
|
999
|
+
return S.validIndices.map((e) => d[e]);
|
|
1000
1000
|
}
|
|
1001
1001
|
return o.getState().getNestedState(t, r);
|
|
1002
1002
|
};
|
|
@@ -1063,7 +1063,7 @@ function Tt(t, c, m, g) {
|
|
|
1063
1063
|
);
|
|
1064
1064
|
const i = o.getState().stateComponents.get(t);
|
|
1065
1065
|
if (i) {
|
|
1066
|
-
const
|
|
1066
|
+
const f = _t(e, a), u = new Set(f);
|
|
1067
1067
|
for (const [
|
|
1068
1068
|
E,
|
|
1069
1069
|
y
|
|
@@ -1129,8 +1129,8 @@ function Tt(t, c, m, g) {
|
|
|
1129
1129
|
const n = o.getState().cogsStateStore[t];
|
|
1130
1130
|
try {
|
|
1131
1131
|
const a = o.getState().getValidationErrors(d.key);
|
|
1132
|
-
a && a.length > 0 && a.forEach(([
|
|
1133
|
-
|
|
1132
|
+
a && a.length > 0 && a.forEach(([f]) => {
|
|
1133
|
+
f && f.startsWith(d.key) && X(f);
|
|
1134
1134
|
});
|
|
1135
1135
|
const i = d.zodSchema.safeParse(n);
|
|
1136
1136
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
@@ -1170,7 +1170,7 @@ function Tt(t, c, m, g) {
|
|
|
1170
1170
|
path: r,
|
|
1171
1171
|
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1172
1172
|
stateKey: t,
|
|
1173
|
-
validIndices:
|
|
1173
|
+
validIndices: S?.validIndices,
|
|
1174
1174
|
children: d
|
|
1175
1175
|
}
|
|
1176
1176
|
);
|
|
@@ -1204,10 +1204,10 @@ function Tt(t, c, m, g) {
|
|
|
1204
1204
|
}
|
|
1205
1205
|
);
|
|
1206
1206
|
const L = [...r, l], at = o.getState().getNestedState(t, L);
|
|
1207
|
-
return s(at, L,
|
|
1207
|
+
return s(at, L, S);
|
|
1208
1208
|
}
|
|
1209
1209
|
}, z = new Proxy(j, U);
|
|
1210
|
-
return
|
|
1210
|
+
return I.set(W, {
|
|
1211
1211
|
proxy: z,
|
|
1212
1212
|
stateVersion: N
|
|
1213
1213
|
}), z;
|
|
@@ -1228,7 +1228,7 @@ function re({
|
|
|
1228
1228
|
m,
|
|
1229
1229
|
t._path
|
|
1230
1230
|
).stateMapNoRender(
|
|
1231
|
-
(
|
|
1231
|
+
(I, N, p, v, s) => t._mapFn(I, N, p, v, s)
|
|
1232
1232
|
) : null;
|
|
1233
1233
|
}
|
|
1234
1234
|
function oe({
|
|
@@ -1238,31 +1238,31 @@ function oe({
|
|
|
1238
1238
|
return ot(() => {
|
|
1239
1239
|
const g = c.current;
|
|
1240
1240
|
if (!g || !g.parentElement) return;
|
|
1241
|
-
const
|
|
1242
|
-
let v =
|
|
1243
|
-
v || (v = `parent-${crypto.randomUUID()}`,
|
|
1244
|
-
const
|
|
1241
|
+
const I = g.parentElement, p = Array.from(I.childNodes).indexOf(g);
|
|
1242
|
+
let v = I.getAttribute("data-parent-id");
|
|
1243
|
+
v || (v = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", v));
|
|
1244
|
+
const T = {
|
|
1245
1245
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1246
1246
|
parentId: v,
|
|
1247
1247
|
position: p,
|
|
1248
1248
|
effect: t._effect
|
|
1249
1249
|
};
|
|
1250
|
-
o.getState().addSignalElement(m,
|
|
1250
|
+
o.getState().addSignalElement(m, T);
|
|
1251
1251
|
const r = o.getState().getNestedState(t._stateKey, t._path);
|
|
1252
|
-
let
|
|
1252
|
+
let S;
|
|
1253
1253
|
if (t._effect)
|
|
1254
1254
|
try {
|
|
1255
|
-
|
|
1255
|
+
S = new Function(
|
|
1256
1256
|
"state",
|
|
1257
1257
|
`return (${t._effect})(state)`
|
|
1258
1258
|
)(r);
|
|
1259
1259
|
} catch (j) {
|
|
1260
|
-
console.error("Error evaluating effect function during mount:", j),
|
|
1260
|
+
console.error("Error evaluating effect function during mount:", j), S = r;
|
|
1261
1261
|
}
|
|
1262
1262
|
else
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
const W = document.createTextNode(String(
|
|
1263
|
+
S = r;
|
|
1264
|
+
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1265
|
+
const W = document.createTextNode(String(S));
|
|
1266
1266
|
g.replaceWith(W);
|
|
1267
1267
|
}, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
|
|
1268
1268
|
ref: c,
|
|
@@ -1291,7 +1291,7 @@ function ae({
|
|
|
1291
1291
|
itemPath: m,
|
|
1292
1292
|
children: g
|
|
1293
1293
|
}) {
|
|
1294
|
-
const [,
|
|
1294
|
+
const [, I] = K({}), [N, p] = Zt(), v = q(null);
|
|
1295
1295
|
return ot(() => {
|
|
1296
1296
|
p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1297
1297
|
virtualizer: {
|
|
@@ -1299,13 +1299,13 @@ function ae({
|
|
|
1299
1299
|
}
|
|
1300
1300
|
}));
|
|
1301
1301
|
}, [p.height, t, m]), ct(() => {
|
|
1302
|
-
const s = `${t}////${c}`,
|
|
1302
|
+
const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
|
|
1303
1303
|
components: /* @__PURE__ */ new Map()
|
|
1304
1304
|
};
|
|
1305
|
-
return
|
|
1306
|
-
forceUpdate: () =>
|
|
1305
|
+
return T.components.set(s, {
|
|
1306
|
+
forceUpdate: () => I({}),
|
|
1307
1307
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1308
|
-
}), o.getState().stateComponents.set(t,
|
|
1308
|
+
}), o.getState().stateComponents.set(t, T), () => {
|
|
1309
1309
|
const r = o.getState().stateComponents.get(t);
|
|
1310
1310
|
r && r.components.delete(s);
|
|
1311
1311
|
};
|
|
@@ -1314,7 +1314,7 @@ function ae({
|
|
|
1314
1314
|
export {
|
|
1315
1315
|
Vt as $cogsSignal,
|
|
1316
1316
|
pe as $cogsSignalStore,
|
|
1317
|
-
|
|
1317
|
+
Ie as addStateOptions,
|
|
1318
1318
|
ve as createCogsState,
|
|
1319
1319
|
ye as notifyComponent,
|
|
1320
1320
|
ne as useCogsStateFn
|