cogsbox-state 0.5.280 → 0.5.281
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.d.ts +1 -0
- package/dist/CogsState.jsx +259 -253
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.js +23 -21
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +20 -4
- package/src/store.ts +8 -2
package/dist/CogsState.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as K, useRef as
|
|
4
|
-
import { transformStateFunc as bt, isDeepEqual as L, isFunction as J, getNestedValue as
|
|
5
|
-
import { pushFunc as
|
|
2
|
+
import { jsx as mt } from "react/jsx-runtime";
|
|
3
|
+
import { useState as K, useRef as q, useEffect as st, useLayoutEffect as it, useMemo as Tt, createElement as rt, useSyncExternalStore as Ct, startTransition as Vt, useCallback as ft } from "react";
|
|
4
|
+
import { transformStateFunc as bt, isDeepEqual as L, isFunction as J, getNestedValue as z, getDifferences as ht, debounce as xt } from "./utility.js";
|
|
5
|
+
import { pushFunc as St, updateFn as nt, cutFunc as ot, ValidationWrapper as Pt, FormControlComponent as _t } from "./Functions.jsx";
|
|
6
6
|
import Mt from "superjson";
|
|
7
|
-
import { v4 as
|
|
7
|
+
import { v4 as yt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as r, formRefStore as It } from "./store.js";
|
|
10
10
|
import { useCogsConfig as $t } from "./CogsStateClient.jsx";
|
|
@@ -25,15 +25,15 @@ function wt({
|
|
|
25
25
|
const g = Q(t) || {}, v = h[t] || {}, $ = r.getState().setInitialStateOptions, p = { ...v, ...g };
|
|
26
26
|
let I = !1;
|
|
27
27
|
if (c)
|
|
28
|
-
for (const
|
|
29
|
-
p.hasOwnProperty(
|
|
30
|
-
!L(p[
|
|
28
|
+
for (const o in c)
|
|
29
|
+
p.hasOwnProperty(o) ? (o == "localStorage" && c[o] && p[o].key !== c[o]?.key && (I = !0, p[o] = c[o]), o == "initialState" && c[o] && p[o] !== c[o] && // Different references
|
|
30
|
+
!L(p[o], c[o]) && (I = !0, p[o] = c[o])) : (I = !0, p[o] = c[o]);
|
|
31
31
|
I && $(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ae(t, { formElements: c, validation: h }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: h };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const oe = (t, c) => {
|
|
37
37
|
let h = t;
|
|
38
38
|
const [g, v] = bt(h);
|
|
39
39
|
(Object.keys(v).length > 0 || c && Object.keys(c).length > 0) && Object.keys(v).forEach((I) => {
|
|
@@ -45,33 +45,33 @@ const ae = (t, c) => {
|
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, Q(I) || r.getState().setInitialStateOptions(I, v[I]);
|
|
47
47
|
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
|
-
const $ = (I,
|
|
49
|
-
const [y] = K(
|
|
48
|
+
const $ = (I, o) => {
|
|
49
|
+
const [y] = K(o?.componentId ?? yt());
|
|
50
50
|
wt({
|
|
51
51
|
stateKey: I,
|
|
52
|
-
options:
|
|
52
|
+
options: o,
|
|
53
53
|
initialOptionsPart: v
|
|
54
54
|
});
|
|
55
|
-
const
|
|
55
|
+
const a = r.getState().cogsStateStore[I] || g[I], S = o?.modifyState ? o.modifyState(a) : a, [D, O] = Lt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
59
|
-
syncUpdate:
|
|
59
|
+
syncUpdate: o?.syncUpdate,
|
|
60
60
|
componentId: y,
|
|
61
|
-
localStorage:
|
|
62
|
-
middleware:
|
|
63
|
-
enabledSync:
|
|
64
|
-
reactiveType:
|
|
65
|
-
reactiveDeps:
|
|
66
|
-
initialState:
|
|
67
|
-
dependencies:
|
|
68
|
-
serverState:
|
|
61
|
+
localStorage: o?.localStorage,
|
|
62
|
+
middleware: o?.middleware,
|
|
63
|
+
enabledSync: o?.enabledSync,
|
|
64
|
+
reactiveType: o?.reactiveType,
|
|
65
|
+
reactiveDeps: o?.reactiveDeps,
|
|
66
|
+
initialState: o?.initialState,
|
|
67
|
+
dependencies: o?.dependencies,
|
|
68
|
+
serverState: o?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
71
|
return O;
|
|
72
72
|
};
|
|
73
|
-
function p(I,
|
|
74
|
-
wt({ stateKey: I, options:
|
|
73
|
+
function p(I, o) {
|
|
74
|
+
wt({ stateKey: I, options: o, initialOptionsPart: v }), o.localStorage && Wt(I, o), ut(I);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: $, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
@@ -81,9 +81,9 @@ const ae = (t, c) => {
|
|
|
81
81
|
getKeyState: kt,
|
|
82
82
|
getValidationErrors: Ut,
|
|
83
83
|
setStateLog: Rt,
|
|
84
|
-
updateInitialStateGlobal:
|
|
84
|
+
updateInitialStateGlobal: vt,
|
|
85
85
|
addValidationError: Ft,
|
|
86
|
-
removeValidationError:
|
|
86
|
+
removeValidationError: H,
|
|
87
87
|
setServerSyncActions: Dt
|
|
88
88
|
} = r.getState(), Et = (t, c, h, g, v) => {
|
|
89
89
|
h?.log && console.log(
|
|
@@ -100,11 +100,11 @@ const ae = (t, c) => {
|
|
|
100
100
|
I = dt(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
const o = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: v ?? I
|
|
107
|
-
}, y = Mt.serialize(
|
|
107
|
+
}, y = Mt.serialize(o);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(y.json)
|
|
@@ -139,7 +139,7 @@ const ae = (t, c) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: h
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
vt(t, p.initialState), ct(t, p.updaterState), Z(t, p.state);
|
|
143
143
|
}, ut = (t) => {
|
|
144
144
|
const c = r.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
@@ -161,18 +161,18 @@ const ae = (t, c) => {
|
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: z(c, g),
|
|
165
|
+
newValue: z(h, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: z(h, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: z(c, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -188,14 +188,14 @@ function Lt(t, {
|
|
|
188
188
|
reactiveDeps: $,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: I,
|
|
191
|
-
initialState:
|
|
191
|
+
initialState: o,
|
|
192
192
|
syncUpdate: y,
|
|
193
|
-
dependencies:
|
|
193
|
+
dependencies: a,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
196
|
const [D, O] = K({}), { sessionId: U } = $t();
|
|
197
197
|
let W = !c;
|
|
198
|
-
const [m] = K(c ??
|
|
198
|
+
const [m] = K(c ?? yt()), l = r.getState().stateLog[m], at = q(/* @__PURE__ */ new Set()), Y = q(I ?? yt()), j = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
201
|
j.current = Q(m) ?? null, st(() => {
|
|
@@ -211,37 +211,37 @@ function Lt(t, {
|
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
}, [y]), st(() => {
|
|
214
|
-
if (
|
|
214
|
+
if (o) {
|
|
215
215
|
pt(m, {
|
|
216
|
-
initialState:
|
|
216
|
+
initialState: o
|
|
217
217
|
});
|
|
218
218
|
const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = r.getState().initialStateGlobal[m];
|
|
219
|
-
if (!(i && !L(i,
|
|
219
|
+
if (!(i && !L(i, o) || !i) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let d = null;
|
|
222
|
-
const k = J(e?.localStorage?.key) ? e?.localStorage?.key(
|
|
222
|
+
const k = J(e?.localStorage?.key) ? e?.localStorage?.key(o) : e?.localStorage?.key;
|
|
223
223
|
k && U && (d = dt(`${U}-${m}-${k}`));
|
|
224
|
-
let w =
|
|
224
|
+
let w = o, T = !1;
|
|
225
225
|
const x = s ? Date.now() : 0, C = d?.lastUpdated || 0, V = d?.lastSyncedWithServer || 0;
|
|
226
|
-
s && x > C ? (w = e.serverState.data,
|
|
226
|
+
s && x > C ? (w = e.serverState.data, T = !0) : d && C > V && (w = d.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), r.getState().initializeShadowState(m, o), Nt(
|
|
227
227
|
m,
|
|
228
|
-
|
|
228
|
+
o,
|
|
229
229
|
w,
|
|
230
230
|
tt,
|
|
231
231
|
Y.current,
|
|
232
232
|
U
|
|
233
|
-
),
|
|
233
|
+
), T && k && U && Et(w, m, e, U, Date.now()), ut(m), (Array.isArray(p) ? p : [p || "component"]).includes("none") || O({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
|
-
|
|
236
|
+
o,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
|
-
...
|
|
239
|
+
...a || []
|
|
240
240
|
]), it(() => {
|
|
241
241
|
W && pt(m, {
|
|
242
242
|
serverSync: h,
|
|
243
243
|
formElements: v,
|
|
244
|
-
initialState:
|
|
244
|
+
initialState: o,
|
|
245
245
|
localStorage: g,
|
|
246
246
|
middleware: j.current?.middleware
|
|
247
247
|
});
|
|
@@ -261,30 +261,30 @@ function Lt(t, {
|
|
|
261
261
|
const tt = (e, n, s, i) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
263
263
|
const f = `${m}-${n.join(".")}`;
|
|
264
|
-
|
|
264
|
+
at.current.add(f);
|
|
265
265
|
}
|
|
266
266
|
Z(m, (f) => {
|
|
267
267
|
const d = J(e) ? e(f) : e, k = `${m}-${n.join(".")}`;
|
|
268
268
|
if (k) {
|
|
269
|
-
let
|
|
269
|
+
let _ = !1, N = r.getState().signalDomElements.get(k);
|
|
270
270
|
if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
271
|
-
const
|
|
272
|
-
if (Array.isArray(
|
|
273
|
-
|
|
274
|
-
const E = `${m}-${
|
|
271
|
+
const A = n.slice(0, -1), P = z(d, A);
|
|
272
|
+
if (Array.isArray(P)) {
|
|
273
|
+
_ = !0;
|
|
274
|
+
const E = `${m}-${A.join(".")}`;
|
|
275
275
|
N = r.getState().signalDomElements.get(E);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
if (N) {
|
|
279
|
-
const
|
|
280
|
-
N.forEach(({ parentId:
|
|
279
|
+
const A = _ ? z(d, n.slice(0, -1)) : z(d, n);
|
|
280
|
+
N.forEach(({ parentId: P, position: E, effect: M }) => {
|
|
281
281
|
const b = document.querySelector(
|
|
282
|
-
`[data-parent-id="${
|
|
282
|
+
`[data-parent-id="${P}"]`
|
|
283
283
|
);
|
|
284
284
|
if (b) {
|
|
285
285
|
const F = Array.from(b.childNodes);
|
|
286
286
|
if (F[E]) {
|
|
287
|
-
const R = M ? new Function("state", `return (${M})(state)`)(
|
|
287
|
+
const R = M ? new Function("state", `return (${M})(state)`)(A) : A;
|
|
288
288
|
F[E].textContent = String(R);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
@@ -292,40 +292,40 @@ function Lt(t, {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
(() => {
|
|
295
|
-
const
|
|
295
|
+
const _ = r.getState();
|
|
296
296
|
switch (s.updateType) {
|
|
297
297
|
case "update":
|
|
298
|
-
|
|
298
|
+
_.updateShadowAtPath(m, n, d);
|
|
299
299
|
break;
|
|
300
300
|
case "insert":
|
|
301
301
|
const N = n.slice(0, -1);
|
|
302
|
-
|
|
302
|
+
_.insertShadowArrayElement(m, N);
|
|
303
303
|
break;
|
|
304
304
|
case "cut":
|
|
305
|
-
const
|
|
306
|
-
|
|
305
|
+
const A = n.slice(0, -1), P = parseInt(n[n.length - 1]);
|
|
306
|
+
_.removeShadowArrayElement(m, A, P);
|
|
307
307
|
break;
|
|
308
308
|
}
|
|
309
|
-
})(), console.log("shadowState", r.getState().shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && n &&
|
|
309
|
+
})(), console.log("shadowState", r.getState().shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && n && H(
|
|
310
310
|
(i || j.current?.validation?.key) + "." + n.join(".")
|
|
311
311
|
);
|
|
312
|
-
const
|
|
313
|
-
s.updateType === "cut" && j.current?.validation?.key &&
|
|
314
|
-
j.current?.validation?.key + "." +
|
|
312
|
+
const T = n.slice(0, n.length - 1);
|
|
313
|
+
s.updateType === "cut" && j.current?.validation?.key && H(
|
|
314
|
+
j.current?.validation?.key + "." + T.join(".")
|
|
315
315
|
), s.updateType === "insert" && j.current?.validation?.key && Ut(
|
|
316
|
-
j.current?.validation?.key + "." +
|
|
317
|
-
).filter(([N,
|
|
318
|
-
let
|
|
319
|
-
if (N ==
|
|
320
|
-
let E = N + "." +
|
|
321
|
-
|
|
316
|
+
j.current?.validation?.key + "." + T.join(".")
|
|
317
|
+
).filter(([N, A]) => {
|
|
318
|
+
let P = N?.split(".").length;
|
|
319
|
+
if (N == T.join(".") && P == T.length - 1) {
|
|
320
|
+
let E = N + "." + T;
|
|
321
|
+
H(N), Ft(E, A);
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
324
|
const x = r.getState().stateComponents.get(m);
|
|
325
325
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
|
|
326
|
-
const
|
|
326
|
+
const _ = ht(f, d), N = new Set(_), A = s.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
327
327
|
for (const [
|
|
328
|
-
|
|
328
|
+
P,
|
|
329
329
|
E
|
|
330
330
|
] of x.components.entries()) {
|
|
331
331
|
let M = !1;
|
|
@@ -335,7 +335,7 @@ function Lt(t, {
|
|
|
335
335
|
E.forceUpdate();
|
|
336
336
|
continue;
|
|
337
337
|
}
|
|
338
|
-
if (b.includes("component") && ((E.paths.has(
|
|
338
|
+
if (b.includes("component") && ((E.paths.has(A) || E.paths.has("")) && (M = !0), !M))
|
|
339
339
|
for (const F of N) {
|
|
340
340
|
let R = F;
|
|
341
341
|
for (; ; ) {
|
|
@@ -373,16 +373,16 @@ function Lt(t, {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
const C = Date.now();
|
|
376
|
-
n = n.map((
|
|
377
|
-
const
|
|
378
|
-
return N === n.length - 1 && ["insert", "cut"].includes(s.updateType) ? (
|
|
376
|
+
n = n.map((_, N) => {
|
|
377
|
+
const A = n.slice(0, -1), P = z(d, A);
|
|
378
|
+
return N === n.length - 1 && ["insert", "cut"].includes(s.updateType) ? (P.length - 1).toString() : _;
|
|
379
379
|
});
|
|
380
380
|
const { oldValue: V, newValue: G } = Gt(
|
|
381
381
|
s.updateType,
|
|
382
382
|
f,
|
|
383
383
|
d,
|
|
384
384
|
n
|
|
385
|
-
),
|
|
385
|
+
), B = {
|
|
386
386
|
timeStamp: C,
|
|
387
387
|
stateKey: m,
|
|
388
388
|
path: n,
|
|
@@ -391,12 +391,12 @@ function Lt(t, {
|
|
|
391
391
|
oldValue: V,
|
|
392
392
|
newValue: G
|
|
393
393
|
};
|
|
394
|
-
if (Rt(m, (
|
|
395
|
-
const
|
|
396
|
-
const M = `${E.stateKey}:${JSON.stringify(E.path)}`, b =
|
|
397
|
-
return b ? (b.timeStamp = Math.max(b.timeStamp, E.timeStamp), b.newValue = E.newValue, b.oldValue = b.oldValue ?? E.oldValue, b.updateType = E.updateType) :
|
|
394
|
+
if (Rt(m, (_) => {
|
|
395
|
+
const A = [..._ ?? [], B].reduce((P, E) => {
|
|
396
|
+
const M = `${E.stateKey}:${JSON.stringify(E.path)}`, b = P.get(M);
|
|
397
|
+
return b ? (b.timeStamp = Math.max(b.timeStamp, E.timeStamp), b.newValue = E.newValue, b.oldValue = b.oldValue ?? E.oldValue, b.updateType = E.updateType) : P.set(M, { ...E }), P;
|
|
398
398
|
}, /* @__PURE__ */ new Map());
|
|
399
|
-
return Array.from(
|
|
399
|
+
return Array.from(A.values());
|
|
400
400
|
}), Et(
|
|
401
401
|
d,
|
|
402
402
|
m,
|
|
@@ -404,12 +404,12 @@ function Lt(t, {
|
|
|
404
404
|
U
|
|
405
405
|
), j.current?.middleware && j.current.middleware({
|
|
406
406
|
updateLog: l,
|
|
407
|
-
update:
|
|
407
|
+
update: B
|
|
408
408
|
}), j.current?.serverSync) {
|
|
409
|
-
const
|
|
409
|
+
const _ = r.getState().serverState[m], N = j.current?.serverSync;
|
|
410
410
|
Dt(m, {
|
|
411
411
|
syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: d }),
|
|
412
|
-
rollBackState:
|
|
412
|
+
rollBackState: _,
|
|
413
413
|
actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
|
|
414
414
|
status: "waiting"
|
|
415
415
|
});
|
|
@@ -425,7 +425,7 @@ function Lt(t, {
|
|
|
425
425
|
Y.current,
|
|
426
426
|
U
|
|
427
427
|
)
|
|
428
|
-
), r.getState().cogsStateStore[m] || Z(m, t), r.getState().initialStateGlobal[m] ||
|
|
428
|
+
), r.getState().cogsStateStore[m] || Z(m, t), r.getState().initialStateGlobal[m] || vt(m, t));
|
|
429
429
|
const u = Tt(() => lt(
|
|
430
430
|
m,
|
|
431
431
|
tt,
|
|
@@ -438,20 +438,20 @@ function lt(t, c, h, g) {
|
|
|
438
438
|
const v = /* @__PURE__ */ new Map();
|
|
439
439
|
let $ = 0;
|
|
440
440
|
const p = (y) => {
|
|
441
|
-
const
|
|
441
|
+
const a = y.join(".");
|
|
442
442
|
for (const [S] of v)
|
|
443
|
-
(S ===
|
|
443
|
+
(S === a || S.startsWith(a + ".")) && v.delete(S);
|
|
444
444
|
$++;
|
|
445
445
|
}, I = {
|
|
446
446
|
removeValidation: (y) => {
|
|
447
|
-
y?.validationKey &&
|
|
447
|
+
y?.validationKey && H(y.validationKey);
|
|
448
448
|
},
|
|
449
449
|
revertToInitialState: (y) => {
|
|
450
|
-
const
|
|
451
|
-
|
|
450
|
+
const a = r.getState().getInitialOptions(t)?.validation;
|
|
451
|
+
a?.key && H(a?.key), y?.validationKey && H(y.validationKey);
|
|
452
452
|
const S = r.getState().initialStateGlobal[t];
|
|
453
453
|
r.getState().clearSelectedIndexesForState(t), v.clear(), $++;
|
|
454
|
-
const D =
|
|
454
|
+
const D = o(S, []), O = Q(t), U = J(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, W = `${g}-${t}-${U}`;
|
|
455
455
|
W && localStorage.removeItem(W), ct(t, D), Z(t, S);
|
|
456
456
|
const m = r.getState().stateComponents.get(t);
|
|
457
457
|
return m && m.components.forEach((l) => {
|
|
@@ -460,20 +460,20 @@ function lt(t, c, h, g) {
|
|
|
460
460
|
},
|
|
461
461
|
updateInitialState: (y) => {
|
|
462
462
|
v.clear(), $++;
|
|
463
|
-
const
|
|
463
|
+
const a = lt(
|
|
464
464
|
t,
|
|
465
465
|
c,
|
|
466
466
|
h,
|
|
467
467
|
g
|
|
468
468
|
), S = r.getState().initialStateGlobal[t], D = Q(t), O = J(D?.localStorage?.key) ? D?.localStorage?.key(S) : D?.localStorage?.key, U = `${g}-${t}-${O}`;
|
|
469
469
|
return localStorage.getItem(U) && localStorage.removeItem(U), Vt(() => {
|
|
470
|
-
|
|
470
|
+
vt(t, y), r.getState().initializeShadowState(t, y), ct(t, a), Z(t, y);
|
|
471
471
|
const W = r.getState().stateComponents.get(t);
|
|
472
472
|
W && W.components.forEach((m) => {
|
|
473
473
|
m.forceUpdate();
|
|
474
474
|
});
|
|
475
475
|
}), {
|
|
476
|
-
fetchId: (W) =>
|
|
476
|
+
fetchId: (W) => a.get()[W]
|
|
477
477
|
};
|
|
478
478
|
},
|
|
479
479
|
_initialState: r.getState().initialStateGlobal[t],
|
|
@@ -484,24 +484,24 @@ function lt(t, c, h, g) {
|
|
|
484
484
|
return !!(y && L(y, kt(t)));
|
|
485
485
|
}
|
|
486
486
|
};
|
|
487
|
-
function
|
|
488
|
-
const D =
|
|
487
|
+
function o(y, a = [], S) {
|
|
488
|
+
const D = a.map(String).join(".");
|
|
489
489
|
v.get(D);
|
|
490
490
|
const O = function() {
|
|
491
|
-
return r().getNestedState(t,
|
|
491
|
+
return r().getNestedState(t, a);
|
|
492
492
|
};
|
|
493
493
|
Object.keys(I).forEach((m) => {
|
|
494
494
|
O[m] = I[m];
|
|
495
495
|
});
|
|
496
496
|
const U = {
|
|
497
|
-
apply(m, l,
|
|
497
|
+
apply(m, l, at) {
|
|
498
498
|
return console.log(
|
|
499
|
-
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${
|
|
500
|
-
), console.trace("Apply trap stack trace"), r().getNestedState(t,
|
|
499
|
+
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${a.join(".")}`
|
|
500
|
+
), console.trace("Apply trap stack trace"), r().getNestedState(t, a);
|
|
501
501
|
},
|
|
502
502
|
get(m, l) {
|
|
503
503
|
S?.validIndices && !Array.isArray(y) && (S = { ...S, validIndices: void 0 });
|
|
504
|
-
const
|
|
504
|
+
const at = /* @__PURE__ */ new Set([
|
|
505
505
|
"insert",
|
|
506
506
|
"cut",
|
|
507
507
|
"cutByValue",
|
|
@@ -524,12 +524,12 @@ function lt(t, c, h, g) {
|
|
|
524
524
|
"_stateKey",
|
|
525
525
|
"getComponents"
|
|
526
526
|
]);
|
|
527
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
527
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !at.has(l)) {
|
|
528
528
|
const u = `${t}////${h}`, e = r.getState().stateComponents.get(t);
|
|
529
529
|
if (e) {
|
|
530
530
|
const n = e.components.get(u);
|
|
531
531
|
if (n && !n.paths.has("")) {
|
|
532
|
-
const s =
|
|
532
|
+
const s = a.join(".");
|
|
533
533
|
let i = !0;
|
|
534
534
|
for (const f of n.paths)
|
|
535
535
|
if (s.startsWith(f) && (s === f || s[f.length] === ".")) {
|
|
@@ -541,11 +541,11 @@ function lt(t, c, h, g) {
|
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
if (l === "getDifferences")
|
|
544
|
-
return () =>
|
|
544
|
+
return () => ht(
|
|
545
545
|
r.getState().cogsStateStore[t],
|
|
546
546
|
r.getState().initialStateGlobal[t]
|
|
547
547
|
);
|
|
548
|
-
if (l === "sync" &&
|
|
548
|
+
if (l === "sync" && a.length === 0)
|
|
549
549
|
return async function() {
|
|
550
550
|
const u = r.getState().getInitialOptions(t), e = u?.sync;
|
|
551
551
|
if (!e)
|
|
@@ -569,15 +569,15 @@ function lt(t, c, h, g) {
|
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
571
|
if (l === "_status") {
|
|
572
|
-
const u = r.getState().getNestedState(t,
|
|
572
|
+
const u = r.getState().getNestedState(t, a), e = r.getState().initialStateGlobal[t], n = z(e, a);
|
|
573
573
|
return L(u, n) ? "fresh" : "stale";
|
|
574
574
|
}
|
|
575
575
|
if (l === "getStatus")
|
|
576
576
|
return function() {
|
|
577
577
|
const u = r().getNestedState(
|
|
578
578
|
t,
|
|
579
|
-
|
|
580
|
-
), e = r.getState().initialStateGlobal[t], n =
|
|
579
|
+
a
|
|
580
|
+
), e = r.getState().initialStateGlobal[t], n = z(e, a);
|
|
581
581
|
return L(u, n) ? "fresh" : "stale";
|
|
582
582
|
};
|
|
583
583
|
if (l === "removeStorage")
|
|
@@ -590,61 +590,63 @@ function lt(t, c, h, g) {
|
|
|
590
590
|
const u = r.getState().getInitialOptions(t)?.validation;
|
|
591
591
|
if (!u?.key)
|
|
592
592
|
throw new Error("Validation key not found");
|
|
593
|
-
return r.getState().getValidationErrors(u.key + "." +
|
|
593
|
+
return r.getState().getValidationErrors(u.key + "." + a.join("."));
|
|
594
594
|
};
|
|
595
595
|
if (Array.isArray(y)) {
|
|
596
596
|
const u = () => S?.validIndices ? y.map((n, s) => ({
|
|
597
597
|
item: n,
|
|
598
598
|
originalIndex: S.validIndices[s]
|
|
599
|
-
})) : r.getState().getNestedState(t,
|
|
599
|
+
})) : r.getState().getNestedState(t, a).map((n, s) => ({
|
|
600
600
|
item: n,
|
|
601
601
|
originalIndex: s
|
|
602
602
|
}));
|
|
603
603
|
if (l === "getSelected")
|
|
604
604
|
return () => {
|
|
605
|
-
const e = r.getState().getSelectedIndex(t,
|
|
605
|
+
const e = r.getState().getSelectedIndex(t, a.join("."));
|
|
606
606
|
if (e !== void 0)
|
|
607
|
-
return
|
|
607
|
+
return o(
|
|
608
608
|
y[e],
|
|
609
|
-
[...
|
|
609
|
+
[...a, e.toString()],
|
|
610
610
|
S
|
|
611
611
|
);
|
|
612
612
|
};
|
|
613
613
|
if (l === "clearSelected")
|
|
614
614
|
return () => {
|
|
615
|
-
r.getState().clearSelectedIndex({ stateKey: t, path:
|
|
615
|
+
r.getState().clearSelectedIndex({ stateKey: t, path: a });
|
|
616
616
|
};
|
|
617
617
|
if (l === "getSelectedIndex")
|
|
618
|
-
return () => r.getState().getSelectedIndex(t,
|
|
618
|
+
return () => r.getState().getSelectedIndex(t, a.join(".")) ?? -1;
|
|
619
619
|
if (l === "useVirtualView")
|
|
620
620
|
return (e) => {
|
|
621
621
|
const {
|
|
622
622
|
itemHeight: n,
|
|
623
623
|
overscan: s = 5,
|
|
624
624
|
stickToBottom: i = !1
|
|
625
|
-
} = e, f =
|
|
625
|
+
} = e, f = q(null), [d, k] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
})
|
|
628
|
+
});
|
|
629
|
+
ft((A) => r.getState().getShadowMetadata(t, [...a, A.toString()])?.virtualizer?.itemHeight || e.itemHeight, []);
|
|
630
|
+
const w = q(i), T = q(0), x = q(!0), C = r().getNestedState(
|
|
629
631
|
t,
|
|
630
|
-
|
|
632
|
+
a
|
|
631
633
|
), V = C.length, G = Tt(() => {
|
|
632
|
-
const
|
|
633
|
-
{ length:
|
|
634
|
-
(b, F) =>
|
|
634
|
+
const A = Math.max(0, d.startIndex), P = Math.min(V, d.endIndex), E = Array.from(
|
|
635
|
+
{ length: P - A },
|
|
636
|
+
(b, F) => A + F
|
|
635
637
|
), M = E.map((b) => C[b]);
|
|
636
|
-
return
|
|
638
|
+
return o(M, a, {
|
|
637
639
|
...S,
|
|
638
640
|
validIndices: E
|
|
639
641
|
});
|
|
640
642
|
}, [d.startIndex, d.endIndex, C, V]);
|
|
641
643
|
it(() => {
|
|
642
|
-
const
|
|
643
|
-
if (!
|
|
644
|
-
const
|
|
645
|
-
|
|
644
|
+
const A = f.current;
|
|
645
|
+
if (!A) return;
|
|
646
|
+
const P = w.current, E = V > T.current;
|
|
647
|
+
T.current = V;
|
|
646
648
|
const M = () => {
|
|
647
|
-
const { scrollTop: b, clientHeight: F, scrollHeight: R } =
|
|
649
|
+
const { scrollTop: b, clientHeight: F, scrollHeight: R } = A;
|
|
648
650
|
w.current = R - b - F < 10;
|
|
649
651
|
const X = Math.max(
|
|
650
652
|
0,
|
|
@@ -655,31 +657,31 @@ function lt(t, c, h, g) {
|
|
|
655
657
|
);
|
|
656
658
|
k((gt) => gt.startIndex !== X || gt.endIndex !== et ? { startIndex: X, endIndex: et } : gt);
|
|
657
659
|
};
|
|
658
|
-
return
|
|
660
|
+
return A.addEventListener("scroll", M, {
|
|
659
661
|
passive: !0
|
|
660
|
-
}), i && (x.current ?
|
|
661
|
-
top:
|
|
662
|
+
}), i && (x.current ? A.scrollTo({
|
|
663
|
+
top: A.scrollHeight,
|
|
662
664
|
behavior: "auto"
|
|
663
|
-
}) :
|
|
664
|
-
|
|
665
|
-
top:
|
|
665
|
+
}) : P && E && requestAnimationFrame(() => {
|
|
666
|
+
A.scrollTo({
|
|
667
|
+
top: A.scrollHeight,
|
|
666
668
|
behavior: "smooth"
|
|
667
669
|
});
|
|
668
|
-
})), x.current = !1, M(), () =>
|
|
670
|
+
})), x.current = !1, M(), () => A.removeEventListener("scroll", M);
|
|
669
671
|
}, [V, n, s, i]);
|
|
670
|
-
const
|
|
671
|
-
(
|
|
672
|
+
const B = ft(
|
|
673
|
+
(A = "smooth") => {
|
|
672
674
|
f.current && f.current.scrollTo({
|
|
673
675
|
top: f.current.scrollHeight,
|
|
674
|
-
behavior:
|
|
676
|
+
behavior: A
|
|
675
677
|
});
|
|
676
678
|
},
|
|
677
679
|
[]
|
|
678
|
-
),
|
|
679
|
-
(
|
|
680
|
+
), _ = ft(
|
|
681
|
+
(A, P = "smooth") => {
|
|
680
682
|
f.current && f.current.scrollTo({
|
|
681
|
-
top:
|
|
682
|
-
behavior:
|
|
683
|
+
top: A * n,
|
|
684
|
+
behavior: P
|
|
683
685
|
});
|
|
684
686
|
},
|
|
685
687
|
[n]
|
|
@@ -703,8 +705,8 @@ function lt(t, c, h, g) {
|
|
|
703
705
|
return {
|
|
704
706
|
virtualState: G,
|
|
705
707
|
virtualizerProps: N,
|
|
706
|
-
scrollToBottom:
|
|
707
|
-
scrollToIndex:
|
|
708
|
+
scrollToBottom: B,
|
|
709
|
+
scrollToIndex: _
|
|
708
710
|
};
|
|
709
711
|
};
|
|
710
712
|
if (l === "stateSort")
|
|
@@ -717,7 +719,7 @@ function lt(t, c, h, g) {
|
|
|
717
719
|
({ originalIndex: d }) => d
|
|
718
720
|
)
|
|
719
721
|
};
|
|
720
|
-
return
|
|
722
|
+
return o(i, a, f);
|
|
721
723
|
};
|
|
722
724
|
if (l === "stateFilter")
|
|
723
725
|
return (e) => {
|
|
@@ -729,16 +731,16 @@ function lt(t, c, h, g) {
|
|
|
729
731
|
({ originalIndex: d }) => d
|
|
730
732
|
)
|
|
731
733
|
};
|
|
732
|
-
return
|
|
734
|
+
return o(i, a, f);
|
|
733
735
|
};
|
|
734
736
|
if (l === "stateMap")
|
|
735
737
|
return (e) => {
|
|
736
|
-
const n = r.getState().getNestedState(t,
|
|
738
|
+
const n = r.getState().getNestedState(t, a);
|
|
737
739
|
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
738
|
-
const d = n[i], k = [...
|
|
740
|
+
const d = n[i], k = [...a, i.toString()], w = o(d, k, S);
|
|
739
741
|
return e(d, w, {
|
|
740
742
|
register: () => {
|
|
741
|
-
const [, x] = K({}), C = `${h}-${
|
|
743
|
+
const [, x] = K({}), C = `${h}-${a.join(".")}-${i}`;
|
|
742
744
|
it(() => {
|
|
743
745
|
const V = `${t}////${C}`, G = r.getState().stateComponents.get(t) || {
|
|
744
746
|
components: /* @__PURE__ */ new Map()
|
|
@@ -747,8 +749,8 @@ function lt(t, c, h, g) {
|
|
|
747
749
|
forceUpdate: () => x({}),
|
|
748
750
|
paths: /* @__PURE__ */ new Set([k.join(".")])
|
|
749
751
|
}), r.getState().stateComponents.set(t, G), () => {
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
+
const B = r.getState().stateComponents.get(t);
|
|
753
|
+
B && B.components.delete(V);
|
|
752
754
|
};
|
|
753
755
|
}, [t, C]);
|
|
754
756
|
},
|
|
@@ -756,7 +758,7 @@ function lt(t, c, h, g) {
|
|
|
756
758
|
originalIndex: i
|
|
757
759
|
});
|
|
758
760
|
}) : (console.warn(
|
|
759
|
-
`stateMap called on a non-array value at path: ${
|
|
761
|
+
`stateMap called on a non-array value at path: ${a.join(".")}. The current value is:`,
|
|
760
762
|
n
|
|
761
763
|
), null);
|
|
762
764
|
};
|
|
@@ -764,45 +766,45 @@ function lt(t, c, h, g) {
|
|
|
764
766
|
return (e) => y.map((s, i) => {
|
|
765
767
|
let f;
|
|
766
768
|
S?.validIndices && S.validIndices[i] !== void 0 ? f = S.validIndices[i] : f = i;
|
|
767
|
-
const d = [...
|
|
769
|
+
const d = [...a, f.toString()], k = o(s, d, S);
|
|
768
770
|
return e(
|
|
769
771
|
s,
|
|
770
772
|
k,
|
|
771
773
|
i,
|
|
772
774
|
y,
|
|
773
|
-
|
|
775
|
+
o(y, a, S)
|
|
774
776
|
);
|
|
775
777
|
});
|
|
776
778
|
if (l === "$stateMap")
|
|
777
|
-
return (e) => rt(
|
|
779
|
+
return (e) => rt(zt, {
|
|
778
780
|
proxy: {
|
|
779
781
|
_stateKey: t,
|
|
780
|
-
_path:
|
|
782
|
+
_path: a,
|
|
781
783
|
_mapFn: e
|
|
782
784
|
// Pass the actual function, not string
|
|
783
785
|
},
|
|
784
|
-
rebuildStateShape:
|
|
786
|
+
rebuildStateShape: o
|
|
785
787
|
});
|
|
786
788
|
if (l === "stateList")
|
|
787
789
|
return (e) => {
|
|
788
|
-
const n = r.getState().getNestedState(t,
|
|
790
|
+
const n = r.getState().getNestedState(t, a);
|
|
789
791
|
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
790
|
-
const d = n[i], k = [...
|
|
791
|
-
return rt(
|
|
792
|
+
const d = n[i], k = [...a, i.toString()], w = o(d, k, S), T = `${h}-${a.join(".")}-${i}`;
|
|
793
|
+
return rt(Ht, {
|
|
792
794
|
key: i,
|
|
793
795
|
stateKey: t,
|
|
794
|
-
itemComponentId:
|
|
796
|
+
itemComponentId: T,
|
|
795
797
|
itemPath: k,
|
|
796
798
|
children: e(
|
|
797
799
|
d,
|
|
798
800
|
w,
|
|
799
801
|
f,
|
|
800
802
|
n,
|
|
801
|
-
|
|
803
|
+
o(n, a, S)
|
|
802
804
|
)
|
|
803
805
|
});
|
|
804
806
|
}) : (console.warn(
|
|
805
|
-
`stateList called on a non-array value at path: ${
|
|
807
|
+
`stateList called on a non-array value at path: ${a.join(".")}.`
|
|
806
808
|
), null);
|
|
807
809
|
};
|
|
808
810
|
if (l === "stateFlattenOn")
|
|
@@ -812,32 +814,32 @@ function lt(t, c, h, g) {
|
|
|
812
814
|
const s = n.flatMap(
|
|
813
815
|
(i) => i[e] ?? []
|
|
814
816
|
);
|
|
815
|
-
return
|
|
817
|
+
return o(
|
|
816
818
|
s,
|
|
817
|
-
[...
|
|
819
|
+
[...a, "[*]", e],
|
|
818
820
|
S
|
|
819
821
|
);
|
|
820
822
|
};
|
|
821
823
|
if (l === "index")
|
|
822
824
|
return (e) => {
|
|
823
825
|
const n = y[e];
|
|
824
|
-
return
|
|
826
|
+
return o(n, [...a, e.toString()]);
|
|
825
827
|
};
|
|
826
828
|
if (l === "last")
|
|
827
829
|
return () => {
|
|
828
|
-
const e = r.getState().getNestedState(t,
|
|
830
|
+
const e = r.getState().getNestedState(t, a);
|
|
829
831
|
if (e.length === 0) return;
|
|
830
|
-
const n = e.length - 1, s = e[n], i = [...
|
|
831
|
-
return
|
|
832
|
+
const n = e.length - 1, s = e[n], i = [...a, n.toString()];
|
|
833
|
+
return o(s, i);
|
|
832
834
|
};
|
|
833
835
|
if (l === "insert")
|
|
834
|
-
return (e) => (p(
|
|
835
|
-
r.getState().getNestedState(t,
|
|
836
|
-
|
|
836
|
+
return (e) => (p(a), St(c, e, a, t), o(
|
|
837
|
+
r.getState().getNestedState(t, a),
|
|
838
|
+
a
|
|
837
839
|
));
|
|
838
840
|
if (l === "uniqueInsert")
|
|
839
841
|
return (e, n, s) => {
|
|
840
|
-
const i = r.getState().getNestedState(t,
|
|
842
|
+
const i = r.getState().getNestedState(t, a), f = J(e) ? e(i) : e;
|
|
841
843
|
let d = null;
|
|
842
844
|
if (!i.some((w) => {
|
|
843
845
|
if (n) {
|
|
@@ -846,34 +848,34 @@ function lt(t, c, h, g) {
|
|
|
846
848
|
);
|
|
847
849
|
return x && (d = w), x;
|
|
848
850
|
}
|
|
849
|
-
const
|
|
850
|
-
return
|
|
851
|
+
const T = L(w, f);
|
|
852
|
+
return T && (d = w), T;
|
|
851
853
|
}))
|
|
852
|
-
p(
|
|
854
|
+
p(a), St(c, f, a, t);
|
|
853
855
|
else if (s && d) {
|
|
854
|
-
const w = s(d),
|
|
856
|
+
const w = s(d), T = i.map(
|
|
855
857
|
(x) => L(x, d) ? w : x
|
|
856
858
|
);
|
|
857
|
-
p(
|
|
859
|
+
p(a), nt(c, T, a);
|
|
858
860
|
}
|
|
859
861
|
};
|
|
860
862
|
if (l === "cut")
|
|
861
863
|
return (e, n) => {
|
|
862
864
|
if (!n?.waitForSync)
|
|
863
|
-
return p(
|
|
864
|
-
r.getState().getNestedState(t,
|
|
865
|
-
|
|
865
|
+
return p(a), ot(c, a, t, e), o(
|
|
866
|
+
r.getState().getNestedState(t, a),
|
|
867
|
+
a
|
|
866
868
|
);
|
|
867
869
|
};
|
|
868
870
|
if (l === "cutByValue")
|
|
869
871
|
return (e) => {
|
|
870
872
|
for (let n = 0; n < y.length; n++)
|
|
871
|
-
y[n] === e &&
|
|
873
|
+
y[n] === e && ot(c, a, t, n);
|
|
872
874
|
};
|
|
873
875
|
if (l === "toggleByValue")
|
|
874
876
|
return (e) => {
|
|
875
877
|
const n = y.findIndex((s) => s === e);
|
|
876
|
-
n > -1 ?
|
|
878
|
+
n > -1 ? ot(c, a, t, n) : St(c, e, a, t);
|
|
877
879
|
};
|
|
878
880
|
if (l === "stateFind")
|
|
879
881
|
return (e) => {
|
|
@@ -881,8 +883,8 @@ function lt(t, c, h, g) {
|
|
|
881
883
|
({ item: f }, d) => e(f, d)
|
|
882
884
|
);
|
|
883
885
|
if (!s) return;
|
|
884
|
-
const i = [...
|
|
885
|
-
return
|
|
886
|
+
const i = [...a, s.originalIndex.toString()];
|
|
887
|
+
return o(s.item, i, S);
|
|
886
888
|
};
|
|
887
889
|
if (l === "findWith")
|
|
888
890
|
return (e, n) => {
|
|
@@ -890,15 +892,15 @@ function lt(t, c, h, g) {
|
|
|
890
892
|
({ item: d }) => d[e] === n
|
|
891
893
|
);
|
|
892
894
|
if (!i) return;
|
|
893
|
-
const f = [...
|
|
894
|
-
return
|
|
895
|
+
const f = [...a, i.originalIndex.toString()];
|
|
896
|
+
return o(i.item, f, S);
|
|
895
897
|
};
|
|
896
898
|
}
|
|
897
|
-
const Y =
|
|
899
|
+
const Y = a[a.length - 1];
|
|
898
900
|
if (!isNaN(Number(Y))) {
|
|
899
|
-
const u =
|
|
901
|
+
const u = a.slice(0, -1), e = r.getState().getNestedState(t, u);
|
|
900
902
|
if (Array.isArray(e) && l === "cut")
|
|
901
|
-
return () =>
|
|
903
|
+
return () => ot(
|
|
902
904
|
c,
|
|
903
905
|
u,
|
|
904
906
|
t,
|
|
@@ -908,42 +910,42 @@ function lt(t, c, h, g) {
|
|
|
908
910
|
if (l === "get")
|
|
909
911
|
return () => {
|
|
910
912
|
if (S?.validIndices && Array.isArray(y)) {
|
|
911
|
-
const u = r.getState().getNestedState(t,
|
|
913
|
+
const u = r.getState().getNestedState(t, a);
|
|
912
914
|
return S.validIndices.map((e) => u[e]);
|
|
913
915
|
}
|
|
914
|
-
return r.getState().getNestedState(t,
|
|
916
|
+
return r.getState().getNestedState(t, a);
|
|
915
917
|
};
|
|
916
918
|
if (l === "$derive")
|
|
917
919
|
return (u) => At({
|
|
918
920
|
_stateKey: t,
|
|
919
|
-
_path:
|
|
921
|
+
_path: a,
|
|
920
922
|
_effect: u.toString()
|
|
921
923
|
});
|
|
922
924
|
if (l === "$get")
|
|
923
925
|
return () => At({
|
|
924
926
|
_stateKey: t,
|
|
925
|
-
_path:
|
|
927
|
+
_path: a
|
|
926
928
|
});
|
|
927
929
|
if (l === "lastSynced") {
|
|
928
|
-
const u = `${t}:${
|
|
930
|
+
const u = `${t}:${a.join(".")}`;
|
|
929
931
|
return r.getState().getSyncInfo(u);
|
|
930
932
|
}
|
|
931
933
|
if (l == "getLocalStorage")
|
|
932
934
|
return (u) => dt(g + "-" + t + "-" + u);
|
|
933
935
|
if (l === "_selected") {
|
|
934
|
-
const u =
|
|
935
|
-
return Array.isArray(n) ? Number(
|
|
936
|
+
const u = a.slice(0, -1), e = u.join("."), n = r.getState().getNestedState(t, u);
|
|
937
|
+
return Array.isArray(n) ? Number(a[a.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
|
|
936
938
|
}
|
|
937
939
|
if (l === "setSelected")
|
|
938
940
|
return (u) => {
|
|
939
|
-
const e =
|
|
941
|
+
const e = a.slice(0, -1), n = Number(a[a.length - 1]), s = e.join(".");
|
|
940
942
|
u ? r.getState().setSelectedIndex(t, s, n) : r.getState().setSelectedIndex(t, s, void 0);
|
|
941
943
|
const i = r.getState().getNestedState(t, [...e]);
|
|
942
944
|
nt(c, i, e), p(e);
|
|
943
945
|
};
|
|
944
946
|
if (l === "toggleSelected")
|
|
945
947
|
return () => {
|
|
946
|
-
const u =
|
|
948
|
+
const u = a.slice(0, -1), e = Number(a[a.length - 1]), n = u.join("."), s = r.getState().getSelectedIndex(t, n);
|
|
947
949
|
r.getState().setSelectedIndex(
|
|
948
950
|
t,
|
|
949
951
|
n,
|
|
@@ -952,7 +954,7 @@ function lt(t, c, h, g) {
|
|
|
952
954
|
const i = r.getState().getNestedState(t, [...u]);
|
|
953
955
|
nt(c, i, u), p(u);
|
|
954
956
|
};
|
|
955
|
-
if (
|
|
957
|
+
if (a.length == 0) {
|
|
956
958
|
if (l === "applyJsonPatch")
|
|
957
959
|
return (u) => {
|
|
958
960
|
const e = r.getState().cogsStateStore[t], s = jt(e, u).newDocument;
|
|
@@ -966,57 +968,57 @@ function lt(t, c, h, g) {
|
|
|
966
968
|
);
|
|
967
969
|
const i = r.getState().stateComponents.get(t);
|
|
968
970
|
if (i) {
|
|
969
|
-
const f =
|
|
971
|
+
const f = ht(e, s), d = new Set(f);
|
|
970
972
|
for (const [
|
|
971
973
|
k,
|
|
972
974
|
w
|
|
973
975
|
] of i.components.entries()) {
|
|
974
|
-
let
|
|
976
|
+
let T = !1;
|
|
975
977
|
const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
976
978
|
if (!x.includes("none")) {
|
|
977
979
|
if (x.includes("all")) {
|
|
978
980
|
w.forceUpdate();
|
|
979
981
|
continue;
|
|
980
982
|
}
|
|
981
|
-
if (x.includes("component") && (w.paths.has("") && (
|
|
983
|
+
if (x.includes("component") && (w.paths.has("") && (T = !0), !T))
|
|
982
984
|
for (const C of d) {
|
|
983
985
|
if (w.paths.has(C)) {
|
|
984
|
-
|
|
986
|
+
T = !0;
|
|
985
987
|
break;
|
|
986
988
|
}
|
|
987
989
|
let V = C.lastIndexOf(".");
|
|
988
990
|
for (; V !== -1; ) {
|
|
989
991
|
const G = C.substring(0, V);
|
|
990
992
|
if (w.paths.has(G)) {
|
|
991
|
-
|
|
993
|
+
T = !0;
|
|
992
994
|
break;
|
|
993
995
|
}
|
|
994
|
-
const
|
|
996
|
+
const B = C.substring(
|
|
995
997
|
V + 1
|
|
996
998
|
);
|
|
997
|
-
if (!isNaN(Number(
|
|
998
|
-
const
|
|
999
|
-
if (
|
|
999
|
+
if (!isNaN(Number(B))) {
|
|
1000
|
+
const _ = G.lastIndexOf(".");
|
|
1001
|
+
if (_ !== -1) {
|
|
1000
1002
|
const N = G.substring(
|
|
1001
1003
|
0,
|
|
1002
|
-
|
|
1004
|
+
_
|
|
1003
1005
|
);
|
|
1004
1006
|
if (w.paths.has(N)) {
|
|
1005
|
-
|
|
1007
|
+
T = !0;
|
|
1006
1008
|
break;
|
|
1007
1009
|
}
|
|
1008
1010
|
}
|
|
1009
1011
|
}
|
|
1010
1012
|
V = G.lastIndexOf(".");
|
|
1011
1013
|
}
|
|
1012
|
-
if (
|
|
1014
|
+
if (T) break;
|
|
1013
1015
|
}
|
|
1014
|
-
if (!
|
|
1016
|
+
if (!T && x.includes("deps") && w.depsFunction) {
|
|
1015
1017
|
const C = w.depsFunction(s);
|
|
1016
1018
|
let V = !1;
|
|
1017
|
-
typeof C == "boolean" ? C && (V = !0) : L(w.deps, C) || (w.deps = C, V = !0), V && (
|
|
1019
|
+
typeof C == "boolean" ? C && (V = !0) : L(w.deps, C) || (w.deps = C, V = !0), V && (T = !0);
|
|
1018
1020
|
}
|
|
1019
|
-
|
|
1021
|
+
T && w.forceUpdate();
|
|
1020
1022
|
}
|
|
1021
1023
|
}
|
|
1022
1024
|
}
|
|
@@ -1028,17 +1030,17 @@ function lt(t, c, h, g) {
|
|
|
1028
1030
|
throw new Error("Zod schema not found");
|
|
1029
1031
|
if (!u?.key)
|
|
1030
1032
|
throw new Error("Validation key not found");
|
|
1031
|
-
|
|
1033
|
+
H(u.key);
|
|
1032
1034
|
const n = r.getState().cogsStateStore[t];
|
|
1033
1035
|
try {
|
|
1034
1036
|
const s = r.getState().getValidationErrors(u.key);
|
|
1035
1037
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1036
|
-
f && f.startsWith(u.key) &&
|
|
1038
|
+
f && f.startsWith(u.key) && H(f);
|
|
1037
1039
|
});
|
|
1038
1040
|
const i = u.zodSchema.safeParse(n);
|
|
1039
1041
|
return i.success ? !0 : (i.error.errors.forEach((d) => {
|
|
1040
|
-
const k = d.path, w = d.message,
|
|
1041
|
-
e(
|
|
1042
|
+
const k = d.path, w = d.message, T = [u.key, ...k].join(".");
|
|
1043
|
+
e(T, w);
|
|
1042
1044
|
}), ut(t), !1);
|
|
1043
1045
|
} catch (s) {
|
|
1044
1046
|
return console.error("Zod schema validation failed", s), !1;
|
|
@@ -1061,16 +1063,16 @@ function lt(t, c, h, g) {
|
|
|
1061
1063
|
if (l === "removeValidation") return I.removeValidation;
|
|
1062
1064
|
}
|
|
1063
1065
|
if (l === "getFormRef")
|
|
1064
|
-
return () => It.getState().getFormRef(t + "." +
|
|
1066
|
+
return () => It.getState().getFormRef(t + "." + a.join("."));
|
|
1065
1067
|
if (l === "validationWrapper")
|
|
1066
1068
|
return ({
|
|
1067
1069
|
children: u,
|
|
1068
1070
|
hideMessage: e
|
|
1069
|
-
}) => /* @__PURE__ */
|
|
1071
|
+
}) => /* @__PURE__ */ mt(
|
|
1070
1072
|
Pt,
|
|
1071
1073
|
{
|
|
1072
1074
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1073
|
-
path:
|
|
1075
|
+
path: a,
|
|
1074
1076
|
validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1075
1077
|
stateKey: t,
|
|
1076
1078
|
validIndices: S?.validIndices,
|
|
@@ -1078,36 +1080,36 @@ function lt(t, c, h, g) {
|
|
|
1078
1080
|
}
|
|
1079
1081
|
);
|
|
1080
1082
|
if (l === "_stateKey") return t;
|
|
1081
|
-
if (l === "_path") return
|
|
1083
|
+
if (l === "_path") return a;
|
|
1082
1084
|
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1083
1085
|
if (l === "update")
|
|
1084
1086
|
return (u, e) => {
|
|
1085
1087
|
if (e?.debounce)
|
|
1086
1088
|
xt(() => {
|
|
1087
|
-
nt(c, u,
|
|
1088
|
-
const n = r.getState().getNestedState(t,
|
|
1089
|
+
nt(c, u, a, "");
|
|
1090
|
+
const n = r.getState().getNestedState(t, a);
|
|
1089
1091
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1090
1092
|
}, e.debounce);
|
|
1091
1093
|
else {
|
|
1092
|
-
nt(c, u,
|
|
1093
|
-
const n = r.getState().getNestedState(t,
|
|
1094
|
+
nt(c, u, a, "");
|
|
1095
|
+
const n = r.getState().getNestedState(t, a);
|
|
1094
1096
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1095
1097
|
}
|
|
1096
|
-
p(
|
|
1098
|
+
p(a);
|
|
1097
1099
|
};
|
|
1098
1100
|
if (l === "formElement")
|
|
1099
|
-
return (u, e) => /* @__PURE__ */
|
|
1101
|
+
return (u, e) => /* @__PURE__ */ mt(
|
|
1100
1102
|
_t,
|
|
1101
1103
|
{
|
|
1102
1104
|
setState: c,
|
|
1103
1105
|
stateKey: t,
|
|
1104
|
-
path:
|
|
1106
|
+
path: a,
|
|
1105
1107
|
child: u,
|
|
1106
1108
|
formOpts: e
|
|
1107
1109
|
}
|
|
1108
1110
|
);
|
|
1109
|
-
const j = [...
|
|
1110
|
-
return
|
|
1111
|
+
const j = [...a, l], tt = r.getState().getNestedState(t, j);
|
|
1112
|
+
return o(tt, j, S);
|
|
1111
1113
|
}
|
|
1112
1114
|
}, W = new Proxy(O, U);
|
|
1113
1115
|
return v.set(D, {
|
|
@@ -1115,14 +1117,14 @@ function lt(t, c, h, g) {
|
|
|
1115
1117
|
stateVersion: $
|
|
1116
1118
|
}), W;
|
|
1117
1119
|
}
|
|
1118
|
-
return
|
|
1120
|
+
return o(
|
|
1119
1121
|
r.getState().getNestedState(t, [])
|
|
1120
1122
|
);
|
|
1121
1123
|
}
|
|
1122
1124
|
function At(t) {
|
|
1123
|
-
return rt(
|
|
1125
|
+
return rt(Bt, { proxy: t });
|
|
1124
1126
|
}
|
|
1125
|
-
function
|
|
1127
|
+
function zt({
|
|
1126
1128
|
proxy: t,
|
|
1127
1129
|
rebuildStateShape: c
|
|
1128
1130
|
}) {
|
|
@@ -1131,13 +1133,13 @@ function Bt({
|
|
|
1131
1133
|
h,
|
|
1132
1134
|
t._path
|
|
1133
1135
|
).stateMapNoRender(
|
|
1134
|
-
(v, $, p, I,
|
|
1136
|
+
(v, $, p, I, o) => t._mapFn(v, $, p, I, o)
|
|
1135
1137
|
) : null;
|
|
1136
1138
|
}
|
|
1137
|
-
function
|
|
1139
|
+
function Bt({
|
|
1138
1140
|
proxy: t
|
|
1139
1141
|
}) {
|
|
1140
|
-
const c =
|
|
1142
|
+
const c = q(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1141
1143
|
return st(() => {
|
|
1142
1144
|
const g = c.current;
|
|
1143
1145
|
if (!g || !g.parentElement) return;
|
|
@@ -1151,19 +1153,19 @@ function zt({
|
|
|
1151
1153
|
effect: t._effect
|
|
1152
1154
|
};
|
|
1153
1155
|
r.getState().addSignalElement(h, y);
|
|
1154
|
-
const
|
|
1156
|
+
const a = r.getState().getNestedState(t._stateKey, t._path);
|
|
1155
1157
|
let S;
|
|
1156
1158
|
if (t._effect)
|
|
1157
1159
|
try {
|
|
1158
1160
|
S = new Function(
|
|
1159
1161
|
"state",
|
|
1160
1162
|
`return (${t._effect})(state)`
|
|
1161
|
-
)(
|
|
1163
|
+
)(a);
|
|
1162
1164
|
} catch (O) {
|
|
1163
|
-
console.error("Error evaluating effect function during mount:", O), S =
|
|
1165
|
+
console.error("Error evaluating effect function during mount:", O), S = a;
|
|
1164
1166
|
}
|
|
1165
1167
|
else
|
|
1166
|
-
S =
|
|
1168
|
+
S = a;
|
|
1167
1169
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1168
1170
|
const D = document.createTextNode(String(S));
|
|
1169
1171
|
g.replaceWith(D);
|
|
@@ -1188,7 +1190,7 @@ function ie(t) {
|
|
|
1188
1190
|
);
|
|
1189
1191
|
return rt("text", {}, String(c));
|
|
1190
1192
|
}
|
|
1191
|
-
function
|
|
1193
|
+
function Ht({
|
|
1192
1194
|
stateKey: t,
|
|
1193
1195
|
itemComponentId: c,
|
|
1194
1196
|
itemPath: h,
|
|
@@ -1196,25 +1198,29 @@ function qt({
|
|
|
1196
1198
|
}) {
|
|
1197
1199
|
const [, v] = K({}), [$, p] = Ot();
|
|
1198
1200
|
return st(() => {
|
|
1199
|
-
p.height > 0 && r.getState().setShadowMetadata(t, h, {
|
|
1201
|
+
p.height > 0 && r.getState().setShadowMetadata(t, h, {
|
|
1202
|
+
virtualizer: {
|
|
1203
|
+
itemHeight: p.height
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1200
1206
|
}, [p.height]), it(() => {
|
|
1201
|
-
const I = `${t}////${c}`,
|
|
1207
|
+
const I = `${t}////${c}`, o = r.getState().stateComponents.get(t) || {
|
|
1202
1208
|
components: /* @__PURE__ */ new Map()
|
|
1203
1209
|
};
|
|
1204
|
-
return
|
|
1210
|
+
return o.components.set(I, {
|
|
1205
1211
|
forceUpdate: () => v({}),
|
|
1206
1212
|
paths: /* @__PURE__ */ new Set([h.join(".")])
|
|
1207
|
-
}), r.getState().stateComponents.set(t,
|
|
1213
|
+
}), r.getState().stateComponents.set(t, o), () => {
|
|
1208
1214
|
const y = r.getState().stateComponents.get(t);
|
|
1209
1215
|
y && y.components.delete(I);
|
|
1210
1216
|
};
|
|
1211
|
-
}, [t, c, h.join(".")]), /* @__PURE__ */
|
|
1217
|
+
}, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: $, children: g });
|
|
1212
1218
|
}
|
|
1213
1219
|
export {
|
|
1214
1220
|
At as $cogsSignal,
|
|
1215
1221
|
ie as $cogsSignalStore,
|
|
1216
|
-
|
|
1217
|
-
|
|
1222
|
+
ae as addStateOptions,
|
|
1223
|
+
oe as createCogsState,
|
|
1218
1224
|
se as notifyComponent,
|
|
1219
1225
|
Lt as useCogsStateFn
|
|
1220
1226
|
};
|