cogsbox-state 0.5.373 → 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 +565 -558
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +49 -11
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,49 +68,49 @@ const ft = (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
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
78
|
+
setUpdaterState: me,
|
|
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
|
}
|
|
113
|
-
},
|
|
113
|
+
}, he = (e) => {
|
|
114
114
|
if (!e) return null;
|
|
115
115
|
try {
|
|
116
116
|
const i = window.localStorage.getItem(e);
|
|
@@ -118,30 +118,30 @@ const ft = (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,30 +149,30 @@ const ft = (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 {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: Z(i, g),
|
|
165
|
+
newValue: Z(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: Z(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: Z(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,57 +180,57 @@ const ft = (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
|
-
P.current = re(
|
|
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 = P.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c =
|
|
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,
|
|
@@ -238,267 +238,267 @@ function Xe(e, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), ce(() => {
|
|
241
|
-
|
|
241
|
+
W && ke(T, {
|
|
242
242
|
serverSync: m,
|
|
243
|
-
formElements:
|
|
243
|
+
formElements: I,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
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 = `${
|
|
261
|
+
const ae = (t, r, s, c) => {
|
|
262
|
+
if (Array.isArray(r)) {
|
|
263
|
+
const u = `${T}-${r.join(".")}`;
|
|
264
264
|
de.current.add(u);
|
|
265
265
|
}
|
|
266
|
-
const f =
|
|
267
|
-
|
|
268
|
-
const E = K(t) ? t(u) : t,
|
|
269
|
-
if (
|
|
270
|
-
let M = !1,
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
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
|
+
if ((!C || C.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const V = r.slice(0, -1), R = Z(E, V);
|
|
273
|
+
if (Array.isArray(R)) {
|
|
274
274
|
M = !0;
|
|
275
|
-
const
|
|
276
|
-
|
|
275
|
+
const v = `${T}-${V.join(".")}`;
|
|
276
|
+
C = f.signalDomElements.get(v);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (C) {
|
|
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
|
|
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 || P.current?.validation?.key) &&
|
|
296
|
-
(c || P.current?.validation?.key) + "." +
|
|
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
|
|
298
|
+
const _ = r.slice(0, r.length - 1);
|
|
299
299
|
s.updateType === "cut" && P.current?.validation?.key && X(
|
|
300
|
-
P.current?.validation?.key + "." +
|
|
301
|
-
), s.updateType === "insert" && P.current?.validation?.key &&
|
|
302
|
-
P.current?.validation?.key + "." +
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
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 M =
|
|
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
|
|
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
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const se = j.lastIndexOf(".");
|
|
333
|
+
if (se !== -1) {
|
|
334
|
+
const ue = j.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
se
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(j.substring(se + 1))
|
|
340
|
+
) && v.paths.has(ue)) {
|
|
341
|
+
D = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
j = ue;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
j = "";
|
|
347
|
+
if (j === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (D) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!D && $.includes("deps") && v.depsFunction) {
|
|
353
|
+
const z = v.depsFunction(E);
|
|
354
|
+
let j = !1;
|
|
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
|
|
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
|
-
|
|
370
|
+
r
|
|
371
371
|
), Y = {
|
|
372
|
-
timeStamp:
|
|
373
|
-
stateKey:
|
|
374
|
-
path:
|
|
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 M =
|
|
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
|
|
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
|
-
|
|
401
|
+
T,
|
|
402
402
|
P.current,
|
|
403
|
-
|
|
403
|
+
G
|
|
404
404
|
), P.current?.middleware && P.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
407
|
}), P.current?.serverSync) {
|
|
408
|
-
const M = f.serverState[
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
408
|
+
const M = f.serverState[T], C = P.current?.serverSync;
|
|
409
|
+
Xe(T, {
|
|
410
|
+
syncKey: typeof C.syncKey == "string" ? C.syncKey : C.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
412
|
+
actionTimeStamp: Date.now() + (C.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
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
503
|
const de = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
@@ -524,40 +524,40 @@ function me(e, i, m, g) {
|
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
526
|
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !de.has(l)) {
|
|
527
|
-
const d = `${e}////${m}`, t =
|
|
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
|
-
return () =>
|
|
544
|
-
|
|
545
|
-
|
|
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 =
|
|
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 me(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,168 +611,175 @@ function me(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
|
-
}, [
|
|
660
|
+
}, [p.startIndex, p.endIndex, R, v]);
|
|
661
661
|
ce(() => {
|
|
662
|
-
const
|
|
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
|
-
), u.current = !1,
|
|
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
|
-
|
|
715
|
+
}, [N, v, $]), oe(() => {
|
|
716
|
+
const b = E.current;
|
|
717
|
+
if (!b) return;
|
|
718
|
+
const x = r / 2, B = () => {
|
|
719
|
+
if (k.current)
|
|
720
|
+
return;
|
|
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(
|
|
720
725
|
"USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
|
|
721
|
-
), u.current = !0,
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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;
|
|
727
734
|
}
|
|
728
|
-
const
|
|
729
|
-
let
|
|
730
|
-
const
|
|
731
|
-
for (;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
startIndex:
|
|
735
|
-
endIndex: Math.min(
|
|
735
|
+
const Ce = Math.max(0, ge - s);
|
|
736
|
+
let fe = Ce;
|
|
737
|
+
const Re = H + ve;
|
|
738
|
+
for (; fe < v && $[fe] < Re; )
|
|
739
|
+
fe++;
|
|
740
|
+
_({
|
|
741
|
+
startIndex: Ce,
|
|
742
|
+
endIndex: Math.min(v, fe + s)
|
|
736
743
|
});
|
|
737
744
|
};
|
|
738
|
-
return
|
|
745
|
+
return b.addEventListener("scroll", B, {
|
|
739
746
|
passive: !0
|
|
740
|
-
}), () =>
|
|
741
|
-
}, [
|
|
742
|
-
const
|
|
747
|
+
}), () => b.removeEventListener("scroll", B);
|
|
748
|
+
}, [v, $, N, r]);
|
|
749
|
+
const j = $e(() => {
|
|
743
750
|
console.log(
|
|
744
751
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
745
|
-
),
|
|
746
|
-
}, []),
|
|
747
|
-
(
|
|
748
|
-
E.current &&
|
|
749
|
-
top:
|
|
750
|
-
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
|
|
751
758
|
}));
|
|
752
759
|
},
|
|
753
|
-
[
|
|
754
|
-
),
|
|
760
|
+
[$]
|
|
761
|
+
), ue = {
|
|
755
762
|
outer: {
|
|
756
763
|
ref: E,
|
|
757
764
|
style: { overflowY: "auto", height: "100%" }
|
|
758
765
|
},
|
|
759
766
|
inner: {
|
|
760
767
|
style: {
|
|
761
|
-
height: `${
|
|
768
|
+
height: `${D}px`,
|
|
762
769
|
position: "relative"
|
|
763
770
|
}
|
|
764
771
|
},
|
|
765
772
|
list: {
|
|
766
773
|
style: {
|
|
767
|
-
transform: `translateY(${
|
|
774
|
+
transform: `translateY(${$[p.startIndex] || 0}px)`
|
|
768
775
|
}
|
|
769
776
|
}
|
|
770
777
|
};
|
|
771
778
|
return {
|
|
772
|
-
virtualState:
|
|
773
|
-
virtualizerProps:
|
|
774
|
-
scrollToBottom:
|
|
775
|
-
scrollToIndex:
|
|
779
|
+
virtualState: z,
|
|
780
|
+
virtualizerProps: ue,
|
|
781
|
+
scrollToBottom: j,
|
|
782
|
+
scrollToIndex: se
|
|
776
783
|
};
|
|
777
784
|
};
|
|
778
785
|
if (l === "stateSort")
|
|
@@ -801,31 +808,31 @@ function me(e, i, m, g) {
|
|
|
801
808
|
};
|
|
802
809
|
if (l === "stateMap")
|
|
803
810
|
return (t) => {
|
|
804
|
-
const
|
|
805
|
-
return Array.isArray(
|
|
806
|
-
const u =
|
|
807
|
-
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, {
|
|
808
815
|
register: () => {
|
|
809
|
-
const [,
|
|
816
|
+
const [, N] = Q({}), w = `${m}-${n.join(".")}-${c}`;
|
|
810
817
|
ce(() => {
|
|
811
|
-
const
|
|
818
|
+
const k = `${e}////${w}`, U = o.getState().stateComponents.get(e) || {
|
|
812
819
|
components: /* @__PURE__ */ new Map()
|
|
813
820
|
};
|
|
814
|
-
return U.components.set(
|
|
815
|
-
forceUpdate: () =>
|
|
821
|
+
return U.components.set(k, {
|
|
822
|
+
forceUpdate: () => N({}),
|
|
816
823
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
817
|
-
}),
|
|
818
|
-
const Y =
|
|
819
|
-
Y && Y.components.delete(
|
|
824
|
+
}), o.getState().stateComponents.set(e, U), () => {
|
|
825
|
+
const Y = o.getState().stateComponents.get(e);
|
|
826
|
+
Y && Y.components.delete(k);
|
|
820
827
|
};
|
|
821
|
-
}, [e,
|
|
828
|
+
}, [e, w]);
|
|
822
829
|
},
|
|
823
830
|
index: f,
|
|
824
831
|
originalIndex: c
|
|
825
832
|
});
|
|
826
833
|
}) : (console.warn(
|
|
827
834
|
`stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
|
|
828
|
-
|
|
835
|
+
r
|
|
829
836
|
), null);
|
|
830
837
|
};
|
|
831
838
|
if (l === "stateMapNoRender")
|
|
@@ -842,7 +849,7 @@ function me(e, i, m, g) {
|
|
|
842
849
|
);
|
|
843
850
|
});
|
|
844
851
|
if (l === "$stateMap")
|
|
845
|
-
return (t) => le(
|
|
852
|
+
return (t) => le(tt, {
|
|
846
853
|
proxy: {
|
|
847
854
|
_stateKey: e,
|
|
848
855
|
_path: n,
|
|
@@ -853,20 +860,20 @@ function me(e, i, m, g) {
|
|
|
853
860
|
});
|
|
854
861
|
if (l === "stateList")
|
|
855
862
|
return (t) => {
|
|
856
|
-
const
|
|
857
|
-
return Array.isArray(
|
|
858
|
-
const u =
|
|
859
|
-
return le(
|
|
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, {
|
|
860
867
|
key: c,
|
|
861
868
|
stateKey: e,
|
|
862
|
-
itemComponentId:
|
|
869
|
+
itemComponentId: _,
|
|
863
870
|
itemPath: E,
|
|
864
871
|
children: t(
|
|
865
872
|
u,
|
|
866
|
-
|
|
873
|
+
p,
|
|
867
874
|
f,
|
|
868
|
-
|
|
869
|
-
a(
|
|
875
|
+
r,
|
|
876
|
+
a(r, n, S)
|
|
870
877
|
)
|
|
871
878
|
});
|
|
872
879
|
}) : (console.warn(
|
|
@@ -875,9 +882,9 @@ function me(e, i, m, g) {
|
|
|
875
882
|
};
|
|
876
883
|
if (l === "stateFlattenOn")
|
|
877
884
|
return (t) => {
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
const s =
|
|
885
|
+
const r = h;
|
|
886
|
+
I.clear(), A++;
|
|
887
|
+
const s = r.flatMap(
|
|
881
888
|
(c) => c[t] ?? []
|
|
882
889
|
);
|
|
883
890
|
return a(
|
|
@@ -888,60 +895,60 @@ function me(e, i, m, g) {
|
|
|
888
895
|
};
|
|
889
896
|
if (l === "index")
|
|
890
897
|
return (t) => {
|
|
891
|
-
const
|
|
892
|
-
return a(
|
|
898
|
+
const r = h[t];
|
|
899
|
+
return a(r, [...n, t.toString()]);
|
|
893
900
|
};
|
|
894
901
|
if (l === "last")
|
|
895
902
|
return () => {
|
|
896
|
-
const t =
|
|
903
|
+
const t = o.getState().getNestedState(e, n);
|
|
897
904
|
if (t.length === 0) return;
|
|
898
|
-
const
|
|
905
|
+
const r = t.length - 1, s = t[r], c = [...n, r.toString()];
|
|
899
906
|
return a(s, c);
|
|
900
907
|
};
|
|
901
908
|
if (l === "insert")
|
|
902
|
-
return (t) => (
|
|
903
|
-
|
|
909
|
+
return (t) => (O(n), Oe(i, t, n, e), a(
|
|
910
|
+
o.getState().getNestedState(e, n),
|
|
904
911
|
n
|
|
905
912
|
));
|
|
906
913
|
if (l === "uniqueInsert")
|
|
907
|
-
return (t,
|
|
908
|
-
const c =
|
|
914
|
+
return (t, r, s) => {
|
|
915
|
+
const c = o.getState().getNestedState(e, n), f = K(t) ? t(c) : t;
|
|
909
916
|
let u = null;
|
|
910
|
-
if (!c.some((
|
|
911
|
-
if (
|
|
912
|
-
const
|
|
913
|
-
(
|
|
917
|
+
if (!c.some((p) => {
|
|
918
|
+
if (r) {
|
|
919
|
+
const N = r.every(
|
|
920
|
+
(w) => q(p[w], f[w])
|
|
914
921
|
);
|
|
915
|
-
return
|
|
922
|
+
return N && (u = p), N;
|
|
916
923
|
}
|
|
917
|
-
const
|
|
918
|
-
return
|
|
924
|
+
const _ = q(p, f);
|
|
925
|
+
return _ && (u = p), _;
|
|
919
926
|
}))
|
|
920
|
-
|
|
927
|
+
O(n), Oe(i, f, n, e);
|
|
921
928
|
else if (s && u) {
|
|
922
|
-
const
|
|
923
|
-
(
|
|
929
|
+
const p = s(u), _ = c.map(
|
|
930
|
+
(N) => q(N, u) ? p : N
|
|
924
931
|
);
|
|
925
|
-
|
|
932
|
+
O(n), ie(i, _, n);
|
|
926
933
|
}
|
|
927
934
|
};
|
|
928
935
|
if (l === "cut")
|
|
929
|
-
return (t,
|
|
930
|
-
if (!
|
|
931
|
-
return
|
|
932
|
-
|
|
936
|
+
return (t, r) => {
|
|
937
|
+
if (!r?.waitForSync)
|
|
938
|
+
return O(n), Se(i, n, e, t), a(
|
|
939
|
+
o.getState().getNestedState(e, n),
|
|
933
940
|
n
|
|
934
941
|
);
|
|
935
942
|
};
|
|
936
943
|
if (l === "cutByValue")
|
|
937
944
|
return (t) => {
|
|
938
|
-
for (let
|
|
939
|
-
h[
|
|
945
|
+
for (let r = 0; r < h.length; r++)
|
|
946
|
+
h[r] === t && Se(i, n, e, r);
|
|
940
947
|
};
|
|
941
948
|
if (l === "toggleByValue")
|
|
942
949
|
return (t) => {
|
|
943
|
-
const
|
|
944
|
-
|
|
950
|
+
const r = h.findIndex((s) => s === t);
|
|
951
|
+
r > -1 ? Se(i, n, e, r) : Oe(i, t, n, e);
|
|
945
952
|
};
|
|
946
953
|
if (l === "stateFind")
|
|
947
954
|
return (t) => {
|
|
@@ -953,9 +960,9 @@ function me(e, i, m, g) {
|
|
|
953
960
|
return a(s.item, c, S);
|
|
954
961
|
};
|
|
955
962
|
if (l === "findWith")
|
|
956
|
-
return (t,
|
|
963
|
+
return (t, r) => {
|
|
957
964
|
const c = d().find(
|
|
958
|
-
({ item: u }) => u[t] ===
|
|
965
|
+
({ item: u }) => u[t] === r
|
|
959
966
|
);
|
|
960
967
|
if (!c) return;
|
|
961
968
|
const f = [...n, c.originalIndex.toString()];
|
|
@@ -964,9 +971,9 @@ function me(e, i, m, g) {
|
|
|
964
971
|
}
|
|
965
972
|
const ee = n[n.length - 1];
|
|
966
973
|
if (!isNaN(Number(ee))) {
|
|
967
|
-
const d = n.slice(0, -1), t =
|
|
974
|
+
const d = n.slice(0, -1), t = o.getState().getNestedState(e, d);
|
|
968
975
|
if (Array.isArray(t) && l === "cut")
|
|
969
|
-
return () =>
|
|
976
|
+
return () => Se(
|
|
970
977
|
i,
|
|
971
978
|
d,
|
|
972
979
|
e,
|
|
@@ -976,170 +983,170 @@ function me(e, i, m, g) {
|
|
|
976
983
|
if (l === "get")
|
|
977
984
|
return () => {
|
|
978
985
|
if (S?.validIndices && Array.isArray(h)) {
|
|
979
|
-
const d =
|
|
986
|
+
const d = o.getState().getNestedState(e, n);
|
|
980
987
|
return S.validIndices.map((t) => d[t]);
|
|
981
988
|
}
|
|
982
|
-
return
|
|
989
|
+
return o.getState().getNestedState(e, n);
|
|
983
990
|
};
|
|
984
991
|
if (l === "$derive")
|
|
985
|
-
return (d) =>
|
|
992
|
+
return (d) => Pe({
|
|
986
993
|
_stateKey: e,
|
|
987
994
|
_path: n,
|
|
988
995
|
_effect: d.toString()
|
|
989
996
|
});
|
|
990
997
|
if (l === "$get")
|
|
991
|
-
return () =>
|
|
998
|
+
return () => Pe({
|
|
992
999
|
_stateKey: e,
|
|
993
1000
|
_path: n
|
|
994
1001
|
});
|
|
995
1002
|
if (l === "lastSynced") {
|
|
996
1003
|
const d = `${e}:${n.join(".")}`;
|
|
997
|
-
return
|
|
1004
|
+
return o.getState().getSyncInfo(d);
|
|
998
1005
|
}
|
|
999
1006
|
if (l == "getLocalStorage")
|
|
1000
|
-
return (d) =>
|
|
1007
|
+
return (d) => he(g + "-" + e + "-" + d);
|
|
1001
1008
|
if (l === "_selected") {
|
|
1002
|
-
const d = n.slice(0, -1), t = d.join("."),
|
|
1003
|
-
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;
|
|
1004
1011
|
}
|
|
1005
1012
|
if (l === "setSelected")
|
|
1006
1013
|
return (d) => {
|
|
1007
|
-
const t = n.slice(0, -1),
|
|
1008
|
-
d ?
|
|
1009
|
-
const c =
|
|
1010
|
-
ie(i, c, t),
|
|
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);
|
|
1011
1018
|
};
|
|
1012
1019
|
if (l === "toggleSelected")
|
|
1013
1020
|
return () => {
|
|
1014
|
-
const d = n.slice(0, -1), t = Number(n[n.length - 1]),
|
|
1015
|
-
|
|
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(
|
|
1016
1023
|
e,
|
|
1017
|
-
|
|
1024
|
+
r,
|
|
1018
1025
|
s === t ? void 0 : t
|
|
1019
1026
|
);
|
|
1020
|
-
const c =
|
|
1021
|
-
ie(i, c, d),
|
|
1027
|
+
const c = o.getState().getNestedState(e, [...d]);
|
|
1028
|
+
ie(i, c, d), O(d);
|
|
1022
1029
|
};
|
|
1023
1030
|
if (n.length == 0) {
|
|
1024
1031
|
if (l === "applyJsonPatch")
|
|
1025
1032
|
return (d) => {
|
|
1026
|
-
const t =
|
|
1027
|
-
|
|
1033
|
+
const t = o.getState().cogsStateStore[e], s = ze(t, d).newDocument;
|
|
1034
|
+
Ge(
|
|
1028
1035
|
e,
|
|
1029
|
-
|
|
1036
|
+
o.getState().initialStateGlobal[e],
|
|
1030
1037
|
s,
|
|
1031
1038
|
i,
|
|
1032
1039
|
m,
|
|
1033
1040
|
g
|
|
1034
1041
|
);
|
|
1035
|
-
const c =
|
|
1042
|
+
const c = o.getState().stateComponents.get(e);
|
|
1036
1043
|
if (c) {
|
|
1037
|
-
const f =
|
|
1044
|
+
const f = we(t, s), u = new Set(f);
|
|
1038
1045
|
for (const [
|
|
1039
1046
|
E,
|
|
1040
|
-
|
|
1047
|
+
p
|
|
1041
1048
|
] of c.components.entries()) {
|
|
1042
|
-
let
|
|
1043
|
-
const
|
|
1044
|
-
if (!
|
|
1045
|
-
if (
|
|
1046
|
-
|
|
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();
|
|
1047
1054
|
continue;
|
|
1048
1055
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
for (const
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
1056
|
+
if (N.includes("component") && (p.paths.has("") && (_ = !0), !_))
|
|
1057
|
+
for (const w of u) {
|
|
1058
|
+
if (p.paths.has(w)) {
|
|
1059
|
+
_ = !0;
|
|
1053
1060
|
break;
|
|
1054
1061
|
}
|
|
1055
|
-
let
|
|
1056
|
-
for (;
|
|
1057
|
-
const U =
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1062
|
+
let k = w.lastIndexOf(".");
|
|
1063
|
+
for (; k !== -1; ) {
|
|
1064
|
+
const U = w.substring(0, k);
|
|
1065
|
+
if (p.paths.has(U)) {
|
|
1066
|
+
_ = !0;
|
|
1060
1067
|
break;
|
|
1061
1068
|
}
|
|
1062
|
-
const Y =
|
|
1063
|
-
|
|
1069
|
+
const Y = w.substring(
|
|
1070
|
+
k + 1
|
|
1064
1071
|
);
|
|
1065
1072
|
if (!isNaN(Number(Y))) {
|
|
1066
1073
|
const M = U.lastIndexOf(".");
|
|
1067
1074
|
if (M !== -1) {
|
|
1068
|
-
const
|
|
1075
|
+
const C = U.substring(
|
|
1069
1076
|
0,
|
|
1070
1077
|
M
|
|
1071
1078
|
);
|
|
1072
|
-
if (
|
|
1073
|
-
|
|
1079
|
+
if (p.paths.has(C)) {
|
|
1080
|
+
_ = !0;
|
|
1074
1081
|
break;
|
|
1075
1082
|
}
|
|
1076
1083
|
}
|
|
1077
1084
|
}
|
|
1078
|
-
|
|
1085
|
+
k = U.lastIndexOf(".");
|
|
1079
1086
|
}
|
|
1080
|
-
if (
|
|
1087
|
+
if (_) break;
|
|
1081
1088
|
}
|
|
1082
|
-
if (!
|
|
1083
|
-
const
|
|
1084
|
-
let
|
|
1085
|
-
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);
|
|
1086
1093
|
}
|
|
1087
|
-
|
|
1094
|
+
_ && p.forceUpdate();
|
|
1088
1095
|
}
|
|
1089
1096
|
}
|
|
1090
1097
|
}
|
|
1091
1098
|
};
|
|
1092
1099
|
if (l === "validateZodSchema")
|
|
1093
1100
|
return () => {
|
|
1094
|
-
const d =
|
|
1101
|
+
const d = o.getState().getInitialOptions(e)?.validation, t = o.getState().addValidationError;
|
|
1095
1102
|
if (!d?.zodSchema)
|
|
1096
1103
|
throw new Error("Zod schema not found");
|
|
1097
1104
|
if (!d?.key)
|
|
1098
1105
|
throw new Error("Validation key not found");
|
|
1099
1106
|
X(d.key);
|
|
1100
|
-
const
|
|
1107
|
+
const r = o.getState().cogsStateStore[e];
|
|
1101
1108
|
try {
|
|
1102
|
-
const s =
|
|
1109
|
+
const s = o.getState().getValidationErrors(d.key);
|
|
1103
1110
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1104
1111
|
f && f.startsWith(d.key) && X(f);
|
|
1105
1112
|
});
|
|
1106
|
-
const c = d.zodSchema.safeParse(
|
|
1113
|
+
const c = d.zodSchema.safeParse(r);
|
|
1107
1114
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1108
|
-
const E = u.path,
|
|
1109
|
-
t(
|
|
1110
|
-
}),
|
|
1115
|
+
const E = u.path, p = u.message, _ = [d.key, ...E].join(".");
|
|
1116
|
+
t(_, p);
|
|
1117
|
+
}), Ie(e), !1);
|
|
1111
1118
|
} catch (s) {
|
|
1112
1119
|
return console.error("Zod schema validation failed", s), !1;
|
|
1113
1120
|
}
|
|
1114
1121
|
};
|
|
1115
1122
|
if (l === "_componentId") return m;
|
|
1116
1123
|
if (l === "getComponents")
|
|
1117
|
-
return () =>
|
|
1124
|
+
return () => o().stateComponents.get(e);
|
|
1118
1125
|
if (l === "getAllFormRefs")
|
|
1119
|
-
return () =>
|
|
1126
|
+
return () => be.getState().getFormRefsByStateKey(e);
|
|
1120
1127
|
if (l === "_initialState")
|
|
1121
|
-
return
|
|
1128
|
+
return o.getState().initialStateGlobal[e];
|
|
1122
1129
|
if (l === "_serverState")
|
|
1123
|
-
return
|
|
1130
|
+
return o.getState().serverState[e];
|
|
1124
1131
|
if (l === "_isLoading")
|
|
1125
|
-
return
|
|
1132
|
+
return o.getState().isLoadingGlobal[e];
|
|
1126
1133
|
if (l === "revertToInitialState")
|
|
1127
|
-
return
|
|
1128
|
-
if (l === "updateInitialState") return
|
|
1129
|
-
if (l === "removeValidation") return
|
|
1134
|
+
return y.revertToInitialState;
|
|
1135
|
+
if (l === "updateInitialState") return y.updateInitialState;
|
|
1136
|
+
if (l === "removeValidation") return y.removeValidation;
|
|
1130
1137
|
}
|
|
1131
1138
|
if (l === "getFormRef")
|
|
1132
|
-
return () =>
|
|
1139
|
+
return () => be.getState().getFormRef(e + "." + n.join("."));
|
|
1133
1140
|
if (l === "validationWrapper")
|
|
1134
1141
|
return ({
|
|
1135
1142
|
children: d,
|
|
1136
1143
|
hideMessage: t
|
|
1137
|
-
}) => /* @__PURE__ */
|
|
1138
|
-
|
|
1144
|
+
}) => /* @__PURE__ */ Ee(
|
|
1145
|
+
Be,
|
|
1139
1146
|
{
|
|
1140
1147
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1141
1148
|
path: n,
|
|
1142
|
-
validationKey:
|
|
1149
|
+
validationKey: o.getState().getInitialOptions(e)?.validation?.key || "",
|
|
1143
1150
|
stateKey: e,
|
|
1144
1151
|
validIndices: S?.validIndices,
|
|
1145
1152
|
children: d
|
|
@@ -1147,25 +1154,25 @@ function me(e, i, m, g) {
|
|
|
1147
1154
|
);
|
|
1148
1155
|
if (l === "_stateKey") return e;
|
|
1149
1156
|
if (l === "_path") return n;
|
|
1150
|
-
if (l === "_isServerSynced") return
|
|
1157
|
+
if (l === "_isServerSynced") return y._isServerSynced;
|
|
1151
1158
|
if (l === "update")
|
|
1152
1159
|
return (d, t) => {
|
|
1153
1160
|
if (t?.debounce)
|
|
1154
|
-
|
|
1161
|
+
He(() => {
|
|
1155
1162
|
ie(i, d, n, "");
|
|
1156
|
-
const
|
|
1157
|
-
t?.afterUpdate && t.afterUpdate(
|
|
1163
|
+
const r = o.getState().getNestedState(e, n);
|
|
1164
|
+
t?.afterUpdate && t.afterUpdate(r);
|
|
1158
1165
|
}, t.debounce);
|
|
1159
1166
|
else {
|
|
1160
1167
|
ie(i, d, n, "");
|
|
1161
|
-
const
|
|
1162
|
-
t?.afterUpdate && t.afterUpdate(
|
|
1168
|
+
const r = o.getState().getNestedState(e, n);
|
|
1169
|
+
t?.afterUpdate && t.afterUpdate(r);
|
|
1163
1170
|
}
|
|
1164
|
-
|
|
1171
|
+
O(n);
|
|
1165
1172
|
};
|
|
1166
1173
|
if (l === "formElement")
|
|
1167
|
-
return (d, t) => /* @__PURE__ */
|
|
1168
|
-
|
|
1174
|
+
return (d, t) => /* @__PURE__ */ Ee(
|
|
1175
|
+
Fe,
|
|
1169
1176
|
{
|
|
1170
1177
|
setState: i,
|
|
1171
1178
|
stateKey: e,
|
|
@@ -1174,52 +1181,52 @@ function me(e, i, m, g) {
|
|
|
1174
1181
|
formOpts: t
|
|
1175
1182
|
}
|
|
1176
1183
|
);
|
|
1177
|
-
const P = [...n, l], ae =
|
|
1184
|
+
const P = [...n, l], ae = o.getState().getNestedState(e, P);
|
|
1178
1185
|
return a(ae, P, S);
|
|
1179
1186
|
}
|
|
1180
|
-
},
|
|
1181
|
-
return
|
|
1182
|
-
proxy:
|
|
1183
|
-
stateVersion:
|
|
1184
|
-
}),
|
|
1187
|
+
}, W = new Proxy(L, G);
|
|
1188
|
+
return I.set(F, {
|
|
1189
|
+
proxy: W,
|
|
1190
|
+
stateVersion: A
|
|
1191
|
+
}), W;
|
|
1185
1192
|
}
|
|
1186
1193
|
return a(
|
|
1187
|
-
|
|
1194
|
+
o.getState().getNestedState(e, [])
|
|
1188
1195
|
);
|
|
1189
1196
|
}
|
|
1190
|
-
function
|
|
1191
|
-
return le(
|
|
1197
|
+
function Pe(e) {
|
|
1198
|
+
return le(nt, { proxy: e });
|
|
1192
1199
|
}
|
|
1193
|
-
function
|
|
1200
|
+
function tt({
|
|
1194
1201
|
proxy: e,
|
|
1195
1202
|
rebuildStateShape: i
|
|
1196
1203
|
}) {
|
|
1197
|
-
const m =
|
|
1204
|
+
const m = o().getNestedState(e._stateKey, e._path);
|
|
1198
1205
|
return Array.isArray(m) ? i(
|
|
1199
1206
|
m,
|
|
1200
1207
|
e._path
|
|
1201
1208
|
).stateMapNoRender(
|
|
1202
|
-
(
|
|
1209
|
+
(I, A, O, y, a) => e._mapFn(I, A, O, y, a)
|
|
1203
1210
|
) : null;
|
|
1204
1211
|
}
|
|
1205
|
-
function
|
|
1212
|
+
function nt({
|
|
1206
1213
|
proxy: e
|
|
1207
1214
|
}) {
|
|
1208
|
-
const i =
|
|
1215
|
+
const i = J(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1209
1216
|
return oe(() => {
|
|
1210
1217
|
const g = i.current;
|
|
1211
1218
|
if (!g || !g.parentElement) return;
|
|
1212
|
-
const
|
|
1213
|
-
let
|
|
1214
|
-
|
|
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));
|
|
1215
1222
|
const h = {
|
|
1216
1223
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1217
|
-
parentId:
|
|
1218
|
-
position:
|
|
1224
|
+
parentId: y,
|
|
1225
|
+
position: O,
|
|
1219
1226
|
effect: e._effect
|
|
1220
1227
|
};
|
|
1221
|
-
|
|
1222
|
-
const n =
|
|
1228
|
+
o.getState().addSignalElement(m, h);
|
|
1229
|
+
const n = o.getState().getNestedState(e._stateKey, e._path);
|
|
1223
1230
|
let S;
|
|
1224
1231
|
if (e._effect)
|
|
1225
1232
|
try {
|
|
@@ -1227,24 +1234,24 @@ function Ke({
|
|
|
1227
1234
|
"state",
|
|
1228
1235
|
`return (${e._effect})(state)`
|
|
1229
1236
|
)(n);
|
|
1230
|
-
} catch (
|
|
1231
|
-
console.error("Error evaluating effect function during mount:",
|
|
1237
|
+
} catch (L) {
|
|
1238
|
+
console.error("Error evaluating effect function during mount:", L), S = n;
|
|
1232
1239
|
}
|
|
1233
1240
|
else
|
|
1234
1241
|
S = n;
|
|
1235
1242
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1236
|
-
const
|
|
1237
|
-
g.replaceWith(
|
|
1243
|
+
const F = document.createTextNode(String(S));
|
|
1244
|
+
g.replaceWith(F);
|
|
1238
1245
|
}, [e._stateKey, e._path.join("."), e._effect]), le("span", {
|
|
1239
1246
|
ref: i,
|
|
1240
1247
|
style: { display: "none" },
|
|
1241
1248
|
"data-signal-id": m
|
|
1242
1249
|
});
|
|
1243
1250
|
}
|
|
1244
|
-
function
|
|
1245
|
-
const i =
|
|
1251
|
+
function It(e) {
|
|
1252
|
+
const i = De(
|
|
1246
1253
|
(m) => {
|
|
1247
|
-
const g =
|
|
1254
|
+
const g = o.getState().stateComponents.get(e._stateKey) || {
|
|
1248
1255
|
components: /* @__PURE__ */ new Map()
|
|
1249
1256
|
};
|
|
1250
1257
|
return g.components.set(e._stateKey, {
|
|
@@ -1252,42 +1259,42 @@ function mt(e) {
|
|
|
1252
1259
|
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
1253
1260
|
}), () => g.components.delete(e._stateKey);
|
|
1254
1261
|
},
|
|
1255
|
-
() =>
|
|
1262
|
+
() => o.getState().getNestedState(e._stateKey, e._path)
|
|
1256
1263
|
);
|
|
1257
1264
|
return le("text", {}, String(i));
|
|
1258
1265
|
}
|
|
1259
|
-
function
|
|
1266
|
+
function rt({
|
|
1260
1267
|
stateKey: e,
|
|
1261
1268
|
itemComponentId: i,
|
|
1262
1269
|
itemPath: m,
|
|
1263
1270
|
children: g
|
|
1264
1271
|
}) {
|
|
1265
|
-
const [,
|
|
1272
|
+
const [, I] = Q({}), [A, O] = qe(), y = J(null);
|
|
1266
1273
|
return oe(() => {
|
|
1267
|
-
|
|
1274
|
+
O.height > 0 && O.height !== y.current && (y.current = O.height, o.getState().setShadowMetadata(e, m, {
|
|
1268
1275
|
virtualizer: {
|
|
1269
|
-
itemHeight:
|
|
1276
|
+
itemHeight: O.height
|
|
1270
1277
|
}
|
|
1271
1278
|
}));
|
|
1272
|
-
}, [
|
|
1273
|
-
const a = `${e}////${i}`, h =
|
|
1279
|
+
}, [O.height, e, m]), ce(() => {
|
|
1280
|
+
const a = `${e}////${i}`, h = o.getState().stateComponents.get(e) || {
|
|
1274
1281
|
components: /* @__PURE__ */ new Map()
|
|
1275
1282
|
};
|
|
1276
1283
|
return h.components.set(a, {
|
|
1277
|
-
forceUpdate: () =>
|
|
1284
|
+
forceUpdate: () => I({}),
|
|
1278
1285
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1279
|
-
}),
|
|
1280
|
-
const n =
|
|
1286
|
+
}), o.getState().stateComponents.set(e, h), () => {
|
|
1287
|
+
const n = o.getState().stateComponents.get(e);
|
|
1281
1288
|
n && n.components.delete(a);
|
|
1282
1289
|
};
|
|
1283
|
-
}, [e, i, m.join(".")]), /* @__PURE__ */
|
|
1290
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ Ee("div", { ref: A, children: g });
|
|
1284
1291
|
}
|
|
1285
1292
|
export {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1293
|
+
Pe as $cogsSignal,
|
|
1294
|
+
It as $cogsSignalStore,
|
|
1295
|
+
mt as addStateOptions,
|
|
1296
|
+
Tt as createCogsState,
|
|
1297
|
+
ht as notifyComponent,
|
|
1298
|
+
et as useCogsStateFn
|
|
1292
1299
|
};
|
|
1293
1300
|
//# sourceMappingURL=CogsState.jsx.map
|