cogsbox-state 0.5.400 → 0.5.402
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 +292 -283
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +19 -7
package/dist/CogsState.jsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as _t } from "react/jsx-runtime";
|
|
3
|
+
import { useState as K, useRef as q, useEffect as ot, useLayoutEffect as lt, useMemo as wt, createElement as dt, useSyncExternalStore as Bt, startTransition as Ft, useCallback as bt } from "react";
|
|
4
|
+
import { transformStateFunc as Wt, isDeepEqual as J, isFunction as tt, getNestedValue as Z, getDifferences as At, debounce as zt } from "./utility.js";
|
|
5
|
+
import { pushFunc as Ot, updateFn as ct, cutFunc as ht, ValidationWrapper as qt, FormControlComponent as Jt } from "./Functions.jsx";
|
|
6
|
+
import Yt from "superjson";
|
|
7
|
+
import { v4 as Nt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
9
|
+
import { getGlobalStore as o, formRefStore as Mt } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Lt } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Zt } from "fast-json-patch";
|
|
12
|
+
import Xt from "react-use-measure";
|
|
13
|
+
function xt(t, c) {
|
|
14
14
|
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
|
|
15
15
|
g(t, {
|
|
16
16
|
...I,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Pt({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
@@ -35,7 +35,7 @@ function Ie(t, { formElements: c, validation: m }) {
|
|
|
35
35
|
}
|
|
36
36
|
const ve = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [g, I] =
|
|
38
|
+
const [g, I] = Wt(m);
|
|
39
39
|
(Object.keys(I).length > 0 || c && Object.keys(c).length > 0) && Object.keys(I).forEach((v) => {
|
|
40
40
|
I[v] = I[v] || {}, I[v].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
@@ -46,13 +46,13 @@ const ve = (t, c) => {
|
|
|
46
46
|
}, rt(v) || o.getState().setInitialStateOptions(v, I[v]);
|
|
47
47
|
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
48
|
const N = (v, s) => {
|
|
49
|
-
const [T] = K(s?.componentId ??
|
|
50
|
-
|
|
49
|
+
const [T] = K(s?.componentId ?? Nt());
|
|
50
|
+
Pt({
|
|
51
51
|
stateKey: v,
|
|
52
52
|
options: s,
|
|
53
53
|
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] =
|
|
55
|
+
const r = o.getState().cogsStateStore[v] || g[v], S = s?.modifyState ? s.modifyState(r) : r, [W, j] = re(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
@@ -71,21 +71,21 @@ const ve = (t, c) => {
|
|
|
71
71
|
return j;
|
|
72
72
|
};
|
|
73
73
|
function p(v, s) {
|
|
74
|
-
|
|
74
|
+
Pt({ stateKey: v, options: s, initialOptionsPart: I }), s.localStorage && ee(v, s), ut(v);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: Tt,
|
|
79
79
|
setState: nt,
|
|
80
80
|
getInitialOptions: rt,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
81
|
+
getKeyState: Rt,
|
|
82
|
+
getValidationErrors: Qt,
|
|
83
|
+
setStateLog: Kt,
|
|
84
|
+
updateInitialStateGlobal: Ct,
|
|
85
|
+
addValidationError: Dt,
|
|
86
|
+
removeValidationError: Q,
|
|
87
|
+
setServerSyncActions: te
|
|
88
|
+
} = o.getState(), Vt = (t, c, m, g, I) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
@@ -104,7 +104,7 @@ const ve = (t, c) => {
|
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: I ?? v
|
|
107
|
-
}, T =
|
|
107
|
+
}, T = Yt.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(T.json)
|
|
@@ -118,17 +118,17 @@ const ve = (t, c) => {
|
|
|
118
118
|
} catch (c) {
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: g } =
|
|
121
|
+
}, ee = (t, c) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = Lt(), I = tt(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (I && g) {
|
|
124
124
|
const N = vt(
|
|
125
125
|
`${g}-${t}-${I}`
|
|
126
126
|
);
|
|
127
127
|
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
|
-
return nt(t, N.state),
|
|
128
|
+
return nt(t, N.state), ut(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ht = (t, c, m, g, I, N) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
134
|
updaterState: It(
|
|
@@ -139,8 +139,8 @@ const ve = (t, c) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
Ct(t, p.initialState), Tt(t, p.updaterState), nt(t, p.state);
|
|
143
|
+
}, ut = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -157,7 +157,7 @@ const ve = (t, c) => {
|
|
|
157
157
|
return;
|
|
158
158
|
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, ne = (t, c, m, g) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
@@ -180,7 +180,7 @@ const ve = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function re(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
@@ -193,12 +193,12 @@ function ne(t, {
|
|
|
193
193
|
dependencies: r,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [W, j] = K({}), { sessionId: U } =
|
|
196
|
+
const [W, j] = K({}), { sessionId: U } = Lt();
|
|
197
197
|
let z = !c;
|
|
198
|
-
const [h] = K(c ??
|
|
198
|
+
const [h] = K(c ?? Nt()), l = o.getState().stateLog[h], gt = q(/* @__PURE__ */ new Set()), et = q(v ?? Nt()), R = q(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
R.current = rt(h) ?? null, ot(() => {
|
|
202
202
|
if (T && T.stateKey === h && T.path?.[0]) {
|
|
203
203
|
nt(h, (n) => ({
|
|
204
204
|
...n,
|
|
@@ -212,38 +212,38 @@ function ne(t, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [T]), ot(() => {
|
|
214
214
|
if (s) {
|
|
215
|
-
|
|
215
|
+
xt(h, {
|
|
216
216
|
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
218
|
+
const e = R.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
219
|
if (!(i && !J(i, s) || !i) && !a)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const E = tt(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
223
|
E && U && (u = vt(`${U}-${h}-${E}`));
|
|
224
|
-
let y = s,
|
|
225
|
-
const C = a ? Date.now() : 0,
|
|
226
|
-
a && C >
|
|
224
|
+
let y = s, _ = !1;
|
|
225
|
+
const C = a ? Date.now() : 0, w = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
|
|
226
|
+
a && C > w ? (y = e.serverState.data, _ = !0) : u && w > b && (y = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(y)), o.getState().initializeShadowState(h, s), Ht(
|
|
227
227
|
h,
|
|
228
228
|
s,
|
|
229
229
|
y,
|
|
230
230
|
at,
|
|
231
231
|
et.current,
|
|
232
232
|
U
|
|
233
|
-
),
|
|
233
|
+
), _ && E && U && Vt(y, h, e, U, Date.now()), ut(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || j({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
s,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...r || []
|
|
240
|
-
]),
|
|
241
|
-
z &&
|
|
240
|
+
]), lt(() => {
|
|
241
|
+
z && xt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: I,
|
|
244
244
|
initialState: s,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: R.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const e = `${h}////${et.current}`, n = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
@@ -261,154 +261,154 @@ function ne(t, {
|
|
|
261
261
|
const at = (e, n, a, i) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
263
263
|
const u = `${h}-${n.join(".")}`;
|
|
264
|
-
|
|
264
|
+
gt.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = o.getState();
|
|
267
267
|
nt(h, (u) => {
|
|
268
268
|
const E = tt(e) ? e(u) : e, y = `${h}-${n.join(".")}`;
|
|
269
269
|
if (y) {
|
|
270
|
-
let
|
|
270
|
+
let P = !1, $ = f.signalDomElements.get(y);
|
|
271
271
|
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const
|
|
272
|
+
const D = n.slice(0, -1), V = Z(E, D);
|
|
273
273
|
if (Array.isArray(V)) {
|
|
274
|
-
|
|
275
|
-
const O = `${h}-${
|
|
274
|
+
P = !0;
|
|
275
|
+
const O = `${h}-${D.join(".")}`;
|
|
276
276
|
$ = f.signalDomElements.get(O);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if ($) {
|
|
280
|
-
const
|
|
281
|
-
$.forEach(({ parentId: V, position: O, effect:
|
|
282
|
-
const
|
|
280
|
+
const D = P ? Z(E, n.slice(0, -1)) : Z(E, n);
|
|
281
|
+
$.forEach(({ parentId: V, position: O, effect: A }) => {
|
|
282
|
+
const H = document.querySelector(
|
|
283
283
|
`[data-parent-id="${V}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const G = Array.from(
|
|
285
|
+
if (H) {
|
|
286
|
+
const G = Array.from(H.childNodes);
|
|
287
287
|
if (G[O]) {
|
|
288
|
-
const
|
|
289
|
-
G[O].textContent = String(
|
|
288
|
+
const F = A ? new Function("state", `return (${A})(state)`)(D) : D;
|
|
289
|
+
G[O].textContent = String(F);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i ||
|
|
296
|
-
(i ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (i || R.current?.validation?.key) && n && Q(
|
|
296
|
+
(i || R.current?.validation?.key) + "." + n.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([$,
|
|
298
|
+
const _ = n.slice(0, n.length - 1);
|
|
299
|
+
a.updateType === "cut" && R.current?.validation?.key && Q(
|
|
300
|
+
R.current?.validation?.key + "." + _.join(".")
|
|
301
|
+
), a.updateType === "insert" && R.current?.validation?.key && Qt(
|
|
302
|
+
R.current?.validation?.key + "." + _.join(".")
|
|
303
|
+
).filter(([$, D]) => {
|
|
304
304
|
let V = $?.split(".").length;
|
|
305
|
-
if ($ ==
|
|
306
|
-
let O = $ + "." +
|
|
307
|
-
|
|
305
|
+
if ($ == _.join(".") && V == _.length - 1) {
|
|
306
|
+
let O = $ + "." + _;
|
|
307
|
+
Q($), Dt(O, D);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
const C = f.stateComponents.get(h);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
-
const
|
|
312
|
+
const P = At(u, E), $ = new Set(P), D = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
V,
|
|
315
315
|
O
|
|
316
316
|
] of C.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", O), !
|
|
320
|
-
if (
|
|
317
|
+
let A = !1;
|
|
318
|
+
const H = Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", O), !H.includes("none")) {
|
|
320
|
+
if (H.includes("all")) {
|
|
321
321
|
O.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
324
|
+
if (H.includes("component") && ((O.paths.has(D) || O.paths.has("")) && (A = !0), !A))
|
|
325
325
|
for (const G of $) {
|
|
326
|
-
let
|
|
326
|
+
let F = G;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (O.paths.has(
|
|
329
|
-
|
|
328
|
+
if (O.paths.has(F)) {
|
|
329
|
+
A = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const st =
|
|
332
|
+
const st = F.lastIndexOf(".");
|
|
333
333
|
if (st !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const ft = F.substring(
|
|
335
335
|
0,
|
|
336
336
|
st
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && O.paths.has(
|
|
341
|
-
|
|
339
|
+
Number(F.substring(st + 1))
|
|
340
|
+
) && O.paths.has(ft)) {
|
|
341
|
+
A = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
F = ft;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
F = "";
|
|
347
|
+
if (F === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (A) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
352
|
+
if (!A && H.includes("deps") && O.depsFunction) {
|
|
353
353
|
const G = O.depsFunction(E);
|
|
354
|
-
let
|
|
355
|
-
typeof G == "boolean" ? G && (
|
|
354
|
+
let F = !1;
|
|
355
|
+
typeof G == "boolean" ? G && (F = !0) : J(O.deps, G) || (O.deps = G, F = !0), F && (A = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
A && O.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
n = n.map((
|
|
363
|
-
const
|
|
364
|
-
return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() :
|
|
361
|
+
const w = Date.now();
|
|
362
|
+
n = n.map((P, $) => {
|
|
363
|
+
const D = n.slice(0, -1), V = Z(E, D);
|
|
364
|
+
return $ === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (V.length - 1).toString() : P;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: b, newValue:
|
|
366
|
+
const { oldValue: b, newValue: B } = ne(
|
|
367
367
|
a.updateType,
|
|
368
368
|
u,
|
|
369
369
|
E,
|
|
370
370
|
n
|
|
371
371
|
), Y = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: w,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: n,
|
|
375
375
|
updateType: a.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: b,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: B
|
|
379
379
|
};
|
|
380
380
|
switch (a.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
f.updateShadowAtPath(h, n, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(h,
|
|
385
|
+
const P = n.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(h, P, B);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const $ = n.slice(0, -1),
|
|
390
|
-
f.removeShadowArrayElement(h, $,
|
|
389
|
+
const $ = n.slice(0, -1), D = parseInt(n[n.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(h, $, D);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Kt(h, (P) => {
|
|
394
|
+
const D = [...P ?? [], Y].reduce((V, O) => {
|
|
395
|
+
const A = `${O.stateKey}:${JSON.stringify(O.path)}`, H = V.get(A);
|
|
396
|
+
return H ? (H.timeStamp = Math.max(H.timeStamp, O.timeStamp), H.newValue = O.newValue, H.oldValue = H.oldValue ?? O.oldValue, H.updateType = O.updateType) : V.set(A, { ...O }), V;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(D.values());
|
|
399
|
+
}), Vt(
|
|
400
400
|
E,
|
|
401
401
|
h,
|
|
402
|
-
|
|
402
|
+
R.current,
|
|
403
403
|
U
|
|
404
|
-
),
|
|
404
|
+
), R.current?.middleware && R.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
407
|
+
}), R.current?.serverSync) {
|
|
408
|
+
const P = f.serverState[h], $ = R.current?.serverSync;
|
|
409
|
+
te(h, {
|
|
410
410
|
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
|
|
411
|
-
rollBackState:
|
|
411
|
+
rollBackState: P,
|
|
412
412
|
actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
@@ -424,14 +424,14 @@ function ne(t, {
|
|
|
424
424
|
et.current,
|
|
425
425
|
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] ||
|
|
427
|
+
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Ct(h, t));
|
|
428
428
|
const d = wt(() => It(
|
|
429
429
|
h,
|
|
430
430
|
at,
|
|
431
431
|
et.current,
|
|
432
432
|
U
|
|
433
433
|
), [h, U]);
|
|
434
|
-
return [
|
|
434
|
+
return [Rt(h), d];
|
|
435
435
|
}
|
|
436
436
|
function It(t, c, m, g) {
|
|
437
437
|
const I = /* @__PURE__ */ new Map();
|
|
@@ -443,11 +443,11 @@ function It(t, c, m, g) {
|
|
|
443
443
|
N++;
|
|
444
444
|
}, v = {
|
|
445
445
|
removeValidation: (T) => {
|
|
446
|
-
T?.validationKey &&
|
|
446
|
+
T?.validationKey && Q(T.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (T) => {
|
|
449
449
|
const r = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
r?.key &&
|
|
450
|
+
r?.key && Q(r?.key), T?.validationKey && Q(T.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
452
|
o.getState().clearSelectedIndexesForState(t), I.clear(), N++;
|
|
453
453
|
const W = s(S, []), j = rt(t), U = tt(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, z = `${g}-${t}-${U}`;
|
|
@@ -466,7 +466,7 @@ function It(t, c, m, g) {
|
|
|
466
466
|
g
|
|
467
467
|
), S = o.getState().initialStateGlobal[t], W = rt(t), j = tt(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, U = `${g}-${t}-${j}`;
|
|
468
468
|
return localStorage.getItem(U) && localStorage.removeItem(U), Ft(() => {
|
|
469
|
-
|
|
469
|
+
Ct(t, T), o.getState().initializeShadowState(t, T), Tt(t, r), nt(t, T);
|
|
470
470
|
const z = o.getState().stateComponents.get(t);
|
|
471
471
|
z && z.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
@@ -480,7 +480,7 @@ function It(t, c, m, g) {
|
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const T = o.getState().serverState[t];
|
|
483
|
-
return !!(T && J(T,
|
|
483
|
+
return !!(T && J(T, Rt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function s(T, r = [], S) {
|
|
@@ -493,14 +493,14 @@ function It(t, c, m, g) {
|
|
|
493
493
|
j[h] = v[h];
|
|
494
494
|
});
|
|
495
495
|
const U = {
|
|
496
|
-
apply(h, l,
|
|
496
|
+
apply(h, l, gt) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${r.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, r);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(T) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const gt = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function It(t, c, m, g) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !gt.has(l)) {
|
|
527
527
|
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const n = e.components.get(d);
|
|
@@ -540,7 +540,7 @@ function It(t, c, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => At(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -622,49 +622,49 @@ function It(t, c, m, g) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: i = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = e, u = q(!1), E = q(null), [y,
|
|
625
|
+
} = e, u = q(!1), E = q(null), [y, _] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [C,
|
|
628
|
+
}), [C, w] = K("IDLE_AT_TOP"), b = q(!1), B = q(0), Y = q(f), P = q(0), [$, D] = K(0), V = q(null);
|
|
629
629
|
ot(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
|
-
|
|
630
|
+
D((M) => M + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const O = o().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
r
|
|
635
|
-
),
|
|
635
|
+
), A = O.length, { totalHeight: H, positions: G } = wt(() => {
|
|
636
636
|
const k = o.getState().getShadowMetadata(t, r) || [];
|
|
637
|
-
let
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
637
|
+
let M = 0;
|
|
638
|
+
const L = [];
|
|
639
|
+
for (let x = 0; x < A; x++) {
|
|
640
|
+
L[x] = M;
|
|
641
|
+
const X = k[x]?.virtualizer?.itemHeight;
|
|
642
|
+
M += X || n;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: M, positions: L };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
646
|
+
A,
|
|
647
647
|
t,
|
|
648
648
|
r.join("."),
|
|
649
649
|
n,
|
|
650
650
|
$
|
|
651
|
-
]),
|
|
652
|
-
const k = Math.max(0, y.startIndex),
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return s(
|
|
651
|
+
]), F = wt(() => {
|
|
652
|
+
const k = Math.max(0, y.startIndex), M = Math.min(A, y.endIndex), L = Array.from(
|
|
653
|
+
{ length: M - k },
|
|
654
|
+
(X, it) => k + it
|
|
655
|
+
), x = L.map((X) => O[X]);
|
|
656
|
+
return s(x, r, {
|
|
657
657
|
...S,
|
|
658
|
-
validIndices:
|
|
658
|
+
validIndices: L
|
|
659
659
|
});
|
|
660
|
-
}, [y.startIndex, y.endIndex, O,
|
|
661
|
-
|
|
660
|
+
}, [y.startIndex, y.endIndex, O, A]);
|
|
661
|
+
lt(() => {
|
|
662
662
|
const k = E.current;
|
|
663
663
|
if (!k) return;
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
666
|
-
const { top:
|
|
667
|
-
b.current = !0, k.scrollTop =
|
|
664
|
+
const M = A > B.current;
|
|
665
|
+
if (M && V.current) {
|
|
666
|
+
const { top: L, height: x } = V.current;
|
|
667
|
+
b.current = !0, k.scrollTop = L + (k.scrollHeight - x), console.log(
|
|
668
668
|
`ANCHOR RESTORED to scrollTop: ${k.scrollTop}`
|
|
669
669
|
), setTimeout(() => {
|
|
670
670
|
b.current = !1;
|
|
@@ -674,99 +674,108 @@ function It(t, c, m, g) {
|
|
|
674
674
|
f,
|
|
675
675
|
Y.current
|
|
676
676
|
)) {
|
|
677
|
-
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"),
|
|
677
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), w("IDLE_AT_TOP");
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
|
-
|
|
680
|
+
M && C === "LOCKED_AT_BOTTOM" && i && (console.log(
|
|
681
681
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
682
|
-
),
|
|
682
|
+
), w("GETTING_HEIGHTS"));
|
|
683
683
|
}
|
|
684
|
-
|
|
685
|
-
}, [
|
|
684
|
+
B.current = A, Y.current = f;
|
|
685
|
+
}, [A, ...f]), lt(() => {
|
|
686
686
|
const k = E.current;
|
|
687
687
|
if (!k) return;
|
|
688
|
-
let
|
|
689
|
-
if (C === "IDLE_AT_TOP" && i &&
|
|
688
|
+
let M;
|
|
689
|
+
if (C === "IDLE_AT_TOP" && i && A > 0)
|
|
690
690
|
console.log(
|
|
691
691
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
692
|
-
),
|
|
693
|
-
else if (C === "GETTING_HEIGHTS")
|
|
692
|
+
), w("GETTING_HEIGHTS");
|
|
693
|
+
else if (C === "GETTING_HEIGHTS") {
|
|
694
694
|
console.log(
|
|
695
695
|
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
696
|
-
),
|
|
697
|
-
startIndex: Math.max(0,
|
|
698
|
-
endIndex:
|
|
699
|
-
})
|
|
700
|
-
|
|
701
|
-
|
|
696
|
+
), _({
|
|
697
|
+
startIndex: Math.max(0, A - 10 - a),
|
|
698
|
+
endIndex: A
|
|
699
|
+
});
|
|
700
|
+
let L = 0;
|
|
701
|
+
const x = 50;
|
|
702
|
+
M = setInterval(() => {
|
|
703
|
+
L++;
|
|
704
|
+
const X = A - 1, yt = (o.getState().getShadowMetadata(t, r) || [])[X]?.virtualizer?.itemHeight || 0;
|
|
705
|
+
console.log(
|
|
706
|
+
`ACTION (GETTING_HEIGHTS): attempt ${L}, lastItemHeight =`,
|
|
707
|
+
yt
|
|
708
|
+
), yt > 0 ? (clearInterval(M), console.log(
|
|
702
709
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
703
|
-
),
|
|
710
|
+
), w("SCROLLING_TO_BOTTOM")) : L >= x && (clearInterval(M), console.log(
|
|
711
|
+
"ACTION (GETTING_HEIGHTS): Timeout - proceeding anyway"
|
|
712
|
+
), w("SCROLLING_TO_BOTTOM"));
|
|
704
713
|
}, 100);
|
|
705
|
-
else if (C === "SCROLLING_TO_BOTTOM") {
|
|
714
|
+
} else if (C === "SCROLLING_TO_BOTTOM") {
|
|
706
715
|
console.log(
|
|
707
716
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
708
717
|
), b.current = !0;
|
|
709
|
-
const
|
|
718
|
+
const L = B.current === 0 ? "auto" : "smooth";
|
|
710
719
|
k.scrollTo({
|
|
711
720
|
top: k.scrollHeight,
|
|
712
|
-
behavior:
|
|
721
|
+
behavior: L
|
|
713
722
|
});
|
|
714
|
-
const
|
|
723
|
+
const x = setTimeout(
|
|
715
724
|
() => {
|
|
716
725
|
console.log(
|
|
717
726
|
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
718
|
-
), b.current = !1, u.current = !1,
|
|
727
|
+
), b.current = !1, u.current = !1, w("LOCKED_AT_BOTTOM");
|
|
719
728
|
},
|
|
720
|
-
|
|
729
|
+
L === "smooth" ? 500 : 50
|
|
721
730
|
);
|
|
722
|
-
return () => clearTimeout(
|
|
731
|
+
return () => clearTimeout(x);
|
|
723
732
|
}
|
|
724
733
|
return () => {
|
|
725
|
-
|
|
734
|
+
M && clearInterval(M);
|
|
726
735
|
};
|
|
727
|
-
}, [C,
|
|
736
|
+
}, [C, A, G]), ot(() => {
|
|
728
737
|
const k = E.current;
|
|
729
738
|
if (!k) return;
|
|
730
|
-
const
|
|
739
|
+
const M = n, L = () => {
|
|
731
740
|
if (b.current)
|
|
732
741
|
return;
|
|
733
|
-
const { scrollTop:
|
|
734
|
-
if (
|
|
735
|
-
top:
|
|
736
|
-
height:
|
|
737
|
-
}), Math.abs(
|
|
742
|
+
const { scrollTop: x, scrollHeight: X, clientHeight: it } = k;
|
|
743
|
+
if (X - x - it < 10 ? (C !== "LOCKED_AT_BOTTOM" && w("LOCKED_AT_BOTTOM"), V.current = null) : (C !== "IDLE_NOT_AT_BOTTOM" && w("IDLE_NOT_AT_BOTTOM"), V.current = {
|
|
744
|
+
top: x,
|
|
745
|
+
height: X
|
|
746
|
+
}), Math.abs(x - P.current) < M)
|
|
738
747
|
return;
|
|
739
748
|
console.log(
|
|
740
|
-
`Threshold passed at ${
|
|
749
|
+
`Threshold passed at ${x}px. Recalculating range...`
|
|
741
750
|
);
|
|
742
|
-
let
|
|
743
|
-
for (;
|
|
744
|
-
const mt = Math.floor((
|
|
745
|
-
G[mt] <
|
|
751
|
+
let pt = A - 1, Et = 0, $t = 0;
|
|
752
|
+
for (; Et <= pt; ) {
|
|
753
|
+
const mt = Math.floor((Et + pt) / 2);
|
|
754
|
+
G[mt] < x ? ($t = mt, Et = mt + 1) : pt = mt - 1;
|
|
746
755
|
}
|
|
747
|
-
const
|
|
748
|
-
let St =
|
|
749
|
-
const Ut =
|
|
750
|
-
for (; St <
|
|
756
|
+
const kt = Math.max(0, $t - a);
|
|
757
|
+
let St = kt;
|
|
758
|
+
const Ut = x + it;
|
|
759
|
+
for (; St < A && G[St] < Ut; )
|
|
751
760
|
St++;
|
|
752
|
-
|
|
753
|
-
startIndex:
|
|
754
|
-
endIndex: Math.min(
|
|
755
|
-
}),
|
|
761
|
+
_({
|
|
762
|
+
startIndex: kt,
|
|
763
|
+
endIndex: Math.min(A, St + a)
|
|
764
|
+
}), P.current = x;
|
|
756
765
|
};
|
|
757
|
-
return k.addEventListener("scroll",
|
|
766
|
+
return k.addEventListener("scroll", L, {
|
|
758
767
|
passive: !0
|
|
759
|
-
}), () => k.removeEventListener("scroll",
|
|
760
|
-
}, [
|
|
761
|
-
const st =
|
|
768
|
+
}), () => k.removeEventListener("scroll", L);
|
|
769
|
+
}, [A, G, n, a, C]);
|
|
770
|
+
const st = bt(() => {
|
|
762
771
|
console.log(
|
|
763
772
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
764
|
-
),
|
|
765
|
-
}, []),
|
|
766
|
-
(k,
|
|
767
|
-
E.current && G[k] !== void 0 && (
|
|
773
|
+
), w("SCROLLING_TO_BOTTOM");
|
|
774
|
+
}, []), ft = bt(
|
|
775
|
+
(k, M = "smooth") => {
|
|
776
|
+
E.current && G[k] !== void 0 && (w("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
768
777
|
top: G[k],
|
|
769
|
-
behavior:
|
|
778
|
+
behavior: M
|
|
770
779
|
}));
|
|
771
780
|
},
|
|
772
781
|
[G]
|
|
@@ -777,7 +786,7 @@ function It(t, c, m, g) {
|
|
|
777
786
|
},
|
|
778
787
|
inner: {
|
|
779
788
|
style: {
|
|
780
|
-
height: `${
|
|
789
|
+
height: `${H}px`,
|
|
781
790
|
position: "relative"
|
|
782
791
|
}
|
|
783
792
|
},
|
|
@@ -788,10 +797,10 @@ function It(t, c, m, g) {
|
|
|
788
797
|
}
|
|
789
798
|
};
|
|
790
799
|
return {
|
|
791
|
-
virtualState:
|
|
800
|
+
virtualState: F,
|
|
792
801
|
virtualizerProps: jt,
|
|
793
802
|
scrollToBottom: st,
|
|
794
|
-
scrollToIndex:
|
|
803
|
+
scrollToIndex: ft
|
|
795
804
|
};
|
|
796
805
|
};
|
|
797
806
|
if (l === "stateSort")
|
|
@@ -825,19 +834,19 @@ function It(t, c, m, g) {
|
|
|
825
834
|
const u = n[i], E = [...r, i.toString()], y = s(u, E, S);
|
|
826
835
|
return e(u, y, {
|
|
827
836
|
register: () => {
|
|
828
|
-
const [, C] = K({}),
|
|
829
|
-
|
|
830
|
-
const b = `${t}////${
|
|
837
|
+
const [, C] = K({}), w = `${m}-${r.join(".")}-${i}`;
|
|
838
|
+
lt(() => {
|
|
839
|
+
const b = `${t}////${w}`, B = o.getState().stateComponents.get(t) || {
|
|
831
840
|
components: /* @__PURE__ */ new Map()
|
|
832
841
|
};
|
|
833
|
-
return
|
|
842
|
+
return B.components.set(b, {
|
|
834
843
|
forceUpdate: () => C({}),
|
|
835
844
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
836
|
-
}), o.getState().stateComponents.set(t,
|
|
845
|
+
}), o.getState().stateComponents.set(t, B), () => {
|
|
837
846
|
const Y = o.getState().stateComponents.get(t);
|
|
838
847
|
Y && Y.components.delete(b);
|
|
839
848
|
};
|
|
840
|
-
}, [t,
|
|
849
|
+
}, [t, w]);
|
|
841
850
|
},
|
|
842
851
|
index: f,
|
|
843
852
|
originalIndex: i
|
|
@@ -861,7 +870,7 @@ function It(t, c, m, g) {
|
|
|
861
870
|
);
|
|
862
871
|
});
|
|
863
872
|
if (l === "$stateMap")
|
|
864
|
-
return (e) =>
|
|
873
|
+
return (e) => dt(oe, {
|
|
865
874
|
proxy: {
|
|
866
875
|
_stateKey: t,
|
|
867
876
|
_path: r,
|
|
@@ -874,11 +883,11 @@ function It(t, c, m, g) {
|
|
|
874
883
|
return (e) => {
|
|
875
884
|
const n = o.getState().getNestedState(t, r);
|
|
876
885
|
return Array.isArray(n) ? (S?.validIndices || Array.from({ length: n.length }, (i, f) => f)).map((i, f) => {
|
|
877
|
-
const u = n[i], E = [...r, i.toString()], y = s(u, E, S),
|
|
878
|
-
return
|
|
886
|
+
const u = n[i], E = [...r, i.toString()], y = s(u, E, S), _ = `${m}-${r.join(".")}-${i}`;
|
|
887
|
+
return dt(se, {
|
|
879
888
|
key: i,
|
|
880
889
|
stateKey: t,
|
|
881
|
-
itemComponentId:
|
|
890
|
+
itemComponentId: _,
|
|
882
891
|
itemPath: E,
|
|
883
892
|
children: e(
|
|
884
893
|
u,
|
|
@@ -918,7 +927,7 @@ function It(t, c, m, g) {
|
|
|
918
927
|
return s(a, i);
|
|
919
928
|
};
|
|
920
929
|
if (l === "insert")
|
|
921
|
-
return (e) => (p(r),
|
|
930
|
+
return (e) => (p(r), Ot(c, e, r, t), s(
|
|
922
931
|
o.getState().getNestedState(t, r),
|
|
923
932
|
r
|
|
924
933
|
));
|
|
@@ -929,19 +938,19 @@ function It(t, c, m, g) {
|
|
|
929
938
|
if (!i.some((y) => {
|
|
930
939
|
if (n) {
|
|
931
940
|
const C = n.every(
|
|
932
|
-
(
|
|
941
|
+
(w) => J(y[w], f[w])
|
|
933
942
|
);
|
|
934
943
|
return C && (u = y), C;
|
|
935
944
|
}
|
|
936
|
-
const
|
|
937
|
-
return
|
|
945
|
+
const _ = J(y, f);
|
|
946
|
+
return _ && (u = y), _;
|
|
938
947
|
}))
|
|
939
|
-
p(r),
|
|
948
|
+
p(r), Ot(c, f, r, t);
|
|
940
949
|
else if (a && u) {
|
|
941
|
-
const y = a(u),
|
|
950
|
+
const y = a(u), _ = i.map(
|
|
942
951
|
(C) => J(C, u) ? y : C
|
|
943
952
|
);
|
|
944
|
-
p(r),
|
|
953
|
+
p(r), ct(c, _, r);
|
|
945
954
|
}
|
|
946
955
|
};
|
|
947
956
|
if (l === "cut")
|
|
@@ -960,7 +969,7 @@ function It(t, c, m, g) {
|
|
|
960
969
|
if (l === "toggleByValue")
|
|
961
970
|
return (e) => {
|
|
962
971
|
const n = T.findIndex((a) => a === e);
|
|
963
|
-
n > -1 ? ht(c, r, t, n) :
|
|
972
|
+
n > -1 ? ht(c, r, t, n) : Ot(c, e, r, t);
|
|
964
973
|
};
|
|
965
974
|
if (l === "stateFind")
|
|
966
975
|
return (e) => {
|
|
@@ -1001,13 +1010,13 @@ function It(t, c, m, g) {
|
|
|
1001
1010
|
return o.getState().getNestedState(t, r);
|
|
1002
1011
|
};
|
|
1003
1012
|
if (l === "$derive")
|
|
1004
|
-
return (d) =>
|
|
1013
|
+
return (d) => Gt({
|
|
1005
1014
|
_stateKey: t,
|
|
1006
1015
|
_path: r,
|
|
1007
1016
|
_effect: d.toString()
|
|
1008
1017
|
});
|
|
1009
1018
|
if (l === "$get")
|
|
1010
|
-
return () =>
|
|
1019
|
+
return () => Gt({
|
|
1011
1020
|
_stateKey: t,
|
|
1012
1021
|
_path: r
|
|
1013
1022
|
});
|
|
@@ -1026,7 +1035,7 @@ function It(t, c, m, g) {
|
|
|
1026
1035
|
const e = r.slice(0, -1), n = Number(r[r.length - 1]), a = e.join(".");
|
|
1027
1036
|
d ? o.getState().setSelectedIndex(t, a, n) : o.getState().setSelectedIndex(t, a, void 0);
|
|
1028
1037
|
const i = o.getState().getNestedState(t, [...e]);
|
|
1029
|
-
|
|
1038
|
+
ct(c, i, e), p(e);
|
|
1030
1039
|
};
|
|
1031
1040
|
if (l === "toggleSelected")
|
|
1032
1041
|
return () => {
|
|
@@ -1037,7 +1046,7 @@ function It(t, c, m, g) {
|
|
|
1037
1046
|
a === e ? void 0 : e
|
|
1038
1047
|
);
|
|
1039
1048
|
const i = o.getState().getNestedState(t, [...d]);
|
|
1040
|
-
|
|
1049
|
+
ct(c, i, d), p(d);
|
|
1041
1050
|
};
|
|
1042
1051
|
if (r.length == 0) {
|
|
1043
1052
|
if (l === "addValidation")
|
|
@@ -1045,15 +1054,15 @@ function It(t, c, m, g) {
|
|
|
1045
1054
|
const e = o.getState().getInitialOptions(t)?.validation;
|
|
1046
1055
|
if (!e?.key)
|
|
1047
1056
|
throw new Error("Validation key not found");
|
|
1048
|
-
|
|
1057
|
+
Q(e.key), console.log("addValidationError", d), d.forEach((n) => {
|
|
1049
1058
|
const a = [e.key, ...n.path].join(".");
|
|
1050
|
-
console.log("fullErrorPath", a),
|
|
1051
|
-
}),
|
|
1059
|
+
console.log("fullErrorPath", a), Dt(a, n.message);
|
|
1060
|
+
}), ut(t);
|
|
1052
1061
|
};
|
|
1053
1062
|
if (l === "applyJsonPatch")
|
|
1054
1063
|
return (d) => {
|
|
1055
|
-
const e = o.getState().cogsStateStore[t], a =
|
|
1056
|
-
|
|
1064
|
+
const e = o.getState().cogsStateStore[t], a = Zt(e, d).newDocument;
|
|
1065
|
+
Ht(
|
|
1057
1066
|
t,
|
|
1058
1067
|
o.getState().initialStateGlobal[t],
|
|
1059
1068
|
a,
|
|
@@ -1063,57 +1072,57 @@ function It(t, c, m, g) {
|
|
|
1063
1072
|
);
|
|
1064
1073
|
const i = o.getState().stateComponents.get(t);
|
|
1065
1074
|
if (i) {
|
|
1066
|
-
const f =
|
|
1075
|
+
const f = At(e, a), u = new Set(f);
|
|
1067
1076
|
for (const [
|
|
1068
1077
|
E,
|
|
1069
1078
|
y
|
|
1070
1079
|
] of i.components.entries()) {
|
|
1071
|
-
let
|
|
1080
|
+
let _ = !1;
|
|
1072
1081
|
const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
1073
1082
|
if (!C.includes("none")) {
|
|
1074
1083
|
if (C.includes("all")) {
|
|
1075
1084
|
y.forceUpdate();
|
|
1076
1085
|
continue;
|
|
1077
1086
|
}
|
|
1078
|
-
if (C.includes("component") && (y.paths.has("") && (
|
|
1079
|
-
for (const
|
|
1080
|
-
if (y.paths.has(
|
|
1081
|
-
|
|
1087
|
+
if (C.includes("component") && (y.paths.has("") && (_ = !0), !_))
|
|
1088
|
+
for (const w of u) {
|
|
1089
|
+
if (y.paths.has(w)) {
|
|
1090
|
+
_ = !0;
|
|
1082
1091
|
break;
|
|
1083
1092
|
}
|
|
1084
|
-
let b =
|
|
1093
|
+
let b = w.lastIndexOf(".");
|
|
1085
1094
|
for (; b !== -1; ) {
|
|
1086
|
-
const
|
|
1087
|
-
if (y.paths.has(
|
|
1088
|
-
|
|
1095
|
+
const B = w.substring(0, b);
|
|
1096
|
+
if (y.paths.has(B)) {
|
|
1097
|
+
_ = !0;
|
|
1089
1098
|
break;
|
|
1090
1099
|
}
|
|
1091
|
-
const Y =
|
|
1100
|
+
const Y = w.substring(
|
|
1092
1101
|
b + 1
|
|
1093
1102
|
);
|
|
1094
1103
|
if (!isNaN(Number(Y))) {
|
|
1095
|
-
const
|
|
1096
|
-
if (
|
|
1097
|
-
const $ =
|
|
1104
|
+
const P = B.lastIndexOf(".");
|
|
1105
|
+
if (P !== -1) {
|
|
1106
|
+
const $ = B.substring(
|
|
1098
1107
|
0,
|
|
1099
|
-
|
|
1108
|
+
P
|
|
1100
1109
|
);
|
|
1101
1110
|
if (y.paths.has($)) {
|
|
1102
|
-
|
|
1111
|
+
_ = !0;
|
|
1103
1112
|
break;
|
|
1104
1113
|
}
|
|
1105
1114
|
}
|
|
1106
1115
|
}
|
|
1107
|
-
b =
|
|
1116
|
+
b = B.lastIndexOf(".");
|
|
1108
1117
|
}
|
|
1109
|
-
if (
|
|
1118
|
+
if (_) break;
|
|
1110
1119
|
}
|
|
1111
|
-
if (!
|
|
1112
|
-
const
|
|
1120
|
+
if (!_ && C.includes("deps") && y.depsFunction) {
|
|
1121
|
+
const w = y.depsFunction(a);
|
|
1113
1122
|
let b = !1;
|
|
1114
|
-
typeof
|
|
1123
|
+
typeof w == "boolean" ? w && (b = !0) : J(y.deps, w) || (y.deps = w, b = !0), b && (_ = !0);
|
|
1115
1124
|
}
|
|
1116
|
-
|
|
1125
|
+
_ && y.forceUpdate();
|
|
1117
1126
|
}
|
|
1118
1127
|
}
|
|
1119
1128
|
}
|
|
@@ -1125,18 +1134,18 @@ function It(t, c, m, g) {
|
|
|
1125
1134
|
throw new Error("Zod schema not found");
|
|
1126
1135
|
if (!d?.key)
|
|
1127
1136
|
throw new Error("Validation key not found");
|
|
1128
|
-
|
|
1137
|
+
Q(d.key);
|
|
1129
1138
|
const n = o.getState().cogsStateStore[t];
|
|
1130
1139
|
try {
|
|
1131
1140
|
const a = o.getState().getValidationErrors(d.key);
|
|
1132
1141
|
a && a.length > 0 && a.forEach(([f]) => {
|
|
1133
|
-
f && f.startsWith(d.key) &&
|
|
1142
|
+
f && f.startsWith(d.key) && Q(f);
|
|
1134
1143
|
});
|
|
1135
1144
|
const i = d.zodSchema.safeParse(n);
|
|
1136
1145
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1137
|
-
const E = u.path, y = u.message,
|
|
1138
|
-
e(
|
|
1139
|
-
}),
|
|
1146
|
+
const E = u.path, y = u.message, _ = [d.key, ...E].join(".");
|
|
1147
|
+
e(_, y);
|
|
1148
|
+
}), ut(t), !1);
|
|
1140
1149
|
} catch (a) {
|
|
1141
1150
|
return console.error("Zod schema validation failed", a), !1;
|
|
1142
1151
|
}
|
|
@@ -1145,7 +1154,7 @@ function It(t, c, m, g) {
|
|
|
1145
1154
|
if (l === "getComponents")
|
|
1146
1155
|
return () => o().stateComponents.get(t);
|
|
1147
1156
|
if (l === "getAllFormRefs")
|
|
1148
|
-
return () =>
|
|
1157
|
+
return () => Mt.getState().getFormRefsByStateKey(t);
|
|
1149
1158
|
if (l === "_initialState")
|
|
1150
1159
|
return o.getState().initialStateGlobal[t];
|
|
1151
1160
|
if (l === "_serverState")
|
|
@@ -1158,13 +1167,13 @@ function It(t, c, m, g) {
|
|
|
1158
1167
|
if (l === "removeValidation") return v.removeValidation;
|
|
1159
1168
|
}
|
|
1160
1169
|
if (l === "getFormRef")
|
|
1161
|
-
return () =>
|
|
1170
|
+
return () => Mt.getState().getFormRef(t + "." + r.join("."));
|
|
1162
1171
|
if (l === "validationWrapper")
|
|
1163
1172
|
return ({
|
|
1164
1173
|
children: d,
|
|
1165
1174
|
hideMessage: e
|
|
1166
|
-
}) => /* @__PURE__ */
|
|
1167
|
-
|
|
1175
|
+
}) => /* @__PURE__ */ _t(
|
|
1176
|
+
qt,
|
|
1168
1177
|
{
|
|
1169
1178
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1170
1179
|
path: r,
|
|
@@ -1180,21 +1189,21 @@ function It(t, c, m, g) {
|
|
|
1180
1189
|
if (l === "update")
|
|
1181
1190
|
return (d, e) => {
|
|
1182
1191
|
if (e?.debounce)
|
|
1183
|
-
|
|
1184
|
-
|
|
1192
|
+
zt(() => {
|
|
1193
|
+
ct(c, d, r, "");
|
|
1185
1194
|
const n = o.getState().getNestedState(t, r);
|
|
1186
1195
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1187
1196
|
}, e.debounce);
|
|
1188
1197
|
else {
|
|
1189
|
-
|
|
1198
|
+
ct(c, d, r, "");
|
|
1190
1199
|
const n = o.getState().getNestedState(t, r);
|
|
1191
1200
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1192
1201
|
}
|
|
1193
1202
|
p(r);
|
|
1194
1203
|
};
|
|
1195
1204
|
if (l === "formElement")
|
|
1196
|
-
return (d, e) => /* @__PURE__ */
|
|
1197
|
-
|
|
1205
|
+
return (d, e) => /* @__PURE__ */ _t(
|
|
1206
|
+
Jt,
|
|
1198
1207
|
{
|
|
1199
1208
|
setState: c,
|
|
1200
1209
|
stateKey: t,
|
|
@@ -1203,8 +1212,8 @@ function It(t, c, m, g) {
|
|
|
1203
1212
|
formOpts: e
|
|
1204
1213
|
}
|
|
1205
1214
|
);
|
|
1206
|
-
const
|
|
1207
|
-
return s(at,
|
|
1215
|
+
const R = [...r, l], at = o.getState().getNestedState(t, R);
|
|
1216
|
+
return s(at, R, S);
|
|
1208
1217
|
}
|
|
1209
1218
|
}, z = new Proxy(j, U);
|
|
1210
1219
|
return I.set(W, {
|
|
@@ -1216,10 +1225,10 @@ function It(t, c, m, g) {
|
|
|
1216
1225
|
o.getState().getNestedState(t, [])
|
|
1217
1226
|
);
|
|
1218
1227
|
}
|
|
1219
|
-
function
|
|
1220
|
-
return
|
|
1228
|
+
function Gt(t) {
|
|
1229
|
+
return dt(ae, { proxy: t });
|
|
1221
1230
|
}
|
|
1222
|
-
function
|
|
1231
|
+
function oe({
|
|
1223
1232
|
proxy: t,
|
|
1224
1233
|
rebuildStateShape: c
|
|
1225
1234
|
}) {
|
|
@@ -1231,7 +1240,7 @@ function re({
|
|
|
1231
1240
|
(I, N, p, v, s) => t._mapFn(I, N, p, v, s)
|
|
1232
1241
|
) : null;
|
|
1233
1242
|
}
|
|
1234
|
-
function
|
|
1243
|
+
function ae({
|
|
1235
1244
|
proxy: t
|
|
1236
1245
|
}) {
|
|
1237
1246
|
const c = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
@@ -1264,14 +1273,14 @@ function oe({
|
|
|
1264
1273
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1265
1274
|
const W = document.createTextNode(String(S));
|
|
1266
1275
|
g.replaceWith(W);
|
|
1267
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1276
|
+
}, [t._stateKey, t._path.join("."), t._effect]), dt("span", {
|
|
1268
1277
|
ref: c,
|
|
1269
1278
|
style: { display: "none" },
|
|
1270
1279
|
"data-signal-id": m
|
|
1271
1280
|
});
|
|
1272
1281
|
}
|
|
1273
1282
|
function pe(t) {
|
|
1274
|
-
const c =
|
|
1283
|
+
const c = Bt(
|
|
1275
1284
|
(m) => {
|
|
1276
1285
|
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1277
1286
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1283,22 +1292,22 @@ function pe(t) {
|
|
|
1283
1292
|
},
|
|
1284
1293
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1285
1294
|
);
|
|
1286
|
-
return
|
|
1295
|
+
return dt("text", {}, String(c));
|
|
1287
1296
|
}
|
|
1288
|
-
function
|
|
1297
|
+
function se({
|
|
1289
1298
|
stateKey: t,
|
|
1290
1299
|
itemComponentId: c,
|
|
1291
1300
|
itemPath: m,
|
|
1292
1301
|
children: g
|
|
1293
1302
|
}) {
|
|
1294
|
-
const [, I] = K({}), [N, p] =
|
|
1303
|
+
const [, I] = K({}), [N, p] = Xt(), v = q(null);
|
|
1295
1304
|
return ot(() => {
|
|
1296
1305
|
p.height > 0 && p.height !== v.current && (v.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1297
1306
|
virtualizer: {
|
|
1298
1307
|
itemHeight: p.height
|
|
1299
1308
|
}
|
|
1300
1309
|
}));
|
|
1301
|
-
}, [p.height, t, m]),
|
|
1310
|
+
}, [p.height, t, m]), lt(() => {
|
|
1302
1311
|
const s = `${t}////${c}`, T = o.getState().stateComponents.get(t) || {
|
|
1303
1312
|
components: /* @__PURE__ */ new Map()
|
|
1304
1313
|
};
|
|
@@ -1309,14 +1318,14 @@ function ae({
|
|
|
1309
1318
|
const r = o.getState().stateComponents.get(t);
|
|
1310
1319
|
r && r.components.delete(s);
|
|
1311
1320
|
};
|
|
1312
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */
|
|
1321
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ _t("div", { ref: N, children: g });
|
|
1313
1322
|
}
|
|
1314
1323
|
export {
|
|
1315
|
-
|
|
1324
|
+
Gt as $cogsSignal,
|
|
1316
1325
|
pe as $cogsSignalStore,
|
|
1317
1326
|
Ie as addStateOptions,
|
|
1318
1327
|
ve as createCogsState,
|
|
1319
1328
|
ye as notifyComponent,
|
|
1320
|
-
|
|
1329
|
+
re as useCogsStateFn
|
|
1321
1330
|
};
|
|
1322
1331
|
//# sourceMappingURL=CogsState.jsx.map
|