cogsbox-state 0.5.263 → 0.5.265
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 +183 -176
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +31 -23
package/dist/CogsState.jsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as me } from "react/jsx-runtime";
|
|
3
|
-
import { useState as K, useRef as Z, useEffect as ne, useLayoutEffect as de, useMemo as
|
|
4
|
-
import { transformStateFunc as ke, isDeepEqual as L, isFunction as z, getNestedValue as
|
|
3
|
+
import { useState as K, useRef as Z, useEffect as ne, useLayoutEffect as de, useMemo as Te, createElement as ae, useSyncExternalStore as xe, startTransition as Ve, useCallback as ye } from "react";
|
|
4
|
+
import { transformStateFunc as ke, isDeepEqual as L, isFunction as z, getNestedValue as H, getDifferences as ue, debounce as Ne } from "./utility.js";
|
|
5
5
|
import { pushFunc as le, updateFn as Q, cutFunc as te, ValidationWrapper as be, FormControlComponent as Ce } from "./Functions.jsx";
|
|
6
6
|
import Pe from "superjson";
|
|
7
7
|
import { v4 as ge } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as r, formRefStore as ve } from "./store.js";
|
|
10
|
-
import { useCogsConfig as
|
|
10
|
+
import { useCogsConfig as Ee } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as _e } from "fast-json-patch";
|
|
12
12
|
function he(e, s) {
|
|
13
13
|
const h = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, y = h(e) || {};
|
|
@@ -51,7 +51,7 @@ const et = (e, s) => {
|
|
|
51
51
|
options: i,
|
|
52
52
|
initialOptionsPart: y
|
|
53
53
|
});
|
|
54
|
-
const o = r.getState().cogsStateStore[p] || g[p], S = i?.modifyState ? i.modifyState(o) : o, [
|
|
54
|
+
const o = r.getState().cogsStateStore[p] || g[p], S = i?.modifyState ? i.modifyState(o) : o, [W, R] = De(
|
|
55
55
|
S,
|
|
56
56
|
{
|
|
57
57
|
stateKey: p,
|
|
@@ -67,7 +67,7 @@ const et = (e, s) => {
|
|
|
67
67
|
serverState: i?.serverState
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
|
-
return
|
|
70
|
+
return R;
|
|
71
71
|
};
|
|
72
72
|
function T(p, i) {
|
|
73
73
|
Ie({ stateKey: p, options: i, initialOptionsPart: y }), i.localStorage && Fe(p, i), se(p);
|
|
@@ -82,7 +82,7 @@ const et = (e, s) => {
|
|
|
82
82
|
setStateLog: Oe,
|
|
83
83
|
updateInitialStateGlobal: fe,
|
|
84
84
|
addValidationError: Re,
|
|
85
|
-
removeValidationError:
|
|
85
|
+
removeValidationError: B,
|
|
86
86
|
setServerSyncActions: je
|
|
87
87
|
} = r.getState(), pe = (e, s, h, g, y) => {
|
|
88
88
|
h?.log && console.log(
|
|
@@ -118,7 +118,7 @@ const et = (e, s) => {
|
|
|
118
118
|
return console.error("Error loading from localStorage:", s), null;
|
|
119
119
|
}
|
|
120
120
|
}, Fe = (e, s) => {
|
|
121
|
-
const h = r.getState().cogsStateStore[e], { sessionId: g } =
|
|
121
|
+
const h = r.getState().cogsStateStore[e], { sessionId: g } = Ee(), y = z(s?.localStorage?.key) ? s.localStorage.key(h) : s?.localStorage?.key;
|
|
122
122
|
if (y && g) {
|
|
123
123
|
const A = ie(
|
|
124
124
|
`${g}-${e}-${y}`
|
|
@@ -160,18 +160,18 @@ const et = (e, s) => {
|
|
|
160
160
|
switch (e) {
|
|
161
161
|
case "update":
|
|
162
162
|
return {
|
|
163
|
-
oldValue:
|
|
164
|
-
newValue:
|
|
163
|
+
oldValue: H(s, g),
|
|
164
|
+
newValue: H(h, g)
|
|
165
165
|
};
|
|
166
166
|
case "insert":
|
|
167
167
|
return {
|
|
168
168
|
oldValue: null,
|
|
169
169
|
// or undefined
|
|
170
|
-
newValue:
|
|
170
|
+
newValue: H(h, g)
|
|
171
171
|
};
|
|
172
172
|
case "cut":
|
|
173
173
|
return {
|
|
174
|
-
oldValue:
|
|
174
|
+
oldValue: H(s, g),
|
|
175
175
|
newValue: null
|
|
176
176
|
// or undefined
|
|
177
177
|
};
|
|
@@ -192,12 +192,12 @@ function De(e, {
|
|
|
192
192
|
dependencies: o,
|
|
193
193
|
serverState: S
|
|
194
194
|
} = {}) {
|
|
195
|
-
const [
|
|
196
|
-
let
|
|
197
|
-
const [m] = K(s ?? ge()), l = r.getState().stateLog[m], ee = Z(/* @__PURE__ */ new Set()),
|
|
195
|
+
const [W, R] = K({}), { sessionId: j } = Ee();
|
|
196
|
+
let G = !s;
|
|
197
|
+
const [m] = K(s ?? ge()), l = r.getState().stateLog[m], ee = Z(/* @__PURE__ */ new Set()), q = Z(p ?? ge()), M = Z(
|
|
198
198
|
null
|
|
199
199
|
);
|
|
200
|
-
|
|
200
|
+
M.current = Y(m) ?? null, ne(() => {
|
|
201
201
|
if (v && v.stateKey === m && v.path?.[0]) {
|
|
202
202
|
J(m, (n) => ({
|
|
203
203
|
...n,
|
|
@@ -214,22 +214,22 @@ function De(e, {
|
|
|
214
214
|
he(m, {
|
|
215
215
|
initialState: i
|
|
216
216
|
});
|
|
217
|
-
const t =
|
|
217
|
+
const t = M.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[m];
|
|
218
218
|
if (!(c && !L(c, i) || !c) && !a)
|
|
219
219
|
return;
|
|
220
220
|
let d = null;
|
|
221
221
|
const V = z(t?.localStorage?.key) ? t?.localStorage?.key(i) : t?.localStorage?.key;
|
|
222
|
-
V &&
|
|
222
|
+
V && j && (d = ie(`${j}-${m}-${V}`));
|
|
223
223
|
let w = i, $ = !1;
|
|
224
|
-
const x = a ? Date.now() : 0, N = d?.lastUpdated || 0,
|
|
225
|
-
a && x > N ? (w = t.serverState.data, $ = !0) : d && N >
|
|
224
|
+
const x = a ? Date.now() : 0, N = d?.lastUpdated || 0, O = d?.lastSyncedWithServer || 0;
|
|
225
|
+
a && x > N ? (w = t.serverState.data, $ = !0) : d && N > O && (w = d.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), Ae(
|
|
226
226
|
m,
|
|
227
227
|
i,
|
|
228
228
|
w,
|
|
229
229
|
X,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
), $ && V &&
|
|
230
|
+
q.current,
|
|
231
|
+
j
|
|
232
|
+
), $ && V && j && pe(w, m, t, j, Date.now()), se(m), (Array.isArray(T) ? T : [T || "component"]).includes("none") || R({});
|
|
233
233
|
}
|
|
234
234
|
}, [
|
|
235
235
|
i,
|
|
@@ -237,24 +237,24 @@ function De(e, {
|
|
|
237
237
|
S?.data,
|
|
238
238
|
...o || []
|
|
239
239
|
]), de(() => {
|
|
240
|
-
|
|
240
|
+
G && he(m, {
|
|
241
241
|
serverSync: h,
|
|
242
242
|
formElements: y,
|
|
243
243
|
initialState: i,
|
|
244
244
|
localStorage: g,
|
|
245
|
-
middleware:
|
|
245
|
+
middleware: M.current?.middleware
|
|
246
246
|
});
|
|
247
|
-
const t = `${m}////${
|
|
247
|
+
const t = `${m}////${q.current}`, n = r.getState().stateComponents.get(m) || {
|
|
248
248
|
components: /* @__PURE__ */ new Map()
|
|
249
249
|
};
|
|
250
250
|
return n.components.set(t, {
|
|
251
|
-
forceUpdate: () =>
|
|
251
|
+
forceUpdate: () => R({}),
|
|
252
252
|
paths: /* @__PURE__ */ new Set(),
|
|
253
253
|
deps: [],
|
|
254
254
|
depsFunction: A || void 0,
|
|
255
255
|
reactiveType: T ?? ["component", "deps"]
|
|
256
|
-
}), r.getState().stateComponents.set(m, n),
|
|
257
|
-
const a = `${m}////${
|
|
256
|
+
}), r.getState().stateComponents.set(m, n), R({}), () => {
|
|
257
|
+
const a = `${m}////${q.current}`;
|
|
258
258
|
n && (n.components.delete(a), n.components.size === 0 && r.getState().stateComponents.delete(m));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
@@ -266,135 +266,135 @@ function De(e, {
|
|
|
266
266
|
J(m, (f) => {
|
|
267
267
|
const d = z(t) ? t(f) : t, V = `${m}-${n.join(".")}`;
|
|
268
268
|
if (V) {
|
|
269
|
-
let
|
|
269
|
+
let _ = !1, I = r.getState().signalDomElements.get(V);
|
|
270
270
|
if ((!I || I.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
271
|
-
const k = n.slice(0, -1),
|
|
272
|
-
if (Array.isArray(
|
|
273
|
-
|
|
271
|
+
const k = n.slice(0, -1), C = H(d, k);
|
|
272
|
+
if (Array.isArray(C)) {
|
|
273
|
+
_ = !0;
|
|
274
274
|
const E = `${m}-${k.join(".")}`;
|
|
275
275
|
I = r.getState().signalDomElements.get(E);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
if (I) {
|
|
279
|
-
const k =
|
|
280
|
-
I.forEach(({ parentId:
|
|
281
|
-
const
|
|
282
|
-
`[data-parent-id="${
|
|
279
|
+
const k = _ ? H(d, n.slice(0, -1)) : H(d, n);
|
|
280
|
+
I.forEach(({ parentId: C, position: E, effect: b }) => {
|
|
281
|
+
const P = document.querySelector(
|
|
282
|
+
`[data-parent-id="${C}"]`
|
|
283
283
|
);
|
|
284
|
-
if (
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
const
|
|
288
|
-
|
|
284
|
+
if (P) {
|
|
285
|
+
const D = Array.from(P.childNodes);
|
|
286
|
+
if (D[E]) {
|
|
287
|
+
const F = b ? new Function("state", `return (${b})(state)`)(k) : k;
|
|
288
|
+
D[E].textContent = String(F);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
a.updateType === "update" && (c ||
|
|
295
|
-
(c ||
|
|
294
|
+
a.updateType === "update" && (c || M.current?.validation?.key) && n && B(
|
|
295
|
+
(c || M.current?.validation?.key) + "." + n.join(".")
|
|
296
296
|
);
|
|
297
297
|
const w = n.slice(0, n.length - 1);
|
|
298
|
-
a.updateType === "cut" &&
|
|
299
|
-
|
|
300
|
-
), a.updateType === "insert" &&
|
|
301
|
-
|
|
298
|
+
a.updateType === "cut" && M.current?.validation?.key && B(
|
|
299
|
+
M.current?.validation?.key + "." + w.join(".")
|
|
300
|
+
), a.updateType === "insert" && M.current?.validation?.key && Me(
|
|
301
|
+
M.current?.validation?.key + "." + w.join(".")
|
|
302
302
|
).filter(([I, k]) => {
|
|
303
|
-
let
|
|
304
|
-
if (I == w.join(".") &&
|
|
303
|
+
let C = I?.split(".").length;
|
|
304
|
+
if (I == w.join(".") && C == w.length - 1) {
|
|
305
305
|
let E = I + "." + w;
|
|
306
|
-
|
|
306
|
+
B(I), Re(E, k);
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
const $ = r.getState().stateComponents.get(m);
|
|
310
310
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", $), $) {
|
|
311
|
-
const
|
|
311
|
+
const _ = ue(f, d), I = new Set(_), k = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
312
312
|
for (const [
|
|
313
|
-
|
|
313
|
+
C,
|
|
314
314
|
E
|
|
315
315
|
] of $.components.entries()) {
|
|
316
|
-
let
|
|
317
|
-
const
|
|
318
|
-
if (console.log("component", E), !
|
|
319
|
-
if (
|
|
316
|
+
let b = !1;
|
|
317
|
+
const P = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
318
|
+
if (console.log("component", E), !P.includes("none")) {
|
|
319
|
+
if (P.includes("all")) {
|
|
320
320
|
E.forceUpdate();
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
324
|
-
for (const
|
|
325
|
-
let
|
|
323
|
+
if (P.includes("component") && ((E.paths.has(k) || E.paths.has("")) && (b = !0), !b))
|
|
324
|
+
for (const D of I) {
|
|
325
|
+
let F = D;
|
|
326
326
|
for (; ; ) {
|
|
327
|
-
if (E.paths.has(
|
|
328
|
-
|
|
327
|
+
if (E.paths.has(F)) {
|
|
328
|
+
b = !0;
|
|
329
329
|
break;
|
|
330
330
|
}
|
|
331
|
-
const ce =
|
|
331
|
+
const ce = F.lastIndexOf(".");
|
|
332
332
|
if (ce !== -1) {
|
|
333
|
-
const Se =
|
|
333
|
+
const Se = F.substring(
|
|
334
334
|
0,
|
|
335
335
|
ce
|
|
336
336
|
);
|
|
337
337
|
if (!isNaN(
|
|
338
|
-
Number(
|
|
338
|
+
Number(F.substring(ce + 1))
|
|
339
339
|
) && E.paths.has(Se)) {
|
|
340
|
-
|
|
340
|
+
b = !0;
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
F = Se;
|
|
344
344
|
} else
|
|
345
|
-
|
|
346
|
-
if (
|
|
345
|
+
F = "";
|
|
346
|
+
if (F === "")
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
|
-
if (
|
|
349
|
+
if (b) break;
|
|
350
350
|
}
|
|
351
|
-
if (!
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
typeof
|
|
351
|
+
if (!b && P.includes("deps") && E.depsFunction) {
|
|
352
|
+
const D = E.depsFunction(d);
|
|
353
|
+
let F = !1;
|
|
354
|
+
typeof D == "boolean" ? D && (F = !0) : L(E.deps, D) || (E.deps = D, F = !0), F && (b = !0);
|
|
355
355
|
}
|
|
356
|
-
|
|
356
|
+
b && E.forceUpdate();
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
const x = Date.now();
|
|
361
|
-
n = n.map((
|
|
362
|
-
const k = n.slice(0, -1),
|
|
363
|
-
return I === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (
|
|
361
|
+
n = n.map((_, I) => {
|
|
362
|
+
const k = n.slice(0, -1), C = H(d, k);
|
|
363
|
+
return I === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (C.length - 1).toString() : _;
|
|
364
364
|
});
|
|
365
|
-
const { oldValue: N, newValue:
|
|
365
|
+
const { oldValue: N, newValue: O } = Ue(
|
|
366
366
|
a.updateType,
|
|
367
367
|
f,
|
|
368
368
|
d,
|
|
369
369
|
n
|
|
370
|
-
),
|
|
370
|
+
), U = {
|
|
371
371
|
timeStamp: x,
|
|
372
372
|
stateKey: m,
|
|
373
373
|
path: n,
|
|
374
374
|
updateType: a.updateType,
|
|
375
375
|
status: "new",
|
|
376
376
|
oldValue: N,
|
|
377
|
-
newValue:
|
|
377
|
+
newValue: O
|
|
378
378
|
};
|
|
379
|
-
if (Oe(m, (
|
|
380
|
-
const k = [...
|
|
381
|
-
const
|
|
382
|
-
return
|
|
379
|
+
if (Oe(m, (_) => {
|
|
380
|
+
const k = [..._ ?? [], U].reduce((C, E) => {
|
|
381
|
+
const b = `${E.stateKey}:${JSON.stringify(E.path)}`, P = C.get(b);
|
|
382
|
+
return P ? (P.timeStamp = Math.max(P.timeStamp, E.timeStamp), P.newValue = E.newValue, P.oldValue = P.oldValue ?? E.oldValue, P.updateType = E.updateType) : C.set(b, { ...E }), C;
|
|
383
383
|
}, /* @__PURE__ */ new Map());
|
|
384
384
|
return Array.from(k.values());
|
|
385
385
|
}), pe(
|
|
386
386
|
d,
|
|
387
387
|
m,
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
),
|
|
388
|
+
M.current,
|
|
389
|
+
j
|
|
390
|
+
), M.current?.middleware && M.current.middleware({
|
|
391
391
|
updateLog: l,
|
|
392
|
-
update:
|
|
393
|
-
}),
|
|
394
|
-
const
|
|
392
|
+
update: U
|
|
393
|
+
}), M.current?.serverSync) {
|
|
394
|
+
const _ = r.getState().serverState[m], I = M.current?.serverSync;
|
|
395
395
|
je(m, {
|
|
396
396
|
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: d }),
|
|
397
|
-
rollBackState:
|
|
397
|
+
rollBackState: _,
|
|
398
398
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
399
399
|
status: "waiting"
|
|
400
400
|
});
|
|
@@ -407,16 +407,16 @@ function De(e, {
|
|
|
407
407
|
oe(
|
|
408
408
|
m,
|
|
409
409
|
X,
|
|
410
|
-
|
|
411
|
-
|
|
410
|
+
q.current,
|
|
411
|
+
j
|
|
412
412
|
)
|
|
413
413
|
), r.getState().cogsStateStore[m] || J(m, e), r.getState().initialStateGlobal[m] || fe(m, e));
|
|
414
|
-
const u =
|
|
414
|
+
const u = Te(() => oe(
|
|
415
415
|
m,
|
|
416
416
|
X,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
), [m,
|
|
417
|
+
q.current,
|
|
418
|
+
j
|
|
419
|
+
), [m, j]);
|
|
420
420
|
return [$e(m), u];
|
|
421
421
|
}
|
|
422
422
|
function oe(e, s, h, g) {
|
|
@@ -429,15 +429,15 @@ function oe(e, s, h, g) {
|
|
|
429
429
|
A++;
|
|
430
430
|
}, p = {
|
|
431
431
|
removeValidation: (v) => {
|
|
432
|
-
v?.validationKey &&
|
|
432
|
+
v?.validationKey && B(v.validationKey);
|
|
433
433
|
},
|
|
434
434
|
revertToInitialState: (v) => {
|
|
435
435
|
const o = r.getState().getInitialOptions(e)?.validation;
|
|
436
|
-
o?.key &&
|
|
436
|
+
o?.key && B(o?.key), v?.validationKey && B(v.validationKey);
|
|
437
437
|
const S = r.getState().initialStateGlobal[e];
|
|
438
438
|
r.getState().clearSelectedIndexesForState(e), y.clear(), A++;
|
|
439
|
-
const
|
|
440
|
-
|
|
439
|
+
const W = i(S, []), R = Y(e), j = z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${g}-${e}-${j}`;
|
|
440
|
+
G && localStorage.removeItem(G), re(e, W), J(e, S);
|
|
441
441
|
const m = r.getState().stateComponents.get(e);
|
|
442
442
|
return m && m.components.forEach((l) => {
|
|
443
443
|
l.forceUpdate();
|
|
@@ -450,15 +450,15 @@ function oe(e, s, h, g) {
|
|
|
450
450
|
s,
|
|
451
451
|
h,
|
|
452
452
|
g
|
|
453
|
-
), S = r.getState().initialStateGlobal[e],
|
|
454
|
-
return localStorage.getItem(
|
|
453
|
+
), S = r.getState().initialStateGlobal[e], W = Y(e), R = z(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, j = `${g}-${e}-${R}`;
|
|
454
|
+
return localStorage.getItem(j) && localStorage.removeItem(j), Ve(() => {
|
|
455
455
|
fe(e, v), re(e, o), J(e, v);
|
|
456
|
-
const
|
|
457
|
-
|
|
456
|
+
const G = r.getState().stateComponents.get(e);
|
|
457
|
+
G && G.components.forEach((m) => {
|
|
458
458
|
m.forceUpdate();
|
|
459
459
|
});
|
|
460
460
|
}), {
|
|
461
|
-
fetchId: (
|
|
461
|
+
fetchId: (G) => o.get()[G]
|
|
462
462
|
};
|
|
463
463
|
},
|
|
464
464
|
_initialState: r.getState().initialStateGlobal[e],
|
|
@@ -470,15 +470,15 @@ function oe(e, s, h, g) {
|
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
472
|
function i(v, o = [], S) {
|
|
473
|
-
const
|
|
474
|
-
y.get(
|
|
475
|
-
const
|
|
473
|
+
const W = o.map(String).join(".");
|
|
474
|
+
y.get(W);
|
|
475
|
+
const R = function() {
|
|
476
476
|
return r().getNestedState(e, o);
|
|
477
477
|
};
|
|
478
478
|
Object.keys(p).forEach((m) => {
|
|
479
|
-
|
|
479
|
+
R[m] = p[m];
|
|
480
480
|
});
|
|
481
|
-
const
|
|
481
|
+
const j = {
|
|
482
482
|
apply(m, l, ee) {
|
|
483
483
|
return console.log(
|
|
484
484
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${o.join(".")}`
|
|
@@ -554,7 +554,7 @@ function oe(e, s, h, g) {
|
|
|
554
554
|
}
|
|
555
555
|
};
|
|
556
556
|
if (l === "_status") {
|
|
557
|
-
const u = r.getState().getNestedState(e, o), t = r.getState().initialStateGlobal[e], n =
|
|
557
|
+
const u = r.getState().getNestedState(e, o), t = r.getState().initialStateGlobal[e], n = H(t, o);
|
|
558
558
|
return L(u, n) ? "fresh" : "stale";
|
|
559
559
|
}
|
|
560
560
|
if (l === "getStatus")
|
|
@@ -562,7 +562,7 @@ function oe(e, s, h, g) {
|
|
|
562
562
|
const u = r().getNestedState(
|
|
563
563
|
e,
|
|
564
564
|
o
|
|
565
|
-
), t = r.getState().initialStateGlobal[e], n =
|
|
565
|
+
), t = r.getState().initialStateGlobal[e], n = H(t, o);
|
|
566
566
|
return L(u, n) ? "fresh" : "stale";
|
|
567
567
|
};
|
|
568
568
|
if (l === "removeStorage")
|
|
@@ -618,11 +618,11 @@ function oe(e, s, h, g) {
|
|
|
618
618
|
}), w = Z(!0), $ = r().getNestedState(
|
|
619
619
|
e,
|
|
620
620
|
o
|
|
621
|
-
), x = $.length, N =
|
|
621
|
+
), x = $.length, N = Te(() => {
|
|
622
622
|
const I = Array.from(
|
|
623
623
|
{ length: d.endIndex - d.startIndex },
|
|
624
|
-
(
|
|
625
|
-
).filter((
|
|
624
|
+
(C, E) => d.startIndex + E
|
|
625
|
+
).filter((C) => C < x), k = I.map((C) => $[C]);
|
|
626
626
|
return i(k, o, {
|
|
627
627
|
...S,
|
|
628
628
|
validIndices: I
|
|
@@ -631,46 +631,53 @@ function oe(e, s, h, g) {
|
|
|
631
631
|
de(() => {
|
|
632
632
|
const I = f.current;
|
|
633
633
|
if (!I) return;
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
let k;
|
|
635
|
+
const C = () => {
|
|
636
|
+
const { scrollTop: b, clientHeight: P } = I, D = Math.max(
|
|
636
637
|
0,
|
|
637
|
-
Math.floor(
|
|
638
|
-
),
|
|
638
|
+
Math.floor(b / n) - a
|
|
639
|
+
), F = Math.min(
|
|
639
640
|
x,
|
|
640
|
-
Math.ceil((
|
|
641
|
+
Math.ceil((b + P) / n) + a
|
|
641
642
|
);
|
|
642
|
-
V({ startIndex:
|
|
643
|
-
},
|
|
644
|
-
|
|
643
|
+
V({ startIndex: D, endIndex: F });
|
|
644
|
+
}, E = () => {
|
|
645
|
+
const { scrollTop: b, scrollHeight: P, clientHeight: D } = I;
|
|
646
|
+
w.current = P - b - D < 5, clearTimeout(k), k = setTimeout(C, 10);
|
|
645
647
|
};
|
|
646
|
-
if (I.addEventListener("scroll",
|
|
648
|
+
if (I.addEventListener("scroll", E, {
|
|
647
649
|
passive: !0
|
|
648
|
-
}),
|
|
649
|
-
|
|
650
|
-
const E = Math.max(
|
|
650
|
+
}), c && x > 0) {
|
|
651
|
+
const b = Math.max(
|
|
651
652
|
0,
|
|
652
653
|
x - Math.ceil(I.clientHeight / n) - a
|
|
653
654
|
);
|
|
654
|
-
V({ startIndex:
|
|
655
|
-
I.scrollTop = I.scrollHeight;
|
|
656
|
-
}
|
|
655
|
+
V({ startIndex: b, endIndex: x }), requestAnimationFrame(() => {
|
|
656
|
+
I.scrollTop = I.scrollHeight, w.current = !0;
|
|
657
|
+
});
|
|
657
658
|
} else
|
|
658
|
-
|
|
659
|
+
C();
|
|
659
660
|
return () => {
|
|
660
|
-
I.removeEventListener("scroll",
|
|
661
|
+
clearTimeout(k), I.removeEventListener("scroll", E);
|
|
661
662
|
};
|
|
662
|
-
}, [x, n, a]), ne(() => {
|
|
663
|
-
if (c && f.current &&
|
|
663
|
+
}, [x, n, a, c]), ne(() => {
|
|
664
|
+
if (c && f.current && w.current) {
|
|
664
665
|
const I = f.current;
|
|
665
|
-
I.
|
|
666
|
+
I.scrollTo({
|
|
667
|
+
top: I.scrollHeight,
|
|
668
|
+
behavior: "smooth"
|
|
669
|
+
});
|
|
666
670
|
}
|
|
667
|
-
}, [x]);
|
|
668
|
-
const
|
|
671
|
+
}, [x, c]);
|
|
672
|
+
const O = ye(
|
|
669
673
|
(I = "smooth") => {
|
|
670
|
-
f.current &&
|
|
674
|
+
f.current && f.current.scrollTo({
|
|
675
|
+
top: f.current.scrollHeight,
|
|
676
|
+
behavior: I
|
|
677
|
+
});
|
|
671
678
|
},
|
|
672
679
|
[]
|
|
673
|
-
),
|
|
680
|
+
), U = ye(
|
|
674
681
|
(I, k = "smooth") => {
|
|
675
682
|
f.current && f.current.scrollTo({
|
|
676
683
|
top: I * n,
|
|
@@ -678,7 +685,7 @@ function oe(e, s, h, g) {
|
|
|
678
685
|
});
|
|
679
686
|
},
|
|
680
687
|
[n]
|
|
681
|
-
),
|
|
688
|
+
), _ = {
|
|
682
689
|
outer: {
|
|
683
690
|
ref: f,
|
|
684
691
|
style: {
|
|
@@ -701,9 +708,9 @@ function oe(e, s, h, g) {
|
|
|
701
708
|
};
|
|
702
709
|
return {
|
|
703
710
|
virtualState: N,
|
|
704
|
-
virtualizerProps:
|
|
705
|
-
scrollToBottom:
|
|
706
|
-
scrollToIndex:
|
|
711
|
+
virtualizerProps: _,
|
|
712
|
+
scrollToBottom: O,
|
|
713
|
+
scrollToIndex: U
|
|
707
714
|
};
|
|
708
715
|
};
|
|
709
716
|
if (l === "stateSort")
|
|
@@ -739,15 +746,15 @@ function oe(e, s, h, g) {
|
|
|
739
746
|
register: () => {
|
|
740
747
|
const [, x] = K({}), N = `${h}-${o.join(".")}-${c}`;
|
|
741
748
|
de(() => {
|
|
742
|
-
const
|
|
749
|
+
const O = `${e}////${N}`, U = r.getState().stateComponents.get(e) || {
|
|
743
750
|
components: /* @__PURE__ */ new Map()
|
|
744
751
|
};
|
|
745
|
-
return
|
|
752
|
+
return U.components.set(O, {
|
|
746
753
|
forceUpdate: () => x({}),
|
|
747
754
|
paths: /* @__PURE__ */ new Set([V.join(".")])
|
|
748
|
-
}), r.getState().stateComponents.set(e,
|
|
749
|
-
const
|
|
750
|
-
|
|
755
|
+
}), r.getState().stateComponents.set(e, U), () => {
|
|
756
|
+
const _ = r.getState().stateComponents.get(e);
|
|
757
|
+
_ && _.components.delete(O);
|
|
751
758
|
};
|
|
752
759
|
}, [e, N]);
|
|
753
760
|
},
|
|
@@ -871,15 +878,15 @@ function oe(e, s, h, g) {
|
|
|
871
878
|
return i(c.item, f, S);
|
|
872
879
|
};
|
|
873
880
|
}
|
|
874
|
-
const
|
|
875
|
-
if (!isNaN(Number(
|
|
881
|
+
const q = o[o.length - 1];
|
|
882
|
+
if (!isNaN(Number(q))) {
|
|
876
883
|
const u = o.slice(0, -1), t = r.getState().getNestedState(e, u);
|
|
877
884
|
if (Array.isArray(t) && l === "cut")
|
|
878
885
|
return () => te(
|
|
879
886
|
s,
|
|
880
887
|
u,
|
|
881
888
|
e,
|
|
882
|
-
Number(
|
|
889
|
+
Number(q)
|
|
883
890
|
);
|
|
884
891
|
}
|
|
885
892
|
if (l === "get")
|
|
@@ -961,20 +968,20 @@ function oe(e, s, h, g) {
|
|
|
961
968
|
$ = !0;
|
|
962
969
|
break;
|
|
963
970
|
}
|
|
964
|
-
let
|
|
965
|
-
for (;
|
|
966
|
-
const
|
|
967
|
-
if (w.paths.has(
|
|
971
|
+
let O = N.lastIndexOf(".");
|
|
972
|
+
for (; O !== -1; ) {
|
|
973
|
+
const U = N.substring(0, O);
|
|
974
|
+
if (w.paths.has(U)) {
|
|
968
975
|
$ = !0;
|
|
969
976
|
break;
|
|
970
977
|
}
|
|
971
|
-
const
|
|
972
|
-
|
|
978
|
+
const _ = N.substring(
|
|
979
|
+
O + 1
|
|
973
980
|
);
|
|
974
|
-
if (!isNaN(Number(
|
|
975
|
-
const I =
|
|
981
|
+
if (!isNaN(Number(_))) {
|
|
982
|
+
const I = U.lastIndexOf(".");
|
|
976
983
|
if (I !== -1) {
|
|
977
|
-
const k =
|
|
984
|
+
const k = U.substring(
|
|
978
985
|
0,
|
|
979
986
|
I
|
|
980
987
|
);
|
|
@@ -984,14 +991,14 @@ function oe(e, s, h, g) {
|
|
|
984
991
|
}
|
|
985
992
|
}
|
|
986
993
|
}
|
|
987
|
-
|
|
994
|
+
O = U.lastIndexOf(".");
|
|
988
995
|
}
|
|
989
996
|
if ($) break;
|
|
990
997
|
}
|
|
991
998
|
if (!$ && x.includes("deps") && w.depsFunction) {
|
|
992
999
|
const N = w.depsFunction(a);
|
|
993
|
-
let
|
|
994
|
-
typeof N == "boolean" ? N && (
|
|
1000
|
+
let O = !1;
|
|
1001
|
+
typeof N == "boolean" ? N && (O = !0) : L(w.deps, N) || (w.deps = N, O = !0), O && ($ = !0);
|
|
995
1002
|
}
|
|
996
1003
|
$ && w.forceUpdate();
|
|
997
1004
|
}
|
|
@@ -1005,12 +1012,12 @@ function oe(e, s, h, g) {
|
|
|
1005
1012
|
throw new Error("Zod schema not found");
|
|
1006
1013
|
if (!u?.key)
|
|
1007
1014
|
throw new Error("Validation key not found");
|
|
1008
|
-
|
|
1015
|
+
B(u.key);
|
|
1009
1016
|
const n = r.getState().cogsStateStore[e];
|
|
1010
1017
|
try {
|
|
1011
1018
|
const a = r.getState().getValidationErrors(u.key);
|
|
1012
1019
|
a && a.length > 0 && a.forEach(([f]) => {
|
|
1013
|
-
f && f.startsWith(u.key) &&
|
|
1020
|
+
f && f.startsWith(u.key) && B(f);
|
|
1014
1021
|
});
|
|
1015
1022
|
const c = u.zodSchema.safeParse(n);
|
|
1016
1023
|
return c.success ? !0 : (c.error.errors.forEach((d) => {
|
|
@@ -1083,14 +1090,14 @@ function oe(e, s, h, g) {
|
|
|
1083
1090
|
formOpts: t
|
|
1084
1091
|
}
|
|
1085
1092
|
);
|
|
1086
|
-
const
|
|
1087
|
-
return i(X,
|
|
1093
|
+
const M = [...o, l], X = r.getState().getNestedState(e, M);
|
|
1094
|
+
return i(X, M, S);
|
|
1088
1095
|
}
|
|
1089
|
-
},
|
|
1090
|
-
return y.set(
|
|
1091
|
-
proxy:
|
|
1096
|
+
}, G = new Proxy(R, j);
|
|
1097
|
+
return y.set(W, {
|
|
1098
|
+
proxy: G,
|
|
1092
1099
|
stateVersion: A
|
|
1093
|
-
}),
|
|
1100
|
+
}), G;
|
|
1094
1101
|
}
|
|
1095
1102
|
return i(
|
|
1096
1103
|
r.getState().getNestedState(e, [])
|
|
@@ -1136,14 +1143,14 @@ function Ge({
|
|
|
1136
1143
|
"state",
|
|
1137
1144
|
`return (${e._effect})(state)`
|
|
1138
1145
|
)(o);
|
|
1139
|
-
} catch (
|
|
1140
|
-
console.error("Error evaluating effect function during mount:",
|
|
1146
|
+
} catch (R) {
|
|
1147
|
+
console.error("Error evaluating effect function during mount:", R), S = o;
|
|
1141
1148
|
}
|
|
1142
1149
|
else
|
|
1143
1150
|
S = o;
|
|
1144
1151
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1145
|
-
const
|
|
1146
|
-
g.replaceWith(
|
|
1152
|
+
const W = document.createTextNode(String(S));
|
|
1153
|
+
g.replaceWith(W);
|
|
1147
1154
|
}, [e._stateKey, e._path.join("."), e._effect]), ae("span", {
|
|
1148
1155
|
ref: s,
|
|
1149
1156
|
style: { display: "none" },
|