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