cogsbox-state 0.5.281 → 0.5.283
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 +480 -481
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/store.js +65 -49
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +28 -34
- package/src/store.ts +33 -5
package/dist/CogsState.jsx
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { jsx as mt } from "react/jsx-runtime";
|
|
3
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
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
|
|
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
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
|
-
for (const
|
|
29
|
-
p.hasOwnProperty(
|
|
30
|
-
!L(p[
|
|
31
|
-
I &&
|
|
28
|
+
for (const a in c)
|
|
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
|
+
!L(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
|
|
31
|
+
I && k(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function oe(t, { formElements: c, validation: h }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: h };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
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,68 +43,68 @@ const oe = (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(
|
|
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
|
-
options:
|
|
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, [W, O] = Lt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
59
|
-
syncUpdate:
|
|
59
|
+
syncUpdate: a?.syncUpdate,
|
|
60
60
|
componentId: y,
|
|
61
|
-
localStorage:
|
|
62
|
-
middleware:
|
|
63
|
-
enabledSync:
|
|
64
|
-
reactiveType:
|
|
65
|
-
reactiveDeps:
|
|
66
|
-
initialState:
|
|
67
|
-
dependencies:
|
|
68
|
-
serverState:
|
|
61
|
+
localStorage: a?.localStorage,
|
|
62
|
+
middleware: a?.middleware,
|
|
63
|
+
enabledSync: a?.enabledSync,
|
|
64
|
+
reactiveType: a?.reactiveType,
|
|
65
|
+
reactiveDeps: a?.reactiveDeps,
|
|
66
|
+
initialState: a?.initialState,
|
|
67
|
+
dependencies: a?.dependencies,
|
|
68
|
+
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
71
|
return O;
|
|
72
72
|
};
|
|
73
|
-
function p(I,
|
|
74
|
-
wt({ stateKey: I, options:
|
|
73
|
+
function p(I, a) {
|
|
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:
|
|
82
|
+
getValidationErrors: Rt,
|
|
83
|
+
setStateLog: Ft,
|
|
84
84
|
updateInitialStateGlobal: vt,
|
|
85
|
-
addValidationError:
|
|
85
|
+
addValidationError: Ut,
|
|
86
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;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: v ?? I
|
|
107
|
-
}, y = Mt.serialize(
|
|
107
|
+
}, y = Mt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(y.json)
|
|
@@ -119,60 +119,60 @@ const oe = (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: z(c,
|
|
165
|
-
newValue: z(h,
|
|
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: z(h,
|
|
171
|
+
newValue: z(h, f)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue: z(c,
|
|
175
|
+
oldValue: z(c, f),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -183,19 +183,19 @@ const oe = (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
|
-
initialState:
|
|
191
|
+
initialState: a,
|
|
192
192
|
syncUpdate: y,
|
|
193
|
-
dependencies:
|
|
193
|
+
dependencies: r,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [m] = K(c ?? yt()), l =
|
|
196
|
+
const [W, O] = K({}), { sessionId: R } = $t();
|
|
197
|
+
let G = !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,182 +205,168 @@ 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
|
});
|
|
212
212
|
}
|
|
213
213
|
}, [y]), st(() => {
|
|
214
|
-
if (
|
|
214
|
+
if (a) {
|
|
215
215
|
pt(m, {
|
|
216
|
-
initialState:
|
|
216
|
+
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i =
|
|
219
|
-
if (!(i && !L(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
|
+
if (!(i && !L(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let w =
|
|
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
|
+
G && pt(m, {
|
|
242
242
|
serverSync: h,
|
|
243
243
|
formElements: v,
|
|
244
|
-
initialState:
|
|
245
|
-
localStorage:
|
|
244
|
+
initialState: a,
|
|
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
|
-
|
|
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
|
|
272
|
-
if (Array.isArray(
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
N =
|
|
272
|
+
const T = n.slice(0, -1), _ = z(E, T);
|
|
273
|
+
if (Array.isArray(_)) {
|
|
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
|
|
280
|
-
N.forEach(({ parentId:
|
|
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
|
-
`[data-parent-id="${
|
|
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 _ = r.getState();
|
|
296
|
-
switch (s.updateType) {
|
|
297
|
-
case "update":
|
|
298
|
-
_.updateShadowAtPath(m, n, d);
|
|
299
|
-
break;
|
|
300
|
-
case "insert":
|
|
301
|
-
const N = n.slice(0, -1);
|
|
302
|
-
_.insertShadowArrayElement(m, N);
|
|
303
|
-
break;
|
|
304
|
-
case "cut":
|
|
305
|
-
const A = n.slice(0, -1), P = parseInt(n[n.length - 1]);
|
|
306
|
-
_.removeShadowArrayElement(m, A, P);
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
})(), console.log("shadowState", r.getState().shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && n && H(
|
|
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
|
|
298
|
+
const $ = n.slice(0, n.length - 1);
|
|
313
299
|
s.updateType === "cut" && j.current?.validation?.key && H(
|
|
314
|
-
j.current?.validation?.key + "." +
|
|
315
|
-
), s.updateType === "insert" && j.current?.validation?.key &&
|
|
316
|
-
j.current?.validation?.key + "." +
|
|
317
|
-
).filter(([N,
|
|
318
|
-
let
|
|
319
|
-
if (N ==
|
|
320
|
-
let
|
|
321
|
-
H(N),
|
|
300
|
+
j.current?.validation?.key + "." + $.join(".")
|
|
301
|
+
), s.updateType === "insert" && j.current?.validation?.key && Rt(
|
|
302
|
+
j.current?.validation?.key + "." + $.join(".")
|
|
303
|
+
).filter(([N, T]) => {
|
|
304
|
+
let _ = N?.split(".").length;
|
|
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
|
-
|
|
329
|
-
|
|
314
|
+
_,
|
|
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
|
|
378
|
-
return N === n.length - 1 && ["insert", "cut"].includes(s.updateType) ? (
|
|
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
|
-
const { oldValue: V, newValue:
|
|
366
|
+
const { oldValue: V, newValue: D } = Gt(
|
|
381
367
|
s.updateType,
|
|
382
|
-
|
|
383
|
-
|
|
368
|
+
u,
|
|
369
|
+
E,
|
|
384
370
|
n
|
|
385
371
|
), B = {
|
|
386
372
|
timeStamp: C,
|
|
@@ -389,119 +375,132 @@ function Lt(t, {
|
|
|
389
375
|
updateType: s.updateType,
|
|
390
376
|
status: "new",
|
|
391
377
|
oldValue: V,
|
|
392
|
-
newValue:
|
|
378
|
+
newValue: D
|
|
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, D);
|
|
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
|
-
return Array.from(
|
|
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
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
446
|
y?.validationKey && H(y.validationKey);
|
|
448
447
|
},
|
|
449
448
|
revertToInitialState: (y) => {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
const S =
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const m =
|
|
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 W = a(S, []), O = Q(t), R = J(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, G = `${f}-${t}-${R}`;
|
|
454
|
+
G && localStorage.removeItem(G), ct(t, W), Z(t, S);
|
|
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
|
-
vt(t, y),
|
|
471
|
-
const
|
|
472
|
-
|
|
466
|
+
f
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = Q(t), O = J(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.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 G = o.getState().stateComponents.get(t);
|
|
471
|
+
G && G.components.forEach((m) => {
|
|
473
472
|
m.forceUpdate();
|
|
474
473
|
});
|
|
475
474
|
}), {
|
|
476
|
-
fetchId: (
|
|
475
|
+
fetchId: (G) => r.get()[G]
|
|
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
|
|
488
|
-
const
|
|
489
|
-
v.get(
|
|
486
|
+
function a(y, r = [], S) {
|
|
487
|
+
const W = r.map(String).join(".");
|
|
488
|
+
v.get(W);
|
|
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
|
|
497
|
-
apply(m, l,
|
|
495
|
+
const R = {
|
|
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 });
|
|
504
|
-
const
|
|
503
|
+
const ot = /* @__PURE__ */ new Set([
|
|
505
504
|
"insert",
|
|
506
505
|
"cut",
|
|
507
506
|
"cutByValue",
|
|
@@ -524,15 +523,15 @@ function lt(t, c, h, g) {
|
|
|
524
523
|
"_stateKey",
|
|
525
524
|
"getComponents"
|
|
526
525
|
]);
|
|
527
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
528
|
-
const
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ot.has(l)) {
|
|
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
|
}
|
|
@@ -542,25 +541,25 @@ function lt(t, c, h, g) {
|
|
|
542
541
|
}
|
|
543
542
|
if (l === "getDifferences")
|
|
544
543
|
return () => ht(
|
|
545
|
-
|
|
546
|
-
|
|
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,125 +568,125 @@ 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
|
-
return
|
|
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
|
});
|
|
629
|
-
ft((
|
|
630
|
-
const w = q(i),
|
|
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(
|
|
631
630
|
t,
|
|
632
|
-
|
|
633
|
-
), V = C.length,
|
|
634
|
-
const
|
|
635
|
-
{ length:
|
|
636
|
-
(b,
|
|
637
|
-
),
|
|
638
|
-
return
|
|
631
|
+
r
|
|
632
|
+
), V = C.length, D = Tt(() => {
|
|
633
|
+
const T = Math.max(0, u.startIndex), _ = Math.min(V, u.endIndex), A = Array.from(
|
|
634
|
+
{ length: _ - T },
|
|
635
|
+
(b, U) => T + U
|
|
636
|
+
), P = A.map((b) => C[b]);
|
|
637
|
+
return a(P, r, {
|
|
639
638
|
...S,
|
|
640
|
-
validIndices:
|
|
639
|
+
validIndices: A
|
|
641
640
|
});
|
|
642
|
-
}, [
|
|
641
|
+
}, [u.startIndex, u.endIndex, C, V]);
|
|
643
642
|
it(() => {
|
|
644
|
-
const
|
|
645
|
-
if (!
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
const
|
|
649
|
-
const { scrollTop: b, clientHeight:
|
|
650
|
-
w.current =
|
|
643
|
+
const T = g.current;
|
|
644
|
+
if (!T) return;
|
|
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;
|
|
651
650
|
const X = Math.max(
|
|
652
651
|
0,
|
|
653
652
|
Math.floor(b / n) - s
|
|
654
653
|
), et = Math.min(
|
|
655
654
|
V,
|
|
656
|
-
Math.ceil((b +
|
|
655
|
+
Math.ceil((b + U) / n) + s
|
|
657
656
|
);
|
|
658
|
-
|
|
657
|
+
E((gt) => gt.startIndex !== X || gt.endIndex !== et ? { startIndex: X, endIndex: et } : gt);
|
|
659
658
|
};
|
|
660
|
-
return
|
|
659
|
+
return T.addEventListener("scroll", P, {
|
|
661
660
|
passive: !0
|
|
662
|
-
}), i && (x.current ?
|
|
663
|
-
top:
|
|
661
|
+
}), i && (x.current ? T.scrollTo({
|
|
662
|
+
top: T.scrollHeight,
|
|
664
663
|
behavior: "auto"
|
|
665
|
-
}) :
|
|
666
|
-
|
|
667
|
-
top:
|
|
664
|
+
}) : _ && A && requestAnimationFrame(() => {
|
|
665
|
+
T.scrollTo({
|
|
666
|
+
top: T.scrollHeight,
|
|
668
667
|
behavior: "smooth"
|
|
669
668
|
});
|
|
670
|
-
})), x.current = !1,
|
|
669
|
+
})), x.current = !1, P(), () => T.removeEventListener("scroll", P);
|
|
671
670
|
}, [V, n, s, i]);
|
|
672
671
|
const B = ft(
|
|
673
|
-
(
|
|
674
|
-
|
|
675
|
-
top:
|
|
676
|
-
behavior:
|
|
672
|
+
(T = "smooth") => {
|
|
673
|
+
g.current && g.current.scrollTo({
|
|
674
|
+
top: g.current.scrollHeight,
|
|
675
|
+
behavior: T
|
|
677
676
|
});
|
|
678
677
|
},
|
|
679
678
|
[]
|
|
680
|
-
),
|
|
681
|
-
(
|
|
682
|
-
|
|
683
|
-
top:
|
|
684
|
-
behavior:
|
|
679
|
+
), M = ft(
|
|
680
|
+
(T, _ = "smooth") => {
|
|
681
|
+
g.current && g.current.scrollTo({
|
|
682
|
+
top: T * n,
|
|
683
|
+
behavior: _
|
|
685
684
|
});
|
|
686
685
|
},
|
|
687
686
|
[n]
|
|
688
687
|
), N = {
|
|
689
688
|
outer: {
|
|
690
|
-
ref:
|
|
689
|
+
ref: g,
|
|
691
690
|
style: { overflowY: "auto", height: "100%" }
|
|
692
691
|
},
|
|
693
692
|
inner: {
|
|
@@ -698,211 +697,211 @@ function lt(t, c, h, g) {
|
|
|
698
697
|
},
|
|
699
698
|
list: {
|
|
700
699
|
style: {
|
|
701
|
-
transform: `translateY(${
|
|
700
|
+
transform: `translateY(${u.startIndex * n}px)`
|
|
702
701
|
}
|
|
703
702
|
}
|
|
704
703
|
};
|
|
705
704
|
return {
|
|
706
|
-
virtualState:
|
|
705
|
+
virtualState: D,
|
|
707
706
|
virtualizerProps: N,
|
|
708
707
|
scrollToBottom: B,
|
|
709
|
-
scrollToIndex:
|
|
708
|
+
scrollToIndex: M
|
|
710
709
|
};
|
|
711
710
|
};
|
|
712
711
|
if (l === "stateSort")
|
|
713
712
|
return (e) => {
|
|
714
|
-
const s = [...
|
|
715
|
-
(
|
|
716
|
-
), 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 = {
|
|
717
716
|
...S,
|
|
718
717
|
validIndices: s.map(
|
|
719
|
-
({ originalIndex:
|
|
718
|
+
({ originalIndex: u }) => u
|
|
720
719
|
)
|
|
721
720
|
};
|
|
722
|
-
return
|
|
721
|
+
return a(i, r, g);
|
|
723
722
|
};
|
|
724
723
|
if (l === "stateFilter")
|
|
725
724
|
return (e) => {
|
|
726
|
-
const s =
|
|
727
|
-
({ item:
|
|
728
|
-
), i = s.map(({ item:
|
|
725
|
+
const s = d().filter(
|
|
726
|
+
({ item: u }, E) => e(u, E)
|
|
727
|
+
), i = s.map(({ item: u }) => u), g = {
|
|
729
728
|
...S,
|
|
730
729
|
validIndices: s.map(
|
|
731
|
-
({ originalIndex:
|
|
730
|
+
({ originalIndex: u }) => u
|
|
732
731
|
)
|
|
733
732
|
};
|
|
734
|
-
return
|
|
733
|
+
return a(i, r, g);
|
|
735
734
|
};
|
|
736
735
|
if (l === "stateMap")
|
|
737
736
|
return (e) => {
|
|
738
|
-
const n =
|
|
739
|
-
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i,
|
|
740
|
-
const
|
|
741
|
-
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, {
|
|
742
741
|
register: () => {
|
|
743
|
-
const [, x] = K({}), C = `${h}-${
|
|
742
|
+
const [, x] = K({}), C = `${h}-${r.join(".")}-${i}`;
|
|
744
743
|
it(() => {
|
|
745
|
-
const V = `${t}////${C}`,
|
|
744
|
+
const V = `${t}////${C}`, D = o.getState().stateComponents.get(t) || {
|
|
746
745
|
components: /* @__PURE__ */ new Map()
|
|
747
746
|
};
|
|
748
|
-
return
|
|
747
|
+
return D.components.set(V, {
|
|
749
748
|
forceUpdate: () => x({}),
|
|
750
|
-
paths: /* @__PURE__ */ new Set([
|
|
751
|
-
}),
|
|
752
|
-
const B =
|
|
749
|
+
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
750
|
+
}), o.getState().stateComponents.set(t, D), () => {
|
|
751
|
+
const B = o.getState().stateComponents.get(t);
|
|
753
752
|
B && B.components.delete(V);
|
|
754
753
|
};
|
|
755
754
|
}, [t, C]);
|
|
756
755
|
},
|
|
757
|
-
index:
|
|
756
|
+
index: g,
|
|
758
757
|
originalIndex: i
|
|
759
758
|
});
|
|
760
759
|
}) : (console.warn(
|
|
761
|
-
`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:`,
|
|
762
761
|
n
|
|
763
762
|
), null);
|
|
764
763
|
};
|
|
765
764
|
if (l === "stateMapNoRender")
|
|
766
765
|
return (e) => y.map((s, i) => {
|
|
767
|
-
let
|
|
768
|
-
S?.validIndices && S.validIndices[i] !== void 0 ?
|
|
769
|
-
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);
|
|
770
769
|
return e(
|
|
771
770
|
s,
|
|
772
|
-
|
|
771
|
+
E,
|
|
773
772
|
i,
|
|
774
773
|
y,
|
|
775
|
-
|
|
774
|
+
a(y, r, S)
|
|
776
775
|
);
|
|
777
776
|
});
|
|
778
777
|
if (l === "$stateMap")
|
|
779
778
|
return (e) => rt(zt, {
|
|
780
779
|
proxy: {
|
|
781
780
|
_stateKey: t,
|
|
782
|
-
_path:
|
|
781
|
+
_path: r,
|
|
783
782
|
_mapFn: e
|
|
784
783
|
// Pass the actual function, not string
|
|
785
784
|
},
|
|
786
|
-
rebuildStateShape:
|
|
785
|
+
rebuildStateShape: a
|
|
787
786
|
});
|
|
788
787
|
if (l === "stateList")
|
|
789
788
|
return (e) => {
|
|
790
|
-
const n =
|
|
791
|
-
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i,
|
|
792
|
-
const
|
|
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}`;
|
|
793
792
|
return rt(Ht, {
|
|
794
793
|
key: i,
|
|
795
794
|
stateKey: t,
|
|
796
|
-
itemComponentId:
|
|
797
|
-
itemPath:
|
|
795
|
+
itemComponentId: $,
|
|
796
|
+
itemPath: E,
|
|
798
797
|
children: e(
|
|
799
|
-
|
|
798
|
+
u,
|
|
800
799
|
w,
|
|
801
|
-
|
|
800
|
+
g,
|
|
802
801
|
n,
|
|
803
|
-
|
|
802
|
+
a(n, r, S)
|
|
804
803
|
)
|
|
805
804
|
});
|
|
806
805
|
}) : (console.warn(
|
|
807
|
-
`stateList called on a non-array value at path: ${
|
|
806
|
+
`stateList called on a non-array value at path: ${r.join(".")}.`
|
|
808
807
|
), null);
|
|
809
808
|
};
|
|
810
809
|
if (l === "stateFlattenOn")
|
|
811
810
|
return (e) => {
|
|
812
811
|
const n = y;
|
|
813
|
-
v.clear(),
|
|
812
|
+
v.clear(), k++;
|
|
814
813
|
const s = n.flatMap(
|
|
815
814
|
(i) => i[e] ?? []
|
|
816
815
|
);
|
|
817
|
-
return
|
|
816
|
+
return a(
|
|
818
817
|
s,
|
|
819
|
-
[...
|
|
818
|
+
[...r, "[*]", e],
|
|
820
819
|
S
|
|
821
820
|
);
|
|
822
821
|
};
|
|
823
822
|
if (l === "index")
|
|
824
823
|
return (e) => {
|
|
825
824
|
const n = y[e];
|
|
826
|
-
return
|
|
825
|
+
return a(n, [...r, e.toString()]);
|
|
827
826
|
};
|
|
828
827
|
if (l === "last")
|
|
829
828
|
return () => {
|
|
830
|
-
const e =
|
|
829
|
+
const e = o.getState().getNestedState(t, r);
|
|
831
830
|
if (e.length === 0) return;
|
|
832
|
-
const n = e.length - 1, s = e[n], i = [...
|
|
833
|
-
return
|
|
831
|
+
const n = e.length - 1, s = e[n], i = [...r, n.toString()];
|
|
832
|
+
return a(s, i);
|
|
834
833
|
};
|
|
835
834
|
if (l === "insert")
|
|
836
|
-
return (e) => (p(
|
|
837
|
-
|
|
838
|
-
|
|
835
|
+
return (e) => (p(r), St(c, e, r, t), a(
|
|
836
|
+
o.getState().getNestedState(t, r),
|
|
837
|
+
r
|
|
839
838
|
));
|
|
840
839
|
if (l === "uniqueInsert")
|
|
841
840
|
return (e, n, s) => {
|
|
842
|
-
const i =
|
|
843
|
-
let
|
|
841
|
+
const i = o.getState().getNestedState(t, r), g = J(e) ? e(i) : e;
|
|
842
|
+
let u = null;
|
|
844
843
|
if (!i.some((w) => {
|
|
845
844
|
if (n) {
|
|
846
845
|
const x = n.every(
|
|
847
|
-
(C) => L(w[C],
|
|
846
|
+
(C) => L(w[C], g[C])
|
|
848
847
|
);
|
|
849
|
-
return x && (
|
|
848
|
+
return x && (u = w), x;
|
|
850
849
|
}
|
|
851
|
-
const
|
|
852
|
-
return
|
|
850
|
+
const $ = L(w, g);
|
|
851
|
+
return $ && (u = w), $;
|
|
853
852
|
}))
|
|
854
|
-
p(
|
|
855
|
-
else if (s &&
|
|
856
|
-
const w = s(
|
|
857
|
-
(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
|
|
858
857
|
);
|
|
859
|
-
p(
|
|
858
|
+
p(r), nt(c, $, r);
|
|
860
859
|
}
|
|
861
860
|
};
|
|
862
861
|
if (l === "cut")
|
|
863
862
|
return (e, n) => {
|
|
864
863
|
if (!n?.waitForSync)
|
|
865
|
-
return p(
|
|
866
|
-
|
|
867
|
-
|
|
864
|
+
return p(r), at(c, r, t, e), a(
|
|
865
|
+
o.getState().getNestedState(t, r),
|
|
866
|
+
r
|
|
868
867
|
);
|
|
869
868
|
};
|
|
870
869
|
if (l === "cutByValue")
|
|
871
870
|
return (e) => {
|
|
872
871
|
for (let n = 0; n < y.length; n++)
|
|
873
|
-
y[n] === e &&
|
|
872
|
+
y[n] === e && at(c, r, t, n);
|
|
874
873
|
};
|
|
875
874
|
if (l === "toggleByValue")
|
|
876
875
|
return (e) => {
|
|
877
876
|
const n = y.findIndex((s) => s === e);
|
|
878
|
-
n > -1 ?
|
|
877
|
+
n > -1 ? at(c, r, t, n) : St(c, e, r, t);
|
|
879
878
|
};
|
|
880
879
|
if (l === "stateFind")
|
|
881
880
|
return (e) => {
|
|
882
|
-
const s =
|
|
883
|
-
({ item:
|
|
881
|
+
const s = d().find(
|
|
882
|
+
({ item: g }, u) => e(g, u)
|
|
884
883
|
);
|
|
885
884
|
if (!s) return;
|
|
886
|
-
const i = [...
|
|
887
|
-
return
|
|
885
|
+
const i = [...r, s.originalIndex.toString()];
|
|
886
|
+
return a(s.item, i, S);
|
|
888
887
|
};
|
|
889
888
|
if (l === "findWith")
|
|
890
889
|
return (e, n) => {
|
|
891
|
-
const i =
|
|
892
|
-
({ item:
|
|
890
|
+
const i = d().find(
|
|
891
|
+
({ item: u }) => u[e] === n
|
|
893
892
|
);
|
|
894
893
|
if (!i) return;
|
|
895
|
-
const
|
|
896
|
-
return
|
|
894
|
+
const g = [...r, i.originalIndex.toString()];
|
|
895
|
+
return a(i.item, g, S);
|
|
897
896
|
};
|
|
898
897
|
}
|
|
899
|
-
const Y =
|
|
898
|
+
const Y = r[r.length - 1];
|
|
900
899
|
if (!isNaN(Number(Y))) {
|
|
901
|
-
const
|
|
900
|
+
const d = r.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
902
901
|
if (Array.isArray(e) && l === "cut")
|
|
903
|
-
return () =>
|
|
902
|
+
return () => at(
|
|
904
903
|
c,
|
|
905
|
-
|
|
904
|
+
d,
|
|
906
905
|
t,
|
|
907
906
|
Number(Y)
|
|
908
907
|
);
|
|
@@ -910,137 +909,137 @@ function lt(t, c, h, g) {
|
|
|
910
909
|
if (l === "get")
|
|
911
910
|
return () => {
|
|
912
911
|
if (S?.validIndices && Array.isArray(y)) {
|
|
913
|
-
const
|
|
914
|
-
return S.validIndices.map((e) =>
|
|
912
|
+
const d = o.getState().getNestedState(t, r);
|
|
913
|
+
return S.validIndices.map((e) => d[e]);
|
|
915
914
|
}
|
|
916
|
-
return
|
|
915
|
+
return o.getState().getNestedState(t, r);
|
|
917
916
|
};
|
|
918
917
|
if (l === "$derive")
|
|
919
|
-
return (
|
|
918
|
+
return (d) => At({
|
|
920
919
|
_stateKey: t,
|
|
921
|
-
_path:
|
|
922
|
-
_effect:
|
|
920
|
+
_path: r,
|
|
921
|
+
_effect: d.toString()
|
|
923
922
|
});
|
|
924
923
|
if (l === "$get")
|
|
925
924
|
return () => At({
|
|
926
925
|
_stateKey: t,
|
|
927
|
-
_path:
|
|
926
|
+
_path: r
|
|
928
927
|
});
|
|
929
928
|
if (l === "lastSynced") {
|
|
930
|
-
const
|
|
931
|
-
return
|
|
929
|
+
const d = `${t}:${r.join(".")}`;
|
|
930
|
+
return o.getState().getSyncInfo(d);
|
|
932
931
|
}
|
|
933
932
|
if (l == "getLocalStorage")
|
|
934
|
-
return (
|
|
933
|
+
return (d) => dt(f + "-" + t + "-" + d);
|
|
935
934
|
if (l === "_selected") {
|
|
936
|
-
const
|
|
937
|
-
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;
|
|
938
937
|
}
|
|
939
938
|
if (l === "setSelected")
|
|
940
|
-
return (
|
|
941
|
-
const e =
|
|
942
|
-
|
|
943
|
-
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]);
|
|
944
943
|
nt(c, i, e), p(e);
|
|
945
944
|
};
|
|
946
945
|
if (l === "toggleSelected")
|
|
947
946
|
return () => {
|
|
948
|
-
const
|
|
949
|
-
|
|
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(
|
|
950
949
|
t,
|
|
951
950
|
n,
|
|
952
951
|
s === e ? void 0 : e
|
|
953
952
|
);
|
|
954
|
-
const i =
|
|
955
|
-
nt(c, i,
|
|
953
|
+
const i = o.getState().getNestedState(t, [...d]);
|
|
954
|
+
nt(c, i, d), p(d);
|
|
956
955
|
};
|
|
957
|
-
if (
|
|
956
|
+
if (r.length == 0) {
|
|
958
957
|
if (l === "applyJsonPatch")
|
|
959
|
-
return (
|
|
960
|
-
const e =
|
|
958
|
+
return (d) => {
|
|
959
|
+
const e = o.getState().cogsStateStore[t], s = jt(e, d).newDocument;
|
|
961
960
|
Nt(
|
|
962
961
|
t,
|
|
963
|
-
|
|
962
|
+
o.getState().initialStateGlobal[t],
|
|
964
963
|
s,
|
|
965
964
|
c,
|
|
966
965
|
h,
|
|
967
|
-
|
|
966
|
+
f
|
|
968
967
|
);
|
|
969
|
-
const i =
|
|
968
|
+
const i = o.getState().stateComponents.get(t);
|
|
970
969
|
if (i) {
|
|
971
|
-
const
|
|
970
|
+
const g = ht(e, s), u = new Set(g);
|
|
972
971
|
for (const [
|
|
973
|
-
|
|
972
|
+
E,
|
|
974
973
|
w
|
|
975
974
|
] of i.components.entries()) {
|
|
976
|
-
let
|
|
975
|
+
let $ = !1;
|
|
977
976
|
const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
978
977
|
if (!x.includes("none")) {
|
|
979
978
|
if (x.includes("all")) {
|
|
980
979
|
w.forceUpdate();
|
|
981
980
|
continue;
|
|
982
981
|
}
|
|
983
|
-
if (x.includes("component") && (w.paths.has("") && (
|
|
984
|
-
for (const C of
|
|
982
|
+
if (x.includes("component") && (w.paths.has("") && ($ = !0), !$))
|
|
983
|
+
for (const C of u) {
|
|
985
984
|
if (w.paths.has(C)) {
|
|
986
|
-
|
|
985
|
+
$ = !0;
|
|
987
986
|
break;
|
|
988
987
|
}
|
|
989
988
|
let V = C.lastIndexOf(".");
|
|
990
989
|
for (; V !== -1; ) {
|
|
991
|
-
const
|
|
992
|
-
if (w.paths.has(
|
|
993
|
-
|
|
990
|
+
const D = C.substring(0, V);
|
|
991
|
+
if (w.paths.has(D)) {
|
|
992
|
+
$ = !0;
|
|
994
993
|
break;
|
|
995
994
|
}
|
|
996
995
|
const B = C.substring(
|
|
997
996
|
V + 1
|
|
998
997
|
);
|
|
999
998
|
if (!isNaN(Number(B))) {
|
|
1000
|
-
const
|
|
1001
|
-
if (
|
|
1002
|
-
const N =
|
|
999
|
+
const M = D.lastIndexOf(".");
|
|
1000
|
+
if (M !== -1) {
|
|
1001
|
+
const N = D.substring(
|
|
1003
1002
|
0,
|
|
1004
|
-
|
|
1003
|
+
M
|
|
1005
1004
|
);
|
|
1006
1005
|
if (w.paths.has(N)) {
|
|
1007
|
-
|
|
1006
|
+
$ = !0;
|
|
1008
1007
|
break;
|
|
1009
1008
|
}
|
|
1010
1009
|
}
|
|
1011
1010
|
}
|
|
1012
|
-
V =
|
|
1011
|
+
V = D.lastIndexOf(".");
|
|
1013
1012
|
}
|
|
1014
|
-
if (
|
|
1013
|
+
if ($) break;
|
|
1015
1014
|
}
|
|
1016
|
-
if (
|
|
1015
|
+
if (!$ && x.includes("deps") && w.depsFunction) {
|
|
1017
1016
|
const C = w.depsFunction(s);
|
|
1018
1017
|
let V = !1;
|
|
1019
|
-
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);
|
|
1020
1019
|
}
|
|
1021
|
-
|
|
1020
|
+
$ && w.forceUpdate();
|
|
1022
1021
|
}
|
|
1023
1022
|
}
|
|
1024
1023
|
}
|
|
1025
1024
|
};
|
|
1026
1025
|
if (l === "validateZodSchema")
|
|
1027
1026
|
return () => {
|
|
1028
|
-
const
|
|
1029
|
-
if (!
|
|
1027
|
+
const d = o.getState().getInitialOptions(t)?.validation, e = o.getState().addValidationError;
|
|
1028
|
+
if (!d?.zodSchema)
|
|
1030
1029
|
throw new Error("Zod schema not found");
|
|
1031
|
-
if (!
|
|
1030
|
+
if (!d?.key)
|
|
1032
1031
|
throw new Error("Validation key not found");
|
|
1033
|
-
H(
|
|
1034
|
-
const n =
|
|
1032
|
+
H(d.key);
|
|
1033
|
+
const n = o.getState().cogsStateStore[t];
|
|
1035
1034
|
try {
|
|
1036
|
-
const s =
|
|
1037
|
-
s && s.length > 0 && s.forEach(([
|
|
1038
|
-
|
|
1035
|
+
const s = o.getState().getValidationErrors(d.key);
|
|
1036
|
+
s && s.length > 0 && s.forEach(([g]) => {
|
|
1037
|
+
g && g.startsWith(d.key) && H(g);
|
|
1039
1038
|
});
|
|
1040
|
-
const i =
|
|
1041
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
1042
|
-
const
|
|
1043
|
-
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);
|
|
1044
1043
|
}), ut(t), !1);
|
|
1045
1044
|
} catch (s) {
|
|
1046
1045
|
return console.error("Zod schema validation failed", s), !1;
|
|
@@ -1048,77 +1047,77 @@ function lt(t, c, h, g) {
|
|
|
1048
1047
|
};
|
|
1049
1048
|
if (l === "_componentId") return h;
|
|
1050
1049
|
if (l === "getComponents")
|
|
1051
|
-
return () =>
|
|
1050
|
+
return () => o().stateComponents.get(t);
|
|
1052
1051
|
if (l === "getAllFormRefs")
|
|
1053
1052
|
return () => It.getState().getFormRefsByStateKey(t);
|
|
1054
1053
|
if (l === "_initialState")
|
|
1055
|
-
return
|
|
1054
|
+
return o.getState().initialStateGlobal[t];
|
|
1056
1055
|
if (l === "_serverState")
|
|
1057
|
-
return
|
|
1056
|
+
return o.getState().serverState[t];
|
|
1058
1057
|
if (l === "_isLoading")
|
|
1059
|
-
return
|
|
1058
|
+
return o.getState().isLoadingGlobal[t];
|
|
1060
1059
|
if (l === "revertToInitialState")
|
|
1061
1060
|
return I.revertToInitialState;
|
|
1062
1061
|
if (l === "updateInitialState") return I.updateInitialState;
|
|
1063
1062
|
if (l === "removeValidation") return I.removeValidation;
|
|
1064
1063
|
}
|
|
1065
1064
|
if (l === "getFormRef")
|
|
1066
|
-
return () => It.getState().getFormRef(t + "." +
|
|
1065
|
+
return () => It.getState().getFormRef(t + "." + r.join("."));
|
|
1067
1066
|
if (l === "validationWrapper")
|
|
1068
1067
|
return ({
|
|
1069
|
-
children:
|
|
1068
|
+
children: d,
|
|
1070
1069
|
hideMessage: e
|
|
1071
1070
|
}) => /* @__PURE__ */ mt(
|
|
1072
1071
|
Pt,
|
|
1073
1072
|
{
|
|
1074
1073
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1075
|
-
path:
|
|
1076
|
-
validationKey:
|
|
1074
|
+
path: r,
|
|
1075
|
+
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1077
1076
|
stateKey: t,
|
|
1078
1077
|
validIndices: S?.validIndices,
|
|
1079
|
-
children:
|
|
1078
|
+
children: d
|
|
1080
1079
|
}
|
|
1081
1080
|
);
|
|
1082
1081
|
if (l === "_stateKey") return t;
|
|
1083
|
-
if (l === "_path") return
|
|
1082
|
+
if (l === "_path") return r;
|
|
1084
1083
|
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1085
1084
|
if (l === "update")
|
|
1086
|
-
return (
|
|
1085
|
+
return (d, e) => {
|
|
1087
1086
|
if (e?.debounce)
|
|
1088
1087
|
xt(() => {
|
|
1089
|
-
nt(c,
|
|
1090
|
-
const n =
|
|
1088
|
+
nt(c, d, r, "");
|
|
1089
|
+
const n = o.getState().getNestedState(t, r);
|
|
1091
1090
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1092
1091
|
}, e.debounce);
|
|
1093
1092
|
else {
|
|
1094
|
-
nt(c,
|
|
1095
|
-
const n =
|
|
1093
|
+
nt(c, d, r, "");
|
|
1094
|
+
const n = o.getState().getNestedState(t, r);
|
|
1096
1095
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1097
1096
|
}
|
|
1098
|
-
p(
|
|
1097
|
+
p(r);
|
|
1099
1098
|
};
|
|
1100
1099
|
if (l === "formElement")
|
|
1101
|
-
return (
|
|
1100
|
+
return (d, e) => /* @__PURE__ */ mt(
|
|
1102
1101
|
_t,
|
|
1103
1102
|
{
|
|
1104
1103
|
setState: c,
|
|
1105
1104
|
stateKey: t,
|
|
1106
|
-
path:
|
|
1107
|
-
child:
|
|
1105
|
+
path: r,
|
|
1106
|
+
child: d,
|
|
1108
1107
|
formOpts: e
|
|
1109
1108
|
}
|
|
1110
1109
|
);
|
|
1111
|
-
const j = [...
|
|
1112
|
-
return
|
|
1110
|
+
const j = [...r, l], tt = o.getState().getNestedState(t, j);
|
|
1111
|
+
return a(tt, j, S);
|
|
1113
1112
|
}
|
|
1114
|
-
},
|
|
1115
|
-
return v.set(
|
|
1116
|
-
proxy:
|
|
1117
|
-
stateVersion:
|
|
1118
|
-
}),
|
|
1113
|
+
}, G = new Proxy(O, R);
|
|
1114
|
+
return v.set(W, {
|
|
1115
|
+
proxy: G,
|
|
1116
|
+
stateVersion: k
|
|
1117
|
+
}), G;
|
|
1119
1118
|
}
|
|
1120
|
-
return
|
|
1121
|
-
|
|
1119
|
+
return a(
|
|
1120
|
+
o.getState().getNestedState(t, [])
|
|
1122
1121
|
);
|
|
1123
1122
|
}
|
|
1124
1123
|
function At(t) {
|
|
@@ -1128,12 +1127,12 @@ function zt({
|
|
|
1128
1127
|
proxy: t,
|
|
1129
1128
|
rebuildStateShape: c
|
|
1130
1129
|
}) {
|
|
1131
|
-
const h =
|
|
1130
|
+
const h = o().getNestedState(t._stateKey, t._path);
|
|
1132
1131
|
return Array.isArray(h) ? c(
|
|
1133
1132
|
h,
|
|
1134
1133
|
t._path
|
|
1135
1134
|
).stateMapNoRender(
|
|
1136
|
-
(v,
|
|
1135
|
+
(v, k, p, I, a) => t._mapFn(v, k, p, I, a)
|
|
1137
1136
|
) : null;
|
|
1138
1137
|
}
|
|
1139
1138
|
function Bt({
|
|
@@ -1141,9 +1140,9 @@ function Bt({
|
|
|
1141
1140
|
}) {
|
|
1142
1141
|
const c = q(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1143
1142
|
return st(() => {
|
|
1144
|
-
const
|
|
1145
|
-
if (!
|
|
1146
|
-
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);
|
|
1147
1146
|
let I = v.getAttribute("data-parent-id");
|
|
1148
1147
|
I || (I = `parent-${crypto.randomUUID()}`, v.setAttribute("data-parent-id", I));
|
|
1149
1148
|
const y = {
|
|
@@ -1152,23 +1151,23 @@ function Bt({
|
|
|
1152
1151
|
position: p,
|
|
1153
1152
|
effect: t._effect
|
|
1154
1153
|
};
|
|
1155
|
-
|
|
1156
|
-
const
|
|
1154
|
+
o.getState().addSignalElement(h, y);
|
|
1155
|
+
const r = o.getState().getNestedState(t._stateKey, t._path);
|
|
1157
1156
|
let S;
|
|
1158
1157
|
if (t._effect)
|
|
1159
1158
|
try {
|
|
1160
1159
|
S = new Function(
|
|
1161
1160
|
"state",
|
|
1162
1161
|
`return (${t._effect})(state)`
|
|
1163
|
-
)(
|
|
1162
|
+
)(r);
|
|
1164
1163
|
} catch (O) {
|
|
1165
|
-
console.error("Error evaluating effect function during mount:", O), S =
|
|
1164
|
+
console.error("Error evaluating effect function during mount:", O), S = r;
|
|
1166
1165
|
}
|
|
1167
1166
|
else
|
|
1168
|
-
S =
|
|
1167
|
+
S = r;
|
|
1169
1168
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1169
|
+
const W = document.createTextNode(String(S));
|
|
1170
|
+
f.replaceWith(W);
|
|
1172
1171
|
}, [t._stateKey, t._path.join("."), t._effect]), rt("span", {
|
|
1173
1172
|
ref: c,
|
|
1174
1173
|
style: { display: "none" },
|
|
@@ -1178,15 +1177,15 @@ function Bt({
|
|
|
1178
1177
|
function ie(t) {
|
|
1179
1178
|
const c = Ct(
|
|
1180
1179
|
(h) => {
|
|
1181
|
-
const
|
|
1180
|
+
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1182
1181
|
components: /* @__PURE__ */ new Map()
|
|
1183
1182
|
};
|
|
1184
|
-
return
|
|
1183
|
+
return f.components.set(t._stateKey, {
|
|
1185
1184
|
forceUpdate: h,
|
|
1186
1185
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1187
|
-
}), () =>
|
|
1186
|
+
}), () => f.components.delete(t._stateKey);
|
|
1188
1187
|
},
|
|
1189
|
-
() =>
|
|
1188
|
+
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1190
1189
|
);
|
|
1191
1190
|
return rt("text", {}, String(c));
|
|
1192
1191
|
}
|
|
@@ -1194,33 +1193,33 @@ function Ht({
|
|
|
1194
1193
|
stateKey: t,
|
|
1195
1194
|
itemComponentId: c,
|
|
1196
1195
|
itemPath: h,
|
|
1197
|
-
children:
|
|
1196
|
+
children: f
|
|
1198
1197
|
}) {
|
|
1199
|
-
const [, v] = K({}), [
|
|
1198
|
+
const [, v] = K({}), [k, p] = Ot();
|
|
1200
1199
|
return st(() => {
|
|
1201
|
-
p.height > 0 &&
|
|
1200
|
+
p.height > 0 && o.getState().setShadowMetadata(t, h, {
|
|
1202
1201
|
virtualizer: {
|
|
1203
1202
|
itemHeight: p.height
|
|
1204
1203
|
}
|
|
1205
1204
|
});
|
|
1206
1205
|
}, [p.height]), it(() => {
|
|
1207
|
-
const I = `${t}////${c}`,
|
|
1206
|
+
const I = `${t}////${c}`, a = o.getState().stateComponents.get(t) || {
|
|
1208
1207
|
components: /* @__PURE__ */ new Map()
|
|
1209
1208
|
};
|
|
1210
|
-
return
|
|
1209
|
+
return a.components.set(I, {
|
|
1211
1210
|
forceUpdate: () => v({}),
|
|
1212
1211
|
paths: /* @__PURE__ */ new Set([h.join(".")])
|
|
1213
|
-
}),
|
|
1214
|
-
const y =
|
|
1212
|
+
}), o.getState().stateComponents.set(t, a), () => {
|
|
1213
|
+
const y = o.getState().stateComponents.get(t);
|
|
1215
1214
|
y && y.components.delete(I);
|
|
1216
1215
|
};
|
|
1217
|
-
}, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref:
|
|
1216
|
+
}, [t, c, h.join(".")]), /* @__PURE__ */ mt("div", { ref: k, children: f });
|
|
1218
1217
|
}
|
|
1219
1218
|
export {
|
|
1220
1219
|
At as $cogsSignal,
|
|
1221
1220
|
ie as $cogsSignalStore,
|
|
1222
|
-
|
|
1223
|
-
|
|
1221
|
+
oe as addStateOptions,
|
|
1222
|
+
ae as createCogsState,
|
|
1224
1223
|
se as notifyComponent,
|
|
1225
1224
|
Lt as useCogsStateFn
|
|
1226
1225
|
};
|