cogsbox-state 0.5.297 → 0.5.299
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 +307 -309
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.d.ts +26 -24
- package/dist/store.js +109 -95
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +45 -40
- package/src/store.ts +96 -57
package/dist/CogsState.jsx
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as Tt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as tt, useRef as
|
|
4
|
-
import { transformStateFunc as
|
|
3
|
+
import { useState as tt, useRef as J, useEffect as it, useLayoutEffect as ft, useMemo as Et, createElement as ct, useSyncExternalStore as Rt, startTransition as Ut, useCallback as pt } from "react";
|
|
4
|
+
import { transformStateFunc as Ft, isDeepEqual as B, isFunction as X, getNestedValue as q, getDifferences as At, debounce as Dt } from "./utility.js";
|
|
5
5
|
import { pushFunc as wt, updateFn as st, cutFunc as gt, ValidationWrapper as Wt, FormControlComponent as Gt } from "./Functions.jsx";
|
|
6
6
|
import Lt from "superjson";
|
|
7
7
|
import { v4 as $t } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
9
|
+
import { getGlobalStore as o, formRefStore as bt } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as Ht } from "fast-json-patch";
|
|
12
12
|
import zt from "react-use-measure";
|
|
13
|
-
function
|
|
14
|
-
const
|
|
13
|
+
function Vt(t, c) {
|
|
14
|
+
const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
|
|
15
15
|
f(t, {
|
|
16
|
-
...
|
|
16
|
+
...y,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Nt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
|
-
initialOptionsPart:
|
|
23
|
+
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const f = rt(t) || {},
|
|
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)
|
|
@@ -30,34 +30,34 @@ function Ct({
|
|
|
30
30
|
!B(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
|
|
31
31
|
I && k(t, p);
|
|
32
32
|
}
|
|
33
|
-
function Se(t, { formElements: c, validation:
|
|
34
|
-
return { initialState: t, formElements: c, validation:
|
|
33
|
+
function Se(t, { formElements: c, validation: m }) {
|
|
34
|
+
return { initialState: t, formElements: c, validation: m };
|
|
35
35
|
}
|
|
36
36
|
const me = (t, c) => {
|
|
37
|
-
let
|
|
38
|
-
const [f,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
37
|
+
let m = t;
|
|
38
|
+
const [f, y] = Ft(m);
|
|
39
|
+
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
|
|
40
|
+
y[I] = y[I] || {}, y[I].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...c?.validation,
|
|
44
|
-
...
|
|
44
|
+
...y[I].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
}, rt(I) || o.getState().setInitialStateOptions(I,
|
|
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 [
|
|
50
|
-
|
|
49
|
+
const [v] = tt(a?.componentId ?? $t());
|
|
50
|
+
Nt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
|
-
initialOptionsPart:
|
|
53
|
+
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
55
|
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [G, O] = Qt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: v,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
62
62
|
middleware: a?.middleware,
|
|
63
63
|
enabledSync: a?.enabledSync,
|
|
@@ -71,7 +71,7 @@ const me = (t, c) => {
|
|
|
71
71
|
return O;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
|
-
|
|
74
|
+
Nt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Zt(I, a), vt(I);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: k, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
@@ -83,16 +83,16 @@ const me = (t, c) => {
|
|
|
83
83
|
setStateLog: qt,
|
|
84
84
|
updateInitialStateGlobal: kt,
|
|
85
85
|
addValidationError: Jt,
|
|
86
|
-
removeValidationError:
|
|
86
|
+
removeValidationError: Z,
|
|
87
87
|
setServerSyncActions: Yt
|
|
88
|
-
} = o.getState(),
|
|
89
|
-
|
|
88
|
+
} = o.getState(), Ct = (t, c, m, f, y) => {
|
|
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 = X(
|
|
95
|
+
const k = X(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;
|
|
@@ -103,11 +103,11 @@ const me = (t, c) => {
|
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: y ?? I
|
|
107
|
+
}, v = Lt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
|
-
JSON.stringify(
|
|
110
|
+
JSON.stringify(v.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
}, ht = (t) => {
|
|
@@ -119,56 +119,56 @@ const me = (t, c) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
121
|
}, Zt = (t, c) => {
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: f } = Pt(), y = X(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
|
+
if (y && f) {
|
|
124
124
|
const k = ht(
|
|
125
|
-
`${f}-${t}-${
|
|
125
|
+
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
127
|
if (k && k.lastUpdated > (k.lastSyncedWithServer || 0))
|
|
128
|
-
return et(t, k.state),
|
|
128
|
+
return et(t, k.state), vt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, Mt = (t, c,
|
|
131
|
+
}, Mt = (t, c, m, f, y, k) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: mt(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
|
-
|
|
137
|
+
y,
|
|
138
138
|
k
|
|
139
139
|
),
|
|
140
|
-
state:
|
|
140
|
+
state: m
|
|
141
141
|
};
|
|
142
142
|
kt(t, p.initialState), St(t, p.updaterState), et(t, p.state);
|
|
143
|
-
},
|
|
143
|
+
}, vt = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
|
-
const
|
|
146
|
+
const m = /* @__PURE__ */ new Set();
|
|
147
147
|
c.components.forEach((f) => {
|
|
148
|
-
(f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") ||
|
|
148
|
+
(f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || m.add(() => f.forceUpdate());
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
|
-
|
|
150
|
+
m.forEach((f) => f());
|
|
151
151
|
});
|
|
152
152
|
}, he = (t, c) => {
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
const f = `${t}////${c}`,
|
|
156
|
-
if ((
|
|
153
|
+
const m = o.getState().stateComponents.get(t);
|
|
154
|
+
if (m) {
|
|
155
|
+
const f = `${t}////${c}`, y = m.components.get(f);
|
|
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
|
-
}, Xt = (t, c,
|
|
160
|
+
}, Xt = (t, c, m, f) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
164
|
oldValue: q(c, f),
|
|
165
|
-
newValue: q(
|
|
165
|
+
newValue: q(m, f)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue: q(
|
|
171
|
+
newValue: q(m, f)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
@@ -182,55 +182,55 @@ const me = (t, c) => {
|
|
|
182
182
|
};
|
|
183
183
|
function Qt(t, {
|
|
184
184
|
stateKey: c,
|
|
185
|
-
serverSync:
|
|
185
|
+
serverSync: m,
|
|
186
186
|
localStorage: f,
|
|
187
|
-
formElements:
|
|
187
|
+
formElements: y,
|
|
188
188
|
reactiveDeps: k,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: I,
|
|
191
191
|
initialState: a,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: v,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
196
|
const [G, O] = tt({}), { sessionId: R } = Pt();
|
|
197
197
|
let L = !c;
|
|
198
|
-
const [
|
|
198
|
+
const [h] = tt(c ?? $t()), l = o.getState().stateLog[h], lt = J(/* @__PURE__ */ new Set()), Q = J(I ?? $t()), M = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
M.current = rt(
|
|
202
|
-
if (
|
|
203
|
-
et(
|
|
201
|
+
M.current = rt(h) ?? null, it(() => {
|
|
202
|
+
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
+
et(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
|
-
[
|
|
205
|
+
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
207
|
-
const e = `${
|
|
207
|
+
const e = `${v.stateKey}:${v.path.join(".")}`;
|
|
208
208
|
o.getState().setSyncInfo(e, {
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
209
|
+
timeStamp: v.timeStamp,
|
|
210
|
+
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [v]), it(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
Vt(h, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const e = M.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[
|
|
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 && !B(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const T = X(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
-
T && R && (u = ht(`${R}-${
|
|
223
|
+
T && R && (u = ht(`${R}-${h}-${T}`));
|
|
224
224
|
let w = a, $ = !1;
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
227
|
-
|
|
225
|
+
const x = s ? Date.now() : 0, C = u?.lastUpdated || 0, _ = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && x > C ? (w = e.serverState.data, $ = !0) : u && C > _ && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Mt(
|
|
227
|
+
h,
|
|
228
228
|
a,
|
|
229
229
|
w,
|
|
230
230
|
ot,
|
|
231
231
|
Q.current,
|
|
232
232
|
R
|
|
233
|
-
), $ && T && R &&
|
|
233
|
+
), $ && T && R && Ct(w, h, e, R, Date.now()), vt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || O({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
@@ -238,14 +238,14 @@ function Qt(t, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), ft(() => {
|
|
241
|
-
L &&
|
|
242
|
-
serverSync:
|
|
243
|
-
formElements:
|
|
241
|
+
L && Vt(h, {
|
|
242
|
+
serverSync: m,
|
|
243
|
+
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: f,
|
|
246
246
|
middleware: M.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${
|
|
248
|
+
const e = `${h}////${Q.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
@@ -254,222 +254,222 @@ function Qt(t, {
|
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: k || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(
|
|
258
|
-
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), O({}), () => {
|
|
258
|
+
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const ot = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const u = `${
|
|
263
|
+
const u = `${h}-${r.join(".")}`;
|
|
264
264
|
lt.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const g = o.getState();
|
|
267
|
-
et(
|
|
268
|
-
const T = X(e) ? e(u) : e, w = `${
|
|
267
|
+
et(h, (u) => {
|
|
268
|
+
const T = X(e) ? e(u) : e, w = `${h}-${r.join(".")}`;
|
|
269
269
|
if (w) {
|
|
270
|
-
let V = !1,
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
270
|
+
let V = !1, b = g.signalDomElements.get(w);
|
|
271
|
+
if ((!b || b.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const P = r.slice(0, -1), D = q(T, P);
|
|
273
273
|
if (Array.isArray(D)) {
|
|
274
274
|
V = !0;
|
|
275
|
-
const
|
|
276
|
-
|
|
275
|
+
const E = `${h}-${P.join(".")}`;
|
|
276
|
+
b = g.signalDomElements.get(E);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
279
|
+
if (b) {
|
|
280
|
+
const P = V ? q(T, r.slice(0, -1)) : q(T, r);
|
|
281
|
+
b.forEach(({ parentId: D, position: E, effect: U }) => {
|
|
282
282
|
const j = document.querySelector(
|
|
283
283
|
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
285
|
if (j) {
|
|
286
|
-
const
|
|
287
|
-
if (E
|
|
288
|
-
const
|
|
289
|
-
E
|
|
286
|
+
const A = Array.from(j.childNodes);
|
|
287
|
+
if (A[E]) {
|
|
288
|
+
const N = U ? new Function("state", `return (${U})(state)`)(P) : P;
|
|
289
|
+
A[E].textContent = String(N);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r &&
|
|
295
|
+
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r && Z(
|
|
296
296
|
(i || M.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
298
|
const $ = r.slice(0, r.length - 1);
|
|
299
|
-
s.updateType === "cut" && M.current?.validation?.key &&
|
|
299
|
+
s.updateType === "cut" && M.current?.validation?.key && Z(
|
|
300
300
|
M.current?.validation?.key + "." + $.join(".")
|
|
301
301
|
), s.updateType === "insert" && M.current?.validation?.key && Bt(
|
|
302
302
|
M.current?.validation?.key + "." + $.join(".")
|
|
303
|
-
).filter(([
|
|
304
|
-
let D =
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
|
|
303
|
+
).filter(([b, P]) => {
|
|
304
|
+
let D = b?.split(".").length;
|
|
305
|
+
if (b == $.join(".") && D == $.length - 1) {
|
|
306
|
+
let E = b + "." + $;
|
|
307
|
+
Z(b), Jt(E, P);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const V =
|
|
310
|
+
const x = g.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", x), x) {
|
|
312
|
+
const V = At(u, T), b = new Set(V), P = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
D,
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const j = Array.isArray(
|
|
319
|
-
if (console.log("component",
|
|
315
|
+
E
|
|
316
|
+
] of x.components.entries()) {
|
|
317
|
+
let U = !1;
|
|
318
|
+
const j = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", E), !j.includes("none")) {
|
|
320
320
|
if (j.includes("all")) {
|
|
321
|
-
|
|
321
|
+
E.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (j.includes("component") && ((
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (j.includes("component") && ((E.paths.has(P) || E.paths.has("")) && (U = !0), !U))
|
|
325
|
+
for (const A of b) {
|
|
326
|
+
let N = A;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (E.paths.has(N)) {
|
|
329
|
+
U = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const z =
|
|
332
|
+
const z = N.lastIndexOf(".");
|
|
333
333
|
if (z !== -1) {
|
|
334
|
-
const W =
|
|
334
|
+
const W = N.substring(
|
|
335
335
|
0,
|
|
336
336
|
z
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(N.substring(z + 1))
|
|
340
|
+
) && E.paths.has(W)) {
|
|
341
|
+
U = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
N = W;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
N = "";
|
|
347
|
+
if (N === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (U) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!U && j.includes("deps") && E.depsFunction) {
|
|
353
|
+
const A = E.depsFunction(T);
|
|
354
|
+
let N = !1;
|
|
355
|
+
typeof A == "boolean" ? A && (N = !0) : B(E.deps, A) || (E.deps = A, N = !0), N && (U = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
U && E.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
const C = Date.now();
|
|
362
|
-
r = r.map((V,
|
|
363
|
-
const
|
|
364
|
-
return
|
|
362
|
+
r = r.map((V, b) => {
|
|
363
|
+
const P = r.slice(0, -1), D = q(T, P);
|
|
364
|
+
return b === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : V;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: _, newValue:
|
|
366
|
+
const { oldValue: _, newValue: F } = Xt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
369
|
T,
|
|
370
370
|
r
|
|
371
371
|
), H = {
|
|
372
372
|
timeStamp: C,
|
|
373
|
-
stateKey:
|
|
373
|
+
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: _,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: F
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
g.updateShadowAtPath(
|
|
382
|
+
g.updateShadowAtPath(h, r, T);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const V = r.slice(0, -1);
|
|
386
|
-
g.insertShadowArrayElement(
|
|
386
|
+
g.insertShadowArrayElement(h, V, F);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
g.removeShadowArrayElement(
|
|
389
|
+
const b = r.slice(0, -1), P = parseInt(r[r.length - 1]);
|
|
390
|
+
g.removeShadowArrayElement(h, b, P);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (qt(
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return j ? (j.timeStamp = Math.max(j.timeStamp,
|
|
393
|
+
if (qt(h, (V) => {
|
|
394
|
+
const P = [...V ?? [], H].reduce((D, E) => {
|
|
395
|
+
const U = `${E.stateKey}:${JSON.stringify(E.path)}`, j = D.get(U);
|
|
396
|
+
return j ? (j.timeStamp = Math.max(j.timeStamp, E.timeStamp), j.newValue = E.newValue, j.oldValue = j.oldValue ?? E.oldValue, j.updateType = E.updateType) : D.set(U, { ...E }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(P.values());
|
|
399
|
+
}), Ct(
|
|
400
400
|
T,
|
|
401
|
-
|
|
401
|
+
h,
|
|
402
402
|
M.current,
|
|
403
403
|
R
|
|
404
404
|
), M.current?.middleware && M.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: H
|
|
407
407
|
}), M.current?.serverSync) {
|
|
408
|
-
const V = g.serverState[
|
|
409
|
-
Yt(
|
|
410
|
-
syncKey: typeof
|
|
408
|
+
const V = g.serverState[h], b = M.current?.serverSync;
|
|
409
|
+
Yt(h, {
|
|
410
|
+
syncKey: typeof b.syncKey == "string" ? b.syncKey : b.syncKey({ state: T }),
|
|
411
411
|
rollBackState: V,
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
412
|
+
actionTimeStamp: Date.now() + (b.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
return T;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[
|
|
420
|
-
|
|
419
|
+
o.getState().updaterState[h] || (St(
|
|
420
|
+
h,
|
|
421
421
|
mt(
|
|
422
|
-
|
|
422
|
+
h,
|
|
423
423
|
ot,
|
|
424
424
|
Q.current,
|
|
425
425
|
R
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[
|
|
428
|
-
const d =
|
|
429
|
-
|
|
427
|
+
), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || kt(h, t));
|
|
428
|
+
const d = Et(() => mt(
|
|
429
|
+
h,
|
|
430
430
|
ot,
|
|
431
431
|
Q.current,
|
|
432
432
|
R
|
|
433
|
-
), [
|
|
434
|
-
return [_t(
|
|
433
|
+
), [h, R]);
|
|
434
|
+
return [_t(h), d];
|
|
435
435
|
}
|
|
436
|
-
function mt(t, c,
|
|
437
|
-
const
|
|
436
|
+
function mt(t, c, m, f) {
|
|
437
|
+
const y = /* @__PURE__ */ new Map();
|
|
438
438
|
let k = 0;
|
|
439
|
-
const p = (
|
|
440
|
-
const n =
|
|
441
|
-
for (const [S] of
|
|
442
|
-
(S === n || S.startsWith(n + ".")) &&
|
|
439
|
+
const p = (v) => {
|
|
440
|
+
const n = v.join(".");
|
|
441
|
+
for (const [S] of y)
|
|
442
|
+
(S === n || S.startsWith(n + ".")) && y.delete(S);
|
|
443
443
|
k++;
|
|
444
444
|
}, I = {
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
445
|
+
removeValidation: (v) => {
|
|
446
|
+
v?.validationKey && Z(v.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
448
|
+
revertToInitialState: (v) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Z(n?.key), v?.validationKey && Z(v.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t),
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), k++;
|
|
453
453
|
const G = a(S, []), O = rt(t), R = X(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, L = `${f}-${t}-${R}`;
|
|
454
454
|
L && localStorage.removeItem(L), St(t, G), et(t, S);
|
|
455
|
-
const
|
|
456
|
-
return
|
|
455
|
+
const h = o.getState().stateComponents.get(t);
|
|
456
|
+
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
460
|
+
updateInitialState: (v) => {
|
|
461
|
+
y.clear(), k++;
|
|
462
462
|
const n = mt(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
|
-
|
|
465
|
+
m,
|
|
466
466
|
f
|
|
467
467
|
), S = o.getState().initialStateGlobal[t], G = rt(t), O = X(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, R = `${f}-${t}-${O}`;
|
|
468
|
-
return localStorage.getItem(R) && localStorage.removeItem(R),
|
|
469
|
-
kt(t,
|
|
468
|
+
return localStorage.getItem(R) && localStorage.removeItem(R), Ut(() => {
|
|
469
|
+
kt(t, v), o.getState().initializeShadowState(t, v), St(t, n), et(t, v);
|
|
470
470
|
const L = o.getState().stateComponents.get(t);
|
|
471
|
-
L && L.components.forEach((
|
|
472
|
-
|
|
471
|
+
L && L.components.forEach((h) => {
|
|
472
|
+
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
475
|
fetchId: (L) => n.get()[L]
|
|
@@ -479,27 +479,27 @@ function mt(t, c, h, f) {
|
|
|
479
479
|
_serverState: o.getState().serverState[t],
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const v = o.getState().serverState[t];
|
|
483
|
+
return !!(v && B(v, _t(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function a(
|
|
486
|
+
function a(v, n = [], S) {
|
|
487
487
|
const G = n.map(String).join(".");
|
|
488
|
-
|
|
488
|
+
y.get(G);
|
|
489
489
|
const O = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(I).forEach((
|
|
493
|
-
O[
|
|
492
|
+
Object.keys(I).forEach((h) => {
|
|
493
|
+
O[h] = I[h];
|
|
494
494
|
});
|
|
495
495
|
const R = {
|
|
496
|
-
apply(
|
|
496
|
+
apply(h, l, lt) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
|
-
get(
|
|
502
|
-
S?.validIndices && !Array.isArray(
|
|
501
|
+
get(h, l) {
|
|
502
|
+
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
503
|
const lt = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
@@ -524,7 +524,7 @@ function mt(t, c, h, f) {
|
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
526
|
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !lt.has(l)) {
|
|
527
|
-
const d = `${t}////${
|
|
527
|
+
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const r = e.components.get(d);
|
|
530
530
|
if (r && !r.paths.has("")) {
|
|
@@ -540,7 +540,7 @@ function mt(t, c, h, f) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => At(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -591,8 +591,8 @@ function mt(t, c, h, f) {
|
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => S?.validIndices ?
|
|
594
|
+
if (Array.isArray(v)) {
|
|
595
|
+
const d = () => S?.validIndices ? v.map((r, s) => ({
|
|
596
596
|
item: r,
|
|
597
597
|
originalIndex: S.validIndices[s]
|
|
598
598
|
})) : o.getState().getNestedState(t, n).map((r, s) => ({
|
|
@@ -604,7 +604,7 @@ function mt(t, c, h, f) {
|
|
|
604
604
|
const e = o.getState().getSelectedIndex(t, n.join("."));
|
|
605
605
|
if (e !== void 0)
|
|
606
606
|
return a(
|
|
607
|
-
|
|
607
|
+
v[e],
|
|
608
608
|
[...n, e.toString()],
|
|
609
609
|
S
|
|
610
610
|
);
|
|
@@ -622,109 +622,107 @@ function mt(t, c, h, f) {
|
|
|
622
622
|
// Default/estimated height
|
|
623
623
|
overscan: s = 5,
|
|
624
624
|
stickToBottom: i = !1
|
|
625
|
-
} = e, g =
|
|
625
|
+
} = e, g = J(null), [u, T] = tt({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [w, $] = tt(0),
|
|
629
|
-
() => $((
|
|
628
|
+
}), [w, $] = tt(0), x = pt(
|
|
629
|
+
() => $((A) => A + 1),
|
|
630
630
|
[]
|
|
631
631
|
);
|
|
632
632
|
it(() => {
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}, [
|
|
638
|
-
const C =
|
|
633
|
+
const A = o.getState().subscribeToShadowState(t, x), N = setTimeout(x, 50);
|
|
634
|
+
return () => {
|
|
635
|
+
A(), clearTimeout(N);
|
|
636
|
+
};
|
|
637
|
+
}, [t, x]);
|
|
638
|
+
const C = J(i), _ = J(0), F = J(!0), H = o().getNestedState(
|
|
639
639
|
t,
|
|
640
640
|
n
|
|
641
|
-
), V = H.length, { totalHeight:
|
|
642
|
-
const
|
|
643
|
-
let
|
|
641
|
+
), V = H.length, { totalHeight: b, positions: P } = Et(() => {
|
|
642
|
+
const A = o.getState().getShadowMetadata(t, n) || [];
|
|
643
|
+
let N = 0;
|
|
644
644
|
const z = [];
|
|
645
645
|
for (let W = 0; W < V; W++) {
|
|
646
|
-
z[W] =
|
|
647
|
-
const
|
|
648
|
-
|
|
646
|
+
z[W] = N;
|
|
647
|
+
const Y = A[W]?.virtualizer?.itemHeight;
|
|
648
|
+
N += Y || r;
|
|
649
649
|
}
|
|
650
|
-
return { totalHeight:
|
|
651
|
-
}, [V, t, n, r, w]), D =
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
), W = z.map((
|
|
650
|
+
return { totalHeight: N, positions: z };
|
|
651
|
+
}, [V, t, n, r, w]), D = Et(() => {
|
|
652
|
+
const A = Math.max(0, u.startIndex), N = Math.min(V, u.endIndex), z = Array.from(
|
|
653
|
+
{ length: N - A },
|
|
654
|
+
(Y, dt) => A + dt
|
|
655
|
+
), W = z.map((Y) => H[Y]);
|
|
656
656
|
return a(W, n, {
|
|
657
657
|
...S,
|
|
658
658
|
validIndices: z
|
|
659
659
|
});
|
|
660
|
-
}, [u.startIndex, u.endIndex, H
|
|
660
|
+
}, [u.startIndex, u.endIndex, H]);
|
|
661
661
|
ft(() => {
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
664
|
-
const
|
|
662
|
+
const A = g.current;
|
|
663
|
+
if (!A) return;
|
|
664
|
+
const N = C.current, z = V > _.current;
|
|
665
665
|
_.current = V;
|
|
666
666
|
const W = () => {
|
|
667
|
-
const { scrollTop:
|
|
668
|
-
C.current = jt -
|
|
667
|
+
const { scrollTop: Y, clientHeight: dt, scrollHeight: jt } = A;
|
|
668
|
+
C.current = jt - Y - dt < 5;
|
|
669
669
|
let at = ((nt, Ot) => {
|
|
670
|
-
let ut = 0,
|
|
671
|
-
for (; ut <=
|
|
672
|
-
const It = Math.floor((ut +
|
|
673
|
-
nt[It] < Ot ? ut = It + 1 :
|
|
670
|
+
let ut = 0, yt = nt.length - 1;
|
|
671
|
+
for (; ut <= yt; ) {
|
|
672
|
+
const It = Math.floor((ut + yt) / 2);
|
|
673
|
+
nt[It] < Ot ? ut = It + 1 : yt = It - 1;
|
|
674
674
|
}
|
|
675
675
|
return ut;
|
|
676
|
-
})(
|
|
677
|
-
for (; K < V &&
|
|
676
|
+
})(P, Y), K = at;
|
|
677
|
+
for (; K < V && P[K] < Y + dt; )
|
|
678
678
|
K++;
|
|
679
679
|
at = Math.max(0, at - s), K = Math.min(V, K + s), T((nt) => nt.startIndex !== at || nt.endIndex !== K ? { startIndex: at, endIndex: K } : nt);
|
|
680
680
|
};
|
|
681
|
-
return
|
|
681
|
+
return A.addEventListener("scroll", W, {
|
|
682
682
|
passive: !0
|
|
683
|
-
}), i && (
|
|
684
|
-
top:
|
|
683
|
+
}), W(), i && (F.current ? (A.scrollTo({
|
|
684
|
+
top: A.scrollHeight,
|
|
685
685
|
behavior: "auto"
|
|
686
|
-
}) :
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
const A = pt(
|
|
694
|
-
(E = "smooth") => {
|
|
686
|
+
}), F.current = !1) : z && N && A.scrollTo({
|
|
687
|
+
top: A.scrollHeight,
|
|
688
|
+
behavior: "auto"
|
|
689
|
+
})), () => A.removeEventListener("scroll", W);
|
|
690
|
+
}, [V, s, i, P]);
|
|
691
|
+
const E = pt(
|
|
692
|
+
(A = "smooth") => {
|
|
695
693
|
g.current && g.current.scrollTo({
|
|
696
694
|
top: g.current.scrollHeight,
|
|
697
|
-
behavior:
|
|
695
|
+
behavior: A
|
|
698
696
|
});
|
|
699
697
|
},
|
|
700
698
|
[]
|
|
701
|
-
),
|
|
702
|
-
(
|
|
699
|
+
), U = pt(
|
|
700
|
+
(A, N = "smooth") => {
|
|
703
701
|
g.current && g.current.scrollTo({
|
|
704
|
-
top:
|
|
705
|
-
behavior:
|
|
702
|
+
top: P[A] || 0,
|
|
703
|
+
behavior: N
|
|
706
704
|
});
|
|
707
705
|
},
|
|
708
|
-
[
|
|
706
|
+
[P]
|
|
709
707
|
), j = {
|
|
710
708
|
outer: {
|
|
711
709
|
ref: g,
|
|
712
710
|
style: { overflowY: "auto", height: "100%" }
|
|
713
711
|
},
|
|
714
712
|
inner: {
|
|
715
|
-
style: { height: `${
|
|
713
|
+
style: { height: `${b}px`, position: "relative" }
|
|
716
714
|
},
|
|
717
715
|
list: {
|
|
718
716
|
style: {
|
|
719
|
-
transform: `translateY(${
|
|
717
|
+
transform: `translateY(${P[u.startIndex] || 0}px)`
|
|
720
718
|
}
|
|
721
719
|
}
|
|
722
720
|
};
|
|
723
721
|
return {
|
|
724
722
|
virtualState: D,
|
|
725
723
|
virtualizerProps: j,
|
|
726
|
-
scrollToBottom:
|
|
727
|
-
scrollToIndex:
|
|
724
|
+
scrollToBottom: E,
|
|
725
|
+
scrollToIndex: U
|
|
728
726
|
};
|
|
729
727
|
};
|
|
730
728
|
if (l === "stateSort")
|
|
@@ -758,15 +756,15 @@ function mt(t, c, h, f) {
|
|
|
758
756
|
const u = r[i], T = [...n, i.toString()], w = a(u, T, S);
|
|
759
757
|
return e(u, w, {
|
|
760
758
|
register: () => {
|
|
761
|
-
const [,
|
|
759
|
+
const [, x] = tt({}), C = `${m}-${n.join(".")}-${i}`;
|
|
762
760
|
ft(() => {
|
|
763
|
-
const _ = `${t}////${C}`,
|
|
761
|
+
const _ = `${t}////${C}`, F = o.getState().stateComponents.get(t) || {
|
|
764
762
|
components: /* @__PURE__ */ new Map()
|
|
765
763
|
};
|
|
766
|
-
return
|
|
767
|
-
forceUpdate: () =>
|
|
764
|
+
return F.components.set(_, {
|
|
765
|
+
forceUpdate: () => x({}),
|
|
768
766
|
paths: /* @__PURE__ */ new Set([T.join(".")])
|
|
769
|
-
}), o.getState().stateComponents.set(t,
|
|
767
|
+
}), o.getState().stateComponents.set(t, F), () => {
|
|
770
768
|
const H = o.getState().stateComponents.get(t);
|
|
771
769
|
H && H.components.delete(_);
|
|
772
770
|
};
|
|
@@ -781,7 +779,7 @@ function mt(t, c, h, f) {
|
|
|
781
779
|
), null);
|
|
782
780
|
};
|
|
783
781
|
if (l === "stateMapNoRender")
|
|
784
|
-
return (e) =>
|
|
782
|
+
return (e) => v.map((s, i) => {
|
|
785
783
|
let g;
|
|
786
784
|
S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
|
|
787
785
|
const u = [...n, g.toString()], T = a(s, u, S);
|
|
@@ -789,8 +787,8 @@ function mt(t, c, h, f) {
|
|
|
789
787
|
s,
|
|
790
788
|
T,
|
|
791
789
|
i,
|
|
792
|
-
|
|
793
|
-
a(
|
|
790
|
+
v,
|
|
791
|
+
a(v, n, S)
|
|
794
792
|
);
|
|
795
793
|
});
|
|
796
794
|
if (l === "$stateMap")
|
|
@@ -807,7 +805,7 @@ function mt(t, c, h, f) {
|
|
|
807
805
|
return (e) => {
|
|
808
806
|
const r = o.getState().getNestedState(t, n);
|
|
809
807
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
810
|
-
const u = r[i], T = [...n, i.toString()], w = a(u, T, S), $ = `${
|
|
808
|
+
const u = r[i], T = [...n, i.toString()], w = a(u, T, S), $ = `${m}-${n.join(".")}-${i}`;
|
|
811
809
|
return ct(ee, {
|
|
812
810
|
key: i,
|
|
813
811
|
stateKey: t,
|
|
@@ -827,8 +825,8 @@ function mt(t, c, h, f) {
|
|
|
827
825
|
};
|
|
828
826
|
if (l === "stateFlattenOn")
|
|
829
827
|
return (e) => {
|
|
830
|
-
const r =
|
|
831
|
-
|
|
828
|
+
const r = v;
|
|
829
|
+
y.clear(), k++;
|
|
832
830
|
const s = r.flatMap(
|
|
833
831
|
(i) => i[e] ?? []
|
|
834
832
|
);
|
|
@@ -840,7 +838,7 @@ function mt(t, c, h, f) {
|
|
|
840
838
|
};
|
|
841
839
|
if (l === "index")
|
|
842
840
|
return (e) => {
|
|
843
|
-
const r =
|
|
841
|
+
const r = v[e];
|
|
844
842
|
return a(r, [...n, e.toString()]);
|
|
845
843
|
};
|
|
846
844
|
if (l === "last")
|
|
@@ -861,10 +859,10 @@ function mt(t, c, h, f) {
|
|
|
861
859
|
let u = null;
|
|
862
860
|
if (!i.some((w) => {
|
|
863
861
|
if (r) {
|
|
864
|
-
const
|
|
862
|
+
const x = r.every(
|
|
865
863
|
(C) => B(w[C], g[C])
|
|
866
864
|
);
|
|
867
|
-
return
|
|
865
|
+
return x && (u = w), x;
|
|
868
866
|
}
|
|
869
867
|
const $ = B(w, g);
|
|
870
868
|
return $ && (u = w), $;
|
|
@@ -872,7 +870,7 @@ function mt(t, c, h, f) {
|
|
|
872
870
|
p(n), wt(c, g, n, t);
|
|
873
871
|
else if (s && u) {
|
|
874
872
|
const w = s(u), $ = i.map(
|
|
875
|
-
(
|
|
873
|
+
(x) => B(x, u) ? w : x
|
|
876
874
|
);
|
|
877
875
|
p(n), st(c, $, n);
|
|
878
876
|
}
|
|
@@ -887,12 +885,12 @@ function mt(t, c, h, f) {
|
|
|
887
885
|
};
|
|
888
886
|
if (l === "cutByValue")
|
|
889
887
|
return (e) => {
|
|
890
|
-
for (let r = 0; r <
|
|
891
|
-
|
|
888
|
+
for (let r = 0; r < v.length; r++)
|
|
889
|
+
v[r] === e && gt(c, n, t, r);
|
|
892
890
|
};
|
|
893
891
|
if (l === "toggleByValue")
|
|
894
892
|
return (e) => {
|
|
895
|
-
const r =
|
|
893
|
+
const r = v.findIndex((s) => s === e);
|
|
896
894
|
r > -1 ? gt(c, n, t, r) : wt(c, e, n, t);
|
|
897
895
|
};
|
|
898
896
|
if (l === "stateFind")
|
|
@@ -927,7 +925,7 @@ function mt(t, c, h, f) {
|
|
|
927
925
|
}
|
|
928
926
|
if (l === "get")
|
|
929
927
|
return () => {
|
|
930
|
-
if (S?.validIndices && Array.isArray(
|
|
928
|
+
if (S?.validIndices && Array.isArray(v)) {
|
|
931
929
|
const d = o.getState().getNestedState(t, n);
|
|
932
930
|
return S.validIndices.map((e) => d[e]);
|
|
933
931
|
}
|
|
@@ -981,24 +979,24 @@ function mt(t, c, h, f) {
|
|
|
981
979
|
o.getState().initialStateGlobal[t],
|
|
982
980
|
s,
|
|
983
981
|
c,
|
|
984
|
-
|
|
982
|
+
m,
|
|
985
983
|
f
|
|
986
984
|
);
|
|
987
985
|
const i = o.getState().stateComponents.get(t);
|
|
988
986
|
if (i) {
|
|
989
|
-
const g =
|
|
987
|
+
const g = At(e, s), u = new Set(g);
|
|
990
988
|
for (const [
|
|
991
989
|
T,
|
|
992
990
|
w
|
|
993
991
|
] of i.components.entries()) {
|
|
994
992
|
let $ = !1;
|
|
995
|
-
const
|
|
996
|
-
if (!
|
|
997
|
-
if (
|
|
993
|
+
const x = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
994
|
+
if (!x.includes("none")) {
|
|
995
|
+
if (x.includes("all")) {
|
|
998
996
|
w.forceUpdate();
|
|
999
997
|
continue;
|
|
1000
998
|
}
|
|
1001
|
-
if (
|
|
999
|
+
if (x.includes("component") && (w.paths.has("") && ($ = !0), !$))
|
|
1002
1000
|
for (const C of u) {
|
|
1003
1001
|
if (w.paths.has(C)) {
|
|
1004
1002
|
$ = !0;
|
|
@@ -1006,8 +1004,8 @@ function mt(t, c, h, f) {
|
|
|
1006
1004
|
}
|
|
1007
1005
|
let _ = C.lastIndexOf(".");
|
|
1008
1006
|
for (; _ !== -1; ) {
|
|
1009
|
-
const
|
|
1010
|
-
if (w.paths.has(
|
|
1007
|
+
const F = C.substring(0, _);
|
|
1008
|
+
if (w.paths.has(F)) {
|
|
1011
1009
|
$ = !0;
|
|
1012
1010
|
break;
|
|
1013
1011
|
}
|
|
@@ -1015,23 +1013,23 @@ function mt(t, c, h, f) {
|
|
|
1015
1013
|
_ + 1
|
|
1016
1014
|
);
|
|
1017
1015
|
if (!isNaN(Number(H))) {
|
|
1018
|
-
const V =
|
|
1016
|
+
const V = F.lastIndexOf(".");
|
|
1019
1017
|
if (V !== -1) {
|
|
1020
|
-
const
|
|
1018
|
+
const b = F.substring(
|
|
1021
1019
|
0,
|
|
1022
1020
|
V
|
|
1023
1021
|
);
|
|
1024
|
-
if (w.paths.has(
|
|
1022
|
+
if (w.paths.has(b)) {
|
|
1025
1023
|
$ = !0;
|
|
1026
1024
|
break;
|
|
1027
1025
|
}
|
|
1028
1026
|
}
|
|
1029
1027
|
}
|
|
1030
|
-
_ =
|
|
1028
|
+
_ = F.lastIndexOf(".");
|
|
1031
1029
|
}
|
|
1032
1030
|
if ($) break;
|
|
1033
1031
|
}
|
|
1034
|
-
if (!$ &&
|
|
1032
|
+
if (!$ && x.includes("deps") && w.depsFunction) {
|
|
1035
1033
|
const C = w.depsFunction(s);
|
|
1036
1034
|
let _ = !1;
|
|
1037
1035
|
typeof C == "boolean" ? C && (_ = !0) : B(w.deps, C) || (w.deps = C, _ = !0), _ && ($ = !0);
|
|
@@ -1048,27 +1046,27 @@ function mt(t, c, h, f) {
|
|
|
1048
1046
|
throw new Error("Zod schema not found");
|
|
1049
1047
|
if (!d?.key)
|
|
1050
1048
|
throw new Error("Validation key not found");
|
|
1051
|
-
|
|
1049
|
+
Z(d.key);
|
|
1052
1050
|
const r = o.getState().cogsStateStore[t];
|
|
1053
1051
|
try {
|
|
1054
1052
|
const s = o.getState().getValidationErrors(d.key);
|
|
1055
1053
|
s && s.length > 0 && s.forEach(([g]) => {
|
|
1056
|
-
g && g.startsWith(d.key) &&
|
|
1054
|
+
g && g.startsWith(d.key) && Z(g);
|
|
1057
1055
|
});
|
|
1058
1056
|
const i = d.zodSchema.safeParse(r);
|
|
1059
1057
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1060
1058
|
const T = u.path, w = u.message, $ = [d.key, ...T].join(".");
|
|
1061
1059
|
e($, w);
|
|
1062
|
-
}),
|
|
1060
|
+
}), vt(t), !1);
|
|
1063
1061
|
} catch (s) {
|
|
1064
1062
|
return console.error("Zod schema validation failed", s), !1;
|
|
1065
1063
|
}
|
|
1066
1064
|
};
|
|
1067
|
-
if (l === "_componentId") return
|
|
1065
|
+
if (l === "_componentId") return m;
|
|
1068
1066
|
if (l === "getComponents")
|
|
1069
1067
|
return () => o().stateComponents.get(t);
|
|
1070
1068
|
if (l === "getAllFormRefs")
|
|
1071
|
-
return () =>
|
|
1069
|
+
return () => bt.getState().getFormRefsByStateKey(t);
|
|
1072
1070
|
if (l === "_initialState")
|
|
1073
1071
|
return o.getState().initialStateGlobal[t];
|
|
1074
1072
|
if (l === "_serverState")
|
|
@@ -1081,7 +1079,7 @@ function mt(t, c, h, f) {
|
|
|
1081
1079
|
if (l === "removeValidation") return I.removeValidation;
|
|
1082
1080
|
}
|
|
1083
1081
|
if (l === "getFormRef")
|
|
1084
|
-
return () =>
|
|
1082
|
+
return () => bt.getState().getFormRef(t + "." + n.join("."));
|
|
1085
1083
|
if (l === "validationWrapper")
|
|
1086
1084
|
return ({
|
|
1087
1085
|
children: d,
|
|
@@ -1130,7 +1128,7 @@ function mt(t, c, h, f) {
|
|
|
1130
1128
|
return a(ot, M, S);
|
|
1131
1129
|
}
|
|
1132
1130
|
}, L = new Proxy(O, R);
|
|
1133
|
-
return
|
|
1131
|
+
return y.set(G, {
|
|
1134
1132
|
proxy: L,
|
|
1135
1133
|
stateVersion: k
|
|
1136
1134
|
}), L;
|
|
@@ -1146,31 +1144,31 @@ function Kt({
|
|
|
1146
1144
|
proxy: t,
|
|
1147
1145
|
rebuildStateShape: c
|
|
1148
1146
|
}) {
|
|
1149
|
-
const
|
|
1150
|
-
return Array.isArray(
|
|
1151
|
-
|
|
1147
|
+
const m = o().getNestedState(t._stateKey, t._path);
|
|
1148
|
+
return Array.isArray(m) ? c(
|
|
1149
|
+
m,
|
|
1152
1150
|
t._path
|
|
1153
1151
|
).stateMapNoRender(
|
|
1154
|
-
(
|
|
1152
|
+
(y, k, p, I, a) => t._mapFn(y, k, p, I, a)
|
|
1155
1153
|
) : null;
|
|
1156
1154
|
}
|
|
1157
1155
|
function te({
|
|
1158
1156
|
proxy: t
|
|
1159
1157
|
}) {
|
|
1160
|
-
const c =
|
|
1158
|
+
const c = J(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1161
1159
|
return it(() => {
|
|
1162
1160
|
const f = c.current;
|
|
1163
1161
|
if (!f || !f.parentElement) return;
|
|
1164
|
-
const
|
|
1165
|
-
let I =
|
|
1166
|
-
I || (I = `parent-${crypto.randomUUID()}`,
|
|
1167
|
-
const
|
|
1162
|
+
const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
|
|
1163
|
+
let I = y.getAttribute("data-parent-id");
|
|
1164
|
+
I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
|
|
1165
|
+
const v = {
|
|
1168
1166
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1169
1167
|
parentId: I,
|
|
1170
1168
|
position: p,
|
|
1171
1169
|
effect: t._effect
|
|
1172
1170
|
};
|
|
1173
|
-
o.getState().addSignalElement(
|
|
1171
|
+
o.getState().addSignalElement(m, v);
|
|
1174
1172
|
const n = o.getState().getNestedState(t._stateKey, t._path);
|
|
1175
1173
|
let S;
|
|
1176
1174
|
if (t._effect)
|
|
@@ -1190,17 +1188,17 @@ function te({
|
|
|
1190
1188
|
}, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
|
|
1191
1189
|
ref: c,
|
|
1192
1190
|
style: { display: "none" },
|
|
1193
|
-
"data-signal-id":
|
|
1191
|
+
"data-signal-id": m
|
|
1194
1192
|
});
|
|
1195
1193
|
}
|
|
1196
|
-
function
|
|
1194
|
+
function ve(t) {
|
|
1197
1195
|
const c = Rt(
|
|
1198
|
-
(
|
|
1196
|
+
(m) => {
|
|
1199
1197
|
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1200
1198
|
components: /* @__PURE__ */ new Map()
|
|
1201
1199
|
};
|
|
1202
1200
|
return f.components.set(t._stateKey, {
|
|
1203
|
-
forceUpdate:
|
|
1201
|
+
forceUpdate: m,
|
|
1204
1202
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1205
1203
|
}), () => f.components.delete(t._stateKey);
|
|
1206
1204
|
},
|
|
@@ -1211,32 +1209,32 @@ function ye(t) {
|
|
|
1211
1209
|
function ee({
|
|
1212
1210
|
stateKey: t,
|
|
1213
1211
|
itemComponentId: c,
|
|
1214
|
-
itemPath:
|
|
1212
|
+
itemPath: m,
|
|
1215
1213
|
children: f
|
|
1216
1214
|
}) {
|
|
1217
|
-
const [,
|
|
1215
|
+
const [, y] = tt({}), [k, p] = zt(), I = J(null);
|
|
1218
1216
|
return it(() => {
|
|
1219
|
-
p.height > 0 && o.getState().setShadowMetadata(t,
|
|
1217
|
+
p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1220
1218
|
virtualizer: {
|
|
1221
1219
|
itemHeight: p.height
|
|
1222
1220
|
}
|
|
1223
|
-
});
|
|
1224
|
-
}, [p.height]), ft(() => {
|
|
1225
|
-
const
|
|
1221
|
+
}));
|
|
1222
|
+
}, [p.height, t, m]), ft(() => {
|
|
1223
|
+
const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
|
|
1226
1224
|
components: /* @__PURE__ */ new Map()
|
|
1227
1225
|
};
|
|
1228
|
-
return
|
|
1229
|
-
forceUpdate: () =>
|
|
1230
|
-
paths: /* @__PURE__ */ new Set([
|
|
1231
|
-
}), o.getState().stateComponents.set(t,
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1226
|
+
return v.components.set(a, {
|
|
1227
|
+
forceUpdate: () => y({}),
|
|
1228
|
+
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1229
|
+
}), o.getState().stateComponents.set(t, v), () => {
|
|
1230
|
+
const n = o.getState().stateComponents.get(t);
|
|
1231
|
+
n && n.components.delete(a);
|
|
1234
1232
|
};
|
|
1235
|
-
}, [t, c,
|
|
1233
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ Tt("div", { ref: k, children: f });
|
|
1236
1234
|
}
|
|
1237
1235
|
export {
|
|
1238
1236
|
xt as $cogsSignal,
|
|
1239
|
-
|
|
1237
|
+
ve as $cogsSignalStore,
|
|
1240
1238
|
Se as addStateOptions,
|
|
1241
1239
|
me as createCogsState,
|
|
1242
1240
|
he as notifyComponent,
|