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