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