cogsbox-state 0.5.425 → 0.5.426
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 +245 -245
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.d.ts +4 -3
- package/dist/Functions.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +2 -5
- package/src/Functions.tsx +8 -8
package/dist/CogsState.jsx
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as pt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as it, useRef as q, useEffect as rt, useLayoutEffect as Ct, useMemo as Et, createElement as dt, useSyncExternalStore as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as wt, updateFn as lt, cutFunc as
|
|
3
|
+
import { useState as it, useRef as q, useEffect as rt, useLayoutEffect as Ct, useMemo as Et, createElement as dt, useSyncExternalStore as Ut, startTransition as Ft, useCallback as St } from "react";
|
|
4
|
+
import { transformStateFunc as Dt, isDeepEqual as Y, isFunction as tt, getNestedValue as Z, getDifferences as Tt, debounce as Lt } from "./utility.js";
|
|
5
|
+
import { pushFunc as wt, updateFn as lt, cutFunc as gt, ValidationWrapper as Gt, FormControlComponent as Wt } from "./Functions.jsx";
|
|
6
6
|
import Ht from "superjson";
|
|
7
7
|
import { v4 as At } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as r, formRefStore as bt } from "./store.js";
|
|
10
|
-
import { useCogsConfig as
|
|
10
|
+
import { useCogsConfig as _t } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as zt } from "fast-json-patch";
|
|
12
12
|
import Bt from "react-use-measure";
|
|
13
13
|
function Vt(t, i) {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const S = r.getState().getInitialOptions, f = r.getState().setInitialStateOptions, h = S(t) || {};
|
|
15
|
+
f(t, {
|
|
16
16
|
...h,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
@@ -20,9 +20,9 @@ function Vt(t, i) {
|
|
|
20
20
|
function $t({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: i,
|
|
23
|
-
initialOptionsPart:
|
|
23
|
+
initialOptionsPart: S
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
25
|
+
const f = st(t) || {}, h = S[t] || {}, x = r.getState().setInitialStateOptions, p = { ...h, ...f };
|
|
26
26
|
let y = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const s in i)
|
|
@@ -30,12 +30,12 @@ function $t({
|
|
|
30
30
|
!Y(p[s], i[s]) && (y = !0, p[s] = i[s])) : (y = !0, p[s] = i[s]);
|
|
31
31
|
y && x(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
return { initialState: t, formElements: i, validation:
|
|
33
|
+
function ge(t, { formElements: i, validation: S }) {
|
|
34
|
+
return { initialState: t, formElements: i, validation: S };
|
|
35
35
|
}
|
|
36
36
|
const Se = (t, i) => {
|
|
37
|
-
let
|
|
38
|
-
const [
|
|
37
|
+
let S = t;
|
|
38
|
+
const [f, h] = Dt(S);
|
|
39
39
|
(Object.keys(h).length > 0 || i && Object.keys(i).length > 0) && Object.keys(h).forEach((y) => {
|
|
40
40
|
h[y] = h[y] || {}, h[y].formElements = {
|
|
41
41
|
...i?.formElements,
|
|
@@ -44,7 +44,7 @@ const Se = (t, i) => {
|
|
|
44
44
|
...h[y].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, st(y) || r.getState().setInitialStateOptions(y, h[y]);
|
|
47
|
-
}), r.getState().setInitialStates(
|
|
47
|
+
}), r.getState().setInitialStates(f), r.getState().setCreatedState(f);
|
|
48
48
|
const x = (y, s) => {
|
|
49
49
|
const [m] = it(s?.componentId ?? At());
|
|
50
50
|
$t({
|
|
@@ -52,8 +52,8 @@ const Se = (t, i) => {
|
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: h
|
|
54
54
|
});
|
|
55
|
-
const n = r.getState().cogsStateStore[y] ||
|
|
56
|
-
|
|
55
|
+
const n = r.getState().cogsStateStore[y] || f[y], u = s?.modifyState ? s.modifyState(n) : n, [L, R] = Qt(
|
|
56
|
+
u,
|
|
57
57
|
{
|
|
58
58
|
stateKey: y,
|
|
59
59
|
syncUpdate: s?.syncUpdate,
|
|
@@ -68,7 +68,7 @@ const Se = (t, i) => {
|
|
|
68
68
|
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return R;
|
|
72
72
|
};
|
|
73
73
|
function p(y, s) {
|
|
74
74
|
$t({ stateKey: y, options: s, initialOptionsPart: h }), s.localStorage && Zt(y, s), ut(y);
|
|
@@ -78,23 +78,23 @@ const Se = (t, i) => {
|
|
|
78
78
|
setUpdaterState: mt,
|
|
79
79
|
setState: ot,
|
|
80
80
|
getInitialOptions: st,
|
|
81
|
-
getKeyState:
|
|
81
|
+
getKeyState: Rt,
|
|
82
82
|
getValidationErrors: qt,
|
|
83
83
|
setStateLog: Jt,
|
|
84
84
|
updateInitialStateGlobal: kt,
|
|
85
|
-
addValidationError:
|
|
85
|
+
addValidationError: Mt,
|
|
86
86
|
removeValidationError: Q,
|
|
87
87
|
setServerSyncActions: Yt
|
|
88
|
-
} = r.getState(), Nt = (t, i,
|
|
89
|
-
|
|
88
|
+
} = r.getState(), Nt = (t, i, S, f, h) => {
|
|
89
|
+
S?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
i,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
S.localStorage?.key,
|
|
93
|
+
f
|
|
94
94
|
);
|
|
95
|
-
const x = tt(
|
|
96
|
-
if (x &&
|
|
97
|
-
const p = `${
|
|
95
|
+
const x = tt(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
|
|
96
|
+
if (x && f) {
|
|
97
|
+
const p = `${f}-${i}-${x}`;
|
|
98
98
|
let y;
|
|
99
99
|
try {
|
|
100
100
|
y = yt(p)?.lastSyncedWithServer;
|
|
@@ -119,60 +119,60 @@ const Se = (t, i) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
121
|
}, Zt = (t, i) => {
|
|
122
|
-
const
|
|
123
|
-
if (h &&
|
|
122
|
+
const S = r.getState().cogsStateStore[t], { sessionId: f } = _t(), h = tt(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
|
|
123
|
+
if (h && f) {
|
|
124
124
|
const x = yt(
|
|
125
|
-
`${
|
|
125
|
+
`${f}-${t}-${h}`
|
|
126
126
|
);
|
|
127
127
|
if (x && x.lastUpdated > (x.lastSyncedWithServer || 0))
|
|
128
128
|
return ot(t, x.state), ut(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ot = (t, i, S, f, h, x) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: i,
|
|
134
134
|
updaterState: ht(
|
|
135
135
|
t,
|
|
136
|
-
|
|
136
|
+
f,
|
|
137
137
|
h,
|
|
138
138
|
x
|
|
139
139
|
),
|
|
140
|
-
state:
|
|
140
|
+
state: S
|
|
141
141
|
};
|
|
142
142
|
kt(t, p.initialState), mt(t, p.updaterState), ot(t, p.state);
|
|
143
143
|
}, ut = (t) => {
|
|
144
144
|
const i = r.getState().stateComponents.get(t);
|
|
145
145
|
if (!i) return;
|
|
146
|
-
const
|
|
147
|
-
i.components.forEach((
|
|
148
|
-
(
|
|
146
|
+
const S = /* @__PURE__ */ new Set();
|
|
147
|
+
i.components.forEach((f) => {
|
|
148
|
+
(f ? Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"] : null)?.includes("none") || S.add(() => f.forceUpdate());
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
|
-
|
|
150
|
+
S.forEach((f) => f());
|
|
151
151
|
});
|
|
152
152
|
}, me = (t, i) => {
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
const
|
|
153
|
+
const S = r.getState().stateComponents.get(t);
|
|
154
|
+
if (S) {
|
|
155
|
+
const f = `${t}////${i}`, h = S.components.get(f);
|
|
156
156
|
if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
158
|
h && h.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
}, Xt = (t, i,
|
|
160
|
+
}, Xt = (t, i, S, f) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue: Z(i,
|
|
165
|
-
newValue: Z(
|
|
164
|
+
oldValue: Z(i, f),
|
|
165
|
+
newValue: Z(S, f)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue: Z(
|
|
171
|
+
newValue: Z(S, f)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue: Z(i,
|
|
175
|
+
oldValue: Z(i, f),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -182,8 +182,8 @@ const Se = (t, i) => {
|
|
|
182
182
|
};
|
|
183
183
|
function Qt(t, {
|
|
184
184
|
stateKey: i,
|
|
185
|
-
serverSync:
|
|
186
|
-
localStorage:
|
|
185
|
+
serverSync: S,
|
|
186
|
+
localStorage: f,
|
|
187
187
|
formElements: h,
|
|
188
188
|
reactiveDeps: x,
|
|
189
189
|
reactiveType: p,
|
|
@@ -191,16 +191,16 @@ function Qt(t, {
|
|
|
191
191
|
initialState: s,
|
|
192
192
|
syncUpdate: m,
|
|
193
193
|
dependencies: n,
|
|
194
|
-
serverState:
|
|
194
|
+
serverState: u
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [L,
|
|
196
|
+
const [L, R] = it({}), { sessionId: D } = _t();
|
|
197
197
|
let H = !i;
|
|
198
|
-
const [
|
|
198
|
+
const [g] = it(i ?? At()), c = r.getState().stateLog[g], ft = q(/* @__PURE__ */ new Set()), et = q(y ?? At()), O = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
202
|
-
if (m && m.stateKey ===
|
|
203
|
-
ot(
|
|
201
|
+
O.current = st(g) ?? null, rt(() => {
|
|
202
|
+
if (m && m.stateKey === g && m.path?.[0]) {
|
|
203
|
+
ot(g, (o) => ({
|
|
204
204
|
...o,
|
|
205
205
|
[m.path[0]]: m.newValue
|
|
206
206
|
}));
|
|
@@ -212,121 +212,121 @@ function Qt(t, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [m]), rt(() => {
|
|
214
214
|
if (s) {
|
|
215
|
-
Vt(
|
|
215
|
+
Vt(g, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
218
|
+
const e = O.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, d = r.getState().initialStateGlobal[g];
|
|
219
219
|
if (!(d && !Y(d, s) || !d) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let v = null;
|
|
222
222
|
const T = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
|
-
T && D && (v = yt(`${D}-${
|
|
223
|
+
T && D && (v = yt(`${D}-${g}-${T}`));
|
|
224
224
|
let E = s, k = !1;
|
|
225
|
-
const C = a ? Date.now() : 0, $ = v?.lastUpdated || 0,
|
|
226
|
-
a && C > $ ? (E = e.serverState.data, k = !0) : v && $ >
|
|
227
|
-
|
|
225
|
+
const C = a ? Date.now() : 0, $ = v?.lastUpdated || 0, M = v?.lastSyncedWithServer || 0;
|
|
226
|
+
a && C > $ ? (E = e.serverState.data, k = !0) : v && $ > M && (E = v.state, e?.localStorage?.onChange && e?.localStorage?.onChange(E)), r.getState().initializeShadowState(g, s), Ot(
|
|
227
|
+
g,
|
|
228
228
|
s,
|
|
229
229
|
E,
|
|
230
230
|
ct,
|
|
231
231
|
et.current,
|
|
232
232
|
D
|
|
233
|
-
), k && T && D && Nt(E,
|
|
233
|
+
), k && T && D && Nt(E, g, e, D, Date.now()), ut(g), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
u?.status,
|
|
238
|
+
u?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), Ct(() => {
|
|
241
|
-
H && Vt(
|
|
242
|
-
serverSync:
|
|
241
|
+
H && Vt(g, {
|
|
242
|
+
serverSync: S,
|
|
243
243
|
formElements: h,
|
|
244
244
|
initialState: s,
|
|
245
|
-
localStorage:
|
|
246
|
-
middleware:
|
|
245
|
+
localStorage: f,
|
|
246
|
+
middleware: O.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${
|
|
248
|
+
const e = `${g}////${et.current}`, o = r.getState().stateComponents.get(g) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return o.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => R({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: x || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), r.getState().stateComponents.set(
|
|
258
|
-
o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(
|
|
257
|
+
}), r.getState().stateComponents.set(g, o), R({}), () => {
|
|
258
|
+
o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(g));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const ct = (e, o, a, d) => {
|
|
262
262
|
if (Array.isArray(o)) {
|
|
263
|
-
const v = `${
|
|
264
|
-
|
|
263
|
+
const v = `${g}-${o.join(".")}`;
|
|
264
|
+
ft.current.add(v);
|
|
265
265
|
}
|
|
266
266
|
const w = r.getState();
|
|
267
|
-
ot(
|
|
268
|
-
const T = tt(e) ? e(v) : e, E = `${
|
|
267
|
+
ot(g, (v) => {
|
|
268
|
+
const T = tt(e) ? e(v) : e, E = `${g}-${o.join(".")}`;
|
|
269
269
|
if (E) {
|
|
270
270
|
let _ = !1, I = w.signalDomElements.get(E);
|
|
271
271
|
if ((!I || I.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const
|
|
272
|
+
const j = o.slice(0, -1), N = Z(T, j);
|
|
273
273
|
if (Array.isArray(N)) {
|
|
274
274
|
_ = !0;
|
|
275
|
-
const A = `${
|
|
275
|
+
const A = `${g}-${j.join(".")}`;
|
|
276
276
|
I = w.signalDomElements.get(A);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if (I) {
|
|
280
|
-
const
|
|
281
|
-
I.forEach(({ parentId: N, position: A, effect:
|
|
282
|
-
const
|
|
280
|
+
const j = _ ? Z(T, o.slice(0, -1)) : Z(T, o);
|
|
281
|
+
I.forEach(({ parentId: N, position: A, effect: U }) => {
|
|
282
|
+
const F = document.querySelector(
|
|
283
283
|
`[data-parent-id="${N}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const B = Array.from(
|
|
285
|
+
if (F) {
|
|
286
|
+
const B = Array.from(F.childNodes);
|
|
287
287
|
if (B[A]) {
|
|
288
|
-
const G =
|
|
288
|
+
const G = U ? new Function("state", `return (${U})(state)`)(j) : j;
|
|
289
289
|
B[A].textContent = String(G);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (d ||
|
|
296
|
-
(d ||
|
|
295
|
+
console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (d || O.current?.validation?.key) && o && Q(
|
|
296
|
+
(d || O.current?.validation?.key) + "." + o.join(".")
|
|
297
297
|
);
|
|
298
298
|
const k = o.slice(0, o.length - 1);
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([I,
|
|
299
|
+
a.updateType === "cut" && O.current?.validation?.key && Q(
|
|
300
|
+
O.current?.validation?.key + "." + k.join(".")
|
|
301
|
+
), a.updateType === "insert" && O.current?.validation?.key && qt(
|
|
302
|
+
O.current?.validation?.key + "." + k.join(".")
|
|
303
|
+
).filter(([I, j]) => {
|
|
304
304
|
let N = I?.split(".").length;
|
|
305
305
|
if (I == k.join(".") && N == k.length - 1) {
|
|
306
306
|
let A = I + "." + k;
|
|
307
|
-
Q(I),
|
|
307
|
+
Q(I), Mt(A, j);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const C = w.stateComponents.get(
|
|
310
|
+
const C = w.stateComponents.get(g);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
-
const _ = Tt(v, T), I = new Set(_),
|
|
312
|
+
const _ = Tt(v, T), I = new Set(_), j = a.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
N,
|
|
315
315
|
A
|
|
316
316
|
] of C.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", A), !
|
|
320
|
-
if (
|
|
317
|
+
let U = !1;
|
|
318
|
+
const F = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", A), !F.includes("none")) {
|
|
320
|
+
if (F.includes("all")) {
|
|
321
321
|
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
324
|
+
if (F.includes("component") && ((A.paths.has(j) || A.paths.has("")) && (U = !0), !U))
|
|
325
325
|
for (const B of I) {
|
|
326
326
|
let G = B;
|
|
327
327
|
for (; ; ) {
|
|
328
328
|
if (A.paths.has(G)) {
|
|
329
|
-
|
|
329
|
+
U = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
332
|
const b = G.lastIndexOf(".");
|
|
@@ -338,7 +338,7 @@ function Qt(t, {
|
|
|
338
338
|
if (!isNaN(
|
|
339
339
|
Number(G.substring(b + 1))
|
|
340
340
|
) && A.paths.has(V)) {
|
|
341
|
-
|
|
341
|
+
U = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
344
|
G = V;
|
|
@@ -347,66 +347,66 @@ function Qt(t, {
|
|
|
347
347
|
if (G === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (U) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
352
|
+
if (!U && F.includes("deps") && A.depsFunction) {
|
|
353
353
|
const B = A.depsFunction(T);
|
|
354
354
|
let G = !1;
|
|
355
|
-
typeof B == "boolean" ? B && (G = !0) : Y(A.deps, B) || (A.deps = B, G = !0), G && (
|
|
355
|
+
typeof B == "boolean" ? B && (G = !0) : Y(A.deps, B) || (A.deps = B, G = !0), G && (U = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
U && A.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
const $ = Date.now();
|
|
362
362
|
o = o.map((_, I) => {
|
|
363
|
-
const
|
|
363
|
+
const j = o.slice(0, -1), N = Z(T, j);
|
|
364
364
|
return I === o.length - 1 && ["insert", "cut"].includes(a.updateType) ? (N.length - 1).toString() : _;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: M, newValue: z } = Xt(
|
|
367
367
|
a.updateType,
|
|
368
368
|
v,
|
|
369
369
|
T,
|
|
370
370
|
o
|
|
371
371
|
), K = {
|
|
372
372
|
timeStamp: $,
|
|
373
|
-
stateKey:
|
|
373
|
+
stateKey: g,
|
|
374
374
|
path: o,
|
|
375
375
|
updateType: a.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: M,
|
|
378
378
|
newValue: z
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
w.updateShadowAtPath(
|
|
382
|
+
w.updateShadowAtPath(g, o, T);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const _ = o.slice(0, -1);
|
|
386
|
-
w.insertShadowArrayElement(
|
|
386
|
+
w.insertShadowArrayElement(g, _, z);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const I = o.slice(0, -1),
|
|
390
|
-
w.removeShadowArrayElement(
|
|
389
|
+
const I = o.slice(0, -1), j = parseInt(o[o.length - 1]);
|
|
390
|
+
w.removeShadowArrayElement(g, I, j);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (Jt(
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Jt(g, (_) => {
|
|
394
|
+
const j = [..._ ?? [], K].reduce((N, A) => {
|
|
395
|
+
const U = `${A.stateKey}:${JSON.stringify(A.path)}`, F = N.get(U);
|
|
396
|
+
return F ? (F.timeStamp = Math.max(F.timeStamp, A.timeStamp), F.newValue = A.newValue, F.oldValue = F.oldValue ?? A.oldValue, F.updateType = A.updateType) : N.set(U, { ...A }), N;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
398
|
+
return Array.from(j.values());
|
|
399
399
|
}), Nt(
|
|
400
400
|
T,
|
|
401
|
-
|
|
402
|
-
|
|
401
|
+
g,
|
|
402
|
+
O.current,
|
|
403
403
|
D
|
|
404
|
-
),
|
|
404
|
+
), O.current?.middleware && O.current.middleware({
|
|
405
405
|
updateLog: c,
|
|
406
406
|
update: K
|
|
407
|
-
}),
|
|
408
|
-
const _ = w.serverState[
|
|
409
|
-
Yt(
|
|
407
|
+
}), O.current?.serverSync) {
|
|
408
|
+
const _ = w.serverState[g], I = O.current?.serverSync;
|
|
409
|
+
Yt(g, {
|
|
410
410
|
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: T }),
|
|
411
411
|
rollBackState: _,
|
|
412
412
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
@@ -416,30 +416,30 @@ function Qt(t, {
|
|
|
416
416
|
return T;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
r.getState().updaterState[
|
|
420
|
-
|
|
419
|
+
r.getState().updaterState[g] || (mt(
|
|
420
|
+
g,
|
|
421
421
|
ht(
|
|
422
|
-
|
|
422
|
+
g,
|
|
423
423
|
ct,
|
|
424
424
|
et.current,
|
|
425
425
|
D
|
|
426
426
|
)
|
|
427
|
-
), r.getState().cogsStateStore[
|
|
427
|
+
), r.getState().cogsStateStore[g] || ot(g, t), r.getState().initialStateGlobal[g] || kt(g, t));
|
|
428
428
|
const l = Et(() => ht(
|
|
429
|
-
|
|
429
|
+
g,
|
|
430
430
|
ct,
|
|
431
431
|
et.current,
|
|
432
432
|
D
|
|
433
|
-
), [
|
|
434
|
-
return [
|
|
433
|
+
), [g, D]);
|
|
434
|
+
return [Rt(g), l];
|
|
435
435
|
}
|
|
436
|
-
function ht(t, i,
|
|
436
|
+
function ht(t, i, S, f) {
|
|
437
437
|
const h = /* @__PURE__ */ new Map();
|
|
438
438
|
let x = 0;
|
|
439
439
|
const p = (m) => {
|
|
440
440
|
const n = m.join(".");
|
|
441
|
-
for (const [
|
|
442
|
-
(
|
|
441
|
+
for (const [u] of h)
|
|
442
|
+
(u === n || u.startsWith(n + ".")) && h.delete(u);
|
|
443
443
|
x++;
|
|
444
444
|
}, y = {
|
|
445
445
|
removeValidation: (m) => {
|
|
@@ -448,28 +448,28 @@ function ht(t, i, f, u) {
|
|
|
448
448
|
revertToInitialState: (m) => {
|
|
449
449
|
const n = r.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && Q(n?.key), m?.validationKey && Q(m.validationKey);
|
|
451
|
-
const
|
|
451
|
+
const u = r.getState().initialStateGlobal[t];
|
|
452
452
|
r.getState().clearSelectedIndexesForState(t), h.clear(), x++;
|
|
453
|
-
const L = s(
|
|
454
|
-
H && localStorage.removeItem(H), mt(t, L), ot(t,
|
|
455
|
-
const
|
|
456
|
-
return
|
|
453
|
+
const L = s(u, []), R = st(t), D = tt(R?.localStorage?.key) ? R?.localStorage?.key(u) : R?.localStorage?.key, H = `${f}-${t}-${D}`;
|
|
454
|
+
H && localStorage.removeItem(H), mt(t, L), ot(t, u);
|
|
455
|
+
const g = r.getState().stateComponents.get(t);
|
|
456
|
+
return g && g.components.forEach((c) => {
|
|
457
457
|
c.forceUpdate();
|
|
458
|
-
}),
|
|
458
|
+
}), u;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (m) => {
|
|
461
461
|
h.clear(), x++;
|
|
462
462
|
const n = ht(
|
|
463
463
|
t,
|
|
464
464
|
i,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
),
|
|
468
|
-
return localStorage.getItem(D) && localStorage.removeItem(D),
|
|
465
|
+
S,
|
|
466
|
+
f
|
|
467
|
+
), u = r.getState().initialStateGlobal[t], L = st(t), R = tt(L?.localStorage?.key) ? L?.localStorage?.key(u) : L?.localStorage?.key, D = `${f}-${t}-${R}`;
|
|
468
|
+
return localStorage.getItem(D) && localStorage.removeItem(D), Ft(() => {
|
|
469
469
|
kt(t, m), r.getState().initializeShadowState(t, m), mt(t, n), ot(t, m);
|
|
470
470
|
const H = r.getState().stateComponents.get(t);
|
|
471
|
-
H && H.components.forEach((
|
|
472
|
-
|
|
471
|
+
H && H.components.forEach((g) => {
|
|
472
|
+
g.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
475
|
fetchId: (H) => n.get()[H]
|
|
@@ -480,27 +480,27 @@ function ht(t, i, f, u) {
|
|
|
480
480
|
_isLoading: r.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const m = r.getState().serverState[t];
|
|
483
|
-
return !!(m && Y(m,
|
|
483
|
+
return !!(m && Y(m, Rt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function s(m, n = [],
|
|
486
|
+
function s(m, n = [], u) {
|
|
487
487
|
const L = n.map(String).join(".");
|
|
488
488
|
h.get(L);
|
|
489
|
-
const
|
|
489
|
+
const R = function() {
|
|
490
490
|
return r().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(y).forEach((
|
|
493
|
-
|
|
492
|
+
Object.keys(y).forEach((g) => {
|
|
493
|
+
R[g] = y[g];
|
|
494
494
|
});
|
|
495
495
|
const D = {
|
|
496
|
-
apply(
|
|
496
|
+
apply(g, c, ft) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), r().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
|
-
get(
|
|
502
|
-
|
|
503
|
-
const
|
|
501
|
+
get(g, c) {
|
|
502
|
+
u?.validIndices && !Array.isArray(m) && (u = { ...u, validIndices: void 0 });
|
|
503
|
+
const ft = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,8 +523,8 @@ function ht(t, i, f, u) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (c !== "then" && !c.startsWith("$") && c !== "stateMapNoRender" && !
|
|
527
|
-
const l = `${t}////${
|
|
526
|
+
if (c !== "then" && !c.startsWith("$") && c !== "stateMapNoRender" && !ft.has(c)) {
|
|
527
|
+
const l = `${t}////${S}`, e = r.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const o = e.components.get(l);
|
|
530
530
|
if (o && !o.paths.has("")) {
|
|
@@ -581,7 +581,7 @@ function ht(t, i, f, u) {
|
|
|
581
581
|
};
|
|
582
582
|
if (c === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const l = r.getState().initialStateGlobal[t], e = st(t), o = tt(e?.localStorage?.key) ? e?.localStorage?.key(l) : e?.localStorage?.key, a = `${
|
|
584
|
+
const l = r.getState().initialStateGlobal[t], e = st(t), o = tt(e?.localStorage?.key) ? e?.localStorage?.key(l) : e?.localStorage?.key, a = `${f}-${t}-${o}`;
|
|
585
585
|
a && localStorage.removeItem(a);
|
|
586
586
|
};
|
|
587
587
|
if (c === "showValidationErrors")
|
|
@@ -592,9 +592,9 @@ function ht(t, i, f, u) {
|
|
|
592
592
|
return r.getState().getValidationErrors(l.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
594
|
if (Array.isArray(m)) {
|
|
595
|
-
const l = () =>
|
|
595
|
+
const l = () => u?.validIndices ? m.map((o, a) => ({
|
|
596
596
|
item: o,
|
|
597
|
-
originalIndex:
|
|
597
|
+
originalIndex: u.validIndices[a]
|
|
598
598
|
})) : r.getState().getNestedState(t, n).map((o, a) => ({
|
|
599
599
|
item: o,
|
|
600
600
|
originalIndex: a
|
|
@@ -606,7 +606,7 @@ function ht(t, i, f, u) {
|
|
|
606
606
|
return s(
|
|
607
607
|
m[e],
|
|
608
608
|
[...n, e.toString()],
|
|
609
|
-
|
|
609
|
+
u
|
|
610
610
|
);
|
|
611
611
|
};
|
|
612
612
|
if (c === "clearSelected")
|
|
@@ -625,14 +625,14 @@ function ht(t, i, f, u) {
|
|
|
625
625
|
} = e, v = q(null), [T, E] = it({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [k, C] = it(0), $ = q(!0),
|
|
628
|
+
}), [k, C] = it(0), $ = q(!0), M = q(!1), z = q(0), K = q(T);
|
|
629
629
|
rt(() => r.getState().subscribeToShadowState(t, () => {
|
|
630
630
|
C((V) => V + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const _ = r().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
n
|
|
635
|
-
), I = _.length, { totalHeight:
|
|
635
|
+
), I = _.length, { totalHeight: j, positions: N } = Et(() => {
|
|
636
636
|
const b = r.getState().getShadowMetadata(t, n) || [];
|
|
637
637
|
let V = 0;
|
|
638
638
|
const P = [];
|
|
@@ -654,10 +654,10 @@ function ht(t, i, f, u) {
|
|
|
654
654
|
(J, at) => b + at
|
|
655
655
|
), W = P.map((J) => _[J]);
|
|
656
656
|
return s(W, n, {
|
|
657
|
-
...
|
|
657
|
+
...u,
|
|
658
658
|
validIndices: P
|
|
659
659
|
});
|
|
660
|
-
}, [T.startIndex, T.endIndex, _, I]),
|
|
660
|
+
}, [T.startIndex, T.endIndex, _, I]), U = St(() => {
|
|
661
661
|
const b = r.getState().getShadowMetadata(t, n) || [], V = I - 1;
|
|
662
662
|
if (V >= 0) {
|
|
663
663
|
const P = b[V];
|
|
@@ -676,7 +676,7 @@ function ht(t, i, f, u) {
|
|
|
676
676
|
rt(() => {
|
|
677
677
|
if (!d || I === 0) return;
|
|
678
678
|
const b = I > z.current, V = z.current === 0 && I > 0;
|
|
679
|
-
if ((b || V) && $.current && !
|
|
679
|
+
if ((b || V) && $.current && !M.current) {
|
|
680
680
|
const P = Math.ceil(
|
|
681
681
|
(v.current?.clientHeight || 0) / o
|
|
682
682
|
), W = {
|
|
@@ -698,7 +698,7 @@ function ht(t, i, f, u) {
|
|
|
698
698
|
if (!b) return;
|
|
699
699
|
const V = () => {
|
|
700
700
|
const { scrollTop: P, scrollHeight: W, clientHeight: J } = b, at = W - P - J;
|
|
701
|
-
$.current = at < 5, at > 100 && (
|
|
701
|
+
$.current = at < 5, at > 100 && (M.current = !0), at < 5 && (M.current = !1);
|
|
702
702
|
let nt = 0;
|
|
703
703
|
for (let X = 0; X < N.length; X++)
|
|
704
704
|
if (N[X] > P - o * a) {
|
|
@@ -706,8 +706,8 @@ function ht(t, i, f, u) {
|
|
|
706
706
|
break;
|
|
707
707
|
}
|
|
708
708
|
let xt = nt;
|
|
709
|
-
const
|
|
710
|
-
for (let X = nt; X < N.length && !(N[X] >
|
|
709
|
+
const jt = P + J;
|
|
710
|
+
for (let X = nt; X < N.length && !(N[X] > jt + o * a); X++)
|
|
711
711
|
xt = X;
|
|
712
712
|
const vt = Math.max(0, nt), It = Math.min(
|
|
713
713
|
I,
|
|
@@ -723,7 +723,7 @@ function ht(t, i, f, u) {
|
|
|
723
723
|
};
|
|
724
724
|
if (b.addEventListener("scroll", V, {
|
|
725
725
|
passive: !0
|
|
726
|
-
}), d && I > 0 && !
|
|
726
|
+
}), d && I > 0 && !M.current) {
|
|
727
727
|
const { scrollTop: P } = b;
|
|
728
728
|
P === 0 && (b.scrollTop = b.scrollHeight, $.current = !0);
|
|
729
729
|
}
|
|
@@ -731,9 +731,9 @@ function ht(t, i, f, u) {
|
|
|
731
731
|
b.removeEventListener("scroll", V);
|
|
732
732
|
};
|
|
733
733
|
}, [N, I, o, a, d]);
|
|
734
|
-
const
|
|
735
|
-
$.current = !0,
|
|
736
|
-
}, [
|
|
734
|
+
const F = St(() => {
|
|
735
|
+
$.current = !0, M.current = !1, !U() && v.current && (v.current.scrollTop = v.current.scrollHeight);
|
|
736
|
+
}, [U]), B = St(
|
|
737
737
|
(b, V = "smooth") => {
|
|
738
738
|
const P = v.current;
|
|
739
739
|
if (!P) return;
|
|
@@ -762,7 +762,7 @@ function ht(t, i, f, u) {
|
|
|
762
762
|
},
|
|
763
763
|
inner: {
|
|
764
764
|
style: {
|
|
765
|
-
height: `${
|
|
765
|
+
height: `${j}px`,
|
|
766
766
|
position: "relative"
|
|
767
767
|
}
|
|
768
768
|
},
|
|
@@ -775,21 +775,21 @@ function ht(t, i, f, u) {
|
|
|
775
775
|
return {
|
|
776
776
|
virtualState: A,
|
|
777
777
|
virtualizerProps: G,
|
|
778
|
-
scrollToBottom:
|
|
778
|
+
scrollToBottom: F,
|
|
779
779
|
scrollToIndex: B
|
|
780
780
|
};
|
|
781
781
|
};
|
|
782
782
|
if (c === "stateMapNoRender")
|
|
783
783
|
return (e) => m.map((a, d) => {
|
|
784
784
|
let w;
|
|
785
|
-
|
|
786
|
-
const v = [...n, w.toString()], T = s(a, v,
|
|
785
|
+
u?.validIndices && u.validIndices[d] !== void 0 ? w = u.validIndices[d] : w = d;
|
|
786
|
+
const v = [...n, w.toString()], T = s(a, v, u);
|
|
787
787
|
return e(
|
|
788
788
|
a,
|
|
789
789
|
T,
|
|
790
790
|
d,
|
|
791
791
|
m,
|
|
792
|
-
s(m, n,
|
|
792
|
+
s(m, n, u)
|
|
793
793
|
);
|
|
794
794
|
});
|
|
795
795
|
if (c === "$stateMap")
|
|
@@ -805,8 +805,8 @@ function ht(t, i, f, u) {
|
|
|
805
805
|
if (c === "stateList")
|
|
806
806
|
return (e, o) => {
|
|
807
807
|
const a = r.getState().getNestedState(t, n);
|
|
808
|
-
return Array.isArray(a) ? (
|
|
809
|
-
const T = a[w], E = [...n, w.toString()], k = s(T, E,
|
|
808
|
+
return Array.isArray(a) ? (u?.validIndices || Array.from({ length: a.length }, (w, v) => v)).map((w, v) => {
|
|
809
|
+
const T = a[w], E = [...n, w.toString()], k = s(T, E, u), C = `${S}-${n.join(".")}-${w}`;
|
|
810
810
|
return dt(ee, {
|
|
811
811
|
key: w,
|
|
812
812
|
stateKey: t,
|
|
@@ -818,7 +818,7 @@ function ht(t, i, f, u) {
|
|
|
818
818
|
k,
|
|
819
819
|
{ localIndex: v, originalIndex: w },
|
|
820
820
|
a,
|
|
821
|
-
s(a, n,
|
|
821
|
+
s(a, n, u)
|
|
822
822
|
)
|
|
823
823
|
});
|
|
824
824
|
}) : (console.warn(
|
|
@@ -835,7 +835,7 @@ function ht(t, i, f, u) {
|
|
|
835
835
|
return s(
|
|
836
836
|
a,
|
|
837
837
|
[...n, "[*]", e],
|
|
838
|
-
|
|
838
|
+
u
|
|
839
839
|
);
|
|
840
840
|
};
|
|
841
841
|
if (c === "index")
|
|
@@ -880,7 +880,7 @@ function ht(t, i, f, u) {
|
|
|
880
880
|
if (c === "cut")
|
|
881
881
|
return (e, o) => {
|
|
882
882
|
if (!o?.waitForSync)
|
|
883
|
-
return p(n),
|
|
883
|
+
return p(n), gt(i, n, t, e), s(
|
|
884
884
|
r.getState().getNestedState(t, n),
|
|
885
885
|
n
|
|
886
886
|
);
|
|
@@ -888,12 +888,12 @@ function ht(t, i, f, u) {
|
|
|
888
888
|
if (c === "cutByValue")
|
|
889
889
|
return (e) => {
|
|
890
890
|
for (let o = 0; o < m.length; o++)
|
|
891
|
-
m[o] === e &&
|
|
891
|
+
m[o] === e && gt(i, n, t, o);
|
|
892
892
|
};
|
|
893
893
|
if (c === "toggleByValue")
|
|
894
894
|
return (e) => {
|
|
895
895
|
const o = m.findIndex((a) => a === e);
|
|
896
|
-
o > -1 ?
|
|
896
|
+
o > -1 ? gt(i, n, t, o) : wt(i, e, n, t);
|
|
897
897
|
};
|
|
898
898
|
if (c === "stateFind")
|
|
899
899
|
return (e) => {
|
|
@@ -902,7 +902,7 @@ function ht(t, i, f, u) {
|
|
|
902
902
|
);
|
|
903
903
|
if (!a) return;
|
|
904
904
|
const d = [...n, a.originalIndex.toString()];
|
|
905
|
-
return s(a.item, d,
|
|
905
|
+
return s(a.item, d, u);
|
|
906
906
|
};
|
|
907
907
|
if (c === "findWith")
|
|
908
908
|
return (e, o) => {
|
|
@@ -911,14 +911,14 @@ function ht(t, i, f, u) {
|
|
|
911
911
|
);
|
|
912
912
|
if (!d) return;
|
|
913
913
|
const w = [...n, d.originalIndex.toString()];
|
|
914
|
-
return s(d.item, w,
|
|
914
|
+
return s(d.item, w, u);
|
|
915
915
|
};
|
|
916
916
|
}
|
|
917
917
|
const et = n[n.length - 1];
|
|
918
918
|
if (!isNaN(Number(et))) {
|
|
919
919
|
const l = n.slice(0, -1), e = r.getState().getNestedState(t, l);
|
|
920
920
|
if (Array.isArray(e) && c === "cut")
|
|
921
|
-
return () =>
|
|
921
|
+
return () => gt(
|
|
922
922
|
i,
|
|
923
923
|
l,
|
|
924
924
|
t,
|
|
@@ -927,9 +927,9 @@ function ht(t, i, f, u) {
|
|
|
927
927
|
}
|
|
928
928
|
if (c === "get")
|
|
929
929
|
return () => {
|
|
930
|
-
if (
|
|
930
|
+
if (u?.validIndices && Array.isArray(m)) {
|
|
931
931
|
const l = r.getState().getNestedState(t, n);
|
|
932
|
-
return
|
|
932
|
+
return u.validIndices.map((e) => l[e]);
|
|
933
933
|
}
|
|
934
934
|
return r.getState().getNestedState(t, n);
|
|
935
935
|
};
|
|
@@ -949,7 +949,7 @@ function ht(t, i, f, u) {
|
|
|
949
949
|
return r.getState().getSyncInfo(l);
|
|
950
950
|
}
|
|
951
951
|
if (c == "getLocalStorage")
|
|
952
|
-
return (l) => yt(
|
|
952
|
+
return (l) => yt(f + "-" + t + "-" + l);
|
|
953
953
|
if (c === "_selected") {
|
|
954
954
|
const l = n.slice(0, -1), e = l.join("."), o = r.getState().getNestedState(t, l);
|
|
955
955
|
return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -980,19 +980,19 @@ function ht(t, i, f, u) {
|
|
|
980
980
|
throw new Error("Validation key not found");
|
|
981
981
|
Q(e.key), console.log("addValidationError", l), l.forEach((o) => {
|
|
982
982
|
const a = [e.key, ...o.path].join(".");
|
|
983
|
-
console.log("fullErrorPath", a),
|
|
983
|
+
console.log("fullErrorPath", a), Mt(a, o.message);
|
|
984
984
|
}), ut(t);
|
|
985
985
|
};
|
|
986
986
|
if (c === "applyJsonPatch")
|
|
987
987
|
return (l) => {
|
|
988
988
|
const e = r.getState().cogsStateStore[t], a = zt(e, l).newDocument;
|
|
989
|
-
|
|
989
|
+
Ot(
|
|
990
990
|
t,
|
|
991
991
|
r.getState().initialStateGlobal[t],
|
|
992
992
|
a,
|
|
993
993
|
i,
|
|
994
|
-
|
|
995
|
-
|
|
994
|
+
S,
|
|
995
|
+
f
|
|
996
996
|
);
|
|
997
997
|
const d = r.getState().stateComponents.get(t);
|
|
998
998
|
if (d) {
|
|
@@ -1014,15 +1014,15 @@ function ht(t, i, f, u) {
|
|
|
1014
1014
|
k = !0;
|
|
1015
1015
|
break;
|
|
1016
1016
|
}
|
|
1017
|
-
let
|
|
1018
|
-
for (;
|
|
1019
|
-
const z = $.substring(0,
|
|
1017
|
+
let M = $.lastIndexOf(".");
|
|
1018
|
+
for (; M !== -1; ) {
|
|
1019
|
+
const z = $.substring(0, M);
|
|
1020
1020
|
if (E.paths.has(z)) {
|
|
1021
1021
|
k = !0;
|
|
1022
1022
|
break;
|
|
1023
1023
|
}
|
|
1024
1024
|
const K = $.substring(
|
|
1025
|
-
|
|
1025
|
+
M + 1
|
|
1026
1026
|
);
|
|
1027
1027
|
if (!isNaN(Number(K))) {
|
|
1028
1028
|
const _ = z.lastIndexOf(".");
|
|
@@ -1037,14 +1037,14 @@ function ht(t, i, f, u) {
|
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
|
-
|
|
1040
|
+
M = z.lastIndexOf(".");
|
|
1041
1041
|
}
|
|
1042
1042
|
if (k) break;
|
|
1043
1043
|
}
|
|
1044
1044
|
if (!k && C.includes("deps") && E.depsFunction) {
|
|
1045
1045
|
const $ = E.depsFunction(a);
|
|
1046
|
-
let
|
|
1047
|
-
typeof $ == "boolean" ? $ && (
|
|
1046
|
+
let M = !1;
|
|
1047
|
+
typeof $ == "boolean" ? $ && (M = !0) : Y(E.deps, $) || (E.deps = $, M = !0), M && (k = !0);
|
|
1048
1048
|
}
|
|
1049
1049
|
k && E.forceUpdate();
|
|
1050
1050
|
}
|
|
@@ -1074,7 +1074,7 @@ function ht(t, i, f, u) {
|
|
|
1074
1074
|
return console.error("Zod schema validation failed", a), !1;
|
|
1075
1075
|
}
|
|
1076
1076
|
};
|
|
1077
|
-
if (c === "_componentId") return
|
|
1077
|
+
if (c === "_componentId") return S;
|
|
1078
1078
|
if (c === "getComponents")
|
|
1079
1079
|
return () => r().stateComponents.get(t);
|
|
1080
1080
|
if (c === "getAllFormRefs")
|
|
@@ -1097,12 +1097,12 @@ function ht(t, i, f, u) {
|
|
|
1097
1097
|
children: l,
|
|
1098
1098
|
hideMessage: e
|
|
1099
1099
|
}) => /* @__PURE__ */ pt(
|
|
1100
|
-
|
|
1100
|
+
Gt,
|
|
1101
1101
|
{
|
|
1102
1102
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1103
1103
|
path: n,
|
|
1104
1104
|
stateKey: t,
|
|
1105
|
-
validIndices:
|
|
1105
|
+
validIndices: u?.validIndices,
|
|
1106
1106
|
children: l
|
|
1107
1107
|
}
|
|
1108
1108
|
);
|
|
@@ -1112,7 +1112,7 @@ function ht(t, i, f, u) {
|
|
|
1112
1112
|
if (c === "update")
|
|
1113
1113
|
return (l, e) => {
|
|
1114
1114
|
if (e?.debounce)
|
|
1115
|
-
|
|
1115
|
+
Lt(() => {
|
|
1116
1116
|
lt(i, l, n, "");
|
|
1117
1117
|
const o = r.getState().getNestedState(t, n);
|
|
1118
1118
|
e?.afterUpdate && e.afterUpdate(o);
|
|
@@ -1135,10 +1135,10 @@ function ht(t, i, f, u) {
|
|
|
1135
1135
|
formOpts: e
|
|
1136
1136
|
}
|
|
1137
1137
|
);
|
|
1138
|
-
const
|
|
1139
|
-
return s(ct,
|
|
1138
|
+
const O = [...n, c], ct = r.getState().getNestedState(t, O);
|
|
1139
|
+
return s(ct, O, u);
|
|
1140
1140
|
}
|
|
1141
|
-
}, H = new Proxy(
|
|
1141
|
+
}, H = new Proxy(R, D);
|
|
1142
1142
|
return h.set(L, {
|
|
1143
1143
|
proxy: H,
|
|
1144
1144
|
stateVersion: x
|
|
@@ -1155,9 +1155,9 @@ function Kt({
|
|
|
1155
1155
|
proxy: t,
|
|
1156
1156
|
rebuildStateShape: i
|
|
1157
1157
|
}) {
|
|
1158
|
-
const
|
|
1159
|
-
return Array.isArray(
|
|
1160
|
-
|
|
1158
|
+
const S = r().getNestedState(t._stateKey, t._path);
|
|
1159
|
+
return Array.isArray(S) ? i(
|
|
1160
|
+
S,
|
|
1161
1161
|
t._path
|
|
1162
1162
|
).stateMapNoRender(
|
|
1163
1163
|
(h, x, p, y, s) => t._mapFn(h, x, p, y, s)
|
|
@@ -1166,11 +1166,11 @@ function Kt({
|
|
|
1166
1166
|
function te({
|
|
1167
1167
|
proxy: t
|
|
1168
1168
|
}) {
|
|
1169
|
-
const i = q(null),
|
|
1169
|
+
const i = q(null), S = `${t._stateKey}-${t._path.join(".")}`;
|
|
1170
1170
|
return rt(() => {
|
|
1171
|
-
const
|
|
1172
|
-
if (!
|
|
1173
|
-
const h =
|
|
1171
|
+
const f = i.current;
|
|
1172
|
+
if (!f || !f.parentElement) return;
|
|
1173
|
+
const h = f.parentElement, p = Array.from(h.childNodes).indexOf(f);
|
|
1174
1174
|
let y = h.getAttribute("data-parent-id");
|
|
1175
1175
|
y || (y = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", y));
|
|
1176
1176
|
const m = {
|
|
@@ -1179,39 +1179,39 @@ function te({
|
|
|
1179
1179
|
position: p,
|
|
1180
1180
|
effect: t._effect
|
|
1181
1181
|
};
|
|
1182
|
-
r.getState().addSignalElement(
|
|
1182
|
+
r.getState().addSignalElement(S, m);
|
|
1183
1183
|
const n = r.getState().getNestedState(t._stateKey, t._path);
|
|
1184
|
-
let
|
|
1184
|
+
let u;
|
|
1185
1185
|
if (t._effect)
|
|
1186
1186
|
try {
|
|
1187
|
-
|
|
1187
|
+
u = new Function(
|
|
1188
1188
|
"state",
|
|
1189
1189
|
`return (${t._effect})(state)`
|
|
1190
1190
|
)(n);
|
|
1191
|
-
} catch (
|
|
1192
|
-
console.error("Error evaluating effect function during mount:",
|
|
1191
|
+
} catch (R) {
|
|
1192
|
+
console.error("Error evaluating effect function during mount:", R), u = n;
|
|
1193
1193
|
}
|
|
1194
1194
|
else
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
const L = document.createTextNode(String(
|
|
1198
|
-
|
|
1195
|
+
u = n;
|
|
1196
|
+
u !== null && typeof u == "object" && (u = JSON.stringify(u));
|
|
1197
|
+
const L = document.createTextNode(String(u));
|
|
1198
|
+
f.replaceWith(L);
|
|
1199
1199
|
}, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
|
|
1200
1200
|
ref: i,
|
|
1201
1201
|
style: { display: "none" },
|
|
1202
|
-
"data-signal-id":
|
|
1202
|
+
"data-signal-id": S
|
|
1203
1203
|
});
|
|
1204
1204
|
}
|
|
1205
1205
|
function he(t) {
|
|
1206
|
-
const i =
|
|
1207
|
-
(
|
|
1208
|
-
const
|
|
1206
|
+
const i = Ut(
|
|
1207
|
+
(S) => {
|
|
1208
|
+
const f = r.getState().stateComponents.get(t._stateKey) || {
|
|
1209
1209
|
components: /* @__PURE__ */ new Map()
|
|
1210
1210
|
};
|
|
1211
|
-
return
|
|
1212
|
-
forceUpdate:
|
|
1211
|
+
return f.components.set(t._stateKey, {
|
|
1212
|
+
forceUpdate: S,
|
|
1213
1213
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1214
|
-
}), () =>
|
|
1214
|
+
}), () => f.components.delete(t._stateKey);
|
|
1215
1215
|
},
|
|
1216
1216
|
() => r.getState().getNestedState(t._stateKey, t._path)
|
|
1217
1217
|
);
|
|
@@ -1220,41 +1220,41 @@ function he(t) {
|
|
|
1220
1220
|
function ee({
|
|
1221
1221
|
stateKey: t,
|
|
1222
1222
|
itemComponentId: i,
|
|
1223
|
-
itemPath:
|
|
1224
|
-
formOpts:
|
|
1223
|
+
itemPath: S,
|
|
1224
|
+
formOpts: f,
|
|
1225
1225
|
children: h
|
|
1226
1226
|
}) {
|
|
1227
|
-
const [, x] = it({}), [p, y] = Bt(), s = q(null), m = q(null)
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
p(n), s.current = n;
|
|
1227
|
+
const [, x] = it({}), [p, y] = Bt(), s = q(null), m = q(null), n = St(
|
|
1228
|
+
(u) => {
|
|
1229
|
+
p(u), s.current = u;
|
|
1231
1230
|
},
|
|
1232
1231
|
[p]
|
|
1233
|
-
)
|
|
1234
|
-
|
|
1232
|
+
);
|
|
1233
|
+
return rt(() => {
|
|
1234
|
+
y.height > 0 && y.height !== m.current && (m.current = y.height, r.getState().setShadowMetadata(t, S, {
|
|
1235
1235
|
virtualizer: {
|
|
1236
1236
|
itemHeight: y.height,
|
|
1237
1237
|
domRef: s.current
|
|
1238
1238
|
// Store the actual DOM element reference
|
|
1239
1239
|
}
|
|
1240
1240
|
}));
|
|
1241
|
-
}, [y.height, t,
|
|
1242
|
-
const
|
|
1241
|
+
}, [y.height, t, S]), Ct(() => {
|
|
1242
|
+
const u = `${t}////${i}`, L = r.getState().stateComponents.get(t) || {
|
|
1243
1243
|
components: /* @__PURE__ */ new Map()
|
|
1244
1244
|
};
|
|
1245
|
-
return
|
|
1245
|
+
return L.components.set(u, {
|
|
1246
1246
|
forceUpdate: () => x({}),
|
|
1247
|
-
paths: /* @__PURE__ */ new Set([
|
|
1248
|
-
}), r.getState().stateComponents.set(t,
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1247
|
+
paths: /* @__PURE__ */ new Set([S.join(".")])
|
|
1248
|
+
}), r.getState().stateComponents.set(t, L), () => {
|
|
1249
|
+
const R = r.getState().stateComponents.get(t);
|
|
1250
|
+
R && R.components.delete(u);
|
|
1251
1251
|
};
|
|
1252
|
-
}, [t, i,
|
|
1252
|
+
}, [t, i, S.join(".")]), /* @__PURE__ */ pt("div", { ref: n, children: h });
|
|
1253
1253
|
}
|
|
1254
1254
|
export {
|
|
1255
1255
|
Pt as $cogsSignal,
|
|
1256
1256
|
he as $cogsSignalStore,
|
|
1257
|
-
|
|
1257
|
+
ge as addStateOptions,
|
|
1258
1258
|
Se as createCogsState,
|
|
1259
1259
|
me as notifyComponent,
|
|
1260
1260
|
Qt as useCogsStateFn
|