cogsbox-state 0.5.386 → 0.5.388
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 +475 -464
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +47 -27
package/dist/CogsState.jsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as Oe } from "react/jsx-runtime";
|
|
3
|
+
import { useState as K, useRef as q, useEffect as oe, useLayoutEffect as ce, useMemo as we, createElement as le, useSyncExternalStore as je, startTransition as He, useCallback as ke } from "react";
|
|
4
|
+
import { transformStateFunc as Fe, isDeepEqual as J, isFunction as ee, getNestedValue as Z, getDifferences as _e, debounce as Be } from "./utility.js";
|
|
5
|
+
import { pushFunc as Ee, updateFn as ie, cutFunc as me, ValidationWrapper as We, FormControlComponent as ze } from "./Functions.jsx";
|
|
6
|
+
import qe from "superjson";
|
|
7
7
|
import { v4 as Ae } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as o, formRefStore as be } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Ge } from "./CogsStateClient.jsx";
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
11
|
+
import { applyPatch as Je } from "fast-json-patch";
|
|
12
|
+
import Ye from "react-use-measure";
|
|
13
13
|
function Me(e, i) {
|
|
14
14
|
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(e) || {};
|
|
15
15
|
g(e, {
|
|
@@ -22,42 +22,42 @@ function xe({
|
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = re(e) || {}, I = m[e] || {},
|
|
26
|
-
let
|
|
25
|
+
const g = re(e) || {}, I = m[e] || {}, N = o.getState().setInitialStateOptions, p = { ...I, ...g };
|
|
26
|
+
let v = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const s in i)
|
|
29
|
-
|
|
30
|
-
!
|
|
31
|
-
|
|
29
|
+
p.hasOwnProperty(s) ? (s == "localStorage" && i[s] && p[s].key !== i[s]?.key && (v = !0, p[s] = i[s]), s == "initialState" && i[s] && p[s] !== i[s] && // Different references
|
|
30
|
+
!J(p[s], i[s]) && (v = !0, p[s] = i[s])) : (v = !0, p[s] = i[s]);
|
|
31
|
+
v && N(e, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function It(e, { formElements: i, validation: m }) {
|
|
34
34
|
return { initialState: e, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const vt = (e, i) => {
|
|
37
37
|
let m = e;
|
|
38
|
-
const [g, I] =
|
|
39
|
-
(Object.keys(I).length > 0 || i && Object.keys(i).length > 0) && Object.keys(I).forEach((
|
|
40
|
-
I[
|
|
38
|
+
const [g, I] = Fe(m);
|
|
39
|
+
(Object.keys(I).length > 0 || i && Object.keys(i).length > 0) && Object.keys(I).forEach((v) => {
|
|
40
|
+
I[v] = I[v] || {}, I[v].formElements = {
|
|
41
41
|
...i?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...i?.validation,
|
|
44
|
-
...I[
|
|
44
|
+
...I[v].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
}, re(
|
|
46
|
+
}, re(v) || o.getState().setInitialStateOptions(v, I[v]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
|
-
const
|
|
49
|
-
const [
|
|
48
|
+
const N = (v, s) => {
|
|
49
|
+
const [T] = K(s?.componentId ?? Ae());
|
|
50
50
|
xe({
|
|
51
|
-
stateKey:
|
|
51
|
+
stateKey: v,
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[
|
|
55
|
+
const n = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(n) : n, [W, U] = nt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
|
-
stateKey:
|
|
58
|
+
stateKey: v,
|
|
59
59
|
syncUpdate: s?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: T,
|
|
61
61
|
localStorage: s?.localStorage,
|
|
62
62
|
middleware: s?.middleware,
|
|
63
63
|
enabledSync: s?.enabledSync,
|
|
@@ -68,23 +68,23 @@ const It = (e, i) => {
|
|
|
68
68
|
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return U;
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
xe({ stateKey:
|
|
73
|
+
function p(v, s) {
|
|
74
|
+
xe({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && et(v, s), ve(v);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
78
|
+
setUpdaterState: he,
|
|
79
79
|
setState: ne,
|
|
80
80
|
getInitialOptions: re,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
81
|
+
getKeyState: Re,
|
|
82
|
+
getValidationErrors: Ze,
|
|
83
|
+
setStateLog: Xe,
|
|
84
84
|
updateInitialStateGlobal: Ne,
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
85
|
+
addValidationError: Qe,
|
|
86
|
+
removeValidationError: Q,
|
|
87
|
+
setServerSyncActions: Ke
|
|
88
88
|
} = o.getState(), Pe = (e, i, m, g, I) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
@@ -92,22 +92,22 @@ const It = (e, i) => {
|
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
let
|
|
95
|
+
const N = ee(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
96
|
+
if (N && g) {
|
|
97
|
+
const p = `${g}-${i}-${N}`;
|
|
98
|
+
let v;
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
v = Ie(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const s = {
|
|
104
104
|
state: e,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer: I ??
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: I ?? v
|
|
107
|
+
}, T = qe.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
|
-
|
|
110
|
-
JSON.stringify(
|
|
109
|
+
p,
|
|
110
|
+
JSON.stringify(T.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
}, Ie = (e) => {
|
|
@@ -118,28 +118,28 @@ const It = (e, i) => {
|
|
|
118
118
|
} catch (i) {
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m = o.getState().cogsStateStore[e], { sessionId: g } = Ge(), I =
|
|
121
|
+
}, et = (e, i) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[e], { sessionId: g } = Ge(), I = ee(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (I && g) {
|
|
124
|
-
const
|
|
124
|
+
const N = Ie(
|
|
125
125
|
`${g}-${e}-${I}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return ne(e,
|
|
127
|
+
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
|
+
return ne(e, N.state), ve(e), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
132
|
-
const
|
|
131
|
+
}, Le = (e, i, m, g, I, N) => {
|
|
132
|
+
const p = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: Te(
|
|
135
135
|
e,
|
|
136
136
|
g,
|
|
137
137
|
I,
|
|
138
|
-
|
|
138
|
+
N
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
Ne(e,
|
|
142
|
+
Ne(e, p.initialState), he(e, p.updaterState), ne(e, p.state);
|
|
143
143
|
}, ve = (e) => {
|
|
144
144
|
const i = o.getState().stateComponents.get(e);
|
|
145
145
|
if (!i) return;
|
|
@@ -149,7 +149,7 @@ const It = (e, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, yt = (e, i) => {
|
|
153
153
|
const m = o.getState().stateComponents.get(e);
|
|
154
154
|
if (m) {
|
|
155
155
|
const g = `${e}////${i}`, I = m.components.get(g);
|
|
@@ -157,7 +157,7 @@ const It = (e, i) => {
|
|
|
157
157
|
return;
|
|
158
158
|
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, tt = (e, i, m, g) => {
|
|
161
161
|
switch (e) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
@@ -180,57 +180,57 @@ const It = (e, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function nt(e, {
|
|
184
184
|
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: I,
|
|
188
|
-
reactiveDeps:
|
|
189
|
-
reactiveType:
|
|
190
|
-
componentId:
|
|
188
|
+
reactiveDeps: N,
|
|
189
|
+
reactiveType: p,
|
|
190
|
+
componentId: v,
|
|
191
191
|
initialState: s,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: T,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [
|
|
196
|
+
const [W, U] = K({}), { sessionId: j } = Ge();
|
|
197
|
+
let z = !i;
|
|
198
|
+
const [h] = K(i ?? Ae()), l = o.getState().stateLog[h], de = q(/* @__PURE__ */ new Set()), te = q(v ?? Ae()), R = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
ne(
|
|
201
|
+
R.current = re(h) ?? null, oe(() => {
|
|
202
|
+
if (T && T.stateKey === h && T.path?.[0]) {
|
|
203
|
+
ne(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
|
-
[
|
|
205
|
+
[T.path[0]]: T.newValue
|
|
206
206
|
}));
|
|
207
|
-
const t = `${
|
|
207
|
+
const t = `${T.stateKey}:${T.path.join(".")}`;
|
|
208
208
|
o.getState().setSyncInfo(t, {
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
209
|
+
timeStamp: T.timeStamp,
|
|
210
|
+
userId: T.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [T]), oe(() => {
|
|
214
214
|
if (s) {
|
|
215
|
-
Me(
|
|
215
|
+
Me(h, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const t =
|
|
219
|
-
if (!(c && !
|
|
218
|
+
const t = R.current, a = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = o.getState().initialStateGlobal[h];
|
|
219
|
+
if (!(c && !J(c, s) || !c) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
const
|
|
226
|
-
a &&
|
|
227
|
-
|
|
222
|
+
const E = ee(t?.localStorage?.key) ? t?.localStorage?.key(s) : t?.localStorage?.key;
|
|
223
|
+
E && j && (u = Ie(`${j}-${h}-${E}`));
|
|
224
|
+
let y = s, w = !1;
|
|
225
|
+
const C = a ? Date.now() : 0, A = u?.lastUpdated || 0, M = u?.lastSyncedWithServer || 0;
|
|
226
|
+
a && C > A ? (y = t.serverState.data, w = !0) : u && A > M && (y = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Le(
|
|
227
|
+
h,
|
|
228
228
|
s,
|
|
229
|
-
|
|
229
|
+
y,
|
|
230
230
|
ae,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
),
|
|
231
|
+
te.current,
|
|
232
|
+
j
|
|
233
|
+
), w && E && j && Pe(y, h, t, j, Date.now()), ve(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || U({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
@@ -238,95 +238,95 @@ function tt(e, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), ce(() => {
|
|
241
|
-
|
|
241
|
+
z && Me(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
|
-
const t = `${
|
|
248
|
+
const t = `${h}////${te.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(t, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => U({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
256
|
-
reactiveType:
|
|
257
|
-
}), o.getState().stateComponents.set(
|
|
258
|
-
r && (r.components.delete(t), r.components.size === 0 && o.getState().stateComponents.delete(
|
|
255
|
+
depsFunction: N || void 0,
|
|
256
|
+
reactiveType: p ?? ["component", "deps"]
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), U({}), () => {
|
|
258
|
+
r && (r.components.delete(t), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const ae = (t, r, a, c) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const u = `${
|
|
263
|
+
const u = `${h}-${r.join(".")}`;
|
|
264
264
|
de.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = o.getState();
|
|
267
|
-
ne(
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
if ((
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
267
|
+
ne(h, (u) => {
|
|
268
|
+
const E = ee(t) ? t(u) : t, y = `${h}-${r.join(".")}`;
|
|
269
|
+
if (y) {
|
|
270
|
+
let x = !1, $ = f.signalDomElements.get(y);
|
|
271
|
+
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
+
const L = r.slice(0, -1), V = Z(E, L);
|
|
273
|
+
if (Array.isArray(V)) {
|
|
274
|
+
x = !0;
|
|
275
|
+
const O = `${h}-${L.join(".")}`;
|
|
276
|
+
$ = f.signalDomElements.get(O);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if ($) {
|
|
280
|
+
const L = x ? Z(E, r.slice(0, -1)) : Z(E, r);
|
|
281
|
+
$.forEach(({ parentId: V, position: O, effect: _ }) => {
|
|
282
|
+
const D = document.querySelector(
|
|
283
|
+
`[data-parent-id="${V}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const B =
|
|
289
|
-
|
|
285
|
+
if (D) {
|
|
286
|
+
const G = Array.from(D.childNodes);
|
|
287
|
+
if (G[O]) {
|
|
288
|
+
const B = _ ? new Function("state", `return (${_})(state)`)(L) : L;
|
|
289
|
+
G[O].textContent = String(B);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c ||
|
|
296
|
-
(c ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c || R.current?.validation?.key) && r && Q(
|
|
296
|
+
(c || R.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
|
|
298
|
+
const w = r.slice(0, r.length - 1);
|
|
299
|
+
a.updateType === "cut" && R.current?.validation?.key && Q(
|
|
300
|
+
R.current?.validation?.key + "." + w.join(".")
|
|
301
|
+
), a.updateType === "insert" && R.current?.validation?.key && Ze(
|
|
302
|
+
R.current?.validation?.key + "." + w.join(".")
|
|
303
|
+
).filter(([$, L]) => {
|
|
304
|
+
let V = $?.split(".").length;
|
|
305
|
+
if ($ == w.join(".") && V == w.length - 1) {
|
|
306
|
+
let O = $ + "." + w;
|
|
307
|
+
Q($), Qe(O, L);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const C = f.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
+
const x = _e(u, E), $ = new Set(x), L = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
314
|
+
V,
|
|
315
|
+
O
|
|
316
|
+
] of C.components.entries()) {
|
|
317
|
+
let _ = !1;
|
|
318
|
+
const D = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", O), !D.includes("none")) {
|
|
320
|
+
if (D.includes("all")) {
|
|
321
|
+
O.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let B =
|
|
324
|
+
if (D.includes("component") && ((O.paths.has(L) || O.paths.has("")) && (_ = !0), !_))
|
|
325
|
+
for (const G of $) {
|
|
326
|
+
let B = G;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (O.paths.has(B)) {
|
|
329
|
+
_ = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
332
|
const se = B.lastIndexOf(".");
|
|
@@ -337,8 +337,8 @@ function tt(e, {
|
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
339
|
Number(B.substring(se + 1))
|
|
340
|
-
) &&
|
|
341
|
-
|
|
340
|
+
) && O.paths.has(ue)) {
|
|
341
|
+
_ = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
344
|
B = ue;
|
|
@@ -347,159 +347,159 @@ function tt(e, {
|
|
|
347
347
|
if (B === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (_) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
352
|
+
if (!_ && D.includes("deps") && O.depsFunction) {
|
|
353
|
+
const G = O.depsFunction(E);
|
|
354
354
|
let B = !1;
|
|
355
|
-
typeof
|
|
355
|
+
typeof G == "boolean" ? G && (B = !0) : J(O.deps, G) || (O.deps = G, B = !0), B && (_ = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
_ && O.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const A = Date.now();
|
|
362
|
+
r = r.map((x, $) => {
|
|
363
|
+
const L = r.slice(0, -1), V = Z(E, L);
|
|
364
|
+
return $ === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : x;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: M, newValue: F } = tt(
|
|
367
367
|
a.updateType,
|
|
368
368
|
u,
|
|
369
|
-
|
|
369
|
+
E,
|
|
370
370
|
r
|
|
371
371
|
), Y = {
|
|
372
|
-
timeStamp:
|
|
373
|
-
stateKey:
|
|
372
|
+
timeStamp: A,
|
|
373
|
+
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: a.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: M,
|
|
378
|
+
newValue: F
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
f.updateShadowAtPath(
|
|
382
|
+
f.updateShadowAtPath(h, r, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(
|
|
385
|
+
const x = r.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(h, x, F);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
f.removeShadowArrayElement(
|
|
389
|
+
const $ = r.slice(0, -1), L = parseInt(r[r.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(h, $, L);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Xe(h, (x) => {
|
|
394
|
+
const L = [...x ?? [], Y].reduce((V, O) => {
|
|
395
|
+
const _ = `${O.stateKey}:${JSON.stringify(O.path)}`, D = V.get(_);
|
|
396
|
+
return D ? (D.timeStamp = Math.max(D.timeStamp, O.timeStamp), D.newValue = O.newValue, D.oldValue = D.oldValue ?? O.oldValue, D.updateType = O.updateType) : V.set(_, { ...O }), V;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
398
|
+
return Array.from(L.values());
|
|
399
399
|
}), Pe(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
400
|
+
E,
|
|
401
|
+
h,
|
|
402
|
+
R.current,
|
|
403
|
+
j
|
|
404
|
+
), R.current?.middleware && R.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
407
|
+
}), R.current?.serverSync) {
|
|
408
|
+
const x = f.serverState[h], $ = R.current?.serverSync;
|
|
409
|
+
Ke(h, {
|
|
410
|
+
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
|
|
411
|
+
rollBackState: x,
|
|
412
|
+
actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
o.getState().updaterState[h] || (he(
|
|
420
|
+
h,
|
|
421
|
+
Te(
|
|
422
|
+
h,
|
|
423
423
|
ae,
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
te.current,
|
|
425
|
+
j
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[
|
|
428
|
-
const d =
|
|
429
|
-
|
|
427
|
+
), o.getState().cogsStateStore[h] || ne(h, e), o.getState().initialStateGlobal[h] || Ne(h, e));
|
|
428
|
+
const d = we(() => Te(
|
|
429
|
+
h,
|
|
430
430
|
ae,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
), [
|
|
434
|
-
return [
|
|
431
|
+
te.current,
|
|
432
|
+
j
|
|
433
|
+
), [h, j]);
|
|
434
|
+
return [Re(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function Te(e, i, m, g) {
|
|
437
437
|
const I = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
439
|
-
const
|
|
440
|
-
const n =
|
|
438
|
+
let N = 0;
|
|
439
|
+
const p = (T) => {
|
|
440
|
+
const n = T.join(".");
|
|
441
441
|
for (const [S] of I)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && I.delete(S);
|
|
443
|
-
|
|
444
|
-
},
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
443
|
+
N++;
|
|
444
|
+
}, v = {
|
|
445
|
+
removeValidation: (T) => {
|
|
446
|
+
T?.validationKey && Q(T.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
448
|
+
revertToInitialState: (T) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(e)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Q(n?.key), T?.validationKey && Q(T.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[e];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(e), I.clear(),
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
return
|
|
452
|
+
o.getState().clearSelectedIndexesForState(e), I.clear(), N++;
|
|
453
|
+
const W = s(S, []), U = re(e), j = ee(U?.localStorage?.key) ? U?.localStorage?.key(S) : U?.localStorage?.key, z = `${g}-${e}-${j}`;
|
|
454
|
+
z && localStorage.removeItem(z), he(e, W), ne(e, S);
|
|
455
|
+
const h = o.getState().stateComponents.get(e);
|
|
456
|
+
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
I.clear(),
|
|
462
|
-
const n =
|
|
460
|
+
updateInitialState: (T) => {
|
|
461
|
+
I.clear(), N++;
|
|
462
|
+
const n = Te(
|
|
463
463
|
e,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = o.getState().initialStateGlobal[e],
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
Ne(e,
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
467
|
+
), S = o.getState().initialStateGlobal[e], W = re(e), U = ee(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, j = `${g}-${e}-${U}`;
|
|
468
|
+
return localStorage.getItem(j) && localStorage.removeItem(j), He(() => {
|
|
469
|
+
Ne(e, T), o.getState().initializeShadowState(e, T), he(e, n), ne(e, T);
|
|
470
|
+
const z = o.getState().stateComponents.get(e);
|
|
471
|
+
z && z.components.forEach((h) => {
|
|
472
|
+
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (z) => n.get()[z]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[e],
|
|
479
479
|
_serverState: o.getState().serverState[e],
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[e],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const T = o.getState().serverState[e];
|
|
483
|
+
return !!(T && J(T, Re(e)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function s(
|
|
487
|
-
const
|
|
488
|
-
I.get(
|
|
489
|
-
const
|
|
486
|
+
function s(T, n = [], S) {
|
|
487
|
+
const W = n.map(String).join(".");
|
|
488
|
+
I.get(W);
|
|
489
|
+
const U = function() {
|
|
490
490
|
return o().getNestedState(e, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(
|
|
493
|
-
|
|
492
|
+
Object.keys(v).forEach((h) => {
|
|
493
|
+
U[h] = v[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(
|
|
495
|
+
const j = {
|
|
496
|
+
apply(h, l, de) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(e, n);
|
|
500
500
|
},
|
|
501
|
-
get(
|
|
502
|
-
S?.validIndices && !Array.isArray(
|
|
501
|
+
get(h, l) {
|
|
502
|
+
S?.validIndices && !Array.isArray(T) && (S = { ...S, validIndices: void 0 });
|
|
503
503
|
const de = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
@@ -540,7 +540,7 @@ function he(e, i, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => _e(
|
|
544
544
|
o.getState().cogsStateStore[e],
|
|
545
545
|
o.getState().initialStateGlobal[e]
|
|
546
546
|
);
|
|
@@ -554,8 +554,8 @@ function he(e, i, m, g) {
|
|
|
554
554
|
const c = await t.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(e);
|
|
561
561
|
f && f.components.forEach((u) => {
|
|
@@ -569,7 +569,7 @@ function he(e, i, m, g) {
|
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
571
|
const d = o.getState().getNestedState(e, n), t = o.getState().initialStateGlobal[e], r = Z(t, n);
|
|
572
|
-
return
|
|
572
|
+
return J(d, r) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
575
575
|
return function() {
|
|
@@ -577,11 +577,11 @@ function he(e, i, m, g) {
|
|
|
577
577
|
e,
|
|
578
578
|
n
|
|
579
579
|
), t = o.getState().initialStateGlobal[e], r = Z(t, n);
|
|
580
|
-
return
|
|
580
|
+
return J(d, r) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[e], t = re(e), r =
|
|
584
|
+
const d = o.getState().initialStateGlobal[e], t = re(e), r = ee(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, a = `${g}-${e}-${r}`;
|
|
585
585
|
a && localStorage.removeItem(a);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -591,8 +591,8 @@ function he(e, i, m, g) {
|
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => S?.validIndices ?
|
|
594
|
+
if (Array.isArray(T)) {
|
|
595
|
+
const d = () => S?.validIndices ? T.map((r, a) => ({
|
|
596
596
|
item: r,
|
|
597
597
|
originalIndex: S.validIndices[a]
|
|
598
598
|
})) : o.getState().getNestedState(e, n).map((r, a) => ({
|
|
@@ -604,7 +604,7 @@ function he(e, i, m, g) {
|
|
|
604
604
|
const t = o.getState().getSelectedIndex(e, n.join("."));
|
|
605
605
|
if (t !== void 0)
|
|
606
606
|
return s(
|
|
607
|
-
|
|
607
|
+
T[t],
|
|
608
608
|
[...n, t.toString()],
|
|
609
609
|
S
|
|
610
610
|
);
|
|
@@ -622,142 +622,153 @@ function he(e, i, m, g) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = t, u =
|
|
625
|
+
} = t, u = q(!1), E = q(null), [y, w] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
628
|
+
}), [C, A] = K("IDLE_AT_TOP"), M = q(!1), F = q(0), Y = q(f), x = q(0), [$, L] = K(0), V = q(null);
|
|
629
629
|
oe(() => o.getState().subscribeToShadowState(e, () => {
|
|
630
|
-
|
|
630
|
+
L((P) => P + 1);
|
|
631
631
|
}), [e]);
|
|
632
|
-
const
|
|
632
|
+
const O = o().getNestedState(
|
|
633
633
|
e,
|
|
634
634
|
n
|
|
635
|
-
),
|
|
636
|
-
const
|
|
637
|
-
let
|
|
635
|
+
), _ = O.length, { totalHeight: D, positions: G } = we(() => {
|
|
636
|
+
const k = o.getState().getShadowMetadata(e, n) || [];
|
|
637
|
+
let P = 0;
|
|
638
638
|
const H = [];
|
|
639
|
-
for (let
|
|
640
|
-
H[
|
|
641
|
-
const
|
|
642
|
-
|
|
639
|
+
for (let b = 0; b < _; b++) {
|
|
640
|
+
H[b] = P;
|
|
641
|
+
const X = k[b]?.virtualizer?.itemHeight;
|
|
642
|
+
P += X || r;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: P, positions: H };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
646
|
+
_,
|
|
647
647
|
e,
|
|
648
648
|
n.join("."),
|
|
649
649
|
r,
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return s(
|
|
650
|
+
$
|
|
651
|
+
]), B = we(() => {
|
|
652
|
+
const k = Math.max(0, y.startIndex), P = Math.min(_, y.endIndex), H = Array.from(
|
|
653
|
+
{ length: P - k },
|
|
654
|
+
(X, ge) => k + ge
|
|
655
|
+
), b = H.map((X) => O[X]);
|
|
656
|
+
return s(b, n, {
|
|
657
657
|
...S,
|
|
658
658
|
validIndices: H
|
|
659
659
|
});
|
|
660
|
-
}, [
|
|
660
|
+
}, [y.startIndex, y.endIndex, O, _]);
|
|
661
661
|
ce(() => {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
662
|
+
const k = E.current, P = _ > F.current;
|
|
663
|
+
if (P && V.current && k) {
|
|
664
|
+
const { top: H, height: b } = V.current;
|
|
665
|
+
k.scrollTop = H + (k.scrollHeight - b), V.current = null, console.log(
|
|
666
|
+
`ANCHOR RESTORED to scrollTop: ${k.scrollTop}`
|
|
667
|
+
);
|
|
668
|
+
} else {
|
|
669
|
+
if (!J(
|
|
670
|
+
f,
|
|
671
|
+
Y.current
|
|
672
|
+
)) {
|
|
673
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), A("IDLE_AT_TOP");
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
P && C === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
677
|
+
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
678
|
+
), A("GETTING_HEIGHTS"));
|
|
669
679
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
if (
|
|
676
|
-
let x;
|
|
677
|
-
if (N === "IDLE_AT_TOP" && c && v > 0)
|
|
680
|
+
F.current = _, Y.current = f;
|
|
681
|
+
}, [_, ...f]), ce(() => {
|
|
682
|
+
const k = E.current;
|
|
683
|
+
if (!k) return;
|
|
684
|
+
let P;
|
|
685
|
+
if (C === "IDLE_AT_TOP" && c && _ > 0)
|
|
678
686
|
console.log(
|
|
679
687
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
680
|
-
),
|
|
681
|
-
else if (
|
|
688
|
+
), A("GETTING_HEIGHTS");
|
|
689
|
+
else if (C === "GETTING_HEIGHTS")
|
|
682
690
|
console.log(
|
|
683
691
|
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
684
|
-
),
|
|
685
|
-
startIndex: Math.max(0,
|
|
686
|
-
endIndex:
|
|
687
|
-
}),
|
|
688
|
-
const H =
|
|
689
|
-
((o.getState().getShadowMetadata(e, n) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(
|
|
692
|
+
), w({
|
|
693
|
+
startIndex: Math.max(0, _ - 10 - a),
|
|
694
|
+
endIndex: _
|
|
695
|
+
}), P = setInterval(() => {
|
|
696
|
+
const H = _ - 1;
|
|
697
|
+
((o.getState().getShadowMetadata(e, n) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(P), u.current || (console.log(
|
|
690
698
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
691
|
-
),
|
|
699
|
+
), A("SCROLLING_TO_BOTTOM")));
|
|
692
700
|
}, 100);
|
|
693
|
-
else if (
|
|
701
|
+
else if (C === "SCROLLING_TO_BOTTOM") {
|
|
694
702
|
console.log(
|
|
695
703
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
696
|
-
),
|
|
697
|
-
const H =
|
|
698
|
-
|
|
699
|
-
top:
|
|
704
|
+
), M.current = !0;
|
|
705
|
+
const H = F.current === 0 ? "auto" : "smooth";
|
|
706
|
+
k.scrollTo({
|
|
707
|
+
top: k.scrollHeight,
|
|
700
708
|
behavior: H
|
|
701
709
|
});
|
|
702
|
-
const
|
|
710
|
+
const b = setTimeout(
|
|
703
711
|
() => {
|
|
704
712
|
console.log(
|
|
705
713
|
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
706
|
-
),
|
|
714
|
+
), M.current = !1, u.current = !1, A("LOCKED_AT_BOTTOM");
|
|
707
715
|
},
|
|
708
716
|
H === "smooth" ? 500 : 50
|
|
709
717
|
);
|
|
710
|
-
return () => clearTimeout(
|
|
718
|
+
return () => clearTimeout(b);
|
|
711
719
|
}
|
|
712
720
|
return () => {
|
|
713
|
-
|
|
721
|
+
P && clearInterval(P);
|
|
714
722
|
};
|
|
715
|
-
}, [
|
|
716
|
-
const
|
|
717
|
-
if (!
|
|
718
|
-
const
|
|
719
|
-
if (
|
|
723
|
+
}, [C, _, G]), oe(() => {
|
|
724
|
+
const k = E.current;
|
|
725
|
+
if (!k) return;
|
|
726
|
+
const P = r, H = () => {
|
|
727
|
+
if (M.current)
|
|
720
728
|
return;
|
|
721
|
-
const { scrollTop:
|
|
722
|
-
if (
|
|
729
|
+
const { scrollTop: b, scrollHeight: X, clientHeight: ge } = k;
|
|
730
|
+
if (X - b - ge < 10 ? C !== "LOCKED_AT_BOTTOM" && (A("LOCKED_AT_BOTTOM"), V.current = null) : C !== "IDLE_NOT_AT_BOTTOM" && (A("IDLE_NOT_AT_BOTTOM"), V.current = {
|
|
731
|
+
top: b,
|
|
732
|
+
height: X
|
|
733
|
+
}, console.log(`ANCHOR SET at scrollTop: ${b}`)), Math.abs(b - x.current) < P)
|
|
723
734
|
return;
|
|
724
735
|
console.log(
|
|
725
|
-
`Threshold passed at ${
|
|
736
|
+
`Threshold passed at ${b}px. Recalculating range...`
|
|
726
737
|
);
|
|
727
|
-
let ye =
|
|
738
|
+
let ye = _ - 1, pe = 0, Ce = 0;
|
|
728
739
|
for (; pe <= ye; ) {
|
|
729
740
|
const Se = Math.floor((pe + ye) / 2);
|
|
730
|
-
|
|
741
|
+
G[Se] < b ? (Ce = Se, pe = Se + 1) : ye = Se - 1;
|
|
731
742
|
}
|
|
732
743
|
const $e = Math.max(0, Ce - a);
|
|
733
744
|
let fe = $e;
|
|
734
|
-
const
|
|
735
|
-
for (; fe <
|
|
745
|
+
const Ue = b + ge;
|
|
746
|
+
for (; fe < _ && G[fe] < Ue; )
|
|
736
747
|
fe++;
|
|
737
|
-
|
|
748
|
+
w({
|
|
738
749
|
startIndex: $e,
|
|
739
|
-
endIndex: Math.min(
|
|
740
|
-
}),
|
|
750
|
+
endIndex: Math.min(_, fe + a)
|
|
751
|
+
}), x.current = b;
|
|
741
752
|
};
|
|
742
|
-
return
|
|
753
|
+
return k.addEventListener("scroll", H, {
|
|
743
754
|
passive: !0
|
|
744
|
-
}), () =>
|
|
745
|
-
}, [
|
|
746
|
-
const
|
|
755
|
+
}), () => k.removeEventListener("scroll", H);
|
|
756
|
+
}, [_, G, r, a, C]);
|
|
757
|
+
const se = ke(() => {
|
|
747
758
|
console.log(
|
|
748
759
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
749
|
-
),
|
|
750
|
-
}, []),
|
|
751
|
-
(
|
|
752
|
-
|
|
753
|
-
top:
|
|
754
|
-
behavior:
|
|
760
|
+
), A("SCROLLING_TO_BOTTOM");
|
|
761
|
+
}, []), ue = ke(
|
|
762
|
+
(k, P = "smooth") => {
|
|
763
|
+
E.current && G[k] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
764
|
+
top: G[k],
|
|
765
|
+
behavior: P
|
|
755
766
|
}));
|
|
756
767
|
},
|
|
757
|
-
[
|
|
758
|
-
),
|
|
768
|
+
[G]
|
|
769
|
+
), De = {
|
|
759
770
|
outer: {
|
|
760
|
-
ref:
|
|
771
|
+
ref: E,
|
|
761
772
|
style: { overflowY: "auto", height: "100%" }
|
|
762
773
|
},
|
|
763
774
|
inner: {
|
|
@@ -768,21 +779,21 @@ function he(e, i, m, g) {
|
|
|
768
779
|
},
|
|
769
780
|
list: {
|
|
770
781
|
style: {
|
|
771
|
-
transform: `translateY(${
|
|
782
|
+
transform: `translateY(${G[y.startIndex] || 0}px)`
|
|
772
783
|
}
|
|
773
784
|
}
|
|
774
785
|
};
|
|
775
786
|
return {
|
|
776
|
-
virtualState:
|
|
777
|
-
virtualizerProps:
|
|
778
|
-
scrollToBottom:
|
|
779
|
-
scrollToIndex:
|
|
787
|
+
virtualState: B,
|
|
788
|
+
virtualizerProps: De,
|
|
789
|
+
scrollToBottom: se,
|
|
790
|
+
scrollToIndex: ue
|
|
780
791
|
};
|
|
781
792
|
};
|
|
782
793
|
if (l === "stateSort")
|
|
783
794
|
return (t) => {
|
|
784
795
|
const a = [...d()].sort(
|
|
785
|
-
(u,
|
|
796
|
+
(u, E) => t(u.item, E.item)
|
|
786
797
|
), c = a.map(({ item: u }) => u), f = {
|
|
787
798
|
...S,
|
|
788
799
|
validIndices: a.map(
|
|
@@ -794,7 +805,7 @@ function he(e, i, m, g) {
|
|
|
794
805
|
if (l === "stateFilter")
|
|
795
806
|
return (t) => {
|
|
796
807
|
const a = d().filter(
|
|
797
|
-
({ item: u },
|
|
808
|
+
({ item: u }, E) => t(u, E)
|
|
798
809
|
), c = a.map(({ item: u }) => u), f = {
|
|
799
810
|
...S,
|
|
800
811
|
validIndices: a.map(
|
|
@@ -807,22 +818,22 @@ function he(e, i, m, g) {
|
|
|
807
818
|
return (t) => {
|
|
808
819
|
const r = o.getState().getNestedState(e, n);
|
|
809
820
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
810
|
-
const u = r[c],
|
|
811
|
-
return t(u,
|
|
821
|
+
const u = r[c], E = [...n, c.toString()], y = s(u, E, S);
|
|
822
|
+
return t(u, y, {
|
|
812
823
|
register: () => {
|
|
813
|
-
const [,
|
|
824
|
+
const [, C] = K({}), A = `${m}-${n.join(".")}-${c}`;
|
|
814
825
|
ce(() => {
|
|
815
|
-
const
|
|
826
|
+
const M = `${e}////${A}`, F = o.getState().stateComponents.get(e) || {
|
|
816
827
|
components: /* @__PURE__ */ new Map()
|
|
817
828
|
};
|
|
818
|
-
return
|
|
819
|
-
forceUpdate: () =>
|
|
820
|
-
paths: /* @__PURE__ */ new Set([
|
|
821
|
-
}), o.getState().stateComponents.set(e,
|
|
829
|
+
return F.components.set(M, {
|
|
830
|
+
forceUpdate: () => C({}),
|
|
831
|
+
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
832
|
+
}), o.getState().stateComponents.set(e, F), () => {
|
|
822
833
|
const Y = o.getState().stateComponents.get(e);
|
|
823
|
-
Y && Y.components.delete(
|
|
834
|
+
Y && Y.components.delete(M);
|
|
824
835
|
};
|
|
825
|
-
}, [e,
|
|
836
|
+
}, [e, A]);
|
|
826
837
|
},
|
|
827
838
|
index: f,
|
|
828
839
|
originalIndex: c
|
|
@@ -833,20 +844,20 @@ function he(e, i, m, g) {
|
|
|
833
844
|
), null);
|
|
834
845
|
};
|
|
835
846
|
if (l === "stateMapNoRender")
|
|
836
|
-
return (t) =>
|
|
847
|
+
return (t) => T.map((a, c) => {
|
|
837
848
|
let f;
|
|
838
849
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
839
|
-
const u = [...n, f.toString()],
|
|
850
|
+
const u = [...n, f.toString()], E = s(a, u, S);
|
|
840
851
|
return t(
|
|
841
852
|
a,
|
|
842
|
-
|
|
853
|
+
E,
|
|
843
854
|
c,
|
|
844
|
-
|
|
845
|
-
s(
|
|
855
|
+
T,
|
|
856
|
+
s(T, n, S)
|
|
846
857
|
);
|
|
847
858
|
});
|
|
848
859
|
if (l === "$stateMap")
|
|
849
|
-
return (t) => le(
|
|
860
|
+
return (t) => le(rt, {
|
|
850
861
|
proxy: {
|
|
851
862
|
_stateKey: e,
|
|
852
863
|
_path: n,
|
|
@@ -859,15 +870,15 @@ function he(e, i, m, g) {
|
|
|
859
870
|
return (t) => {
|
|
860
871
|
const r = o.getState().getNestedState(e, n);
|
|
861
872
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
862
|
-
const u = r[c],
|
|
863
|
-
return le(
|
|
873
|
+
const u = r[c], E = [...n, c.toString()], y = s(u, E, S), w = `${m}-${n.join(".")}-${c}`;
|
|
874
|
+
return le(at, {
|
|
864
875
|
key: c,
|
|
865
876
|
stateKey: e,
|
|
866
|
-
itemComponentId:
|
|
867
|
-
itemPath:
|
|
877
|
+
itemComponentId: w,
|
|
878
|
+
itemPath: E,
|
|
868
879
|
children: t(
|
|
869
880
|
u,
|
|
870
|
-
|
|
881
|
+
y,
|
|
871
882
|
f,
|
|
872
883
|
r,
|
|
873
884
|
s(r, n, S)
|
|
@@ -879,8 +890,8 @@ function he(e, i, m, g) {
|
|
|
879
890
|
};
|
|
880
891
|
if (l === "stateFlattenOn")
|
|
881
892
|
return (t) => {
|
|
882
|
-
const r =
|
|
883
|
-
I.clear(),
|
|
893
|
+
const r = T;
|
|
894
|
+
I.clear(), N++;
|
|
884
895
|
const a = r.flatMap(
|
|
885
896
|
(c) => c[t] ?? []
|
|
886
897
|
);
|
|
@@ -892,7 +903,7 @@ function he(e, i, m, g) {
|
|
|
892
903
|
};
|
|
893
904
|
if (l === "index")
|
|
894
905
|
return (t) => {
|
|
895
|
-
const r =
|
|
906
|
+
const r = T[t];
|
|
896
907
|
return s(r, [...n, t.toString()]);
|
|
897
908
|
};
|
|
898
909
|
if (l === "last")
|
|
@@ -903,49 +914,49 @@ function he(e, i, m, g) {
|
|
|
903
914
|
return s(a, c);
|
|
904
915
|
};
|
|
905
916
|
if (l === "insert")
|
|
906
|
-
return (t) => (
|
|
917
|
+
return (t) => (p(n), Ee(i, t, n, e), s(
|
|
907
918
|
o.getState().getNestedState(e, n),
|
|
908
919
|
n
|
|
909
920
|
));
|
|
910
921
|
if (l === "uniqueInsert")
|
|
911
922
|
return (t, r, a) => {
|
|
912
|
-
const c = o.getState().getNestedState(e, n), f =
|
|
923
|
+
const c = o.getState().getNestedState(e, n), f = ee(t) ? t(c) : t;
|
|
913
924
|
let u = null;
|
|
914
|
-
if (!c.some((
|
|
925
|
+
if (!c.some((y) => {
|
|
915
926
|
if (r) {
|
|
916
|
-
const
|
|
917
|
-
(
|
|
927
|
+
const C = r.every(
|
|
928
|
+
(A) => J(y[A], f[A])
|
|
918
929
|
);
|
|
919
|
-
return
|
|
930
|
+
return C && (u = y), C;
|
|
920
931
|
}
|
|
921
|
-
const
|
|
922
|
-
return
|
|
932
|
+
const w = J(y, f);
|
|
933
|
+
return w && (u = y), w;
|
|
923
934
|
}))
|
|
924
|
-
|
|
935
|
+
p(n), Ee(i, f, n, e);
|
|
925
936
|
else if (a && u) {
|
|
926
|
-
const
|
|
927
|
-
(
|
|
937
|
+
const y = a(u), w = c.map(
|
|
938
|
+
(C) => J(C, u) ? y : C
|
|
928
939
|
);
|
|
929
|
-
|
|
940
|
+
p(n), ie(i, w, n);
|
|
930
941
|
}
|
|
931
942
|
};
|
|
932
943
|
if (l === "cut")
|
|
933
944
|
return (t, r) => {
|
|
934
945
|
if (!r?.waitForSync)
|
|
935
|
-
return
|
|
946
|
+
return p(n), me(i, n, e, t), s(
|
|
936
947
|
o.getState().getNestedState(e, n),
|
|
937
948
|
n
|
|
938
949
|
);
|
|
939
950
|
};
|
|
940
951
|
if (l === "cutByValue")
|
|
941
952
|
return (t) => {
|
|
942
|
-
for (let r = 0; r <
|
|
943
|
-
|
|
953
|
+
for (let r = 0; r < T.length; r++)
|
|
954
|
+
T[r] === t && me(i, n, e, r);
|
|
944
955
|
};
|
|
945
956
|
if (l === "toggleByValue")
|
|
946
957
|
return (t) => {
|
|
947
|
-
const r =
|
|
948
|
-
r > -1 ? me(i, n, e, r) :
|
|
958
|
+
const r = T.findIndex((a) => a === t);
|
|
959
|
+
r > -1 ? me(i, n, e, r) : Ee(i, t, n, e);
|
|
949
960
|
};
|
|
950
961
|
if (l === "stateFind")
|
|
951
962
|
return (t) => {
|
|
@@ -966,20 +977,20 @@ function he(e, i, m, g) {
|
|
|
966
977
|
return s(c.item, f, S);
|
|
967
978
|
};
|
|
968
979
|
}
|
|
969
|
-
const
|
|
970
|
-
if (!isNaN(Number(
|
|
980
|
+
const te = n[n.length - 1];
|
|
981
|
+
if (!isNaN(Number(te))) {
|
|
971
982
|
const d = n.slice(0, -1), t = o.getState().getNestedState(e, d);
|
|
972
983
|
if (Array.isArray(t) && l === "cut")
|
|
973
984
|
return () => me(
|
|
974
985
|
i,
|
|
975
986
|
d,
|
|
976
987
|
e,
|
|
977
|
-
Number(
|
|
988
|
+
Number(te)
|
|
978
989
|
);
|
|
979
990
|
}
|
|
980
991
|
if (l === "get")
|
|
981
992
|
return () => {
|
|
982
|
-
if (S?.validIndices && Array.isArray(
|
|
993
|
+
if (S?.validIndices && Array.isArray(T)) {
|
|
983
994
|
const d = o.getState().getNestedState(e, n);
|
|
984
995
|
return S.validIndices.map((t) => d[t]);
|
|
985
996
|
}
|
|
@@ -1011,7 +1022,7 @@ function he(e, i, m, g) {
|
|
|
1011
1022
|
const t = n.slice(0, -1), r = Number(n[n.length - 1]), a = t.join(".");
|
|
1012
1023
|
d ? o.getState().setSelectedIndex(e, a, r) : o.getState().setSelectedIndex(e, a, void 0);
|
|
1013
1024
|
const c = o.getState().getNestedState(e, [...t]);
|
|
1014
|
-
ie(i, c, t),
|
|
1025
|
+
ie(i, c, t), p(t);
|
|
1015
1026
|
};
|
|
1016
1027
|
if (l === "toggleSelected")
|
|
1017
1028
|
return () => {
|
|
@@ -1022,13 +1033,13 @@ function he(e, i, m, g) {
|
|
|
1022
1033
|
a === t ? void 0 : t
|
|
1023
1034
|
);
|
|
1024
1035
|
const c = o.getState().getNestedState(e, [...d]);
|
|
1025
|
-
ie(i, c, d),
|
|
1036
|
+
ie(i, c, d), p(d);
|
|
1026
1037
|
};
|
|
1027
1038
|
if (n.length == 0) {
|
|
1028
1039
|
if (l === "applyJsonPatch")
|
|
1029
1040
|
return (d) => {
|
|
1030
|
-
const t = o.getState().cogsStateStore[e], a =
|
|
1031
|
-
|
|
1041
|
+
const t = o.getState().cogsStateStore[e], a = Je(t, d).newDocument;
|
|
1042
|
+
Le(
|
|
1032
1043
|
e,
|
|
1033
1044
|
o.getState().initialStateGlobal[e],
|
|
1034
1045
|
a,
|
|
@@ -1038,57 +1049,57 @@ function he(e, i, m, g) {
|
|
|
1038
1049
|
);
|
|
1039
1050
|
const c = o.getState().stateComponents.get(e);
|
|
1040
1051
|
if (c) {
|
|
1041
|
-
const f =
|
|
1052
|
+
const f = _e(t, a), u = new Set(f);
|
|
1042
1053
|
for (const [
|
|
1043
|
-
|
|
1044
|
-
|
|
1054
|
+
E,
|
|
1055
|
+
y
|
|
1045
1056
|
] of c.components.entries()) {
|
|
1046
|
-
let
|
|
1047
|
-
const
|
|
1048
|
-
if (!
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1057
|
+
let w = !1;
|
|
1058
|
+
const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
1059
|
+
if (!C.includes("none")) {
|
|
1060
|
+
if (C.includes("all")) {
|
|
1061
|
+
y.forceUpdate();
|
|
1051
1062
|
continue;
|
|
1052
1063
|
}
|
|
1053
|
-
if (
|
|
1054
|
-
for (const
|
|
1055
|
-
if (
|
|
1056
|
-
|
|
1064
|
+
if (C.includes("component") && (y.paths.has("") && (w = !0), !w))
|
|
1065
|
+
for (const A of u) {
|
|
1066
|
+
if (y.paths.has(A)) {
|
|
1067
|
+
w = !0;
|
|
1057
1068
|
break;
|
|
1058
1069
|
}
|
|
1059
|
-
let
|
|
1060
|
-
for (;
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1063
|
-
|
|
1070
|
+
let M = A.lastIndexOf(".");
|
|
1071
|
+
for (; M !== -1; ) {
|
|
1072
|
+
const F = A.substring(0, M);
|
|
1073
|
+
if (y.paths.has(F)) {
|
|
1074
|
+
w = !0;
|
|
1064
1075
|
break;
|
|
1065
1076
|
}
|
|
1066
|
-
const Y =
|
|
1067
|
-
|
|
1077
|
+
const Y = A.substring(
|
|
1078
|
+
M + 1
|
|
1068
1079
|
);
|
|
1069
1080
|
if (!isNaN(Number(Y))) {
|
|
1070
|
-
const
|
|
1071
|
-
if (
|
|
1072
|
-
const
|
|
1081
|
+
const x = F.lastIndexOf(".");
|
|
1082
|
+
if (x !== -1) {
|
|
1083
|
+
const $ = F.substring(
|
|
1073
1084
|
0,
|
|
1074
|
-
|
|
1085
|
+
x
|
|
1075
1086
|
);
|
|
1076
|
-
if (
|
|
1077
|
-
|
|
1087
|
+
if (y.paths.has($)) {
|
|
1088
|
+
w = !0;
|
|
1078
1089
|
break;
|
|
1079
1090
|
}
|
|
1080
1091
|
}
|
|
1081
1092
|
}
|
|
1082
|
-
|
|
1093
|
+
M = F.lastIndexOf(".");
|
|
1083
1094
|
}
|
|
1084
|
-
if (
|
|
1095
|
+
if (w) break;
|
|
1085
1096
|
}
|
|
1086
|
-
if (!
|
|
1087
|
-
const
|
|
1088
|
-
let
|
|
1089
|
-
typeof
|
|
1097
|
+
if (!w && C.includes("deps") && y.depsFunction) {
|
|
1098
|
+
const A = y.depsFunction(a);
|
|
1099
|
+
let M = !1;
|
|
1100
|
+
typeof A == "boolean" ? A && (M = !0) : J(y.deps, A) || (y.deps = A, M = !0), M && (w = !0);
|
|
1090
1101
|
}
|
|
1091
|
-
|
|
1102
|
+
w && y.forceUpdate();
|
|
1092
1103
|
}
|
|
1093
1104
|
}
|
|
1094
1105
|
}
|
|
@@ -1100,17 +1111,17 @@ function he(e, i, m, g) {
|
|
|
1100
1111
|
throw new Error("Zod schema not found");
|
|
1101
1112
|
if (!d?.key)
|
|
1102
1113
|
throw new Error("Validation key not found");
|
|
1103
|
-
|
|
1114
|
+
Q(d.key);
|
|
1104
1115
|
const r = o.getState().cogsStateStore[e];
|
|
1105
1116
|
try {
|
|
1106
1117
|
const a = o.getState().getValidationErrors(d.key);
|
|
1107
1118
|
a && a.length > 0 && a.forEach(([f]) => {
|
|
1108
|
-
f && f.startsWith(d.key) &&
|
|
1119
|
+
f && f.startsWith(d.key) && Q(f);
|
|
1109
1120
|
});
|
|
1110
1121
|
const c = d.zodSchema.safeParse(r);
|
|
1111
1122
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1112
|
-
const
|
|
1113
|
-
t(
|
|
1123
|
+
const E = u.path, y = u.message, w = [d.key, ...E].join(".");
|
|
1124
|
+
t(w, y);
|
|
1114
1125
|
}), ve(e), !1);
|
|
1115
1126
|
} catch (a) {
|
|
1116
1127
|
return console.error("Zod schema validation failed", a), !1;
|
|
@@ -1128,9 +1139,9 @@ function he(e, i, m, g) {
|
|
|
1128
1139
|
if (l === "_isLoading")
|
|
1129
1140
|
return o.getState().isLoadingGlobal[e];
|
|
1130
1141
|
if (l === "revertToInitialState")
|
|
1131
|
-
return
|
|
1132
|
-
if (l === "updateInitialState") return
|
|
1133
|
-
if (l === "removeValidation") return
|
|
1142
|
+
return v.revertToInitialState;
|
|
1143
|
+
if (l === "updateInitialState") return v.updateInitialState;
|
|
1144
|
+
if (l === "removeValidation") return v.removeValidation;
|
|
1134
1145
|
}
|
|
1135
1146
|
if (l === "getFormRef")
|
|
1136
1147
|
return () => be.getState().getFormRef(e + "." + n.join("."));
|
|
@@ -1138,8 +1149,8 @@ function he(e, i, m, g) {
|
|
|
1138
1149
|
return ({
|
|
1139
1150
|
children: d,
|
|
1140
1151
|
hideMessage: t
|
|
1141
|
-
}) => /* @__PURE__ */
|
|
1142
|
-
|
|
1152
|
+
}) => /* @__PURE__ */ Oe(
|
|
1153
|
+
We,
|
|
1143
1154
|
{
|
|
1144
1155
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1145
1156
|
path: n,
|
|
@@ -1151,11 +1162,11 @@ function he(e, i, m, g) {
|
|
|
1151
1162
|
);
|
|
1152
1163
|
if (l === "_stateKey") return e;
|
|
1153
1164
|
if (l === "_path") return n;
|
|
1154
|
-
if (l === "_isServerSynced") return
|
|
1165
|
+
if (l === "_isServerSynced") return v._isServerSynced;
|
|
1155
1166
|
if (l === "update")
|
|
1156
1167
|
return (d, t) => {
|
|
1157
1168
|
if (t?.debounce)
|
|
1158
|
-
|
|
1169
|
+
Be(() => {
|
|
1159
1170
|
ie(i, d, n, "");
|
|
1160
1171
|
const r = o.getState().getNestedState(e, n);
|
|
1161
1172
|
t?.afterUpdate && t.afterUpdate(r);
|
|
@@ -1165,11 +1176,11 @@ function he(e, i, m, g) {
|
|
|
1165
1176
|
const r = o.getState().getNestedState(e, n);
|
|
1166
1177
|
t?.afterUpdate && t.afterUpdate(r);
|
|
1167
1178
|
}
|
|
1168
|
-
|
|
1179
|
+
p(n);
|
|
1169
1180
|
};
|
|
1170
1181
|
if (l === "formElement")
|
|
1171
|
-
return (d, t) => /* @__PURE__ */
|
|
1172
|
-
|
|
1182
|
+
return (d, t) => /* @__PURE__ */ Oe(
|
|
1183
|
+
ze,
|
|
1173
1184
|
{
|
|
1174
1185
|
setState: i,
|
|
1175
1186
|
stateKey: e,
|
|
@@ -1178,23 +1189,23 @@ function he(e, i, m, g) {
|
|
|
1178
1189
|
formOpts: t
|
|
1179
1190
|
}
|
|
1180
1191
|
);
|
|
1181
|
-
const
|
|
1182
|
-
return s(ae,
|
|
1192
|
+
const R = [...n, l], ae = o.getState().getNestedState(e, R);
|
|
1193
|
+
return s(ae, R, S);
|
|
1183
1194
|
}
|
|
1184
|
-
},
|
|
1185
|
-
return I.set(
|
|
1186
|
-
proxy:
|
|
1187
|
-
stateVersion:
|
|
1188
|
-
}),
|
|
1195
|
+
}, z = new Proxy(U, j);
|
|
1196
|
+
return I.set(W, {
|
|
1197
|
+
proxy: z,
|
|
1198
|
+
stateVersion: N
|
|
1199
|
+
}), z;
|
|
1189
1200
|
}
|
|
1190
1201
|
return s(
|
|
1191
1202
|
o.getState().getNestedState(e, [])
|
|
1192
1203
|
);
|
|
1193
1204
|
}
|
|
1194
1205
|
function Ve(e) {
|
|
1195
|
-
return le(
|
|
1206
|
+
return le(ot, { proxy: e });
|
|
1196
1207
|
}
|
|
1197
|
-
function
|
|
1208
|
+
function rt({
|
|
1198
1209
|
proxy: e,
|
|
1199
1210
|
rebuildStateShape: i
|
|
1200
1211
|
}) {
|
|
@@ -1203,26 +1214,26 @@ function nt({
|
|
|
1203
1214
|
m,
|
|
1204
1215
|
e._path
|
|
1205
1216
|
).stateMapNoRender(
|
|
1206
|
-
(I,
|
|
1217
|
+
(I, N, p, v, s) => e._mapFn(I, N, p, v, s)
|
|
1207
1218
|
) : null;
|
|
1208
1219
|
}
|
|
1209
|
-
function
|
|
1220
|
+
function ot({
|
|
1210
1221
|
proxy: e
|
|
1211
1222
|
}) {
|
|
1212
|
-
const i =
|
|
1223
|
+
const i = q(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1213
1224
|
return oe(() => {
|
|
1214
1225
|
const g = i.current;
|
|
1215
1226
|
if (!g || !g.parentElement) return;
|
|
1216
|
-
const I = g.parentElement,
|
|
1217
|
-
let
|
|
1218
|
-
|
|
1219
|
-
const
|
|
1227
|
+
const I = g.parentElement, p = Array.from(I.childNodes).indexOf(g);
|
|
1228
|
+
let v = I.getAttribute("data-parent-id");
|
|
1229
|
+
v || (v = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", v));
|
|
1230
|
+
const T = {
|
|
1220
1231
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1221
|
-
parentId:
|
|
1222
|
-
position:
|
|
1232
|
+
parentId: v,
|
|
1233
|
+
position: p,
|
|
1223
1234
|
effect: e._effect
|
|
1224
1235
|
};
|
|
1225
|
-
o.getState().addSignalElement(m,
|
|
1236
|
+
o.getState().addSignalElement(m, T);
|
|
1226
1237
|
const n = o.getState().getNestedState(e._stateKey, e._path);
|
|
1227
1238
|
let S;
|
|
1228
1239
|
if (e._effect)
|
|
@@ -1231,22 +1242,22 @@ function rt({
|
|
|
1231
1242
|
"state",
|
|
1232
1243
|
`return (${e._effect})(state)`
|
|
1233
1244
|
)(n);
|
|
1234
|
-
} catch (
|
|
1235
|
-
console.error("Error evaluating effect function during mount:",
|
|
1245
|
+
} catch (U) {
|
|
1246
|
+
console.error("Error evaluating effect function during mount:", U), S = n;
|
|
1236
1247
|
}
|
|
1237
1248
|
else
|
|
1238
1249
|
S = n;
|
|
1239
1250
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1240
|
-
const
|
|
1241
|
-
g.replaceWith(
|
|
1251
|
+
const W = document.createTextNode(String(S));
|
|
1252
|
+
g.replaceWith(W);
|
|
1242
1253
|
}, [e._stateKey, e._path.join("."), e._effect]), le("span", {
|
|
1243
1254
|
ref: i,
|
|
1244
1255
|
style: { display: "none" },
|
|
1245
1256
|
"data-signal-id": m
|
|
1246
1257
|
});
|
|
1247
1258
|
}
|
|
1248
|
-
function
|
|
1249
|
-
const i =
|
|
1259
|
+
function pt(e) {
|
|
1260
|
+
const i = je(
|
|
1250
1261
|
(m) => {
|
|
1251
1262
|
const g = o.getState().stateComponents.get(e._stateKey) || {
|
|
1252
1263
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1260,38 +1271,38 @@ function yt(e) {
|
|
|
1260
1271
|
);
|
|
1261
1272
|
return le("text", {}, String(i));
|
|
1262
1273
|
}
|
|
1263
|
-
function
|
|
1274
|
+
function at({
|
|
1264
1275
|
stateKey: e,
|
|
1265
1276
|
itemComponentId: i,
|
|
1266
1277
|
itemPath: m,
|
|
1267
1278
|
children: g
|
|
1268
1279
|
}) {
|
|
1269
|
-
const [, I] =
|
|
1280
|
+
const [, I] = K({}), [N, p] = Ye(), v = q(null);
|
|
1270
1281
|
return oe(() => {
|
|
1271
|
-
|
|
1282
|
+
p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(e, m, {
|
|
1272
1283
|
virtualizer: {
|
|
1273
|
-
itemHeight:
|
|
1284
|
+
itemHeight: p.height
|
|
1274
1285
|
}
|
|
1275
1286
|
}));
|
|
1276
|
-
}, [
|
|
1277
|
-
const s = `${e}////${i}`,
|
|
1287
|
+
}, [p.height, e, m]), ce(() => {
|
|
1288
|
+
const s = `${e}////${i}`, T = o.getState().stateComponents.get(e) || {
|
|
1278
1289
|
components: /* @__PURE__ */ new Map()
|
|
1279
1290
|
};
|
|
1280
|
-
return
|
|
1291
|
+
return T.components.set(s, {
|
|
1281
1292
|
forceUpdate: () => I({}),
|
|
1282
1293
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1283
|
-
}), o.getState().stateComponents.set(e,
|
|
1294
|
+
}), o.getState().stateComponents.set(e, T), () => {
|
|
1284
1295
|
const n = o.getState().stateComponents.get(e);
|
|
1285
1296
|
n && n.components.delete(s);
|
|
1286
1297
|
};
|
|
1287
|
-
}, [e, i, m.join(".")]), /* @__PURE__ */
|
|
1298
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ Oe("div", { ref: N, children: g });
|
|
1288
1299
|
}
|
|
1289
1300
|
export {
|
|
1290
1301
|
Ve as $cogsSignal,
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1302
|
+
pt as $cogsSignalStore,
|
|
1303
|
+
It as addStateOptions,
|
|
1304
|
+
vt as createCogsState,
|
|
1305
|
+
yt as notifyComponent,
|
|
1306
|
+
nt as useCogsStateFn
|
|
1296
1307
|
};
|
|
1297
1308
|
//# sourceMappingURL=CogsState.jsx.map
|