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