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