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