cogsbox-state 0.5.338 → 0.5.339
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 +181 -196
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +24 -24
package/dist/CogsState.jsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as ht } from "react/jsx-runtime";
|
|
3
|
-
import { useState as Z, useRef as X, useEffect as
|
|
3
|
+
import { useState as Z, useRef as X, useEffect as ot, useLayoutEffect as lt, useMemo as vt, createElement as at, useSyncExternalStore as Pt, startTransition as _t, useCallback as Tt } from "react";
|
|
4
4
|
import { transformStateFunc as Mt, isDeepEqual as H, isFunction as q, getNestedValue as z, getDifferences as yt, debounce as jt } from "./utility.js";
|
|
5
|
-
import { pushFunc as mt, updateFn as
|
|
5
|
+
import { pushFunc as mt, updateFn as rt, cutFunc as ct, ValidationWrapper as Ot, FormControlComponent as Rt } from "./Functions.jsx";
|
|
6
6
|
import Ut from "superjson";
|
|
7
7
|
import { v4 as It } from "uuid";
|
|
8
8
|
import "zod";
|
|
@@ -22,13 +22,13 @@ function $t({
|
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: h
|
|
24
24
|
}) {
|
|
25
|
-
const S = et(t) || {}, I = h[t] || {},
|
|
25
|
+
const S = et(t) || {}, I = h[t] || {}, $ = o.getState().setInitialStateOptions, w = { ...I, ...S };
|
|
26
26
|
let p = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const a in c)
|
|
29
29
|
w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (p = !0, w[a] = c[a]), a == "initialState" && c[a] && w[a] !== c[a] && // Different references
|
|
30
30
|
!H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
|
|
31
|
-
p &&
|
|
31
|
+
p && $(t, w);
|
|
32
32
|
}
|
|
33
33
|
function ce(t, { formElements: c, validation: h }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: h };
|
|
@@ -45,7 +45,7 @@ const le = (t, c) => {
|
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, et(p) || o.getState().setInitialStateOptions(p, I[p]);
|
|
47
47
|
}), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
|
|
48
|
-
const
|
|
48
|
+
const $ = (p, a) => {
|
|
49
49
|
const [y] = Z(a?.componentId ?? It());
|
|
50
50
|
$t({
|
|
51
51
|
stateKey: p,
|
|
@@ -73,7 +73,7 @@ const le = (t, c) => {
|
|
|
73
73
|
function w(p, a) {
|
|
74
74
|
$t({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && zt(p, a), ft(p);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: $, setCogsOptions: w };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: dt,
|
|
79
79
|
setState: Q,
|
|
@@ -92,9 +92,9 @@ const le = (t, c) => {
|
|
|
92
92
|
h.localStorage?.key,
|
|
93
93
|
S
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const w = `${S}-${c}-${
|
|
95
|
+
const $ = q(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
|
|
96
|
+
if ($ && S) {
|
|
97
|
+
const w = `${S}-${c}-${$}`;
|
|
98
98
|
let p;
|
|
99
99
|
try {
|
|
100
100
|
p = gt(w)?.lastSyncedWithServer;
|
|
@@ -121,21 +121,21 @@ const le = (t, c) => {
|
|
|
121
121
|
}, zt = (t, c) => {
|
|
122
122
|
const h = o.getState().cogsStateStore[t], { sessionId: S } = Nt(), I = q(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
|
|
123
123
|
if (I && S) {
|
|
124
|
-
const
|
|
124
|
+
const $ = gt(
|
|
125
125
|
`${S}-${t}-${I}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return Q(t,
|
|
127
|
+
if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
|
|
128
|
+
return Q(t, $.state), ft(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, Ct = (t, c, h, S, I,
|
|
131
|
+
}, Ct = (t, c, h, S, I, $) => {
|
|
132
132
|
const w = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: ut(
|
|
135
135
|
t,
|
|
136
136
|
S,
|
|
137
137
|
I,
|
|
138
|
-
|
|
138
|
+
$
|
|
139
139
|
),
|
|
140
140
|
state: h
|
|
141
141
|
};
|
|
@@ -185,7 +185,7 @@ function qt(t, {
|
|
|
185
185
|
serverSync: h,
|
|
186
186
|
localStorage: S,
|
|
187
187
|
formElements: I,
|
|
188
|
-
reactiveDeps:
|
|
188
|
+
reactiveDeps: $,
|
|
189
189
|
reactiveType: w,
|
|
190
190
|
componentId: p,
|
|
191
191
|
initialState: a,
|
|
@@ -198,7 +198,7 @@ function qt(t, {
|
|
|
198
198
|
const [v] = Z(c ?? It()), l = o.getState().stateLog[v], st = X(/* @__PURE__ */ new Set()), J = X(p ?? It()), j = X(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
j.current = et(v) ?? null,
|
|
201
|
+
j.current = et(v) ?? null, ot(() => {
|
|
202
202
|
if (y && y.stateKey === v && y.path?.[0]) {
|
|
203
203
|
Q(v, (r) => ({
|
|
204
204
|
...r,
|
|
@@ -210,7 +210,7 @@ function qt(t, {
|
|
|
210
210
|
userId: y.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [y]),
|
|
213
|
+
}, [y]), ot(() => {
|
|
214
214
|
if (a) {
|
|
215
215
|
At(v, {
|
|
216
216
|
initialState: a
|
|
@@ -218,16 +218,16 @@ function qt(t, {
|
|
|
218
218
|
const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
|
|
219
219
|
if (!(i && !H(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
221
|
+
let u = null;
|
|
222
222
|
const E = q(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
-
E && U && (
|
|
223
|
+
E && U && (u = gt(`${U}-${v}-${E}`));
|
|
224
224
|
let T = a, A = !1;
|
|
225
|
-
const P = s ? Date.now() : 0,
|
|
226
|
-
s && P >
|
|
225
|
+
const P = s ? Date.now() : 0, N = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && P > N ? (T = e.serverState.data, A = !0) : u && N > V && (T = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Ct(
|
|
227
227
|
v,
|
|
228
228
|
a,
|
|
229
229
|
T,
|
|
230
|
-
|
|
230
|
+
nt,
|
|
231
231
|
J.current,
|
|
232
232
|
U
|
|
233
233
|
), A && E && U && kt(T, v, e, U, Date.now()), ft(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
|
|
@@ -252,41 +252,41 @@ function qt(t, {
|
|
|
252
252
|
forceUpdate: () => R({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: $ || void 0,
|
|
256
256
|
reactiveType: w ?? ["component", "deps"]
|
|
257
257
|
}), o.getState().stateComponents.set(v, r), R({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(v));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const nt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const
|
|
264
|
-
st.current.add(
|
|
263
|
+
const u = `${v}-${r.join(".")}`;
|
|
264
|
+
st.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const g = o.getState();
|
|
267
|
-
Q(v, (
|
|
268
|
-
const E = q(e) ? e(
|
|
267
|
+
Q(v, (u) => {
|
|
268
|
+
const E = q(e) ? e(u) : e, T = `${v}-${r.join(".")}`;
|
|
269
269
|
if (T) {
|
|
270
|
-
let M = !1,
|
|
271
|
-
if ((!
|
|
270
|
+
let M = !1, k = g.signalDomElements.get(T);
|
|
271
|
+
if ((!k || k.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
272
|
const O = r.slice(0, -1), W = z(E, O);
|
|
273
273
|
if (Array.isArray(W)) {
|
|
274
274
|
M = !0;
|
|
275
|
-
const
|
|
276
|
-
|
|
275
|
+
const f = `${v}-${O.join(".")}`;
|
|
276
|
+
k = g.signalDomElements.get(f);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
279
|
+
if (k) {
|
|
280
280
|
const O = M ? z(E, r.slice(0, -1)) : z(E, r);
|
|
281
|
-
|
|
281
|
+
k.forEach(({ parentId: W, position: f, effect: b }) => {
|
|
282
282
|
const C = document.querySelector(
|
|
283
283
|
`[data-parent-id="${W}"]`
|
|
284
284
|
);
|
|
285
285
|
if (C) {
|
|
286
286
|
const _ = Array.from(C.childNodes);
|
|
287
|
-
if (_[
|
|
288
|
-
const x =
|
|
289
|
-
_[
|
|
287
|
+
if (_[f]) {
|
|
288
|
+
const x = b ? new Function("state", `return (${b})(state)`)(O) : O;
|
|
289
|
+
_[f].textContent = String(x);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
@@ -300,33 +300,33 @@ function qt(t, {
|
|
|
300
300
|
j.current?.validation?.key + "." + A.join(".")
|
|
301
301
|
), s.updateType === "insert" && j.current?.validation?.key && Wt(
|
|
302
302
|
j.current?.validation?.key + "." + A.join(".")
|
|
303
|
-
).filter(([
|
|
304
|
-
let W =
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
B(
|
|
303
|
+
).filter(([k, O]) => {
|
|
304
|
+
let W = k?.split(".").length;
|
|
305
|
+
if (k == A.join(".") && W == A.length - 1) {
|
|
306
|
+
let f = k + "." + A;
|
|
307
|
+
B(k), Gt(f, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
const P = g.stateComponents.get(v);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
|
|
312
|
-
const M = yt(
|
|
312
|
+
const M = yt(u, E), k = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
W,
|
|
315
|
-
|
|
315
|
+
f
|
|
316
316
|
] of P.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const C = Array.isArray(
|
|
319
|
-
if (console.log("component",
|
|
317
|
+
let b = !1;
|
|
318
|
+
const C = Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", f), !C.includes("none")) {
|
|
320
320
|
if (C.includes("all")) {
|
|
321
|
-
|
|
321
|
+
f.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (C.includes("component") && ((
|
|
325
|
-
for (const _ of
|
|
324
|
+
if (C.includes("component") && ((f.paths.has(O) || f.paths.has("")) && (b = !0), !b))
|
|
325
|
+
for (const _ of k) {
|
|
326
326
|
let x = _;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (f.paths.has(x)) {
|
|
329
|
+
b = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
332
|
const Y = x.lastIndexOf(".");
|
|
@@ -337,8 +337,8 @@ function qt(t, {
|
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
339
|
Number(x.substring(Y + 1))
|
|
340
|
-
) &&
|
|
341
|
-
|
|
340
|
+
) && f.paths.has(K)) {
|
|
341
|
+
b = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
344
|
x = K;
|
|
@@ -347,34 +347,34 @@ function qt(t, {
|
|
|
347
347
|
if (x === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (b) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const _ =
|
|
352
|
+
if (!b && C.includes("deps") && f.depsFunction) {
|
|
353
|
+
const _ = f.depsFunction(E);
|
|
354
354
|
let x = !1;
|
|
355
|
-
typeof _ == "boolean" ? _ && (x = !0) : H(
|
|
355
|
+
typeof _ == "boolean" ? _ && (x = !0) : H(f.deps, _) || (f.deps = _, x = !0), x && (b = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
b && f.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((M,
|
|
361
|
+
const N = Date.now();
|
|
362
|
+
r = r.map((M, k) => {
|
|
363
363
|
const O = r.slice(0, -1), W = z(E, O);
|
|
364
|
-
return
|
|
364
|
+
return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: V, newValue: D } = Bt(
|
|
367
367
|
s.updateType,
|
|
368
|
-
|
|
368
|
+
u,
|
|
369
369
|
E,
|
|
370
370
|
r
|
|
371
371
|
), F = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: N,
|
|
373
373
|
stateKey: v,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: V,
|
|
378
378
|
newValue: D
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
@@ -386,14 +386,14 @@ function qt(t, {
|
|
|
386
386
|
g.insertShadowArrayElement(v, M, D);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
g.removeShadowArrayElement(v,
|
|
389
|
+
const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
+
g.removeShadowArrayElement(v, k, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
if (Lt(v, (M) => {
|
|
394
|
-
const O = [...M ?? [], F].reduce((W,
|
|
395
|
-
const
|
|
396
|
-
return C ? (C.timeStamp = Math.max(C.timeStamp,
|
|
394
|
+
const O = [...M ?? [], F].reduce((W, f) => {
|
|
395
|
+
const b = `${f.stateKey}:${JSON.stringify(f.path)}`, C = W.get(b);
|
|
396
|
+
return C ? (C.timeStamp = Math.max(C.timeStamp, f.timeStamp), C.newValue = f.newValue, C.oldValue = C.oldValue ?? f.oldValue, C.updateType = f.updateType) : W.set(b, { ...f }), W;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(O.values());
|
|
399
399
|
}), kt(
|
|
@@ -405,11 +405,11 @@ function qt(t, {
|
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: F
|
|
407
407
|
}), j.current?.serverSync) {
|
|
408
|
-
const M = g.serverState[v],
|
|
408
|
+
const M = g.serverState[v], k = j.current?.serverSync;
|
|
409
409
|
Ht(v, {
|
|
410
|
-
syncKey: typeof
|
|
410
|
+
syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
412
|
+
actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
@@ -420,14 +420,14 @@ function qt(t, {
|
|
|
420
420
|
v,
|
|
421
421
|
ut(
|
|
422
422
|
v,
|
|
423
|
-
|
|
423
|
+
nt,
|
|
424
424
|
J.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
427
|
), o.getState().cogsStateStore[v] || Q(v, t), o.getState().initialStateGlobal[v] || pt(v, t));
|
|
428
428
|
const d = vt(() => ut(
|
|
429
429
|
v,
|
|
430
|
-
|
|
430
|
+
nt,
|
|
431
431
|
J.current,
|
|
432
432
|
U
|
|
433
433
|
), [v, U]);
|
|
@@ -435,12 +435,12 @@ function qt(t, {
|
|
|
435
435
|
}
|
|
436
436
|
function ut(t, c, h, S) {
|
|
437
437
|
const I = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
438
|
+
let $ = 0;
|
|
439
439
|
const w = (y) => {
|
|
440
440
|
const n = y.join(".");
|
|
441
441
|
for (const [m] of I)
|
|
442
442
|
(m === n || m.startsWith(n + ".")) && I.delete(m);
|
|
443
|
-
|
|
443
|
+
$++;
|
|
444
444
|
}, p = {
|
|
445
445
|
removeValidation: (y) => {
|
|
446
446
|
y?.validationKey && B(y.validationKey);
|
|
@@ -449,7 +449,7 @@ function ut(t, c, h, S) {
|
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && B(n?.key), y?.validationKey && B(y.validationKey);
|
|
451
451
|
const m = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), I.clear(),
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), I.clear(), $++;
|
|
453
453
|
const L = a(m, []), R = et(t), U = q(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
|
|
454
454
|
G && localStorage.removeItem(G), dt(t, L), Q(t, m);
|
|
455
455
|
const v = o.getState().stateComponents.get(t);
|
|
@@ -458,7 +458,7 @@ function ut(t, c, h, S) {
|
|
|
458
458
|
}), m;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (y) => {
|
|
461
|
-
I.clear(),
|
|
461
|
+
I.clear(), $++;
|
|
462
462
|
const n = ut(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
@@ -553,13 +553,13 @@ function ut(t, c, h, S) {
|
|
|
553
553
|
try {
|
|
554
554
|
const i = await e.action(r);
|
|
555
555
|
if (i && !i.success && i.errors && s) {
|
|
556
|
-
o.getState().removeValidationError(s), i.errors.forEach((
|
|
557
|
-
const E = [s, ...
|
|
558
|
-
o.getState().addValidationError(E,
|
|
556
|
+
o.getState().removeValidationError(s), i.errors.forEach((u) => {
|
|
557
|
+
const E = [s, ...u.path].join(".");
|
|
558
|
+
o.getState().addValidationError(E, u.message);
|
|
559
559
|
});
|
|
560
560
|
const g = o.getState().stateComponents.get(t);
|
|
561
|
-
g && g.components.forEach((
|
|
562
|
-
|
|
561
|
+
g && g.components.forEach((u) => {
|
|
562
|
+
u.forceUpdate();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
565
|
return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
|
|
@@ -621,64 +621,49 @@ function ut(t, c, h, S) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e, g = X(null), [
|
|
624
|
+
} = e, g = X(null), [u, E] = Z({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
627
|
}), T = X(i), [A, P] = Z(0);
|
|
628
|
-
|
|
629
|
-
P((
|
|
628
|
+
ot(() => o.getState().subscribeToShadowState(t, () => {
|
|
629
|
+
P((b) => b + 1);
|
|
630
630
|
}), [t]);
|
|
631
|
-
const
|
|
631
|
+
const N = o().getNestedState(
|
|
632
632
|
t,
|
|
633
633
|
n
|
|
634
|
-
),
|
|
635
|
-
const
|
|
636
|
-
let
|
|
634
|
+
), V = N.length, { totalHeight: D, positions: F } = vt(() => {
|
|
635
|
+
const f = o.getState().getShadowMetadata(t, n) || [];
|
|
636
|
+
let b = 0;
|
|
637
637
|
const C = [];
|
|
638
|
-
for (let _ = 0; _ <
|
|
639
|
-
C[_] =
|
|
640
|
-
const x =
|
|
641
|
-
|
|
638
|
+
for (let _ = 0; _ < V; _++) {
|
|
639
|
+
C[_] = b;
|
|
640
|
+
const x = f[_]?.virtualizer?.itemHeight;
|
|
641
|
+
b += x || r;
|
|
642
642
|
}
|
|
643
|
-
return { totalHeight:
|
|
643
|
+
return { totalHeight: b, positions: C };
|
|
644
644
|
}, [
|
|
645
|
-
|
|
645
|
+
V,
|
|
646
646
|
t,
|
|
647
647
|
n.join("."),
|
|
648
648
|
r,
|
|
649
649
|
A
|
|
650
650
|
]), M = vt(() => {
|
|
651
|
-
const
|
|
652
|
-
{ length:
|
|
653
|
-
(x, Y) =>
|
|
654
|
-
), _ = C.map((x) =>
|
|
651
|
+
const f = Math.max(0, u.startIndex), b = Math.min(V, u.endIndex), C = Array.from(
|
|
652
|
+
{ length: b - f },
|
|
653
|
+
(x, Y) => f + Y
|
|
654
|
+
), _ = C.map((x) => N[x]);
|
|
655
655
|
return a(_, n, {
|
|
656
656
|
...m,
|
|
657
657
|
validIndices: C
|
|
658
658
|
});
|
|
659
|
-
}, [
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
);
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
0,
|
|
668
|
-
$ - k - s
|
|
669
|
-
),
|
|
670
|
-
endIndex: $
|
|
671
|
-
}), setTimeout(() => {
|
|
672
|
-
u.scrollTop = u.scrollHeight;
|
|
673
|
-
}, 100);
|
|
674
|
-
}
|
|
675
|
-
}, [$]), lt(() => {
|
|
676
|
-
const u = g.current;
|
|
677
|
-
if (!u) return;
|
|
678
|
-
const k = u.scrollHeight - u.scrollTop - u.clientHeight < 1, C = () => {
|
|
679
|
-
if (!u) return;
|
|
680
|
-
const { scrollTop: x, clientHeight: Y } = u;
|
|
681
|
-
let K = 0, it = $ - 1;
|
|
659
|
+
}, [u.startIndex, u.endIndex, N, V]);
|
|
660
|
+
lt(() => {
|
|
661
|
+
const f = g.current;
|
|
662
|
+
if (!f) return;
|
|
663
|
+
const b = f.scrollHeight - f.scrollTop - f.clientHeight < r, C = () => {
|
|
664
|
+
if (!f) return;
|
|
665
|
+
const { scrollTop: x, clientHeight: Y } = f;
|
|
666
|
+
let K = 0, it = V - 1;
|
|
682
667
|
for (; K <= it; ) {
|
|
683
668
|
const St = Math.floor((K + it) / 2);
|
|
684
669
|
F[St] < x ? K = St + 1 : it = St - 1;
|
|
@@ -686,31 +671,31 @@ function ut(t, c, h, S) {
|
|
|
686
671
|
const wt = Math.max(0, it - s);
|
|
687
672
|
let tt = wt;
|
|
688
673
|
const xt = x + Y;
|
|
689
|
-
for (; tt <
|
|
674
|
+
for (; tt < V && F[tt] < xt; )
|
|
690
675
|
tt++;
|
|
691
|
-
tt = Math.min(
|
|
676
|
+
tt = Math.min(V, tt + s), E({ startIndex: wt, endIndex: tt });
|
|
692
677
|
}, _ = () => {
|
|
693
|
-
T.current =
|
|
678
|
+
T.current = f.scrollHeight - f.scrollTop - f.clientHeight < 1, C();
|
|
694
679
|
};
|
|
695
|
-
return
|
|
680
|
+
return f.addEventListener("scroll", _, {
|
|
696
681
|
passive: !0
|
|
697
|
-
}), i && (T.current ||
|
|
698
|
-
|
|
682
|
+
}), i && (T.current || b) && (f.scrollTop = f.scrollHeight), C(), () => {
|
|
683
|
+
f.removeEventListener("scroll", _);
|
|
699
684
|
};
|
|
700
|
-
}, [
|
|
701
|
-
const
|
|
702
|
-
(
|
|
685
|
+
}, [V, F, D, i]);
|
|
686
|
+
const k = Tt(
|
|
687
|
+
(f = "smooth") => {
|
|
703
688
|
g.current && (T.current = !0, g.current.scrollTo({
|
|
704
689
|
top: g.current.scrollHeight,
|
|
705
|
-
behavior:
|
|
690
|
+
behavior: f
|
|
706
691
|
}));
|
|
707
692
|
},
|
|
708
693
|
[]
|
|
709
694
|
), O = Tt(
|
|
710
|
-
(
|
|
711
|
-
g.current && F[
|
|
712
|
-
top: F[
|
|
713
|
-
behavior:
|
|
695
|
+
(f, b = "smooth") => {
|
|
696
|
+
g.current && F[f] !== void 0 && (T.current = !1, g.current.scrollTo({
|
|
697
|
+
top: F[f],
|
|
698
|
+
behavior: b
|
|
714
699
|
}));
|
|
715
700
|
},
|
|
716
701
|
[F]
|
|
@@ -727,25 +712,25 @@ function ut(t, c, h, S) {
|
|
|
727
712
|
},
|
|
728
713
|
list: {
|
|
729
714
|
style: {
|
|
730
|
-
transform: `translateY(${F[
|
|
715
|
+
transform: `translateY(${F[u.startIndex] || 0}px)`
|
|
731
716
|
}
|
|
732
717
|
}
|
|
733
718
|
};
|
|
734
719
|
return {
|
|
735
720
|
virtualState: M,
|
|
736
721
|
virtualizerProps: W,
|
|
737
|
-
scrollToBottom:
|
|
722
|
+
scrollToBottom: k,
|
|
738
723
|
scrollToIndex: O
|
|
739
724
|
};
|
|
740
725
|
};
|
|
741
726
|
if (l === "stateSort")
|
|
742
727
|
return (e) => {
|
|
743
728
|
const s = [...d()].sort(
|
|
744
|
-
(
|
|
745
|
-
), i = s.map(({ item:
|
|
729
|
+
(u, E) => e(u.item, E.item)
|
|
730
|
+
), i = s.map(({ item: u }) => u), g = {
|
|
746
731
|
...m,
|
|
747
732
|
validIndices: s.map(
|
|
748
|
-
({ originalIndex:
|
|
733
|
+
({ originalIndex: u }) => u
|
|
749
734
|
)
|
|
750
735
|
};
|
|
751
736
|
return a(i, n, g);
|
|
@@ -753,11 +738,11 @@ function ut(t, c, h, S) {
|
|
|
753
738
|
if (l === "stateFilter")
|
|
754
739
|
return (e) => {
|
|
755
740
|
const s = d().filter(
|
|
756
|
-
({ item:
|
|
757
|
-
), i = s.map(({ item:
|
|
741
|
+
({ item: u }, E) => e(u, E)
|
|
742
|
+
), i = s.map(({ item: u }) => u), g = {
|
|
758
743
|
...m,
|
|
759
744
|
validIndices: s.map(
|
|
760
|
-
({ originalIndex:
|
|
745
|
+
({ originalIndex: u }) => u
|
|
761
746
|
)
|
|
762
747
|
};
|
|
763
748
|
return a(i, n, g);
|
|
@@ -766,22 +751,22 @@ function ut(t, c, h, S) {
|
|
|
766
751
|
return (e) => {
|
|
767
752
|
const r = o.getState().getNestedState(t, n);
|
|
768
753
|
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
769
|
-
const
|
|
770
|
-
return e(
|
|
754
|
+
const u = r[i], E = [...n, i.toString()], T = a(u, E, m);
|
|
755
|
+
return e(u, T, {
|
|
771
756
|
register: () => {
|
|
772
|
-
const [, P] = Z({}),
|
|
757
|
+
const [, P] = Z({}), N = `${h}-${n.join(".")}-${i}`;
|
|
773
758
|
lt(() => {
|
|
774
|
-
const
|
|
759
|
+
const V = `${t}////${N}`, D = o.getState().stateComponents.get(t) || {
|
|
775
760
|
components: /* @__PURE__ */ new Map()
|
|
776
761
|
};
|
|
777
|
-
return D.components.set(
|
|
762
|
+
return D.components.set(V, {
|
|
778
763
|
forceUpdate: () => P({}),
|
|
779
764
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
780
765
|
}), o.getState().stateComponents.set(t, D), () => {
|
|
781
766
|
const F = o.getState().stateComponents.get(t);
|
|
782
|
-
F && F.components.delete(
|
|
767
|
+
F && F.components.delete(V);
|
|
783
768
|
};
|
|
784
|
-
}, [t,
|
|
769
|
+
}, [t, N]);
|
|
785
770
|
},
|
|
786
771
|
index: g,
|
|
787
772
|
originalIndex: i
|
|
@@ -795,7 +780,7 @@ function ut(t, c, h, S) {
|
|
|
795
780
|
return (e) => y.map((s, i) => {
|
|
796
781
|
let g;
|
|
797
782
|
m?.validIndices && m.validIndices[i] !== void 0 ? g = m.validIndices[i] : g = i;
|
|
798
|
-
const
|
|
783
|
+
const u = [...n, g.toString()], E = a(s, u, m);
|
|
799
784
|
return e(
|
|
800
785
|
s,
|
|
801
786
|
E,
|
|
@@ -818,14 +803,14 @@ function ut(t, c, h, S) {
|
|
|
818
803
|
return (e) => {
|
|
819
804
|
const r = o.getState().getNestedState(t, n);
|
|
820
805
|
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
821
|
-
const
|
|
806
|
+
const u = r[i], E = [...n, i.toString()], T = a(u, E, m), A = `${h}-${n.join(".")}-${i}`;
|
|
822
807
|
return at(Zt, {
|
|
823
808
|
key: i,
|
|
824
809
|
stateKey: t,
|
|
825
810
|
itemComponentId: A,
|
|
826
811
|
itemPath: E,
|
|
827
812
|
children: e(
|
|
828
|
-
|
|
813
|
+
u,
|
|
829
814
|
T,
|
|
830
815
|
g,
|
|
831
816
|
r,
|
|
@@ -839,7 +824,7 @@ function ut(t, c, h, S) {
|
|
|
839
824
|
if (l === "stateFlattenOn")
|
|
840
825
|
return (e) => {
|
|
841
826
|
const r = y;
|
|
842
|
-
I.clear(),
|
|
827
|
+
I.clear(), $++;
|
|
843
828
|
const s = r.flatMap(
|
|
844
829
|
(i) => i[e] ?? []
|
|
845
830
|
);
|
|
@@ -869,23 +854,23 @@ function ut(t, c, h, S) {
|
|
|
869
854
|
if (l === "uniqueInsert")
|
|
870
855
|
return (e, r, s) => {
|
|
871
856
|
const i = o.getState().getNestedState(t, n), g = q(e) ? e(i) : e;
|
|
872
|
-
let
|
|
857
|
+
let u = null;
|
|
873
858
|
if (!i.some((T) => {
|
|
874
859
|
if (r) {
|
|
875
860
|
const P = r.every(
|
|
876
|
-
(
|
|
861
|
+
(N) => H(T[N], g[N])
|
|
877
862
|
);
|
|
878
|
-
return P && (
|
|
863
|
+
return P && (u = T), P;
|
|
879
864
|
}
|
|
880
865
|
const A = H(T, g);
|
|
881
|
-
return A && (
|
|
866
|
+
return A && (u = T), A;
|
|
882
867
|
}))
|
|
883
868
|
w(n), mt(c, g, n, t);
|
|
884
|
-
else if (s &&
|
|
885
|
-
const T = s(
|
|
886
|
-
(P) => H(P,
|
|
869
|
+
else if (s && u) {
|
|
870
|
+
const T = s(u), A = i.map(
|
|
871
|
+
(P) => H(P, u) ? T : P
|
|
887
872
|
);
|
|
888
|
-
w(n),
|
|
873
|
+
w(n), rt(c, A, n);
|
|
889
874
|
}
|
|
890
875
|
};
|
|
891
876
|
if (l === "cut")
|
|
@@ -909,7 +894,7 @@ function ut(t, c, h, S) {
|
|
|
909
894
|
if (l === "stateFind")
|
|
910
895
|
return (e) => {
|
|
911
896
|
const s = d().find(
|
|
912
|
-
({ item: g },
|
|
897
|
+
({ item: g }, u) => e(g, u)
|
|
913
898
|
);
|
|
914
899
|
if (!s) return;
|
|
915
900
|
const i = [...n, s.originalIndex.toString()];
|
|
@@ -918,7 +903,7 @@ function ut(t, c, h, S) {
|
|
|
918
903
|
if (l === "findWith")
|
|
919
904
|
return (e, r) => {
|
|
920
905
|
const i = d().find(
|
|
921
|
-
({ item:
|
|
906
|
+
({ item: u }) => u[e] === r
|
|
922
907
|
);
|
|
923
908
|
if (!i) return;
|
|
924
909
|
const g = [...n, i.originalIndex.toString()];
|
|
@@ -970,7 +955,7 @@ function ut(t, c, h, S) {
|
|
|
970
955
|
const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
|
|
971
956
|
d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
|
|
972
957
|
const i = o.getState().getNestedState(t, [...e]);
|
|
973
|
-
|
|
958
|
+
rt(c, i, e), w(e);
|
|
974
959
|
};
|
|
975
960
|
if (l === "toggleSelected")
|
|
976
961
|
return () => {
|
|
@@ -981,7 +966,7 @@ function ut(t, c, h, S) {
|
|
|
981
966
|
s === e ? void 0 : e
|
|
982
967
|
);
|
|
983
968
|
const i = o.getState().getNestedState(t, [...d]);
|
|
984
|
-
|
|
969
|
+
rt(c, i, d), w(d);
|
|
985
970
|
};
|
|
986
971
|
if (n.length == 0) {
|
|
987
972
|
if (l === "applyJsonPatch")
|
|
@@ -997,7 +982,7 @@ function ut(t, c, h, S) {
|
|
|
997
982
|
);
|
|
998
983
|
const i = o.getState().stateComponents.get(t);
|
|
999
984
|
if (i) {
|
|
1000
|
-
const g = yt(e, s),
|
|
985
|
+
const g = yt(e, s), u = new Set(g);
|
|
1001
986
|
for (const [
|
|
1002
987
|
E,
|
|
1003
988
|
T
|
|
@@ -1010,42 +995,42 @@ function ut(t, c, h, S) {
|
|
|
1010
995
|
continue;
|
|
1011
996
|
}
|
|
1012
997
|
if (P.includes("component") && (T.paths.has("") && (A = !0), !A))
|
|
1013
|
-
for (const
|
|
1014
|
-
if (T.paths.has(
|
|
998
|
+
for (const N of u) {
|
|
999
|
+
if (T.paths.has(N)) {
|
|
1015
1000
|
A = !0;
|
|
1016
1001
|
break;
|
|
1017
1002
|
}
|
|
1018
|
-
let
|
|
1019
|
-
for (;
|
|
1020
|
-
const D =
|
|
1003
|
+
let V = N.lastIndexOf(".");
|
|
1004
|
+
for (; V !== -1; ) {
|
|
1005
|
+
const D = N.substring(0, V);
|
|
1021
1006
|
if (T.paths.has(D)) {
|
|
1022
1007
|
A = !0;
|
|
1023
1008
|
break;
|
|
1024
1009
|
}
|
|
1025
|
-
const F =
|
|
1026
|
-
|
|
1010
|
+
const F = N.substring(
|
|
1011
|
+
V + 1
|
|
1027
1012
|
);
|
|
1028
1013
|
if (!isNaN(Number(F))) {
|
|
1029
1014
|
const M = D.lastIndexOf(".");
|
|
1030
1015
|
if (M !== -1) {
|
|
1031
|
-
const
|
|
1016
|
+
const k = D.substring(
|
|
1032
1017
|
0,
|
|
1033
1018
|
M
|
|
1034
1019
|
);
|
|
1035
|
-
if (T.paths.has(
|
|
1020
|
+
if (T.paths.has(k)) {
|
|
1036
1021
|
A = !0;
|
|
1037
1022
|
break;
|
|
1038
1023
|
}
|
|
1039
1024
|
}
|
|
1040
1025
|
}
|
|
1041
|
-
|
|
1026
|
+
V = D.lastIndexOf(".");
|
|
1042
1027
|
}
|
|
1043
1028
|
if (A) break;
|
|
1044
1029
|
}
|
|
1045
1030
|
if (!A && P.includes("deps") && T.depsFunction) {
|
|
1046
|
-
const
|
|
1047
|
-
let
|
|
1048
|
-
typeof
|
|
1031
|
+
const N = T.depsFunction(s);
|
|
1032
|
+
let V = !1;
|
|
1033
|
+
typeof N == "boolean" ? N && (V = !0) : H(T.deps, N) || (T.deps = N, V = !0), V && (A = !0);
|
|
1049
1034
|
}
|
|
1050
1035
|
A && T.forceUpdate();
|
|
1051
1036
|
}
|
|
@@ -1067,8 +1052,8 @@ function ut(t, c, h, S) {
|
|
|
1067
1052
|
g && g.startsWith(d.key) && B(g);
|
|
1068
1053
|
});
|
|
1069
1054
|
const i = d.zodSchema.safeParse(r);
|
|
1070
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
1071
|
-
const E =
|
|
1055
|
+
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1056
|
+
const E = u.path, T = u.message, A = [d.key, ...E].join(".");
|
|
1072
1057
|
e(A, T);
|
|
1073
1058
|
}), ft(t), !1);
|
|
1074
1059
|
} catch (s) {
|
|
@@ -1115,12 +1100,12 @@ function ut(t, c, h, S) {
|
|
|
1115
1100
|
return (d, e) => {
|
|
1116
1101
|
if (e?.debounce)
|
|
1117
1102
|
jt(() => {
|
|
1118
|
-
|
|
1103
|
+
rt(c, d, n, "");
|
|
1119
1104
|
const r = o.getState().getNestedState(t, n);
|
|
1120
1105
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1121
1106
|
}, e.debounce);
|
|
1122
1107
|
else {
|
|
1123
|
-
|
|
1108
|
+
rt(c, d, n, "");
|
|
1124
1109
|
const r = o.getState().getNestedState(t, n);
|
|
1125
1110
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1126
1111
|
}
|
|
@@ -1137,13 +1122,13 @@ function ut(t, c, h, S) {
|
|
|
1137
1122
|
formOpts: e
|
|
1138
1123
|
}
|
|
1139
1124
|
);
|
|
1140
|
-
const j = [...n, l],
|
|
1141
|
-
return a(
|
|
1125
|
+
const j = [...n, l], nt = o.getState().getNestedState(t, j);
|
|
1126
|
+
return a(nt, j, m);
|
|
1142
1127
|
}
|
|
1143
1128
|
}, G = new Proxy(R, U);
|
|
1144
1129
|
return I.set(L, {
|
|
1145
1130
|
proxy: G,
|
|
1146
|
-
stateVersion:
|
|
1131
|
+
stateVersion: $
|
|
1147
1132
|
}), G;
|
|
1148
1133
|
}
|
|
1149
1134
|
return a(
|
|
@@ -1162,14 +1147,14 @@ function Jt({
|
|
|
1162
1147
|
h,
|
|
1163
1148
|
t._path
|
|
1164
1149
|
).stateMapNoRender(
|
|
1165
|
-
(I,
|
|
1150
|
+
(I, $, w, p, a) => t._mapFn(I, $, w, p, a)
|
|
1166
1151
|
) : null;
|
|
1167
1152
|
}
|
|
1168
1153
|
function Yt({
|
|
1169
1154
|
proxy: t
|
|
1170
1155
|
}) {
|
|
1171
1156
|
const c = X(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1172
|
-
return
|
|
1157
|
+
return ot(() => {
|
|
1173
1158
|
const S = c.current;
|
|
1174
1159
|
if (!S || !S.parentElement) return;
|
|
1175
1160
|
const I = S.parentElement, w = Array.from(I.childNodes).indexOf(S);
|
|
@@ -1225,8 +1210,8 @@ function Zt({
|
|
|
1225
1210
|
itemPath: h,
|
|
1226
1211
|
children: S
|
|
1227
1212
|
}) {
|
|
1228
|
-
const [, I] = Z({}), [
|
|
1229
|
-
return
|
|
1213
|
+
const [, I] = Z({}), [$, w] = Dt(), p = X(null);
|
|
1214
|
+
return ot(() => {
|
|
1230
1215
|
w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
|
|
1231
1216
|
virtualizer: {
|
|
1232
1217
|
itemHeight: w.height
|
|
@@ -1243,7 +1228,7 @@ function Zt({
|
|
|
1243
1228
|
const n = o.getState().stateComponents.get(t);
|
|
1244
1229
|
n && n.components.delete(a);
|
|
1245
1230
|
};
|
|
1246
|
-
}, [t, c, h.join(".")]), /* @__PURE__ */ ht("div", { ref:
|
|
1231
|
+
}, [t, c, h.join(".")]), /* @__PURE__ */ ht("div", { ref: $, children: S });
|
|
1247
1232
|
}
|
|
1248
1233
|
export {
|
|
1249
1234
|
bt as $cogsSignal,
|