cogsbox-state 0.5.307 → 0.5.309
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 +340 -336
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +38 -57
package/dist/CogsState.jsx
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as It } from "react/jsx-runtime";
|
|
3
|
-
import { useState as tt, useRef as
|
|
4
|
-
import { transformStateFunc as Rt, isDeepEqual as
|
|
5
|
-
import { pushFunc as yt, updateFn as ot, cutFunc as
|
|
6
|
-
import
|
|
3
|
+
import { useState as tt, useRef as J, useEffect as at, useLayoutEffect as ut, useMemo as pt, createElement as st, useSyncExternalStore as jt, startTransition as Ot, useCallback as Et } from "react";
|
|
4
|
+
import { transformStateFunc as Rt, isDeepEqual as z, isFunction as Z, getNestedValue as q, getDifferences as wt, debounce as Ut } from "./utility.js";
|
|
5
|
+
import { pushFunc as yt, updateFn as ot, cutFunc as dt, ValidationWrapper as Ft, FormControlComponent as Dt } from "./Functions.jsx";
|
|
6
|
+
import Gt from "superjson";
|
|
7
7
|
import { v4 as Tt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as o, formRefStore as $t } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
|
|
11
|
-
import { applyPatch as
|
|
11
|
+
import { applyPatch as Wt } from "fast-json-patch";
|
|
12
12
|
import Lt from "react-use-measure";
|
|
13
|
-
function
|
|
13
|
+
function kt(t, c) {
|
|
14
14
|
const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
|
|
15
15
|
f(t, {
|
|
16
16
|
...y,
|
|
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 = nt(t) || {}, y = m[t] || {},
|
|
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
|
+
!z(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 ue(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
@@ -45,9 +45,9 @@ const ge = (t, c) => {
|
|
|
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
|
|
48
|
+
const b = (I, a) => {
|
|
49
49
|
const [v] = tt(a?.componentId ?? Tt());
|
|
50
|
-
|
|
50
|
+
bt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
@@ -71,30 +71,30 @@ const ge = (t, c) => {
|
|
|
71
71
|
return R;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
|
-
|
|
74
|
+
bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Jt(I, a), mt(I);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: b, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: gt,
|
|
79
79
|
setState: et,
|
|
80
80
|
getInitialOptions: nt,
|
|
81
81
|
getKeyState: xt,
|
|
82
82
|
getValidationErrors: Ht,
|
|
83
|
-
setStateLog:
|
|
83
|
+
setStateLog: Bt,
|
|
84
84
|
updateInitialStateGlobal: At,
|
|
85
|
-
addValidationError:
|
|
85
|
+
addValidationError: zt,
|
|
86
86
|
removeValidationError: Y,
|
|
87
87
|
setServerSyncActions: qt
|
|
88
|
-
} = o.getState(),
|
|
88
|
+
} = o.getState(), Nt = (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 = Z(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 = St(p)?.lastSyncedWithServer;
|
|
@@ -104,7 +104,7 @@ const ge = (t, c) => {
|
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: y ?? I
|
|
107
|
-
}, v =
|
|
107
|
+
}, v = Gt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(v.json)
|
|
@@ -121,21 +121,21 @@ const ge = (t, c) => {
|
|
|
121
121
|
}, Jt = (t, c) => {
|
|
122
122
|
const m = o.getState().cogsStateStore[t], { sessionId: f } = Vt(), y = Z(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (y && f) {
|
|
124
|
-
const
|
|
124
|
+
const b = St(
|
|
125
125
|
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return et(t,
|
|
127
|
+
if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
|
|
128
|
+
return et(t, b.state), mt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, Pt = (t, c, m, f, y,
|
|
131
|
+
}, Pt = (t, c, m, f, y, b) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: ft(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
137
|
y,
|
|
138
|
-
|
|
138
|
+
b
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
@@ -161,18 +161,18 @@ const ge = (t, c) => {
|
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: q(c, f),
|
|
165
|
+
newValue: q(m, f)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: q(m, f)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: q(c, f),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -185,7 +185,7 @@ function Zt(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,12 +193,12 @@ function Zt(t, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [L, R] = tt({}), { sessionId:
|
|
196
|
+
const [L, R] = tt({}), { sessionId: U } = Vt();
|
|
197
197
|
let H = !c;
|
|
198
|
-
const [h] = tt(c ?? Tt()), l = o.getState().stateLog[h],
|
|
198
|
+
const [h] = tt(c ?? Tt()), l = o.getState().stateLog[h], it = J(/* @__PURE__ */ new Set()), X = J(I ?? Tt()), M = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
M.current = nt(h) ?? null, at(() => {
|
|
202
202
|
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
203
|
et(h, (r) => ({
|
|
204
204
|
...r,
|
|
@@ -210,40 +210,40 @@ function Zt(t, {
|
|
|
210
210
|
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [v]),
|
|
213
|
+
}, [v]), at(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
kt(h, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
219
|
-
if (!(i && !
|
|
218
|
+
const e = M.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
|
+
if (!(i && !z(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
221
|
+
let u = null;
|
|
222
222
|
const A = Z(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
-
A &&
|
|
224
|
-
let w = a,
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
223
|
+
A && U && (u = St(`${U}-${h}-${A}`));
|
|
224
|
+
let w = a, $ = !1;
|
|
225
|
+
const x = s ? Date.now() : 0, N = u?.lastUpdated || 0, j = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && x > N ? (w = e.serverState.data, $ = !0) : u && N > j && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Pt(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
229
|
w,
|
|
230
230
|
rt,
|
|
231
231
|
X.current,
|
|
232
|
-
|
|
233
|
-
),
|
|
232
|
+
U
|
|
233
|
+
), $ && A && U && Nt(w, h, e, U, Date.now()), mt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
H &&
|
|
240
|
+
]), ut(() => {
|
|
241
|
+
H && kt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: f,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: M.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const e = `${h}////${X.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
@@ -252,7 +252,7 @@ function Zt(t, {
|
|
|
252
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
257
|
}), o.getState().stateComponents.set(h, r), R({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
@@ -260,156 +260,156 @@ function Zt(t, {
|
|
|
260
260
|
}, []);
|
|
261
261
|
const rt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const
|
|
264
|
-
|
|
263
|
+
const u = `${h}-${r.join(".")}`;
|
|
264
|
+
it.current.add(u);
|
|
265
265
|
}
|
|
266
|
-
const
|
|
267
|
-
et(h, (
|
|
268
|
-
const A = Z(e) ? e(
|
|
266
|
+
const g = o.getState();
|
|
267
|
+
et(h, (u) => {
|
|
268
|
+
const A = Z(e) ? e(u) : 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
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
270
|
+
let P = !1, E = g.signalDomElements.get(w);
|
|
271
|
+
if ((!E || E.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const O = r.slice(0, -1), G = q(A, O);
|
|
273
|
+
if (Array.isArray(G)) {
|
|
274
|
+
P = !0;
|
|
275
|
+
const k = `${h}-${O.join(".")}`;
|
|
276
|
+
E = g.signalDomElements.get(k);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const O =
|
|
281
|
-
|
|
279
|
+
if (E) {
|
|
280
|
+
const O = P ? q(A, r.slice(0, -1)) : q(A, r);
|
|
281
|
+
E.forEach(({ parentId: G, position: k, effect: F }) => {
|
|
282
282
|
const T = document.querySelector(
|
|
283
|
-
`[data-parent-id="${
|
|
283
|
+
`[data-parent-id="${G}"]`
|
|
284
284
|
);
|
|
285
285
|
if (T) {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
286
|
+
const C = Array.from(T.childNodes);
|
|
287
|
+
if (C[k]) {
|
|
288
|
+
const V = F ? new Function("state", `return (${F})(state)`)(O) : O;
|
|
289
|
+
C[k].textContent = String(V);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState",
|
|
296
|
-
(i ||
|
|
295
|
+
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r && Y(
|
|
296
|
+
(i || M.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
Y(
|
|
298
|
+
const $ = r.slice(0, r.length - 1);
|
|
299
|
+
s.updateType === "cut" && M.current?.validation?.key && Y(
|
|
300
|
+
M.current?.validation?.key + "." + $.join(".")
|
|
301
|
+
), s.updateType === "insert" && M.current?.validation?.key && Ht(
|
|
302
|
+
M.current?.validation?.key + "." + $.join(".")
|
|
303
|
+
).filter(([E, O]) => {
|
|
304
|
+
let G = E?.split(".").length;
|
|
305
|
+
if (E == $.join(".") && G == $.length - 1) {
|
|
306
|
+
let k = E + "." + $;
|
|
307
|
+
Y(E), zt(k, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const x = g.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
|
|
312
|
+
const P = wt(u, A), E = new Set(P), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const T = Array.isArray(
|
|
319
|
-
if (console.log("component",
|
|
314
|
+
G,
|
|
315
|
+
k
|
|
316
|
+
] of x.components.entries()) {
|
|
317
|
+
let F = !1;
|
|
318
|
+
const T = Array.isArray(k.reactiveType) ? k.reactiveType : [k.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", k), !T.includes("none")) {
|
|
320
320
|
if (T.includes("all")) {
|
|
321
|
-
|
|
321
|
+
k.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (T.includes("component") && ((
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (T.includes("component") && ((k.paths.has(O) || k.paths.has("")) && (F = !0), !F))
|
|
325
|
+
for (const C of E) {
|
|
326
|
+
let V = C;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (k.paths.has(V)) {
|
|
329
|
+
F = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const W = V.lastIndexOf(".");
|
|
333
|
+
if (W !== -1) {
|
|
334
|
+
const B = V.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
W
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(V.substring(W + 1))
|
|
340
|
+
) && k.paths.has(B)) {
|
|
341
|
+
F = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
V = B;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
V = "";
|
|
347
|
+
if (V === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (F) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!F && T.includes("deps") && k.depsFunction) {
|
|
353
|
+
const C = k.depsFunction(A);
|
|
354
|
+
let V = !1;
|
|
355
|
+
typeof C == "boolean" ? C && (V = !0) : z(k.deps, C) || (k.deps = C, V = !0), V && (F = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
F && k.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const O = r.slice(0, -1),
|
|
364
|
-
return
|
|
361
|
+
const N = Date.now();
|
|
362
|
+
r = r.map((P, E) => {
|
|
363
|
+
const O = r.slice(0, -1), G = q(A, O);
|
|
364
|
+
return E === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (G.length - 1).toString() : P;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: j, newValue: D } = Yt(
|
|
367
367
|
s.updateType,
|
|
368
|
-
|
|
368
|
+
u,
|
|
369
369
|
A,
|
|
370
370
|
r
|
|
371
371
|
), _ = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: N,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: j,
|
|
378
378
|
newValue: D
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
|
|
382
|
+
g.updateShadowAtPath(h, r, A);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
|
|
385
|
+
const P = r.slice(0, -1);
|
|
386
|
+
g.insertShadowArrayElement(h, P, D);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
|
|
389
|
+
const E = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
+
g.removeShadowArrayElement(h, E, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const O = [...
|
|
395
|
-
const
|
|
396
|
-
return T ? (T.timeStamp = Math.max(T.timeStamp,
|
|
393
|
+
if (Bt(h, (P) => {
|
|
394
|
+
const O = [...P ?? [], _].reduce((G, k) => {
|
|
395
|
+
const F = `${k.stateKey}:${JSON.stringify(k.path)}`, T = G.get(F);
|
|
396
|
+
return T ? (T.timeStamp = Math.max(T.timeStamp, k.timeStamp), T.newValue = k.newValue, T.oldValue = T.oldValue ?? k.oldValue, T.updateType = k.updateType) : G.set(F, { ...k }), G;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(O.values());
|
|
399
|
-
}),
|
|
399
|
+
}), Nt(
|
|
400
400
|
A,
|
|
401
401
|
h,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
M.current,
|
|
403
|
+
U
|
|
404
|
+
), M.current?.middleware && M.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: _
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
407
|
+
}), M.current?.serverSync) {
|
|
408
|
+
const P = g.serverState[h], E = M.current?.serverSync;
|
|
409
409
|
qt(h, {
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
410
|
+
syncKey: typeof E.syncKey == "string" ? E.syncKey : E.syncKey({ state: A }),
|
|
411
|
+
rollBackState: P,
|
|
412
|
+
actionTimeStamp: Date.now() + (E.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
@@ -422,25 +422,25 @@ function Zt(t, {
|
|
|
422
422
|
h,
|
|
423
423
|
rt,
|
|
424
424
|
X.current,
|
|
425
|
-
|
|
425
|
+
U
|
|
426
426
|
)
|
|
427
427
|
), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
|
|
428
428
|
const d = pt(() => ft(
|
|
429
429
|
h,
|
|
430
430
|
rt,
|
|
431
431
|
X.current,
|
|
432
|
-
|
|
433
|
-
), [h,
|
|
432
|
+
U
|
|
433
|
+
), [h, U]);
|
|
434
434
|
return [xt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function ft(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
446
|
v?.validationKey && Y(v.validationKey);
|
|
@@ -449,8 +449,8 @@ function ft(t, c, m, f) {
|
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && Y(n?.key), v?.validationKey && Y(v.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
453
|
-
const L = a(S, []), R = nt(t),
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
|
|
453
|
+
const L = a(S, []), R = nt(t), U = Z(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, H = `${f}-${t}-${U}`;
|
|
454
454
|
H && localStorage.removeItem(H), gt(t, L), et(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
@@ -458,14 +458,14 @@ function ft(t, c, m, f) {
|
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (v) => {
|
|
461
|
-
y.clear(),
|
|
461
|
+
y.clear(), b++;
|
|
462
462
|
const n = ft(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
f
|
|
467
|
-
), S = o.getState().initialStateGlobal[t], L = nt(t), R = Z(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key,
|
|
468
|
-
return localStorage.getItem(
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], L = nt(t), R = Z(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, U = `${f}-${t}-${R}`;
|
|
468
|
+
return localStorage.getItem(U) && localStorage.removeItem(U), Ot(() => {
|
|
469
469
|
At(t, v), o.getState().initializeShadowState(t, v), gt(t, n), et(t, v);
|
|
470
470
|
const H = o.getState().stateComponents.get(t);
|
|
471
471
|
H && H.components.forEach((h) => {
|
|
@@ -480,7 +480,7 @@ function ft(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 && z(v, xt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(v, n = [], S) {
|
|
@@ -492,15 +492,15 @@ function ft(t, c, m, f) {
|
|
|
492
492
|
Object.keys(I).forEach((h) => {
|
|
493
493
|
R[h] = I[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(h, l,
|
|
495
|
+
const U = {
|
|
496
|
+
apply(h, l, it) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const it = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,15 +523,15 @@ function ft(t, c, m, f) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !it.has(l)) {
|
|
527
527
|
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const r = e.components.get(d);
|
|
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 g of r.paths)
|
|
534
|
+
if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
|
|
535
535
|
i = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
@@ -553,13 +553,13 @@ function ft(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((u) => {
|
|
557
|
+
const A = [s, ...u.path].join(".");
|
|
558
|
+
o.getState().addValidationError(A, u.message);
|
|
559
559
|
});
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
const g = o.getState().stateComponents.get(t);
|
|
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;
|
|
@@ -568,16 +568,16 @@ function ft(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 = q(e, n);
|
|
572
|
+
return z(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 = q(e, n);
|
|
580
|
+
return z(d, r) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
@@ -621,164 +621,168 @@ function ft(t, c, m, f) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e,
|
|
624
|
+
} = e, g = J(null), [u, A] = tt({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
|
-
}),
|
|
628
|
-
|
|
627
|
+
}), w = J(i), $ = J(0), x = J(!0), [N, j] = tt(0);
|
|
628
|
+
at(() => o.getState().subscribeToShadowState(t, () => {
|
|
629
|
+
j((C) => C + 1);
|
|
630
|
+
}), [t]);
|
|
629
631
|
const D = o().getNestedState(
|
|
630
632
|
t,
|
|
631
633
|
n
|
|
632
|
-
), _ = D.length, { totalHeight:
|
|
634
|
+
), _ = D.length, { totalHeight: P, positions: E } = pt(() => {
|
|
633
635
|
const T = o.getState().getShadowMetadata(t, n) || [];
|
|
634
|
-
let
|
|
635
|
-
const
|
|
636
|
-
for (let
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
636
|
+
let C = 0;
|
|
637
|
+
const V = [];
|
|
638
|
+
for (let W = 0; W < _; W++) {
|
|
639
|
+
V[W] = C;
|
|
640
|
+
const B = T[W]?.virtualizer?.itemHeight;
|
|
641
|
+
C += B || r;
|
|
640
642
|
}
|
|
641
|
-
return { totalHeight:
|
|
642
|
-
}, [
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
});
|
|
651
|
-
}, [V]);
|
|
643
|
+
return { totalHeight: C, positions: V };
|
|
644
|
+
}, [
|
|
645
|
+
_,
|
|
646
|
+
t,
|
|
647
|
+
n.join("."),
|
|
648
|
+
r,
|
|
649
|
+
N
|
|
650
|
+
]);
|
|
651
|
+
console.log("height", P);
|
|
652
652
|
const O = pt(() => {
|
|
653
|
-
const T = Math.max(0,
|
|
654
|
-
{ length:
|
|
655
|
-
(
|
|
656
|
-
),
|
|
657
|
-
return a(
|
|
653
|
+
const T = Math.max(0, u.startIndex), C = Math.min(_, u.endIndex), V = Array.from(
|
|
654
|
+
{ length: C - T },
|
|
655
|
+
(B, ct) => T + ct
|
|
656
|
+
), W = V.map((B) => D[B]);
|
|
657
|
+
return a(W, n, {
|
|
658
658
|
...S,
|
|
659
|
-
validIndices:
|
|
659
|
+
validIndices: V
|
|
660
660
|
});
|
|
661
|
-
}, [
|
|
662
|
-
|
|
663
|
-
const T =
|
|
661
|
+
}, [u.startIndex, u.endIndex, D, _]);
|
|
662
|
+
ut(() => {
|
|
663
|
+
const T = g.current;
|
|
664
664
|
if (!T) return;
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
const { scrollTop:
|
|
669
|
-
|
|
670
|
-
let ht = 0,
|
|
671
|
-
for (; ht <=
|
|
672
|
-
const K = Math.floor((ht +
|
|
673
|
-
|
|
665
|
+
const C = w.current, V = _ > $.current;
|
|
666
|
+
$.current = _;
|
|
667
|
+
const W = () => {
|
|
668
|
+
const { scrollTop: B, clientHeight: ct, scrollHeight: _t } = T;
|
|
669
|
+
w.current = _t - B - ct < 10;
|
|
670
|
+
let ht = 0, lt = _ - 1;
|
|
671
|
+
for (; ht <= lt; ) {
|
|
672
|
+
const K = Math.floor((ht + lt) / 2);
|
|
673
|
+
E[K] < B ? ht = K + 1 : lt = K - 1;
|
|
674
674
|
}
|
|
675
|
-
const vt = Math.max(0,
|
|
675
|
+
const vt = Math.max(0, lt - s);
|
|
676
676
|
let Q = vt;
|
|
677
|
-
const Mt =
|
|
678
|
-
for (; Q < _ &&
|
|
677
|
+
const Mt = B + ct;
|
|
678
|
+
for (; Q < _ && E[Q] < Mt; )
|
|
679
679
|
Q++;
|
|
680
680
|
Q = Math.min(_, Q + s), A((K) => K.startIndex !== vt || K.endIndex !== Q ? { startIndex: vt, endIndex: Q } : K);
|
|
681
681
|
};
|
|
682
|
-
return T.addEventListener("scroll",
|
|
682
|
+
return T.addEventListener("scroll", W, {
|
|
683
683
|
passive: !0
|
|
684
|
-
}), i &&
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
684
|
+
}), i && (x.current ? (console.log(
|
|
685
|
+
"stickToBottom initial mount",
|
|
686
|
+
T.scrollHeight
|
|
687
|
+
), T.scrollTo({
|
|
688
|
+
top: T.scrollHeight,
|
|
689
|
+
behavior: "auto"
|
|
690
|
+
}), x.current = !1) : C && V && (console.log(
|
|
691
|
+
"stickToBottom wasAtBottom && listGrew",
|
|
692
|
+
T.scrollHeight
|
|
693
|
+
), requestAnimationFrame(() => {
|
|
690
694
|
T.scrollTo({
|
|
691
695
|
top: T.scrollHeight,
|
|
692
696
|
behavior: "smooth"
|
|
693
697
|
});
|
|
694
|
-
}),
|
|
695
|
-
}, [_,
|
|
696
|
-
const
|
|
698
|
+
}))), console.log("wasAtBottom && listGrew", C, V), W(), () => T.removeEventListener("scroll", W);
|
|
699
|
+
}, [_, E, s, i]);
|
|
700
|
+
const G = Et(
|
|
697
701
|
(T = "smooth") => {
|
|
698
|
-
|
|
699
|
-
top:
|
|
702
|
+
g.current && g.current.scrollTo({
|
|
703
|
+
top: g.current.scrollHeight,
|
|
700
704
|
behavior: T
|
|
701
705
|
});
|
|
702
706
|
},
|
|
703
707
|
[]
|
|
704
|
-
),
|
|
705
|
-
(T,
|
|
706
|
-
|
|
707
|
-
top:
|
|
708
|
-
behavior:
|
|
708
|
+
), k = Et(
|
|
709
|
+
(T, C = "smooth") => {
|
|
710
|
+
g.current && E[T] !== void 0 && g.current.scrollTo({
|
|
711
|
+
top: E[T],
|
|
712
|
+
behavior: C
|
|
709
713
|
});
|
|
710
714
|
},
|
|
711
|
-
[
|
|
712
|
-
),
|
|
715
|
+
[E]
|
|
716
|
+
), F = {
|
|
713
717
|
outer: {
|
|
714
|
-
ref:
|
|
718
|
+
ref: g,
|
|
715
719
|
style: { overflowY: "auto", height: "100%" }
|
|
716
720
|
},
|
|
717
721
|
inner: {
|
|
718
722
|
style: {
|
|
719
|
-
height: `${
|
|
723
|
+
height: `${P}px`,
|
|
720
724
|
position: "relative"
|
|
721
725
|
}
|
|
722
726
|
},
|
|
723
727
|
list: {
|
|
724
728
|
style: {
|
|
725
|
-
transform: `translateY(${
|
|
729
|
+
transform: `translateY(${E[u.startIndex] || 0}px)`
|
|
726
730
|
}
|
|
727
731
|
}
|
|
728
732
|
};
|
|
729
733
|
return {
|
|
730
734
|
virtualState: O,
|
|
731
|
-
virtualizerProps:
|
|
732
|
-
scrollToBottom:
|
|
733
|
-
scrollToIndex:
|
|
735
|
+
virtualizerProps: F,
|
|
736
|
+
scrollToBottom: G,
|
|
737
|
+
scrollToIndex: k
|
|
734
738
|
};
|
|
735
739
|
};
|
|
736
740
|
if (l === "stateSort")
|
|
737
741
|
return (e) => {
|
|
738
742
|
const s = [...d()].sort(
|
|
739
|
-
(
|
|
740
|
-
), i = s.map(({ item:
|
|
743
|
+
(u, A) => e(u.item, A.item)
|
|
744
|
+
), i = s.map(({ item: u }) => u), g = {
|
|
741
745
|
...S,
|
|
742
746
|
validIndices: s.map(
|
|
743
|
-
({ originalIndex:
|
|
747
|
+
({ originalIndex: u }) => u
|
|
744
748
|
)
|
|
745
749
|
};
|
|
746
|
-
return a(i, n,
|
|
750
|
+
return a(i, n, g);
|
|
747
751
|
};
|
|
748
752
|
if (l === "stateFilter")
|
|
749
753
|
return (e) => {
|
|
750
754
|
const s = d().filter(
|
|
751
|
-
({ item:
|
|
752
|
-
), i = s.map(({ item:
|
|
755
|
+
({ item: u }, A) => e(u, A)
|
|
756
|
+
), i = s.map(({ item: u }) => u), g = {
|
|
753
757
|
...S,
|
|
754
758
|
validIndices: s.map(
|
|
755
|
-
({ originalIndex:
|
|
759
|
+
({ originalIndex: u }) => u
|
|
756
760
|
)
|
|
757
761
|
};
|
|
758
|
-
return a(i, n,
|
|
762
|
+
return a(i, n, g);
|
|
759
763
|
};
|
|
760
764
|
if (l === "stateMap")
|
|
761
765
|
return (e) => {
|
|
762
766
|
const r = o.getState().getNestedState(t, n);
|
|
763
|
-
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i,
|
|
764
|
-
const
|
|
765
|
-
return e(
|
|
767
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
768
|
+
const u = r[i], A = [...n, i.toString()], w = a(u, A, S);
|
|
769
|
+
return e(u, w, {
|
|
766
770
|
register: () => {
|
|
767
|
-
const [,
|
|
768
|
-
|
|
769
|
-
const
|
|
771
|
+
const [, x] = tt({}), N = `${m}-${n.join(".")}-${i}`;
|
|
772
|
+
ut(() => {
|
|
773
|
+
const j = `${t}////${N}`, D = o.getState().stateComponents.get(t) || {
|
|
770
774
|
components: /* @__PURE__ */ new Map()
|
|
771
775
|
};
|
|
772
|
-
return D.components.set(
|
|
773
|
-
forceUpdate: () =>
|
|
776
|
+
return D.components.set(j, {
|
|
777
|
+
forceUpdate: () => x({}),
|
|
774
778
|
paths: /* @__PURE__ */ new Set([A.join(".")])
|
|
775
779
|
}), o.getState().stateComponents.set(t, D), () => {
|
|
776
780
|
const _ = o.getState().stateComponents.get(t);
|
|
777
|
-
_ && _.components.delete(
|
|
781
|
+
_ && _.components.delete(j);
|
|
778
782
|
};
|
|
779
|
-
}, [t,
|
|
783
|
+
}, [t, N]);
|
|
780
784
|
},
|
|
781
|
-
index:
|
|
785
|
+
index: g,
|
|
782
786
|
originalIndex: i
|
|
783
787
|
});
|
|
784
788
|
}) : (console.warn(
|
|
@@ -788,9 +792,9 @@ function ft(t, c, m, f) {
|
|
|
788
792
|
};
|
|
789
793
|
if (l === "stateMapNoRender")
|
|
790
794
|
return (e) => v.map((s, i) => {
|
|
791
|
-
let
|
|
792
|
-
S?.validIndices && S.validIndices[i] !== void 0 ?
|
|
793
|
-
const
|
|
795
|
+
let g;
|
|
796
|
+
S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
|
|
797
|
+
const u = [...n, g.toString()], A = a(s, u, S);
|
|
794
798
|
return e(
|
|
795
799
|
s,
|
|
796
800
|
A,
|
|
@@ -800,7 +804,7 @@ function ft(t, c, m, f) {
|
|
|
800
804
|
);
|
|
801
805
|
});
|
|
802
806
|
if (l === "$stateMap")
|
|
803
|
-
return (e) =>
|
|
807
|
+
return (e) => st(Xt, {
|
|
804
808
|
proxy: {
|
|
805
809
|
_stateKey: t,
|
|
806
810
|
_path: n,
|
|
@@ -812,17 +816,17 @@ function ft(t, c, m, f) {
|
|
|
812
816
|
if (l === "stateList")
|
|
813
817
|
return (e) => {
|
|
814
818
|
const r = o.getState().getNestedState(t, n);
|
|
815
|
-
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i,
|
|
816
|
-
const
|
|
817
|
-
return
|
|
819
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
820
|
+
const u = r[i], A = [...n, i.toString()], w = a(u, A, S), $ = `${m}-${n.join(".")}-${i}`;
|
|
821
|
+
return st(Kt, {
|
|
818
822
|
key: i,
|
|
819
823
|
stateKey: t,
|
|
820
|
-
itemComponentId:
|
|
824
|
+
itemComponentId: $,
|
|
821
825
|
itemPath: A,
|
|
822
826
|
children: e(
|
|
823
|
-
g,
|
|
824
|
-
w,
|
|
825
827
|
u,
|
|
828
|
+
w,
|
|
829
|
+
g,
|
|
826
830
|
r,
|
|
827
831
|
a(r, n, S)
|
|
828
832
|
)
|
|
@@ -834,7 +838,7 @@ function ft(t, c, m, f) {
|
|
|
834
838
|
if (l === "stateFlattenOn")
|
|
835
839
|
return (e) => {
|
|
836
840
|
const r = v;
|
|
837
|
-
y.clear(),
|
|
841
|
+
y.clear(), b++;
|
|
838
842
|
const s = r.flatMap(
|
|
839
843
|
(i) => i[e] ?? []
|
|
840
844
|
);
|
|
@@ -863,30 +867,30 @@ function ft(t, c, m, f) {
|
|
|
863
867
|
));
|
|
864
868
|
if (l === "uniqueInsert")
|
|
865
869
|
return (e, r, s) => {
|
|
866
|
-
const i = o.getState().getNestedState(t, n),
|
|
867
|
-
let
|
|
870
|
+
const i = o.getState().getNestedState(t, n), g = Z(e) ? e(i) : e;
|
|
871
|
+
let u = null;
|
|
868
872
|
if (!i.some((w) => {
|
|
869
873
|
if (r) {
|
|
870
|
-
const
|
|
871
|
-
(
|
|
874
|
+
const x = r.every(
|
|
875
|
+
(N) => z(w[N], g[N])
|
|
872
876
|
);
|
|
873
|
-
return
|
|
877
|
+
return x && (u = w), x;
|
|
874
878
|
}
|
|
875
|
-
const
|
|
876
|
-
return
|
|
879
|
+
const $ = z(w, g);
|
|
880
|
+
return $ && (u = w), $;
|
|
877
881
|
}))
|
|
878
|
-
p(n), yt(c,
|
|
879
|
-
else if (s &&
|
|
880
|
-
const w = s(
|
|
881
|
-
(
|
|
882
|
+
p(n), yt(c, g, n, t);
|
|
883
|
+
else if (s && u) {
|
|
884
|
+
const w = s(u), $ = i.map(
|
|
885
|
+
(x) => z(x, u) ? w : x
|
|
882
886
|
);
|
|
883
|
-
p(n), ot(c,
|
|
887
|
+
p(n), ot(c, $, n);
|
|
884
888
|
}
|
|
885
889
|
};
|
|
886
890
|
if (l === "cut")
|
|
887
891
|
return (e, r) => {
|
|
888
892
|
if (!r?.waitForSync)
|
|
889
|
-
return p(n),
|
|
893
|
+
return p(n), dt(c, n, t, e), a(
|
|
890
894
|
o.getState().getNestedState(t, n),
|
|
891
895
|
n
|
|
892
896
|
);
|
|
@@ -894,17 +898,17 @@ function ft(t, c, m, f) {
|
|
|
894
898
|
if (l === "cutByValue")
|
|
895
899
|
return (e) => {
|
|
896
900
|
for (let r = 0; r < v.length; r++)
|
|
897
|
-
v[r] === e &&
|
|
901
|
+
v[r] === e && dt(c, n, t, r);
|
|
898
902
|
};
|
|
899
903
|
if (l === "toggleByValue")
|
|
900
904
|
return (e) => {
|
|
901
905
|
const r = v.findIndex((s) => s === e);
|
|
902
|
-
r > -1 ?
|
|
906
|
+
r > -1 ? dt(c, n, t, r) : yt(c, e, n, t);
|
|
903
907
|
};
|
|
904
908
|
if (l === "stateFind")
|
|
905
909
|
return (e) => {
|
|
906
910
|
const s = d().find(
|
|
907
|
-
({ item:
|
|
911
|
+
({ item: g }, u) => e(g, u)
|
|
908
912
|
);
|
|
909
913
|
if (!s) return;
|
|
910
914
|
const i = [...n, s.originalIndex.toString()];
|
|
@@ -913,18 +917,18 @@ function ft(t, c, m, f) {
|
|
|
913
917
|
if (l === "findWith")
|
|
914
918
|
return (e, r) => {
|
|
915
919
|
const i = d().find(
|
|
916
|
-
({ item:
|
|
920
|
+
({ item: u }) => u[e] === r
|
|
917
921
|
);
|
|
918
922
|
if (!i) return;
|
|
919
|
-
const
|
|
920
|
-
return a(i.item,
|
|
923
|
+
const g = [...n, i.originalIndex.toString()];
|
|
924
|
+
return a(i.item, g, S);
|
|
921
925
|
};
|
|
922
926
|
}
|
|
923
927
|
const X = n[n.length - 1];
|
|
924
928
|
if (!isNaN(Number(X))) {
|
|
925
929
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
926
930
|
if (Array.isArray(e) && l === "cut")
|
|
927
|
-
return () =>
|
|
931
|
+
return () => dt(
|
|
928
932
|
c,
|
|
929
933
|
d,
|
|
930
934
|
t,
|
|
@@ -940,13 +944,13 @@ function ft(t, c, m, f) {
|
|
|
940
944
|
return o.getState().getNestedState(t, n);
|
|
941
945
|
};
|
|
942
946
|
if (l === "$derive")
|
|
943
|
-
return (d) =>
|
|
947
|
+
return (d) => Ct({
|
|
944
948
|
_stateKey: t,
|
|
945
949
|
_path: n,
|
|
946
950
|
_effect: d.toString()
|
|
947
951
|
});
|
|
948
952
|
if (l === "$get")
|
|
949
|
-
return () =>
|
|
953
|
+
return () => Ct({
|
|
950
954
|
_stateKey: t,
|
|
951
955
|
_path: n
|
|
952
956
|
});
|
|
@@ -981,7 +985,7 @@ function ft(t, c, m, f) {
|
|
|
981
985
|
if (n.length == 0) {
|
|
982
986
|
if (l === "applyJsonPatch")
|
|
983
987
|
return (d) => {
|
|
984
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
988
|
+
const e = o.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
|
|
985
989
|
Pt(
|
|
986
990
|
t,
|
|
987
991
|
o.getState().initialStateGlobal[t],
|
|
@@ -992,57 +996,57 @@ function ft(t, c, m, f) {
|
|
|
992
996
|
);
|
|
993
997
|
const i = o.getState().stateComponents.get(t);
|
|
994
998
|
if (i) {
|
|
995
|
-
const
|
|
999
|
+
const g = wt(e, s), u = new Set(g);
|
|
996
1000
|
for (const [
|
|
997
1001
|
A,
|
|
998
1002
|
w
|
|
999
1003
|
] of i.components.entries()) {
|
|
1000
|
-
let
|
|
1001
|
-
const
|
|
1002
|
-
if (!
|
|
1003
|
-
if (
|
|
1004
|
+
let $ = !1;
|
|
1005
|
+
const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
1006
|
+
if (!x.includes("none")) {
|
|
1007
|
+
if (x.includes("all")) {
|
|
1004
1008
|
w.forceUpdate();
|
|
1005
1009
|
continue;
|
|
1006
1010
|
}
|
|
1007
|
-
if (
|
|
1008
|
-
for (const
|
|
1009
|
-
if (w.paths.has(
|
|
1010
|
-
|
|
1011
|
+
if (x.includes("component") && (w.paths.has("") && ($ = !0), !$))
|
|
1012
|
+
for (const N of u) {
|
|
1013
|
+
if (w.paths.has(N)) {
|
|
1014
|
+
$ = !0;
|
|
1011
1015
|
break;
|
|
1012
1016
|
}
|
|
1013
|
-
let
|
|
1014
|
-
for (;
|
|
1015
|
-
const D =
|
|
1017
|
+
let j = N.lastIndexOf(".");
|
|
1018
|
+
for (; j !== -1; ) {
|
|
1019
|
+
const D = N.substring(0, j);
|
|
1016
1020
|
if (w.paths.has(D)) {
|
|
1017
|
-
|
|
1021
|
+
$ = !0;
|
|
1018
1022
|
break;
|
|
1019
1023
|
}
|
|
1020
|
-
const _ =
|
|
1021
|
-
|
|
1024
|
+
const _ = N.substring(
|
|
1025
|
+
j + 1
|
|
1022
1026
|
);
|
|
1023
1027
|
if (!isNaN(Number(_))) {
|
|
1024
|
-
const
|
|
1025
|
-
if (
|
|
1026
|
-
const
|
|
1028
|
+
const P = D.lastIndexOf(".");
|
|
1029
|
+
if (P !== -1) {
|
|
1030
|
+
const E = D.substring(
|
|
1027
1031
|
0,
|
|
1028
|
-
|
|
1032
|
+
P
|
|
1029
1033
|
);
|
|
1030
|
-
if (w.paths.has(
|
|
1031
|
-
|
|
1034
|
+
if (w.paths.has(E)) {
|
|
1035
|
+
$ = !0;
|
|
1032
1036
|
break;
|
|
1033
1037
|
}
|
|
1034
1038
|
}
|
|
1035
1039
|
}
|
|
1036
|
-
|
|
1040
|
+
j = D.lastIndexOf(".");
|
|
1037
1041
|
}
|
|
1038
|
-
if (
|
|
1042
|
+
if ($) break;
|
|
1039
1043
|
}
|
|
1040
|
-
if (
|
|
1041
|
-
const
|
|
1042
|
-
let
|
|
1043
|
-
typeof
|
|
1044
|
+
if (!$ && x.includes("deps") && w.depsFunction) {
|
|
1045
|
+
const N = w.depsFunction(s);
|
|
1046
|
+
let j = !1;
|
|
1047
|
+
typeof N == "boolean" ? N && (j = !0) : z(w.deps, N) || (w.deps = N, j = !0), j && ($ = !0);
|
|
1044
1048
|
}
|
|
1045
|
-
|
|
1049
|
+
$ && w.forceUpdate();
|
|
1046
1050
|
}
|
|
1047
1051
|
}
|
|
1048
1052
|
}
|
|
@@ -1058,13 +1062,13 @@ function ft(t, c, m, f) {
|
|
|
1058
1062
|
const r = o.getState().cogsStateStore[t];
|
|
1059
1063
|
try {
|
|
1060
1064
|
const s = o.getState().getValidationErrors(d.key);
|
|
1061
|
-
s && s.length > 0 && s.forEach(([
|
|
1062
|
-
|
|
1065
|
+
s && s.length > 0 && s.forEach(([g]) => {
|
|
1066
|
+
g && g.startsWith(d.key) && Y(g);
|
|
1063
1067
|
});
|
|
1064
1068
|
const i = d.zodSchema.safeParse(r);
|
|
1065
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
1066
|
-
const A =
|
|
1067
|
-
e(
|
|
1069
|
+
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1070
|
+
const A = u.path, w = u.message, $ = [d.key, ...A].join(".");
|
|
1071
|
+
e($, w);
|
|
1068
1072
|
}), mt(t), !1);
|
|
1069
1073
|
} catch (s) {
|
|
1070
1074
|
return console.error("Zod schema validation failed", s), !1;
|
|
@@ -1093,7 +1097,7 @@ function ft(t, c, m, f) {
|
|
|
1093
1097
|
children: d,
|
|
1094
1098
|
hideMessage: e
|
|
1095
1099
|
}) => /* @__PURE__ */ It(
|
|
1096
|
-
|
|
1100
|
+
Ft,
|
|
1097
1101
|
{
|
|
1098
1102
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1099
1103
|
path: n,
|
|
@@ -1109,7 +1113,7 @@ function ft(t, c, m, f) {
|
|
|
1109
1113
|
if (l === "update")
|
|
1110
1114
|
return (d, e) => {
|
|
1111
1115
|
if (e?.debounce)
|
|
1112
|
-
|
|
1116
|
+
Ut(() => {
|
|
1113
1117
|
ot(c, d, n, "");
|
|
1114
1118
|
const r = o.getState().getNestedState(t, n);
|
|
1115
1119
|
e?.afterUpdate && e.afterUpdate(r);
|
|
@@ -1132,21 +1136,21 @@ function ft(t, c, m, f) {
|
|
|
1132
1136
|
formOpts: e
|
|
1133
1137
|
}
|
|
1134
1138
|
);
|
|
1135
|
-
const
|
|
1136
|
-
return a(rt,
|
|
1139
|
+
const M = [...n, l], rt = o.getState().getNestedState(t, M);
|
|
1140
|
+
return a(rt, M, S);
|
|
1137
1141
|
}
|
|
1138
|
-
}, H = new Proxy(R,
|
|
1142
|
+
}, H = new Proxy(R, U);
|
|
1139
1143
|
return y.set(L, {
|
|
1140
1144
|
proxy: H,
|
|
1141
|
-
stateVersion:
|
|
1145
|
+
stateVersion: b
|
|
1142
1146
|
}), H;
|
|
1143
1147
|
}
|
|
1144
1148
|
return a(
|
|
1145
1149
|
o.getState().getNestedState(t, [])
|
|
1146
1150
|
);
|
|
1147
1151
|
}
|
|
1148
|
-
function
|
|
1149
|
-
return
|
|
1152
|
+
function Ct(t) {
|
|
1153
|
+
return st(Qt, { proxy: t });
|
|
1150
1154
|
}
|
|
1151
1155
|
function Xt({
|
|
1152
1156
|
proxy: t,
|
|
@@ -1157,14 +1161,14 @@ function Xt({
|
|
|
1157
1161
|
m,
|
|
1158
1162
|
t._path
|
|
1159
1163
|
).stateMapNoRender(
|
|
1160
|
-
(y,
|
|
1164
|
+
(y, b, p, I, a) => t._mapFn(y, b, p, I, a)
|
|
1161
1165
|
) : null;
|
|
1162
1166
|
}
|
|
1163
1167
|
function Qt({
|
|
1164
1168
|
proxy: t
|
|
1165
1169
|
}) {
|
|
1166
|
-
const c =
|
|
1167
|
-
return
|
|
1170
|
+
const c = J(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1171
|
+
return at(() => {
|
|
1168
1172
|
const f = c.current;
|
|
1169
1173
|
if (!f || !f.parentElement) return;
|
|
1170
1174
|
const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
|
|
@@ -1193,7 +1197,7 @@ function Qt({
|
|
|
1193
1197
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1194
1198
|
const L = document.createTextNode(String(S));
|
|
1195
1199
|
f.replaceWith(L);
|
|
1196
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1200
|
+
}, [t._stateKey, t._path.join("."), t._effect]), st("span", {
|
|
1197
1201
|
ref: c,
|
|
1198
1202
|
style: { display: "none" },
|
|
1199
1203
|
"data-signal-id": m
|
|
@@ -1212,7 +1216,7 @@ function Se(t) {
|
|
|
1212
1216
|
},
|
|
1213
1217
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1214
1218
|
);
|
|
1215
|
-
return
|
|
1219
|
+
return st("text", {}, String(c));
|
|
1216
1220
|
}
|
|
1217
1221
|
function Kt({
|
|
1218
1222
|
stateKey: t,
|
|
@@ -1220,14 +1224,14 @@ function Kt({
|
|
|
1220
1224
|
itemPath: m,
|
|
1221
1225
|
children: f
|
|
1222
1226
|
}) {
|
|
1223
|
-
const [, y] = tt({}), [
|
|
1224
|
-
return
|
|
1227
|
+
const [, y] = tt({}), [b, p] = Lt(), I = J(null);
|
|
1228
|
+
return at(() => {
|
|
1225
1229
|
p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1226
1230
|
virtualizer: {
|
|
1227
1231
|
itemHeight: p.height
|
|
1228
1232
|
}
|
|
1229
1233
|
}));
|
|
1230
|
-
}, [p.height, t, m]),
|
|
1234
|
+
}, [p.height, t, m]), ut(() => {
|
|
1231
1235
|
const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
|
|
1232
1236
|
components: /* @__PURE__ */ new Map()
|
|
1233
1237
|
};
|
|
@@ -1238,10 +1242,10 @@ function Kt({
|
|
|
1238
1242
|
const n = o.getState().stateComponents.get(t);
|
|
1239
1243
|
n && n.components.delete(a);
|
|
1240
1244
|
};
|
|
1241
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */ It("div", { ref:
|
|
1245
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ It("div", { ref: b, children: f });
|
|
1242
1246
|
}
|
|
1243
1247
|
export {
|
|
1244
|
-
|
|
1248
|
+
Ct as $cogsSignal,
|
|
1245
1249
|
Se as $cogsSignalStore,
|
|
1246
1250
|
ue as addStateOptions,
|
|
1247
1251
|
ge as createCogsState,
|