cogsbox-state 0.5.401 → 0.5.402
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 +301 -297
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +18 -11
package/dist/CogsState.jsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as _t } from "react/jsx-runtime";
|
|
3
|
+
import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as lt, useMemo as wt, createElement as dt, useSyncExternalStore as Bt, startTransition as Ft, useCallback as bt } from "react";
|
|
4
|
+
import { transformStateFunc as Wt, isDeepEqual as J, isFunction as tt, getNestedValue as Z, getDifferences as At, debounce as zt } from "./utility.js";
|
|
5
|
+
import { pushFunc as Ot, updateFn as ct, cutFunc as ht, ValidationWrapper as qt, FormControlComponent as Jt } from "./Functions.jsx";
|
|
6
|
+
import Yt from "superjson";
|
|
7
|
+
import { v4 as Nt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
9
|
+
import { getGlobalStore as o, formRefStore as Mt } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Lt } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Zt } from "fast-json-patch";
|
|
12
|
+
import Xt from "react-use-measure";
|
|
13
|
+
function xt(t, c) {
|
|
14
14
|
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
|
|
15
15
|
g(t, {
|
|
16
16
|
...I,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Pt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
@@ -35,7 +35,7 @@ function Ie(t, { formElements: c, validation: m }) {
|
|
|
35
35
|
}
|
|
36
36
|
const ve = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [g, I] =
|
|
38
|
+
const [g, I] = Wt(m);
|
|
39
39
|
(Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
|
|
40
40
|
I[v] = I[v] || {}, I[v].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
@@ -46,13 +46,13 @@ const ve = (t, c) => {
|
|
|
46
46
|
}, rt(v) || o.getState().setInitialStateOptions(v, I[v]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
48
|
const N = (v, s) => {
|
|
49
|
-
const [T] = K(s?.componentId ??
|
|
50
|
-
|
|
49
|
+
const [T] = K(s?.componentId ?? Nt());
|
|
50
|
+
Pt({
|
|
51
51
|
stateKey: v,
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W,
|
|
55
|
+
const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = re(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
@@ -68,24 +68,24 @@ const ve = (t, c) => {
|
|
|
68
68
|
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return j;
|
|
72
72
|
};
|
|
73
73
|
function p(v, s) {
|
|
74
|
-
|
|
74
|
+
Pt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && ee(v, s), ut(v);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: Tt,
|
|
79
79
|
setState: nt,
|
|
80
80
|
getInitialOptions: rt,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
81
|
+
getKeyState: Rt,
|
|
82
|
+
getValidationErrors: Qt,
|
|
83
|
+
setStateLog: Kt,
|
|
84
|
+
updateInitialStateGlobal: Ct,
|
|
85
|
+
addValidationError: Dt,
|
|
86
86
|
removeValidationError: Q,
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
87
|
+
setServerSyncActions: te
|
|
88
|
+
} = o.getState(), Vt = (t, c, m, g, I) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
@@ -104,7 +104,7 @@ const ve = (t, c) => {
|
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: I ?? v
|
|
107
|
-
}, T =
|
|
107
|
+
}, T = Yt.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(T.json)
|
|
@@ -118,17 +118,17 @@ const ve = (t, c) => {
|
|
|
118
118
|
} catch (c) {
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: g } =
|
|
121
|
+
}, ee = (t, c) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = Lt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (I && g) {
|
|
124
124
|
const N = vt(
|
|
125
125
|
`${g}-${t}-${I}`
|
|
126
126
|
);
|
|
127
127
|
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
|
-
return nt(t, N.state),
|
|
128
|
+
return nt(t, N.state), ut(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ht = (t, c, m, g, I, N) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: It(
|
|
@@ -139,8 +139,8 @@ const ve = (t, c) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
Ct(t, p.initialState), Tt(t, p.updaterState), nt(t, p.state);
|
|
143
|
+
}, ut = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -157,22 +157,22 @@ const ve = (t, c) => {
|
|
|
157
157
|
return;
|
|
158
158
|
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, ne = (t, c, m, g) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: Z(c, g),
|
|
165
|
+
newValue: Z(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: Z(m, 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
|
};
|
|
@@ -180,7 +180,7 @@ const ve = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function re(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
@@ -193,12 +193,12 @@ function ne(t, {
|
|
|
193
193
|
dependencies: r,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [W,
|
|
196
|
+
const [W, j] = K({}), { sessionId: U } = Lt();
|
|
197
197
|
let z = !c;
|
|
198
|
-
const [h] = K(c ??
|
|
198
|
+
const [h] = K(c ?? Nt()), l = o.getState().stateLog[h], gt = q(/* @__PURE__ */ new Set()), et = q(v ?? Nt()), R = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
R.current = rt(h) ?? null, ot(() => {
|
|
202
202
|
if (T && T.stateKey === h && T.path?.[0]) {
|
|
203
203
|
nt(h, (n) => ({
|
|
204
204
|
...n,
|
|
@@ -212,203 +212,203 @@ function ne(t, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [T]), ot(() => {
|
|
214
214
|
if (s) {
|
|
215
|
-
|
|
215
|
+
xt(h, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
218
|
+
const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
219
|
if (!(i && !J(i, s) || !i) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
223
|
E && U && (u = vt(`${U}-${h}-${E}`));
|
|
224
|
-
let y = s,
|
|
225
|
-
const C = a ? Date.now() : 0,
|
|
226
|
-
a && C >
|
|
224
|
+
let y = s, _ = !1;
|
|
225
|
+
const C = a ? Date.now() : 0, w = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
|
|
226
|
+
a && C > w ? (y = e.serverState.data, _ = !0) : u && w > b && (y = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Ht(
|
|
227
227
|
h,
|
|
228
228
|
s,
|
|
229
229
|
y,
|
|
230
230
|
at,
|
|
231
231
|
et.current,
|
|
232
232
|
U
|
|
233
|
-
),
|
|
233
|
+
), _ && E && U && Vt(y, h, e, U, Date.now()), ut(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || j({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...r || []
|
|
240
|
-
]),
|
|
241
|
-
z &&
|
|
240
|
+
]), lt(() => {
|
|
241
|
+
z && xt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: I,
|
|
244
244
|
initialState: s,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: R.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const e = `${h}////${et.current}`, n = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return n.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => j({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: N || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(h, n),
|
|
257
|
+
}), o.getState().stateComponents.set(h, n), j({}), () => {
|
|
258
258
|
n && (n.components.delete(e), n.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const at = (e, n, a, i) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
263
263
|
const u = `${h}-${n.join(".")}`;
|
|
264
|
-
|
|
264
|
+
gt.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = o.getState();
|
|
267
267
|
nt(h, (u) => {
|
|
268
268
|
const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
|
|
269
269
|
if (y) {
|
|
270
|
-
let
|
|
270
|
+
let P = !1, $ = f.signalDomElements.get(y);
|
|
271
271
|
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const
|
|
272
|
+
const D = n.slice(0, -1), V = Z(E, D);
|
|
273
273
|
if (Array.isArray(V)) {
|
|
274
|
-
|
|
275
|
-
const O = `${h}-${
|
|
274
|
+
P = !0;
|
|
275
|
+
const O = `${h}-${D.join(".")}`;
|
|
276
276
|
$ = f.signalDomElements.get(O);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if ($) {
|
|
280
|
-
const
|
|
281
|
-
$.forEach(({ parentId: V, position: O, effect:
|
|
282
|
-
const
|
|
280
|
+
const D = P ? Z(E, n.slice(0, -1)) : Z(E, n);
|
|
281
|
+
$.forEach(({ parentId: V, position: O, effect: A }) => {
|
|
282
|
+
const H = document.querySelector(
|
|
283
283
|
`[data-parent-id="${V}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const G = Array.from(
|
|
285
|
+
if (H) {
|
|
286
|
+
const G = Array.from(H.childNodes);
|
|
287
287
|
if (G[O]) {
|
|
288
|
-
const
|
|
289
|
-
G[O].textContent = String(
|
|
288
|
+
const F = A ? new Function("state", `return (${A})(state)`)(D) : D;
|
|
289
|
+
G[O].textContent = String(F);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i ||
|
|
296
|
-
(i ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i || R.current?.validation?.key) && n && Q(
|
|
296
|
+
(i || R.current?.validation?.key) + "." + n.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([$,
|
|
298
|
+
const _ = n.slice(0, n.length - 1);
|
|
299
|
+
a.updateType === "cut" && R.current?.validation?.key && Q(
|
|
300
|
+
R.current?.validation?.key + "." + _.join(".")
|
|
301
|
+
), a.updateType === "insert" && R.current?.validation?.key && Qt(
|
|
302
|
+
R.current?.validation?.key + "." + _.join(".")
|
|
303
|
+
).filter(([$, D]) => {
|
|
304
304
|
let V = $?.split(".").length;
|
|
305
|
-
if ($ ==
|
|
306
|
-
let O = $ + "." +
|
|
307
|
-
Q($),
|
|
305
|
+
if ($ == _.join(".") && V == _.length - 1) {
|
|
306
|
+
let O = $ + "." + _;
|
|
307
|
+
Q($), Dt(O, D);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
const C = f.stateComponents.get(h);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
-
const
|
|
312
|
+
const P = At(u, E), $ = new Set(P), D = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
V,
|
|
315
315
|
O
|
|
316
316
|
] of C.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", O), !
|
|
320
|
-
if (
|
|
317
|
+
let A = !1;
|
|
318
|
+
const H = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", O), !H.includes("none")) {
|
|
320
|
+
if (H.includes("all")) {
|
|
321
321
|
O.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
324
|
+
if (H.includes("component") && ((O.paths.has(D) || O.paths.has("")) && (A = !0), !A))
|
|
325
325
|
for (const G of $) {
|
|
326
|
-
let
|
|
326
|
+
let F = G;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (O.paths.has(
|
|
329
|
-
|
|
328
|
+
if (O.paths.has(F)) {
|
|
329
|
+
A = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const st =
|
|
332
|
+
const st = F.lastIndexOf(".");
|
|
333
333
|
if (st !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const ft = F.substring(
|
|
335
335
|
0,
|
|
336
336
|
st
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && O.paths.has(
|
|
341
|
-
|
|
339
|
+
Number(F.substring(st + 1))
|
|
340
|
+
) && O.paths.has(ft)) {
|
|
341
|
+
A = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
F = ft;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
F = "";
|
|
347
|
+
if (F === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (A) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
352
|
+
if (!A && H.includes("deps") && O.depsFunction) {
|
|
353
353
|
const G = O.depsFunction(E);
|
|
354
|
-
let
|
|
355
|
-
typeof G == "boolean" ? G && (
|
|
354
|
+
let F = !1;
|
|
355
|
+
typeof G == "boolean" ? G && (F = !0) : J(O.deps, G) || (O.deps = G, F = !0), F && (A = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
A && O.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
n = n.map((
|
|
363
|
-
const
|
|
364
|
-
return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() :
|
|
361
|
+
const w = Date.now();
|
|
362
|
+
n = n.map((P, $) => {
|
|
363
|
+
const D = n.slice(0, -1), V = Z(E, D);
|
|
364
|
+
return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : P;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: b, newValue:
|
|
366
|
+
const { oldValue: b, newValue: B } = ne(
|
|
367
367
|
a.updateType,
|
|
368
368
|
u,
|
|
369
369
|
E,
|
|
370
370
|
n
|
|
371
371
|
), Y = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: w,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: n,
|
|
375
375
|
updateType: a.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: b,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: B
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
f.updateShadowAtPath(h, n, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(h,
|
|
385
|
+
const P = n.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(h, P, B);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const $ = n.slice(0, -1),
|
|
390
|
-
f.removeShadowArrayElement(h, $,
|
|
389
|
+
const $ = n.slice(0, -1), D = parseInt(n[n.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(h, $, D);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Kt(h, (P) => {
|
|
394
|
+
const D = [...P ?? [], Y].reduce((V, O) => {
|
|
395
|
+
const A = `${O.stateKey}:${JSON.stringify(O.path)}`, H = V.get(A);
|
|
396
|
+
return H ? (H.timeStamp = Math.max(H.timeStamp, O.timeStamp), H.newValue = O.newValue, H.oldValue = H.oldValue ?? O.oldValue, H.updateType = O.updateType) : V.set(A, { ...O }), V;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(D.values());
|
|
399
|
+
}), Vt(
|
|
400
400
|
E,
|
|
401
401
|
h,
|
|
402
|
-
|
|
402
|
+
R.current,
|
|
403
403
|
U
|
|
404
|
-
),
|
|
404
|
+
), R.current?.middleware && R.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
407
|
+
}), R.current?.serverSync) {
|
|
408
|
+
const P = f.serverState[h], $ = R.current?.serverSync;
|
|
409
|
+
te(h, {
|
|
410
410
|
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
|
|
411
|
-
rollBackState:
|
|
411
|
+
rollBackState: P,
|
|
412
412
|
actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
@@ -424,14 +424,14 @@ function ne(t, {
|
|
|
424
424
|
et.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] ||
|
|
427
|
+
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Ct(h, t));
|
|
428
428
|
const d = wt(() => It(
|
|
429
429
|
h,
|
|
430
430
|
at,
|
|
431
431
|
et.current,
|
|
432
432
|
U
|
|
433
433
|
), [h, U]);
|
|
434
|
-
return [
|
|
434
|
+
return [Rt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function It(t, c, m, g) {
|
|
437
437
|
const I = /* @__PURE__ */ new Map();
|
|
@@ -450,7 +450,7 @@ function It(t, c, m, g) {
|
|
|
450
450
|
r?.key && Q(r?.key), T?.validationKey && Q(T.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
452
|
o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
|
|
453
|
-
const W = s(S, []),
|
|
453
|
+
const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
|
|
454
454
|
z && localStorage.removeItem(z), Tt(t, W), nt(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
@@ -464,9 +464,9 @@ function It(t, c, m, g) {
|
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = o.getState().initialStateGlobal[t], W = rt(t),
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
|
|
468
468
|
return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
|
|
469
|
-
|
|
469
|
+
Ct(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
|
|
470
470
|
const z = o.getState().stateComponents.get(t);
|
|
471
471
|
z && z.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
@@ -480,27 +480,27 @@ function It(t, c, m, g) {
|
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const T = o.getState().serverState[t];
|
|
483
|
-
return !!(T && J(T,
|
|
483
|
+
return !!(T && J(T, Rt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function s(T, r = [], S) {
|
|
487
487
|
const W = r.map(String).join(".");
|
|
488
488
|
I.get(W);
|
|
489
|
-
const
|
|
489
|
+
const j = function() {
|
|
490
490
|
return o().getNestedState(t, r);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(v).forEach((h) => {
|
|
493
|
-
|
|
493
|
+
j[h] = v[h];
|
|
494
494
|
});
|
|
495
495
|
const U = {
|
|
496
|
-
apply(h, l,
|
|
496
|
+
apply(h, l, gt) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${r.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(T) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const gt = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function It(t, c, m, g) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !gt.has(l)) {
|
|
527
527
|
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const n = e.components.get(d);
|
|
@@ -540,7 +540,7 @@ function It(t, c, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => At(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -568,7 +568,7 @@ function It(t, c, m, g) {
|
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n =
|
|
571
|
+
const d = o.getState().getNestedState(t, r), e = o.getState().initialStateGlobal[t], n = Z(e, r);
|
|
572
572
|
return J(d, n) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
@@ -576,7 +576,7 @@ function It(t, c, m, g) {
|
|
|
576
576
|
const d = o().getNestedState(
|
|
577
577
|
t,
|
|
578
578
|
r
|
|
579
|
-
), e = o.getState().initialStateGlobal[t], n =
|
|
579
|
+
), e = o.getState().initialStateGlobal[t], n = Z(e, r);
|
|
580
580
|
return J(d, n) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
@@ -622,49 +622,49 @@ function It(t, c, m, g) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: i = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = e, u = q(!1), E = q(null), [y,
|
|
625
|
+
} = e, u = q(!1), E = q(null), [y, _] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [C,
|
|
628
|
+
}), [C, w] = K("IDLE_AT_TOP"), b = q(!1), B = q(0), Y = q(f), P = q(0), [$, D] = K(0), V = q(null);
|
|
629
629
|
ot(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
|
-
|
|
630
|
+
D((M) => M + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const O = o().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
r
|
|
635
|
-
),
|
|
635
|
+
), A = O.length, { totalHeight: H, positions: G } = wt(() => {
|
|
636
636
|
const k = o.getState().getShadowMetadata(t, r) || [];
|
|
637
|
-
let
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
637
|
+
let M = 0;
|
|
638
|
+
const L = [];
|
|
639
|
+
for (let x = 0; x < A; x++) {
|
|
640
|
+
L[x] = M;
|
|
641
|
+
const X = k[x]?.virtualizer?.itemHeight;
|
|
642
|
+
M += X || n;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: M, positions: L };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
646
|
+
A,
|
|
647
647
|
t,
|
|
648
648
|
r.join("."),
|
|
649
649
|
n,
|
|
650
650
|
$
|
|
651
|
-
]),
|
|
652
|
-
const k = Math.max(0, y.startIndex),
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return s(
|
|
651
|
+
]), F = wt(() => {
|
|
652
|
+
const k = Math.max(0, y.startIndex), M = Math.min(A, y.endIndex), L = Array.from(
|
|
653
|
+
{ length: M - k },
|
|
654
|
+
(X, it) => k + it
|
|
655
|
+
), x = L.map((X) => O[X]);
|
|
656
|
+
return s(x, r, {
|
|
657
657
|
...S,
|
|
658
|
-
validIndices:
|
|
658
|
+
validIndices: L
|
|
659
659
|
});
|
|
660
|
-
}, [y.startIndex, y.endIndex, O,
|
|
661
|
-
|
|
660
|
+
}, [y.startIndex, y.endIndex, O, A]);
|
|
661
|
+
lt(() => {
|
|
662
662
|
const k = E.current;
|
|
663
663
|
if (!k) return;
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
666
|
-
const { top:
|
|
667
|
-
b.current = !0, k.scrollTop =
|
|
664
|
+
const M = A > B.current;
|
|
665
|
+
if (M && V.current) {
|
|
666
|
+
const { top: L, height: x } = V.current;
|
|
667
|
+
b.current = !0, k.scrollTop = L + (k.scrollHeight - x), console.log(
|
|
668
668
|
`ANCHOR RESTORED to scrollTop: ${k.scrollTop}`
|
|
669
669
|
), setTimeout(() => {
|
|
670
670
|
b.current = !1;
|
|
@@ -674,104 +674,108 @@ function It(t, c, m, g) {
|
|
|
674
674
|
f,
|
|
675
675
|
Y.current
|
|
676
676
|
)) {
|
|
677
|
-
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"),
|
|
677
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), w("IDLE_AT_TOP");
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
|
-
|
|
680
|
+
M && C === "LOCKED_AT_BOTTOM" && i && (console.log(
|
|
681
681
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
682
|
-
),
|
|
682
|
+
), w("GETTING_HEIGHTS"));
|
|
683
683
|
}
|
|
684
|
-
|
|
685
|
-
}, [
|
|
684
|
+
B.current = A, Y.current = f;
|
|
685
|
+
}, [A, ...f]), lt(() => {
|
|
686
686
|
const k = E.current;
|
|
687
687
|
if (!k) return;
|
|
688
|
-
let
|
|
689
|
-
if (C === "IDLE_AT_TOP" && i &&
|
|
688
|
+
let M;
|
|
689
|
+
if (C === "IDLE_AT_TOP" && i && A > 0)
|
|
690
690
|
console.log(
|
|
691
691
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
692
|
-
),
|
|
693
|
-
else if (C === "GETTING_HEIGHTS")
|
|
692
|
+
), w("GETTING_HEIGHTS");
|
|
693
|
+
else if (C === "GETTING_HEIGHTS") {
|
|
694
694
|
console.log(
|
|
695
695
|
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
696
|
-
),
|
|
697
|
-
startIndex: Math.max(0,
|
|
698
|
-
endIndex:
|
|
699
|
-
})
|
|
700
|
-
|
|
696
|
+
), _({
|
|
697
|
+
startIndex: Math.max(0, A - 10 - a),
|
|
698
|
+
endIndex: A
|
|
699
|
+
});
|
|
700
|
+
let L = 0;
|
|
701
|
+
const x = 50;
|
|
702
|
+
M = setInterval(() => {
|
|
703
|
+
L++;
|
|
704
|
+
const X = A - 1, yt = (o.getState().getShadowMetadata(t, r) || [])[X]?.virtualizer?.itemHeight || 0;
|
|
701
705
|
console.log(
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
j
|
|
706
|
-
), Z > 0 && (clearInterval(x), u.current || (console.log(
|
|
706
|
+
`ACTION (GETTING_HEIGHTS): attempt ${L}, lastItemHeight =`,
|
|
707
|
+
yt
|
|
708
|
+
), yt > 0 ? (clearInterval(M), console.log(
|
|
707
709
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
708
|
-
),
|
|
710
|
+
), w("SCROLLING_TO_BOTTOM")) : L >= x && (clearInterval(M), console.log(
|
|
711
|
+
"ACTION (GETTING_HEIGHTS): Timeout - proceeding anyway"
|
|
712
|
+
), w("SCROLLING_TO_BOTTOM"));
|
|
709
713
|
}, 100);
|
|
710
|
-
else if (C === "SCROLLING_TO_BOTTOM") {
|
|
714
|
+
} else if (C === "SCROLLING_TO_BOTTOM") {
|
|
711
715
|
console.log(
|
|
712
716
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
713
717
|
), b.current = !0;
|
|
714
|
-
const
|
|
718
|
+
const L = B.current === 0 ? "auto" : "smooth";
|
|
715
719
|
k.scrollTo({
|
|
716
720
|
top: k.scrollHeight,
|
|
717
|
-
behavior:
|
|
721
|
+
behavior: L
|
|
718
722
|
});
|
|
719
|
-
const
|
|
723
|
+
const x = setTimeout(
|
|
720
724
|
() => {
|
|
721
725
|
console.log(
|
|
722
726
|
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
723
|
-
), b.current = !1, u.current = !1,
|
|
727
|
+
), b.current = !1, u.current = !1, w("LOCKED_AT_BOTTOM");
|
|
724
728
|
},
|
|
725
|
-
|
|
729
|
+
L === "smooth" ? 500 : 50
|
|
726
730
|
);
|
|
727
|
-
return () => clearTimeout(
|
|
731
|
+
return () => clearTimeout(x);
|
|
728
732
|
}
|
|
729
733
|
return () => {
|
|
730
|
-
|
|
734
|
+
M && clearInterval(M);
|
|
731
735
|
};
|
|
732
|
-
}, [C,
|
|
736
|
+
}, [C, A, G]), ot(() => {
|
|
733
737
|
const k = E.current;
|
|
734
738
|
if (!k) return;
|
|
735
|
-
const
|
|
739
|
+
const M = n, L = () => {
|
|
736
740
|
if (b.current)
|
|
737
741
|
return;
|
|
738
|
-
const { scrollTop:
|
|
739
|
-
if (
|
|
740
|
-
top:
|
|
741
|
-
height:
|
|
742
|
-
}), Math.abs(
|
|
742
|
+
const { scrollTop: x, scrollHeight: X, clientHeight: it } = k;
|
|
743
|
+
if (X - x - it < 10 ? (C !== "LOCKED_AT_BOTTOM" && w("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && w("IDLE_NOT_AT_BOTTOM"), V.current = {
|
|
744
|
+
top: x,
|
|
745
|
+
height: X
|
|
746
|
+
}), Math.abs(x - P.current) < M)
|
|
743
747
|
return;
|
|
744
748
|
console.log(
|
|
745
|
-
`Threshold passed at ${
|
|
749
|
+
`Threshold passed at ${x}px. Recalculating range...`
|
|
746
750
|
);
|
|
747
|
-
let
|
|
748
|
-
for (;
|
|
749
|
-
const mt = Math.floor((
|
|
750
|
-
G[mt] <
|
|
751
|
+
let pt = A - 1, Et = 0, $t = 0;
|
|
752
|
+
for (; Et <= pt; ) {
|
|
753
|
+
const mt = Math.floor((Et + pt) / 2);
|
|
754
|
+
G[mt] < x ? ($t = mt, Et = mt + 1) : pt = mt - 1;
|
|
751
755
|
}
|
|
752
|
-
const
|
|
753
|
-
let St =
|
|
754
|
-
const
|
|
755
|
-
for (; St <
|
|
756
|
+
const kt = Math.max(0, $t - a);
|
|
757
|
+
let St = kt;
|
|
758
|
+
const Ut = x + it;
|
|
759
|
+
for (; St < A && G[St] < Ut; )
|
|
756
760
|
St++;
|
|
757
|
-
|
|
758
|
-
startIndex:
|
|
759
|
-
endIndex: Math.min(
|
|
760
|
-
}),
|
|
761
|
+
_({
|
|
762
|
+
startIndex: kt,
|
|
763
|
+
endIndex: Math.min(A, St + a)
|
|
764
|
+
}), P.current = x;
|
|
761
765
|
};
|
|
762
|
-
return k.addEventListener("scroll",
|
|
766
|
+
return k.addEventListener("scroll", L, {
|
|
763
767
|
passive: !0
|
|
764
|
-
}), () => k.removeEventListener("scroll",
|
|
765
|
-
}, [
|
|
766
|
-
const st =
|
|
768
|
+
}), () => k.removeEventListener("scroll", L);
|
|
769
|
+
}, [A, G, n, a, C]);
|
|
770
|
+
const st = bt(() => {
|
|
767
771
|
console.log(
|
|
768
772
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
769
|
-
),
|
|
770
|
-
}, []),
|
|
771
|
-
(k,
|
|
772
|
-
E.current && G[k] !== void 0 && (
|
|
773
|
+
), w("SCROLLING_TO_BOTTOM");
|
|
774
|
+
}, []), ft = bt(
|
|
775
|
+
(k, M = "smooth") => {
|
|
776
|
+
E.current && G[k] !== void 0 && (w("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
773
777
|
top: G[k],
|
|
774
|
-
behavior:
|
|
778
|
+
behavior: M
|
|
775
779
|
}));
|
|
776
780
|
},
|
|
777
781
|
[G]
|
|
@@ -782,7 +786,7 @@ function It(t, c, m, g) {
|
|
|
782
786
|
},
|
|
783
787
|
inner: {
|
|
784
788
|
style: {
|
|
785
|
-
height: `${
|
|
789
|
+
height: `${H}px`,
|
|
786
790
|
position: "relative"
|
|
787
791
|
}
|
|
788
792
|
},
|
|
@@ -793,10 +797,10 @@ function It(t, c, m, g) {
|
|
|
793
797
|
}
|
|
794
798
|
};
|
|
795
799
|
return {
|
|
796
|
-
virtualState:
|
|
800
|
+
virtualState: F,
|
|
797
801
|
virtualizerProps: jt,
|
|
798
802
|
scrollToBottom: st,
|
|
799
|
-
scrollToIndex:
|
|
803
|
+
scrollToIndex: ft
|
|
800
804
|
};
|
|
801
805
|
};
|
|
802
806
|
if (l === "stateSort")
|
|
@@ -830,19 +834,19 @@ function It(t, c, m, g) {
|
|
|
830
834
|
const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
|
|
831
835
|
return e(u, y, {
|
|
832
836
|
register: () => {
|
|
833
|
-
const [, C] = K({}),
|
|
834
|
-
|
|
835
|
-
const b = `${t}////${
|
|
837
|
+
const [, C] = K({}), w = `${m}-${r.join(".")}-${i}`;
|
|
838
|
+
lt(() => {
|
|
839
|
+
const b = `${t}////${w}`, B = o.getState().stateComponents.get(t) || {
|
|
836
840
|
components: /* @__PURE__ */ new Map()
|
|
837
841
|
};
|
|
838
|
-
return
|
|
842
|
+
return B.components.set(b, {
|
|
839
843
|
forceUpdate: () => C({}),
|
|
840
844
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
841
|
-
}), o.getState().stateComponents.set(t,
|
|
845
|
+
}), o.getState().stateComponents.set(t, B), () => {
|
|
842
846
|
const Y = o.getState().stateComponents.get(t);
|
|
843
847
|
Y && Y.components.delete(b);
|
|
844
848
|
};
|
|
845
|
-
}, [t,
|
|
849
|
+
}, [t, w]);
|
|
846
850
|
},
|
|
847
851
|
index: f,
|
|
848
852
|
originalIndex: i
|
|
@@ -866,7 +870,7 @@ function It(t, c, m, g) {
|
|
|
866
870
|
);
|
|
867
871
|
});
|
|
868
872
|
if (l === "$stateMap")
|
|
869
|
-
return (e) =>
|
|
873
|
+
return (e) => dt(oe, {
|
|
870
874
|
proxy: {
|
|
871
875
|
_stateKey: t,
|
|
872
876
|
_path: r,
|
|
@@ -879,11 +883,11 @@ function It(t, c, m, g) {
|
|
|
879
883
|
return (e) => {
|
|
880
884
|
const n = o.getState().getNestedState(t, r);
|
|
881
885
|
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
882
|
-
const u = n[i], E = [...r, i.toString()], y = s(u, E, S),
|
|
883
|
-
return
|
|
886
|
+
const u = n[i], E = [...r, i.toString()], y = s(u, E, S), _ = `${m}-${r.join(".")}-${i}`;
|
|
887
|
+
return dt(se, {
|
|
884
888
|
key: i,
|
|
885
889
|
stateKey: t,
|
|
886
|
-
itemComponentId:
|
|
890
|
+
itemComponentId: _,
|
|
887
891
|
itemPath: E,
|
|
888
892
|
children: e(
|
|
889
893
|
u,
|
|
@@ -923,7 +927,7 @@ function It(t, c, m, g) {
|
|
|
923
927
|
return s(a, i);
|
|
924
928
|
};
|
|
925
929
|
if (l === "insert")
|
|
926
|
-
return (e) => (p(r),
|
|
930
|
+
return (e) => (p(r), Ot(c, e, r, t), s(
|
|
927
931
|
o.getState().getNestedState(t, r),
|
|
928
932
|
r
|
|
929
933
|
));
|
|
@@ -934,19 +938,19 @@ function It(t, c, m, g) {
|
|
|
934
938
|
if (!i.some((y) => {
|
|
935
939
|
if (n) {
|
|
936
940
|
const C = n.every(
|
|
937
|
-
(
|
|
941
|
+
(w) => J(y[w], f[w])
|
|
938
942
|
);
|
|
939
943
|
return C && (u = y), C;
|
|
940
944
|
}
|
|
941
|
-
const
|
|
942
|
-
return
|
|
945
|
+
const _ = J(y, f);
|
|
946
|
+
return _ && (u = y), _;
|
|
943
947
|
}))
|
|
944
|
-
p(r),
|
|
948
|
+
p(r), Ot(c, f, r, t);
|
|
945
949
|
else if (a && u) {
|
|
946
|
-
const y = a(u),
|
|
950
|
+
const y = a(u), _ = i.map(
|
|
947
951
|
(C) => J(C, u) ? y : C
|
|
948
952
|
);
|
|
949
|
-
p(r),
|
|
953
|
+
p(r), ct(c, _, r);
|
|
950
954
|
}
|
|
951
955
|
};
|
|
952
956
|
if (l === "cut")
|
|
@@ -965,7 +969,7 @@ function It(t, c, m, g) {
|
|
|
965
969
|
if (l === "toggleByValue")
|
|
966
970
|
return (e) => {
|
|
967
971
|
const n = T.findIndex((a) => a === e);
|
|
968
|
-
n > -1 ? ht(c, r, t, n) :
|
|
972
|
+
n > -1 ? ht(c, r, t, n) : Ot(c, e, r, t);
|
|
969
973
|
};
|
|
970
974
|
if (l === "stateFind")
|
|
971
975
|
return (e) => {
|
|
@@ -1006,13 +1010,13 @@ function It(t, c, m, g) {
|
|
|
1006
1010
|
return o.getState().getNestedState(t, r);
|
|
1007
1011
|
};
|
|
1008
1012
|
if (l === "$derive")
|
|
1009
|
-
return (d) =>
|
|
1013
|
+
return (d) => Gt({
|
|
1010
1014
|
_stateKey: t,
|
|
1011
1015
|
_path: r,
|
|
1012
1016
|
_effect: d.toString()
|
|
1013
1017
|
});
|
|
1014
1018
|
if (l === "$get")
|
|
1015
|
-
return () =>
|
|
1019
|
+
return () => Gt({
|
|
1016
1020
|
_stateKey: t,
|
|
1017
1021
|
_path: r
|
|
1018
1022
|
});
|
|
@@ -1031,7 +1035,7 @@ function It(t, c, m, g) {
|
|
|
1031
1035
|
const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
|
|
1032
1036
|
d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
|
|
1033
1037
|
const i = o.getState().getNestedState(t, [...e]);
|
|
1034
|
-
|
|
1038
|
+
ct(c, i, e), p(e);
|
|
1035
1039
|
};
|
|
1036
1040
|
if (l === "toggleSelected")
|
|
1037
1041
|
return () => {
|
|
@@ -1042,7 +1046,7 @@ function It(t, c, m, g) {
|
|
|
1042
1046
|
a === e ? void 0 : e
|
|
1043
1047
|
);
|
|
1044
1048
|
const i = o.getState().getNestedState(t, [...d]);
|
|
1045
|
-
|
|
1049
|
+
ct(c, i, d), p(d);
|
|
1046
1050
|
};
|
|
1047
1051
|
if (r.length == 0) {
|
|
1048
1052
|
if (l === "addValidation")
|
|
@@ -1052,13 +1056,13 @@ function It(t, c, m, g) {
|
|
|
1052
1056
|
throw new Error("Validation key not found");
|
|
1053
1057
|
Q(e.key), console.log("addValidationError", d), d.forEach((n) => {
|
|
1054
1058
|
const a = [e.key, ...n.path].join(".");
|
|
1055
|
-
console.log("fullErrorPath", a),
|
|
1056
|
-
}),
|
|
1059
|
+
console.log("fullErrorPath", a), Dt(a, n.message);
|
|
1060
|
+
}), ut(t);
|
|
1057
1061
|
};
|
|
1058
1062
|
if (l === "applyJsonPatch")
|
|
1059
1063
|
return (d) => {
|
|
1060
|
-
const e = o.getState().cogsStateStore[t], a =
|
|
1061
|
-
|
|
1064
|
+
const e = o.getState().cogsStateStore[t], a = Zt(e, d).newDocument;
|
|
1065
|
+
Ht(
|
|
1062
1066
|
t,
|
|
1063
1067
|
o.getState().initialStateGlobal[t],
|
|
1064
1068
|
a,
|
|
@@ -1068,57 +1072,57 @@ function It(t, c, m, g) {
|
|
|
1068
1072
|
);
|
|
1069
1073
|
const i = o.getState().stateComponents.get(t);
|
|
1070
1074
|
if (i) {
|
|
1071
|
-
const f =
|
|
1075
|
+
const f = At(e, a), u = new Set(f);
|
|
1072
1076
|
for (const [
|
|
1073
1077
|
E,
|
|
1074
1078
|
y
|
|
1075
1079
|
] of i.components.entries()) {
|
|
1076
|
-
let
|
|
1080
|
+
let _ = !1;
|
|
1077
1081
|
const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
1078
1082
|
if (!C.includes("none")) {
|
|
1079
1083
|
if (C.includes("all")) {
|
|
1080
1084
|
y.forceUpdate();
|
|
1081
1085
|
continue;
|
|
1082
1086
|
}
|
|
1083
|
-
if (C.includes("component") && (y.paths.has("") && (
|
|
1084
|
-
for (const
|
|
1085
|
-
if (y.paths.has(
|
|
1086
|
-
|
|
1087
|
+
if (C.includes("component") && (y.paths.has("") && (_ = !0), !_))
|
|
1088
|
+
for (const w of u) {
|
|
1089
|
+
if (y.paths.has(w)) {
|
|
1090
|
+
_ = !0;
|
|
1087
1091
|
break;
|
|
1088
1092
|
}
|
|
1089
|
-
let b =
|
|
1093
|
+
let b = w.lastIndexOf(".");
|
|
1090
1094
|
for (; b !== -1; ) {
|
|
1091
|
-
const
|
|
1092
|
-
if (y.paths.has(
|
|
1093
|
-
|
|
1095
|
+
const B = w.substring(0, b);
|
|
1096
|
+
if (y.paths.has(B)) {
|
|
1097
|
+
_ = !0;
|
|
1094
1098
|
break;
|
|
1095
1099
|
}
|
|
1096
|
-
const Y =
|
|
1100
|
+
const Y = w.substring(
|
|
1097
1101
|
b + 1
|
|
1098
1102
|
);
|
|
1099
1103
|
if (!isNaN(Number(Y))) {
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
-
const $ =
|
|
1104
|
+
const P = B.lastIndexOf(".");
|
|
1105
|
+
if (P !== -1) {
|
|
1106
|
+
const $ = B.substring(
|
|
1103
1107
|
0,
|
|
1104
|
-
|
|
1108
|
+
P
|
|
1105
1109
|
);
|
|
1106
1110
|
if (y.paths.has($)) {
|
|
1107
|
-
|
|
1111
|
+
_ = !0;
|
|
1108
1112
|
break;
|
|
1109
1113
|
}
|
|
1110
1114
|
}
|
|
1111
1115
|
}
|
|
1112
|
-
b =
|
|
1116
|
+
b = B.lastIndexOf(".");
|
|
1113
1117
|
}
|
|
1114
|
-
if (
|
|
1118
|
+
if (_) break;
|
|
1115
1119
|
}
|
|
1116
|
-
if (!
|
|
1117
|
-
const
|
|
1120
|
+
if (!_ && C.includes("deps") && y.depsFunction) {
|
|
1121
|
+
const w = y.depsFunction(a);
|
|
1118
1122
|
let b = !1;
|
|
1119
|
-
typeof
|
|
1123
|
+
typeof w == "boolean" ? w && (b = !0) : J(y.deps, w) || (y.deps = w, b = !0), b && (_ = !0);
|
|
1120
1124
|
}
|
|
1121
|
-
|
|
1125
|
+
_ && y.forceUpdate();
|
|
1122
1126
|
}
|
|
1123
1127
|
}
|
|
1124
1128
|
}
|
|
@@ -1139,9 +1143,9 @@ function It(t, c, m, g) {
|
|
|
1139
1143
|
});
|
|
1140
1144
|
const i = d.zodSchema.safeParse(n);
|
|
1141
1145
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1142
|
-
const E = u.path, y = u.message,
|
|
1143
|
-
e(
|
|
1144
|
-
}),
|
|
1146
|
+
const E = u.path, y = u.message, _ = [d.key, ...E].join(".");
|
|
1147
|
+
e(_, y);
|
|
1148
|
+
}), ut(t), !1);
|
|
1145
1149
|
} catch (a) {
|
|
1146
1150
|
return console.error("Zod schema validation failed", a), !1;
|
|
1147
1151
|
}
|
|
@@ -1150,7 +1154,7 @@ function It(t, c, m, g) {
|
|
|
1150
1154
|
if (l === "getComponents")
|
|
1151
1155
|
return () => o().stateComponents.get(t);
|
|
1152
1156
|
if (l === "getAllFormRefs")
|
|
1153
|
-
return () =>
|
|
1157
|
+
return () => Mt.getState().getFormRefsByStateKey(t);
|
|
1154
1158
|
if (l === "_initialState")
|
|
1155
1159
|
return o.getState().initialStateGlobal[t];
|
|
1156
1160
|
if (l === "_serverState")
|
|
@@ -1163,13 +1167,13 @@ function It(t, c, m, g) {
|
|
|
1163
1167
|
if (l === "removeValidation") return v.removeValidation;
|
|
1164
1168
|
}
|
|
1165
1169
|
if (l === "getFormRef")
|
|
1166
|
-
return () =>
|
|
1170
|
+
return () => Mt.getState().getFormRef(t + "." + r.join("."));
|
|
1167
1171
|
if (l === "validationWrapper")
|
|
1168
1172
|
return ({
|
|
1169
1173
|
children: d,
|
|
1170
1174
|
hideMessage: e
|
|
1171
|
-
}) => /* @__PURE__ */
|
|
1172
|
-
|
|
1175
|
+
}) => /* @__PURE__ */ _t(
|
|
1176
|
+
qt,
|
|
1173
1177
|
{
|
|
1174
1178
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1175
1179
|
path: r,
|
|
@@ -1185,21 +1189,21 @@ function It(t, c, m, g) {
|
|
|
1185
1189
|
if (l === "update")
|
|
1186
1190
|
return (d, e) => {
|
|
1187
1191
|
if (e?.debounce)
|
|
1188
|
-
|
|
1189
|
-
|
|
1192
|
+
zt(() => {
|
|
1193
|
+
ct(c, d, r, "");
|
|
1190
1194
|
const n = o.getState().getNestedState(t, r);
|
|
1191
1195
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1192
1196
|
}, e.debounce);
|
|
1193
1197
|
else {
|
|
1194
|
-
|
|
1198
|
+
ct(c, d, r, "");
|
|
1195
1199
|
const n = o.getState().getNestedState(t, r);
|
|
1196
1200
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1197
1201
|
}
|
|
1198
1202
|
p(r);
|
|
1199
1203
|
};
|
|
1200
1204
|
if (l === "formElement")
|
|
1201
|
-
return (d, e) => /* @__PURE__ */
|
|
1202
|
-
|
|
1205
|
+
return (d, e) => /* @__PURE__ */ _t(
|
|
1206
|
+
Jt,
|
|
1203
1207
|
{
|
|
1204
1208
|
setState: c,
|
|
1205
1209
|
stateKey: t,
|
|
@@ -1208,10 +1212,10 @@ function It(t, c, m, g) {
|
|
|
1208
1212
|
formOpts: e
|
|
1209
1213
|
}
|
|
1210
1214
|
);
|
|
1211
|
-
const
|
|
1212
|
-
return s(at,
|
|
1215
|
+
const R = [...r, l], at = o.getState().getNestedState(t, R);
|
|
1216
|
+
return s(at, R, S);
|
|
1213
1217
|
}
|
|
1214
|
-
}, z = new Proxy(
|
|
1218
|
+
}, z = new Proxy(j, U);
|
|
1215
1219
|
return I.set(W, {
|
|
1216
1220
|
proxy: z,
|
|
1217
1221
|
stateVersion: N
|
|
@@ -1221,10 +1225,10 @@ function It(t, c, m, g) {
|
|
|
1221
1225
|
o.getState().getNestedState(t, [])
|
|
1222
1226
|
);
|
|
1223
1227
|
}
|
|
1224
|
-
function
|
|
1225
|
-
return
|
|
1228
|
+
function Gt(t) {
|
|
1229
|
+
return dt(ae, { proxy: t });
|
|
1226
1230
|
}
|
|
1227
|
-
function
|
|
1231
|
+
function oe({
|
|
1228
1232
|
proxy: t,
|
|
1229
1233
|
rebuildStateShape: c
|
|
1230
1234
|
}) {
|
|
@@ -1236,7 +1240,7 @@ function re({
|
|
|
1236
1240
|
(I, N, p, v, s) => t._mapFn(I, N, p, v, s)
|
|
1237
1241
|
) : null;
|
|
1238
1242
|
}
|
|
1239
|
-
function
|
|
1243
|
+
function ae({
|
|
1240
1244
|
proxy: t
|
|
1241
1245
|
}) {
|
|
1242
1246
|
const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
@@ -1261,22 +1265,22 @@ function oe({
|
|
|
1261
1265
|
"state",
|
|
1262
1266
|
`return (${t._effect})(state)`
|
|
1263
1267
|
)(r);
|
|
1264
|
-
} catch (
|
|
1265
|
-
console.error("Error evaluating effect function during mount:",
|
|
1268
|
+
} catch (j) {
|
|
1269
|
+
console.error("Error evaluating effect function during mount:", j), S = r;
|
|
1266
1270
|
}
|
|
1267
1271
|
else
|
|
1268
1272
|
S = r;
|
|
1269
1273
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1270
1274
|
const W = document.createTextNode(String(S));
|
|
1271
1275
|
g.replaceWith(W);
|
|
1272
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1276
|
+
}, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
|
|
1273
1277
|
ref: c,
|
|
1274
1278
|
style: { display: "none" },
|
|
1275
1279
|
"data-signal-id": m
|
|
1276
1280
|
});
|
|
1277
1281
|
}
|
|
1278
1282
|
function pe(t) {
|
|
1279
|
-
const c =
|
|
1283
|
+
const c = Bt(
|
|
1280
1284
|
(m) => {
|
|
1281
1285
|
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1282
1286
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1288,22 +1292,22 @@ function pe(t) {
|
|
|
1288
1292
|
},
|
|
1289
1293
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1290
1294
|
);
|
|
1291
|
-
return
|
|
1295
|
+
return dt("text", {}, String(c));
|
|
1292
1296
|
}
|
|
1293
|
-
function
|
|
1297
|
+
function se({
|
|
1294
1298
|
stateKey: t,
|
|
1295
1299
|
itemComponentId: c,
|
|
1296
1300
|
itemPath: m,
|
|
1297
1301
|
children: g
|
|
1298
1302
|
}) {
|
|
1299
|
-
const [, I] = K({}), [N, p] =
|
|
1303
|
+
const [, I] = K({}), [N, p] = Xt(), v = q(null);
|
|
1300
1304
|
return ot(() => {
|
|
1301
1305
|
p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1302
1306
|
virtualizer: {
|
|
1303
1307
|
itemHeight: p.height
|
|
1304
1308
|
}
|
|
1305
1309
|
}));
|
|
1306
|
-
}, [p.height, t, m]),
|
|
1310
|
+
}, [p.height, t, m]), lt(() => {
|
|
1307
1311
|
const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
|
|
1308
1312
|
components: /* @__PURE__ */ new Map()
|
|
1309
1313
|
};
|
|
@@ -1314,14 +1318,14 @@ function ae({
|
|
|
1314
1318
|
const r = o.getState().stateComponents.get(t);
|
|
1315
1319
|
r && r.components.delete(s);
|
|
1316
1320
|
};
|
|
1317
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */
|
|
1321
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ _t("div", { ref: N, children: g });
|
|
1318
1322
|
}
|
|
1319
1323
|
export {
|
|
1320
|
-
|
|
1324
|
+
Gt as $cogsSignal,
|
|
1321
1325
|
pe as $cogsSignalStore,
|
|
1322
1326
|
Ie as addStateOptions,
|
|
1323
1327
|
ve as createCogsState,
|
|
1324
1328
|
ye as notifyComponent,
|
|
1325
|
-
|
|
1329
|
+
re as useCogsStateFn
|
|
1326
1330
|
};
|
|
1327
1331
|
//# sourceMappingURL=CogsState.jsx.map
|