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