cogsbox-state 0.5.286 → 0.5.288
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 +204 -201
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +30 -24
package/dist/CogsState.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as vt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as rt, useRef as
|
|
4
|
-
import { transformStateFunc as _t, isDeepEqual as H, isFunction as
|
|
3
|
+
import { useState as rt, useRef as Z, useEffect as lt, useLayoutEffect as dt, useMemo as yt, createElement as st, useSyncExternalStore as xt, startTransition as Pt, useCallback as mt } from "react";
|
|
4
|
+
import { transformStateFunc as _t, isDeepEqual as H, isFunction as X, getNestedValue as z, getDifferences as It, debounce as Mt } from "./utility.js";
|
|
5
5
|
import { pushFunc as ht, updateFn as at, cutFunc as ct, ValidationWrapper as jt, FormControlComponent as Ot } from "./Functions.jsx";
|
|
6
6
|
import Rt from "superjson";
|
|
7
7
|
import { v4 as pt } from "uuid";
|
|
@@ -52,7 +52,7 @@ const ce = (t, c) => {
|
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W,
|
|
55
|
+
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, F] = Bt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
@@ -68,7 +68,7 @@ const ce = (t, c) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return F;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
74
|
Tt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Ht(I, a), St(I);
|
|
@@ -83,7 +83,7 @@ const ce = (t, c) => {
|
|
|
83
83
|
setStateLog: Wt,
|
|
84
84
|
updateInitialStateGlobal: wt,
|
|
85
85
|
addValidationError: Gt,
|
|
86
|
-
removeValidationError:
|
|
86
|
+
removeValidationError: Y,
|
|
87
87
|
setServerSyncActions: Lt
|
|
88
88
|
} = o.getState(), $t = (t, c, v, f, y) => {
|
|
89
89
|
v?.log && console.log(
|
|
@@ -92,7 +92,7 @@ const ce = (t, c) => {
|
|
|
92
92
|
v.localStorage?.key,
|
|
93
93
|
f
|
|
94
94
|
);
|
|
95
|
-
const k =
|
|
95
|
+
const k = X(v?.localStorage?.key) ? v.localStorage?.key(t) : v?.localStorage?.key;
|
|
96
96
|
if (k && f) {
|
|
97
97
|
const p = `${f}-${c}-${k}`;
|
|
98
98
|
let I;
|
|
@@ -119,7 +119,7 @@ const ce = (t, c) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
121
|
}, Ht = (t, c) => {
|
|
122
|
-
const v = o.getState().cogsStateStore[t], { sessionId: f } = Nt(), y =
|
|
122
|
+
const v = o.getState().cogsStateStore[t], { sessionId: f } = Nt(), y = X(c?.localStorage?.key) ? c.localStorage.key(v) : c?.localStorage?.key;
|
|
123
123
|
if (y && f) {
|
|
124
124
|
const k = ft(
|
|
125
125
|
`${f}-${t}-${y}`
|
|
@@ -193,12 +193,12 @@ function Bt(t, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [W,
|
|
196
|
+
const [W, F] = rt({}), { sessionId: U } = Nt();
|
|
197
197
|
let G = !c;
|
|
198
|
-
const [h] = rt(c ?? pt()), l = o.getState().stateLog[h], it =
|
|
198
|
+
const [h] = rt(c ?? pt()), l = o.getState().stateLog[h], it = Z(/* @__PURE__ */ new Set()), Q = Z(I ?? pt()), O = Z(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
O.current = nt(h) ?? null, lt(() => {
|
|
202
202
|
if (m && m.stateKey === h && m.path?.[0]) {
|
|
203
203
|
tt(h, (r) => ({
|
|
204
204
|
...r,
|
|
@@ -215,22 +215,22 @@ function Bt(t, {
|
|
|
215
215
|
At(h, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
218
|
+
const e = O.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
219
|
if (!(i && !H(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const A =
|
|
223
|
-
A &&
|
|
222
|
+
const A = X(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
A && U && (u = ft(`${U}-${h}-${A}`));
|
|
224
224
|
let w = a, T = !1;
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
225
|
+
const x = s ? Date.now() : 0, V = u?.lastUpdated || 0, _ = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && x > V ? (w = e.serverState.data, T = !0) : u && V > _ && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Ct(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
229
|
w,
|
|
230
230
|
ot,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
), T && A &&
|
|
231
|
+
Q.current,
|
|
232
|
+
U
|
|
233
|
+
), T && A && U && $t(w, h, e, U, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || F({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
@@ -243,18 +243,18 @@ function Bt(t, {
|
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: f,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: O.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${h}////${
|
|
248
|
+
const e = `${h}////${Q.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => F({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: k || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(h, r),
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), F({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
@@ -265,151 +265,151 @@ function Bt(t, {
|
|
|
265
265
|
}
|
|
266
266
|
const g = o.getState();
|
|
267
267
|
tt(h, (u) => {
|
|
268
|
-
const A =
|
|
268
|
+
const A = X(e) ? e(u) : e, w = `${h}-${r.join(".")}`;
|
|
269
269
|
if (w) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
270
|
+
let N = !1, b = g.signalDomElements.get(w);
|
|
271
|
+
if ((!b || b.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const R = r.slice(0, -1), D = z(A, R);
|
|
273
273
|
if (Array.isArray(D)) {
|
|
274
|
-
|
|
275
|
-
const $ = `${h}-${
|
|
276
|
-
|
|
274
|
+
N = !0;
|
|
275
|
+
const $ = `${h}-${R.join(".")}`;
|
|
276
|
+
b = g.signalDomElements.get($);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
279
|
+
if (b) {
|
|
280
|
+
const R = N ? z(A, r.slice(0, -1)) : z(A, r);
|
|
281
|
+
b.forEach(({ parentId: D, position: $, effect: E }) => {
|
|
282
|
+
const C = document.querySelector(
|
|
283
283
|
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (C) {
|
|
286
|
+
const M = Array.from(C.childNodes);
|
|
287
|
+
if (M[$]) {
|
|
288
|
+
const j = E ? new Function("state", `return (${E})(state)`)(R) : R;
|
|
289
|
+
M[$].textContent = String(j);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i ||
|
|
296
|
-
(i ||
|
|
295
|
+
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || O.current?.validation?.key) && r && Y(
|
|
296
|
+
(i || O.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
298
|
const T = r.slice(0, r.length - 1);
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let D =
|
|
305
|
-
if (
|
|
306
|
-
let $ =
|
|
307
|
-
|
|
299
|
+
s.updateType === "cut" && O.current?.validation?.key && Y(
|
|
300
|
+
O.current?.validation?.key + "." + T.join(".")
|
|
301
|
+
), s.updateType === "insert" && O.current?.validation?.key && Dt(
|
|
302
|
+
O.current?.validation?.key + "." + T.join(".")
|
|
303
|
+
).filter(([b, R]) => {
|
|
304
|
+
let D = b?.split(".").length;
|
|
305
|
+
if (b == T.join(".") && D == T.length - 1) {
|
|
306
|
+
let $ = b + "." + T;
|
|
307
|
+
Y(b), Gt($, R);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const x = g.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
|
|
312
|
+
const N = It(u, A), b = new Set(N), R = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
D,
|
|
315
315
|
$
|
|
316
|
-
] of
|
|
316
|
+
] of x.components.entries()) {
|
|
317
317
|
let E = !1;
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", $), !
|
|
320
|
-
if (
|
|
318
|
+
const C = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", $), !C.includes("none")) {
|
|
320
|
+
if (C.includes("all")) {
|
|
321
321
|
$.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (C.includes("component") && (($.paths.has(R) || $.paths.has("")) && (E = !0), !E))
|
|
325
|
+
for (const M of b) {
|
|
326
|
+
let j = M;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if ($.paths.has(
|
|
328
|
+
if ($.paths.has(j)) {
|
|
329
329
|
E = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const L =
|
|
332
|
+
const L = j.lastIndexOf(".");
|
|
333
333
|
if (L !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const K = j.substring(
|
|
335
335
|
0,
|
|
336
336
|
L
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && $.paths.has(
|
|
339
|
+
Number(j.substring(L + 1))
|
|
340
|
+
) && $.paths.has(K)) {
|
|
341
341
|
E = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
j = K;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
j = "";
|
|
347
|
+
if (j === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
if (E) break;
|
|
351
351
|
}
|
|
352
|
-
if (!E &&
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!E && C.includes("deps") && $.depsFunction) {
|
|
353
|
+
const M = $.depsFunction(A);
|
|
354
|
+
let j = !1;
|
|
355
|
+
typeof M == "boolean" ? M && (j = !0) : H($.deps, M) || ($.deps = M, j = !0), j && (E = !0);
|
|
356
356
|
}
|
|
357
357
|
E && $.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const V = Date.now();
|
|
362
|
+
r = r.map((N, b) => {
|
|
363
|
+
const R = r.slice(0, -1), D = z(A, R);
|
|
364
|
+
return b === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : N;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: _, newValue: P } = zt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
369
|
A,
|
|
370
370
|
r
|
|
371
371
|
), B = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: V,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: _,
|
|
378
|
+
newValue: P
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
g.updateShadowAtPath(h, r, A);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
g.insertShadowArrayElement(h,
|
|
385
|
+
const N = r.slice(0, -1);
|
|
386
|
+
g.insertShadowArrayElement(h, N, P);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
g.removeShadowArrayElement(h,
|
|
389
|
+
const b = r.slice(0, -1), R = parseInt(r[r.length - 1]);
|
|
390
|
+
g.removeShadowArrayElement(h, b, R);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (Wt(h, (
|
|
394
|
-
const
|
|
395
|
-
const E = `${$.stateKey}:${JSON.stringify($.path)}`,
|
|
396
|
-
return
|
|
393
|
+
if (Wt(h, (N) => {
|
|
394
|
+
const R = [...N ?? [], B].reduce((D, $) => {
|
|
395
|
+
const E = `${$.stateKey}:${JSON.stringify($.path)}`, C = D.get(E);
|
|
396
|
+
return C ? (C.timeStamp = Math.max(C.timeStamp, $.timeStamp), C.newValue = $.newValue, C.oldValue = C.oldValue ?? $.oldValue, C.updateType = $.updateType) : D.set(E, { ...$ }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
398
|
+
return Array.from(R.values());
|
|
399
399
|
}), $t(
|
|
400
400
|
A,
|
|
401
401
|
h,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
O.current,
|
|
403
|
+
U
|
|
404
|
+
), O.current?.middleware && O.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: B
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
407
|
+
}), O.current?.serverSync) {
|
|
408
|
+
const N = g.serverState[h], b = O.current?.serverSync;
|
|
409
409
|
Lt(h, {
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
410
|
+
syncKey: typeof b.syncKey == "string" ? b.syncKey : b.syncKey({ state: A }),
|
|
411
|
+
rollBackState: N,
|
|
412
|
+
actionTimeStamp: Date.now() + (b.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
@@ -421,16 +421,16 @@ function Bt(t, {
|
|
|
421
421
|
gt(
|
|
422
422
|
h,
|
|
423
423
|
ot,
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
Q.current,
|
|
425
|
+
U
|
|
426
426
|
)
|
|
427
427
|
), o.getState().cogsStateStore[h] || tt(h, t), o.getState().initialStateGlobal[h] || wt(h, t));
|
|
428
428
|
const d = yt(() => gt(
|
|
429
429
|
h,
|
|
430
430
|
ot,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
), [h,
|
|
431
|
+
Q.current,
|
|
432
|
+
U
|
|
433
|
+
), [h, U]);
|
|
434
434
|
return [bt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function gt(t, c, v, f) {
|
|
@@ -443,14 +443,14 @@ function gt(t, c, v, f) {
|
|
|
443
443
|
k++;
|
|
444
444
|
}, I = {
|
|
445
445
|
removeValidation: (m) => {
|
|
446
|
-
m?.validationKey &&
|
|
446
|
+
m?.validationKey && Y(m.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (m) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Y(n?.key), m?.validationKey && Y(m.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
452
|
o.getState().clearSelectedIndexesForState(t), y.clear(), k++;
|
|
453
|
-
const W = a(S, []),
|
|
453
|
+
const W = a(S, []), F = nt(t), U = X(F?.localStorage?.key) ? F?.localStorage?.key(S) : F?.localStorage?.key, G = `${f}-${t}-${U}`;
|
|
454
454
|
G && localStorage.removeItem(G), ut(t, W), tt(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
@@ -464,8 +464,8 @@ function gt(t, c, v, f) {
|
|
|
464
464
|
c,
|
|
465
465
|
v,
|
|
466
466
|
f
|
|
467
|
-
), S = o.getState().initialStateGlobal[t], W = nt(t),
|
|
468
|
-
return localStorage.getItem(
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = nt(t), F = X(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${f}-${t}-${F}`;
|
|
468
|
+
return localStorage.getItem(U) && localStorage.removeItem(U), console.log("udpating intial State", t, m), Pt(() => {
|
|
469
469
|
wt(t, m), o.getState().initializeShadowState(t, m), ut(t, n), tt(t, m);
|
|
470
470
|
const G = o.getState().stateComponents.get(t);
|
|
471
471
|
G && G.components.forEach((h) => {
|
|
@@ -486,13 +486,13 @@ function gt(t, c, v, f) {
|
|
|
486
486
|
function a(m, n = [], S) {
|
|
487
487
|
const W = n.map(String).join(".");
|
|
488
488
|
y.get(W);
|
|
489
|
-
const
|
|
489
|
+
const F = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(I).forEach((h) => {
|
|
493
|
-
|
|
493
|
+
F[h] = I[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
495
|
+
const U = {
|
|
496
496
|
apply(h, l, it) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
@@ -581,7 +581,7 @@ function gt(t, c, v, f) {
|
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e = nt(t), r =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = nt(t), r = X(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -619,66 +619,66 @@ function gt(t, c, v, f) {
|
|
|
619
619
|
return (e) => {
|
|
620
620
|
const {
|
|
621
621
|
itemHeight: r = 50,
|
|
622
|
-
//
|
|
622
|
+
// Serves as a fallback for unmeasured items
|
|
623
623
|
overscan: s = 5,
|
|
624
624
|
stickToBottom: i = !1
|
|
625
|
-
} = e, g =
|
|
625
|
+
} = e, g = Z(null), [u, A] = rt({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), w =
|
|
629
|
-
t,
|
|
630
|
-
n
|
|
631
|
-
), b = x.length, U = mt(
|
|
628
|
+
}), w = mt(
|
|
632
629
|
(E) => o.getState().getShadowMetadata(t, [...n, E.toString()])?.virtualizer?.itemHeight || r,
|
|
633
630
|
[r, t, n]
|
|
634
|
-
),
|
|
631
|
+
), T = Z(i), x = Z(0), V = Z(!0), _ = o().getNestedState(
|
|
632
|
+
t,
|
|
633
|
+
n
|
|
634
|
+
), P = _.length, { totalHeight: B, positions: N } = yt(() => {
|
|
635
635
|
let E = 0;
|
|
636
|
-
const
|
|
637
|
-
for (let
|
|
638
|
-
|
|
639
|
-
return { totalHeight: E, positions:
|
|
640
|
-
}, [
|
|
641
|
-
const E = Math.max(0, u.startIndex),
|
|
642
|
-
{ length:
|
|
643
|
-
(L,
|
|
644
|
-
),
|
|
645
|
-
return a(
|
|
636
|
+
const C = [];
|
|
637
|
+
for (let M = 0; M < P; M++)
|
|
638
|
+
C[M] = E, E += w(M);
|
|
639
|
+
return { totalHeight: E, positions: C };
|
|
640
|
+
}, [P, w]), b = yt(() => {
|
|
641
|
+
const E = Math.max(0, u.startIndex), C = Math.min(P, u.endIndex), M = Array.from(
|
|
642
|
+
{ length: C - E },
|
|
643
|
+
(L, K) => E + K
|
|
644
|
+
), j = M.map((L) => _[L]);
|
|
645
|
+
return a(j, n, {
|
|
646
646
|
...S,
|
|
647
|
-
validIndices:
|
|
647
|
+
validIndices: M
|
|
648
648
|
});
|
|
649
|
-
}, [u.startIndex, u.endIndex,
|
|
649
|
+
}, [u.startIndex, u.endIndex, _, P]);
|
|
650
650
|
dt(() => {
|
|
651
651
|
const E = g.current;
|
|
652
652
|
if (!E) return;
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
const { scrollTop: L, clientHeight:
|
|
657
|
-
|
|
653
|
+
const C = T.current, M = P > x.current;
|
|
654
|
+
x.current = P;
|
|
655
|
+
const j = () => {
|
|
656
|
+
const { scrollTop: L, clientHeight: K, scrollHeight: Vt } = E;
|
|
657
|
+
T.current = Vt - L - K < 10;
|
|
658
658
|
let et = 0;
|
|
659
|
-
for (let
|
|
660
|
-
if (
|
|
661
|
-
et =
|
|
659
|
+
for (let J = 0; J < N.length; J++)
|
|
660
|
+
if (N[J] >= L) {
|
|
661
|
+
et = J;
|
|
662
662
|
break;
|
|
663
663
|
}
|
|
664
|
-
let
|
|
665
|
-
for (;
|
|
666
|
-
|
|
667
|
-
et = Math.max(0, et - s),
|
|
664
|
+
let q = et;
|
|
665
|
+
for (; q < P && N[q] && N[q] < L + K; )
|
|
666
|
+
q++;
|
|
667
|
+
et = Math.max(0, et - s), q = Math.min(P, q + s), A((J) => J.startIndex !== et || J.endIndex !== q ? { startIndex: et, endIndex: q } : J);
|
|
668
668
|
};
|
|
669
|
-
return E.addEventListener("scroll",
|
|
669
|
+
return E.addEventListener("scroll", j, {
|
|
670
670
|
passive: !0
|
|
671
|
-
}), i && (
|
|
671
|
+
}), i && (V.current ? E.scrollTo({
|
|
672
672
|
top: E.scrollHeight,
|
|
673
673
|
behavior: "auto"
|
|
674
|
-
}) :
|
|
674
|
+
}) : C && M && requestAnimationFrame(() => {
|
|
675
675
|
E.scrollTo({
|
|
676
676
|
top: E.scrollHeight,
|
|
677
677
|
behavior: "smooth"
|
|
678
678
|
});
|
|
679
|
-
})),
|
|
680
|
-
}, [
|
|
681
|
-
const
|
|
679
|
+
})), V.current = !1, j(), () => E.removeEventListener("scroll", j);
|
|
680
|
+
}, [P, s, i, N]);
|
|
681
|
+
const R = mt(
|
|
682
682
|
(E = "smooth") => {
|
|
683
683
|
g.current && g.current.scrollTo({
|
|
684
684
|
top: g.current.scrollHeight,
|
|
@@ -687,14 +687,15 @@ function gt(t, c, v, f) {
|
|
|
687
687
|
},
|
|
688
688
|
[]
|
|
689
689
|
), D = mt(
|
|
690
|
-
(E,
|
|
691
|
-
g.current &&
|
|
692
|
-
top:
|
|
693
|
-
|
|
690
|
+
(E, C = "smooth") => {
|
|
691
|
+
g.current && N[E] !== void 0 && g.current.scrollTo({
|
|
692
|
+
top: N[E],
|
|
693
|
+
// Instead of `index * itemHeight`
|
|
694
|
+
behavior: C
|
|
694
695
|
});
|
|
695
696
|
},
|
|
696
|
-
[
|
|
697
|
-
// Depends on
|
|
697
|
+
[N]
|
|
698
|
+
// Depends on `positions` now instead of `itemHeight`
|
|
698
699
|
), $ = {
|
|
699
700
|
outer: {
|
|
700
701
|
ref: g,
|
|
@@ -703,19 +704,21 @@ function gt(t, c, v, f) {
|
|
|
703
704
|
inner: {
|
|
704
705
|
style: {
|
|
705
706
|
height: `${B}px`,
|
|
707
|
+
// Use calculated total height
|
|
706
708
|
position: "relative"
|
|
707
709
|
}
|
|
708
710
|
},
|
|
709
711
|
list: {
|
|
710
712
|
style: {
|
|
711
|
-
|
|
713
|
+
// Use the pre-calculated position of the first visible item
|
|
714
|
+
transform: `translateY(${N[u.startIndex] || 0}px)`
|
|
712
715
|
}
|
|
713
716
|
}
|
|
714
717
|
};
|
|
715
718
|
return {
|
|
716
|
-
virtualState:
|
|
719
|
+
virtualState: b,
|
|
717
720
|
virtualizerProps: $,
|
|
718
|
-
scrollToBottom:
|
|
721
|
+
scrollToBottom: R,
|
|
719
722
|
scrollToIndex: D
|
|
720
723
|
};
|
|
721
724
|
};
|
|
@@ -750,19 +753,19 @@ function gt(t, c, v, f) {
|
|
|
750
753
|
const u = r[i], A = [...n, i.toString()], w = a(u, A, S);
|
|
751
754
|
return e(u, w, {
|
|
752
755
|
register: () => {
|
|
753
|
-
const [,
|
|
756
|
+
const [, x] = rt({}), V = `${v}-${n.join(".")}-${i}`;
|
|
754
757
|
dt(() => {
|
|
755
|
-
const
|
|
758
|
+
const _ = `${t}////${V}`, P = o.getState().stateComponents.get(t) || {
|
|
756
759
|
components: /* @__PURE__ */ new Map()
|
|
757
760
|
};
|
|
758
|
-
return
|
|
759
|
-
forceUpdate: () =>
|
|
761
|
+
return P.components.set(_, {
|
|
762
|
+
forceUpdate: () => x({}),
|
|
760
763
|
paths: /* @__PURE__ */ new Set([A.join(".")])
|
|
761
|
-
}), o.getState().stateComponents.set(t,
|
|
764
|
+
}), o.getState().stateComponents.set(t, P), () => {
|
|
762
765
|
const B = o.getState().stateComponents.get(t);
|
|
763
|
-
B && B.components.delete(
|
|
766
|
+
B && B.components.delete(_);
|
|
764
767
|
};
|
|
765
|
-
}, [t,
|
|
768
|
+
}, [t, V]);
|
|
766
769
|
},
|
|
767
770
|
index: g,
|
|
768
771
|
originalIndex: i
|
|
@@ -849,14 +852,14 @@ function gt(t, c, v, f) {
|
|
|
849
852
|
));
|
|
850
853
|
if (l === "uniqueInsert")
|
|
851
854
|
return (e, r, s) => {
|
|
852
|
-
const i = o.getState().getNestedState(t, n), g =
|
|
855
|
+
const i = o.getState().getNestedState(t, n), g = X(e) ? e(i) : e;
|
|
853
856
|
let u = null;
|
|
854
857
|
if (!i.some((w) => {
|
|
855
858
|
if (r) {
|
|
856
|
-
const
|
|
857
|
-
(
|
|
859
|
+
const x = r.every(
|
|
860
|
+
(V) => H(w[V], g[V])
|
|
858
861
|
);
|
|
859
|
-
return
|
|
862
|
+
return x && (u = w), x;
|
|
860
863
|
}
|
|
861
864
|
const T = H(w, g);
|
|
862
865
|
return T && (u = w), T;
|
|
@@ -864,7 +867,7 @@ function gt(t, c, v, f) {
|
|
|
864
867
|
p(n), ht(c, g, n, t);
|
|
865
868
|
else if (s && u) {
|
|
866
869
|
const w = s(u), T = i.map(
|
|
867
|
-
(
|
|
870
|
+
(x) => H(x, u) ? w : x
|
|
868
871
|
);
|
|
869
872
|
p(n), at(c, T, n);
|
|
870
873
|
}
|
|
@@ -906,15 +909,15 @@ function gt(t, c, v, f) {
|
|
|
906
909
|
return a(i.item, g, S);
|
|
907
910
|
};
|
|
908
911
|
}
|
|
909
|
-
const
|
|
910
|
-
if (!isNaN(Number(
|
|
912
|
+
const Q = n[n.length - 1];
|
|
913
|
+
if (!isNaN(Number(Q))) {
|
|
911
914
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
912
915
|
if (Array.isArray(e) && l === "cut")
|
|
913
916
|
return () => ct(
|
|
914
917
|
c,
|
|
915
918
|
d,
|
|
916
919
|
t,
|
|
917
|
-
Number(
|
|
920
|
+
Number(Q)
|
|
918
921
|
);
|
|
919
922
|
}
|
|
920
923
|
if (l === "get")
|
|
@@ -984,49 +987,49 @@ function gt(t, c, v, f) {
|
|
|
984
987
|
w
|
|
985
988
|
] of i.components.entries()) {
|
|
986
989
|
let T = !1;
|
|
987
|
-
const
|
|
988
|
-
if (!
|
|
989
|
-
if (
|
|
990
|
+
const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
991
|
+
if (!x.includes("none")) {
|
|
992
|
+
if (x.includes("all")) {
|
|
990
993
|
w.forceUpdate();
|
|
991
994
|
continue;
|
|
992
995
|
}
|
|
993
|
-
if (
|
|
994
|
-
for (const
|
|
995
|
-
if (w.paths.has(
|
|
996
|
+
if (x.includes("component") && (w.paths.has("") && (T = !0), !T))
|
|
997
|
+
for (const V of u) {
|
|
998
|
+
if (w.paths.has(V)) {
|
|
996
999
|
T = !0;
|
|
997
1000
|
break;
|
|
998
1001
|
}
|
|
999
|
-
let
|
|
1000
|
-
for (;
|
|
1001
|
-
const
|
|
1002
|
-
if (w.paths.has(
|
|
1002
|
+
let _ = V.lastIndexOf(".");
|
|
1003
|
+
for (; _ !== -1; ) {
|
|
1004
|
+
const P = V.substring(0, _);
|
|
1005
|
+
if (w.paths.has(P)) {
|
|
1003
1006
|
T = !0;
|
|
1004
1007
|
break;
|
|
1005
1008
|
}
|
|
1006
|
-
const B =
|
|
1007
|
-
|
|
1009
|
+
const B = V.substring(
|
|
1010
|
+
_ + 1
|
|
1008
1011
|
);
|
|
1009
1012
|
if (!isNaN(Number(B))) {
|
|
1010
|
-
const
|
|
1011
|
-
if (
|
|
1012
|
-
const
|
|
1013
|
+
const N = P.lastIndexOf(".");
|
|
1014
|
+
if (N !== -1) {
|
|
1015
|
+
const b = P.substring(
|
|
1013
1016
|
0,
|
|
1014
|
-
|
|
1017
|
+
N
|
|
1015
1018
|
);
|
|
1016
|
-
if (w.paths.has(
|
|
1019
|
+
if (w.paths.has(b)) {
|
|
1017
1020
|
T = !0;
|
|
1018
1021
|
break;
|
|
1019
1022
|
}
|
|
1020
1023
|
}
|
|
1021
1024
|
}
|
|
1022
|
-
|
|
1025
|
+
_ = P.lastIndexOf(".");
|
|
1023
1026
|
}
|
|
1024
1027
|
if (T) break;
|
|
1025
1028
|
}
|
|
1026
|
-
if (!T &&
|
|
1027
|
-
const
|
|
1028
|
-
let
|
|
1029
|
-
typeof
|
|
1029
|
+
if (!T && x.includes("deps") && w.depsFunction) {
|
|
1030
|
+
const V = w.depsFunction(s);
|
|
1031
|
+
let _ = !1;
|
|
1032
|
+
typeof V == "boolean" ? V && (_ = !0) : H(w.deps, V) || (w.deps = V, _ = !0), _ && (T = !0);
|
|
1030
1033
|
}
|
|
1031
1034
|
T && w.forceUpdate();
|
|
1032
1035
|
}
|
|
@@ -1040,12 +1043,12 @@ function gt(t, c, v, f) {
|
|
|
1040
1043
|
throw new Error("Zod schema not found");
|
|
1041
1044
|
if (!d?.key)
|
|
1042
1045
|
throw new Error("Validation key not found");
|
|
1043
|
-
|
|
1046
|
+
Y(d.key);
|
|
1044
1047
|
const r = o.getState().cogsStateStore[t];
|
|
1045
1048
|
try {
|
|
1046
1049
|
const s = o.getState().getValidationErrors(d.key);
|
|
1047
1050
|
s && s.length > 0 && s.forEach(([g]) => {
|
|
1048
|
-
g && g.startsWith(d.key) &&
|
|
1051
|
+
g && g.startsWith(d.key) && Y(g);
|
|
1049
1052
|
});
|
|
1050
1053
|
const i = d.zodSchema.safeParse(r);
|
|
1051
1054
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
@@ -1118,10 +1121,10 @@ function gt(t, c, v, f) {
|
|
|
1118
1121
|
formOpts: e
|
|
1119
1122
|
}
|
|
1120
1123
|
);
|
|
1121
|
-
const
|
|
1122
|
-
return a(ot,
|
|
1124
|
+
const O = [...n, l], ot = o.getState().getNestedState(t, O);
|
|
1125
|
+
return a(ot, O, S);
|
|
1123
1126
|
}
|
|
1124
|
-
}, G = new Proxy(
|
|
1127
|
+
}, G = new Proxy(F, U);
|
|
1125
1128
|
return y.set(W, {
|
|
1126
1129
|
proxy: G,
|
|
1127
1130
|
stateVersion: k
|
|
@@ -1149,7 +1152,7 @@ function qt({
|
|
|
1149
1152
|
function Jt({
|
|
1150
1153
|
proxy: t
|
|
1151
1154
|
}) {
|
|
1152
|
-
const c =
|
|
1155
|
+
const c = Z(null), v = `${t._stateKey}-${t._path.join(".")}`;
|
|
1153
1156
|
return lt(() => {
|
|
1154
1157
|
const f = c.current;
|
|
1155
1158
|
if (!f || !f.parentElement) return;
|
|
@@ -1171,8 +1174,8 @@ function Jt({
|
|
|
1171
1174
|
"state",
|
|
1172
1175
|
`return (${t._effect})(state)`
|
|
1173
1176
|
)(n);
|
|
1174
|
-
} catch (
|
|
1175
|
-
console.error("Error evaluating effect function during mount:",
|
|
1177
|
+
} catch (F) {
|
|
1178
|
+
console.error("Error evaluating effect function during mount:", F), S = n;
|
|
1176
1179
|
}
|
|
1177
1180
|
else
|
|
1178
1181
|
S = n;
|