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