cogsbox-state 0.5.369 → 0.5.370
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 +686 -663
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +113 -66
package/dist/CogsState.jsx
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
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 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
|
+
import { v4 as pe } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
14
|
-
const m =
|
|
15
|
-
g(
|
|
16
|
-
...
|
|
9
|
+
import { getGlobalStore as r, formRefStore as Oe } from "./store.js";
|
|
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
|
+
const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
|
|
15
|
+
g(e, {
|
|
16
|
+
...T,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
stateKey:
|
|
20
|
+
function Ne({
|
|
21
|
+
stateKey: e,
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g =
|
|
26
|
-
let
|
|
25
|
+
const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
|
|
26
|
+
let v = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const a in i)
|
|
29
|
-
p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (
|
|
30
|
-
!
|
|
31
|
-
|
|
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
|
|
34
|
-
return { initialState:
|
|
33
|
+
function dt(e, { formElements: i, validation: m }) {
|
|
34
|
+
return { initialState: e, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
let m =
|
|
38
|
-
const [g,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
36
|
+
const ut = (e, i) => {
|
|
37
|
+
let m = e;
|
|
38
|
+
const [g, T] = Ge(m);
|
|
39
|
+
(Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
|
|
40
|
+
T[v] = T[v] || {}, T[v].formElements = {
|
|
41
41
|
...i?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...i?.validation,
|
|
44
|
-
...
|
|
44
|
+
...T[v].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
47
|
-
}),
|
|
48
|
-
const
|
|
49
|
-
const [
|
|
50
|
-
|
|
51
|
-
stateKey:
|
|
46
|
+
}, re(v) || r.getState().setInitialStateOptions(v, T[v]);
|
|
47
|
+
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
|
+
const N = (v, a) => {
|
|
49
|
+
const [h] = X(a?.componentId ?? pe());
|
|
50
|
+
Ne({
|
|
51
|
+
stateKey: v,
|
|
52
52
|
options: a,
|
|
53
|
-
initialOptionsPart:
|
|
53
|
+
initialOptionsPart: T
|
|
54
54
|
});
|
|
55
|
-
const n =
|
|
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
|
-
stateKey:
|
|
58
|
+
stateKey: v,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: h,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
62
62
|
middleware: a?.middleware,
|
|
63
63
|
enabledSync: a?.enabledSync,
|
|
@@ -70,78 +70,78 @@ const Se = (t, i) => {
|
|
|
70
70
|
);
|
|
71
71
|
return L;
|
|
72
72
|
};
|
|
73
|
-
function p(
|
|
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:
|
|
76
|
+
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} =
|
|
78
|
+
setUpdaterState: fe,
|
|
79
|
+
setState: te,
|
|
80
|
+
getInitialOptions: re,
|
|
81
|
+
getKeyState: be,
|
|
82
|
+
getValidationErrors: Fe,
|
|
83
|
+
setStateLog: Be,
|
|
84
|
+
updateInitialStateGlobal: Ee,
|
|
85
|
+
addValidationError: We,
|
|
86
|
+
removeValidationError: Z,
|
|
87
|
+
setServerSyncActions: ze
|
|
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
|
|
96
|
-
if (
|
|
97
|
-
const p = `${g}-${i}-${
|
|
98
|
-
let
|
|
95
|
+
const N = Q(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
96
|
+
if (N && g) {
|
|
97
|
+
const p = `${g}-${i}-${N}`;
|
|
98
|
+
let v;
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
v = me(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
|
-
state:
|
|
104
|
+
state: e,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: T ?? v
|
|
107
|
+
}, h = Ue.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
|
-
JSON.stringify(
|
|
110
|
+
JSON.stringify(h.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
114
|
-
if (!
|
|
113
|
+
}, me = (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 =
|
|
123
|
-
if (
|
|
124
|
-
const
|
|
125
|
-
`${g}-${
|
|
121
|
+
}, qe = (e, i) => {
|
|
122
|
+
const m = r.getState().cogsStateStore[e], { sessionId: g } = ke(), T = Q(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
|
+
if (T && g) {
|
|
124
|
+
const N = me(
|
|
125
|
+
`${g}-${e}-${T}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
|
+
return te(e, N.state), Ie(e), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Me = (e, i, m, g, T, N) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
135
|
-
|
|
134
|
+
updaterState: Se(
|
|
135
|
+
e,
|
|
136
136
|
g,
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
T,
|
|
138
|
+
N
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
const i =
|
|
142
|
+
Ee(e, p.initialState), fe(e, p.updaterState), te(e, p.state);
|
|
143
|
+
}, Ie = (e) => {
|
|
144
|
+
const i = r.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 Se = (t, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
153
|
-
const m =
|
|
152
|
+
}, gt = (e, i) => {
|
|
153
|
+
const m = r.getState().stateComponents.get(e);
|
|
154
154
|
if (m) {
|
|
155
|
-
const g = `${
|
|
156
|
-
if ((
|
|
155
|
+
const g = `${e}////${i}`, T = m.components.get(g);
|
|
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
|
+
}, Je = (e, i, m, g) => {
|
|
161
|
+
switch (e) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
164
|
oldValue: q(i, g),
|
|
@@ -180,327 +180,327 @@ const Se = (t, 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
|
-
formElements:
|
|
188
|
-
reactiveDeps:
|
|
187
|
+
formElements: T,
|
|
188
|
+
reactiveDeps: N,
|
|
189
189
|
reactiveType: p,
|
|
190
|
-
componentId:
|
|
190
|
+
componentId: v,
|
|
191
191
|
initialState: a,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: h,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [
|
|
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
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
...
|
|
205
|
-
[
|
|
201
|
+
P.current = re(I) ?? null, oe(() => {
|
|
202
|
+
if (h && h.stateKey === I && h.path?.[0]) {
|
|
203
|
+
te(I, (o) => ({
|
|
204
|
+
...o,
|
|
205
|
+
[h.path[0]]: h.newValue
|
|
206
206
|
}));
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
207
|
+
const t = `${h.stateKey}:${h.path.join(".")}`;
|
|
208
|
+
r.getState().setSyncInfo(t, {
|
|
209
|
+
timeStamp: h.timeStamp,
|
|
210
|
+
userId: h.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [h]), oe(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
Ae(I, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const
|
|
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 w = a,
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
227
|
-
|
|
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
|
+
I,
|
|
228
228
|
a,
|
|
229
229
|
w,
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
ae,
|
|
231
|
+
ee.current,
|
|
232
232
|
R
|
|
233
|
-
),
|
|
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,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
240
|
+
]), ie(() => {
|
|
241
|
+
F && Ae(I, {
|
|
242
242
|
serverSync: m,
|
|
243
|
-
formElements:
|
|
243
|
+
formElements: T,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: P.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const
|
|
248
|
+
const t = `${I}////${ee.current}`, o = r.getState().stateComponents.get(I) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
|
-
return
|
|
251
|
+
return o.components.set(t, {
|
|
252
252
|
forceUpdate: () => L({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: N || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}),
|
|
258
|
-
|
|
257
|
+
}), r.getState().stateComponents.set(I, o), L({}), () => {
|
|
258
|
+
o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
262
|
-
if (Array.isArray(
|
|
263
|
-
const u = `${
|
|
264
|
-
|
|
261
|
+
const ae = (t, o, s, c) => {
|
|
262
|
+
if (Array.isArray(o)) {
|
|
263
|
+
const u = `${I}-${o.join(".")}`;
|
|
264
|
+
le.current.add(u);
|
|
265
265
|
}
|
|
266
|
-
const f =
|
|
267
|
-
|
|
268
|
-
const
|
|
266
|
+
const f = r.getState();
|
|
267
|
+
te(I, (u) => {
|
|
268
|
+
const E = Q(t) ? t(u) : t, w = `${I}-${o.join(".")}`;
|
|
269
269
|
if (w) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
270
|
+
let M = !1, y = f.signalDomElements.get(w);
|
|
271
|
+
if ((!y || y.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const V = o.slice(0, -1), b = q(E, V);
|
|
273
|
+
if (Array.isArray(b)) {
|
|
274
|
+
M = !0;
|
|
275
|
+
const A = `${I}-${V.join(".")}`;
|
|
276
|
+
y = f.signalDomElements.get(A);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (y) {
|
|
280
|
+
const V = M ? q(E, o.slice(0, -1)) : q(E, o);
|
|
281
|
+
y.forEach(({ parentId: b, position: A, effect: D }) => {
|
|
282
|
+
const G = document.querySelector(
|
|
283
|
+
`[data-parent-id="${b}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (G) {
|
|
286
|
+
const B = Array.from(G.childNodes);
|
|
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(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
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
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const C = f.stateComponents.get(I);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
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
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
314
|
+
b,
|
|
315
|
+
A
|
|
316
|
+
] of C.components.entries()) {
|
|
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
|
+
if (G.includes("all")) {
|
|
321
|
+
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (G.includes("component") && ((A.paths.has(V) || A.paths.has("")) && (D = !0), !D))
|
|
325
|
+
for (const B of y) {
|
|
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
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
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
|
-
const
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const $ = Date.now();
|
|
362
|
+
o = o.map((M, y) => {
|
|
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
|
-
|
|
370
|
-
|
|
369
|
+
E,
|
|
370
|
+
o
|
|
371
371
|
), J = {
|
|
372
|
-
timeStamp:
|
|
373
|
-
stateKey:
|
|
374
|
-
path:
|
|
372
|
+
timeStamp: $,
|
|
373
|
+
stateKey: I,
|
|
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(
|
|
382
|
+
f.updateShadowAtPath(I, o, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(
|
|
385
|
+
const M = o.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(I, M, j);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
f.removeShadowArrayElement(
|
|
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
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Be(I, (M) => {
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
398
|
+
return Array.from(V.values());
|
|
399
|
+
}), Ce(
|
|
400
|
+
E,
|
|
401
|
+
I,
|
|
402
|
+
P.current,
|
|
403
403
|
R
|
|
404
|
-
),
|
|
404
|
+
), P.current?.middleware && P.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: J
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
407
|
+
}), P.current?.serverSync) {
|
|
408
|
+
const M = f.serverState[I], y = P.current?.serverSync;
|
|
409
|
+
ze(I, {
|
|
410
|
+
syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: E }),
|
|
411
|
+
rollBackState: M,
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
419
|
+
r.getState().updaterState[I] || (fe(
|
|
420
|
+
I,
|
|
421
|
+
Se(
|
|
422
|
+
I,
|
|
423
|
+
ae,
|
|
424
|
+
ee.current,
|
|
425
425
|
R
|
|
426
426
|
)
|
|
427
|
-
),
|
|
428
|
-
const d =
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
427
|
+
), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] || Ee(I, e));
|
|
428
|
+
const d = ve(() => Se(
|
|
429
|
+
I,
|
|
430
|
+
ae,
|
|
431
|
+
ee.current,
|
|
432
432
|
R
|
|
433
|
-
), [
|
|
434
|
-
return [
|
|
433
|
+
), [I, R]);
|
|
434
|
+
return [be(I), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
437
|
-
const
|
|
438
|
-
let
|
|
439
|
-
const p = (
|
|
440
|
-
const n =
|
|
441
|
-
for (const [S] of
|
|
442
|
-
(S === n || S.startsWith(n + ".")) &&
|
|
443
|
-
|
|
444
|
-
},
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
436
|
+
function Se(e, i, m, g) {
|
|
437
|
+
const T = /* @__PURE__ */ new Map();
|
|
438
|
+
let N = 0;
|
|
439
|
+
const p = (h) => {
|
|
440
|
+
const n = h.join(".");
|
|
441
|
+
for (const [S] of T)
|
|
442
|
+
(S === n || S.startsWith(n + ".")) && T.delete(S);
|
|
443
|
+
N++;
|
|
444
|
+
}, v = {
|
|
445
|
+
removeValidation: (h) => {
|
|
446
|
+
h?.validationKey && Z(h.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
449
|
-
const n =
|
|
450
|
-
n?.key &&
|
|
451
|
-
const S =
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
return
|
|
448
|
+
revertToInitialState: (h) => {
|
|
449
|
+
const n = r.getState().getInitialOptions(e)?.validation;
|
|
450
|
+
n?.key && Z(n?.key), h?.validationKey && Z(h.validationKey);
|
|
451
|
+
const S = r.getState().initialStateGlobal[e];
|
|
452
|
+
r.getState().clearSelectedIndexesForState(e), T.clear(), N++;
|
|
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
|
+
const I = r.getState().stateComponents.get(e);
|
|
456
|
+
return I && I.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
462
|
-
const n =
|
|
463
|
-
|
|
460
|
+
updateInitialState: (h) => {
|
|
461
|
+
T.clear(), N++;
|
|
462
|
+
const n = Se(
|
|
463
|
+
e,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S =
|
|
468
|
-
return localStorage.getItem(R) && localStorage.removeItem(R),
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
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
|
+
I.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (F) => n.get()[F]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
|
-
_initialState:
|
|
479
|
-
_serverState:
|
|
480
|
-
_isLoading:
|
|
478
|
+
_initialState: r.getState().initialStateGlobal[e],
|
|
479
|
+
_serverState: r.getState().serverState[e],
|
|
480
|
+
_isLoading: r.getState().isLoadingGlobal[e],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const h = r.getState().serverState[e];
|
|
483
|
+
return !!(h && z(h, be(e)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function a(
|
|
487
|
-
const
|
|
488
|
-
|
|
486
|
+
function a(h, n = [], S) {
|
|
487
|
+
const H = n.map(String).join(".");
|
|
488
|
+
T.get(H);
|
|
489
489
|
const L = function() {
|
|
490
|
-
return
|
|
490
|
+
return r().getNestedState(e, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(
|
|
493
|
-
L[
|
|
492
|
+
Object.keys(v).forEach((I) => {
|
|
493
|
+
L[I] = v[I];
|
|
494
494
|
});
|
|
495
495
|
const R = {
|
|
496
|
-
apply(
|
|
496
|
+
apply(I, l, le) {
|
|
497
497
|
return console.log(
|
|
498
|
-
`PROXY APPLY TRAP HIT: stateKey=${
|
|
499
|
-
), console.trace("Apply trap stack trace"),
|
|
498
|
+
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
|
|
499
|
+
), console.trace("Apply trap stack trace"), r().getNestedState(e, n);
|
|
500
500
|
},
|
|
501
|
-
get(
|
|
502
|
-
S?.validIndices && !Array.isArray(
|
|
503
|
-
const
|
|
501
|
+
get(I, l) {
|
|
502
|
+
S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
|
|
503
|
+
const le = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,239 +523,262 @@ function mt(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
|
|
530
|
-
if (
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !le.has(l)) {
|
|
527
|
+
const d = `${e}////${m}`, t = r.getState().stateComponents.get(e);
|
|
528
|
+
if (t) {
|
|
529
|
+
const o = t.components.get(d);
|
|
530
|
+
if (o && !o.paths.has("")) {
|
|
531
531
|
const s = n.join(".");
|
|
532
532
|
let c = !0;
|
|
533
|
-
for (const f of
|
|
533
|
+
for (const f of o.paths)
|
|
534
534
|
if (s.startsWith(f) && (s === f || s[f.length] === ".")) {
|
|
535
535
|
c = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
538
|
-
c &&
|
|
538
|
+
c && o.paths.add(s);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
544
|
-
|
|
545
|
-
|
|
543
|
+
return () => ye(
|
|
544
|
+
r.getState().cogsStateStore[e],
|
|
545
|
+
r.getState().initialStateGlobal[e]
|
|
546
546
|
);
|
|
547
547
|
if (l === "sync" && n.length === 0)
|
|
548
548
|
return async function() {
|
|
549
|
-
const d =
|
|
550
|
-
if (!
|
|
551
|
-
return console.error(`No mutation defined for state key "${
|
|
552
|
-
const
|
|
549
|
+
const d = r.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 o = r.getState().getNestedState(e, []), s = d?.validation?.key;
|
|
553
553
|
try {
|
|
554
|
-
const c = await
|
|
554
|
+
const c = await t.action(o);
|
|
555
555
|
if (c && !c.success && c.errors && s) {
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
556
|
+
r.getState().removeValidationError(s), c.errors.forEach((u) => {
|
|
557
|
+
const E = [s, ...u.path].join(".");
|
|
558
|
+
r.getState().addValidationError(E, u.message);
|
|
559
559
|
});
|
|
560
|
-
const f =
|
|
560
|
+
const f = r.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 =
|
|
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
|
-
const d =
|
|
577
|
-
|
|
576
|
+
const d = r().getNestedState(
|
|
577
|
+
e,
|
|
578
578
|
n
|
|
579
|
-
),
|
|
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 =
|
|
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")
|
|
588
588
|
return () => {
|
|
589
|
-
const d =
|
|
589
|
+
const d = r.getState().getInitialOptions(e)?.validation;
|
|
590
590
|
if (!d?.key)
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
|
-
return
|
|
592
|
+
return r.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => S?.validIndices ?
|
|
596
|
-
item:
|
|
594
|
+
if (Array.isArray(h)) {
|
|
595
|
+
const d = () => S?.validIndices ? h.map((o, s) => ({
|
|
596
|
+
item: o,
|
|
597
597
|
originalIndex: S.validIndices[s]
|
|
598
|
-
})) :
|
|
599
|
-
item:
|
|
598
|
+
})) : r.getState().getNestedState(e, n).map((o, s) => ({
|
|
599
|
+
item: o,
|
|
600
600
|
originalIndex: s
|
|
601
601
|
}));
|
|
602
602
|
if (l === "getSelected")
|
|
603
603
|
return () => {
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
604
|
+
const t = r.getState().getSelectedIndex(e, n.join("."));
|
|
605
|
+
if (t !== void 0)
|
|
606
606
|
return a(
|
|
607
|
-
|
|
608
|
-
[...n,
|
|
607
|
+
h[t],
|
|
608
|
+
[...n, t.toString()],
|
|
609
609
|
S
|
|
610
610
|
);
|
|
611
611
|
};
|
|
612
612
|
if (l === "clearSelected")
|
|
613
613
|
return () => {
|
|
614
|
-
|
|
614
|
+
r.getState().clearSelectedIndex({ stateKey: e, path: n });
|
|
615
615
|
};
|
|
616
616
|
if (l === "getSelectedIndex")
|
|
617
|
-
return () =>
|
|
617
|
+
return () => r.getState().getSelectedIndex(e, n.join(".")) ?? -1;
|
|
618
618
|
if (l === "useVirtualView")
|
|
619
|
-
return (
|
|
619
|
+
return (t) => {
|
|
620
620
|
const {
|
|
621
|
-
itemHeight:
|
|
621
|
+
itemHeight: o = 50,
|
|
622
622
|
overscan: s = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} =
|
|
625
|
+
} = t, u = K(null), [E, w] = X({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
629
|
-
|
|
630
|
-
J((
|
|
631
|
-
}), [
|
|
632
|
-
const
|
|
633
|
-
|
|
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
|
+
}), [e]);
|
|
632
|
+
const M = r().getNestedState(
|
|
633
|
+
e,
|
|
634
634
|
n
|
|
635
|
-
),
|
|
636
|
-
const
|
|
637
|
-
let
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const Y =
|
|
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
|
-
|
|
647
|
-
|
|
646
|
+
y,
|
|
647
|
+
e,
|
|
648
648
|
n.join("."),
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(Y,
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
649
|
+
o,
|
|
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
|
-
}, [
|
|
661
|
-
|
|
662
|
-
const
|
|
663
|
-
if (!N) return;
|
|
664
|
-
const j = !B(
|
|
660
|
+
}, [E.startIndex, E.endIndex, M, y]);
|
|
661
|
+
ie(() => {
|
|
662
|
+
const O = !z(
|
|
665
663
|
f,
|
|
666
|
-
|
|
667
|
-
),
|
|
668
|
-
if (
|
|
669
|
-
console.log(
|
|
670
|
-
"EVENT: Chat changed. Resetting state and scrolling."
|
|
671
|
-
), O("SCROLLING_TO_BOTTOM");
|
|
664
|
+
x.current
|
|
665
|
+
), k = y > $.current;
|
|
666
|
+
if (O) {
|
|
667
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), C("IDLE_AT_TOP");
|
|
672
668
|
return;
|
|
673
669
|
}
|
|
674
|
-
|
|
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;
|
|
673
|
+
}, [y, ...f]), ie(() => {
|
|
674
|
+
const O = u.current;
|
|
675
|
+
if (!O) return;
|
|
676
|
+
let k;
|
|
677
|
+
if (_ === "IDLE_AT_TOP" && c && y > 0)
|
|
675
678
|
console.log(
|
|
676
|
-
"
|
|
677
|
-
),
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
let z;
|
|
681
|
-
if (A === "SCROLLING_TO_BOTTOM") {
|
|
682
|
-
const Z = b.current === 0 || j, lt = Z ? "auto" : "smooth";
|
|
679
|
+
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
680
|
+
), C("GETTING_HEIGHTS");
|
|
681
|
+
else if (_ === "GETTING_HEIGHTS")
|
|
683
682
|
console.log(
|
|
684
|
-
|
|
685
|
-
),
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}),
|
|
683
|
+
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
684
|
+
), w({
|
|
685
|
+
startIndex: Math.max(0, y - 10 - s),
|
|
686
|
+
endIndex: y
|
|
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"));
|
|
692
|
+
}, 100);
|
|
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
|
+
});
|
|
702
|
+
const W = setTimeout(
|
|
689
703
|
() => {
|
|
690
|
-
console.log(
|
|
704
|
+
console.log(
|
|
705
|
+
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
706
|
+
), C("LOCKED_AT_BOTTOM");
|
|
691
707
|
},
|
|
692
|
-
|
|
708
|
+
U === "smooth" ? 500 : 50
|
|
693
709
|
);
|
|
710
|
+
return () => clearTimeout(W);
|
|
694
711
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
712
|
+
return () => {
|
|
713
|
+
k && clearInterval(k);
|
|
714
|
+
};
|
|
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;
|
|
702
727
|
}
|
|
703
|
-
const
|
|
704
|
-
let
|
|
705
|
-
const
|
|
706
|
-
for (;
|
|
707
|
-
|
|
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++;
|
|
708
733
|
w({
|
|
709
|
-
startIndex:
|
|
710
|
-
endIndex: Math.min(
|
|
734
|
+
startIndex: we,
|
|
735
|
+
endIndex: Math.min(y, de + s)
|
|
711
736
|
});
|
|
712
737
|
};
|
|
713
|
-
return
|
|
738
|
+
return O.addEventListener("scroll", k, {
|
|
714
739
|
passive: !0
|
|
715
|
-
}),
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}, [E, _, A, ...f]);
|
|
719
|
-
const U = $t(() => {
|
|
740
|
+
}), () => O.removeEventListener("scroll", k);
|
|
741
|
+
}, [y, b, _]);
|
|
742
|
+
const D = _e(() => {
|
|
720
743
|
console.log(
|
|
721
744
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
722
|
-
),
|
|
723
|
-
}, []),
|
|
724
|
-
(
|
|
725
|
-
u.current &&
|
|
726
|
-
top:
|
|
727
|
-
behavior:
|
|
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
|
|
728
751
|
}));
|
|
729
752
|
},
|
|
730
|
-
[
|
|
731
|
-
),
|
|
753
|
+
[b]
|
|
754
|
+
), B = {
|
|
732
755
|
outer: {
|
|
733
756
|
ref: u,
|
|
734
757
|
style: { overflowY: "auto", height: "100%" }
|
|
735
758
|
},
|
|
736
759
|
inner: {
|
|
737
760
|
style: {
|
|
738
|
-
height: `${
|
|
761
|
+
height: `${V}px`,
|
|
739
762
|
position: "relative"
|
|
740
763
|
}
|
|
741
764
|
},
|
|
742
765
|
list: {
|
|
743
766
|
style: {
|
|
744
|
-
transform: `translateY(${
|
|
767
|
+
transform: `translateY(${b[E.startIndex] || 0}px)`
|
|
745
768
|
}
|
|
746
769
|
}
|
|
747
770
|
};
|
|
748
771
|
return {
|
|
749
|
-
virtualState:
|
|
750
|
-
virtualizerProps:
|
|
751
|
-
scrollToBottom:
|
|
752
|
-
scrollToIndex:
|
|
772
|
+
virtualState: A,
|
|
773
|
+
virtualizerProps: B,
|
|
774
|
+
scrollToBottom: D,
|
|
775
|
+
scrollToIndex: G
|
|
753
776
|
};
|
|
754
777
|
};
|
|
755
778
|
if (l === "stateSort")
|
|
756
|
-
return (
|
|
779
|
+
return (t) => {
|
|
757
780
|
const s = [...d()].sort(
|
|
758
|
-
(u,
|
|
781
|
+
(u, E) => t(u.item, E.item)
|
|
759
782
|
), c = s.map(({ item: u }) => u), f = {
|
|
760
783
|
...S,
|
|
761
784
|
validIndices: s.map(
|
|
@@ -765,9 +788,9 @@ function mt(t, i, m, g) {
|
|
|
765
788
|
return a(c, n, f);
|
|
766
789
|
};
|
|
767
790
|
if (l === "stateFilter")
|
|
768
|
-
return (
|
|
791
|
+
return (t) => {
|
|
769
792
|
const s = d().filter(
|
|
770
|
-
({ item: u },
|
|
793
|
+
({ item: u }, E) => t(u, E)
|
|
771
794
|
), c = s.map(({ item: u }) => u), f = {
|
|
772
795
|
...S,
|
|
773
796
|
validIndices: s.map(
|
|
@@ -777,73 +800,73 @@ function mt(t, i, m, g) {
|
|
|
777
800
|
return a(c, n, f);
|
|
778
801
|
};
|
|
779
802
|
if (l === "stateMap")
|
|
780
|
-
return (
|
|
781
|
-
const
|
|
782
|
-
return Array.isArray(
|
|
783
|
-
const u =
|
|
784
|
-
return
|
|
803
|
+
return (t) => {
|
|
804
|
+
const o = r.getState().getNestedState(e, n);
|
|
805
|
+
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
806
|
+
const u = o[c], E = [...n, c.toString()], w = a(u, E, S);
|
|
807
|
+
return t(u, w, {
|
|
785
808
|
register: () => {
|
|
786
|
-
const [,
|
|
787
|
-
|
|
788
|
-
const
|
|
809
|
+
const [, C] = X({}), $ = `${m}-${n.join(".")}-${c}`;
|
|
810
|
+
ie(() => {
|
|
811
|
+
const x = `${e}////${$}`, j = r.getState().stateComponents.get(e) || {
|
|
789
812
|
components: /* @__PURE__ */ new Map()
|
|
790
813
|
};
|
|
791
|
-
return
|
|
792
|
-
forceUpdate: () =>
|
|
793
|
-
paths: /* @__PURE__ */ new Set([
|
|
794
|
-
}),
|
|
795
|
-
const J =
|
|
796
|
-
J && J.components.delete(
|
|
814
|
+
return j.components.set(x, {
|
|
815
|
+
forceUpdate: () => C({}),
|
|
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);
|
|
797
820
|
};
|
|
798
|
-
}, [
|
|
821
|
+
}, [e, $]);
|
|
799
822
|
},
|
|
800
823
|
index: f,
|
|
801
824
|
originalIndex: c
|
|
802
825
|
});
|
|
803
826
|
}) : (console.warn(
|
|
804
827
|
`stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
|
|
805
|
-
|
|
828
|
+
o
|
|
806
829
|
), null);
|
|
807
830
|
};
|
|
808
831
|
if (l === "stateMapNoRender")
|
|
809
|
-
return (
|
|
832
|
+
return (t) => h.map((s, c) => {
|
|
810
833
|
let f;
|
|
811
834
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
812
|
-
const u = [...n, f.toString()],
|
|
813
|
-
return
|
|
835
|
+
const u = [...n, f.toString()], E = a(s, u, S);
|
|
836
|
+
return t(
|
|
814
837
|
s,
|
|
815
|
-
|
|
838
|
+
E,
|
|
816
839
|
c,
|
|
817
|
-
|
|
818
|
-
a(
|
|
840
|
+
h,
|
|
841
|
+
a(h, n, S)
|
|
819
842
|
);
|
|
820
843
|
});
|
|
821
844
|
if (l === "$stateMap")
|
|
822
|
-
return (
|
|
845
|
+
return (t) => ce(Ze, {
|
|
823
846
|
proxy: {
|
|
824
|
-
_stateKey:
|
|
847
|
+
_stateKey: e,
|
|
825
848
|
_path: n,
|
|
826
|
-
_mapFn:
|
|
849
|
+
_mapFn: t
|
|
827
850
|
// Pass the actual function, not string
|
|
828
851
|
},
|
|
829
852
|
rebuildStateShape: a
|
|
830
853
|
});
|
|
831
854
|
if (l === "stateList")
|
|
832
|
-
return (
|
|
833
|
-
const
|
|
834
|
-
return Array.isArray(
|
|
835
|
-
const u =
|
|
836
|
-
return
|
|
855
|
+
return (t) => {
|
|
856
|
+
const o = r.getState().getNestedState(e, n);
|
|
857
|
+
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
858
|
+
const u = o[c], E = [...n, c.toString()], w = a(u, E, S), _ = `${m}-${n.join(".")}-${c}`;
|
|
859
|
+
return ce(Qe, {
|
|
837
860
|
key: c,
|
|
838
|
-
stateKey:
|
|
839
|
-
itemComponentId:
|
|
840
|
-
itemPath:
|
|
841
|
-
children:
|
|
861
|
+
stateKey: e,
|
|
862
|
+
itemComponentId: _,
|
|
863
|
+
itemPath: E,
|
|
864
|
+
children: t(
|
|
842
865
|
u,
|
|
843
866
|
w,
|
|
844
867
|
f,
|
|
845
|
-
|
|
846
|
-
a(
|
|
868
|
+
o,
|
|
869
|
+
a(o, n, S)
|
|
847
870
|
)
|
|
848
871
|
});
|
|
849
872
|
}) : (console.warn(
|
|
@@ -851,358 +874,358 @@ function mt(t, i, m, g) {
|
|
|
851
874
|
), null);
|
|
852
875
|
};
|
|
853
876
|
if (l === "stateFlattenOn")
|
|
854
|
-
return (
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
const s =
|
|
858
|
-
(c) => c[
|
|
877
|
+
return (t) => {
|
|
878
|
+
const o = h;
|
|
879
|
+
T.clear(), N++;
|
|
880
|
+
const s = o.flatMap(
|
|
881
|
+
(c) => c[t] ?? []
|
|
859
882
|
);
|
|
860
883
|
return a(
|
|
861
884
|
s,
|
|
862
|
-
[...n, "[*]",
|
|
885
|
+
[...n, "[*]", t],
|
|
863
886
|
S
|
|
864
887
|
);
|
|
865
888
|
};
|
|
866
889
|
if (l === "index")
|
|
867
|
-
return (
|
|
868
|
-
const
|
|
869
|
-
return a(
|
|
890
|
+
return (t) => {
|
|
891
|
+
const o = h[t];
|
|
892
|
+
return a(o, [...n, t.toString()]);
|
|
870
893
|
};
|
|
871
894
|
if (l === "last")
|
|
872
895
|
return () => {
|
|
873
|
-
const
|
|
874
|
-
if (
|
|
875
|
-
const
|
|
896
|
+
const t = r.getState().getNestedState(e, n);
|
|
897
|
+
if (t.length === 0) return;
|
|
898
|
+
const o = t.length - 1, s = t[o], c = [...n, o.toString()];
|
|
876
899
|
return a(s, c);
|
|
877
900
|
};
|
|
878
901
|
if (l === "insert")
|
|
879
|
-
return (
|
|
880
|
-
|
|
902
|
+
return (t) => (p(n), he(i, t, n, e), a(
|
|
903
|
+
r.getState().getNestedState(e, n),
|
|
881
904
|
n
|
|
882
905
|
));
|
|
883
906
|
if (l === "uniqueInsert")
|
|
884
|
-
return (
|
|
885
|
-
const c =
|
|
907
|
+
return (t, o, s) => {
|
|
908
|
+
const c = r.getState().getNestedState(e, n), f = Q(t) ? t(c) : t;
|
|
886
909
|
let u = null;
|
|
887
910
|
if (!c.some((w) => {
|
|
888
|
-
if (
|
|
889
|
-
const
|
|
890
|
-
(
|
|
911
|
+
if (o) {
|
|
912
|
+
const C = o.every(
|
|
913
|
+
($) => z(w[$], f[$])
|
|
891
914
|
);
|
|
892
|
-
return
|
|
915
|
+
return C && (u = w), C;
|
|
893
916
|
}
|
|
894
|
-
const
|
|
895
|
-
return
|
|
917
|
+
const _ = z(w, f);
|
|
918
|
+
return _ && (u = w), _;
|
|
896
919
|
}))
|
|
897
|
-
p(n),
|
|
920
|
+
p(n), he(i, f, n, e);
|
|
898
921
|
else if (s && u) {
|
|
899
|
-
const w = s(u),
|
|
900
|
-
(
|
|
922
|
+
const w = s(u), _ = c.map(
|
|
923
|
+
(C) => z(C, u) ? w : C
|
|
901
924
|
);
|
|
902
|
-
p(n),
|
|
925
|
+
p(n), se(i, _, n);
|
|
903
926
|
}
|
|
904
927
|
};
|
|
905
928
|
if (l === "cut")
|
|
906
|
-
return (
|
|
907
|
-
if (!
|
|
908
|
-
return p(n),
|
|
909
|
-
|
|
929
|
+
return (t, o) => {
|
|
930
|
+
if (!o?.waitForSync)
|
|
931
|
+
return p(n), ge(i, n, e, t), a(
|
|
932
|
+
r.getState().getNestedState(e, n),
|
|
910
933
|
n
|
|
911
934
|
);
|
|
912
935
|
};
|
|
913
936
|
if (l === "cutByValue")
|
|
914
|
-
return (
|
|
915
|
-
for (let
|
|
916
|
-
|
|
937
|
+
return (t) => {
|
|
938
|
+
for (let o = 0; o < h.length; o++)
|
|
939
|
+
h[o] === t && ge(i, n, e, o);
|
|
917
940
|
};
|
|
918
941
|
if (l === "toggleByValue")
|
|
919
|
-
return (
|
|
920
|
-
const
|
|
921
|
-
|
|
942
|
+
return (t) => {
|
|
943
|
+
const o = h.findIndex((s) => s === t);
|
|
944
|
+
o > -1 ? ge(i, n, e, o) : he(i, t, n, e);
|
|
922
945
|
};
|
|
923
946
|
if (l === "stateFind")
|
|
924
|
-
return (
|
|
947
|
+
return (t) => {
|
|
925
948
|
const s = d().find(
|
|
926
|
-
({ item: f }, u) =>
|
|
949
|
+
({ item: f }, u) => t(f, u)
|
|
927
950
|
);
|
|
928
951
|
if (!s) return;
|
|
929
952
|
const c = [...n, s.originalIndex.toString()];
|
|
930
953
|
return a(s.item, c, S);
|
|
931
954
|
};
|
|
932
955
|
if (l === "findWith")
|
|
933
|
-
return (
|
|
956
|
+
return (t, o) => {
|
|
934
957
|
const c = d().find(
|
|
935
|
-
({ item: u }) => u[
|
|
958
|
+
({ item: u }) => u[t] === o
|
|
936
959
|
);
|
|
937
960
|
if (!c) return;
|
|
938
961
|
const f = [...n, c.originalIndex.toString()];
|
|
939
962
|
return a(c.item, f, S);
|
|
940
963
|
};
|
|
941
964
|
}
|
|
942
|
-
const
|
|
943
|
-
if (!isNaN(Number(
|
|
944
|
-
const d = n.slice(0, -1),
|
|
945
|
-
if (Array.isArray(
|
|
946
|
-
return () =>
|
|
965
|
+
const ee = n[n.length - 1];
|
|
966
|
+
if (!isNaN(Number(ee))) {
|
|
967
|
+
const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
|
|
968
|
+
if (Array.isArray(t) && l === "cut")
|
|
969
|
+
return () => ge(
|
|
947
970
|
i,
|
|
948
971
|
d,
|
|
949
|
-
|
|
950
|
-
Number(
|
|
972
|
+
e,
|
|
973
|
+
Number(ee)
|
|
951
974
|
);
|
|
952
975
|
}
|
|
953
976
|
if (l === "get")
|
|
954
977
|
return () => {
|
|
955
|
-
if (S?.validIndices && Array.isArray(
|
|
956
|
-
const d =
|
|
957
|
-
return S.validIndices.map((
|
|
978
|
+
if (S?.validIndices && Array.isArray(h)) {
|
|
979
|
+
const d = r.getState().getNestedState(e, n);
|
|
980
|
+
return S.validIndices.map((t) => d[t]);
|
|
958
981
|
}
|
|
959
|
-
return
|
|
982
|
+
return r.getState().getNestedState(e, n);
|
|
960
983
|
};
|
|
961
984
|
if (l === "$derive")
|
|
962
|
-
return (d) =>
|
|
963
|
-
_stateKey:
|
|
985
|
+
return (d) => $e({
|
|
986
|
+
_stateKey: e,
|
|
964
987
|
_path: n,
|
|
965
988
|
_effect: d.toString()
|
|
966
989
|
});
|
|
967
990
|
if (l === "$get")
|
|
968
|
-
return () =>
|
|
969
|
-
_stateKey:
|
|
991
|
+
return () => $e({
|
|
992
|
+
_stateKey: e,
|
|
970
993
|
_path: n
|
|
971
994
|
});
|
|
972
995
|
if (l === "lastSynced") {
|
|
973
|
-
const d = `${
|
|
974
|
-
return
|
|
996
|
+
const d = `${e}:${n.join(".")}`;
|
|
997
|
+
return r.getState().getSyncInfo(d);
|
|
975
998
|
}
|
|
976
999
|
if (l == "getLocalStorage")
|
|
977
|
-
return (d) =>
|
|
1000
|
+
return (d) => me(g + "-" + e + "-" + d);
|
|
978
1001
|
if (l === "_selected") {
|
|
979
|
-
const d = n.slice(0, -1),
|
|
980
|
-
return Array.isArray(
|
|
1002
|
+
const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
|
|
1003
|
+
return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(e, t) : void 0;
|
|
981
1004
|
}
|
|
982
1005
|
if (l === "setSelected")
|
|
983
1006
|
return (d) => {
|
|
984
|
-
const
|
|
985
|
-
d ?
|
|
986
|
-
const c =
|
|
987
|
-
|
|
1007
|
+
const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
|
|
1008
|
+
d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
|
|
1009
|
+
const c = r.getState().getNestedState(e, [...t]);
|
|
1010
|
+
se(i, c, t), p(t);
|
|
988
1011
|
};
|
|
989
1012
|
if (l === "toggleSelected")
|
|
990
1013
|
return () => {
|
|
991
|
-
const d = n.slice(0, -1),
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
s ===
|
|
1014
|
+
const d = n.slice(0, -1), t = Number(n[n.length - 1]), o = d.join("."), s = r.getState().getSelectedIndex(e, o);
|
|
1015
|
+
r.getState().setSelectedIndex(
|
|
1016
|
+
e,
|
|
1017
|
+
o,
|
|
1018
|
+
s === t ? void 0 : t
|
|
996
1019
|
);
|
|
997
|
-
const c =
|
|
998
|
-
|
|
1020
|
+
const c = r.getState().getNestedState(e, [...d]);
|
|
1021
|
+
se(i, c, d), p(d);
|
|
999
1022
|
};
|
|
1000
1023
|
if (n.length == 0) {
|
|
1001
1024
|
if (l === "applyJsonPatch")
|
|
1002
1025
|
return (d) => {
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1026
|
+
const t = r.getState().cogsStateStore[e], s = je(t, d).newDocument;
|
|
1027
|
+
Me(
|
|
1028
|
+
e,
|
|
1029
|
+
r.getState().initialStateGlobal[e],
|
|
1007
1030
|
s,
|
|
1008
1031
|
i,
|
|
1009
1032
|
m,
|
|
1010
1033
|
g
|
|
1011
1034
|
);
|
|
1012
|
-
const c =
|
|
1035
|
+
const c = r.getState().stateComponents.get(e);
|
|
1013
1036
|
if (c) {
|
|
1014
|
-
const f =
|
|
1037
|
+
const f = ye(t, s), u = new Set(f);
|
|
1015
1038
|
for (const [
|
|
1016
|
-
|
|
1039
|
+
E,
|
|
1017
1040
|
w
|
|
1018
1041
|
] of c.components.entries()) {
|
|
1019
|
-
let
|
|
1020
|
-
const
|
|
1021
|
-
if (!
|
|
1022
|
-
if (
|
|
1042
|
+
let _ = !1;
|
|
1043
|
+
const C = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
1044
|
+
if (!C.includes("none")) {
|
|
1045
|
+
if (C.includes("all")) {
|
|
1023
1046
|
w.forceUpdate();
|
|
1024
1047
|
continue;
|
|
1025
1048
|
}
|
|
1026
|
-
if (
|
|
1027
|
-
for (const
|
|
1028
|
-
if (w.paths.has(
|
|
1029
|
-
|
|
1049
|
+
if (C.includes("component") && (w.paths.has("") && (_ = !0), !_))
|
|
1050
|
+
for (const $ of u) {
|
|
1051
|
+
if (w.paths.has($)) {
|
|
1052
|
+
_ = !0;
|
|
1030
1053
|
break;
|
|
1031
1054
|
}
|
|
1032
|
-
let
|
|
1033
|
-
for (;
|
|
1034
|
-
const
|
|
1035
|
-
if (w.paths.has(
|
|
1036
|
-
|
|
1055
|
+
let x = $.lastIndexOf(".");
|
|
1056
|
+
for (; x !== -1; ) {
|
|
1057
|
+
const j = $.substring(0, x);
|
|
1058
|
+
if (w.paths.has(j)) {
|
|
1059
|
+
_ = !0;
|
|
1037
1060
|
break;
|
|
1038
1061
|
}
|
|
1039
|
-
const J =
|
|
1040
|
-
|
|
1062
|
+
const J = $.substring(
|
|
1063
|
+
x + 1
|
|
1041
1064
|
);
|
|
1042
1065
|
if (!isNaN(Number(J))) {
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
const
|
|
1066
|
+
const M = j.lastIndexOf(".");
|
|
1067
|
+
if (M !== -1) {
|
|
1068
|
+
const y = j.substring(
|
|
1046
1069
|
0,
|
|
1047
|
-
|
|
1070
|
+
M
|
|
1048
1071
|
);
|
|
1049
|
-
if (w.paths.has(
|
|
1050
|
-
|
|
1072
|
+
if (w.paths.has(y)) {
|
|
1073
|
+
_ = !0;
|
|
1051
1074
|
break;
|
|
1052
1075
|
}
|
|
1053
1076
|
}
|
|
1054
1077
|
}
|
|
1055
|
-
|
|
1078
|
+
x = j.lastIndexOf(".");
|
|
1056
1079
|
}
|
|
1057
|
-
if (
|
|
1080
|
+
if (_) break;
|
|
1058
1081
|
}
|
|
1059
|
-
if (!
|
|
1060
|
-
const
|
|
1061
|
-
let
|
|
1062
|
-
typeof
|
|
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);
|
|
1063
1086
|
}
|
|
1064
|
-
|
|
1087
|
+
_ && w.forceUpdate();
|
|
1065
1088
|
}
|
|
1066
1089
|
}
|
|
1067
1090
|
}
|
|
1068
1091
|
};
|
|
1069
1092
|
if (l === "validateZodSchema")
|
|
1070
1093
|
return () => {
|
|
1071
|
-
const d =
|
|
1094
|
+
const d = r.getState().getInitialOptions(e)?.validation, t = r.getState().addValidationError;
|
|
1072
1095
|
if (!d?.zodSchema)
|
|
1073
1096
|
throw new Error("Zod schema not found");
|
|
1074
1097
|
if (!d?.key)
|
|
1075
1098
|
throw new Error("Validation key not found");
|
|
1076
|
-
|
|
1077
|
-
const
|
|
1099
|
+
Z(d.key);
|
|
1100
|
+
const o = r.getState().cogsStateStore[e];
|
|
1078
1101
|
try {
|
|
1079
|
-
const s =
|
|
1102
|
+
const s = r.getState().getValidationErrors(d.key);
|
|
1080
1103
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1081
|
-
f && f.startsWith(d.key) &&
|
|
1104
|
+
f && f.startsWith(d.key) && Z(f);
|
|
1082
1105
|
});
|
|
1083
|
-
const c = d.zodSchema.safeParse(
|
|
1106
|
+
const c = d.zodSchema.safeParse(o);
|
|
1084
1107
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1087
|
-
}),
|
|
1108
|
+
const E = u.path, w = u.message, _ = [d.key, ...E].join(".");
|
|
1109
|
+
t(_, w);
|
|
1110
|
+
}), Ie(e), !1);
|
|
1088
1111
|
} catch (s) {
|
|
1089
1112
|
return console.error("Zod schema validation failed", s), !1;
|
|
1090
1113
|
}
|
|
1091
1114
|
};
|
|
1092
1115
|
if (l === "_componentId") return m;
|
|
1093
1116
|
if (l === "getComponents")
|
|
1094
|
-
return () =>
|
|
1117
|
+
return () => r().stateComponents.get(e);
|
|
1095
1118
|
if (l === "getAllFormRefs")
|
|
1096
|
-
return () =>
|
|
1119
|
+
return () => Oe.getState().getFormRefsByStateKey(e);
|
|
1097
1120
|
if (l === "_initialState")
|
|
1098
|
-
return
|
|
1121
|
+
return r.getState().initialStateGlobal[e];
|
|
1099
1122
|
if (l === "_serverState")
|
|
1100
|
-
return
|
|
1123
|
+
return r.getState().serverState[e];
|
|
1101
1124
|
if (l === "_isLoading")
|
|
1102
|
-
return
|
|
1125
|
+
return r.getState().isLoadingGlobal[e];
|
|
1103
1126
|
if (l === "revertToInitialState")
|
|
1104
|
-
return
|
|
1105
|
-
if (l === "updateInitialState") return
|
|
1106
|
-
if (l === "removeValidation") return
|
|
1127
|
+
return v.revertToInitialState;
|
|
1128
|
+
if (l === "updateInitialState") return v.updateInitialState;
|
|
1129
|
+
if (l === "removeValidation") return v.removeValidation;
|
|
1107
1130
|
}
|
|
1108
1131
|
if (l === "getFormRef")
|
|
1109
|
-
return () =>
|
|
1132
|
+
return () => Oe.getState().getFormRef(e + "." + n.join("."));
|
|
1110
1133
|
if (l === "validationWrapper")
|
|
1111
1134
|
return ({
|
|
1112
1135
|
children: d,
|
|
1113
|
-
hideMessage:
|
|
1114
|
-
}) => /* @__PURE__ */
|
|
1115
|
-
|
|
1136
|
+
hideMessage: t
|
|
1137
|
+
}) => /* @__PURE__ */ Te(
|
|
1138
|
+
Re,
|
|
1116
1139
|
{
|
|
1117
|
-
formOpts:
|
|
1140
|
+
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1118
1141
|
path: n,
|
|
1119
|
-
validationKey:
|
|
1120
|
-
stateKey:
|
|
1142
|
+
validationKey: r.getState().getInitialOptions(e)?.validation?.key || "",
|
|
1143
|
+
stateKey: e,
|
|
1121
1144
|
validIndices: S?.validIndices,
|
|
1122
1145
|
children: d
|
|
1123
1146
|
}
|
|
1124
1147
|
);
|
|
1125
|
-
if (l === "_stateKey") return
|
|
1148
|
+
if (l === "_stateKey") return e;
|
|
1126
1149
|
if (l === "_path") return n;
|
|
1127
|
-
if (l === "_isServerSynced") return
|
|
1150
|
+
if (l === "_isServerSynced") return v._isServerSynced;
|
|
1128
1151
|
if (l === "update")
|
|
1129
|
-
return (d,
|
|
1130
|
-
if (
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
},
|
|
1152
|
+
return (d, t) => {
|
|
1153
|
+
if (t?.debounce)
|
|
1154
|
+
Le(() => {
|
|
1155
|
+
se(i, d, n, "");
|
|
1156
|
+
const o = r.getState().getNestedState(e, n);
|
|
1157
|
+
t?.afterUpdate && t.afterUpdate(o);
|
|
1158
|
+
}, t.debounce);
|
|
1136
1159
|
else {
|
|
1137
|
-
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1160
|
+
se(i, d, n, "");
|
|
1161
|
+
const o = r.getState().getNestedState(e, n);
|
|
1162
|
+
t?.afterUpdate && t.afterUpdate(o);
|
|
1140
1163
|
}
|
|
1141
1164
|
p(n);
|
|
1142
1165
|
};
|
|
1143
1166
|
if (l === "formElement")
|
|
1144
|
-
return (d,
|
|
1145
|
-
|
|
1167
|
+
return (d, t) => /* @__PURE__ */ Te(
|
|
1168
|
+
De,
|
|
1146
1169
|
{
|
|
1147
1170
|
setState: i,
|
|
1148
|
-
stateKey:
|
|
1171
|
+
stateKey: e,
|
|
1149
1172
|
path: n,
|
|
1150
1173
|
child: d,
|
|
1151
|
-
formOpts:
|
|
1174
|
+
formOpts: t
|
|
1152
1175
|
}
|
|
1153
1176
|
);
|
|
1154
|
-
const
|
|
1155
|
-
return a(
|
|
1177
|
+
const P = [...n, l], ae = r.getState().getNestedState(e, P);
|
|
1178
|
+
return a(ae, P, S);
|
|
1156
1179
|
}
|
|
1157
|
-
},
|
|
1158
|
-
return
|
|
1159
|
-
proxy:
|
|
1160
|
-
stateVersion:
|
|
1161
|
-
}),
|
|
1180
|
+
}, F = new Proxy(L, R);
|
|
1181
|
+
return T.set(H, {
|
|
1182
|
+
proxy: F,
|
|
1183
|
+
stateVersion: N
|
|
1184
|
+
}), F;
|
|
1162
1185
|
}
|
|
1163
1186
|
return a(
|
|
1164
|
-
|
|
1187
|
+
r.getState().getNestedState(e, [])
|
|
1165
1188
|
);
|
|
1166
1189
|
}
|
|
1167
|
-
function
|
|
1168
|
-
return
|
|
1190
|
+
function $e(e) {
|
|
1191
|
+
return ce(Xe, { proxy: e });
|
|
1169
1192
|
}
|
|
1170
|
-
function
|
|
1171
|
-
proxy:
|
|
1193
|
+
function Ze({
|
|
1194
|
+
proxy: e,
|
|
1172
1195
|
rebuildStateShape: i
|
|
1173
1196
|
}) {
|
|
1174
|
-
const m =
|
|
1197
|
+
const m = r().getNestedState(e._stateKey, e._path);
|
|
1175
1198
|
return Array.isArray(m) ? i(
|
|
1176
1199
|
m,
|
|
1177
|
-
|
|
1200
|
+
e._path
|
|
1178
1201
|
).stateMapNoRender(
|
|
1179
|
-
(
|
|
1202
|
+
(T, N, p, v, a) => e._mapFn(T, N, p, v, a)
|
|
1180
1203
|
) : null;
|
|
1181
1204
|
}
|
|
1182
|
-
function
|
|
1183
|
-
proxy:
|
|
1205
|
+
function Xe({
|
|
1206
|
+
proxy: e
|
|
1184
1207
|
}) {
|
|
1185
|
-
const i =
|
|
1186
|
-
return
|
|
1208
|
+
const i = K(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1209
|
+
return oe(() => {
|
|
1187
1210
|
const g = i.current;
|
|
1188
1211
|
if (!g || !g.parentElement) return;
|
|
1189
|
-
const
|
|
1190
|
-
let
|
|
1191
|
-
|
|
1192
|
-
const
|
|
1212
|
+
const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
|
|
1213
|
+
let v = T.getAttribute("data-parent-id");
|
|
1214
|
+
v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
|
|
1215
|
+
const h = {
|
|
1193
1216
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1194
|
-
parentId:
|
|
1217
|
+
parentId: v,
|
|
1195
1218
|
position: p,
|
|
1196
|
-
effect:
|
|
1219
|
+
effect: e._effect
|
|
1197
1220
|
};
|
|
1198
|
-
|
|
1199
|
-
const n =
|
|
1221
|
+
r.getState().addSignalElement(m, h);
|
|
1222
|
+
const n = r.getState().getNestedState(e._stateKey, e._path);
|
|
1200
1223
|
let S;
|
|
1201
|
-
if (
|
|
1224
|
+
if (e._effect)
|
|
1202
1225
|
try {
|
|
1203
1226
|
S = new Function(
|
|
1204
1227
|
"state",
|
|
1205
|
-
`return (${
|
|
1228
|
+
`return (${e._effect})(state)`
|
|
1206
1229
|
)(n);
|
|
1207
1230
|
} catch (L) {
|
|
1208
1231
|
console.error("Error evaluating effect function during mount:", L), S = n;
|
|
@@ -1210,61 +1233,61 @@ function te({
|
|
|
1210
1233
|
else
|
|
1211
1234
|
S = n;
|
|
1212
1235
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1213
|
-
const
|
|
1214
|
-
g.replaceWith(
|
|
1215
|
-
}, [
|
|
1236
|
+
const H = document.createTextNode(String(S));
|
|
1237
|
+
g.replaceWith(H);
|
|
1238
|
+
}, [e._stateKey, e._path.join("."), e._effect]), ce("span", {
|
|
1216
1239
|
ref: i,
|
|
1217
1240
|
style: { display: "none" },
|
|
1218
1241
|
"data-signal-id": m
|
|
1219
1242
|
});
|
|
1220
1243
|
}
|
|
1221
|
-
function
|
|
1222
|
-
const i =
|
|
1244
|
+
function ft(e) {
|
|
1245
|
+
const i = Pe(
|
|
1223
1246
|
(m) => {
|
|
1224
|
-
const g =
|
|
1247
|
+
const g = r.getState().stateComponents.get(e._stateKey) || {
|
|
1225
1248
|
components: /* @__PURE__ */ new Map()
|
|
1226
1249
|
};
|
|
1227
|
-
return g.components.set(
|
|
1250
|
+
return g.components.set(e._stateKey, {
|
|
1228
1251
|
forceUpdate: m,
|
|
1229
|
-
paths: /* @__PURE__ */ new Set([
|
|
1230
|
-
}), () => g.components.delete(
|
|
1252
|
+
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
1253
|
+
}), () => g.components.delete(e._stateKey);
|
|
1231
1254
|
},
|
|
1232
|
-
() =>
|
|
1255
|
+
() => r.getState().getNestedState(e._stateKey, e._path)
|
|
1233
1256
|
);
|
|
1234
|
-
return
|
|
1257
|
+
return ce("text", {}, String(i));
|
|
1235
1258
|
}
|
|
1236
|
-
function
|
|
1237
|
-
stateKey:
|
|
1259
|
+
function Qe({
|
|
1260
|
+
stateKey: e,
|
|
1238
1261
|
itemComponentId: i,
|
|
1239
1262
|
itemPath: m,
|
|
1240
1263
|
children: g
|
|
1241
1264
|
}) {
|
|
1242
|
-
const [,
|
|
1243
|
-
return
|
|
1244
|
-
p.height > 0 && p.height !==
|
|
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, {
|
|
1245
1268
|
virtualizer: {
|
|
1246
1269
|
itemHeight: p.height
|
|
1247
1270
|
}
|
|
1248
1271
|
}));
|
|
1249
|
-
}, [p.height,
|
|
1250
|
-
const a = `${
|
|
1272
|
+
}, [p.height, e, m]), ie(() => {
|
|
1273
|
+
const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
|
|
1251
1274
|
components: /* @__PURE__ */ new Map()
|
|
1252
1275
|
};
|
|
1253
|
-
return
|
|
1254
|
-
forceUpdate: () =>
|
|
1276
|
+
return h.components.set(a, {
|
|
1277
|
+
forceUpdate: () => T({}),
|
|
1255
1278
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1256
|
-
}),
|
|
1257
|
-
const n =
|
|
1279
|
+
}), r.getState().stateComponents.set(e, h), () => {
|
|
1280
|
+
const n = r.getState().stateComponents.get(e);
|
|
1258
1281
|
n && n.components.delete(a);
|
|
1259
1282
|
};
|
|
1260
|
-
}, [
|
|
1283
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ Te("div", { ref: N, children: g });
|
|
1261
1284
|
}
|
|
1262
1285
|
export {
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1286
|
+
$e as $cogsSignal,
|
|
1287
|
+
ft as $cogsSignalStore,
|
|
1288
|
+
dt as addStateOptions,
|
|
1289
|
+
ut as createCogsState,
|
|
1290
|
+
gt as notifyComponent,
|
|
1291
|
+
Ye as useCogsStateFn
|
|
1269
1292
|
};
|
|
1270
1293
|
//# sourceMappingURL=CogsState.jsx.map
|