cogsbox-state 0.5.305 → 0.5.306
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 +309 -313
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +31 -31
package/dist/CogsState.jsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as yt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as Ot, isDeepEqual as
|
|
5
|
-
import { pushFunc as vt, updateFn as ot, cutFunc as lt, ValidationWrapper as
|
|
3
|
+
import { useState as tt, useRef as B, useEffect as at, useLayoutEffect as dt, useMemo as It, createElement as st, useSyncExternalStore as Mt, startTransition as jt, useCallback as Et } from "react";
|
|
4
|
+
import { transformStateFunc as Ot, isDeepEqual as H, isFunction as Y, getNestedValue as z, getDifferences as pt, debounce as Ft } from "./utility.js";
|
|
5
|
+
import { pushFunc as vt, updateFn as ot, cutFunc as lt, ValidationWrapper as Rt, FormControlComponent as Ut } from "./Functions.jsx";
|
|
6
6
|
import Dt from "superjson";
|
|
7
7
|
import { v4 as wt } from "uuid";
|
|
8
8
|
import "zod";
|
|
@@ -17,18 +17,18 @@ function $t(t, c) {
|
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function bt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const f =
|
|
25
|
+
const f = nt(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, p = { ...y, ...f };
|
|
26
26
|
let I = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const a in c)
|
|
29
29
|
p.hasOwnProperty(a) ? (a == "localStorage" && c[a] && p[a].key !== c[a]?.key && (I = !0, p[a] = c[a]), a == "initialState" && c[a] && p[a] !== c[a] && // Different references
|
|
30
|
-
!
|
|
31
|
-
I &&
|
|
30
|
+
!H(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
|
|
31
|
+
I && b(t, p);
|
|
32
32
|
}
|
|
33
33
|
function de(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
@@ -43,16 +43,16 @@ const ue = (t, c) => {
|
|
|
43
43
|
...c?.validation,
|
|
44
44
|
...y[I].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
46
|
+
}, nt(I) || o.getState().setInitialStateOptions(I, y[I]);
|
|
47
47
|
}), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
|
|
48
|
-
const
|
|
49
|
-
const [v] =
|
|
50
|
-
|
|
48
|
+
const b = (I, a) => {
|
|
49
|
+
const [v] = tt(a?.componentId ?? wt());
|
|
50
|
+
bt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [
|
|
55
|
+
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, R] = Yt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
@@ -68,33 +68,33 @@ const ue = (t, c) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return R;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
|
-
|
|
74
|
+
bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Bt(I, a), St(I);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: b, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: ut,
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
79
|
+
setState: et,
|
|
80
|
+
getInitialOptions: nt,
|
|
81
81
|
getKeyState: Vt,
|
|
82
82
|
getValidationErrors: Lt,
|
|
83
83
|
setStateLog: Ht,
|
|
84
84
|
updateInitialStateGlobal: At,
|
|
85
85
|
addValidationError: zt,
|
|
86
|
-
removeValidationError:
|
|
86
|
+
removeValidationError: J,
|
|
87
87
|
setServerSyncActions: qt
|
|
88
|
-
} = o.getState(),
|
|
88
|
+
} = o.getState(), kt = (t, c, m, f, y) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
f
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const p = `${f}-${c}-${
|
|
95
|
+
const b = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
|
+
if (b && f) {
|
|
97
|
+
const p = `${f}-${c}-${b}`;
|
|
98
98
|
let I;
|
|
99
99
|
try {
|
|
100
100
|
I = ft(p)?.lastSyncedWithServer;
|
|
@@ -119,27 +119,27 @@ const ue = (t, c) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
121
|
}, Bt = (t, c) => {
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: f } = Ct(), y =
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: f } = Ct(), y = Y(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (y && f) {
|
|
124
|
-
const
|
|
124
|
+
const b = ft(
|
|
125
125
|
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
|
|
128
|
+
return et(t, b.state), St(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, xt = (t, c, m, f, y,
|
|
131
|
+
}, xt = (t, c, m, f, y, b) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: gt(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
137
|
y,
|
|
138
|
-
|
|
138
|
+
b
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
At(t, p.initialState), ut(t, p.updaterState),
|
|
142
|
+
At(t, p.initialState), ut(t, p.updaterState), et(t, p.state);
|
|
143
143
|
}, St = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
@@ -161,18 +161,18 @@ const ue = (t, c) => {
|
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: z(c, f),
|
|
165
|
+
newValue: z(m, f)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: z(m, f)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: z(c, f),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -185,7 +185,7 @@ function Yt(t, {
|
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: f,
|
|
187
187
|
formElements: y,
|
|
188
|
-
reactiveDeps:
|
|
188
|
+
reactiveDeps: b,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: I,
|
|
191
191
|
initialState: a,
|
|
@@ -193,14 +193,14 @@ function Yt(t, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [h] =
|
|
196
|
+
const [W, R] = tt({}), { sessionId: U } = Ct();
|
|
197
|
+
let G = !c;
|
|
198
|
+
const [h] = tt(c ?? wt()), l = o.getState().stateLog[h], it = B(/* @__PURE__ */ new Set()), Z = B(I ?? wt()), j = B(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
j.current =
|
|
201
|
+
j.current = nt(h) ?? null, at(() => {
|
|
202
202
|
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
-
|
|
203
|
+
et(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
205
|
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
@@ -216,21 +216,21 @@ function Yt(t, {
|
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
218
|
const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
|
-
if (!(i && !
|
|
219
|
+
if (!(i && !H(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
222
|
-
const A =
|
|
223
|
-
A && U && (
|
|
221
|
+
let g = null;
|
|
222
|
+
const A = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
A && U && (g = ft(`${U}-${h}-${A}`));
|
|
224
224
|
let w = a, T = !1;
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
225
|
+
const _ = s ? Date.now() : 0, C = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
|
|
226
|
+
s && _ > C ? (w = e.serverState.data, T = !0) : g && C > M && (w = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), xt(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
229
|
w,
|
|
230
230
|
rt,
|
|
231
|
-
|
|
231
|
+
Z.current,
|
|
232
232
|
U
|
|
233
|
-
), T && A && U &&
|
|
233
|
+
), T && A && U && kt(w, h, e, U, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
@@ -238,178 +238,178 @@ function Yt(t, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), dt(() => {
|
|
241
|
-
|
|
241
|
+
G && $t(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: f,
|
|
246
246
|
middleware: j.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${h}////${
|
|
248
|
+
const e = `${h}////${Z.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => R({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: b || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(h, r),
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), R({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const rt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const
|
|
264
|
-
it.current.add(
|
|
263
|
+
const g = `${h}-${r.join(".")}`;
|
|
264
|
+
it.current.add(g);
|
|
265
265
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const A =
|
|
266
|
+
const u = o.getState();
|
|
267
|
+
et(h, (g) => {
|
|
268
|
+
const A = Y(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
|
|
269
269
|
if (w) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const O = r.slice(0, -1),
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
270
|
+
let V = !1, k = u.signalDomElements.get(w);
|
|
271
|
+
if ((!k || k.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const O = r.slice(0, -1), D = z(A, O);
|
|
273
|
+
if (Array.isArray(D)) {
|
|
274
|
+
V = !0;
|
|
275
275
|
const $ = `${h}-${O.join(".")}`;
|
|
276
|
-
|
|
276
|
+
k = u.signalDomElements.get($);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const O =
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (k) {
|
|
280
|
+
const O = V ? z(A, r.slice(0, -1)) : z(A, r);
|
|
281
|
+
k.forEach(({ parentId: D, position: $, effect: E }) => {
|
|
282
|
+
const N = document.querySelector(
|
|
283
|
+
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (N) {
|
|
286
|
+
const F = Array.from(N.childNodes);
|
|
287
|
+
if (F[$]) {
|
|
288
|
+
const x = E ? new Function("state", `return (${E})(state)`)(O) : O;
|
|
289
|
+
F[$].textContent = String(x);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState",
|
|
295
|
+
console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && J(
|
|
296
296
|
(i || j.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
298
|
const T = r.slice(0, r.length - 1);
|
|
299
|
-
s.updateType === "cut" && j.current?.validation?.key &&
|
|
299
|
+
s.updateType === "cut" && j.current?.validation?.key && J(
|
|
300
300
|
j.current?.validation?.key + "." + T.join(".")
|
|
301
301
|
), s.updateType === "insert" && j.current?.validation?.key && Lt(
|
|
302
302
|
j.current?.validation?.key + "." + T.join(".")
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let $ =
|
|
307
|
-
|
|
303
|
+
).filter(([k, O]) => {
|
|
304
|
+
let D = k?.split(".").length;
|
|
305
|
+
if (k == T.join(".") && D == T.length - 1) {
|
|
306
|
+
let $ = k + "." + T;
|
|
307
|
+
J(k), zt($, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const _ = u.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
|
|
312
|
+
const V = pt(g, A), k = new Set(V), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
314
|
+
D,
|
|
315
315
|
$
|
|
316
|
-
] of
|
|
316
|
+
] of _.components.entries()) {
|
|
317
317
|
let E = !1;
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", $), !
|
|
320
|
-
if (
|
|
318
|
+
const N = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", $), !N.includes("none")) {
|
|
320
|
+
if (N.includes("all")) {
|
|
321
321
|
$.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (N.includes("component") && (($.paths.has(O) || $.paths.has("")) && (E = !0), !E))
|
|
325
|
+
for (const F of k) {
|
|
326
|
+
let x = F;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if ($.paths.has(
|
|
328
|
+
if ($.paths.has(x)) {
|
|
329
329
|
E = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const L = x.lastIndexOf(".");
|
|
333
|
+
if (L !== -1) {
|
|
334
|
+
const X = x.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
L
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && $.paths.has(
|
|
339
|
+
Number(x.substring(L + 1))
|
|
340
|
+
) && $.paths.has(X)) {
|
|
341
341
|
E = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
x = X;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
x = "";
|
|
347
|
+
if (x === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
if (E) break;
|
|
351
351
|
}
|
|
352
|
-
if (!E &&
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!E && N.includes("deps") && $.depsFunction) {
|
|
353
|
+
const F = $.depsFunction(A);
|
|
354
|
+
let x = !1;
|
|
355
|
+
typeof F == "boolean" ? F && (x = !0) : H($.deps, F) || ($.deps = F, x = !0), x && (E = !0);
|
|
356
356
|
}
|
|
357
357
|
E && $.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const O = r.slice(0, -1),
|
|
364
|
-
return
|
|
361
|
+
const C = Date.now();
|
|
362
|
+
r = r.map((V, k) => {
|
|
363
|
+
const O = r.slice(0, -1), D = z(A, O);
|
|
364
|
+
return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : V;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: M, newValue:
|
|
366
|
+
const { oldValue: M, newValue: P } = Jt(
|
|
367
367
|
s.updateType,
|
|
368
|
-
|
|
368
|
+
g,
|
|
369
369
|
A,
|
|
370
370
|
r
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), q = {
|
|
372
|
+
timeStamp: C,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: M,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: P
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
|
|
382
|
+
u.updateShadowAtPath(h, r, A);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
|
|
385
|
+
const V = r.slice(0, -1);
|
|
386
|
+
u.insertShadowArrayElement(h, V, P);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
|
|
389
|
+
const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
+
u.removeShadowArrayElement(h, k, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (Ht(h, (
|
|
394
|
-
const O = [...
|
|
395
|
-
const E = `${$.stateKey}:${JSON.stringify($.path)}`,
|
|
396
|
-
return
|
|
393
|
+
if (Ht(h, (V) => {
|
|
394
|
+
const O = [...V ?? [], q].reduce((D, $) => {
|
|
395
|
+
const E = `${$.stateKey}:${JSON.stringify($.path)}`, N = D.get(E);
|
|
396
|
+
return N ? (N.timeStamp = Math.max(N.timeStamp, $.timeStamp), N.newValue = $.newValue, N.oldValue = N.oldValue ?? $.oldValue, N.updateType = $.updateType) : D.set(E, { ...$ }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(O.values());
|
|
399
|
-
}),
|
|
399
|
+
}), kt(
|
|
400
400
|
A,
|
|
401
401
|
h,
|
|
402
402
|
j.current,
|
|
403
403
|
U
|
|
404
404
|
), j.current?.middleware && j.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
406
|
+
update: q
|
|
407
407
|
}), j.current?.serverSync) {
|
|
408
|
-
const
|
|
408
|
+
const V = u.serverState[h], k = j.current?.serverSync;
|
|
409
409
|
qt(h, {
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
410
|
+
syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: A }),
|
|
411
|
+
rollBackState: V,
|
|
412
|
+
actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
@@ -421,58 +421,58 @@ function Yt(t, {
|
|
|
421
421
|
gt(
|
|
422
422
|
h,
|
|
423
423
|
rt,
|
|
424
|
-
|
|
424
|
+
Z.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] ||
|
|
427
|
+
), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
|
|
428
428
|
const d = It(() => gt(
|
|
429
429
|
h,
|
|
430
430
|
rt,
|
|
431
|
-
|
|
431
|
+
Z.current,
|
|
432
432
|
U
|
|
433
433
|
), [h, U]);
|
|
434
434
|
return [Vt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function gt(t, c, m, f) {
|
|
437
437
|
const y = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
438
|
+
let b = 0;
|
|
439
439
|
const p = (v) => {
|
|
440
440
|
const n = v.join(".");
|
|
441
441
|
for (const [S] of y)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && y.delete(S);
|
|
443
|
-
|
|
443
|
+
b++;
|
|
444
444
|
}, I = {
|
|
445
445
|
removeValidation: (v) => {
|
|
446
|
-
v?.validationKey &&
|
|
446
|
+
v?.validationKey && J(v.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (v) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
|
|
453
|
+
const W = a(S, []), R = nt(t), U = Y(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${f}-${t}-${U}`;
|
|
454
|
+
G && localStorage.removeItem(G), ut(t, W), et(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (v) => {
|
|
461
|
-
y.clear(),
|
|
461
|
+
y.clear(), b++;
|
|
462
462
|
const n = gt(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
f
|
|
467
|
-
), S = o.getState().initialStateGlobal[t],
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = nt(t), R = Y(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${f}-${t}-${R}`;
|
|
468
468
|
return localStorage.getItem(U) && localStorage.removeItem(U), jt(() => {
|
|
469
|
-
At(t, v), o.getState().initializeShadowState(t, v), ut(t, n),
|
|
470
|
-
const
|
|
471
|
-
|
|
469
|
+
At(t, v), o.getState().initializeShadowState(t, v), ut(t, n), et(t, v);
|
|
470
|
+
const G = o.getState().stateComponents.get(t);
|
|
471
|
+
G && G.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (G) => n.get()[G]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
@@ -480,17 +480,17 @@ function gt(t, c, m, f) {
|
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const v = o.getState().serverState[t];
|
|
483
|
-
return !!(v &&
|
|
483
|
+
return !!(v && H(v, Vt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(v, n = [], S) {
|
|
487
|
-
const
|
|
488
|
-
y.get(
|
|
489
|
-
const
|
|
487
|
+
const W = n.map(String).join(".");
|
|
488
|
+
y.get(W);
|
|
489
|
+
const R = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(I).forEach((h) => {
|
|
493
|
-
|
|
493
|
+
R[h] = I[h];
|
|
494
494
|
});
|
|
495
495
|
const U = {
|
|
496
496
|
apply(h, l, it) {
|
|
@@ -530,8 +530,8 @@ function gt(t, c, m, f) {
|
|
|
530
530
|
if (r && !r.paths.has("")) {
|
|
531
531
|
const s = n.join(".");
|
|
532
532
|
let i = !0;
|
|
533
|
-
for (const
|
|
534
|
-
if (s.startsWith(
|
|
533
|
+
for (const u of r.paths)
|
|
534
|
+
if (s.startsWith(u) && (s === u || s[u.length] === ".")) {
|
|
535
535
|
i = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
@@ -553,13 +553,13 @@ function gt(t, c, m, f) {
|
|
|
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 A = [s, ...
|
|
558
|
-
o.getState().addValidationError(A,
|
|
556
|
+
o.getState().removeValidationError(s), i.errors.forEach((g) => {
|
|
557
|
+
const A = [s, ...g.path].join(".");
|
|
558
|
+
o.getState().addValidationError(A, g.message);
|
|
559
559
|
});
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
const u = o.getState().stateComponents.get(t);
|
|
561
|
+
u && u.components.forEach((g) => {
|
|
562
|
+
g.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;
|
|
@@ -568,20 +568,20 @@ function gt(t, c, m, f) {
|
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r =
|
|
572
|
-
return
|
|
571
|
+
const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = z(e, n);
|
|
572
|
+
return H(d, r) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
575
575
|
return function() {
|
|
576
576
|
const d = o().getNestedState(
|
|
577
577
|
t,
|
|
578
578
|
n
|
|
579
|
-
), e = o.getState().initialStateGlobal[t], r =
|
|
580
|
-
return
|
|
579
|
+
), e = o.getState().initialStateGlobal[t], r = z(e, n);
|
|
580
|
+
return H(d, r) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = nt(t), r = Y(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -621,160 +621,156 @@ function gt(t, c, m, f) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e,
|
|
624
|
+
} = e, u = B(null), [g, A] = tt({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
|
-
}), w =
|
|
627
|
+
}), [, w] = tt({}), T = B(i), _ = B(0), C = B(!0);
|
|
628
|
+
at(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
|
|
629
|
+
const M = o().getNestedState(
|
|
628
630
|
t,
|
|
629
631
|
n
|
|
630
|
-
),
|
|
632
|
+
), P = M.length, { totalHeight: q, positions: V } = It(() => {
|
|
631
633
|
const E = o.getState().getShadowMetadata(t, n) || [];
|
|
632
|
-
let
|
|
633
|
-
const
|
|
634
|
-
let
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
H && (_ = !0), C += H || r;
|
|
634
|
+
let N = 0;
|
|
635
|
+
const F = [];
|
|
636
|
+
for (let x = 0; x < P; x++) {
|
|
637
|
+
F[x] = N;
|
|
638
|
+
const L = E[x]?.virtualizer?.itemHeight;
|
|
639
|
+
N += L || r;
|
|
639
640
|
}
|
|
640
|
-
return
|
|
641
|
-
}, [
|
|
642
|
-
const E = Math.max(0,
|
|
643
|
-
{ length:
|
|
644
|
-
(
|
|
645
|
-
),
|
|
646
|
-
return a(
|
|
641
|
+
return { totalHeight: N, positions: F };
|
|
642
|
+
}, [P, t, n.join("."), r]), k = It(() => {
|
|
643
|
+
const E = Math.max(0, g.startIndex), N = Math.min(P, g.endIndex), F = Array.from(
|
|
644
|
+
{ length: N - E },
|
|
645
|
+
(L, X) => E + X
|
|
646
|
+
), x = F.map((L) => M[L]);
|
|
647
|
+
return a(x, n, {
|
|
647
648
|
...S,
|
|
648
|
-
validIndices:
|
|
649
|
+
validIndices: F
|
|
649
650
|
});
|
|
650
|
-
}, [
|
|
651
|
+
}, [g.startIndex, g.endIndex, M, P]);
|
|
651
652
|
dt(() => {
|
|
652
|
-
const E =
|
|
653
|
+
const E = u.current;
|
|
653
654
|
if (!E) return;
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
const
|
|
657
|
-
const { scrollTop:
|
|
658
|
-
|
|
659
|
-
let mt = 0, ct =
|
|
655
|
+
const N = T.current, F = P > _.current;
|
|
656
|
+
_.current = P;
|
|
657
|
+
const x = () => {
|
|
658
|
+
const { scrollTop: L, clientHeight: X, scrollHeight: Pt } = E;
|
|
659
|
+
T.current = Pt - L - X < 10;
|
|
660
|
+
let mt = 0, ct = P - 1;
|
|
660
661
|
for (; mt <= ct; ) {
|
|
661
662
|
const K = Math.floor((mt + ct) / 2);
|
|
662
|
-
|
|
663
|
+
V[K] < L ? mt = K + 1 : ct = K - 1;
|
|
663
664
|
}
|
|
664
665
|
const ht = Math.max(0, ct - s);
|
|
665
666
|
let Q = ht;
|
|
666
|
-
const _t =
|
|
667
|
-
for (; Q <
|
|
667
|
+
const _t = L + X;
|
|
668
|
+
for (; Q < P && V[Q] < _t; )
|
|
668
669
|
Q++;
|
|
669
|
-
Q = Math.min(
|
|
670
|
+
Q = Math.min(P, Q + s), A((K) => K.startIndex !== ht || K.endIndex !== Q ? { startIndex: ht, endIndex: Q } : K);
|
|
670
671
|
};
|
|
671
|
-
return E.addEventListener("scroll",
|
|
672
|
+
return E.addEventListener("scroll", x, {
|
|
672
673
|
passive: !0
|
|
673
|
-
}), i &&
|
|
674
|
+
}), i && (C.current && P > 0 ? requestAnimationFrame(() => {
|
|
675
|
+
requestAnimationFrame(() => {
|
|
676
|
+
u.current && (u.current.scrollTo({
|
|
677
|
+
top: u.current.scrollHeight,
|
|
678
|
+
behavior: "auto"
|
|
679
|
+
}), C.current = !1);
|
|
680
|
+
});
|
|
681
|
+
}) : !C.current && N && F && requestAnimationFrame(() => {
|
|
674
682
|
E.scrollTo({
|
|
675
683
|
top: E.scrollHeight,
|
|
676
684
|
behavior: "smooth"
|
|
677
685
|
});
|
|
678
|
-
}),
|
|
679
|
-
}, [
|
|
680
|
-
if (i && P.current && V > 0 && x.current) {
|
|
681
|
-
const E = g.current;
|
|
682
|
-
E && requestAnimationFrame(() => {
|
|
683
|
-
requestAnimationFrame(() => {
|
|
684
|
-
E.scrollTo({
|
|
685
|
-
top: E.scrollHeight,
|
|
686
|
-
behavior: "auto"
|
|
687
|
-
}), P.current = !1;
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
}, [i, V, b]);
|
|
686
|
+
})), x(), () => E.removeEventListener("scroll", x);
|
|
687
|
+
}, [P, V, s, i]);
|
|
692
688
|
const O = Et(
|
|
693
689
|
(E = "smooth") => {
|
|
694
|
-
|
|
695
|
-
top:
|
|
690
|
+
u.current && u.current.scrollTo({
|
|
691
|
+
top: u.current.scrollHeight,
|
|
696
692
|
behavior: E
|
|
697
693
|
});
|
|
698
694
|
},
|
|
699
695
|
[]
|
|
700
|
-
),
|
|
701
|
-
(E,
|
|
702
|
-
|
|
703
|
-
top:
|
|
704
|
-
behavior:
|
|
696
|
+
), D = Et(
|
|
697
|
+
(E, N = "smooth") => {
|
|
698
|
+
u.current && V[E] !== void 0 && u.current.scrollTo({
|
|
699
|
+
top: V[E],
|
|
700
|
+
behavior: N
|
|
705
701
|
});
|
|
706
702
|
},
|
|
707
|
-
[
|
|
703
|
+
[V]
|
|
708
704
|
), $ = {
|
|
709
705
|
outer: {
|
|
710
|
-
ref:
|
|
706
|
+
ref: u,
|
|
711
707
|
style: { overflowY: "auto", height: "100%" }
|
|
712
708
|
},
|
|
713
709
|
inner: {
|
|
714
710
|
style: {
|
|
715
|
-
height: `${
|
|
711
|
+
height: `${q}px`,
|
|
716
712
|
position: "relative"
|
|
717
713
|
}
|
|
718
714
|
},
|
|
719
715
|
list: {
|
|
720
716
|
style: {
|
|
721
|
-
transform: `translateY(${
|
|
717
|
+
transform: `translateY(${V[g.startIndex] || 0}px)`
|
|
722
718
|
}
|
|
723
719
|
}
|
|
724
720
|
};
|
|
725
721
|
return {
|
|
726
|
-
virtualState:
|
|
722
|
+
virtualState: k,
|
|
727
723
|
virtualizerProps: $,
|
|
728
724
|
scrollToBottom: O,
|
|
729
|
-
scrollToIndex:
|
|
725
|
+
scrollToIndex: D
|
|
730
726
|
};
|
|
731
727
|
};
|
|
732
728
|
if (l === "stateSort")
|
|
733
729
|
return (e) => {
|
|
734
730
|
const s = [...d()].sort(
|
|
735
|
-
(
|
|
736
|
-
), i = s.map(({ item:
|
|
731
|
+
(g, A) => e(g.item, A.item)
|
|
732
|
+
), i = s.map(({ item: g }) => g), u = {
|
|
737
733
|
...S,
|
|
738
734
|
validIndices: s.map(
|
|
739
|
-
({ originalIndex:
|
|
735
|
+
({ originalIndex: g }) => g
|
|
740
736
|
)
|
|
741
737
|
};
|
|
742
|
-
return a(i, n,
|
|
738
|
+
return a(i, n, u);
|
|
743
739
|
};
|
|
744
740
|
if (l === "stateFilter")
|
|
745
741
|
return (e) => {
|
|
746
742
|
const s = d().filter(
|
|
747
|
-
({ item:
|
|
748
|
-
), i = s.map(({ item:
|
|
743
|
+
({ item: g }, A) => e(g, A)
|
|
744
|
+
), i = s.map(({ item: g }) => g), u = {
|
|
749
745
|
...S,
|
|
750
746
|
validIndices: s.map(
|
|
751
|
-
({ originalIndex:
|
|
747
|
+
({ originalIndex: g }) => g
|
|
752
748
|
)
|
|
753
749
|
};
|
|
754
|
-
return a(i, n,
|
|
750
|
+
return a(i, n, u);
|
|
755
751
|
};
|
|
756
752
|
if (l === "stateMap")
|
|
757
753
|
return (e) => {
|
|
758
754
|
const r = o.getState().getNestedState(t, n);
|
|
759
|
-
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i,
|
|
760
|
-
const
|
|
761
|
-
return e(
|
|
755
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
|
|
756
|
+
const g = r[i], A = [...n, i.toString()], w = a(g, A, S);
|
|
757
|
+
return e(g, w, {
|
|
762
758
|
register: () => {
|
|
763
|
-
const [,
|
|
759
|
+
const [, _] = tt({}), C = `${m}-${n.join(".")}-${i}`;
|
|
764
760
|
dt(() => {
|
|
765
|
-
const M = `${t}////${
|
|
761
|
+
const M = `${t}////${C}`, P = o.getState().stateComponents.get(t) || {
|
|
766
762
|
components: /* @__PURE__ */ new Map()
|
|
767
763
|
};
|
|
768
|
-
return
|
|
769
|
-
forceUpdate: () =>
|
|
764
|
+
return P.components.set(M, {
|
|
765
|
+
forceUpdate: () => _({}),
|
|
770
766
|
paths: /* @__PURE__ */ new Set([A.join(".")])
|
|
771
|
-
}), o.getState().stateComponents.set(t,
|
|
772
|
-
const
|
|
773
|
-
|
|
767
|
+
}), o.getState().stateComponents.set(t, P), () => {
|
|
768
|
+
const q = o.getState().stateComponents.get(t);
|
|
769
|
+
q && q.components.delete(M);
|
|
774
770
|
};
|
|
775
|
-
}, [t,
|
|
771
|
+
}, [t, C]);
|
|
776
772
|
},
|
|
777
|
-
index:
|
|
773
|
+
index: u,
|
|
778
774
|
originalIndex: i
|
|
779
775
|
});
|
|
780
776
|
}) : (console.warn(
|
|
@@ -784,9 +780,9 @@ function gt(t, c, m, f) {
|
|
|
784
780
|
};
|
|
785
781
|
if (l === "stateMapNoRender")
|
|
786
782
|
return (e) => v.map((s, i) => {
|
|
787
|
-
let
|
|
788
|
-
S?.validIndices && S.validIndices[i] !== void 0 ?
|
|
789
|
-
const
|
|
783
|
+
let u;
|
|
784
|
+
S?.validIndices && S.validIndices[i] !== void 0 ? u = S.validIndices[i] : u = i;
|
|
785
|
+
const g = [...n, u.toString()], A = a(s, g, S);
|
|
790
786
|
return e(
|
|
791
787
|
s,
|
|
792
788
|
A,
|
|
@@ -808,17 +804,17 @@ function gt(t, c, m, f) {
|
|
|
808
804
|
if (l === "stateList")
|
|
809
805
|
return (e) => {
|
|
810
806
|
const r = o.getState().getNestedState(t, n);
|
|
811
|
-
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i,
|
|
812
|
-
const
|
|
807
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
|
|
808
|
+
const g = r[i], A = [...n, i.toString()], w = a(g, A, S), T = `${m}-${n.join(".")}-${i}`;
|
|
813
809
|
return st(Qt, {
|
|
814
810
|
key: i,
|
|
815
811
|
stateKey: t,
|
|
816
812
|
itemComponentId: T,
|
|
817
813
|
itemPath: A,
|
|
818
814
|
children: e(
|
|
819
|
-
u,
|
|
820
|
-
w,
|
|
821
815
|
g,
|
|
816
|
+
w,
|
|
817
|
+
u,
|
|
822
818
|
r,
|
|
823
819
|
a(r, n, S)
|
|
824
820
|
)
|
|
@@ -830,7 +826,7 @@ function gt(t, c, m, f) {
|
|
|
830
826
|
if (l === "stateFlattenOn")
|
|
831
827
|
return (e) => {
|
|
832
828
|
const r = v;
|
|
833
|
-
y.clear(),
|
|
829
|
+
y.clear(), b++;
|
|
834
830
|
const s = r.flatMap(
|
|
835
831
|
(i) => i[e] ?? []
|
|
836
832
|
);
|
|
@@ -859,22 +855,22 @@ function gt(t, c, m, f) {
|
|
|
859
855
|
));
|
|
860
856
|
if (l === "uniqueInsert")
|
|
861
857
|
return (e, r, s) => {
|
|
862
|
-
const i = o.getState().getNestedState(t, n),
|
|
863
|
-
let
|
|
858
|
+
const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
|
|
859
|
+
let g = null;
|
|
864
860
|
if (!i.some((w) => {
|
|
865
861
|
if (r) {
|
|
866
|
-
const
|
|
867
|
-
(
|
|
862
|
+
const _ = r.every(
|
|
863
|
+
(C) => H(w[C], u[C])
|
|
868
864
|
);
|
|
869
|
-
return
|
|
865
|
+
return _ && (g = w), _;
|
|
870
866
|
}
|
|
871
|
-
const T =
|
|
872
|
-
return T && (
|
|
867
|
+
const T = H(w, u);
|
|
868
|
+
return T && (g = w), T;
|
|
873
869
|
}))
|
|
874
|
-
p(n), vt(c,
|
|
875
|
-
else if (s &&
|
|
876
|
-
const w = s(
|
|
877
|
-
(
|
|
870
|
+
p(n), vt(c, u, n, t);
|
|
871
|
+
else if (s && g) {
|
|
872
|
+
const w = s(g), T = i.map(
|
|
873
|
+
(_) => H(_, g) ? w : _
|
|
878
874
|
);
|
|
879
875
|
p(n), ot(c, T, n);
|
|
880
876
|
}
|
|
@@ -900,7 +896,7 @@ function gt(t, c, m, f) {
|
|
|
900
896
|
if (l === "stateFind")
|
|
901
897
|
return (e) => {
|
|
902
898
|
const s = d().find(
|
|
903
|
-
({ item:
|
|
899
|
+
({ item: u }, g) => e(u, g)
|
|
904
900
|
);
|
|
905
901
|
if (!s) return;
|
|
906
902
|
const i = [...n, s.originalIndex.toString()];
|
|
@@ -909,22 +905,22 @@ function gt(t, c, m, f) {
|
|
|
909
905
|
if (l === "findWith")
|
|
910
906
|
return (e, r) => {
|
|
911
907
|
const i = d().find(
|
|
912
|
-
({ item:
|
|
908
|
+
({ item: g }) => g[e] === r
|
|
913
909
|
);
|
|
914
910
|
if (!i) return;
|
|
915
|
-
const
|
|
916
|
-
return a(i.item,
|
|
911
|
+
const u = [...n, i.originalIndex.toString()];
|
|
912
|
+
return a(i.item, u, S);
|
|
917
913
|
};
|
|
918
914
|
}
|
|
919
|
-
const
|
|
920
|
-
if (!isNaN(Number(
|
|
915
|
+
const Z = n[n.length - 1];
|
|
916
|
+
if (!isNaN(Number(Z))) {
|
|
921
917
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
922
918
|
if (Array.isArray(e) && l === "cut")
|
|
923
919
|
return () => lt(
|
|
924
920
|
c,
|
|
925
921
|
d,
|
|
926
922
|
t,
|
|
927
|
-
Number(
|
|
923
|
+
Number(Z)
|
|
928
924
|
);
|
|
929
925
|
}
|
|
930
926
|
if (l === "get")
|
|
@@ -936,13 +932,13 @@ function gt(t, c, m, f) {
|
|
|
936
932
|
return o.getState().getNestedState(t, n);
|
|
937
933
|
};
|
|
938
934
|
if (l === "$derive")
|
|
939
|
-
return (d) =>
|
|
935
|
+
return (d) => Nt({
|
|
940
936
|
_stateKey: t,
|
|
941
937
|
_path: n,
|
|
942
938
|
_effect: d.toString()
|
|
943
939
|
});
|
|
944
940
|
if (l === "$get")
|
|
945
|
-
return () =>
|
|
941
|
+
return () => Nt({
|
|
946
942
|
_stateKey: t,
|
|
947
943
|
_path: n
|
|
948
944
|
});
|
|
@@ -988,55 +984,55 @@ function gt(t, c, m, f) {
|
|
|
988
984
|
);
|
|
989
985
|
const i = o.getState().stateComponents.get(t);
|
|
990
986
|
if (i) {
|
|
991
|
-
const
|
|
987
|
+
const u = pt(e, s), g = new Set(u);
|
|
992
988
|
for (const [
|
|
993
989
|
A,
|
|
994
990
|
w
|
|
995
991
|
] of i.components.entries()) {
|
|
996
992
|
let T = !1;
|
|
997
|
-
const
|
|
998
|
-
if (!
|
|
999
|
-
if (
|
|
993
|
+
const _ = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
994
|
+
if (!_.includes("none")) {
|
|
995
|
+
if (_.includes("all")) {
|
|
1000
996
|
w.forceUpdate();
|
|
1001
997
|
continue;
|
|
1002
998
|
}
|
|
1003
|
-
if (
|
|
1004
|
-
for (const
|
|
1005
|
-
if (w.paths.has(
|
|
999
|
+
if (_.includes("component") && (w.paths.has("") && (T = !0), !T))
|
|
1000
|
+
for (const C of g) {
|
|
1001
|
+
if (w.paths.has(C)) {
|
|
1006
1002
|
T = !0;
|
|
1007
1003
|
break;
|
|
1008
1004
|
}
|
|
1009
|
-
let M =
|
|
1005
|
+
let M = C.lastIndexOf(".");
|
|
1010
1006
|
for (; M !== -1; ) {
|
|
1011
|
-
const
|
|
1012
|
-
if (w.paths.has(
|
|
1007
|
+
const P = C.substring(0, M);
|
|
1008
|
+
if (w.paths.has(P)) {
|
|
1013
1009
|
T = !0;
|
|
1014
1010
|
break;
|
|
1015
1011
|
}
|
|
1016
|
-
const
|
|
1012
|
+
const q = C.substring(
|
|
1017
1013
|
M + 1
|
|
1018
1014
|
);
|
|
1019
|
-
if (!isNaN(Number(
|
|
1020
|
-
const
|
|
1021
|
-
if (
|
|
1022
|
-
const
|
|
1015
|
+
if (!isNaN(Number(q))) {
|
|
1016
|
+
const V = P.lastIndexOf(".");
|
|
1017
|
+
if (V !== -1) {
|
|
1018
|
+
const k = P.substring(
|
|
1023
1019
|
0,
|
|
1024
|
-
|
|
1020
|
+
V
|
|
1025
1021
|
);
|
|
1026
|
-
if (w.paths.has(
|
|
1022
|
+
if (w.paths.has(k)) {
|
|
1027
1023
|
T = !0;
|
|
1028
1024
|
break;
|
|
1029
1025
|
}
|
|
1030
1026
|
}
|
|
1031
1027
|
}
|
|
1032
|
-
M =
|
|
1028
|
+
M = P.lastIndexOf(".");
|
|
1033
1029
|
}
|
|
1034
1030
|
if (T) break;
|
|
1035
1031
|
}
|
|
1036
|
-
if (!T &&
|
|
1037
|
-
const
|
|
1032
|
+
if (!T && _.includes("deps") && w.depsFunction) {
|
|
1033
|
+
const C = w.depsFunction(s);
|
|
1038
1034
|
let M = !1;
|
|
1039
|
-
typeof
|
|
1035
|
+
typeof C == "boolean" ? C && (M = !0) : H(w.deps, C) || (w.deps = C, M = !0), M && (T = !0);
|
|
1040
1036
|
}
|
|
1041
1037
|
T && w.forceUpdate();
|
|
1042
1038
|
}
|
|
@@ -1050,16 +1046,16 @@ function gt(t, c, m, f) {
|
|
|
1050
1046
|
throw new Error("Zod schema not found");
|
|
1051
1047
|
if (!d?.key)
|
|
1052
1048
|
throw new Error("Validation key not found");
|
|
1053
|
-
|
|
1049
|
+
J(d.key);
|
|
1054
1050
|
const r = o.getState().cogsStateStore[t];
|
|
1055
1051
|
try {
|
|
1056
1052
|
const s = o.getState().getValidationErrors(d.key);
|
|
1057
|
-
s && s.length > 0 && s.forEach(([
|
|
1058
|
-
|
|
1053
|
+
s && s.length > 0 && s.forEach(([u]) => {
|
|
1054
|
+
u && u.startsWith(d.key) && J(u);
|
|
1059
1055
|
});
|
|
1060
1056
|
const i = d.zodSchema.safeParse(r);
|
|
1061
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
1062
|
-
const A =
|
|
1057
|
+
return i.success ? !0 : (i.error.errors.forEach((g) => {
|
|
1058
|
+
const A = g.path, w = g.message, T = [d.key, ...A].join(".");
|
|
1063
1059
|
e(T, w);
|
|
1064
1060
|
}), St(t), !1);
|
|
1065
1061
|
} catch (s) {
|
|
@@ -1089,7 +1085,7 @@ function gt(t, c, m, f) {
|
|
|
1089
1085
|
children: d,
|
|
1090
1086
|
hideMessage: e
|
|
1091
1087
|
}) => /* @__PURE__ */ yt(
|
|
1092
|
-
|
|
1088
|
+
Rt,
|
|
1093
1089
|
{
|
|
1094
1090
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1095
1091
|
path: n,
|
|
@@ -1105,7 +1101,7 @@ function gt(t, c, m, f) {
|
|
|
1105
1101
|
if (l === "update")
|
|
1106
1102
|
return (d, e) => {
|
|
1107
1103
|
if (e?.debounce)
|
|
1108
|
-
|
|
1104
|
+
Ft(() => {
|
|
1109
1105
|
ot(c, d, n, "");
|
|
1110
1106
|
const r = o.getState().getNestedState(t, n);
|
|
1111
1107
|
e?.afterUpdate && e.afterUpdate(r);
|
|
@@ -1131,17 +1127,17 @@ function gt(t, c, m, f) {
|
|
|
1131
1127
|
const j = [...n, l], rt = o.getState().getNestedState(t, j);
|
|
1132
1128
|
return a(rt, j, S);
|
|
1133
1129
|
}
|
|
1134
|
-
},
|
|
1135
|
-
return y.set(
|
|
1136
|
-
proxy:
|
|
1137
|
-
stateVersion:
|
|
1138
|
-
}),
|
|
1130
|
+
}, G = new Proxy(R, U);
|
|
1131
|
+
return y.set(W, {
|
|
1132
|
+
proxy: G,
|
|
1133
|
+
stateVersion: b
|
|
1134
|
+
}), G;
|
|
1139
1135
|
}
|
|
1140
1136
|
return a(
|
|
1141
1137
|
o.getState().getNestedState(t, [])
|
|
1142
1138
|
);
|
|
1143
1139
|
}
|
|
1144
|
-
function
|
|
1140
|
+
function Nt(t) {
|
|
1145
1141
|
return st(Xt, { proxy: t });
|
|
1146
1142
|
}
|
|
1147
1143
|
function Zt({
|
|
@@ -1153,13 +1149,13 @@ function Zt({
|
|
|
1153
1149
|
m,
|
|
1154
1150
|
t._path
|
|
1155
1151
|
).stateMapNoRender(
|
|
1156
|
-
(y,
|
|
1152
|
+
(y, b, p, I, a) => t._mapFn(y, b, p, I, a)
|
|
1157
1153
|
) : null;
|
|
1158
1154
|
}
|
|
1159
1155
|
function Xt({
|
|
1160
1156
|
proxy: t
|
|
1161
1157
|
}) {
|
|
1162
|
-
const c =
|
|
1158
|
+
const c = B(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1163
1159
|
return at(() => {
|
|
1164
1160
|
const f = c.current;
|
|
1165
1161
|
if (!f || !f.parentElement) return;
|
|
@@ -1181,14 +1177,14 @@ function Xt({
|
|
|
1181
1177
|
"state",
|
|
1182
1178
|
`return (${t._effect})(state)`
|
|
1183
1179
|
)(n);
|
|
1184
|
-
} catch (
|
|
1185
|
-
console.error("Error evaluating effect function during mount:",
|
|
1180
|
+
} catch (R) {
|
|
1181
|
+
console.error("Error evaluating effect function during mount:", R), S = n;
|
|
1186
1182
|
}
|
|
1187
1183
|
else
|
|
1188
1184
|
S = n;
|
|
1189
1185
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1190
|
-
const
|
|
1191
|
-
f.replaceWith(
|
|
1186
|
+
const W = document.createTextNode(String(S));
|
|
1187
|
+
f.replaceWith(W);
|
|
1192
1188
|
}, [t._stateKey, t._path.join("."), t._effect]), st("span", {
|
|
1193
1189
|
ref: c,
|
|
1194
1190
|
style: { display: "none" },
|
|
@@ -1216,7 +1212,7 @@ function Qt({
|
|
|
1216
1212
|
itemPath: m,
|
|
1217
1213
|
children: f
|
|
1218
1214
|
}) {
|
|
1219
|
-
const [, y] =
|
|
1215
|
+
const [, y] = tt({}), [b, p] = Gt(), I = B(null);
|
|
1220
1216
|
return at(() => {
|
|
1221
1217
|
p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1222
1218
|
virtualizer: {
|
|
@@ -1234,10 +1230,10 @@ function Qt({
|
|
|
1234
1230
|
const n = o.getState().stateComponents.get(t);
|
|
1235
1231
|
n && n.components.delete(a);
|
|
1236
1232
|
};
|
|
1237
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref:
|
|
1233
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref: b, children: f });
|
|
1238
1234
|
}
|
|
1239
1235
|
export {
|
|
1240
|
-
|
|
1236
|
+
Nt as $cogsSignal,
|
|
1241
1237
|
fe as $cogsSignalStore,
|
|
1242
1238
|
de as addStateOptions,
|
|
1243
1239
|
ue as createCogsState,
|