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