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