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