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