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