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