cogsbox-state 0.5.304 → 0.5.306
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 +358 -354
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +28 -13
package/dist/CogsState.jsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as yt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as vt, updateFn as
|
|
6
|
-
import
|
|
3
|
+
import { useState as tt, useRef as B, useEffect as at, useLayoutEffect as dt, useMemo as It, createElement as st, useSyncExternalStore as Mt, startTransition as jt, useCallback as Et } from "react";
|
|
4
|
+
import { transformStateFunc as Ot, isDeepEqual as H, isFunction as Y, getNestedValue as z, getDifferences as pt, debounce as Ft } from "./utility.js";
|
|
5
|
+
import { pushFunc as vt, updateFn as ot, cutFunc as lt, ValidationWrapper as Rt, FormControlComponent as Ut } from "./Functions.jsx";
|
|
6
|
+
import Dt from "superjson";
|
|
7
7
|
import { v4 as wt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Ct } from "./CogsStateClient.jsx";
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
11
|
+
import { applyPatch as Wt } from "fast-json-patch";
|
|
12
|
+
import Gt from "react-use-measure";
|
|
13
13
|
function $t(t, c) {
|
|
14
14
|
const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
|
|
15
15
|
f(t, {
|
|
@@ -17,45 +17,45 @@ function $t(t, c) {
|
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function bt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const f =
|
|
26
|
-
let
|
|
25
|
+
const f = nt(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, p = { ...y, ...f };
|
|
26
|
+
let I = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const a in c)
|
|
29
|
-
|
|
30
|
-
!H(
|
|
31
|
-
|
|
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
|
+
!H(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
|
|
31
|
+
I && b(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function de(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const ue = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [f, y] =
|
|
39
|
-
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((
|
|
40
|
-
y[
|
|
38
|
+
const [f, y] = Ot(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
|
-
...y[
|
|
44
|
+
...y[I].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
46
|
+
}, nt(I) || o.getState().setInitialStateOptions(I, y[I]);
|
|
47
47
|
}), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
|
|
48
|
-
const
|
|
49
|
-
const [v] =
|
|
50
|
-
|
|
51
|
-
stateKey:
|
|
48
|
+
const b = (I, a) => {
|
|
49
|
+
const [v] = tt(a?.componentId ?? wt());
|
|
50
|
+
bt({
|
|
51
|
+
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[
|
|
55
|
+
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [W, R] = Yt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
|
-
stateKey:
|
|
58
|
+
stateKey: I,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
60
|
componentId: v,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
@@ -70,43 +70,43 @@ const de = (t, c) => {
|
|
|
70
70
|
);
|
|
71
71
|
return R;
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function p(I, a) {
|
|
74
|
+
bt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Bt(I, a), St(I);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: b, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: ut,
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
79
|
+
setState: et,
|
|
80
|
+
getInitialOptions: nt,
|
|
81
81
|
getKeyState: Vt,
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
82
|
+
getValidationErrors: Lt,
|
|
83
|
+
setStateLog: Ht,
|
|
84
|
+
updateInitialStateGlobal: At,
|
|
85
|
+
addValidationError: zt,
|
|
86
86
|
removeValidationError: J,
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
87
|
+
setServerSyncActions: qt
|
|
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
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
let
|
|
95
|
+
const b = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
|
+
if (b && f) {
|
|
97
|
+
const p = `${f}-${c}-${b}`;
|
|
98
|
+
let I;
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
I = ft(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer: y ??
|
|
107
|
-
}, v =
|
|
106
|
+
lastSyncedWithServer: y ?? I
|
|
107
|
+
}, v = Dt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
|
-
|
|
109
|
+
p,
|
|
110
110
|
JSON.stringify(v.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
@@ -121,25 +121,25 @@ const de = (t, c) => {
|
|
|
121
121
|
}, Bt = (t, c) => {
|
|
122
122
|
const m = o.getState().cogsStateStore[t], { sessionId: f } = Ct(), y = Y(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (y && f) {
|
|
124
|
-
const
|
|
124
|
+
const b = ft(
|
|
125
125
|
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
|
|
128
|
+
return et(t, b.state), St(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, xt = (t, c, m, f, y,
|
|
132
|
-
const
|
|
131
|
+
}, xt = (t, c, m, f, y, b) => {
|
|
132
|
+
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: gt(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
137
|
y,
|
|
138
|
-
|
|
138
|
+
b
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
At(t, p.initialState), ut(t, p.updaterState), et(t, p.state);
|
|
143
143
|
}, St = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
@@ -149,7 +149,7 @@ const de = (t, c) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((f) => f());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, ge = (t, c) => {
|
|
153
153
|
const m = o.getState().stateComponents.get(t);
|
|
154
154
|
if (m) {
|
|
155
155
|
const f = `${t}////${c}`, y = m.components.get(f);
|
|
@@ -157,7 +157,7 @@ const de = (t, c) => {
|
|
|
157
157
|
return;
|
|
158
158
|
y && y.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Jt = (t, c, m, f) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
@@ -180,27 +180,27 @@ const de = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Yt(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: f,
|
|
187
187
|
formElements: y,
|
|
188
|
-
reactiveDeps:
|
|
189
|
-
reactiveType:
|
|
190
|
-
componentId:
|
|
188
|
+
reactiveDeps: b,
|
|
189
|
+
reactiveType: p,
|
|
190
|
+
componentId: I,
|
|
191
191
|
initialState: a,
|
|
192
192
|
syncUpdate: v,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [h] =
|
|
196
|
+
const [W, R] = tt({}), { sessionId: U } = Ct();
|
|
197
|
+
let G = !c;
|
|
198
|
+
const [h] = tt(c ?? wt()), l = o.getState().stateLog[h], it = B(/* @__PURE__ */ new Set()), Z = B(I ?? wt()), j = B(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
j.current =
|
|
201
|
+
j.current = nt(h) ?? null, at(() => {
|
|
202
202
|
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
-
|
|
203
|
+
et(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
205
|
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
@@ -210,7 +210,7 @@ function Jt(t, {
|
|
|
210
210
|
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [v]),
|
|
213
|
+
}, [v]), at(() => {
|
|
214
214
|
if (a) {
|
|
215
215
|
$t(h, {
|
|
216
216
|
initialState: a
|
|
@@ -220,17 +220,17 @@ function Jt(t, {
|
|
|
220
220
|
return;
|
|
221
221
|
let g = null;
|
|
222
222
|
const A = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
-
A &&
|
|
224
|
-
let
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
223
|
+
A && U && (g = ft(`${U}-${h}-${A}`));
|
|
224
|
+
let w = a, T = !1;
|
|
225
|
+
const _ = s ? Date.now() : 0, C = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
|
|
226
|
+
s && _ > C ? (w = e.serverState.data, T = !0) : g && C > M && (w = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), xt(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
w,
|
|
230
|
+
rt,
|
|
231
231
|
Z.current,
|
|
232
|
-
|
|
233
|
-
), T && A &&
|
|
232
|
+
U
|
|
233
|
+
), T && A && U && kt(w, h, e, U, Date.now()), St(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
@@ -238,7 +238,7 @@ function Jt(t, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), dt(() => {
|
|
241
|
-
|
|
241
|
+
G && $t(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
@@ -252,41 +252,41 @@ function Jt(t, {
|
|
|
252
252
|
forceUpdate: () => R({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
256
|
-
reactiveType:
|
|
255
|
+
depsFunction: b || void 0,
|
|
256
|
+
reactiveType: p ?? ["component", "deps"]
|
|
257
257
|
}), o.getState().stateComponents.set(h, r), R({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const rt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
263
|
const g = `${h}-${r.join(".")}`;
|
|
264
|
-
|
|
264
|
+
it.current.add(g);
|
|
265
265
|
}
|
|
266
266
|
const u = o.getState();
|
|
267
|
-
|
|
268
|
-
const A = Y(e) ? e(g) : e,
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
267
|
+
et(h, (g) => {
|
|
268
|
+
const A = Y(e) ? e(g) : e, w = `${h}-${r.join(".")}`;
|
|
269
|
+
if (w) {
|
|
270
|
+
let V = !1, k = u.signalDomElements.get(w);
|
|
271
|
+
if ((!k || k.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
272
|
const O = r.slice(0, -1), D = z(A, O);
|
|
273
273
|
if (Array.isArray(D)) {
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
274
|
+
V = !0;
|
|
275
|
+
const $ = `${h}-${O.join(".")}`;
|
|
276
|
+
k = u.signalDomElements.get($);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const O =
|
|
281
|
-
|
|
282
|
-
const
|
|
279
|
+
if (k) {
|
|
280
|
+
const O = V ? z(A, r.slice(0, -1)) : z(A, r);
|
|
281
|
+
k.forEach(({ parentId: D, position: $, effect: E }) => {
|
|
282
|
+
const N = document.querySelector(
|
|
283
283
|
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (N) {
|
|
286
|
+
const F = Array.from(N.childNodes);
|
|
287
|
+
if (F[$]) {
|
|
288
|
+
const x = E ? new Function("state", `return (${E})(state)`)(O) : O;
|
|
289
|
+
F[$].textContent = String(x);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
@@ -298,118 +298,118 @@ function Jt(t, {
|
|
|
298
298
|
const T = r.slice(0, r.length - 1);
|
|
299
299
|
s.updateType === "cut" && j.current?.validation?.key && J(
|
|
300
300
|
j.current?.validation?.key + "." + T.join(".")
|
|
301
|
-
), s.updateType === "insert" && j.current?.validation?.key &&
|
|
301
|
+
), s.updateType === "insert" && j.current?.validation?.key && Lt(
|
|
302
302
|
j.current?.validation?.key + "." + T.join(".")
|
|
303
|
-
).filter(([
|
|
304
|
-
let D =
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
J(
|
|
303
|
+
).filter(([k, O]) => {
|
|
304
|
+
let D = k?.split(".").length;
|
|
305
|
+
if (k == T.join(".") && D == T.length - 1) {
|
|
306
|
+
let $ = k + "." + T;
|
|
307
|
+
J(k), zt($, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const _ = u.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
|
|
312
|
+
const V = pt(g, A), k = new Set(V), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
D,
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
315
|
+
$
|
|
316
|
+
] of _.components.entries()) {
|
|
317
|
+
let E = !1;
|
|
318
|
+
const N = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", $), !N.includes("none")) {
|
|
320
|
+
if (N.includes("all")) {
|
|
321
|
+
$.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (N.includes("component") && (($.paths.has(O) || $.paths.has("")) && (E = !0), !E))
|
|
325
|
+
for (const F of k) {
|
|
326
|
+
let x = F;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if ($.paths.has(x)) {
|
|
329
|
+
E = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const L = x.lastIndexOf(".");
|
|
333
|
+
if (L !== -1) {
|
|
334
|
+
const X = x.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
L
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(x.substring(L + 1))
|
|
340
|
+
) && $.paths.has(X)) {
|
|
341
|
+
E = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
x = X;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
x = "";
|
|
347
|
+
if (x === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (E) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!E && N.includes("deps") && $.depsFunction) {
|
|
353
|
+
const F = $.depsFunction(A);
|
|
354
|
+
let x = !1;
|
|
355
|
+
typeof F == "boolean" ? F && (x = !0) : H($.deps, F) || ($.deps = F, x = !0), x && (E = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
E && $.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
361
|
+
const C = Date.now();
|
|
362
|
+
r = r.map((V, k) => {
|
|
363
363
|
const O = r.slice(0, -1), D = z(A, O);
|
|
364
|
-
return
|
|
364
|
+
return k === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : V;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: M, newValue: P } = Jt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
g,
|
|
369
369
|
A,
|
|
370
370
|
r
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), q = {
|
|
372
|
+
timeStamp: C,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: M,
|
|
378
|
+
newValue: P
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
u.updateShadowAtPath(h, r, A);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
u.insertShadowArrayElement(h,
|
|
385
|
+
const V = r.slice(0, -1);
|
|
386
|
+
u.insertShadowArrayElement(h, V, P);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
u.removeShadowArrayElement(h,
|
|
389
|
+
const k = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
+
u.removeShadowArrayElement(h, k, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const O = [...
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Ht(h, (V) => {
|
|
394
|
+
const O = [...V ?? [], q].reduce((D, $) => {
|
|
395
|
+
const E = `${$.stateKey}:${JSON.stringify($.path)}`, N = D.get(E);
|
|
396
|
+
return N ? (N.timeStamp = Math.max(N.timeStamp, $.timeStamp), N.newValue = $.newValue, N.oldValue = N.oldValue ?? $.oldValue, N.updateType = $.updateType) : D.set(E, { ...$ }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(O.values());
|
|
399
|
-
}),
|
|
399
|
+
}), kt(
|
|
400
400
|
A,
|
|
401
401
|
h,
|
|
402
402
|
j.current,
|
|
403
|
-
|
|
403
|
+
U
|
|
404
404
|
), j.current?.middleware && j.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
406
|
+
update: q
|
|
407
407
|
}), j.current?.serverSync) {
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
408
|
+
const V = u.serverState[h], k = j.current?.serverSync;
|
|
409
|
+
qt(h, {
|
|
410
|
+
syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: A }),
|
|
411
|
+
rollBackState: V,
|
|
412
|
+
actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
@@ -420,28 +420,28 @@ function Jt(t, {
|
|
|
420
420
|
h,
|
|
421
421
|
gt(
|
|
422
422
|
h,
|
|
423
|
-
|
|
423
|
+
rt,
|
|
424
424
|
Z.current,
|
|
425
|
-
|
|
425
|
+
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] ||
|
|
427
|
+
), o.getState().cogsStateStore[h] || et(h, t), o.getState().initialStateGlobal[h] || At(h, t));
|
|
428
428
|
const d = It(() => gt(
|
|
429
429
|
h,
|
|
430
|
-
|
|
430
|
+
rt,
|
|
431
431
|
Z.current,
|
|
432
|
-
|
|
433
|
-
), [h,
|
|
432
|
+
U
|
|
433
|
+
), [h, U]);
|
|
434
434
|
return [Vt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function gt(t, c, m, f) {
|
|
437
437
|
const y = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
439
|
-
const
|
|
438
|
+
let b = 0;
|
|
439
|
+
const p = (v) => {
|
|
440
440
|
const n = v.join(".");
|
|
441
441
|
for (const [S] of y)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && y.delete(S);
|
|
443
|
-
|
|
444
|
-
},
|
|
443
|
+
b++;
|
|
444
|
+
}, I = {
|
|
445
445
|
removeValidation: (v) => {
|
|
446
446
|
v?.validationKey && J(v.validationKey);
|
|
447
447
|
},
|
|
@@ -449,30 +449,30 @@ function gt(t, c, m, f) {
|
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), b++;
|
|
453
|
+
const W = a(S, []), R = nt(t), U = Y(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, G = `${f}-${t}-${U}`;
|
|
454
|
+
G && localStorage.removeItem(G), ut(t, W), et(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (v) => {
|
|
461
|
-
y.clear(),
|
|
461
|
+
y.clear(), b++;
|
|
462
462
|
const n = gt(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
f
|
|
467
|
-
), S = o.getState().initialStateGlobal[t],
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], W = nt(t), R = Y(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${f}-${t}-${R}`;
|
|
468
|
+
return localStorage.getItem(U) && localStorage.removeItem(U), jt(() => {
|
|
469
|
+
At(t, v), o.getState().initializeShadowState(t, v), ut(t, n), et(t, v);
|
|
470
|
+
const G = o.getState().stateComponents.get(t);
|
|
471
|
+
G && G.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (G) => n.get()[G]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
@@ -484,23 +484,23 @@ function gt(t, c, m, f) {
|
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(v, n = [], S) {
|
|
487
|
-
const
|
|
488
|
-
y.get(
|
|
487
|
+
const W = n.map(String).join(".");
|
|
488
|
+
y.get(W);
|
|
489
489
|
const R = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(
|
|
493
|
-
R[h] =
|
|
492
|
+
Object.keys(I).forEach((h) => {
|
|
493
|
+
R[h] = I[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(h, l,
|
|
495
|
+
const U = {
|
|
496
|
+
apply(h, l, it) {
|
|
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
501
|
get(h, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const it = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function gt(t, c, m, f) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !it.has(l)) {
|
|
527
527
|
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const r = e.components.get(d);
|
|
@@ -581,7 +581,7 @@ function gt(t, c, m, f) {
|
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = nt(t), r = Y(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -621,104 +621,108 @@ function gt(t, c, m, f) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e, u = B(null), [g, A] =
|
|
624
|
+
} = e, u = B(null), [g, A] = tt({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
|
-
}),
|
|
627
|
+
}), [, w] = tt({}), T = B(i), _ = B(0), C = B(!0);
|
|
628
|
+
at(() => o.getState().subscribeToShadowState(t, () => w({})), [t]);
|
|
629
|
+
const M = o().getNestedState(
|
|
628
630
|
t,
|
|
629
631
|
n
|
|
630
|
-
),
|
|
631
|
-
const
|
|
632
|
-
let
|
|
633
|
-
const
|
|
634
|
-
for (let
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
632
|
+
), P = M.length, { totalHeight: q, positions: V } = It(() => {
|
|
633
|
+
const E = o.getState().getShadowMetadata(t, n) || [];
|
|
634
|
+
let N = 0;
|
|
635
|
+
const F = [];
|
|
636
|
+
for (let x = 0; x < P; x++) {
|
|
637
|
+
F[x] = N;
|
|
638
|
+
const L = E[x]?.virtualizer?.itemHeight;
|
|
639
|
+
N += L || r;
|
|
638
640
|
}
|
|
639
|
-
return { totalHeight:
|
|
640
|
-
}, [
|
|
641
|
-
const
|
|
642
|
-
{ length:
|
|
643
|
-
(
|
|
644
|
-
),
|
|
645
|
-
return a(
|
|
641
|
+
return { totalHeight: N, positions: F };
|
|
642
|
+
}, [P, t, n.join("."), r]), k = It(() => {
|
|
643
|
+
const E = Math.max(0, g.startIndex), N = Math.min(P, g.endIndex), F = Array.from(
|
|
644
|
+
{ length: N - E },
|
|
645
|
+
(L, X) => E + X
|
|
646
|
+
), x = F.map((L) => M[L]);
|
|
647
|
+
return a(x, n, {
|
|
646
648
|
...S,
|
|
647
|
-
validIndices:
|
|
649
|
+
validIndices: F
|
|
648
650
|
});
|
|
649
|
-
}, [g.startIndex, g.endIndex,
|
|
651
|
+
}, [g.startIndex, g.endIndex, M, P]);
|
|
650
652
|
dt(() => {
|
|
651
|
-
const
|
|
652
|
-
if (!
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
const { scrollTop:
|
|
657
|
-
|
|
658
|
-
let mt = 0,
|
|
659
|
-
for (; mt <=
|
|
660
|
-
const
|
|
661
|
-
|
|
653
|
+
const E = u.current;
|
|
654
|
+
if (!E) return;
|
|
655
|
+
const N = T.current, F = P > _.current;
|
|
656
|
+
_.current = P;
|
|
657
|
+
const x = () => {
|
|
658
|
+
const { scrollTop: L, clientHeight: X, scrollHeight: Pt } = E;
|
|
659
|
+
T.current = Pt - L - X < 10;
|
|
660
|
+
let mt = 0, ct = P - 1;
|
|
661
|
+
for (; mt <= ct; ) {
|
|
662
|
+
const K = Math.floor((mt + ct) / 2);
|
|
663
|
+
V[K] < L ? mt = K + 1 : ct = K - 1;
|
|
662
664
|
}
|
|
663
|
-
const ht = Math.max(0,
|
|
664
|
-
let
|
|
665
|
-
const
|
|
666
|
-
for (;
|
|
667
|
-
|
|
668
|
-
|
|
665
|
+
const ht = Math.max(0, ct - s);
|
|
666
|
+
let Q = ht;
|
|
667
|
+
const _t = L + X;
|
|
668
|
+
for (; Q < P && V[Q] < _t; )
|
|
669
|
+
Q++;
|
|
670
|
+
Q = Math.min(P, Q + s), A((K) => K.startIndex !== ht || K.endIndex !== Q ? { startIndex: ht, endIndex: Q } : K);
|
|
669
671
|
};
|
|
670
|
-
return
|
|
672
|
+
return E.addEventListener("scroll", x, {
|
|
671
673
|
passive: !0
|
|
672
|
-
}), i
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
674
|
+
}), i && (C.current && P > 0 ? requestAnimationFrame(() => {
|
|
675
|
+
requestAnimationFrame(() => {
|
|
676
|
+
u.current && (u.current.scrollTo({
|
|
677
|
+
top: u.current.scrollHeight,
|
|
678
|
+
behavior: "auto"
|
|
679
|
+
}), C.current = !1);
|
|
676
680
|
});
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
top:
|
|
681
|
+
}) : !C.current && N && F && requestAnimationFrame(() => {
|
|
682
|
+
E.scrollTo({
|
|
683
|
+
top: E.scrollHeight,
|
|
680
684
|
behavior: "smooth"
|
|
681
685
|
});
|
|
682
|
-
})
|
|
683
|
-
}, [
|
|
684
|
-
const
|
|
685
|
-
(
|
|
686
|
+
})), x(), () => E.removeEventListener("scroll", x);
|
|
687
|
+
}, [P, V, s, i]);
|
|
688
|
+
const O = Et(
|
|
689
|
+
(E = "smooth") => {
|
|
686
690
|
u.current && u.current.scrollTo({
|
|
687
691
|
top: u.current.scrollHeight,
|
|
688
|
-
behavior:
|
|
692
|
+
behavior: E
|
|
689
693
|
});
|
|
690
694
|
},
|
|
691
695
|
[]
|
|
692
|
-
),
|
|
693
|
-
(
|
|
694
|
-
u.current &&
|
|
695
|
-
top:
|
|
696
|
-
behavior:
|
|
696
|
+
), D = Et(
|
|
697
|
+
(E, N = "smooth") => {
|
|
698
|
+
u.current && V[E] !== void 0 && u.current.scrollTo({
|
|
699
|
+
top: V[E],
|
|
700
|
+
behavior: N
|
|
697
701
|
});
|
|
698
702
|
},
|
|
699
|
-
[
|
|
700
|
-
),
|
|
703
|
+
[V]
|
|
704
|
+
), $ = {
|
|
701
705
|
outer: {
|
|
702
706
|
ref: u,
|
|
703
707
|
style: { overflowY: "auto", height: "100%" }
|
|
704
708
|
},
|
|
705
709
|
inner: {
|
|
706
710
|
style: {
|
|
707
|
-
height: `${
|
|
711
|
+
height: `${q}px`,
|
|
708
712
|
position: "relative"
|
|
709
713
|
}
|
|
710
714
|
},
|
|
711
715
|
list: {
|
|
712
716
|
style: {
|
|
713
|
-
transform: `translateY(${
|
|
717
|
+
transform: `translateY(${V[g.startIndex] || 0}px)`
|
|
714
718
|
}
|
|
715
719
|
}
|
|
716
720
|
};
|
|
717
721
|
return {
|
|
718
|
-
virtualState:
|
|
719
|
-
virtualizerProps:
|
|
720
|
-
scrollToBottom:
|
|
721
|
-
scrollToIndex:
|
|
722
|
+
virtualState: k,
|
|
723
|
+
virtualizerProps: $,
|
|
724
|
+
scrollToBottom: O,
|
|
725
|
+
scrollToIndex: D
|
|
722
726
|
};
|
|
723
727
|
};
|
|
724
728
|
if (l === "stateSort")
|
|
@@ -749,22 +753,22 @@ function gt(t, c, m, f) {
|
|
|
749
753
|
return (e) => {
|
|
750
754
|
const r = o.getState().getNestedState(t, n);
|
|
751
755
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
|
|
752
|
-
const g = r[i], A = [...n, i.toString()],
|
|
753
|
-
return e(g,
|
|
756
|
+
const g = r[i], A = [...n, i.toString()], w = a(g, A, S);
|
|
757
|
+
return e(g, w, {
|
|
754
758
|
register: () => {
|
|
755
|
-
const [,
|
|
759
|
+
const [, _] = tt({}), C = `${m}-${n.join(".")}-${i}`;
|
|
756
760
|
dt(() => {
|
|
757
|
-
const
|
|
761
|
+
const M = `${t}////${C}`, P = o.getState().stateComponents.get(t) || {
|
|
758
762
|
components: /* @__PURE__ */ new Map()
|
|
759
763
|
};
|
|
760
|
-
return
|
|
761
|
-
forceUpdate: () =>
|
|
764
|
+
return P.components.set(M, {
|
|
765
|
+
forceUpdate: () => _({}),
|
|
762
766
|
paths: /* @__PURE__ */ new Set([A.join(".")])
|
|
763
|
-
}), o.getState().stateComponents.set(t,
|
|
764
|
-
const
|
|
765
|
-
|
|
767
|
+
}), o.getState().stateComponents.set(t, P), () => {
|
|
768
|
+
const q = o.getState().stateComponents.get(t);
|
|
769
|
+
q && q.components.delete(M);
|
|
766
770
|
};
|
|
767
|
-
}, [t,
|
|
771
|
+
}, [t, C]);
|
|
768
772
|
},
|
|
769
773
|
index: u,
|
|
770
774
|
originalIndex: i
|
|
@@ -788,7 +792,7 @@ function gt(t, c, m, f) {
|
|
|
788
792
|
);
|
|
789
793
|
});
|
|
790
794
|
if (l === "$stateMap")
|
|
791
|
-
return (e) =>
|
|
795
|
+
return (e) => st(Zt, {
|
|
792
796
|
proxy: {
|
|
793
797
|
_stateKey: t,
|
|
794
798
|
_path: n,
|
|
@@ -801,15 +805,15 @@ function gt(t, c, m, f) {
|
|
|
801
805
|
return (e) => {
|
|
802
806
|
const r = o.getState().getNestedState(t, n);
|
|
803
807
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
|
|
804
|
-
const g = r[i], A = [...n, i.toString()],
|
|
805
|
-
return
|
|
808
|
+
const g = r[i], A = [...n, i.toString()], w = a(g, A, S), T = `${m}-${n.join(".")}-${i}`;
|
|
809
|
+
return st(Qt, {
|
|
806
810
|
key: i,
|
|
807
811
|
stateKey: t,
|
|
808
812
|
itemComponentId: T,
|
|
809
813
|
itemPath: A,
|
|
810
814
|
children: e(
|
|
811
815
|
g,
|
|
812
|
-
|
|
816
|
+
w,
|
|
813
817
|
u,
|
|
814
818
|
r,
|
|
815
819
|
a(r, n, S)
|
|
@@ -822,7 +826,7 @@ function gt(t, c, m, f) {
|
|
|
822
826
|
if (l === "stateFlattenOn")
|
|
823
827
|
return (e) => {
|
|
824
828
|
const r = v;
|
|
825
|
-
y.clear(),
|
|
829
|
+
y.clear(), b++;
|
|
826
830
|
const s = r.flatMap(
|
|
827
831
|
(i) => i[e] ?? []
|
|
828
832
|
);
|
|
@@ -845,7 +849,7 @@ function gt(t, c, m, f) {
|
|
|
845
849
|
return a(s, i);
|
|
846
850
|
};
|
|
847
851
|
if (l === "insert")
|
|
848
|
-
return (e) => (
|
|
852
|
+
return (e) => (p(n), vt(c, e, n, t), a(
|
|
849
853
|
o.getState().getNestedState(t, n),
|
|
850
854
|
n
|
|
851
855
|
));
|
|
@@ -853,28 +857,28 @@ function gt(t, c, m, f) {
|
|
|
853
857
|
return (e, r, s) => {
|
|
854
858
|
const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
|
|
855
859
|
let g = null;
|
|
856
|
-
if (!i.some((
|
|
860
|
+
if (!i.some((w) => {
|
|
857
861
|
if (r) {
|
|
858
|
-
const
|
|
859
|
-
(
|
|
862
|
+
const _ = r.every(
|
|
863
|
+
(C) => H(w[C], u[C])
|
|
860
864
|
);
|
|
861
|
-
return
|
|
865
|
+
return _ && (g = w), _;
|
|
862
866
|
}
|
|
863
|
-
const T = H(
|
|
864
|
-
return T && (g =
|
|
867
|
+
const T = H(w, u);
|
|
868
|
+
return T && (g = w), T;
|
|
865
869
|
}))
|
|
866
|
-
|
|
870
|
+
p(n), vt(c, u, n, t);
|
|
867
871
|
else if (s && g) {
|
|
868
|
-
const
|
|
869
|
-
(
|
|
872
|
+
const w = s(g), T = i.map(
|
|
873
|
+
(_) => H(_, g) ? w : _
|
|
870
874
|
);
|
|
871
|
-
|
|
875
|
+
p(n), ot(c, T, n);
|
|
872
876
|
}
|
|
873
877
|
};
|
|
874
878
|
if (l === "cut")
|
|
875
879
|
return (e, r) => {
|
|
876
880
|
if (!r?.waitForSync)
|
|
877
|
-
return
|
|
881
|
+
return p(n), lt(c, n, t, e), a(
|
|
878
882
|
o.getState().getNestedState(t, n),
|
|
879
883
|
n
|
|
880
884
|
);
|
|
@@ -882,12 +886,12 @@ function gt(t, c, m, f) {
|
|
|
882
886
|
if (l === "cutByValue")
|
|
883
887
|
return (e) => {
|
|
884
888
|
for (let r = 0; r < v.length; r++)
|
|
885
|
-
v[r] === e &&
|
|
889
|
+
v[r] === e && lt(c, n, t, r);
|
|
886
890
|
};
|
|
887
891
|
if (l === "toggleByValue")
|
|
888
892
|
return (e) => {
|
|
889
893
|
const r = v.findIndex((s) => s === e);
|
|
890
|
-
r > -1 ?
|
|
894
|
+
r > -1 ? lt(c, n, t, r) : vt(c, e, n, t);
|
|
891
895
|
};
|
|
892
896
|
if (l === "stateFind")
|
|
893
897
|
return (e) => {
|
|
@@ -912,7 +916,7 @@ function gt(t, c, m, f) {
|
|
|
912
916
|
if (!isNaN(Number(Z))) {
|
|
913
917
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
914
918
|
if (Array.isArray(e) && l === "cut")
|
|
915
|
-
return () =>
|
|
919
|
+
return () => lt(
|
|
916
920
|
c,
|
|
917
921
|
d,
|
|
918
922
|
t,
|
|
@@ -928,13 +932,13 @@ function gt(t, c, m, f) {
|
|
|
928
932
|
return o.getState().getNestedState(t, n);
|
|
929
933
|
};
|
|
930
934
|
if (l === "$derive")
|
|
931
|
-
return (d) =>
|
|
935
|
+
return (d) => Nt({
|
|
932
936
|
_stateKey: t,
|
|
933
937
|
_path: n,
|
|
934
938
|
_effect: d.toString()
|
|
935
939
|
});
|
|
936
940
|
if (l === "$get")
|
|
937
|
-
return () =>
|
|
941
|
+
return () => Nt({
|
|
938
942
|
_stateKey: t,
|
|
939
943
|
_path: n
|
|
940
944
|
});
|
|
@@ -953,7 +957,7 @@ function gt(t, c, m, f) {
|
|
|
953
957
|
const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
|
|
954
958
|
d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
|
|
955
959
|
const i = o.getState().getNestedState(t, [...e]);
|
|
956
|
-
|
|
960
|
+
ot(c, i, e), p(e);
|
|
957
961
|
};
|
|
958
962
|
if (l === "toggleSelected")
|
|
959
963
|
return () => {
|
|
@@ -964,12 +968,12 @@ function gt(t, c, m, f) {
|
|
|
964
968
|
s === e ? void 0 : e
|
|
965
969
|
);
|
|
966
970
|
const i = o.getState().getNestedState(t, [...d]);
|
|
967
|
-
|
|
971
|
+
ot(c, i, d), p(d);
|
|
968
972
|
};
|
|
969
973
|
if (n.length == 0) {
|
|
970
974
|
if (l === "applyJsonPatch")
|
|
971
975
|
return (d) => {
|
|
972
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
976
|
+
const e = o.getState().cogsStateStore[t], s = Wt(e, d).newDocument;
|
|
973
977
|
xt(
|
|
974
978
|
t,
|
|
975
979
|
o.getState().initialStateGlobal[t],
|
|
@@ -983,54 +987,54 @@ function gt(t, c, m, f) {
|
|
|
983
987
|
const u = pt(e, s), g = new Set(u);
|
|
984
988
|
for (const [
|
|
985
989
|
A,
|
|
986
|
-
|
|
990
|
+
w
|
|
987
991
|
] of i.components.entries()) {
|
|
988
992
|
let T = !1;
|
|
989
|
-
const
|
|
990
|
-
if (!
|
|
991
|
-
if (
|
|
992
|
-
|
|
993
|
+
const _ = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
994
|
+
if (!_.includes("none")) {
|
|
995
|
+
if (_.includes("all")) {
|
|
996
|
+
w.forceUpdate();
|
|
993
997
|
continue;
|
|
994
998
|
}
|
|
995
|
-
if (
|
|
996
|
-
for (const
|
|
997
|
-
if (
|
|
999
|
+
if (_.includes("component") && (w.paths.has("") && (T = !0), !T))
|
|
1000
|
+
for (const C of g) {
|
|
1001
|
+
if (w.paths.has(C)) {
|
|
998
1002
|
T = !0;
|
|
999
1003
|
break;
|
|
1000
1004
|
}
|
|
1001
|
-
let
|
|
1002
|
-
for (;
|
|
1003
|
-
const
|
|
1004
|
-
if (
|
|
1005
|
+
let M = C.lastIndexOf(".");
|
|
1006
|
+
for (; M !== -1; ) {
|
|
1007
|
+
const P = C.substring(0, M);
|
|
1008
|
+
if (w.paths.has(P)) {
|
|
1005
1009
|
T = !0;
|
|
1006
1010
|
break;
|
|
1007
1011
|
}
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1012
|
+
const q = C.substring(
|
|
1013
|
+
M + 1
|
|
1010
1014
|
);
|
|
1011
|
-
if (!isNaN(Number(
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1014
|
-
const
|
|
1015
|
+
if (!isNaN(Number(q))) {
|
|
1016
|
+
const V = P.lastIndexOf(".");
|
|
1017
|
+
if (V !== -1) {
|
|
1018
|
+
const k = P.substring(
|
|
1015
1019
|
0,
|
|
1016
|
-
|
|
1020
|
+
V
|
|
1017
1021
|
);
|
|
1018
|
-
if (
|
|
1022
|
+
if (w.paths.has(k)) {
|
|
1019
1023
|
T = !0;
|
|
1020
1024
|
break;
|
|
1021
1025
|
}
|
|
1022
1026
|
}
|
|
1023
1027
|
}
|
|
1024
|
-
|
|
1028
|
+
M = P.lastIndexOf(".");
|
|
1025
1029
|
}
|
|
1026
1030
|
if (T) break;
|
|
1027
1031
|
}
|
|
1028
|
-
if (!T &&
|
|
1029
|
-
const
|
|
1030
|
-
let
|
|
1031
|
-
typeof
|
|
1032
|
+
if (!T && _.includes("deps") && w.depsFunction) {
|
|
1033
|
+
const C = w.depsFunction(s);
|
|
1034
|
+
let M = !1;
|
|
1035
|
+
typeof C == "boolean" ? C && (M = !0) : H(w.deps, C) || (w.deps = C, M = !0), M && (T = !0);
|
|
1032
1036
|
}
|
|
1033
|
-
T &&
|
|
1037
|
+
T && w.forceUpdate();
|
|
1034
1038
|
}
|
|
1035
1039
|
}
|
|
1036
1040
|
}
|
|
@@ -1051,8 +1055,8 @@ function gt(t, c, m, f) {
|
|
|
1051
1055
|
});
|
|
1052
1056
|
const i = d.zodSchema.safeParse(r);
|
|
1053
1057
|
return i.success ? !0 : (i.error.errors.forEach((g) => {
|
|
1054
|
-
const A = g.path,
|
|
1055
|
-
e(T,
|
|
1058
|
+
const A = g.path, w = g.message, T = [d.key, ...A].join(".");
|
|
1059
|
+
e(T, w);
|
|
1056
1060
|
}), St(t), !1);
|
|
1057
1061
|
} catch (s) {
|
|
1058
1062
|
return console.error("Zod schema validation failed", s), !1;
|
|
@@ -1070,9 +1074,9 @@ function gt(t, c, m, f) {
|
|
|
1070
1074
|
if (l === "_isLoading")
|
|
1071
1075
|
return o.getState().isLoadingGlobal[t];
|
|
1072
1076
|
if (l === "revertToInitialState")
|
|
1073
|
-
return
|
|
1074
|
-
if (l === "updateInitialState") return
|
|
1075
|
-
if (l === "removeValidation") return
|
|
1077
|
+
return I.revertToInitialState;
|
|
1078
|
+
if (l === "updateInitialState") return I.updateInitialState;
|
|
1079
|
+
if (l === "removeValidation") return I.removeValidation;
|
|
1076
1080
|
}
|
|
1077
1081
|
if (l === "getFormRef")
|
|
1078
1082
|
return () => Tt.getState().getFormRef(t + "." + n.join("."));
|
|
@@ -1093,25 +1097,25 @@ function gt(t, c, m, f) {
|
|
|
1093
1097
|
);
|
|
1094
1098
|
if (l === "_stateKey") return t;
|
|
1095
1099
|
if (l === "_path") return n;
|
|
1096
|
-
if (l === "_isServerSynced") return
|
|
1100
|
+
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1097
1101
|
if (l === "update")
|
|
1098
1102
|
return (d, e) => {
|
|
1099
1103
|
if (e?.debounce)
|
|
1100
|
-
|
|
1101
|
-
|
|
1104
|
+
Ft(() => {
|
|
1105
|
+
ot(c, d, n, "");
|
|
1102
1106
|
const r = o.getState().getNestedState(t, n);
|
|
1103
1107
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1104
1108
|
}, e.debounce);
|
|
1105
1109
|
else {
|
|
1106
|
-
|
|
1110
|
+
ot(c, d, n, "");
|
|
1107
1111
|
const r = o.getState().getNestedState(t, n);
|
|
1108
1112
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1109
1113
|
}
|
|
1110
|
-
|
|
1114
|
+
p(n);
|
|
1111
1115
|
};
|
|
1112
1116
|
if (l === "formElement")
|
|
1113
1117
|
return (d, e) => /* @__PURE__ */ yt(
|
|
1114
|
-
|
|
1118
|
+
Ut,
|
|
1115
1119
|
{
|
|
1116
1120
|
setState: c,
|
|
1117
1121
|
stateKey: t,
|
|
@@ -1120,23 +1124,23 @@ function gt(t, c, m, f) {
|
|
|
1120
1124
|
formOpts: e
|
|
1121
1125
|
}
|
|
1122
1126
|
);
|
|
1123
|
-
const j = [...n, l],
|
|
1124
|
-
return a(
|
|
1127
|
+
const j = [...n, l], rt = o.getState().getNestedState(t, j);
|
|
1128
|
+
return a(rt, j, S);
|
|
1125
1129
|
}
|
|
1126
|
-
},
|
|
1127
|
-
return y.set(
|
|
1128
|
-
proxy:
|
|
1129
|
-
stateVersion:
|
|
1130
|
-
}),
|
|
1130
|
+
}, G = new Proxy(R, U);
|
|
1131
|
+
return y.set(W, {
|
|
1132
|
+
proxy: G,
|
|
1133
|
+
stateVersion: b
|
|
1134
|
+
}), G;
|
|
1131
1135
|
}
|
|
1132
1136
|
return a(
|
|
1133
1137
|
o.getState().getNestedState(t, [])
|
|
1134
1138
|
);
|
|
1135
1139
|
}
|
|
1136
|
-
function
|
|
1137
|
-
return
|
|
1140
|
+
function Nt(t) {
|
|
1141
|
+
return st(Xt, { proxy: t });
|
|
1138
1142
|
}
|
|
1139
|
-
function
|
|
1143
|
+
function Zt({
|
|
1140
1144
|
proxy: t,
|
|
1141
1145
|
rebuildStateShape: c
|
|
1142
1146
|
}) {
|
|
@@ -1145,23 +1149,23 @@ function Yt({
|
|
|
1145
1149
|
m,
|
|
1146
1150
|
t._path
|
|
1147
1151
|
).stateMapNoRender(
|
|
1148
|
-
(y,
|
|
1152
|
+
(y, b, p, I, a) => t._mapFn(y, b, p, I, a)
|
|
1149
1153
|
) : null;
|
|
1150
1154
|
}
|
|
1151
|
-
function
|
|
1155
|
+
function Xt({
|
|
1152
1156
|
proxy: t
|
|
1153
1157
|
}) {
|
|
1154
1158
|
const c = B(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1155
|
-
return
|
|
1159
|
+
return at(() => {
|
|
1156
1160
|
const f = c.current;
|
|
1157
1161
|
if (!f || !f.parentElement) return;
|
|
1158
|
-
const y = f.parentElement,
|
|
1159
|
-
let
|
|
1160
|
-
|
|
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));
|
|
1161
1165
|
const v = {
|
|
1162
1166
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1163
|
-
parentId:
|
|
1164
|
-
position:
|
|
1167
|
+
parentId: I,
|
|
1168
|
+
position: p,
|
|
1165
1169
|
effect: t._effect
|
|
1166
1170
|
};
|
|
1167
1171
|
o.getState().addSignalElement(m, v);
|
|
@@ -1179,16 +1183,16 @@ function Zt({
|
|
|
1179
1183
|
else
|
|
1180
1184
|
S = n;
|
|
1181
1185
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1182
|
-
const
|
|
1183
|
-
f.replaceWith(
|
|
1184
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1186
|
+
const W = document.createTextNode(String(S));
|
|
1187
|
+
f.replaceWith(W);
|
|
1188
|
+
}, [t._stateKey, t._path.join("."), t._effect]), st("span", {
|
|
1185
1189
|
ref: c,
|
|
1186
1190
|
style: { display: "none" },
|
|
1187
1191
|
"data-signal-id": m
|
|
1188
1192
|
});
|
|
1189
1193
|
}
|
|
1190
|
-
function
|
|
1191
|
-
const c =
|
|
1194
|
+
function fe(t) {
|
|
1195
|
+
const c = Mt(
|
|
1192
1196
|
(m) => {
|
|
1193
1197
|
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1194
1198
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1200,22 +1204,22 @@ function ge(t) {
|
|
|
1200
1204
|
},
|
|
1201
1205
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1202
1206
|
);
|
|
1203
|
-
return
|
|
1207
|
+
return st("text", {}, String(c));
|
|
1204
1208
|
}
|
|
1205
|
-
function
|
|
1209
|
+
function Qt({
|
|
1206
1210
|
stateKey: t,
|
|
1207
1211
|
itemComponentId: c,
|
|
1208
1212
|
itemPath: m,
|
|
1209
1213
|
children: f
|
|
1210
1214
|
}) {
|
|
1211
|
-
const [, y] =
|
|
1212
|
-
return
|
|
1213
|
-
|
|
1215
|
+
const [, y] = tt({}), [b, p] = Gt(), I = B(null);
|
|
1216
|
+
return at(() => {
|
|
1217
|
+
p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1214
1218
|
virtualizer: {
|
|
1215
|
-
itemHeight:
|
|
1219
|
+
itemHeight: p.height
|
|
1216
1220
|
}
|
|
1217
1221
|
}));
|
|
1218
|
-
}, [
|
|
1222
|
+
}, [p.height, t, m]), dt(() => {
|
|
1219
1223
|
const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
|
|
1220
1224
|
components: /* @__PURE__ */ new Map()
|
|
1221
1225
|
};
|
|
@@ -1226,14 +1230,14 @@ function Xt({
|
|
|
1226
1230
|
const n = o.getState().stateComponents.get(t);
|
|
1227
1231
|
n && n.components.delete(a);
|
|
1228
1232
|
};
|
|
1229
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref:
|
|
1233
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ yt("div", { ref: b, children: f });
|
|
1230
1234
|
}
|
|
1231
1235
|
export {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1236
|
+
Nt as $cogsSignal,
|
|
1237
|
+
fe as $cogsSignalStore,
|
|
1238
|
+
de as addStateOptions,
|
|
1239
|
+
ue as createCogsState,
|
|
1240
|
+
ge as notifyComponent,
|
|
1241
|
+
Yt as useCogsStateFn
|
|
1238
1242
|
};
|
|
1239
1243
|
//# sourceMappingURL=CogsState.jsx.map
|