cogsbox-state 0.5.336 → 0.5.338
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 +300 -300
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +20 -10
package/dist/CogsState.jsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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 ht } from "react/jsx-runtime";
|
|
3
|
+
import { useState as Z, useRef as X, useEffect as nt, useLayoutEffect as lt, useMemo as vt, createElement as at, useSyncExternalStore as Pt, startTransition as _t, useCallback as Tt } from "react";
|
|
4
|
+
import { transformStateFunc as Mt, isDeepEqual as H, isFunction as q, getNestedValue as z, getDifferences as yt, debounce as jt } from "./utility.js";
|
|
5
|
+
import { pushFunc as mt, updateFn as ot, cutFunc as ct, ValidationWrapper as Ot, FormControlComponent as Rt } from "./Functions.jsx";
|
|
6
|
+
import Ut from "superjson";
|
|
7
|
+
import { v4 as It } 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
|
|
9
|
+
import { getGlobalStore as o, formRefStore as Et } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Nt } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Ft } from "fast-json-patch";
|
|
12
|
+
import Dt from "react-use-measure";
|
|
13
|
+
function At(t, c) {
|
|
14
14
|
const h = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, I = h(t) || {};
|
|
15
15
|
S(t, {
|
|
16
16
|
...I,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function $t({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: h
|
|
@@ -30,12 +30,12 @@ function At({
|
|
|
30
30
|
!H(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
|
|
31
31
|
p && b(t, w);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ce(t, { formElements: c, validation: h }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: h };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const le = (t, c) => {
|
|
37
37
|
let h = t;
|
|
38
|
-
const [S, I] =
|
|
38
|
+
const [S, I] = Mt(h);
|
|
39
39
|
(Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((p) => {
|
|
40
40
|
I[p] = I[p] || {}, I[p].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
@@ -46,13 +46,13 @@ const ce = (t, c) => {
|
|
|
46
46
|
}, et(p) || o.getState().setInitialStateOptions(p, I[p]);
|
|
47
47
|
}), o.getState().setInitialStates(S), o.getState().setCreatedState(S);
|
|
48
48
|
const b = (p, a) => {
|
|
49
|
-
const [y] =
|
|
50
|
-
|
|
49
|
+
const [y] = Z(a?.componentId ?? It());
|
|
50
|
+
$t({
|
|
51
51
|
stateKey: p,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] =
|
|
55
|
+
const n = o.getState().cogsStateStore[p] || S[p], m = a?.modifyState ? a.modifyState(n) : n, [L, R] = qt(
|
|
56
56
|
m,
|
|
57
57
|
{
|
|
58
58
|
stateKey: p,
|
|
@@ -71,46 +71,46 @@ const ce = (t, c) => {
|
|
|
71
71
|
return R;
|
|
72
72
|
};
|
|
73
73
|
function w(p, a) {
|
|
74
|
-
|
|
74
|
+
$t({ stateKey: p, options: a, initialOptionsPart: I }), a.localStorage && zt(p, a), ft(p);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: b, setCogsOptions: w };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
78
|
+
setUpdaterState: dt,
|
|
79
|
+
setState: Q,
|
|
80
80
|
getInitialOptions: et,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
81
|
+
getKeyState: Vt,
|
|
82
|
+
getValidationErrors: Wt,
|
|
83
|
+
setStateLog: Lt,
|
|
84
|
+
updateInitialStateGlobal: pt,
|
|
85
|
+
addValidationError: Gt,
|
|
86
|
+
removeValidationError: B,
|
|
87
|
+
setServerSyncActions: Ht
|
|
88
|
+
} = o.getState(), kt = (t, c, h, S, I) => {
|
|
89
89
|
h?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
92
92
|
h.localStorage?.key,
|
|
93
93
|
S
|
|
94
94
|
);
|
|
95
|
-
const b =
|
|
95
|
+
const b = q(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
|
|
96
96
|
if (b && S) {
|
|
97
97
|
const w = `${S}-${c}-${b}`;
|
|
98
98
|
let p;
|
|
99
99
|
try {
|
|
100
|
-
p =
|
|
100
|
+
p = gt(w)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: I ?? p
|
|
107
|
-
}, y =
|
|
107
|
+
}, y = Ut.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
w,
|
|
110
110
|
JSON.stringify(y.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, gt = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
116
|
const c = window.localStorage.getItem(t);
|
|
@@ -118,20 +118,20 @@ const ce = (t, c) => {
|
|
|
118
118
|
} catch (c) {
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const h = o.getState().cogsStateStore[t], { sessionId: S } =
|
|
121
|
+
}, zt = (t, c) => {
|
|
122
|
+
const h = o.getState().cogsStateStore[t], { sessionId: S } = Nt(), I = q(c?.localStorage?.key) ? c.localStorage.key(h) : c?.localStorage?.key;
|
|
123
123
|
if (I && S) {
|
|
124
|
-
const b =
|
|
124
|
+
const b = gt(
|
|
125
125
|
`${S}-${t}-${I}`
|
|
126
126
|
);
|
|
127
127
|
if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
|
|
128
|
-
return
|
|
128
|
+
return Q(t, b.state), ft(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ct = (t, c, h, S, I, b) => {
|
|
132
132
|
const w = {
|
|
133
133
|
initialState: c,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: ut(
|
|
135
135
|
t,
|
|
136
136
|
S,
|
|
137
137
|
I,
|
|
@@ -139,8 +139,8 @@ const ce = (t, c) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: h
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
pt(t, w.initialState), dt(t, w.updaterState), Q(t, w.state);
|
|
143
|
+
}, ft = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
146
|
const h = /* @__PURE__ */ new Set();
|
|
@@ -149,7 +149,7 @@ const ce = (t, c) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
h.forEach((S) => S());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, de = (t, c) => {
|
|
153
153
|
const h = o.getState().stateComponents.get(t);
|
|
154
154
|
if (h) {
|
|
155
155
|
const S = `${t}////${c}`, I = h.components.get(S);
|
|
@@ -157,7 +157,7 @@ const ce = (t, c) => {
|
|
|
157
157
|
return;
|
|
158
158
|
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Bt = (t, c, h, S) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
@@ -180,7 +180,7 @@ const ce = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function qt(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: h,
|
|
186
186
|
localStorage: S,
|
|
@@ -193,14 +193,14 @@ function Bt(t, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: m
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [L, R] =
|
|
196
|
+
const [L, R] = Z({}), { sessionId: U } = Nt();
|
|
197
197
|
let G = !c;
|
|
198
|
-
const [v] =
|
|
198
|
+
const [v] = Z(c ?? It()), l = o.getState().stateLog[v], st = X(/* @__PURE__ */ new Set()), J = X(p ?? It()), j = X(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
201
|
j.current = et(v) ?? null, nt(() => {
|
|
202
202
|
if (y && y.stateKey === v && y.path?.[0]) {
|
|
203
|
-
|
|
203
|
+
Q(v, (r) => ({
|
|
204
204
|
...r,
|
|
205
205
|
[y.path[0]]: y.newValue
|
|
206
206
|
}));
|
|
@@ -212,40 +212,40 @@ function Bt(t, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [y]), nt(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
At(v, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
218
|
const e = j.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[v];
|
|
219
219
|
if (!(i && !H(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
222
|
-
const E =
|
|
223
|
-
E && U && (
|
|
221
|
+
let f = null;
|
|
222
|
+
const E = q(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
E && U && (f = gt(`${U}-${v}-${E}`));
|
|
224
224
|
let T = a, A = !1;
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
225
|
+
const P = s ? Date.now() : 0, V = f?.lastUpdated || 0, $ = f?.lastSyncedWithServer || 0;
|
|
226
|
+
s && P > V ? (T = e.serverState.data, A = !0) : f && V > $ && (T = f.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(v, a), Ct(
|
|
227
227
|
v,
|
|
228
228
|
a,
|
|
229
229
|
T,
|
|
230
230
|
rt,
|
|
231
|
-
|
|
231
|
+
J.current,
|
|
232
232
|
U
|
|
233
|
-
), A && E && U &&
|
|
233
|
+
), A && E && U && kt(T, v, e, U, Date.now()), ft(v), (Array.isArray(w) ? w : [w || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
m?.status,
|
|
238
238
|
m?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
G &&
|
|
240
|
+
]), lt(() => {
|
|
241
|
+
G && At(v, {
|
|
242
242
|
serverSync: h,
|
|
243
243
|
formElements: I,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: S,
|
|
246
246
|
middleware: j.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${v}////${
|
|
248
|
+
const e = `${v}////${J.current}`, r = o.getState().stateComponents.get(v) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
@@ -260,101 +260,101 @@ function Bt(t, {
|
|
|
260
260
|
}, []);
|
|
261
261
|
const rt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const
|
|
264
|
-
st.current.add(
|
|
263
|
+
const f = `${v}-${r.join(".")}`;
|
|
264
|
+
st.current.add(f);
|
|
265
265
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const E =
|
|
266
|
+
const g = o.getState();
|
|
267
|
+
Q(v, (f) => {
|
|
268
|
+
const E = q(e) ? e(f) : e, T = `${v}-${r.join(".")}`;
|
|
269
269
|
if (T) {
|
|
270
|
-
let M = !1, N =
|
|
270
|
+
let M = !1, N = g.signalDomElements.get(T);
|
|
271
271
|
if ((!N || N.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
272
|
const O = r.slice(0, -1), W = z(E, O);
|
|
273
273
|
if (Array.isArray(W)) {
|
|
274
274
|
M = !0;
|
|
275
|
-
const
|
|
276
|
-
N =
|
|
275
|
+
const u = `${v}-${O.join(".")}`;
|
|
276
|
+
N = g.signalDomElements.get(u);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if (N) {
|
|
280
280
|
const O = M ? z(E, r.slice(0, -1)) : z(E, r);
|
|
281
|
-
N.forEach(({ parentId: W, position:
|
|
281
|
+
N.forEach(({ parentId: W, position: u, effect: k }) => {
|
|
282
282
|
const C = document.querySelector(
|
|
283
283
|
`[data-parent-id="${W}"]`
|
|
284
284
|
);
|
|
285
285
|
if (C) {
|
|
286
286
|
const _ = Array.from(C.childNodes);
|
|
287
|
-
if (_[
|
|
288
|
-
const
|
|
289
|
-
_[
|
|
287
|
+
if (_[u]) {
|
|
288
|
+
const x = k ? new Function("state", `return (${k})(state)`)(O) : O;
|
|
289
|
+
_[u].textContent = String(x);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState",
|
|
295
|
+
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || j.current?.validation?.key) && r && B(
|
|
296
296
|
(i || j.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
298
|
const A = r.slice(0, r.length - 1);
|
|
299
|
-
s.updateType === "cut" && j.current?.validation?.key &&
|
|
299
|
+
s.updateType === "cut" && j.current?.validation?.key && B(
|
|
300
300
|
j.current?.validation?.key + "." + A.join(".")
|
|
301
|
-
), s.updateType === "insert" && j.current?.validation?.key &&
|
|
301
|
+
), s.updateType === "insert" && j.current?.validation?.key && Wt(
|
|
302
302
|
j.current?.validation?.key + "." + A.join(".")
|
|
303
303
|
).filter(([N, O]) => {
|
|
304
304
|
let W = N?.split(".").length;
|
|
305
305
|
if (N == A.join(".") && W == A.length - 1) {
|
|
306
|
-
let
|
|
307
|
-
|
|
306
|
+
let u = N + "." + A;
|
|
307
|
+
B(N), Gt(u, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const M =
|
|
310
|
+
const P = g.stateComponents.get(v);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
|
|
312
|
+
const M = yt(f, E), N = new Set(M), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
W,
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const C = Array.isArray(
|
|
319
|
-
if (console.log("component",
|
|
315
|
+
u
|
|
316
|
+
] of P.components.entries()) {
|
|
317
|
+
let k = !1;
|
|
318
|
+
const C = Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", u), !C.includes("none")) {
|
|
320
320
|
if (C.includes("all")) {
|
|
321
|
-
|
|
321
|
+
u.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (C.includes("component") && ((
|
|
324
|
+
if (C.includes("component") && ((u.paths.has(O) || u.paths.has("")) && (k = !0), !k))
|
|
325
325
|
for (const _ of N) {
|
|
326
|
-
let
|
|
326
|
+
let x = _;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (u.paths.has(x)) {
|
|
329
|
+
k = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const Y = x.lastIndexOf(".");
|
|
333
|
+
if (Y !== -1) {
|
|
334
|
+
const K = x.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
Y
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(x.substring(Y + 1))
|
|
340
|
+
) && u.paths.has(K)) {
|
|
341
|
+
k = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
x = K;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
x = "";
|
|
347
|
+
if (x === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (k) break;
|
|
351
351
|
}
|
|
352
|
-
if (
|
|
353
|
-
const _ =
|
|
354
|
-
let
|
|
355
|
-
typeof _ == "boolean" ? _ && (
|
|
352
|
+
if (!k && C.includes("deps") && u.depsFunction) {
|
|
353
|
+
const _ = u.depsFunction(E);
|
|
354
|
+
let x = !1;
|
|
355
|
+
typeof _ == "boolean" ? _ && (x = !0) : H(u.deps, _) || (u.deps = _, x = !0), x && (k = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
k && u.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -363,9 +363,9 @@ function Bt(t, {
|
|
|
363
363
|
const O = r.slice(0, -1), W = z(E, O);
|
|
364
364
|
return N === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (W.length - 1).toString() : M;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: $, newValue: D } = Bt(
|
|
367
367
|
s.updateType,
|
|
368
|
-
|
|
368
|
+
f,
|
|
369
369
|
E,
|
|
370
370
|
r
|
|
371
371
|
), F = {
|
|
@@ -374,29 +374,29 @@ function Bt(t, {
|
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: $,
|
|
378
378
|
newValue: D
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
|
|
382
|
+
g.updateShadowAtPath(v, r, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const M = r.slice(0, -1);
|
|
386
|
-
|
|
386
|
+
g.insertShadowArrayElement(v, M, D);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
389
|
const N = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
-
|
|
390
|
+
g.removeShadowArrayElement(v, N, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const O = [...M ?? [], F].reduce((W,
|
|
395
|
-
const
|
|
396
|
-
return C ? (C.timeStamp = Math.max(C.timeStamp,
|
|
393
|
+
if (Lt(v, (M) => {
|
|
394
|
+
const O = [...M ?? [], F].reduce((W, u) => {
|
|
395
|
+
const k = `${u.stateKey}:${JSON.stringify(u.path)}`, C = W.get(k);
|
|
396
|
+
return C ? (C.timeStamp = Math.max(C.timeStamp, u.timeStamp), C.newValue = u.newValue, C.oldValue = C.oldValue ?? u.oldValue, C.updateType = u.updateType) : W.set(k, { ...u }), W;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(O.values());
|
|
399
|
-
}),
|
|
399
|
+
}), kt(
|
|
400
400
|
E,
|
|
401
401
|
v,
|
|
402
402
|
j.current,
|
|
@@ -405,8 +405,8 @@ function Bt(t, {
|
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: F
|
|
407
407
|
}), j.current?.serverSync) {
|
|
408
|
-
const M =
|
|
409
|
-
|
|
408
|
+
const M = g.serverState[v], N = j.current?.serverSync;
|
|
409
|
+
Ht(v, {
|
|
410
410
|
syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
412
|
actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
|
|
@@ -416,24 +416,24 @@ function Bt(t, {
|
|
|
416
416
|
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[v] || (
|
|
419
|
+
o.getState().updaterState[v] || (dt(
|
|
420
420
|
v,
|
|
421
|
-
|
|
421
|
+
ut(
|
|
422
422
|
v,
|
|
423
423
|
rt,
|
|
424
|
-
|
|
424
|
+
J.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[v] ||
|
|
428
|
-
const d =
|
|
427
|
+
), o.getState().cogsStateStore[v] || Q(v, t), o.getState().initialStateGlobal[v] || pt(v, t));
|
|
428
|
+
const d = vt(() => ut(
|
|
429
429
|
v,
|
|
430
430
|
rt,
|
|
431
|
-
|
|
431
|
+
J.current,
|
|
432
432
|
U
|
|
433
433
|
), [v, U]);
|
|
434
|
-
return [
|
|
434
|
+
return [Vt(v), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function ut(t, c, h, S) {
|
|
437
437
|
const I = /* @__PURE__ */ new Map();
|
|
438
438
|
let b = 0;
|
|
439
439
|
const w = (y) => {
|
|
@@ -443,15 +443,15 @@ function dt(t, c, h, S) {
|
|
|
443
443
|
b++;
|
|
444
444
|
}, p = {
|
|
445
445
|
removeValidation: (y) => {
|
|
446
|
-
y?.validationKey &&
|
|
446
|
+
y?.validationKey && B(y.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (y) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && B(n?.key), y?.validationKey && B(y.validationKey);
|
|
451
451
|
const m = o.getState().initialStateGlobal[t];
|
|
452
452
|
o.getState().clearSelectedIndexesForState(t), I.clear(), b++;
|
|
453
|
-
const L = a(m, []), R = et(t), U =
|
|
454
|
-
G && localStorage.removeItem(G),
|
|
453
|
+
const L = a(m, []), R = et(t), U = q(R?.localStorage?.key) ? R?.localStorage?.key(m) : R?.localStorage?.key, G = `${S}-${t}-${U}`;
|
|
454
|
+
G && localStorage.removeItem(G), dt(t, L), Q(t, m);
|
|
455
455
|
const v = o.getState().stateComponents.get(t);
|
|
456
456
|
return v && v.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
@@ -459,14 +459,14 @@ function dt(t, c, h, S) {
|
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (y) => {
|
|
461
461
|
I.clear(), b++;
|
|
462
|
-
const n =
|
|
462
|
+
const n = ut(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
h,
|
|
466
466
|
S
|
|
467
|
-
), m = o.getState().initialStateGlobal[t], L = et(t), R =
|
|
468
|
-
return localStorage.getItem(U) && localStorage.removeItem(U),
|
|
469
|
-
|
|
467
|
+
), m = o.getState().initialStateGlobal[t], L = et(t), R = q(L?.localStorage?.key) ? L?.localStorage?.key(m) : L?.localStorage?.key, U = `${S}-${t}-${R}`;
|
|
468
|
+
return localStorage.getItem(U) && localStorage.removeItem(U), _t(() => {
|
|
469
|
+
pt(t, y), o.getState().initializeShadowState(t, y), dt(t, n), Q(t, y);
|
|
470
470
|
const G = o.getState().stateComponents.get(t);
|
|
471
471
|
G && G.components.forEach((v) => {
|
|
472
472
|
v.forceUpdate();
|
|
@@ -480,7 +480,7 @@ function dt(t, c, h, S) {
|
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const y = o.getState().serverState[t];
|
|
483
|
-
return !!(y && H(y,
|
|
483
|
+
return !!(y && H(y, Vt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(y, n = [], m) {
|
|
@@ -530,8 +530,8 @@ function dt(t, c, h, S) {
|
|
|
530
530
|
if (r && !r.paths.has("")) {
|
|
531
531
|
const s = n.join(".");
|
|
532
532
|
let i = !0;
|
|
533
|
-
for (const
|
|
534
|
-
if (s.startsWith(
|
|
533
|
+
for (const g of r.paths)
|
|
534
|
+
if (s.startsWith(g) && (s === g || s[g.length] === ".")) {
|
|
535
535
|
i = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
@@ -540,7 +540,7 @@ function dt(t, c, h, S) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => yt(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -553,13 +553,13 @@ function dt(t, c, h, S) {
|
|
|
553
553
|
try {
|
|
554
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 E = [s, ...
|
|
558
|
-
o.getState().addValidationError(E,
|
|
556
|
+
o.getState().removeValidationError(s), i.errors.forEach((f) => {
|
|
557
|
+
const E = [s, ...f.path].join(".");
|
|
558
|
+
o.getState().addValidationError(E, f.message);
|
|
559
559
|
});
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
const g = o.getState().stateComponents.get(t);
|
|
561
|
+
g && g.components.forEach((f) => {
|
|
562
|
+
f.forceUpdate();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
565
|
return i?.success && e.onSuccess ? e.onSuccess(i.data) : !i?.success && e.onError && e.onError(i.error), i;
|
|
@@ -581,7 +581,7 @@ function dt(t, c, h, S) {
|
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e = et(t), r =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = et(t), r = q(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${S}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -621,102 +621,102 @@ function dt(t, c, h, S) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e,
|
|
624
|
+
} = e, g = X(null), [f, E] = Z({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
|
-
}), T =
|
|
627
|
+
}), T = X(i), [A, P] = Z(0);
|
|
628
628
|
nt(() => o.getState().subscribeToShadowState(t, () => {
|
|
629
|
-
|
|
629
|
+
P((k) => k + 1);
|
|
630
630
|
}), [t]);
|
|
631
631
|
const V = o().getNestedState(
|
|
632
632
|
t,
|
|
633
633
|
n
|
|
634
|
-
),
|
|
635
|
-
const
|
|
636
|
-
let
|
|
634
|
+
), $ = V.length, { totalHeight: D, positions: F } = vt(() => {
|
|
635
|
+
const u = o.getState().getShadowMetadata(t, n) || [];
|
|
636
|
+
let k = 0;
|
|
637
637
|
const C = [];
|
|
638
|
-
for (let _ = 0; _ <
|
|
639
|
-
C[_] =
|
|
640
|
-
const
|
|
641
|
-
|
|
638
|
+
for (let _ = 0; _ < $; _++) {
|
|
639
|
+
C[_] = k;
|
|
640
|
+
const x = u[_]?.virtualizer?.itemHeight;
|
|
641
|
+
k += x || r;
|
|
642
642
|
}
|
|
643
|
-
return { totalHeight:
|
|
643
|
+
return { totalHeight: k, positions: C };
|
|
644
644
|
}, [
|
|
645
|
-
|
|
645
|
+
$,
|
|
646
646
|
t,
|
|
647
647
|
n.join("."),
|
|
648
648
|
r,
|
|
649
649
|
A
|
|
650
|
-
]), M =
|
|
651
|
-
const
|
|
652
|
-
{ length:
|
|
653
|
-
(
|
|
654
|
-
), _ = C.map((
|
|
650
|
+
]), M = vt(() => {
|
|
651
|
+
const u = Math.max(0, f.startIndex), k = Math.min($, f.endIndex), C = Array.from(
|
|
652
|
+
{ length: k - u },
|
|
653
|
+
(x, Y) => u + Y
|
|
654
|
+
), _ = C.map((x) => V[x]);
|
|
655
655
|
return a(_, n, {
|
|
656
656
|
...m,
|
|
657
657
|
validIndices: C
|
|
658
658
|
});
|
|
659
|
-
}, [
|
|
659
|
+
}, [f.startIndex, f.endIndex, V, $]);
|
|
660
660
|
nt(() => {
|
|
661
|
-
if (i &&
|
|
662
|
-
const
|
|
663
|
-
|
|
661
|
+
if (i && $ > 0 && g.current) {
|
|
662
|
+
const u = g.current, k = Math.ceil(
|
|
663
|
+
u.clientHeight / r
|
|
664
664
|
);
|
|
665
665
|
E({
|
|
666
666
|
startIndex: Math.max(
|
|
667
667
|
0,
|
|
668
|
-
|
|
668
|
+
$ - k - s
|
|
669
669
|
),
|
|
670
|
-
endIndex:
|
|
670
|
+
endIndex: $
|
|
671
671
|
}), setTimeout(() => {
|
|
672
|
-
|
|
672
|
+
u.scrollTop = u.scrollHeight;
|
|
673
673
|
}, 100);
|
|
674
674
|
}
|
|
675
|
-
}, [
|
|
676
|
-
const
|
|
677
|
-
if (!
|
|
678
|
-
const
|
|
679
|
-
if (!
|
|
680
|
-
const { scrollTop:
|
|
681
|
-
let
|
|
682
|
-
for (;
|
|
683
|
-
const
|
|
684
|
-
F[
|
|
675
|
+
}, [$]), lt(() => {
|
|
676
|
+
const u = g.current;
|
|
677
|
+
if (!u) return;
|
|
678
|
+
const k = u.scrollHeight - u.scrollTop - u.clientHeight < 1, C = () => {
|
|
679
|
+
if (!u) return;
|
|
680
|
+
const { scrollTop: x, clientHeight: Y } = u;
|
|
681
|
+
let K = 0, it = $ - 1;
|
|
682
|
+
for (; K <= it; ) {
|
|
683
|
+
const St = Math.floor((K + it) / 2);
|
|
684
|
+
F[St] < x ? K = St + 1 : it = St - 1;
|
|
685
685
|
}
|
|
686
|
-
const
|
|
687
|
-
let tt =
|
|
688
|
-
const
|
|
689
|
-
for (; tt <
|
|
686
|
+
const wt = Math.max(0, it - s);
|
|
687
|
+
let tt = wt;
|
|
688
|
+
const xt = x + Y;
|
|
689
|
+
for (; tt < $ && F[tt] < xt; )
|
|
690
690
|
tt++;
|
|
691
|
-
tt = Math.min(
|
|
692
|
-
},
|
|
693
|
-
T.current =
|
|
691
|
+
tt = Math.min($, tt + s), E({ startIndex: wt, endIndex: tt });
|
|
692
|
+
}, _ = () => {
|
|
693
|
+
T.current = u.scrollHeight - u.scrollTop - u.clientHeight < 1, C();
|
|
694
694
|
};
|
|
695
|
-
return
|
|
695
|
+
return u.addEventListener("scroll", _, {
|
|
696
696
|
passive: !0
|
|
697
|
-
}), i && T.current && (
|
|
698
|
-
|
|
697
|
+
}), i && (T.current || k) && (u.scrollTop = u.scrollHeight), C(), () => {
|
|
698
|
+
u.removeEventListener("scroll", _);
|
|
699
699
|
};
|
|
700
|
-
}, [
|
|
701
|
-
const N =
|
|
702
|
-
(
|
|
703
|
-
|
|
704
|
-
top:
|
|
705
|
-
behavior:
|
|
700
|
+
}, [$, F, D, i]);
|
|
701
|
+
const N = Tt(
|
|
702
|
+
(u = "smooth") => {
|
|
703
|
+
g.current && (T.current = !0, g.current.scrollTo({
|
|
704
|
+
top: g.current.scrollHeight,
|
|
705
|
+
behavior: u
|
|
706
706
|
}));
|
|
707
707
|
},
|
|
708
708
|
[]
|
|
709
|
-
), O =
|
|
710
|
-
(
|
|
711
|
-
|
|
712
|
-
top: F[
|
|
713
|
-
behavior:
|
|
709
|
+
), O = Tt(
|
|
710
|
+
(u, k = "smooth") => {
|
|
711
|
+
g.current && F[u] !== void 0 && (T.current = !1, g.current.scrollTo({
|
|
712
|
+
top: F[u],
|
|
713
|
+
behavior: k
|
|
714
714
|
}));
|
|
715
715
|
},
|
|
716
716
|
[F]
|
|
717
717
|
), W = {
|
|
718
718
|
outer: {
|
|
719
|
-
ref:
|
|
719
|
+
ref: g,
|
|
720
720
|
style: { overflowY: "auto", height: "100%" }
|
|
721
721
|
},
|
|
722
722
|
inner: {
|
|
@@ -727,7 +727,7 @@ function dt(t, c, h, S) {
|
|
|
727
727
|
},
|
|
728
728
|
list: {
|
|
729
729
|
style: {
|
|
730
|
-
transform: `translateY(${F[
|
|
730
|
+
transform: `translateY(${F[f.startIndex] || 0}px)`
|
|
731
731
|
}
|
|
732
732
|
}
|
|
733
733
|
};
|
|
@@ -741,49 +741,49 @@ function dt(t, c, h, S) {
|
|
|
741
741
|
if (l === "stateSort")
|
|
742
742
|
return (e) => {
|
|
743
743
|
const s = [...d()].sort(
|
|
744
|
-
(
|
|
745
|
-
), i = s.map(({ item:
|
|
744
|
+
(f, E) => e(f.item, E.item)
|
|
745
|
+
), i = s.map(({ item: f }) => f), g = {
|
|
746
746
|
...m,
|
|
747
747
|
validIndices: s.map(
|
|
748
|
-
({ originalIndex:
|
|
748
|
+
({ originalIndex: f }) => f
|
|
749
749
|
)
|
|
750
750
|
};
|
|
751
|
-
return a(i, n,
|
|
751
|
+
return a(i, n, g);
|
|
752
752
|
};
|
|
753
753
|
if (l === "stateFilter")
|
|
754
754
|
return (e) => {
|
|
755
755
|
const s = d().filter(
|
|
756
|
-
({ item:
|
|
757
|
-
), i = s.map(({ item:
|
|
756
|
+
({ item: f }, E) => e(f, E)
|
|
757
|
+
), i = s.map(({ item: f }) => f), g = {
|
|
758
758
|
...m,
|
|
759
759
|
validIndices: s.map(
|
|
760
|
-
({ originalIndex:
|
|
760
|
+
({ originalIndex: f }) => f
|
|
761
761
|
)
|
|
762
762
|
};
|
|
763
|
-
return a(i, n,
|
|
763
|
+
return a(i, n, g);
|
|
764
764
|
};
|
|
765
765
|
if (l === "stateMap")
|
|
766
766
|
return (e) => {
|
|
767
767
|
const r = o.getState().getNestedState(t, n);
|
|
768
|
-
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i,
|
|
769
|
-
const
|
|
770
|
-
return e(
|
|
768
|
+
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
769
|
+
const f = r[i], E = [...n, i.toString()], T = a(f, E, m);
|
|
770
|
+
return e(f, T, {
|
|
771
771
|
register: () => {
|
|
772
|
-
const [,
|
|
773
|
-
|
|
774
|
-
const
|
|
772
|
+
const [, P] = Z({}), V = `${h}-${n.join(".")}-${i}`;
|
|
773
|
+
lt(() => {
|
|
774
|
+
const $ = `${t}////${V}`, D = o.getState().stateComponents.get(t) || {
|
|
775
775
|
components: /* @__PURE__ */ new Map()
|
|
776
776
|
};
|
|
777
|
-
return D.components.set(
|
|
778
|
-
forceUpdate: () =>
|
|
777
|
+
return D.components.set($, {
|
|
778
|
+
forceUpdate: () => P({}),
|
|
779
779
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
780
780
|
}), o.getState().stateComponents.set(t, D), () => {
|
|
781
781
|
const F = o.getState().stateComponents.get(t);
|
|
782
|
-
F && F.components.delete(
|
|
782
|
+
F && F.components.delete($);
|
|
783
783
|
};
|
|
784
784
|
}, [t, V]);
|
|
785
785
|
},
|
|
786
|
-
index:
|
|
786
|
+
index: g,
|
|
787
787
|
originalIndex: i
|
|
788
788
|
});
|
|
789
789
|
}) : (console.warn(
|
|
@@ -793,9 +793,9 @@ function dt(t, c, h, S) {
|
|
|
793
793
|
};
|
|
794
794
|
if (l === "stateMapNoRender")
|
|
795
795
|
return (e) => y.map((s, i) => {
|
|
796
|
-
let
|
|
797
|
-
m?.validIndices && m.validIndices[i] !== void 0 ?
|
|
798
|
-
const
|
|
796
|
+
let g;
|
|
797
|
+
m?.validIndices && m.validIndices[i] !== void 0 ? g = m.validIndices[i] : g = i;
|
|
798
|
+
const f = [...n, g.toString()], E = a(s, f, m);
|
|
799
799
|
return e(
|
|
800
800
|
s,
|
|
801
801
|
E,
|
|
@@ -805,7 +805,7 @@ function dt(t, c, h, S) {
|
|
|
805
805
|
);
|
|
806
806
|
});
|
|
807
807
|
if (l === "$stateMap")
|
|
808
|
-
return (e) => at(
|
|
808
|
+
return (e) => at(Jt, {
|
|
809
809
|
proxy: {
|
|
810
810
|
_stateKey: t,
|
|
811
811
|
_path: n,
|
|
@@ -817,17 +817,17 @@ function dt(t, c, h, S) {
|
|
|
817
817
|
if (l === "stateList")
|
|
818
818
|
return (e) => {
|
|
819
819
|
const r = o.getState().getNestedState(t, n);
|
|
820
|
-
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i,
|
|
821
|
-
const
|
|
822
|
-
return at(
|
|
820
|
+
return Array.isArray(r) ? (m?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
821
|
+
const f = r[i], E = [...n, i.toString()], T = a(f, E, m), A = `${h}-${n.join(".")}-${i}`;
|
|
822
|
+
return at(Zt, {
|
|
823
823
|
key: i,
|
|
824
824
|
stateKey: t,
|
|
825
825
|
itemComponentId: A,
|
|
826
826
|
itemPath: E,
|
|
827
827
|
children: e(
|
|
828
|
-
|
|
828
|
+
f,
|
|
829
829
|
T,
|
|
830
|
-
|
|
830
|
+
g,
|
|
831
831
|
r,
|
|
832
832
|
a(r, n, m)
|
|
833
833
|
)
|
|
@@ -862,28 +862,28 @@ function dt(t, c, h, S) {
|
|
|
862
862
|
return a(s, i);
|
|
863
863
|
};
|
|
864
864
|
if (l === "insert")
|
|
865
|
-
return (e) => (w(n),
|
|
865
|
+
return (e) => (w(n), mt(c, e, n, t), a(
|
|
866
866
|
o.getState().getNestedState(t, n),
|
|
867
867
|
n
|
|
868
868
|
));
|
|
869
869
|
if (l === "uniqueInsert")
|
|
870
870
|
return (e, r, s) => {
|
|
871
|
-
const i = o.getState().getNestedState(t, n),
|
|
872
|
-
let
|
|
871
|
+
const i = o.getState().getNestedState(t, n), g = q(e) ? e(i) : e;
|
|
872
|
+
let f = null;
|
|
873
873
|
if (!i.some((T) => {
|
|
874
874
|
if (r) {
|
|
875
|
-
const
|
|
876
|
-
(V) => H(T[V],
|
|
875
|
+
const P = r.every(
|
|
876
|
+
(V) => H(T[V], g[V])
|
|
877
877
|
);
|
|
878
|
-
return
|
|
878
|
+
return P && (f = T), P;
|
|
879
879
|
}
|
|
880
|
-
const A = H(T,
|
|
881
|
-
return A && (
|
|
880
|
+
const A = H(T, g);
|
|
881
|
+
return A && (f = T), A;
|
|
882
882
|
}))
|
|
883
|
-
w(n),
|
|
884
|
-
else if (s &&
|
|
885
|
-
const T = s(
|
|
886
|
-
(
|
|
883
|
+
w(n), mt(c, g, n, t);
|
|
884
|
+
else if (s && f) {
|
|
885
|
+
const T = s(f), A = i.map(
|
|
886
|
+
(P) => H(P, f) ? T : P
|
|
887
887
|
);
|
|
888
888
|
w(n), ot(c, A, n);
|
|
889
889
|
}
|
|
@@ -891,7 +891,7 @@ function dt(t, c, h, S) {
|
|
|
891
891
|
if (l === "cut")
|
|
892
892
|
return (e, r) => {
|
|
893
893
|
if (!r?.waitForSync)
|
|
894
|
-
return w(n),
|
|
894
|
+
return w(n), ct(c, n, t, e), a(
|
|
895
895
|
o.getState().getNestedState(t, n),
|
|
896
896
|
n
|
|
897
897
|
);
|
|
@@ -899,17 +899,17 @@ function dt(t, c, h, S) {
|
|
|
899
899
|
if (l === "cutByValue")
|
|
900
900
|
return (e) => {
|
|
901
901
|
for (let r = 0; r < y.length; r++)
|
|
902
|
-
y[r] === e &&
|
|
902
|
+
y[r] === e && ct(c, n, t, r);
|
|
903
903
|
};
|
|
904
904
|
if (l === "toggleByValue")
|
|
905
905
|
return (e) => {
|
|
906
906
|
const r = y.findIndex((s) => s === e);
|
|
907
|
-
r > -1 ?
|
|
907
|
+
r > -1 ? ct(c, n, t, r) : mt(c, e, n, t);
|
|
908
908
|
};
|
|
909
909
|
if (l === "stateFind")
|
|
910
910
|
return (e) => {
|
|
911
911
|
const s = d().find(
|
|
912
|
-
({ item:
|
|
912
|
+
({ item: g }, f) => e(g, f)
|
|
913
913
|
);
|
|
914
914
|
if (!s) return;
|
|
915
915
|
const i = [...n, s.originalIndex.toString()];
|
|
@@ -918,22 +918,22 @@ function dt(t, c, h, S) {
|
|
|
918
918
|
if (l === "findWith")
|
|
919
919
|
return (e, r) => {
|
|
920
920
|
const i = d().find(
|
|
921
|
-
({ item:
|
|
921
|
+
({ item: f }) => f[e] === r
|
|
922
922
|
);
|
|
923
923
|
if (!i) return;
|
|
924
|
-
const
|
|
925
|
-
return a(i.item,
|
|
924
|
+
const g = [...n, i.originalIndex.toString()];
|
|
925
|
+
return a(i.item, g, m);
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
|
-
const
|
|
929
|
-
if (!isNaN(Number(
|
|
928
|
+
const J = n[n.length - 1];
|
|
929
|
+
if (!isNaN(Number(J))) {
|
|
930
930
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
931
931
|
if (Array.isArray(e) && l === "cut")
|
|
932
|
-
return () =>
|
|
932
|
+
return () => ct(
|
|
933
933
|
c,
|
|
934
934
|
d,
|
|
935
935
|
t,
|
|
936
|
-
Number(
|
|
936
|
+
Number(J)
|
|
937
937
|
);
|
|
938
938
|
}
|
|
939
939
|
if (l === "get")
|
|
@@ -945,13 +945,13 @@ function dt(t, c, h, S) {
|
|
|
945
945
|
return o.getState().getNestedState(t, n);
|
|
946
946
|
};
|
|
947
947
|
if (l === "$derive")
|
|
948
|
-
return (d) =>
|
|
948
|
+
return (d) => bt({
|
|
949
949
|
_stateKey: t,
|
|
950
950
|
_path: n,
|
|
951
951
|
_effect: d.toString()
|
|
952
952
|
});
|
|
953
953
|
if (l === "$get")
|
|
954
|
-
return () =>
|
|
954
|
+
return () => bt({
|
|
955
955
|
_stateKey: t,
|
|
956
956
|
_path: n
|
|
957
957
|
});
|
|
@@ -960,7 +960,7 @@ function dt(t, c, h, S) {
|
|
|
960
960
|
return o.getState().getSyncInfo(d);
|
|
961
961
|
}
|
|
962
962
|
if (l == "getLocalStorage")
|
|
963
|
-
return (d) =>
|
|
963
|
+
return (d) => gt(S + "-" + t + "-" + d);
|
|
964
964
|
if (l === "_selected") {
|
|
965
965
|
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
966
966
|
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -986,8 +986,8 @@ function dt(t, c, h, S) {
|
|
|
986
986
|
if (n.length == 0) {
|
|
987
987
|
if (l === "applyJsonPatch")
|
|
988
988
|
return (d) => {
|
|
989
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
990
|
-
|
|
989
|
+
const e = o.getState().cogsStateStore[t], s = Ft(e, d).newDocument;
|
|
990
|
+
Ct(
|
|
991
991
|
t,
|
|
992
992
|
o.getState().initialStateGlobal[t],
|
|
993
993
|
s,
|
|
@@ -997,33 +997,33 @@ function dt(t, c, h, S) {
|
|
|
997
997
|
);
|
|
998
998
|
const i = o.getState().stateComponents.get(t);
|
|
999
999
|
if (i) {
|
|
1000
|
-
const
|
|
1000
|
+
const g = yt(e, s), f = new Set(g);
|
|
1001
1001
|
for (const [
|
|
1002
1002
|
E,
|
|
1003
1003
|
T
|
|
1004
1004
|
] of i.components.entries()) {
|
|
1005
1005
|
let A = !1;
|
|
1006
|
-
const
|
|
1007
|
-
if (!
|
|
1008
|
-
if (
|
|
1006
|
+
const P = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
|
|
1007
|
+
if (!P.includes("none")) {
|
|
1008
|
+
if (P.includes("all")) {
|
|
1009
1009
|
T.forceUpdate();
|
|
1010
1010
|
continue;
|
|
1011
1011
|
}
|
|
1012
|
-
if (
|
|
1013
|
-
for (const V of
|
|
1012
|
+
if (P.includes("component") && (T.paths.has("") && (A = !0), !A))
|
|
1013
|
+
for (const V of f) {
|
|
1014
1014
|
if (T.paths.has(V)) {
|
|
1015
1015
|
A = !0;
|
|
1016
1016
|
break;
|
|
1017
1017
|
}
|
|
1018
|
-
let
|
|
1019
|
-
for (;
|
|
1020
|
-
const D = V.substring(0,
|
|
1018
|
+
let $ = V.lastIndexOf(".");
|
|
1019
|
+
for (; $ !== -1; ) {
|
|
1020
|
+
const D = V.substring(0, $);
|
|
1021
1021
|
if (T.paths.has(D)) {
|
|
1022
1022
|
A = !0;
|
|
1023
1023
|
break;
|
|
1024
1024
|
}
|
|
1025
1025
|
const F = V.substring(
|
|
1026
|
-
|
|
1026
|
+
$ + 1
|
|
1027
1027
|
);
|
|
1028
1028
|
if (!isNaN(Number(F))) {
|
|
1029
1029
|
const M = D.lastIndexOf(".");
|
|
@@ -1038,14 +1038,14 @@ function dt(t, c, h, S) {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
|
-
|
|
1041
|
+
$ = D.lastIndexOf(".");
|
|
1042
1042
|
}
|
|
1043
1043
|
if (A) break;
|
|
1044
1044
|
}
|
|
1045
|
-
if (!A &&
|
|
1045
|
+
if (!A && P.includes("deps") && T.depsFunction) {
|
|
1046
1046
|
const V = T.depsFunction(s);
|
|
1047
|
-
let
|
|
1048
|
-
typeof V == "boolean" ? V && (
|
|
1047
|
+
let $ = !1;
|
|
1048
|
+
typeof V == "boolean" ? V && ($ = !0) : H(T.deps, V) || (T.deps = V, $ = !0), $ && (A = !0);
|
|
1049
1049
|
}
|
|
1050
1050
|
A && T.forceUpdate();
|
|
1051
1051
|
}
|
|
@@ -1059,18 +1059,18 @@ function dt(t, c, h, S) {
|
|
|
1059
1059
|
throw new Error("Zod schema not found");
|
|
1060
1060
|
if (!d?.key)
|
|
1061
1061
|
throw new Error("Validation key not found");
|
|
1062
|
-
|
|
1062
|
+
B(d.key);
|
|
1063
1063
|
const r = o.getState().cogsStateStore[t];
|
|
1064
1064
|
try {
|
|
1065
1065
|
const s = o.getState().getValidationErrors(d.key);
|
|
1066
|
-
s && s.length > 0 && s.forEach(([
|
|
1067
|
-
|
|
1066
|
+
s && s.length > 0 && s.forEach(([g]) => {
|
|
1067
|
+
g && g.startsWith(d.key) && B(g);
|
|
1068
1068
|
});
|
|
1069
1069
|
const i = d.zodSchema.safeParse(r);
|
|
1070
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
1071
|
-
const E =
|
|
1070
|
+
return i.success ? !0 : (i.error.errors.forEach((f) => {
|
|
1071
|
+
const E = f.path, T = f.message, A = [d.key, ...E].join(".");
|
|
1072
1072
|
e(A, T);
|
|
1073
|
-
}),
|
|
1073
|
+
}), ft(t), !1);
|
|
1074
1074
|
} catch (s) {
|
|
1075
1075
|
return console.error("Zod schema validation failed", s), !1;
|
|
1076
1076
|
}
|
|
@@ -1079,7 +1079,7 @@ function dt(t, c, h, S) {
|
|
|
1079
1079
|
if (l === "getComponents")
|
|
1080
1080
|
return () => o().stateComponents.get(t);
|
|
1081
1081
|
if (l === "getAllFormRefs")
|
|
1082
|
-
return () =>
|
|
1082
|
+
return () => Et.getState().getFormRefsByStateKey(t);
|
|
1083
1083
|
if (l === "_initialState")
|
|
1084
1084
|
return o.getState().initialStateGlobal[t];
|
|
1085
1085
|
if (l === "_serverState")
|
|
@@ -1092,13 +1092,13 @@ function dt(t, c, h, S) {
|
|
|
1092
1092
|
if (l === "removeValidation") return p.removeValidation;
|
|
1093
1093
|
}
|
|
1094
1094
|
if (l === "getFormRef")
|
|
1095
|
-
return () =>
|
|
1095
|
+
return () => Et.getState().getFormRef(t + "." + n.join("."));
|
|
1096
1096
|
if (l === "validationWrapper")
|
|
1097
1097
|
return ({
|
|
1098
1098
|
children: d,
|
|
1099
1099
|
hideMessage: e
|
|
1100
|
-
}) => /* @__PURE__ */
|
|
1101
|
-
|
|
1100
|
+
}) => /* @__PURE__ */ ht(
|
|
1101
|
+
Ot,
|
|
1102
1102
|
{
|
|
1103
1103
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1104
1104
|
path: n,
|
|
@@ -1114,7 +1114,7 @@ function dt(t, c, h, S) {
|
|
|
1114
1114
|
if (l === "update")
|
|
1115
1115
|
return (d, e) => {
|
|
1116
1116
|
if (e?.debounce)
|
|
1117
|
-
|
|
1117
|
+
jt(() => {
|
|
1118
1118
|
ot(c, d, n, "");
|
|
1119
1119
|
const r = o.getState().getNestedState(t, n);
|
|
1120
1120
|
e?.afterUpdate && e.afterUpdate(r);
|
|
@@ -1127,8 +1127,8 @@ function dt(t, c, h, S) {
|
|
|
1127
1127
|
w(n);
|
|
1128
1128
|
};
|
|
1129
1129
|
if (l === "formElement")
|
|
1130
|
-
return (d, e) => /* @__PURE__ */
|
|
1131
|
-
|
|
1130
|
+
return (d, e) => /* @__PURE__ */ ht(
|
|
1131
|
+
Rt,
|
|
1132
1132
|
{
|
|
1133
1133
|
setState: c,
|
|
1134
1134
|
stateKey: t,
|
|
@@ -1150,10 +1150,10 @@ function dt(t, c, h, S) {
|
|
|
1150
1150
|
o.getState().getNestedState(t, [])
|
|
1151
1151
|
);
|
|
1152
1152
|
}
|
|
1153
|
-
function
|
|
1154
|
-
return at(
|
|
1153
|
+
function bt(t) {
|
|
1154
|
+
return at(Yt, { proxy: t });
|
|
1155
1155
|
}
|
|
1156
|
-
function
|
|
1156
|
+
function Jt({
|
|
1157
1157
|
proxy: t,
|
|
1158
1158
|
rebuildStateShape: c
|
|
1159
1159
|
}) {
|
|
@@ -1165,10 +1165,10 @@ function qt({
|
|
|
1165
1165
|
(I, b, w, p, a) => t._mapFn(I, b, w, p, a)
|
|
1166
1166
|
) : null;
|
|
1167
1167
|
}
|
|
1168
|
-
function
|
|
1168
|
+
function Yt({
|
|
1169
1169
|
proxy: t
|
|
1170
1170
|
}) {
|
|
1171
|
-
const c =
|
|
1171
|
+
const c = X(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1172
1172
|
return nt(() => {
|
|
1173
1173
|
const S = c.current;
|
|
1174
1174
|
if (!S || !S.parentElement) return;
|
|
@@ -1204,8 +1204,8 @@ function Jt({
|
|
|
1204
1204
|
"data-signal-id": h
|
|
1205
1205
|
});
|
|
1206
1206
|
}
|
|
1207
|
-
function
|
|
1208
|
-
const c =
|
|
1207
|
+
function ue(t) {
|
|
1208
|
+
const c = Pt(
|
|
1209
1209
|
(h) => {
|
|
1210
1210
|
const S = o.getState().stateComponents.get(t._stateKey) || {
|
|
1211
1211
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1219,20 +1219,20 @@ function de(t) {
|
|
|
1219
1219
|
);
|
|
1220
1220
|
return at("text", {}, String(c));
|
|
1221
1221
|
}
|
|
1222
|
-
function
|
|
1222
|
+
function Zt({
|
|
1223
1223
|
stateKey: t,
|
|
1224
1224
|
itemComponentId: c,
|
|
1225
1225
|
itemPath: h,
|
|
1226
1226
|
children: S
|
|
1227
1227
|
}) {
|
|
1228
|
-
const [, I] =
|
|
1228
|
+
const [, I] = Z({}), [b, w] = Dt(), p = X(null);
|
|
1229
1229
|
return nt(() => {
|
|
1230
1230
|
w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, h, {
|
|
1231
1231
|
virtualizer: {
|
|
1232
1232
|
itemHeight: w.height
|
|
1233
1233
|
}
|
|
1234
1234
|
}));
|
|
1235
|
-
}, [w.height, t, h]),
|
|
1235
|
+
}, [w.height, t, h]), lt(() => {
|
|
1236
1236
|
const a = `${t}////${c}`, y = o.getState().stateComponents.get(t) || {
|
|
1237
1237
|
components: /* @__PURE__ */ new Map()
|
|
1238
1238
|
};
|
|
@@ -1243,14 +1243,14 @@ function Yt({
|
|
|
1243
1243
|
const n = o.getState().stateComponents.get(t);
|
|
1244
1244
|
n && n.components.delete(a);
|
|
1245
1245
|
};
|
|
1246
|
-
}, [t, c, h.join(".")]), /* @__PURE__ */
|
|
1246
|
+
}, [t, c, h.join(".")]), /* @__PURE__ */ ht("div", { ref: b, children: S });
|
|
1247
1247
|
}
|
|
1248
1248
|
export {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1249
|
+
bt as $cogsSignal,
|
|
1250
|
+
ue as $cogsSignalStore,
|
|
1251
|
+
ce as addStateOptions,
|
|
1252
|
+
le as createCogsState,
|
|
1253
|
+
de as notifyComponent,
|
|
1254
|
+
qt as useCogsStateFn
|
|
1255
1255
|
};
|
|
1256
1256
|
//# sourceMappingURL=CogsState.jsx.map
|