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