cogsbox-state 0.5.404 → 0.5.406
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 +364 -302
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +104 -18
package/dist/CogsState.jsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
2
|
+
import { jsx as It } from "react/jsx-runtime";
|
|
3
|
+
import { useState as nt, useRef as X, useEffect as rt, useLayoutEffect as kt, useMemo as wt, createElement as ut, useSyncExternalStore as Ut, startTransition as jt, useCallback as bt } from "react";
|
|
4
|
+
import { transformStateFunc as Ot, isDeepEqual as q, isFunction as K, getNestedValue as Y, getDifferences as Tt, debounce as Ft } from "./utility.js";
|
|
5
|
+
import { pushFunc as yt, updateFn as dt, cutFunc as mt, ValidationWrapper as Dt, FormControlComponent as Wt } from "./Functions.jsx";
|
|
6
6
|
import Lt from "superjson";
|
|
7
7
|
import { v4 as Et } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
9
|
+
import { getGlobalStore as o, formRefStore as $t } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as Gt } from "fast-json-patch";
|
|
12
12
|
import Bt from "react-use-measure";
|
|
@@ -22,20 +22,20 @@ function Vt({
|
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: S
|
|
24
24
|
}) {
|
|
25
|
-
const g = at(t) || {}, y = S[t] || {},
|
|
25
|
+
const g = at(t) || {}, y = S[t] || {}, x = o.getState().setInitialStateOptions, w = { ...y, ...g };
|
|
26
26
|
let I = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const s in c)
|
|
29
29
|
w.hasOwnProperty(s) ? (s == "localStorage" && c[s] && w[s].key !== c[s]?.key && (I = !0, w[s] = c[s]), s == "initialState" && c[s] && w[s] !== c[s] && // Different references
|
|
30
30
|
!q(w[s], c[s]) && (I = !0, w[s] = c[s])) : (I = !0, w[s] = c[s]);
|
|
31
|
-
I &&
|
|
31
|
+
I && x(t, w);
|
|
32
32
|
}
|
|
33
33
|
function ue(t, { formElements: c, validation: S }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: S };
|
|
35
35
|
}
|
|
36
36
|
const ge = (t, c) => {
|
|
37
37
|
let S = t;
|
|
38
|
-
const [g, y] =
|
|
38
|
+
const [g, y] = Ot(S);
|
|
39
39
|
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
|
|
40
40
|
y[I] = y[I] || {}, y[I].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
@@ -45,14 +45,14 @@ const ge = (t, c) => {
|
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, at(I) || o.getState().setInitialStateOptions(I, y[I]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
|
-
const
|
|
49
|
-
const [h] =
|
|
48
|
+
const x = (I, s) => {
|
|
49
|
+
const [h] = nt(s?.componentId ?? Et());
|
|
50
50
|
Vt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const r = o.getState().cogsStateStore[I] || g[I], f = s?.modifyState ? s.modifyState(r) : r, [
|
|
55
|
+
const r = o.getState().cogsStateStore[I] || g[I], f = s?.modifyState ? s.modifyState(r) : r, [H, O] = Zt(
|
|
56
56
|
f,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
@@ -68,36 +68,36 @@ const ge = (t, c) => {
|
|
|
68
68
|
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return O;
|
|
72
72
|
};
|
|
73
73
|
function w(I, s) {
|
|
74
|
-
Vt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage &&
|
|
74
|
+
Vt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && qt(I, s), gt(I);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: x, setCogsOptions: w };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
78
|
+
setUpdaterState: ht,
|
|
79
|
+
setState: ot,
|
|
80
80
|
getInitialOptions: at,
|
|
81
81
|
getKeyState: _t,
|
|
82
82
|
getValidationErrors: Ht,
|
|
83
83
|
setStateLog: zt,
|
|
84
|
-
updateInitialStateGlobal:
|
|
84
|
+
updateInitialStateGlobal: At,
|
|
85
85
|
addValidationError: Mt,
|
|
86
86
|
removeValidationError: Z,
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
87
|
+
setServerSyncActions: Jt
|
|
88
|
+
} = o.getState(), Ct = (t, c, S, g, y) => {
|
|
89
89
|
S?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
92
92
|
S.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const w = `${g}-${c}-${
|
|
95
|
+
const x = K(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
|
|
96
|
+
if (x && g) {
|
|
97
|
+
const w = `${g}-${c}-${x}`;
|
|
98
98
|
let I;
|
|
99
99
|
try {
|
|
100
|
-
I =
|
|
100
|
+
I = pt(w)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const s = {
|
|
@@ -110,7 +110,7 @@ const ge = (t, c) => {
|
|
|
110
110
|
JSON.stringify(h.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, pt = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
116
|
const c = window.localStorage.getItem(t);
|
|
@@ -118,29 +118,29 @@ const ge = (t, c) => {
|
|
|
118
118
|
} catch (c) {
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
121
|
+
}, qt = (t, c) => {
|
|
122
122
|
const S = o.getState().cogsStateStore[t], { sessionId: g } = Pt(), y = K(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
|
|
123
123
|
if (y && g) {
|
|
124
|
-
const
|
|
124
|
+
const x = pt(
|
|
125
125
|
`${g}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if (x && x.lastUpdated > (x.lastSyncedWithServer || 0))
|
|
128
|
+
return ot(t, x.state), gt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Rt = (t, c, S, g, y, x) => {
|
|
132
132
|
const w = {
|
|
133
133
|
initialState: c,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: vt(
|
|
135
135
|
t,
|
|
136
136
|
g,
|
|
137
137
|
y,
|
|
138
|
-
|
|
138
|
+
x
|
|
139
139
|
),
|
|
140
140
|
state: S
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
At(t, w.initialState), ht(t, w.updaterState), ot(t, w.state);
|
|
143
|
+
}, gt = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
146
|
const S = /* @__PURE__ */ new Set();
|
|
@@ -161,18 +161,18 @@ const ge = (t, c) => {
|
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: Y(c, g),
|
|
165
|
+
newValue: Y(S, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: Y(S, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: Y(c, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -185,7 +185,7 @@ function Zt(t, {
|
|
|
185
185
|
serverSync: S,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: y,
|
|
188
|
-
reactiveDeps:
|
|
188
|
+
reactiveDeps: x,
|
|
189
189
|
reactiveType: w,
|
|
190
190
|
componentId: I,
|
|
191
191
|
initialState: s,
|
|
@@ -193,14 +193,14 @@ function Zt(t, {
|
|
|
193
193
|
dependencies: r,
|
|
194
194
|
serverState: f
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [m] =
|
|
196
|
+
const [H, O] = nt({}), { sessionId: F } = Pt();
|
|
197
|
+
let z = !c;
|
|
198
|
+
const [m] = nt(c ?? Et()), l = o.getState().stateLog[m], ft = X(/* @__PURE__ */ new Set()), tt = X(I ?? Et()), R = X(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
R.current = at(m) ?? null, rt(() => {
|
|
202
202
|
if (h && h.stateKey === m && h.path?.[0]) {
|
|
203
|
-
|
|
203
|
+
ot(m, (n) => ({
|
|
204
204
|
...n,
|
|
205
205
|
[h.path[0]]: h.newValue
|
|
206
206
|
}));
|
|
@@ -210,157 +210,157 @@ function Zt(t, {
|
|
|
210
210
|
userId: h.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [h]),
|
|
213
|
+
}, [h]), rt(() => {
|
|
214
214
|
if (s) {
|
|
215
215
|
xt(m, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
218
|
+
const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[m];
|
|
219
219
|
if (!(i && !q(i, s) || !i) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const p = K(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
|
-
p && F && (u =
|
|
224
|
-
let T = s,
|
|
225
|
-
const _ = a ? Date.now() : 0,
|
|
226
|
-
a && _ >
|
|
223
|
+
p && F && (u = pt(`${F}-${m}-${p}`));
|
|
224
|
+
let T = s, b = !1;
|
|
225
|
+
const _ = a ? Date.now() : 0, N = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
|
|
226
|
+
a && _ > N ? (T = e.serverState.data, b = !0) : u && N > M && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(m, s), Rt(
|
|
227
227
|
m,
|
|
228
228
|
s,
|
|
229
229
|
T,
|
|
230
230
|
st,
|
|
231
231
|
tt.current,
|
|
232
232
|
F
|
|
233
|
-
),
|
|
233
|
+
), b && p && F && Ct(T, m, e, F, Date.now()), gt(m), (Array.isArray(w) ? w : [w || "component"]).includes("none") || O({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
237
|
f?.status,
|
|
238
238
|
f?.data,
|
|
239
239
|
...r || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
240
|
+
]), kt(() => {
|
|
241
|
+
z && xt(m, {
|
|
242
242
|
serverSync: S,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: s,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: R.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const e = `${m}////${tt.current}`, n = o.getState().stateComponents.get(m) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return n.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => O({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: x || void 0,
|
|
256
256
|
reactiveType: w ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(m, n),
|
|
257
|
+
}), o.getState().stateComponents.set(m, n), O({}), () => {
|
|
258
258
|
n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(m));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const st = (e, n, a, i) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
263
263
|
const u = `${m}-${n.join(".")}`;
|
|
264
|
-
|
|
264
|
+
ft.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const v = o.getState();
|
|
267
|
-
|
|
267
|
+
ot(m, (u) => {
|
|
268
268
|
const p = K(e) ? e(u) : e, T = `${m}-${n.join(".")}`;
|
|
269
269
|
if (T) {
|
|
270
270
|
let k = !1, V = v.signalDomElements.get(T);
|
|
271
271
|
if ((!V || V.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const
|
|
272
|
+
const C = n.slice(0, -1), L = Y(p, C);
|
|
273
273
|
if (Array.isArray(L)) {
|
|
274
274
|
k = !0;
|
|
275
|
-
const
|
|
276
|
-
V = v.signalDomElements.get(
|
|
275
|
+
const A = `${m}-${C.join(".")}`;
|
|
276
|
+
V = v.signalDomElements.get(A);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if (V) {
|
|
280
|
-
const
|
|
281
|
-
V.forEach(({ parentId: L, position:
|
|
282
|
-
const
|
|
280
|
+
const C = k ? Y(p, n.slice(0, -1)) : Y(p, n);
|
|
281
|
+
V.forEach(({ parentId: L, position: A, effect: D }) => {
|
|
282
|
+
const U = document.querySelector(
|
|
283
283
|
`[data-parent-id="${L}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (U) {
|
|
286
|
+
const $ = Array.from(U.childNodes);
|
|
287
|
+
if ($[A]) {
|
|
288
|
+
const E = D ? new Function("state", `return (${D})(state)`)(C) : C;
|
|
289
|
+
$[A].textContent = String(E);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", v.shadowStateStore), a.updateType === "update" && (i ||
|
|
296
|
-
(i ||
|
|
295
|
+
console.log("shadowState", v.shadowStateStore), a.updateType === "update" && (i || R.current?.validation?.key) && n && Z(
|
|
296
|
+
(i || R.current?.validation?.key) + "." + n.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([V,
|
|
298
|
+
const b = n.slice(0, n.length - 1);
|
|
299
|
+
a.updateType === "cut" && R.current?.validation?.key && Z(
|
|
300
|
+
R.current?.validation?.key + "." + b.join(".")
|
|
301
|
+
), a.updateType === "insert" && R.current?.validation?.key && Ht(
|
|
302
|
+
R.current?.validation?.key + "." + b.join(".")
|
|
303
|
+
).filter(([V, C]) => {
|
|
304
304
|
let L = V?.split(".").length;
|
|
305
|
-
if (V ==
|
|
306
|
-
let
|
|
307
|
-
Z(V), Mt(
|
|
305
|
+
if (V == b.join(".") && L == b.length - 1) {
|
|
306
|
+
let A = V + "." + b;
|
|
307
|
+
Z(V), Mt(A, C);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
const _ = v.stateComponents.get(m);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
|
|
312
|
-
const k = Tt(u, p), V = new Set(k),
|
|
312
|
+
const k = Tt(u, p), V = new Set(k), C = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
L,
|
|
315
|
-
|
|
315
|
+
A
|
|
316
316
|
] of _.components.entries()) {
|
|
317
317
|
let D = !1;
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
318
|
+
const U = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", A), !U.includes("none")) {
|
|
320
|
+
if (U.includes("all")) {
|
|
321
|
+
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (U.includes("component") && ((A.paths.has(C) || A.paths.has("")) && (D = !0), !D))
|
|
325
|
+
for (const $ of V) {
|
|
326
|
+
let E = $;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
328
|
+
if (A.paths.has(E)) {
|
|
329
329
|
D = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const W =
|
|
332
|
+
const W = E.lastIndexOf(".");
|
|
333
333
|
if (W !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const j = E.substring(
|
|
335
335
|
0,
|
|
336
336
|
W
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
339
|
+
Number(E.substring(W + 1))
|
|
340
|
+
) && A.paths.has(j)) {
|
|
341
341
|
D = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
E = j;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
E = "";
|
|
347
|
+
if (E === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
if (D) break;
|
|
351
351
|
}
|
|
352
|
-
if (!D &&
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!D && U.includes("deps") && A.depsFunction) {
|
|
353
|
+
const $ = A.depsFunction(p);
|
|
354
|
+
let E = !1;
|
|
355
|
+
typeof $ == "boolean" ? $ && (E = !0) : q(A.deps, $) || (A.deps = $, E = !0), E && (D = !0);
|
|
356
356
|
}
|
|
357
|
-
D &&
|
|
357
|
+
D && A.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
361
|
+
const N = Date.now();
|
|
362
362
|
n = n.map((k, V) => {
|
|
363
|
-
const
|
|
363
|
+
const C = n.slice(0, -1), L = Y(p, C);
|
|
364
364
|
return V === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (L.length - 1).toString() : k;
|
|
365
365
|
});
|
|
366
366
|
const { oldValue: M, newValue: P } = Yt(
|
|
@@ -368,8 +368,8 @@ function Zt(t, {
|
|
|
368
368
|
u,
|
|
369
369
|
p,
|
|
370
370
|
n
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), J = {
|
|
372
|
+
timeStamp: N,
|
|
373
373
|
stateKey: m,
|
|
374
374
|
path: n,
|
|
375
375
|
updateType: a.updateType,
|
|
@@ -386,27 +386,27 @@ function Zt(t, {
|
|
|
386
386
|
v.insertShadowArrayElement(m, k, P);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const V = n.slice(0, -1),
|
|
390
|
-
v.removeShadowArrayElement(m, V,
|
|
389
|
+
const V = n.slice(0, -1), C = parseInt(n[n.length - 1]);
|
|
390
|
+
v.removeShadowArrayElement(m, V, C);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
if (zt(m, (k) => {
|
|
394
|
-
const
|
|
395
|
-
const D = `${
|
|
396
|
-
return
|
|
394
|
+
const C = [...k ?? [], J].reduce((L, A) => {
|
|
395
|
+
const D = `${A.stateKey}:${JSON.stringify(A.path)}`, U = L.get(D);
|
|
396
|
+
return U ? (U.timeStamp = Math.max(U.timeStamp, A.timeStamp), U.newValue = A.newValue, U.oldValue = U.oldValue ?? A.oldValue, U.updateType = A.updateType) : L.set(D, { ...A }), L;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(C.values());
|
|
399
|
+
}), Ct(
|
|
400
400
|
p,
|
|
401
401
|
m,
|
|
402
|
-
|
|
402
|
+
R.current,
|
|
403
403
|
F
|
|
404
|
-
),
|
|
404
|
+
), R.current?.middleware && R.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
407
|
-
}),
|
|
408
|
-
const k = v.serverState[m], V =
|
|
409
|
-
|
|
406
|
+
update: J
|
|
407
|
+
}), R.current?.serverSync) {
|
|
408
|
+
const k = v.serverState[m], V = R.current?.serverSync;
|
|
409
|
+
Jt(m, {
|
|
410
410
|
syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: p }),
|
|
411
411
|
rollBackState: k,
|
|
412
412
|
actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
|
|
@@ -416,16 +416,16 @@ function Zt(t, {
|
|
|
416
416
|
return p;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[m] || (
|
|
419
|
+
o.getState().updaterState[m] || (ht(
|
|
420
420
|
m,
|
|
421
|
-
|
|
421
|
+
vt(
|
|
422
422
|
m,
|
|
423
423
|
st,
|
|
424
424
|
tt.current,
|
|
425
425
|
F
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[m] ||
|
|
428
|
-
const d = wt(() =>
|
|
427
|
+
), o.getState().cogsStateStore[m] || ot(m, t), o.getState().initialStateGlobal[m] || At(m, t));
|
|
428
|
+
const d = wt(() => vt(
|
|
429
429
|
m,
|
|
430
430
|
st,
|
|
431
431
|
tt.current,
|
|
@@ -433,14 +433,14 @@ function Zt(t, {
|
|
|
433
433
|
), [m, F]);
|
|
434
434
|
return [_t(m), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function vt(t, c, S, g) {
|
|
437
437
|
const y = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
438
|
+
let x = 0;
|
|
439
439
|
const w = (h) => {
|
|
440
440
|
const r = h.join(".");
|
|
441
441
|
for (const [f] of y)
|
|
442
442
|
(f === r || f.startsWith(r + ".")) && y.delete(f);
|
|
443
|
-
|
|
443
|
+
x++;
|
|
444
444
|
}, I = {
|
|
445
445
|
removeValidation: (h) => {
|
|
446
446
|
h?.validationKey && Z(h.validationKey);
|
|
@@ -449,30 +449,30 @@ function mt(t, c, S, g) {
|
|
|
449
449
|
const r = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
r?.key && Z(r?.key), h?.validationKey && Z(h.validationKey);
|
|
451
451
|
const f = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), x++;
|
|
453
|
+
const H = s(f, []), O = at(t), F = K(O?.localStorage?.key) ? O?.localStorage?.key(f) : O?.localStorage?.key, z = `${g}-${t}-${F}`;
|
|
454
|
+
z && localStorage.removeItem(z), ht(t, H), ot(t, f);
|
|
455
455
|
const m = o.getState().stateComponents.get(t);
|
|
456
456
|
return m && m.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), f;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (h) => {
|
|
461
|
-
y.clear(),
|
|
462
|
-
const r =
|
|
461
|
+
y.clear(), x++;
|
|
462
|
+
const r = vt(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
S,
|
|
466
466
|
g
|
|
467
|
-
), f = o.getState().initialStateGlobal[t],
|
|
468
|
-
return localStorage.getItem(F) && localStorage.removeItem(F),
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), f = o.getState().initialStateGlobal[t], H = at(t), O = K(H?.localStorage?.key) ? H?.localStorage?.key(f) : H?.localStorage?.key, F = `${g}-${t}-${O}`;
|
|
468
|
+
return localStorage.getItem(F) && localStorage.removeItem(F), jt(() => {
|
|
469
|
+
At(t, h), o.getState().initializeShadowState(t, h), ht(t, r), ot(t, h);
|
|
470
|
+
const z = o.getState().stateComponents.get(t);
|
|
471
|
+
z && z.components.forEach((m) => {
|
|
472
472
|
m.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (z) => r.get()[z]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
@@ -484,23 +484,23 @@ function mt(t, c, S, g) {
|
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function s(h, r = [], f) {
|
|
487
|
-
const
|
|
488
|
-
y.get(
|
|
489
|
-
const
|
|
487
|
+
const H = r.map(String).join(".");
|
|
488
|
+
y.get(H);
|
|
489
|
+
const O = function() {
|
|
490
490
|
return o().getNestedState(t, r);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(I).forEach((m) => {
|
|
493
|
-
|
|
493
|
+
O[m] = I[m];
|
|
494
494
|
});
|
|
495
495
|
const F = {
|
|
496
|
-
apply(m, l,
|
|
496
|
+
apply(m, l, ft) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${r.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
|
|
500
500
|
},
|
|
501
501
|
get(m, l) {
|
|
502
502
|
f?.validIndices && !Array.isArray(h) && (f = { ...f, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const ft = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function mt(t, c, S, g) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ft.has(l)) {
|
|
527
527
|
const d = `${t}////${S}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const n = e.components.get(d);
|
|
@@ -568,7 +568,7 @@ function mt(t, c, S, g) {
|
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n =
|
|
571
|
+
const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Y(e, r);
|
|
572
572
|
return q(d, n) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
@@ -576,7 +576,7 @@ function mt(t, c, S, g) {
|
|
|
576
576
|
const d = o().getNestedState(
|
|
577
577
|
t,
|
|
578
578
|
r
|
|
579
|
-
), e = o.getState().initialStateGlobal[t], n =
|
|
579
|
+
), e = o.getState().initialStateGlobal[t], n = Y(e, r);
|
|
580
580
|
return q(d, n) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
@@ -622,112 +622,170 @@ function mt(t, c, S, g) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: i = !1,
|
|
624
624
|
dependencies: v = []
|
|
625
|
-
} = e
|
|
625
|
+
} = e;
|
|
626
|
+
console.log("useVirtualView initialized with:", {
|
|
627
|
+
itemHeight: n,
|
|
628
|
+
overscan: a,
|
|
629
|
+
stickToBottom: i
|
|
630
|
+
});
|
|
631
|
+
const u = X(null), [p, T] = nt({
|
|
626
632
|
startIndex: 0,
|
|
627
633
|
endIndex: 10
|
|
628
|
-
}), [
|
|
634
|
+
}), [b, _] = nt(0), N = X(!1), M = X(!0), P = X(
|
|
629
635
|
null
|
|
630
636
|
);
|
|
631
|
-
|
|
632
|
-
_((
|
|
633
|
-
}), [t]);
|
|
634
|
-
const
|
|
637
|
+
rt(() => (console.log("Setting up shadow state subscription"), o.getState().subscribeToShadowState(t, () => {
|
|
638
|
+
console.log("Shadow state updated"), _((E) => E + 1);
|
|
639
|
+
})), [t]);
|
|
640
|
+
const J = o().getNestedState(
|
|
635
641
|
t,
|
|
636
642
|
r
|
|
637
|
-
), k =
|
|
638
|
-
|
|
639
|
-
|
|
643
|
+
), k = J.length;
|
|
644
|
+
console.log("Source array length:", k);
|
|
645
|
+
const { totalHeight: V, positions: C } = wt(() => {
|
|
646
|
+
console.log("Recalculating heights and positions");
|
|
647
|
+
const $ = o.getState().getShadowMetadata(t, r) || [];
|
|
648
|
+
let E = 0;
|
|
640
649
|
const W = [];
|
|
641
|
-
for (let
|
|
642
|
-
W[
|
|
643
|
-
const Q =
|
|
644
|
-
|
|
650
|
+
for (let j = 0; j < k; j++) {
|
|
651
|
+
W[j] = E;
|
|
652
|
+
const Q = $[j]?.virtualizer?.itemHeight;
|
|
653
|
+
E += Q || n;
|
|
645
654
|
}
|
|
646
|
-
return { totalHeight:
|
|
655
|
+
return console.log("Total height calculated:", E), { totalHeight: E, positions: W };
|
|
647
656
|
}, [
|
|
648
657
|
k,
|
|
649
658
|
t,
|
|
650
659
|
r.join("."),
|
|
651
660
|
n,
|
|
652
|
-
|
|
661
|
+
b
|
|
653
662
|
]), L = wt(() => {
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
663
|
+
const $ = Math.max(0, p.startIndex), E = Math.min(k, p.endIndex);
|
|
664
|
+
console.log("Creating virtual state for range:", {
|
|
665
|
+
start: $,
|
|
666
|
+
end: E
|
|
667
|
+
});
|
|
668
|
+
const W = Array.from(
|
|
669
|
+
{ length: E - $ },
|
|
670
|
+
(Q, G) => $ + G
|
|
671
|
+
), j = W.map((Q) => J[Q]);
|
|
672
|
+
return s(j, r, {
|
|
659
673
|
...f,
|
|
660
674
|
validIndices: W
|
|
661
675
|
});
|
|
662
|
-
}, [p.startIndex, p.endIndex,
|
|
663
|
-
|
|
664
|
-
if (
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
676
|
+
}, [p.startIndex, p.endIndex, J, k]);
|
|
677
|
+
rt(() => {
|
|
678
|
+
if (console.log("Auto-scroll effect triggered:", {
|
|
679
|
+
stickToBottom: i,
|
|
680
|
+
hasContainer: !!u.current,
|
|
681
|
+
totalCount: k,
|
|
682
|
+
shouldStickToBottom: M.current,
|
|
683
|
+
range: p
|
|
684
|
+
}), !i) {
|
|
685
|
+
console.log("Stick to bottom is false, skipping");
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (!u.current) {
|
|
689
|
+
console.log("No container ref, skipping");
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (k === 0) {
|
|
693
|
+
console.log("No items, skipping");
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
if (!M.current) {
|
|
678
697
|
console.log(
|
|
679
|
-
|
|
680
|
-
)
|
|
681
|
-
|
|
682
|
-
|
|
698
|
+
"Should not stick to bottom (user scrolled), skipping"
|
|
699
|
+
);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
console.log("Proceeding with auto-scroll logic"), P.current && (console.log("Clearing existing scroll interval"), clearInterval(P.current));
|
|
703
|
+
const $ = 50, E = p.endIndex < $, W = k > p.endIndex + $;
|
|
704
|
+
if (console.log("Jump check:", {
|
|
705
|
+
isInitialLoad: E,
|
|
706
|
+
isBigJump: W,
|
|
707
|
+
totalCount: k,
|
|
708
|
+
currentEndIndex: p.endIndex
|
|
709
|
+
}), E || W) {
|
|
710
|
+
const G = {
|
|
711
|
+
startIndex: Math.max(0, k - 20),
|
|
712
|
+
endIndex: k
|
|
713
|
+
};
|
|
714
|
+
console.log("Jumping to end range:", G), T(G);
|
|
715
|
+
}
|
|
716
|
+
let j = 0;
|
|
717
|
+
const Q = 50;
|
|
718
|
+
return console.log("Starting scroll-to-bottom interval"), P.current = setInterval(() => {
|
|
719
|
+
const G = u.current;
|
|
720
|
+
if (!G) {
|
|
721
|
+
console.log("Container lost during interval");
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
j++;
|
|
725
|
+
const { scrollTop: it, scrollHeight: et, clientHeight: ct } = G, St = it + ct, lt = et, B = lt - St < 5;
|
|
726
|
+
console.log(`Scroll attempt ${j}:`, {
|
|
727
|
+
currentBottom: St,
|
|
728
|
+
actualBottom: lt,
|
|
729
|
+
isAtBottom: B,
|
|
730
|
+
scrollTop: it,
|
|
731
|
+
scrollHeight: et,
|
|
732
|
+
clientHeight: ct
|
|
733
|
+
}), B || j >= Q ? (console.log(
|
|
734
|
+
B ? "Successfully reached bottom!" : "Timeout - giving up"
|
|
735
|
+
), clearInterval(P.current), P.current = null) : (console.log("Scrolling to", G.scrollHeight), G.scrollTop = G.scrollHeight);
|
|
683
736
|
}, 100), () => {
|
|
684
|
-
P.current && (clearInterval(P.current), P.current = null);
|
|
737
|
+
console.log("Cleaning up scroll interval"), P.current && (clearInterval(P.current), P.current = null);
|
|
685
738
|
};
|
|
686
|
-
}, [k, i]),
|
|
687
|
-
const
|
|
688
|
-
if (
|
|
689
|
-
|
|
739
|
+
}, [k, i, p.startIndex, p.endIndex]), rt(() => {
|
|
740
|
+
const $ = u.current;
|
|
741
|
+
if (!$) {
|
|
742
|
+
console.log("No container for scroll handler");
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
console.log("Setting up scroll handler");
|
|
746
|
+
let E;
|
|
690
747
|
const W = () => {
|
|
691
|
-
P.current && (clearInterval(P.current), P.current = null);
|
|
692
|
-
const { scrollTop:
|
|
693
|
-
M.current =
|
|
694
|
-
|
|
748
|
+
P.current && (console.log("User scrolled - stopping auto-scroll"), clearInterval(P.current), P.current = null);
|
|
749
|
+
const { scrollTop: j, scrollHeight: Q, clientHeight: G } = $, it = Q - j - G < 10;
|
|
750
|
+
M.current = it, console.log("User scroll - at bottom:", it), clearTimeout(E), N.current = !0, E = setTimeout(() => {
|
|
751
|
+
N.current = !1, console.log("User stopped scrolling");
|
|
695
752
|
}, 150);
|
|
696
|
-
let
|
|
697
|
-
for (let
|
|
698
|
-
if (
|
|
699
|
-
|
|
753
|
+
let et = 0;
|
|
754
|
+
for (let B = 0; B < C.length; B++)
|
|
755
|
+
if (C[B] > j - n * a) {
|
|
756
|
+
et = Math.max(0, B - 1);
|
|
700
757
|
break;
|
|
701
758
|
}
|
|
702
|
-
let
|
|
703
|
-
const
|
|
704
|
-
for (let
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
startIndex: Math.max(0,
|
|
708
|
-
endIndex: Math.min(k,
|
|
709
|
-
}
|
|
759
|
+
let ct = et;
|
|
760
|
+
const St = j + G;
|
|
761
|
+
for (let B = et; B < C.length && !(C[B] > St + n * a); B++)
|
|
762
|
+
ct = B;
|
|
763
|
+
const lt = {
|
|
764
|
+
startIndex: Math.max(0, et),
|
|
765
|
+
endIndex: Math.min(k, ct + 1 + a)
|
|
766
|
+
};
|
|
767
|
+
console.log("Updating visible range:", lt), T(lt);
|
|
710
768
|
};
|
|
711
|
-
return
|
|
769
|
+
return $.addEventListener("scroll", W, {
|
|
712
770
|
passive: !0
|
|
713
|
-
}), W(), () => {
|
|
714
|
-
|
|
771
|
+
}), console.log("Initial scroll calculation"), W(), () => {
|
|
772
|
+
console.log("Removing scroll handler"), $.removeEventListener("scroll", W), clearTimeout(E);
|
|
715
773
|
};
|
|
716
|
-
}, [
|
|
717
|
-
const
|
|
718
|
-
(
|
|
719
|
-
M.current = !0, u.current && (u.current.scrollTop = u.current.scrollHeight);
|
|
774
|
+
}, [C, k, n, a]);
|
|
775
|
+
const A = bt(
|
|
776
|
+
($ = "auto") => {
|
|
777
|
+
console.log("Manual scrollToBottom called"), M.current = !0, u.current && (u.current.scrollTop = u.current.scrollHeight);
|
|
720
778
|
},
|
|
721
779
|
[]
|
|
722
|
-
), D =
|
|
723
|
-
(
|
|
724
|
-
u.current &&
|
|
725
|
-
top:
|
|
726
|
-
behavior:
|
|
780
|
+
), D = bt(
|
|
781
|
+
($, E = "smooth") => {
|
|
782
|
+
console.log("scrollToIndex called:", $), u.current && C[$] !== void 0 && u.current.scrollTo({
|
|
783
|
+
top: C[$],
|
|
784
|
+
behavior: E
|
|
727
785
|
});
|
|
728
786
|
},
|
|
729
|
-
[
|
|
730
|
-
),
|
|
787
|
+
[C]
|
|
788
|
+
), U = {
|
|
731
789
|
outer: {
|
|
732
790
|
ref: u,
|
|
733
791
|
style: { overflowY: "auto", height: "100%" }
|
|
@@ -740,14 +798,18 @@ function mt(t, c, S, g) {
|
|
|
740
798
|
},
|
|
741
799
|
list: {
|
|
742
800
|
style: {
|
|
743
|
-
transform: `translateY(${
|
|
801
|
+
transform: `translateY(${C[p.startIndex] || 0}px)`
|
|
744
802
|
}
|
|
745
803
|
}
|
|
746
804
|
};
|
|
747
|
-
return {
|
|
805
|
+
return console.log("Returning virtualizer with props:", {
|
|
806
|
+
range: p,
|
|
807
|
+
totalHeight: V,
|
|
808
|
+
startPosition: C[p.startIndex] || 0
|
|
809
|
+
}), {
|
|
748
810
|
virtualState: L,
|
|
749
|
-
virtualizerProps:
|
|
750
|
-
scrollToBottom:
|
|
811
|
+
virtualizerProps: U,
|
|
812
|
+
scrollToBottom: A,
|
|
751
813
|
scrollToIndex: D
|
|
752
814
|
};
|
|
753
815
|
};
|
|
@@ -782,19 +844,19 @@ function mt(t, c, S, g) {
|
|
|
782
844
|
const u = n[i], p = [...r, i.toString()], T = s(u, p, f);
|
|
783
845
|
return e(u, T, {
|
|
784
846
|
register: () => {
|
|
785
|
-
const [, _] =
|
|
786
|
-
|
|
787
|
-
const M = `${t}////${
|
|
847
|
+
const [, _] = nt({}), N = `${S}-${r.join(".")}-${i}`;
|
|
848
|
+
kt(() => {
|
|
849
|
+
const M = `${t}////${N}`, P = o.getState().stateComponents.get(t) || {
|
|
788
850
|
components: /* @__PURE__ */ new Map()
|
|
789
851
|
};
|
|
790
852
|
return P.components.set(M, {
|
|
791
853
|
forceUpdate: () => _({}),
|
|
792
854
|
paths: /* @__PURE__ */ new Set([p.join(".")])
|
|
793
855
|
}), o.getState().stateComponents.set(t, P), () => {
|
|
794
|
-
const
|
|
795
|
-
|
|
856
|
+
const J = o.getState().stateComponents.get(t);
|
|
857
|
+
J && J.components.delete(M);
|
|
796
858
|
};
|
|
797
|
-
}, [t,
|
|
859
|
+
}, [t, N]);
|
|
798
860
|
},
|
|
799
861
|
index: v,
|
|
800
862
|
originalIndex: i
|
|
@@ -818,7 +880,7 @@ function mt(t, c, S, g) {
|
|
|
818
880
|
);
|
|
819
881
|
});
|
|
820
882
|
if (l === "$stateMap")
|
|
821
|
-
return (e) =>
|
|
883
|
+
return (e) => ut(Xt, {
|
|
822
884
|
proxy: {
|
|
823
885
|
_stateKey: t,
|
|
824
886
|
_path: r,
|
|
@@ -831,11 +893,11 @@ function mt(t, c, S, g) {
|
|
|
831
893
|
return (e) => {
|
|
832
894
|
const n = o.getState().getNestedState(t, r);
|
|
833
895
|
return Array.isArray(n) ? (f?.validIndices || Array.from({ length: n.length }, (i, v) => v)).map((i, v) => {
|
|
834
|
-
const u = n[i], p = [...r, i.toString()], T = s(u, p, f),
|
|
835
|
-
return
|
|
896
|
+
const u = n[i], p = [...r, i.toString()], T = s(u, p, f), b = `${S}-${r.join(".")}-${i}`;
|
|
897
|
+
return ut(Kt, {
|
|
836
898
|
key: i,
|
|
837
899
|
stateKey: t,
|
|
838
|
-
itemComponentId:
|
|
900
|
+
itemComponentId: b,
|
|
839
901
|
itemPath: p,
|
|
840
902
|
children: e(
|
|
841
903
|
u,
|
|
@@ -852,7 +914,7 @@ function mt(t, c, S, g) {
|
|
|
852
914
|
if (l === "stateFlattenOn")
|
|
853
915
|
return (e) => {
|
|
854
916
|
const n = h;
|
|
855
|
-
y.clear(),
|
|
917
|
+
y.clear(), x++;
|
|
856
918
|
const a = n.flatMap(
|
|
857
919
|
(i) => i[e] ?? []
|
|
858
920
|
);
|
|
@@ -875,7 +937,7 @@ function mt(t, c, S, g) {
|
|
|
875
937
|
return s(a, i);
|
|
876
938
|
};
|
|
877
939
|
if (l === "insert")
|
|
878
|
-
return (e) => (w(r),
|
|
940
|
+
return (e) => (w(r), yt(c, e, r, t), s(
|
|
879
941
|
o.getState().getNestedState(t, r),
|
|
880
942
|
r
|
|
881
943
|
));
|
|
@@ -886,25 +948,25 @@ function mt(t, c, S, g) {
|
|
|
886
948
|
if (!i.some((T) => {
|
|
887
949
|
if (n) {
|
|
888
950
|
const _ = n.every(
|
|
889
|
-
(
|
|
951
|
+
(N) => q(T[N], v[N])
|
|
890
952
|
);
|
|
891
953
|
return _ && (u = T), _;
|
|
892
954
|
}
|
|
893
|
-
const
|
|
894
|
-
return
|
|
955
|
+
const b = q(T, v);
|
|
956
|
+
return b && (u = T), b;
|
|
895
957
|
}))
|
|
896
|
-
w(r),
|
|
958
|
+
w(r), yt(c, v, r, t);
|
|
897
959
|
else if (a && u) {
|
|
898
|
-
const T = a(u),
|
|
960
|
+
const T = a(u), b = i.map(
|
|
899
961
|
(_) => q(_, u) ? T : _
|
|
900
962
|
);
|
|
901
|
-
w(r),
|
|
963
|
+
w(r), dt(c, b, r);
|
|
902
964
|
}
|
|
903
965
|
};
|
|
904
966
|
if (l === "cut")
|
|
905
967
|
return (e, n) => {
|
|
906
968
|
if (!n?.waitForSync)
|
|
907
|
-
return w(r),
|
|
969
|
+
return w(r), mt(c, r, t, e), s(
|
|
908
970
|
o.getState().getNestedState(t, r),
|
|
909
971
|
r
|
|
910
972
|
);
|
|
@@ -912,12 +974,12 @@ function mt(t, c, S, g) {
|
|
|
912
974
|
if (l === "cutByValue")
|
|
913
975
|
return (e) => {
|
|
914
976
|
for (let n = 0; n < h.length; n++)
|
|
915
|
-
h[n] === e &&
|
|
977
|
+
h[n] === e && mt(c, r, t, n);
|
|
916
978
|
};
|
|
917
979
|
if (l === "toggleByValue")
|
|
918
980
|
return (e) => {
|
|
919
981
|
const n = h.findIndex((a) => a === e);
|
|
920
|
-
n > -1 ?
|
|
982
|
+
n > -1 ? mt(c, r, t, n) : yt(c, e, r, t);
|
|
921
983
|
};
|
|
922
984
|
if (l === "stateFind")
|
|
923
985
|
return (e) => {
|
|
@@ -942,7 +1004,7 @@ function mt(t, c, S, g) {
|
|
|
942
1004
|
if (!isNaN(Number(tt))) {
|
|
943
1005
|
const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
944
1006
|
if (Array.isArray(e) && l === "cut")
|
|
945
|
-
return () =>
|
|
1007
|
+
return () => mt(
|
|
946
1008
|
c,
|
|
947
1009
|
d,
|
|
948
1010
|
t,
|
|
@@ -958,13 +1020,13 @@ function mt(t, c, S, g) {
|
|
|
958
1020
|
return o.getState().getNestedState(t, r);
|
|
959
1021
|
};
|
|
960
1022
|
if (l === "$derive")
|
|
961
|
-
return (d) =>
|
|
1023
|
+
return (d) => Nt({
|
|
962
1024
|
_stateKey: t,
|
|
963
1025
|
_path: r,
|
|
964
1026
|
_effect: d.toString()
|
|
965
1027
|
});
|
|
966
1028
|
if (l === "$get")
|
|
967
|
-
return () =>
|
|
1029
|
+
return () => Nt({
|
|
968
1030
|
_stateKey: t,
|
|
969
1031
|
_path: r
|
|
970
1032
|
});
|
|
@@ -973,7 +1035,7 @@ function mt(t, c, S, g) {
|
|
|
973
1035
|
return o.getState().getSyncInfo(d);
|
|
974
1036
|
}
|
|
975
1037
|
if (l == "getLocalStorage")
|
|
976
|
-
return (d) =>
|
|
1038
|
+
return (d) => pt(g + "-" + t + "-" + d);
|
|
977
1039
|
if (l === "_selected") {
|
|
978
1040
|
const d = r.slice(0, -1), e = d.join("."), n = o.getState().getNestedState(t, d);
|
|
979
1041
|
return Array.isArray(n) ? Number(r[r.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -983,7 +1045,7 @@ function mt(t, c, S, g) {
|
|
|
983
1045
|
const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
|
|
984
1046
|
d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
|
|
985
1047
|
const i = o.getState().getNestedState(t, [...e]);
|
|
986
|
-
|
|
1048
|
+
dt(c, i, e), w(e);
|
|
987
1049
|
};
|
|
988
1050
|
if (l === "toggleSelected")
|
|
989
1051
|
return () => {
|
|
@@ -994,7 +1056,7 @@ function mt(t, c, S, g) {
|
|
|
994
1056
|
a === e ? void 0 : e
|
|
995
1057
|
);
|
|
996
1058
|
const i = o.getState().getNestedState(t, [...d]);
|
|
997
|
-
|
|
1059
|
+
dt(c, i, d), w(d);
|
|
998
1060
|
};
|
|
999
1061
|
if (r.length == 0) {
|
|
1000
1062
|
if (l === "addValidation")
|
|
@@ -1005,12 +1067,12 @@ function mt(t, c, S, g) {
|
|
|
1005
1067
|
Z(e.key), console.log("addValidationError", d), d.forEach((n) => {
|
|
1006
1068
|
const a = [e.key, ...n.path].join(".");
|
|
1007
1069
|
console.log("fullErrorPath", a), Mt(a, n.message);
|
|
1008
|
-
}),
|
|
1070
|
+
}), gt(t);
|
|
1009
1071
|
};
|
|
1010
1072
|
if (l === "applyJsonPatch")
|
|
1011
1073
|
return (d) => {
|
|
1012
1074
|
const e = o.getState().cogsStateStore[t], a = Gt(e, d).newDocument;
|
|
1013
|
-
|
|
1075
|
+
Rt(
|
|
1014
1076
|
t,
|
|
1015
1077
|
o.getState().initialStateGlobal[t],
|
|
1016
1078
|
a,
|
|
@@ -1025,30 +1087,30 @@ function mt(t, c, S, g) {
|
|
|
1025
1087
|
p,
|
|
1026
1088
|
T
|
|
1027
1089
|
] of i.components.entries()) {
|
|
1028
|
-
let
|
|
1090
|
+
let b = !1;
|
|
1029
1091
|
const _ = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
|
|
1030
1092
|
if (!_.includes("none")) {
|
|
1031
1093
|
if (_.includes("all")) {
|
|
1032
1094
|
T.forceUpdate();
|
|
1033
1095
|
continue;
|
|
1034
1096
|
}
|
|
1035
|
-
if (_.includes("component") && (T.paths.has("") && (
|
|
1036
|
-
for (const
|
|
1037
|
-
if (T.paths.has(
|
|
1038
|
-
|
|
1097
|
+
if (_.includes("component") && (T.paths.has("") && (b = !0), !b))
|
|
1098
|
+
for (const N of u) {
|
|
1099
|
+
if (T.paths.has(N)) {
|
|
1100
|
+
b = !0;
|
|
1039
1101
|
break;
|
|
1040
1102
|
}
|
|
1041
|
-
let M =
|
|
1103
|
+
let M = N.lastIndexOf(".");
|
|
1042
1104
|
for (; M !== -1; ) {
|
|
1043
|
-
const P =
|
|
1105
|
+
const P = N.substring(0, M);
|
|
1044
1106
|
if (T.paths.has(P)) {
|
|
1045
|
-
|
|
1107
|
+
b = !0;
|
|
1046
1108
|
break;
|
|
1047
1109
|
}
|
|
1048
|
-
const
|
|
1110
|
+
const J = N.substring(
|
|
1049
1111
|
M + 1
|
|
1050
1112
|
);
|
|
1051
|
-
if (!isNaN(Number(
|
|
1113
|
+
if (!isNaN(Number(J))) {
|
|
1052
1114
|
const k = P.lastIndexOf(".");
|
|
1053
1115
|
if (k !== -1) {
|
|
1054
1116
|
const V = P.substring(
|
|
@@ -1056,21 +1118,21 @@ function mt(t, c, S, g) {
|
|
|
1056
1118
|
k
|
|
1057
1119
|
);
|
|
1058
1120
|
if (T.paths.has(V)) {
|
|
1059
|
-
|
|
1121
|
+
b = !0;
|
|
1060
1122
|
break;
|
|
1061
1123
|
}
|
|
1062
1124
|
}
|
|
1063
1125
|
}
|
|
1064
1126
|
M = P.lastIndexOf(".");
|
|
1065
1127
|
}
|
|
1066
|
-
if (
|
|
1128
|
+
if (b) break;
|
|
1067
1129
|
}
|
|
1068
|
-
if (!
|
|
1069
|
-
const
|
|
1130
|
+
if (!b && _.includes("deps") && T.depsFunction) {
|
|
1131
|
+
const N = T.depsFunction(a);
|
|
1070
1132
|
let M = !1;
|
|
1071
|
-
typeof
|
|
1133
|
+
typeof N == "boolean" ? N && (M = !0) : q(T.deps, N) || (T.deps = N, M = !0), M && (b = !0);
|
|
1072
1134
|
}
|
|
1073
|
-
|
|
1135
|
+
b && T.forceUpdate();
|
|
1074
1136
|
}
|
|
1075
1137
|
}
|
|
1076
1138
|
}
|
|
@@ -1091,9 +1153,9 @@ function mt(t, c, S, g) {
|
|
|
1091
1153
|
});
|
|
1092
1154
|
const i = d.zodSchema.safeParse(n);
|
|
1093
1155
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1094
|
-
const p = u.path, T = u.message,
|
|
1095
|
-
e(
|
|
1096
|
-
}),
|
|
1156
|
+
const p = u.path, T = u.message, b = [d.key, ...p].join(".");
|
|
1157
|
+
e(b, T);
|
|
1158
|
+
}), gt(t), !1);
|
|
1097
1159
|
} catch (a) {
|
|
1098
1160
|
return console.error("Zod schema validation failed", a), !1;
|
|
1099
1161
|
}
|
|
@@ -1102,7 +1164,7 @@ function mt(t, c, S, g) {
|
|
|
1102
1164
|
if (l === "getComponents")
|
|
1103
1165
|
return () => o().stateComponents.get(t);
|
|
1104
1166
|
if (l === "getAllFormRefs")
|
|
1105
|
-
return () =>
|
|
1167
|
+
return () => $t.getState().getFormRefsByStateKey(t);
|
|
1106
1168
|
if (l === "_initialState")
|
|
1107
1169
|
return o.getState().initialStateGlobal[t];
|
|
1108
1170
|
if (l === "_serverState")
|
|
@@ -1115,12 +1177,12 @@ function mt(t, c, S, g) {
|
|
|
1115
1177
|
if (l === "removeValidation") return I.removeValidation;
|
|
1116
1178
|
}
|
|
1117
1179
|
if (l === "getFormRef")
|
|
1118
|
-
return () =>
|
|
1180
|
+
return () => $t.getState().getFormRef(t + "." + r.join("."));
|
|
1119
1181
|
if (l === "validationWrapper")
|
|
1120
1182
|
return ({
|
|
1121
1183
|
children: d,
|
|
1122
1184
|
hideMessage: e
|
|
1123
|
-
}) => /* @__PURE__ */
|
|
1185
|
+
}) => /* @__PURE__ */ It(
|
|
1124
1186
|
Dt,
|
|
1125
1187
|
{
|
|
1126
1188
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
@@ -1138,19 +1200,19 @@ function mt(t, c, S, g) {
|
|
|
1138
1200
|
return (d, e) => {
|
|
1139
1201
|
if (e?.debounce)
|
|
1140
1202
|
Ft(() => {
|
|
1141
|
-
|
|
1203
|
+
dt(c, d, r, "");
|
|
1142
1204
|
const n = o.getState().getNestedState(t, r);
|
|
1143
1205
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1144
1206
|
}, e.debounce);
|
|
1145
1207
|
else {
|
|
1146
|
-
|
|
1208
|
+
dt(c, d, r, "");
|
|
1147
1209
|
const n = o.getState().getNestedState(t, r);
|
|
1148
1210
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1149
1211
|
}
|
|
1150
1212
|
w(r);
|
|
1151
1213
|
};
|
|
1152
1214
|
if (l === "formElement")
|
|
1153
|
-
return (d, e) => /* @__PURE__ */
|
|
1215
|
+
return (d, e) => /* @__PURE__ */ It(
|
|
1154
1216
|
Wt,
|
|
1155
1217
|
{
|
|
1156
1218
|
setState: c,
|
|
@@ -1160,21 +1222,21 @@ function mt(t, c, S, g) {
|
|
|
1160
1222
|
formOpts: e
|
|
1161
1223
|
}
|
|
1162
1224
|
);
|
|
1163
|
-
const
|
|
1164
|
-
return s(st,
|
|
1225
|
+
const R = [...r, l], st = o.getState().getNestedState(t, R);
|
|
1226
|
+
return s(st, R, f);
|
|
1165
1227
|
}
|
|
1166
|
-
},
|
|
1167
|
-
return y.set(
|
|
1168
|
-
proxy:
|
|
1169
|
-
stateVersion:
|
|
1170
|
-
}),
|
|
1228
|
+
}, z = new Proxy(O, F);
|
|
1229
|
+
return y.set(H, {
|
|
1230
|
+
proxy: z,
|
|
1231
|
+
stateVersion: x
|
|
1232
|
+
}), z;
|
|
1171
1233
|
}
|
|
1172
1234
|
return s(
|
|
1173
1235
|
o.getState().getNestedState(t, [])
|
|
1174
1236
|
);
|
|
1175
1237
|
}
|
|
1176
|
-
function
|
|
1177
|
-
return
|
|
1238
|
+
function Nt(t) {
|
|
1239
|
+
return ut(Qt, { proxy: t });
|
|
1178
1240
|
}
|
|
1179
1241
|
function Xt({
|
|
1180
1242
|
proxy: t,
|
|
@@ -1185,14 +1247,14 @@ function Xt({
|
|
|
1185
1247
|
S,
|
|
1186
1248
|
t._path
|
|
1187
1249
|
).stateMapNoRender(
|
|
1188
|
-
(y,
|
|
1250
|
+
(y, x, w, I, s) => t._mapFn(y, x, w, I, s)
|
|
1189
1251
|
) : null;
|
|
1190
1252
|
}
|
|
1191
1253
|
function Qt({
|
|
1192
1254
|
proxy: t
|
|
1193
1255
|
}) {
|
|
1194
1256
|
const c = X(null), S = `${t._stateKey}-${t._path.join(".")}`;
|
|
1195
|
-
return
|
|
1257
|
+
return rt(() => {
|
|
1196
1258
|
const g = c.current;
|
|
1197
1259
|
if (!g || !g.parentElement) return;
|
|
1198
1260
|
const y = g.parentElement, w = Array.from(y.childNodes).indexOf(g);
|
|
@@ -1213,22 +1275,22 @@ function Qt({
|
|
|
1213
1275
|
"state",
|
|
1214
1276
|
`return (${t._effect})(state)`
|
|
1215
1277
|
)(r);
|
|
1216
|
-
} catch (
|
|
1217
|
-
console.error("Error evaluating effect function during mount:",
|
|
1278
|
+
} catch (O) {
|
|
1279
|
+
console.error("Error evaluating effect function during mount:", O), f = r;
|
|
1218
1280
|
}
|
|
1219
1281
|
else
|
|
1220
1282
|
f = r;
|
|
1221
1283
|
f !== null && typeof f == "object" && (f = JSON.stringify(f));
|
|
1222
|
-
const
|
|
1223
|
-
g.replaceWith(
|
|
1224
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1284
|
+
const H = document.createTextNode(String(f));
|
|
1285
|
+
g.replaceWith(H);
|
|
1286
|
+
}, [t._stateKey, t._path.join("."), t._effect]), ut("span", {
|
|
1225
1287
|
ref: c,
|
|
1226
1288
|
style: { display: "none" },
|
|
1227
1289
|
"data-signal-id": S
|
|
1228
1290
|
});
|
|
1229
1291
|
}
|
|
1230
1292
|
function Se(t) {
|
|
1231
|
-
const c =
|
|
1293
|
+
const c = Ut(
|
|
1232
1294
|
(S) => {
|
|
1233
1295
|
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1234
1296
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1240,7 +1302,7 @@ function Se(t) {
|
|
|
1240
1302
|
},
|
|
1241
1303
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1242
1304
|
);
|
|
1243
|
-
return
|
|
1305
|
+
return ut("text", {}, String(c));
|
|
1244
1306
|
}
|
|
1245
1307
|
function Kt({
|
|
1246
1308
|
stateKey: t,
|
|
@@ -1248,14 +1310,14 @@ function Kt({
|
|
|
1248
1310
|
itemPath: S,
|
|
1249
1311
|
children: g
|
|
1250
1312
|
}) {
|
|
1251
|
-
const [, y] =
|
|
1252
|
-
return
|
|
1313
|
+
const [, y] = nt({}), [x, w] = Bt(), I = X(null);
|
|
1314
|
+
return rt(() => {
|
|
1253
1315
|
w.height > 0 && w.height !== I.current && (I.current = w.height, o.getState().setShadowMetadata(t, S, {
|
|
1254
1316
|
virtualizer: {
|
|
1255
1317
|
itemHeight: w.height
|
|
1256
1318
|
}
|
|
1257
1319
|
}));
|
|
1258
|
-
}, [w.height, t, S]),
|
|
1320
|
+
}, [w.height, t, S]), kt(() => {
|
|
1259
1321
|
const s = `${t}////${c}`, h = o.getState().stateComponents.get(t) || {
|
|
1260
1322
|
components: /* @__PURE__ */ new Map()
|
|
1261
1323
|
};
|
|
@@ -1266,10 +1328,10 @@ function Kt({
|
|
|
1266
1328
|
const r = o.getState().stateComponents.get(t);
|
|
1267
1329
|
r && r.components.delete(s);
|
|
1268
1330
|
};
|
|
1269
|
-
}, [t, c, S.join(".")]), /* @__PURE__ */
|
|
1331
|
+
}, [t, c, S.join(".")]), /* @__PURE__ */ It("div", { ref: x, children: g });
|
|
1270
1332
|
}
|
|
1271
1333
|
export {
|
|
1272
|
-
|
|
1334
|
+
Nt as $cogsSignal,
|
|
1273
1335
|
Se as $cogsSignalStore,
|
|
1274
1336
|
ue as addStateOptions,
|
|
1275
1337
|
ge as createCogsState,
|