cogsbox-state 0.5.393 → 0.5.394
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 +170 -170
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -10,37 +10,37 @@ import { getGlobalStore as o, formRefStore as bt } from "./store.js";
|
|
|
10
10
|
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
|
-
function Mt(t,
|
|
13
|
+
function Mt(t, i) {
|
|
14
14
|
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, T = m(t) || {};
|
|
15
15
|
g(t, {
|
|
16
16
|
...T,
|
|
17
|
-
...
|
|
17
|
+
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
function xt({
|
|
21
21
|
stateKey: t,
|
|
22
|
-
options:
|
|
22
|
+
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
25
|
const g = rt(t) || {}, T = m[t] || {}, N = o.getState().setInitialStateOptions, p = { ...T, ...g };
|
|
26
26
|
let v = !1;
|
|
27
|
-
if (
|
|
28
|
-
for (const s in
|
|
29
|
-
p.hasOwnProperty(s) ? (s == "localStorage" &&
|
|
30
|
-
!J(p[s],
|
|
27
|
+
if (i)
|
|
28
|
+
for (const s in i)
|
|
29
|
+
p.hasOwnProperty(s) ? (s == "localStorage" && i[s] && p[s].key !== i[s]?.key && (v = !0, p[s] = i[s]), s == "initialState" && i[s] && p[s] !== i[s] && // Different references
|
|
30
|
+
!J(p[s], i[s]) && (v = !0, p[s] = i[s])) : (v = !0, p[s] = i[s]);
|
|
31
31
|
v && N(t, p);
|
|
32
32
|
}
|
|
33
|
-
function Te(t, { formElements:
|
|
34
|
-
return { initialState: t, formElements:
|
|
33
|
+
function Te(t, { formElements: i, validation: m }) {
|
|
34
|
+
return { initialState: t, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const ve = (t,
|
|
36
|
+
const ve = (t, i) => {
|
|
37
37
|
let m = t;
|
|
38
38
|
const [g, T] = Bt(m);
|
|
39
|
-
(Object.keys(T).length > 0 ||
|
|
39
|
+
(Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
|
|
40
40
|
T[v] = T[v] || {}, T[v].formElements = {
|
|
41
|
-
...
|
|
41
|
+
...i?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
|
-
...
|
|
43
|
+
...i?.validation,
|
|
44
44
|
...T[v].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, rt(v) || o.getState().setInitialStateOptions(v, T[v]);
|
|
@@ -52,8 +52,8 @@ const ve = (t, c) => {
|
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: T
|
|
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,
|
|
@@ -85,16 +85,16 @@ const ve = (t, c) => {
|
|
|
85
85
|
addValidationError: Rt,
|
|
86
86
|
removeValidationError: X,
|
|
87
87
|
setServerSyncActions: Kt
|
|
88
|
-
} = o.getState(), Pt = (t,
|
|
88
|
+
} = o.getState(), Pt = (t, i, m, g, T) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
|
-
|
|
91
|
+
i,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
95
|
const N = tt(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
96
|
if (N && g) {
|
|
97
|
-
const p = `${g}-${
|
|
97
|
+
const p = `${g}-${i}-${N}`;
|
|
98
98
|
let v;
|
|
99
99
|
try {
|
|
100
100
|
v = vt(p)?.lastSyncedWithServer;
|
|
@@ -113,13 +113,13 @@ const ve = (t, c) => {
|
|
|
113
113
|
}, vt = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
|
-
const
|
|
117
|
-
return
|
|
118
|
-
} catch (
|
|
119
|
-
return console.error("Error loading from localStorage:",
|
|
116
|
+
const i = window.localStorage.getItem(t);
|
|
117
|
+
return i ? JSON.parse(i) : null;
|
|
118
|
+
} catch (i) {
|
|
119
|
+
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
|
-
}, te = (t,
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), T = tt(
|
|
121
|
+
}, te = (t, i) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), T = tt(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (T && g) {
|
|
124
124
|
const N = vt(
|
|
125
125
|
`${g}-${t}-${T}`
|
|
@@ -128,9 +128,9 @@ const ve = (t, c) => {
|
|
|
128
128
|
return nt(t, N.state), dt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, Dt = (t,
|
|
131
|
+
}, Dt = (t, i, m, g, T, N) => {
|
|
132
132
|
const p = {
|
|
133
|
-
initialState:
|
|
133
|
+
initialState: i,
|
|
134
134
|
updaterState: Tt(
|
|
135
135
|
t,
|
|
136
136
|
g,
|
|
@@ -141,27 +141,27 @@ const ve = (t, c) => {
|
|
|
141
141
|
};
|
|
142
142
|
Nt(t, p.initialState), It(t, p.updaterState), nt(t, p.state);
|
|
143
143
|
}, dt = (t) => {
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
144
|
+
const i = o.getState().stateComponents.get(t);
|
|
145
|
+
if (!i) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
147
|
-
|
|
147
|
+
i.components.forEach((g) => {
|
|
148
148
|
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || m.add(() => g.forceUpdate());
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
}, ye = (t,
|
|
152
|
+
}, ye = (t, i) => {
|
|
153
153
|
const m = o.getState().stateComponents.get(t);
|
|
154
154
|
if (m) {
|
|
155
|
-
const g = `${t}////${
|
|
155
|
+
const g = `${t}////${i}`, T = m.components.get(g);
|
|
156
156
|
if ((T ? Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
158
|
T && T.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
}, ee = (t,
|
|
160
|
+
}, ee = (t, i, m, g) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue: Z(
|
|
164
|
+
oldValue: Z(i, g),
|
|
165
165
|
newValue: Z(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
@@ -172,7 +172,7 @@ const ve = (t, c) => {
|
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue: Z(
|
|
175
|
+
oldValue: Z(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -181,7 +181,7 @@ const ve = (t, c) => {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
function ne(t, {
|
|
184
|
-
stateKey:
|
|
184
|
+
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: T,
|
|
@@ -191,11 +191,11 @@ function ne(t, {
|
|
|
191
191
|
initialState: s,
|
|
192
192
|
syncUpdate: I,
|
|
193
193
|
dependencies: r,
|
|
194
|
-
serverState:
|
|
194
|
+
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
196
|
const [W, j] = K({}), { sessionId: U } = Gt();
|
|
197
|
-
let z = !
|
|
198
|
-
const [h] = K(
|
|
197
|
+
let z = !i;
|
|
198
|
+
const [h] = K(i ?? At()), l = o.getState().stateLog[h], ut = q(/* @__PURE__ */ new Set()), et = q(v ?? At()), L = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
201
|
L.current = rt(h) ?? null, ot(() => {
|
|
@@ -215,8 +215,8 @@ function ne(t, {
|
|
|
215
215
|
Mt(h, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e = L.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data,
|
|
219
|
-
if (!(
|
|
218
|
+
const e = L.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[h];
|
|
219
|
+
if (!(c && !J(c, s) || !c) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
@@ -234,8 +234,8 @@ 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, {
|
|
@@ -258,22 +258,22 @@ function ne(t, {
|
|
|
258
258
|
n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const at = (e, n, a,
|
|
261
|
+
const at = (e, n, a, c) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
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,8 +292,8 @@ function ne(t, {
|
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState",
|
|
296
|
-
(
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c || L.current?.validation?.key) && n && X(
|
|
296
|
+
(c || L.current?.validation?.key) + "." + n.join(".")
|
|
297
297
|
);
|
|
298
298
|
const w = n.slice(0, n.length - 1);
|
|
299
299
|
a.updateType === "cut" && L.current?.validation?.key && X(
|
|
@@ -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,
|
|
@@ -433,13 +433,13 @@ function ne(t, {
|
|
|
433
433
|
), [h, U]);
|
|
434
434
|
return [Lt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function Tt(t,
|
|
436
|
+
function Tt(t, i, m, g) {
|
|
437
437
|
const T = /* @__PURE__ */ new Map();
|
|
438
438
|
let N = 0;
|
|
439
439
|
const p = (I) => {
|
|
440
440
|
const r = I.join(".");
|
|
441
|
-
for (const [
|
|
442
|
-
(
|
|
441
|
+
for (const [S] of T)
|
|
442
|
+
(S === r || S.startsWith(r + ".")) && T.delete(S);
|
|
443
443
|
N++;
|
|
444
444
|
}, v = {
|
|
445
445
|
removeValidation: (I) => {
|
|
@@ -448,23 +448,23 @@ function Tt(t, c, m, g) {
|
|
|
448
448
|
revertToInitialState: (I) => {
|
|
449
449
|
const r = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
r?.key && X(r?.key), I?.validationKey && X(I.validationKey);
|
|
451
|
-
const
|
|
451
|
+
const S = o.getState().initialStateGlobal[t];
|
|
452
452
|
o.getState().clearSelectedIndexesForState(t), T.clear(), N++;
|
|
453
|
-
const W = s(
|
|
454
|
-
z && localStorage.removeItem(z), It(t, W), nt(t,
|
|
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), It(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
460
|
updateInitialState: (I) => {
|
|
461
461
|
T.clear(), N++;
|
|
462
462
|
const r = Tt(
|
|
463
463
|
t,
|
|
464
|
-
|
|
464
|
+
i,
|
|
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
469
|
Nt(t, I), o.getState().initializeShadowState(t, I), It(t, r), nt(t, I);
|
|
470
470
|
const z = o.getState().stateComponents.get(t);
|
|
@@ -483,7 +483,7 @@ function Tt(t, c, m, g) {
|
|
|
483
483
|
return !!(I && J(I, Lt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function s(I, r = [],
|
|
486
|
+
function s(I, r = [], S) {
|
|
487
487
|
const W = r.map(String).join(".");
|
|
488
488
|
T.get(W);
|
|
489
489
|
const j = function() {
|
|
@@ -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(I) && (S = { ...S, validIndices: void 0 });
|
|
503
503
|
const ut = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
@@ -529,13 +529,13 @@ function Tt(t, c, m, g) {
|
|
|
529
529
|
const n = e.components.get(d);
|
|
530
530
|
if (n && !n.paths.has("")) {
|
|
531
531
|
const a = r.join(".");
|
|
532
|
-
let
|
|
533
|
-
for (const
|
|
534
|
-
if (a.startsWith(
|
|
535
|
-
|
|
532
|
+
let c = !0;
|
|
533
|
+
for (const f of n.paths)
|
|
534
|
+
if (a.startsWith(f) && (a === f || a[f.length] === ".")) {
|
|
535
|
+
c = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
538
|
-
|
|
538
|
+
c && n.paths.add(a);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
@@ -551,20 +551,20 @@ function Tt(t, c, m, g) {
|
|
|
551
551
|
return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
|
|
552
552
|
const n = o.getState().getNestedState(t, []), a = d?.validation?.key;
|
|
553
553
|
try {
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
556
|
-
o.getState().removeValidationError(a),
|
|
554
|
+
const c = await e.action(n);
|
|
555
|
+
if (c && !c.success && c.errors && a) {
|
|
556
|
+
o.getState().removeValidationError(a), c.errors.forEach((u) => {
|
|
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
|
}
|
|
565
|
-
return
|
|
566
|
-
} catch (
|
|
567
|
-
return e.onError && e.onError(
|
|
565
|
+
return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
|
|
566
|
+
} catch (c) {
|
|
567
|
+
return e.onError && e.onError(c), { success: !1, error: c };
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
@@ -592,9 +592,9 @@ function Tt(t, c, m, g) {
|
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + r.join("."));
|
|
593
593
|
};
|
|
594
594
|
if (Array.isArray(I)) {
|
|
595
|
-
const d = () =>
|
|
595
|
+
const d = () => S?.validIndices ? I.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
|
|
@@ -606,7 +606,7 @@ function Tt(t, c, m, g) {
|
|
|
606
606
|
return s(
|
|
607
607
|
I[e],
|
|
608
608
|
[...r, e.toString()],
|
|
609
|
-
|
|
609
|
+
S
|
|
610
610
|
);
|
|
611
611
|
};
|
|
612
612
|
if (l === "clearSelected")
|
|
@@ -620,12 +620,12 @@ function Tt(t, c, m, g) {
|
|
|
620
620
|
const {
|
|
621
621
|
itemHeight: n = 50,
|
|
622
622
|
overscan: a = 6,
|
|
623
|
-
stickToBottom:
|
|
624
|
-
dependencies:
|
|
623
|
+
stickToBottom: c = !1,
|
|
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,22 +671,22 @@ 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");
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
|
-
x && C === "LOCKED_AT_BOTTOM" &&
|
|
680
|
+
x && C === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
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;
|
|
689
|
-
if (C === "IDLE_AT_TOP" &&
|
|
689
|
+
if (C === "IDLE_AT_TOP" && c && _ > 0)
|
|
690
690
|
console.log(
|
|
691
691
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
692
692
|
), A("GETTING_HEIGHTS");
|
|
@@ -798,34 +798,34 @@ 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
|
-
),
|
|
802
|
-
...
|
|
801
|
+
), c = 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(
|
|
807
|
+
return s(c, 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
|
-
),
|
|
814
|
-
...
|
|
813
|
+
), c = 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(
|
|
819
|
+
return s(c, 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[
|
|
824
|
+
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (c, f) => f)).map((c, f) => {
|
|
825
|
+
const u = n[c], E = [...r, c.toString()], y = s(u, E, S);
|
|
826
826
|
return e(u, y, {
|
|
827
827
|
register: () => {
|
|
828
|
-
const [, C] = K({}), A = `${m}-${r.join(".")}-${
|
|
828
|
+
const [, C] = K({}), A = `${m}-${r.join(".")}-${c}`;
|
|
829
829
|
ct(() => {
|
|
830
830
|
const b = `${t}////${A}`, F = o.getState().stateComponents.get(t) || {
|
|
831
831
|
components: /* @__PURE__ */ new Map()
|
|
@@ -839,8 +839,8 @@ function Tt(t, c, m, g) {
|
|
|
839
839
|
};
|
|
840
840
|
}, [t, A]);
|
|
841
841
|
},
|
|
842
|
-
index:
|
|
843
|
-
originalIndex:
|
|
842
|
+
index: f,
|
|
843
|
+
originalIndex: c
|
|
844
844
|
});
|
|
845
845
|
}) : (console.warn(
|
|
846
846
|
`stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
|
|
@@ -848,16 +848,16 @@ function Tt(t, c, m, g) {
|
|
|
848
848
|
), null);
|
|
849
849
|
};
|
|
850
850
|
if (l === "stateMapNoRender")
|
|
851
|
-
return (e) => I.map((a,
|
|
852
|
-
let
|
|
853
|
-
|
|
854
|
-
const u = [...r,
|
|
851
|
+
return (e) => I.map((a, c) => {
|
|
852
|
+
let f;
|
|
853
|
+
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
854
|
+
const u = [...r, f.toString()], E = s(a, u, S);
|
|
855
855
|
return e(
|
|
856
856
|
a,
|
|
857
857
|
E,
|
|
858
|
-
|
|
858
|
+
c,
|
|
859
859
|
I,
|
|
860
|
-
s(I, r,
|
|
860
|
+
s(I, r, S)
|
|
861
861
|
);
|
|
862
862
|
});
|
|
863
863
|
if (l === "$stateMap")
|
|
@@ -873,19 +873,19 @@ 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[
|
|
876
|
+
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (c, f) => f)).map((c, f) => {
|
|
877
|
+
const u = n[c], E = [...r, c.toString()], y = s(u, E, S), w = `${m}-${r.join(".")}-${c}`;
|
|
878
878
|
return lt(ae, {
|
|
879
|
-
key:
|
|
879
|
+
key: c,
|
|
880
880
|
stateKey: t,
|
|
881
881
|
itemComponentId: w,
|
|
882
882
|
itemPath: E,
|
|
883
883
|
children: e(
|
|
884
884
|
u,
|
|
885
885
|
y,
|
|
886
|
-
|
|
886
|
+
f,
|
|
887
887
|
n,
|
|
888
|
-
s(n, r,
|
|
888
|
+
s(n, r, S)
|
|
889
889
|
)
|
|
890
890
|
});
|
|
891
891
|
}) : (console.warn(
|
|
@@ -897,12 +897,12 @@ function Tt(t, c, m, g) {
|
|
|
897
897
|
const n = I;
|
|
898
898
|
T.clear(), N++;
|
|
899
899
|
const a = n.flatMap(
|
|
900
|
-
(
|
|
900
|
+
(c) => c[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")
|
|
@@ -914,40 +914,40 @@ function Tt(t, c, m, g) {
|
|
|
914
914
|
return () => {
|
|
915
915
|
const e = o.getState().getNestedState(t, r);
|
|
916
916
|
if (e.length === 0) return;
|
|
917
|
-
const n = e.length - 1, a = e[n],
|
|
918
|
-
return s(a,
|
|
917
|
+
const n = e.length - 1, a = e[n], c = [...r, n.toString()];
|
|
918
|
+
return s(a, c);
|
|
919
919
|
};
|
|
920
920
|
if (l === "insert")
|
|
921
|
-
return (e) => (p(r), Et(
|
|
921
|
+
return (e) => (p(r), Et(i, e, r, t), s(
|
|
922
922
|
o.getState().getNestedState(t, r),
|
|
923
923
|
r
|
|
924
924
|
));
|
|
925
925
|
if (l === "uniqueInsert")
|
|
926
926
|
return (e, n, a) => {
|
|
927
|
-
const
|
|
927
|
+
const c = o.getState().getNestedState(t, r), f = tt(e) ? e(c) : e;
|
|
928
928
|
let u = null;
|
|
929
|
-
if (!
|
|
929
|
+
if (!c.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(
|
|
939
|
+
p(r), Et(i, f, r, t);
|
|
940
940
|
else if (a && u) {
|
|
941
|
-
const y = a(u), w =
|
|
941
|
+
const y = a(u), w = c.map(
|
|
942
942
|
(C) => J(C, u) ? y : C
|
|
943
943
|
);
|
|
944
|
-
p(r), it(
|
|
944
|
+
p(r), it(i, w, r);
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
947
|
if (l === "cut")
|
|
948
948
|
return (e, n) => {
|
|
949
949
|
if (!n?.waitForSync)
|
|
950
|
-
return p(r), ht(
|
|
950
|
+
return p(r), ht(i, r, t, e), s(
|
|
951
951
|
o.getState().getNestedState(t, r),
|
|
952
952
|
r
|
|
953
953
|
);
|
|
@@ -955,30 +955,30 @@ function Tt(t, c, m, g) {
|
|
|
955
955
|
if (l === "cutByValue")
|
|
956
956
|
return (e) => {
|
|
957
957
|
for (let n = 0; n < I.length; n++)
|
|
958
|
-
I[n] === e && ht(
|
|
958
|
+
I[n] === e && ht(i, r, t, n);
|
|
959
959
|
};
|
|
960
960
|
if (l === "toggleByValue")
|
|
961
961
|
return (e) => {
|
|
962
962
|
const n = I.findIndex((a) => a === e);
|
|
963
|
-
n > -1 ? ht(
|
|
963
|
+
n > -1 ? ht(i, r, t, n) : Et(i, 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
|
-
const
|
|
972
|
-
return s(a.item,
|
|
971
|
+
const c = [...r, a.originalIndex.toString()];
|
|
972
|
+
return s(a.item, c, S);
|
|
973
973
|
};
|
|
974
974
|
if (l === "findWith")
|
|
975
975
|
return (e, n) => {
|
|
976
|
-
const
|
|
976
|
+
const c = d().find(
|
|
977
977
|
({ item: u }) => u[e] === n
|
|
978
978
|
);
|
|
979
|
-
if (!
|
|
980
|
-
const
|
|
981
|
-
return s(
|
|
979
|
+
if (!c) return;
|
|
980
|
+
const f = [...r, c.originalIndex.toString()];
|
|
981
|
+
return s(c.item, f, S);
|
|
982
982
|
};
|
|
983
983
|
}
|
|
984
984
|
const et = r[r.length - 1];
|
|
@@ -986,7 +986,7 @@ function Tt(t, c, m, g) {
|
|
|
986
986
|
const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
987
987
|
if (Array.isArray(e) && l === "cut")
|
|
988
988
|
return () => ht(
|
|
989
|
-
|
|
989
|
+
i,
|
|
990
990
|
d,
|
|
991
991
|
t,
|
|
992
992
|
Number(et)
|
|
@@ -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(I)) {
|
|
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
|
};
|
|
@@ -1025,8 +1025,8 @@ function Tt(t, c, m, g) {
|
|
|
1025
1025
|
return (d) => {
|
|
1026
1026
|
const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
|
|
1027
1027
|
d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
|
|
1028
|
-
const
|
|
1029
|
-
it(
|
|
1028
|
+
const c = o.getState().getNestedState(t, [...e]);
|
|
1029
|
+
it(i, c, e), p(e);
|
|
1030
1030
|
};
|
|
1031
1031
|
if (l === "toggleSelected")
|
|
1032
1032
|
return () => {
|
|
@@ -1036,8 +1036,8 @@ function Tt(t, c, m, g) {
|
|
|
1036
1036
|
n,
|
|
1037
1037
|
a === e ? void 0 : e
|
|
1038
1038
|
);
|
|
1039
|
-
const
|
|
1040
|
-
it(
|
|
1039
|
+
const c = o.getState().getNestedState(t, [...d]);
|
|
1040
|
+
it(i, c, d), p(d);
|
|
1041
1041
|
};
|
|
1042
1042
|
if (r.length == 0) {
|
|
1043
1043
|
if (l === "addValidation")
|
|
@@ -1057,17 +1057,17 @@ function Tt(t, c, m, g) {
|
|
|
1057
1057
|
t,
|
|
1058
1058
|
o.getState().initialStateGlobal[t],
|
|
1059
1059
|
a,
|
|
1060
|
-
|
|
1060
|
+
i,
|
|
1061
1061
|
m,
|
|
1062
1062
|
g
|
|
1063
1063
|
);
|
|
1064
|
-
const
|
|
1065
|
-
if (
|
|
1066
|
-
const
|
|
1064
|
+
const c = o.getState().stateComponents.get(t);
|
|
1065
|
+
if (c) {
|
|
1066
|
+
const f = _t(e, a), u = new Set(f);
|
|
1067
1067
|
for (const [
|
|
1068
1068
|
E,
|
|
1069
1069
|
y
|
|
1070
|
-
] of
|
|
1070
|
+
] of c.components.entries()) {
|
|
1071
1071
|
let w = !1;
|
|
1072
1072
|
const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
1073
1073
|
if (!C.includes("none")) {
|
|
@@ -1129,11 +1129,11 @@ 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
|
-
const
|
|
1136
|
-
return
|
|
1135
|
+
const c = d.zodSchema.safeParse(n);
|
|
1136
|
+
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1137
1137
|
const E = u.path, y = u.message, w = [d.key, ...E].join(".");
|
|
1138
1138
|
e(w, y);
|
|
1139
1139
|
}), dt(t), !1);
|
|
@@ -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
|
);
|
|
@@ -1181,12 +1181,12 @@ function Tt(t, c, m, g) {
|
|
|
1181
1181
|
return (d, e) => {
|
|
1182
1182
|
if (e?.debounce)
|
|
1183
1183
|
Wt(() => {
|
|
1184
|
-
it(
|
|
1184
|
+
it(i, d, r, "");
|
|
1185
1185
|
const n = o.getState().getNestedState(t, r);
|
|
1186
1186
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1187
1187
|
}, e.debounce);
|
|
1188
1188
|
else {
|
|
1189
|
-
it(
|
|
1189
|
+
it(i, d, r, "");
|
|
1190
1190
|
const n = o.getState().getNestedState(t, r);
|
|
1191
1191
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1192
1192
|
}
|
|
@@ -1196,7 +1196,7 @@ function Tt(t, c, m, g) {
|
|
|
1196
1196
|
return (d, e) => /* @__PURE__ */ Ot(
|
|
1197
1197
|
qt,
|
|
1198
1198
|
{
|
|
1199
|
-
setState:
|
|
1199
|
+
setState: i,
|
|
1200
1200
|
stateKey: t,
|
|
1201
1201
|
path: r,
|
|
1202
1202
|
child: d,
|
|
@@ -1204,7 +1204,7 @@ 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
1210
|
return T.set(W, {
|
|
@@ -1221,10 +1221,10 @@ function Vt(t) {
|
|
|
1221
1221
|
}
|
|
1222
1222
|
function re({
|
|
1223
1223
|
proxy: t,
|
|
1224
|
-
rebuildStateShape:
|
|
1224
|
+
rebuildStateShape: i
|
|
1225
1225
|
}) {
|
|
1226
1226
|
const m = o().getNestedState(t._stateKey, t._path);
|
|
1227
|
-
return Array.isArray(m) ?
|
|
1227
|
+
return Array.isArray(m) ? i(
|
|
1228
1228
|
m,
|
|
1229
1229
|
t._path
|
|
1230
1230
|
).stateMapNoRender(
|
|
@@ -1234,9 +1234,9 @@ function re({
|
|
|
1234
1234
|
function oe({
|
|
1235
1235
|
proxy: t
|
|
1236
1236
|
}) {
|
|
1237
|
-
const
|
|
1237
|
+
const i = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1238
1238
|
return ot(() => {
|
|
1239
|
-
const g =
|
|
1239
|
+
const g = i.current;
|
|
1240
1240
|
if (!g || !g.parentElement) return;
|
|
1241
1241
|
const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
|
|
1242
1242
|
let v = T.getAttribute("data-parent-id");
|
|
@@ -1249,29 +1249,29 @@ function oe({
|
|
|
1249
1249
|
};
|
|
1250
1250
|
o.getState().addSignalElement(m, I);
|
|
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
|
-
ref:
|
|
1268
|
+
ref: i,
|
|
1269
1269
|
style: { display: "none" },
|
|
1270
1270
|
"data-signal-id": m
|
|
1271
1271
|
});
|
|
1272
1272
|
}
|
|
1273
1273
|
function pe(t) {
|
|
1274
|
-
const
|
|
1274
|
+
const i = Ht(
|
|
1275
1275
|
(m) => {
|
|
1276
1276
|
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1277
1277
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1283,11 +1283,11 @@ function pe(t) {
|
|
|
1283
1283
|
},
|
|
1284
1284
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1285
1285
|
);
|
|
1286
|
-
return lt("text", {}, String(
|
|
1286
|
+
return lt("text", {}, String(i));
|
|
1287
1287
|
}
|
|
1288
1288
|
function ae({
|
|
1289
1289
|
stateKey: t,
|
|
1290
|
-
itemComponentId:
|
|
1290
|
+
itemComponentId: i,
|
|
1291
1291
|
itemPath: m,
|
|
1292
1292
|
children: g
|
|
1293
1293
|
}) {
|
|
@@ -1299,7 +1299,7 @@ function ae({
|
|
|
1299
1299
|
}
|
|
1300
1300
|
}));
|
|
1301
1301
|
}, [p.height, t, m]), ct(() => {
|
|
1302
|
-
const s = `${t}////${
|
|
1302
|
+
const s = `${t}////${i}`, I = o.getState().stateComponents.get(t) || {
|
|
1303
1303
|
components: /* @__PURE__ */ new Map()
|
|
1304
1304
|
};
|
|
1305
1305
|
return I.components.set(s, {
|
|
@@ -1309,7 +1309,7 @@ function ae({
|
|
|
1309
1309
|
const r = o.getState().stateComponents.get(t);
|
|
1310
1310
|
r && r.components.delete(s);
|
|
1311
1311
|
};
|
|
1312
|
-
}, [t,
|
|
1312
|
+
}, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
|
|
1313
1313
|
}
|
|
1314
1314
|
export {
|
|
1315
1315
|
Vt as $cogsSignal,
|