cogsbox-state 0.5.378 → 0.5.380
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 +276 -277
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +21 -13
package/dist/CogsState.jsx
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as Ot } from "react/jsx-runtime";
|
|
3
|
-
import { useState as K, useRef as J, useEffect as st, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as jt, isDeepEqual as q, isFunction as tt, getNestedValue as Z, getDifferences as
|
|
5
|
-
import { pushFunc as
|
|
3
|
+
import { useState as K, useRef as J, useEffect as st, useLayoutEffect as ut, useMemo as _t, createElement as gt, useSyncExternalStore as Dt, startTransition as Ut, useCallback as bt } from "react";
|
|
4
|
+
import { transformStateFunc as jt, isDeepEqual as q, isFunction as tt, getNestedValue as Z, getDifferences as Nt, debounce as Ht } from "./utility.js";
|
|
5
|
+
import { pushFunc as At, updateFn as dt, cutFunc as Tt, ValidationWrapper as Ft, FormControlComponent as Bt } from "./Functions.jsx";
|
|
6
6
|
import Wt from "superjson";
|
|
7
|
-
import { v4 as
|
|
7
|
+
import { v4 as Ct } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
9
|
+
import { getGlobalStore as o, formRefStore as kt } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Gt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as zt } from "fast-json-patch";
|
|
12
12
|
import qt from "react-use-measure";
|
|
13
|
-
function
|
|
13
|
+
function xt(t, i) {
|
|
14
14
|
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, v = m(t) || {};
|
|
15
15
|
g(t, {
|
|
16
16
|
...v,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Mt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = at(t) || {}, v = m[t] || {},
|
|
25
|
+
const g = at(t) || {}, v = m[t] || {}, _ = o.getState().setInitialStateOptions, w = { ...v, ...g };
|
|
26
26
|
let y = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const s in i)
|
|
29
|
-
|
|
30
|
-
!q(
|
|
31
|
-
y &&
|
|
29
|
+
w.hasOwnProperty(s) ? (s == "localStorage" && i[s] && w[s].key !== i[s]?.key && (y = !0, w[s] = i[s]), s == "initialState" && i[s] && w[s] !== i[s] && // Different references
|
|
30
|
+
!q(w[s], i[s]) && (y = !0, w[s] = i[s])) : (y = !0, w[s] = i[s]);
|
|
31
|
+
y && _(t, w);
|
|
32
32
|
}
|
|
33
33
|
function me(t, { formElements: i, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: i, validation: m };
|
|
@@ -45,14 +45,14 @@ const he = (t, i) => {
|
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, at(y) || o.getState().setInitialStateOptions(y, v[y]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
|
-
const
|
|
49
|
-
const [I] = K(s?.componentId ??
|
|
50
|
-
|
|
48
|
+
const _ = (y, s) => {
|
|
49
|
+
const [I] = K(s?.componentId ?? Ct());
|
|
50
|
+
Mt({
|
|
51
51
|
stateKey: y,
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: v
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[y] || g[y], S = s?.modifyState ? s.modifyState(n) : n, [F,
|
|
55
|
+
const n = o.getState().cogsStateStore[y] || g[y], S = s?.modifyState ? s.modifyState(n) : n, [F, L] = te(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: y,
|
|
@@ -68,36 +68,36 @@ const he = (t, i) => {
|
|
|
68
68
|
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return L;
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function w(y, s) {
|
|
74
|
+
Mt({ stateKey: y, options: s, initialOptionsPart: v }), s.localStorage && Qt(y, s), wt(y);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: _, setCogsOptions: w };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
78
|
+
setUpdaterState: vt,
|
|
79
79
|
setState: rt,
|
|
80
80
|
getInitialOptions: at,
|
|
81
|
-
getKeyState:
|
|
81
|
+
getKeyState: Lt,
|
|
82
82
|
getValidationErrors: Jt,
|
|
83
83
|
setStateLog: Yt,
|
|
84
|
-
updateInitialStateGlobal:
|
|
84
|
+
updateInitialStateGlobal: $t,
|
|
85
85
|
addValidationError: Zt,
|
|
86
86
|
removeValidationError: Q,
|
|
87
87
|
setServerSyncActions: Xt
|
|
88
|
-
} = o.getState(),
|
|
88
|
+
} = o.getState(), Pt = (t, i, m, g, v) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
i,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
95
|
+
const _ = tt(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
|
+
if (_ && g) {
|
|
97
|
+
const w = `${g}-${i}-${_}`;
|
|
98
98
|
let y;
|
|
99
99
|
try {
|
|
100
|
-
y =
|
|
100
|
+
y = pt(w)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const s = {
|
|
@@ -106,11 +106,11 @@ const he = (t, i) => {
|
|
|
106
106
|
lastSyncedWithServer: v ?? y
|
|
107
107
|
}, I = Wt.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
|
-
|
|
109
|
+
w,
|
|
110
110
|
JSON.stringify(I.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, pt = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
116
|
const i = window.localStorage.getItem(t);
|
|
@@ -119,28 +119,28 @@ const he = (t, i) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
121
|
}, Qt = (t, i) => {
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: g } =
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = Gt(), v = tt(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (v && g) {
|
|
124
|
-
const
|
|
124
|
+
const _ = pt(
|
|
125
125
|
`${g}-${t}-${v}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return rt(t,
|
|
127
|
+
if (_ && _.lastUpdated > (_.lastSyncedWithServer || 0))
|
|
128
|
+
return rt(t, _.state), wt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
132
|
-
const
|
|
131
|
+
}, Rt = (t, i, m, g, v, _) => {
|
|
132
|
+
const w = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: yt(
|
|
135
135
|
t,
|
|
136
136
|
g,
|
|
137
137
|
v,
|
|
138
|
-
|
|
138
|
+
_
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
$t(t, w.initialState), vt(t, w.updaterState), rt(t, w.state);
|
|
143
|
+
}, wt = (t) => {
|
|
144
144
|
const i = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!i) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -185,17 +185,17 @@ function te(t, {
|
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: v,
|
|
188
|
-
reactiveDeps:
|
|
189
|
-
reactiveType:
|
|
188
|
+
reactiveDeps: _,
|
|
189
|
+
reactiveType: w,
|
|
190
190
|
componentId: y,
|
|
191
191
|
initialState: s,
|
|
192
192
|
syncUpdate: I,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [F,
|
|
196
|
+
const [F, L] = K({}), { sessionId: R } = Gt();
|
|
197
197
|
let B = !i;
|
|
198
|
-
const [h] = K(i ??
|
|
198
|
+
const [h] = K(i ?? Ct()), l = o.getState().stateLog[h], ft = J(/* @__PURE__ */ new Set()), et = J(y ?? Ct()), P = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
201
|
P.current = at(h) ?? null, st(() => {
|
|
@@ -212,33 +212,33 @@ function te(t, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [I]), st(() => {
|
|
214
214
|
if (s) {
|
|
215
|
-
|
|
215
|
+
xt(h, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
218
|
const e = P.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[h];
|
|
219
219
|
if (!(c && !q(c, s) || !c) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let p = s,
|
|
225
|
-
const
|
|
226
|
-
a &&
|
|
222
|
+
const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
|
+
E && R && (u = pt(`${R}-${h}-${E}`));
|
|
224
|
+
let p = s, A = !1;
|
|
225
|
+
const C = a ? Date.now() : 0, O = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
|
|
226
|
+
a && C > O ? (p = e.serverState.data, A = !0) : u && O > x && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), o.getState().initializeShadowState(h, s), Rt(
|
|
227
227
|
h,
|
|
228
228
|
s,
|
|
229
229
|
p,
|
|
230
230
|
it,
|
|
231
231
|
et.current,
|
|
232
|
-
|
|
233
|
-
),
|
|
232
|
+
R
|
|
233
|
+
), A && E && R && Pt(p, h, e, R, Date.now()), wt(h), (Array.isArray(w) ? w : [w || "component"]).includes("none") || L({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
B &&
|
|
240
|
+
]), ut(() => {
|
|
241
|
+
B && xt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: v,
|
|
244
244
|
initialState: s,
|
|
@@ -249,43 +249,43 @@ function te(t, {
|
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => L({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
256
|
-
reactiveType:
|
|
257
|
-
}), o.getState().stateComponents.set(h, r),
|
|
255
|
+
depsFunction: _ || void 0,
|
|
256
|
+
reactiveType: w ?? ["component", "deps"]
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), L({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const it = (e, r, a, c) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
263
|
const u = `${h}-${r.join(".")}`;
|
|
264
|
-
|
|
264
|
+
ft.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = o.getState();
|
|
267
267
|
rt(h, (u) => {
|
|
268
|
-
const
|
|
268
|
+
const E = tt(e) ? e(u) : e, p = `${h}-${r.join(".")}`;
|
|
269
269
|
if (p) {
|
|
270
270
|
let M = !1, N = f.signalDomElements.get(p);
|
|
271
271
|
if ((!N || N.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const
|
|
272
|
+
const G = r.slice(0, -1), D = Z(E, G);
|
|
273
273
|
if (Array.isArray(D)) {
|
|
274
274
|
M = !0;
|
|
275
|
-
const T = `${h}-${
|
|
275
|
+
const T = `${h}-${G.join(".")}`;
|
|
276
276
|
N = f.signalDomElements.get(T);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if (N) {
|
|
280
|
-
const
|
|
280
|
+
const G = M ? Z(E, r.slice(0, -1)) : Z(E, r);
|
|
281
281
|
N.forEach(({ parentId: D, position: T, effect: U }) => {
|
|
282
|
-
const
|
|
282
|
+
const $ = document.querySelector(
|
|
283
283
|
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const z = Array.from(
|
|
285
|
+
if ($) {
|
|
286
|
+
const z = Array.from($.childNodes);
|
|
287
287
|
if (z[T]) {
|
|
288
|
-
const j = U ? new Function("state", `return (${U})(state)`)(
|
|
288
|
+
const j = U ? new Function("state", `return (${U})(state)`)(G) : G;
|
|
289
289
|
z[T].textContent = String(j);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
@@ -295,33 +295,33 @@ function te(t, {
|
|
|
295
295
|
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c || P.current?.validation?.key) && r && Q(
|
|
296
296
|
(c || P.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
298
|
+
const A = r.slice(0, r.length - 1);
|
|
299
299
|
a.updateType === "cut" && P.current?.validation?.key && Q(
|
|
300
|
-
P.current?.validation?.key + "." +
|
|
300
|
+
P.current?.validation?.key + "." + A.join(".")
|
|
301
301
|
), a.updateType === "insert" && P.current?.validation?.key && Jt(
|
|
302
|
-
P.current?.validation?.key + "." +
|
|
303
|
-
).filter(([N,
|
|
302
|
+
P.current?.validation?.key + "." + A.join(".")
|
|
303
|
+
).filter(([N, G]) => {
|
|
304
304
|
let D = N?.split(".").length;
|
|
305
|
-
if (N ==
|
|
306
|
-
let T = N + "." +
|
|
307
|
-
Q(N), Zt(T,
|
|
305
|
+
if (N == A.join(".") && D == A.length - 1) {
|
|
306
|
+
let T = N + "." + A;
|
|
307
|
+
Q(N), Zt(T, G);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const M =
|
|
310
|
+
const C = f.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
+
const M = Nt(u, E), N = new Set(M), G = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
D,
|
|
315
315
|
T
|
|
316
|
-
] of
|
|
316
|
+
] of C.components.entries()) {
|
|
317
317
|
let U = !1;
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", T),
|
|
320
|
-
if (
|
|
318
|
+
const $ = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", T), !$.includes("none")) {
|
|
320
|
+
if ($.includes("all")) {
|
|
321
321
|
T.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
324
|
+
if ($.includes("component") && ((T.paths.has(G) || T.paths.has("")) && (U = !0), !U))
|
|
325
325
|
for (const z of N) {
|
|
326
326
|
let j = z;
|
|
327
327
|
for (; ; ) {
|
|
@@ -331,17 +331,17 @@ function te(t, {
|
|
|
331
331
|
}
|
|
332
332
|
const ct = j.lastIndexOf(".");
|
|
333
333
|
if (ct !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const St = j.substring(
|
|
335
335
|
0,
|
|
336
336
|
ct
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
339
|
Number(j.substring(ct + 1))
|
|
340
|
-
) && T.paths.has(
|
|
340
|
+
) && T.paths.has(St)) {
|
|
341
341
|
U = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
j =
|
|
344
|
+
j = St;
|
|
345
345
|
} else
|
|
346
346
|
j = "";
|
|
347
347
|
if (j === "")
|
|
@@ -349,8 +349,8 @@ function te(t, {
|
|
|
349
349
|
}
|
|
350
350
|
if (U) break;
|
|
351
351
|
}
|
|
352
|
-
if (!U &&
|
|
353
|
-
const z = T.depsFunction(
|
|
352
|
+
if (!U && $.includes("deps") && T.depsFunction) {
|
|
353
|
+
const z = T.depsFunction(E);
|
|
354
354
|
let j = !1;
|
|
355
355
|
typeof z == "boolean" ? z && (j = !0) : q(T.deps, z) || (T.deps = z, j = !0), j && (U = !0);
|
|
356
356
|
}
|
|
@@ -358,89 +358,89 @@ function te(t, {
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
361
|
+
const O = Date.now();
|
|
362
362
|
r = r.map((M, N) => {
|
|
363
|
-
const
|
|
363
|
+
const G = r.slice(0, -1), D = Z(E, G);
|
|
364
364
|
return N === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (D.length - 1).toString() : M;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: x, newValue:
|
|
366
|
+
const { oldValue: x, newValue: V } = Kt(
|
|
367
367
|
a.updateType,
|
|
368
368
|
u,
|
|
369
|
-
|
|
369
|
+
E,
|
|
370
370
|
r
|
|
371
371
|
), Y = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: O,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: a.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: x,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: V
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
f.updateShadowAtPath(h, r,
|
|
382
|
+
f.updateShadowAtPath(h, r, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const M = r.slice(0, -1);
|
|
386
|
-
f.insertShadowArrayElement(h, M,
|
|
386
|
+
f.insertShadowArrayElement(h, M, V);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const N = r.slice(0, -1),
|
|
390
|
-
f.removeShadowArrayElement(h, N,
|
|
389
|
+
const N = r.slice(0, -1), G = parseInt(r[r.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(h, N, G);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
if (Yt(h, (M) => {
|
|
394
|
-
const
|
|
395
|
-
const U = `${T.stateKey}:${JSON.stringify(T.path)}`,
|
|
396
|
-
return
|
|
394
|
+
const G = [...M ?? [], Y].reduce((D, T) => {
|
|
395
|
+
const U = `${T.stateKey}:${JSON.stringify(T.path)}`, $ = D.get(U);
|
|
396
|
+
return $ ? ($.timeStamp = Math.max($.timeStamp, T.timeStamp), $.newValue = T.newValue, $.oldValue = $.oldValue ?? T.oldValue, $.updateType = T.updateType) : D.set(U, { ...T }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
400
|
-
|
|
398
|
+
return Array.from(G.values());
|
|
399
|
+
}), Pt(
|
|
400
|
+
E,
|
|
401
401
|
h,
|
|
402
402
|
P.current,
|
|
403
|
-
|
|
403
|
+
R
|
|
404
404
|
), P.current?.middleware && P.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
407
|
}), P.current?.serverSync) {
|
|
408
408
|
const M = f.serverState[h], N = P.current?.serverSync;
|
|
409
409
|
Xt(h, {
|
|
410
|
-
syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state:
|
|
410
|
+
syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
412
|
actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[h] || (
|
|
419
|
+
o.getState().updaterState[h] || (vt(
|
|
420
420
|
h,
|
|
421
|
-
|
|
421
|
+
yt(
|
|
422
422
|
h,
|
|
423
423
|
it,
|
|
424
424
|
et.current,
|
|
425
|
-
|
|
425
|
+
R
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] || rt(h, t), o.getState().initialStateGlobal[h] ||
|
|
428
|
-
const d = _t(() =>
|
|
427
|
+
), o.getState().cogsStateStore[h] || rt(h, t), o.getState().initialStateGlobal[h] || $t(h, t));
|
|
428
|
+
const d = _t(() => yt(
|
|
429
429
|
h,
|
|
430
430
|
it,
|
|
431
431
|
et.current,
|
|
432
|
-
|
|
433
|
-
), [h,
|
|
434
|
-
return [
|
|
432
|
+
R
|
|
433
|
+
), [h, R]);
|
|
434
|
+
return [Lt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function yt(t, i, m, g) {
|
|
437
437
|
const v = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
439
|
-
const
|
|
438
|
+
let _ = 0;
|
|
439
|
+
const w = (I) => {
|
|
440
440
|
const n = I.join(".");
|
|
441
441
|
for (const [S] of v)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && v.delete(S);
|
|
443
|
-
|
|
443
|
+
_++;
|
|
444
444
|
}, y = {
|
|
445
445
|
removeValidation: (I) => {
|
|
446
446
|
I?.validationKey && Q(I.validationKey);
|
|
@@ -449,24 +449,24 @@ function vt(t, i, m, g) {
|
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && Q(n?.key), I?.validationKey && Q(I.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), v.clear(),
|
|
453
|
-
const F = s(S, []),
|
|
454
|
-
B && localStorage.removeItem(B),
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), v.clear(), _++;
|
|
453
|
+
const F = s(S, []), L = at(t), R = tt(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, B = `${g}-${t}-${R}`;
|
|
454
|
+
B && localStorage.removeItem(B), vt(t, F), rt(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: (I) => {
|
|
461
|
-
v.clear(),
|
|
462
|
-
const n =
|
|
461
|
+
v.clear(), _++;
|
|
462
|
+
const n = yt(
|
|
463
463
|
t,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = o.getState().initialStateGlobal[t], F = at(t),
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], F = at(t), L = tt(F?.localStorage?.key) ? F?.localStorage?.key(S) : F?.localStorage?.key, R = `${g}-${t}-${L}`;
|
|
468
|
+
return localStorage.getItem(R) && localStorage.removeItem(R), Ut(() => {
|
|
469
|
+
$t(t, I), o.getState().initializeShadowState(t, I), vt(t, n), rt(t, I);
|
|
470
470
|
const B = o.getState().stateComponents.get(t);
|
|
471
471
|
B && B.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
@@ -480,27 +480,27 @@ function vt(t, i, m, g) {
|
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const I = o.getState().serverState[t];
|
|
483
|
-
return !!(I && q(I,
|
|
483
|
+
return !!(I && q(I, Lt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function s(I, n = [], S) {
|
|
487
487
|
const F = n.map(String).join(".");
|
|
488
488
|
v.get(F);
|
|
489
|
-
const
|
|
489
|
+
const L = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(y).forEach((h) => {
|
|
493
|
-
|
|
493
|
+
L[h] = y[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(h, l,
|
|
495
|
+
const R = {
|
|
496
|
+
apply(h, l, ft) {
|
|
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(I) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const ft = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function vt(t, i, 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" && !ft.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);
|
|
@@ -540,7 +540,7 @@ function vt(t, i, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => Nt(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -554,8 +554,8 @@ function vt(t, i, m, g) {
|
|
|
554
554
|
const c = await e.action(r);
|
|
555
555
|
if (c && !c.success && c.errors && a) {
|
|
556
556
|
o.getState().removeValidationError(a), c.errors.forEach((u) => {
|
|
557
|
-
const
|
|
558
|
-
o.getState().addValidationError(
|
|
557
|
+
const E = [a, ...u.path].join(".");
|
|
558
|
+
o.getState().addValidationError(E, u.message);
|
|
559
559
|
});
|
|
560
560
|
const f = o.getState().stateComponents.get(t);
|
|
561
561
|
f && f.components.forEach((u) => {
|
|
@@ -622,17 +622,17 @@ function vt(t, i, m, g) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = e, u = J(!1),
|
|
625
|
+
} = e, u = J(!1), E = J(null), [p, A] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
628
|
+
}), [C, O] = K("IDLE_AT_TOP"), x = J(!1), V = J(0), Y = J(f), M = J(0), [N, G] = K(0);
|
|
629
629
|
st(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
|
-
|
|
630
|
+
G((k) => k + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const D = o().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
n
|
|
635
|
-
), T = D.length, { totalHeight: U, positions:
|
|
635
|
+
), T = D.length, { totalHeight: U, positions: $ } = _t(() => {
|
|
636
636
|
const b = o.getState().getShadowMetadata(t, n) || [];
|
|
637
637
|
let k = 0;
|
|
638
638
|
const W = [];
|
|
@@ -658,29 +658,29 @@ function vt(t, i, m, g) {
|
|
|
658
658
|
validIndices: W
|
|
659
659
|
});
|
|
660
660
|
}, [p.startIndex, p.endIndex, D, T]);
|
|
661
|
-
|
|
661
|
+
ut(() => {
|
|
662
662
|
const b = !q(
|
|
663
663
|
f,
|
|
664
664
|
Y.current
|
|
665
|
-
), k = T >
|
|
665
|
+
), k = T > V.current;
|
|
666
666
|
if (b) {
|
|
667
|
-
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"),
|
|
667
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), O("IDLE_AT_TOP");
|
|
668
668
|
return;
|
|
669
669
|
}
|
|
670
|
-
k &&
|
|
670
|
+
k && C === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
671
671
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
672
|
-
),
|
|
673
|
-
}, [T, ...f]),
|
|
674
|
-
const b =
|
|
672
|
+
), O("GETTING_HEIGHTS")), Y.current = f;
|
|
673
|
+
}, [T, ...f]), ut(() => {
|
|
674
|
+
const b = E.current;
|
|
675
675
|
if (b) {
|
|
676
|
-
if (
|
|
676
|
+
if (C === "IDLE_AT_TOP" && c && T > 0)
|
|
677
677
|
console.log(
|
|
678
678
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
679
|
-
),
|
|
680
|
-
else if (
|
|
679
|
+
), O("GETTING_HEIGHTS");
|
|
680
|
+
else if (C === "GETTING_HEIGHTS") {
|
|
681
681
|
console.log(
|
|
682
682
|
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
683
|
-
),
|
|
683
|
+
), A({
|
|
684
684
|
startIndex: Math.max(0, T - 10 - a),
|
|
685
685
|
endIndex: T
|
|
686
686
|
});
|
|
@@ -688,26 +688,25 @@ function vt(t, i, m, g) {
|
|
|
688
688
|
return k = setInterval(() => {
|
|
689
689
|
const W = T - 1;
|
|
690
690
|
if (((o.getState().getShadowMetadata(t, n) || [])[W]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(k), !u.current)) {
|
|
691
|
-
const X =
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
b.scrollBy({
|
|
695
|
-
top:
|
|
691
|
+
const X = V.current, ot = T - X;
|
|
692
|
+
ot > 0 && ot <= 3 ? requestAnimationFrame(() => {
|
|
693
|
+
const mt = $[X] ?? b.scrollHeight, ht = b.scrollHeight - mt;
|
|
694
|
+
ht > 0 && b.scrollBy({
|
|
695
|
+
top: ht,
|
|
696
696
|
behavior: "smooth"
|
|
697
|
-
}), console.log(
|
|
697
|
+
}), V.current = T, console.log(
|
|
698
698
|
"ACTION (GETTING_HEIGHTS): Small addition -> LOCKED_AT_BOTTOM"
|
|
699
|
-
),
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
), _("SCROLLING_TO_BOTTOM");
|
|
699
|
+
), O("LOCKED_AT_BOTTOM");
|
|
700
|
+
}) : (console.log(
|
|
701
|
+
"ACTION (GETTING_HEIGHTS): Large change -> SCROLLING_TO_BOTTOM"
|
|
702
|
+
), O("SCROLLING_TO_BOTTOM"));
|
|
704
703
|
}
|
|
705
|
-
},
|
|
706
|
-
} else if (
|
|
704
|
+
}, 50), () => clearInterval(k);
|
|
705
|
+
} else if (C === "SCROLLING_TO_BOTTOM") {
|
|
707
706
|
console.log(
|
|
708
707
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
709
708
|
), x.current = !0;
|
|
710
|
-
const k =
|
|
709
|
+
const k = V.current === 0 ? "auto" : "smooth";
|
|
711
710
|
b.scrollTo({
|
|
712
711
|
top: b.scrollHeight,
|
|
713
712
|
behavior: k
|
|
@@ -716,7 +715,7 @@ function vt(t, i, m, g) {
|
|
|
716
715
|
() => {
|
|
717
716
|
console.log(
|
|
718
717
|
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
719
|
-
), x.current = !1, u.current = !1,
|
|
718
|
+
), x.current = !1, u.current = !1, O("LOCKED_AT_BOTTOM"), V.current = T;
|
|
720
719
|
},
|
|
721
720
|
k === "smooth" ? 500 : 50
|
|
722
721
|
);
|
|
@@ -725,8 +724,8 @@ function vt(t, i, m, g) {
|
|
|
725
724
|
return () => {
|
|
726
725
|
};
|
|
727
726
|
}
|
|
728
|
-
}, [
|
|
729
|
-
const b =
|
|
727
|
+
}, [C, T, $]), st(() => {
|
|
728
|
+
const b = E.current;
|
|
730
729
|
if (!b) return;
|
|
731
730
|
const k = r, W = () => {
|
|
732
731
|
if (x.current)
|
|
@@ -740,38 +739,38 @@ function vt(t, i, m, g) {
|
|
|
740
739
|
const { clientHeight: nt } = b;
|
|
741
740
|
let X = T - 1, ot = 0, Et = 0;
|
|
742
741
|
for (; ot <= X; ) {
|
|
743
|
-
const
|
|
744
|
-
|
|
742
|
+
const It = Math.floor((ot + X) / 2);
|
|
743
|
+
$[It] < H ? (Et = It, ot = It + 1) : X = It - 1;
|
|
745
744
|
}
|
|
746
|
-
const
|
|
747
|
-
let
|
|
748
|
-
const
|
|
749
|
-
for (;
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
startIndex:
|
|
753
|
-
endIndex: Math.min(T,
|
|
745
|
+
const mt = Math.max(0, Et - a);
|
|
746
|
+
let lt = mt;
|
|
747
|
+
const ht = H + nt;
|
|
748
|
+
for (; lt < T && $[lt] < ht; )
|
|
749
|
+
lt++;
|
|
750
|
+
A({
|
|
751
|
+
startIndex: mt,
|
|
752
|
+
endIndex: Math.min(T, lt + a)
|
|
754
753
|
}), M.current = H;
|
|
755
754
|
};
|
|
756
755
|
return b.addEventListener("scroll", W, {
|
|
757
756
|
passive: !0
|
|
758
757
|
}), () => b.removeEventListener("scroll", W);
|
|
759
|
-
}, [T,
|
|
760
|
-
const j =
|
|
758
|
+
}, [T, $, r, a, C]);
|
|
759
|
+
const j = bt(() => {
|
|
761
760
|
console.log(
|
|
762
761
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
763
|
-
),
|
|
764
|
-
}, []), ct =
|
|
762
|
+
), O("SCROLLING_TO_BOTTOM");
|
|
763
|
+
}, []), ct = bt(
|
|
765
764
|
(b, k = "smooth") => {
|
|
766
|
-
|
|
767
|
-
top:
|
|
765
|
+
E.current && $[b] !== void 0 && (O("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
766
|
+
top: $[b],
|
|
768
767
|
behavior: k
|
|
769
768
|
}));
|
|
770
769
|
},
|
|
771
|
-
[
|
|
772
|
-
),
|
|
770
|
+
[$]
|
|
771
|
+
), St = {
|
|
773
772
|
outer: {
|
|
774
|
-
ref:
|
|
773
|
+
ref: E,
|
|
775
774
|
style: { overflowY: "auto", height: "100%" }
|
|
776
775
|
},
|
|
777
776
|
inner: {
|
|
@@ -782,13 +781,13 @@ function vt(t, i, m, g) {
|
|
|
782
781
|
},
|
|
783
782
|
list: {
|
|
784
783
|
style: {
|
|
785
|
-
transform: `translateY(${
|
|
784
|
+
transform: `translateY(${$[p.startIndex] || 0}px)`
|
|
786
785
|
}
|
|
787
786
|
}
|
|
788
787
|
};
|
|
789
788
|
return {
|
|
790
789
|
virtualState: z,
|
|
791
|
-
virtualizerProps:
|
|
790
|
+
virtualizerProps: St,
|
|
792
791
|
scrollToBottom: j,
|
|
793
792
|
scrollToIndex: ct
|
|
794
793
|
};
|
|
@@ -796,7 +795,7 @@ function vt(t, i, m, g) {
|
|
|
796
795
|
if (l === "stateSort")
|
|
797
796
|
return (e) => {
|
|
798
797
|
const a = [...d()].sort(
|
|
799
|
-
(u,
|
|
798
|
+
(u, E) => e(u.item, E.item)
|
|
800
799
|
), c = a.map(({ item: u }) => u), f = {
|
|
801
800
|
...S,
|
|
802
801
|
validIndices: a.map(
|
|
@@ -808,7 +807,7 @@ function vt(t, i, m, g) {
|
|
|
808
807
|
if (l === "stateFilter")
|
|
809
808
|
return (e) => {
|
|
810
809
|
const a = d().filter(
|
|
811
|
-
({ item: u },
|
|
810
|
+
({ item: u }, E) => e(u, E)
|
|
812
811
|
), c = a.map(({ item: u }) => u), f = {
|
|
813
812
|
...S,
|
|
814
813
|
validIndices: a.map(
|
|
@@ -821,22 +820,22 @@ function vt(t, i, m, g) {
|
|
|
821
820
|
return (e) => {
|
|
822
821
|
const r = o.getState().getNestedState(t, n);
|
|
823
822
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
824
|
-
const u = r[c],
|
|
823
|
+
const u = r[c], E = [...n, c.toString()], p = s(u, E, S);
|
|
825
824
|
return e(u, p, {
|
|
826
825
|
register: () => {
|
|
827
|
-
const [,
|
|
828
|
-
|
|
829
|
-
const x = `${t}////${
|
|
826
|
+
const [, C] = K({}), O = `${m}-${n.join(".")}-${c}`;
|
|
827
|
+
ut(() => {
|
|
828
|
+
const x = `${t}////${O}`, V = o.getState().stateComponents.get(t) || {
|
|
830
829
|
components: /* @__PURE__ */ new Map()
|
|
831
830
|
};
|
|
832
|
-
return
|
|
833
|
-
forceUpdate: () =>
|
|
834
|
-
paths: /* @__PURE__ */ new Set([
|
|
835
|
-
}), o.getState().stateComponents.set(t,
|
|
831
|
+
return V.components.set(x, {
|
|
832
|
+
forceUpdate: () => C({}),
|
|
833
|
+
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
834
|
+
}), o.getState().stateComponents.set(t, V), () => {
|
|
836
835
|
const Y = o.getState().stateComponents.get(t);
|
|
837
836
|
Y && Y.components.delete(x);
|
|
838
837
|
};
|
|
839
|
-
}, [t,
|
|
838
|
+
}, [t, O]);
|
|
840
839
|
},
|
|
841
840
|
index: f,
|
|
842
841
|
originalIndex: c
|
|
@@ -850,17 +849,17 @@ function vt(t, i, m, g) {
|
|
|
850
849
|
return (e) => I.map((a, c) => {
|
|
851
850
|
let f;
|
|
852
851
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
853
|
-
const u = [...n, f.toString()],
|
|
852
|
+
const u = [...n, f.toString()], E = s(a, u, S);
|
|
854
853
|
return e(
|
|
855
854
|
a,
|
|
856
|
-
|
|
855
|
+
E,
|
|
857
856
|
c,
|
|
858
857
|
I,
|
|
859
858
|
s(I, n, S)
|
|
860
859
|
);
|
|
861
860
|
});
|
|
862
861
|
if (l === "$stateMap")
|
|
863
|
-
return (e) =>
|
|
862
|
+
return (e) => gt(ee, {
|
|
864
863
|
proxy: {
|
|
865
864
|
_stateKey: t,
|
|
866
865
|
_path: n,
|
|
@@ -873,12 +872,12 @@ function vt(t, i, m, g) {
|
|
|
873
872
|
return (e) => {
|
|
874
873
|
const r = o.getState().getNestedState(t, n);
|
|
875
874
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
876
|
-
const u = r[c],
|
|
877
|
-
return
|
|
875
|
+
const u = r[c], E = [...n, c.toString()], p = s(u, E, S), A = `${m}-${n.join(".")}-${c}`;
|
|
876
|
+
return gt(re, {
|
|
878
877
|
key: c,
|
|
879
878
|
stateKey: t,
|
|
880
|
-
itemComponentId:
|
|
881
|
-
itemPath:
|
|
879
|
+
itemComponentId: A,
|
|
880
|
+
itemPath: E,
|
|
882
881
|
children: e(
|
|
883
882
|
u,
|
|
884
883
|
p,
|
|
@@ -894,7 +893,7 @@ function vt(t, i, m, g) {
|
|
|
894
893
|
if (l === "stateFlattenOn")
|
|
895
894
|
return (e) => {
|
|
896
895
|
const r = I;
|
|
897
|
-
v.clear(),
|
|
896
|
+
v.clear(), _++;
|
|
898
897
|
const a = r.flatMap(
|
|
899
898
|
(c) => c[e] ?? []
|
|
900
899
|
);
|
|
@@ -917,7 +916,7 @@ function vt(t, i, m, g) {
|
|
|
917
916
|
return s(a, c);
|
|
918
917
|
};
|
|
919
918
|
if (l === "insert")
|
|
920
|
-
return (e) => (
|
|
919
|
+
return (e) => (w(n), At(i, e, n, t), s(
|
|
921
920
|
o.getState().getNestedState(t, n),
|
|
922
921
|
n
|
|
923
922
|
));
|
|
@@ -927,26 +926,26 @@ function vt(t, i, m, g) {
|
|
|
927
926
|
let u = null;
|
|
928
927
|
if (!c.some((p) => {
|
|
929
928
|
if (r) {
|
|
930
|
-
const
|
|
931
|
-
(
|
|
929
|
+
const C = r.every(
|
|
930
|
+
(O) => q(p[O], f[O])
|
|
932
931
|
);
|
|
933
|
-
return
|
|
932
|
+
return C && (u = p), C;
|
|
934
933
|
}
|
|
935
|
-
const
|
|
936
|
-
return
|
|
934
|
+
const A = q(p, f);
|
|
935
|
+
return A && (u = p), A;
|
|
937
936
|
}))
|
|
938
|
-
|
|
937
|
+
w(n), At(i, f, n, t);
|
|
939
938
|
else if (a && u) {
|
|
940
|
-
const p = a(u),
|
|
941
|
-
(
|
|
939
|
+
const p = a(u), A = c.map(
|
|
940
|
+
(C) => q(C, u) ? p : C
|
|
942
941
|
);
|
|
943
|
-
|
|
942
|
+
w(n), dt(i, A, n);
|
|
944
943
|
}
|
|
945
944
|
};
|
|
946
945
|
if (l === "cut")
|
|
947
946
|
return (e, r) => {
|
|
948
947
|
if (!r?.waitForSync)
|
|
949
|
-
return
|
|
948
|
+
return w(n), Tt(i, n, t, e), s(
|
|
950
949
|
o.getState().getNestedState(t, n),
|
|
951
950
|
n
|
|
952
951
|
);
|
|
@@ -954,12 +953,12 @@ function vt(t, i, m, g) {
|
|
|
954
953
|
if (l === "cutByValue")
|
|
955
954
|
return (e) => {
|
|
956
955
|
for (let r = 0; r < I.length; r++)
|
|
957
|
-
I[r] === e &&
|
|
956
|
+
I[r] === e && Tt(i, n, t, r);
|
|
958
957
|
};
|
|
959
958
|
if (l === "toggleByValue")
|
|
960
959
|
return (e) => {
|
|
961
960
|
const r = I.findIndex((a) => a === e);
|
|
962
|
-
r > -1 ?
|
|
961
|
+
r > -1 ? Tt(i, n, t, r) : At(i, e, n, t);
|
|
963
962
|
};
|
|
964
963
|
if (l === "stateFind")
|
|
965
964
|
return (e) => {
|
|
@@ -984,7 +983,7 @@ function vt(t, i, m, g) {
|
|
|
984
983
|
if (!isNaN(Number(et))) {
|
|
985
984
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
986
985
|
if (Array.isArray(e) && l === "cut")
|
|
987
|
-
return () =>
|
|
986
|
+
return () => Tt(
|
|
988
987
|
i,
|
|
989
988
|
d,
|
|
990
989
|
t,
|
|
@@ -1000,13 +999,13 @@ function vt(t, i, m, g) {
|
|
|
1000
999
|
return o.getState().getNestedState(t, n);
|
|
1001
1000
|
};
|
|
1002
1001
|
if (l === "$derive")
|
|
1003
|
-
return (d) =>
|
|
1002
|
+
return (d) => Vt({
|
|
1004
1003
|
_stateKey: t,
|
|
1005
1004
|
_path: n,
|
|
1006
1005
|
_effect: d.toString()
|
|
1007
1006
|
});
|
|
1008
1007
|
if (l === "$get")
|
|
1009
|
-
return () =>
|
|
1008
|
+
return () => Vt({
|
|
1010
1009
|
_stateKey: t,
|
|
1011
1010
|
_path: n
|
|
1012
1011
|
});
|
|
@@ -1015,7 +1014,7 @@ function vt(t, i, m, g) {
|
|
|
1015
1014
|
return o.getState().getSyncInfo(d);
|
|
1016
1015
|
}
|
|
1017
1016
|
if (l == "getLocalStorage")
|
|
1018
|
-
return (d) =>
|
|
1017
|
+
return (d) => pt(g + "-" + t + "-" + d);
|
|
1019
1018
|
if (l === "_selected") {
|
|
1020
1019
|
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
1021
1020
|
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -1025,7 +1024,7 @@ function vt(t, i, m, g) {
|
|
|
1025
1024
|
const e = n.slice(0, -1), r = Number(n[n.length - 1]), a = e.join(".");
|
|
1026
1025
|
d ? o.getState().setSelectedIndex(t, a, r) : o.getState().setSelectedIndex(t, a, void 0);
|
|
1027
1026
|
const c = o.getState().getNestedState(t, [...e]);
|
|
1028
|
-
|
|
1027
|
+
dt(i, c, e), w(e);
|
|
1029
1028
|
};
|
|
1030
1029
|
if (l === "toggleSelected")
|
|
1031
1030
|
return () => {
|
|
@@ -1036,13 +1035,13 @@ function vt(t, i, m, g) {
|
|
|
1036
1035
|
a === e ? void 0 : e
|
|
1037
1036
|
);
|
|
1038
1037
|
const c = o.getState().getNestedState(t, [...d]);
|
|
1039
|
-
|
|
1038
|
+
dt(i, c, d), w(d);
|
|
1040
1039
|
};
|
|
1041
1040
|
if (n.length == 0) {
|
|
1042
1041
|
if (l === "applyJsonPatch")
|
|
1043
1042
|
return (d) => {
|
|
1044
1043
|
const e = o.getState().cogsStateStore[t], a = zt(e, d).newDocument;
|
|
1045
|
-
|
|
1044
|
+
Rt(
|
|
1046
1045
|
t,
|
|
1047
1046
|
o.getState().initialStateGlobal[t],
|
|
1048
1047
|
a,
|
|
@@ -1052,57 +1051,57 @@ function vt(t, i, m, g) {
|
|
|
1052
1051
|
);
|
|
1053
1052
|
const c = o.getState().stateComponents.get(t);
|
|
1054
1053
|
if (c) {
|
|
1055
|
-
const f =
|
|
1054
|
+
const f = Nt(e, a), u = new Set(f);
|
|
1056
1055
|
for (const [
|
|
1057
|
-
|
|
1056
|
+
E,
|
|
1058
1057
|
p
|
|
1059
1058
|
] of c.components.entries()) {
|
|
1060
|
-
let
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1063
|
-
if (
|
|
1059
|
+
let A = !1;
|
|
1060
|
+
const C = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
|
|
1061
|
+
if (!C.includes("none")) {
|
|
1062
|
+
if (C.includes("all")) {
|
|
1064
1063
|
p.forceUpdate();
|
|
1065
1064
|
continue;
|
|
1066
1065
|
}
|
|
1067
|
-
if (
|
|
1068
|
-
for (const
|
|
1069
|
-
if (p.paths.has(
|
|
1070
|
-
|
|
1066
|
+
if (C.includes("component") && (p.paths.has("") && (A = !0), !A))
|
|
1067
|
+
for (const O of u) {
|
|
1068
|
+
if (p.paths.has(O)) {
|
|
1069
|
+
A = !0;
|
|
1071
1070
|
break;
|
|
1072
1071
|
}
|
|
1073
|
-
let x =
|
|
1072
|
+
let x = O.lastIndexOf(".");
|
|
1074
1073
|
for (; x !== -1; ) {
|
|
1075
|
-
const
|
|
1076
|
-
if (p.paths.has(
|
|
1077
|
-
|
|
1074
|
+
const V = O.substring(0, x);
|
|
1075
|
+
if (p.paths.has(V)) {
|
|
1076
|
+
A = !0;
|
|
1078
1077
|
break;
|
|
1079
1078
|
}
|
|
1080
|
-
const Y =
|
|
1079
|
+
const Y = O.substring(
|
|
1081
1080
|
x + 1
|
|
1082
1081
|
);
|
|
1083
1082
|
if (!isNaN(Number(Y))) {
|
|
1084
|
-
const M =
|
|
1083
|
+
const M = V.lastIndexOf(".");
|
|
1085
1084
|
if (M !== -1) {
|
|
1086
|
-
const N =
|
|
1085
|
+
const N = V.substring(
|
|
1087
1086
|
0,
|
|
1088
1087
|
M
|
|
1089
1088
|
);
|
|
1090
1089
|
if (p.paths.has(N)) {
|
|
1091
|
-
|
|
1090
|
+
A = !0;
|
|
1092
1091
|
break;
|
|
1093
1092
|
}
|
|
1094
1093
|
}
|
|
1095
1094
|
}
|
|
1096
|
-
x =
|
|
1095
|
+
x = V.lastIndexOf(".");
|
|
1097
1096
|
}
|
|
1098
|
-
if (
|
|
1097
|
+
if (A) break;
|
|
1099
1098
|
}
|
|
1100
|
-
if (!
|
|
1101
|
-
const
|
|
1099
|
+
if (!A && C.includes("deps") && p.depsFunction) {
|
|
1100
|
+
const O = p.depsFunction(a);
|
|
1102
1101
|
let x = !1;
|
|
1103
|
-
typeof
|
|
1102
|
+
typeof O == "boolean" ? O && (x = !0) : q(p.deps, O) || (p.deps = O, x = !0), x && (A = !0);
|
|
1104
1103
|
}
|
|
1105
|
-
|
|
1104
|
+
A && p.forceUpdate();
|
|
1106
1105
|
}
|
|
1107
1106
|
}
|
|
1108
1107
|
}
|
|
@@ -1123,9 +1122,9 @@ function vt(t, i, m, g) {
|
|
|
1123
1122
|
});
|
|
1124
1123
|
const c = d.zodSchema.safeParse(r);
|
|
1125
1124
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1126
|
-
const
|
|
1127
|
-
e(
|
|
1128
|
-
}),
|
|
1125
|
+
const E = u.path, p = u.message, A = [d.key, ...E].join(".");
|
|
1126
|
+
e(A, p);
|
|
1127
|
+
}), wt(t), !1);
|
|
1129
1128
|
} catch (a) {
|
|
1130
1129
|
return console.error("Zod schema validation failed", a), !1;
|
|
1131
1130
|
}
|
|
@@ -1134,7 +1133,7 @@ function vt(t, i, m, g) {
|
|
|
1134
1133
|
if (l === "getComponents")
|
|
1135
1134
|
return () => o().stateComponents.get(t);
|
|
1136
1135
|
if (l === "getAllFormRefs")
|
|
1137
|
-
return () =>
|
|
1136
|
+
return () => kt.getState().getFormRefsByStateKey(t);
|
|
1138
1137
|
if (l === "_initialState")
|
|
1139
1138
|
return o.getState().initialStateGlobal[t];
|
|
1140
1139
|
if (l === "_serverState")
|
|
@@ -1147,7 +1146,7 @@ function vt(t, i, m, g) {
|
|
|
1147
1146
|
if (l === "removeValidation") return y.removeValidation;
|
|
1148
1147
|
}
|
|
1149
1148
|
if (l === "getFormRef")
|
|
1150
|
-
return () =>
|
|
1149
|
+
return () => kt.getState().getFormRef(t + "." + n.join("."));
|
|
1151
1150
|
if (l === "validationWrapper")
|
|
1152
1151
|
return ({
|
|
1153
1152
|
children: d,
|
|
@@ -1170,16 +1169,16 @@ function vt(t, i, m, g) {
|
|
|
1170
1169
|
return (d, e) => {
|
|
1171
1170
|
if (e?.debounce)
|
|
1172
1171
|
Ht(() => {
|
|
1173
|
-
|
|
1172
|
+
dt(i, d, n, "");
|
|
1174
1173
|
const r = o.getState().getNestedState(t, n);
|
|
1175
1174
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1176
1175
|
}, e.debounce);
|
|
1177
1176
|
else {
|
|
1178
|
-
|
|
1177
|
+
dt(i, d, n, "");
|
|
1179
1178
|
const r = o.getState().getNestedState(t, n);
|
|
1180
1179
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1181
1180
|
}
|
|
1182
|
-
|
|
1181
|
+
w(n);
|
|
1183
1182
|
};
|
|
1184
1183
|
if (l === "formElement")
|
|
1185
1184
|
return (d, e) => /* @__PURE__ */ Ot(
|
|
@@ -1195,18 +1194,18 @@ function vt(t, i, m, g) {
|
|
|
1195
1194
|
const P = [...n, l], it = o.getState().getNestedState(t, P);
|
|
1196
1195
|
return s(it, P, S);
|
|
1197
1196
|
}
|
|
1198
|
-
}, B = new Proxy(
|
|
1197
|
+
}, B = new Proxy(L, R);
|
|
1199
1198
|
return v.set(F, {
|
|
1200
1199
|
proxy: B,
|
|
1201
|
-
stateVersion:
|
|
1200
|
+
stateVersion: _
|
|
1202
1201
|
}), B;
|
|
1203
1202
|
}
|
|
1204
1203
|
return s(
|
|
1205
1204
|
o.getState().getNestedState(t, [])
|
|
1206
1205
|
);
|
|
1207
1206
|
}
|
|
1208
|
-
function
|
|
1209
|
-
return
|
|
1207
|
+
function Vt(t) {
|
|
1208
|
+
return gt(ne, { proxy: t });
|
|
1210
1209
|
}
|
|
1211
1210
|
function ee({
|
|
1212
1211
|
proxy: t,
|
|
@@ -1217,7 +1216,7 @@ function ee({
|
|
|
1217
1216
|
m,
|
|
1218
1217
|
t._path
|
|
1219
1218
|
).stateMapNoRender(
|
|
1220
|
-
(v,
|
|
1219
|
+
(v, _, w, y, s) => t._mapFn(v, _, w, y, s)
|
|
1221
1220
|
) : null;
|
|
1222
1221
|
}
|
|
1223
1222
|
function ne({
|
|
@@ -1227,13 +1226,13 @@ function ne({
|
|
|
1227
1226
|
return st(() => {
|
|
1228
1227
|
const g = i.current;
|
|
1229
1228
|
if (!g || !g.parentElement) return;
|
|
1230
|
-
const v = g.parentElement,
|
|
1229
|
+
const v = g.parentElement, w = Array.from(v.childNodes).indexOf(g);
|
|
1231
1230
|
let y = v.getAttribute("data-parent-id");
|
|
1232
1231
|
y || (y = `parent-${crypto.randomUUID()}`, v.setAttribute("data-parent-id", y));
|
|
1233
1232
|
const I = {
|
|
1234
1233
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1235
1234
|
parentId: y,
|
|
1236
|
-
position:
|
|
1235
|
+
position: w,
|
|
1237
1236
|
effect: t._effect
|
|
1238
1237
|
};
|
|
1239
1238
|
o.getState().addSignalElement(m, I);
|
|
@@ -1245,15 +1244,15 @@ function ne({
|
|
|
1245
1244
|
"state",
|
|
1246
1245
|
`return (${t._effect})(state)`
|
|
1247
1246
|
)(n);
|
|
1248
|
-
} catch (
|
|
1249
|
-
console.error("Error evaluating effect function during mount:",
|
|
1247
|
+
} catch (L) {
|
|
1248
|
+
console.error("Error evaluating effect function during mount:", L), S = n;
|
|
1250
1249
|
}
|
|
1251
1250
|
else
|
|
1252
1251
|
S = n;
|
|
1253
1252
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1254
1253
|
const F = document.createTextNode(String(S));
|
|
1255
1254
|
g.replaceWith(F);
|
|
1256
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1255
|
+
}, [t._stateKey, t._path.join("."), t._effect]), gt("span", {
|
|
1257
1256
|
ref: i,
|
|
1258
1257
|
style: { display: "none" },
|
|
1259
1258
|
"data-signal-id": m
|
|
@@ -1272,7 +1271,7 @@ function Te(t) {
|
|
|
1272
1271
|
},
|
|
1273
1272
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1274
1273
|
);
|
|
1275
|
-
return
|
|
1274
|
+
return gt("text", {}, String(i));
|
|
1276
1275
|
}
|
|
1277
1276
|
function re({
|
|
1278
1277
|
stateKey: t,
|
|
@@ -1280,14 +1279,14 @@ function re({
|
|
|
1280
1279
|
itemPath: m,
|
|
1281
1280
|
children: g
|
|
1282
1281
|
}) {
|
|
1283
|
-
const [, v] = K({}), [
|
|
1282
|
+
const [, v] = K({}), [_, w] = qt(), y = J(null);
|
|
1284
1283
|
return st(() => {
|
|
1285
|
-
|
|
1284
|
+
w.height > 0 && w.height !== y.current && (y.current = w.height, o.getState().setShadowMetadata(t, m, {
|
|
1286
1285
|
virtualizer: {
|
|
1287
|
-
itemHeight:
|
|
1286
|
+
itemHeight: w.height
|
|
1288
1287
|
}
|
|
1289
1288
|
}));
|
|
1290
|
-
}, [
|
|
1289
|
+
}, [w.height, t, m]), ut(() => {
|
|
1291
1290
|
const s = `${t}////${i}`, I = o.getState().stateComponents.get(t) || {
|
|
1292
1291
|
components: /* @__PURE__ */ new Map()
|
|
1293
1292
|
};
|
|
@@ -1298,10 +1297,10 @@ function re({
|
|
|
1298
1297
|
const n = o.getState().stateComponents.get(t);
|
|
1299
1298
|
n && n.components.delete(s);
|
|
1300
1299
|
};
|
|
1301
|
-
}, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref:
|
|
1300
|
+
}, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: _, children: g });
|
|
1302
1301
|
}
|
|
1303
1302
|
export {
|
|
1304
|
-
|
|
1303
|
+
Vt as $cogsSignal,
|
|
1305
1304
|
Te as $cogsSignalStore,
|
|
1306
1305
|
me as addStateOptions,
|
|
1307
1306
|
he as createCogsState,
|