cogsbox-state 0.5.366 → 0.5.367
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 +387 -384
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +70 -76
package/dist/CogsState.jsx
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as Ge, isDeepEqual as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as Te } from "react/jsx-runtime";
|
|
3
|
+
import { useState as X, useRef as K, useEffect as oe, useLayoutEffect as ie, useMemo as ve, createElement as ce, useSyncExternalStore as Pe, startTransition as Ve, useCallback as _e } from "react";
|
|
4
|
+
import { transformStateFunc as Ge, isDeepEqual as z, isFunction as Q, getNestedValue as q, getDifferences as ye, debounce as Le } from "./utility.js";
|
|
5
|
+
import { pushFunc as he, updateFn as se, cutFunc as ge, ValidationWrapper as Re, FormControlComponent as De } from "./Functions.jsx";
|
|
6
|
+
import Ue from "superjson";
|
|
7
7
|
import { v4 as pe } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as r, formRefStore as Oe } from "./store.js";
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
10
|
+
import { useCogsConfig as ke } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as je } from "fast-json-patch";
|
|
12
|
+
import He from "react-use-measure";
|
|
13
|
+
function Ae(e, i) {
|
|
14
14
|
const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
|
|
15
15
|
g(e, {
|
|
16
16
|
...T,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Ne({
|
|
21
21
|
stateKey: e,
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions,
|
|
25
|
+
const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
|
|
26
26
|
let v = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const a in i)
|
|
29
|
-
|
|
30
|
-
!
|
|
31
|
-
v && N(e,
|
|
29
|
+
p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (v = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
|
|
30
|
+
!z(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
|
|
31
|
+
v && N(e, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function dt(e, { formElements: i, validation: m }) {
|
|
34
34
|
return { initialState: e, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const ut = (e, i) => {
|
|
37
37
|
let m = e;
|
|
38
38
|
const [g, T] = Ge(m);
|
|
39
39
|
(Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
|
|
@@ -46,13 +46,13 @@ const gt = (e, i) => {
|
|
|
46
46
|
}, re(v) || r.getState().setInitialStateOptions(v, T[v]);
|
|
47
47
|
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
48
|
const N = (v, a) => {
|
|
49
|
-
const [h] =
|
|
50
|
-
|
|
49
|
+
const [h] = X(a?.componentId ?? pe());
|
|
50
|
+
Ne({
|
|
51
51
|
stateKey: v,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: T
|
|
54
54
|
});
|
|
55
|
-
const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [
|
|
55
|
+
const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, L] = Ye(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
@@ -68,45 +68,45 @@ const gt = (e, i) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return L;
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function p(v, a) {
|
|
74
|
+
Ne({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && qe(v, a), Ie(v);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState: N, setCogsOptions:
|
|
76
|
+
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: fe,
|
|
79
79
|
setState: te,
|
|
80
80
|
getInitialOptions: re,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
81
|
+
getKeyState: be,
|
|
82
|
+
getValidationErrors: Fe,
|
|
83
83
|
setStateLog: Be,
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
84
|
+
updateInitialStateGlobal: Ee,
|
|
85
|
+
addValidationError: We,
|
|
86
|
+
removeValidationError: Z,
|
|
87
87
|
setServerSyncActions: ze
|
|
88
|
-
} = r.getState(),
|
|
88
|
+
} = r.getState(), Ce = (e, i, m, g, T) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
i,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const N =
|
|
95
|
+
const N = Q(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
96
96
|
if (N && g) {
|
|
97
|
-
const
|
|
97
|
+
const p = `${g}-${i}-${N}`;
|
|
98
98
|
let v;
|
|
99
99
|
try {
|
|
100
|
-
v = me(
|
|
100
|
+
v = me(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: e,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: T ?? v
|
|
107
|
-
}, h =
|
|
107
|
+
}, h = Ue.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
|
-
|
|
109
|
+
p,
|
|
110
110
|
JSON.stringify(h.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
@@ -119,7 +119,7 @@ const gt = (e, i) => {
|
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
121
|
}, qe = (e, i) => {
|
|
122
|
-
const m = r.getState().cogsStateStore[e], { sessionId: g } =
|
|
122
|
+
const m = r.getState().cogsStateStore[e], { sessionId: g } = ke(), T = Q(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (T && g) {
|
|
124
124
|
const N = me(
|
|
125
125
|
`${g}-${e}-${T}`
|
|
@@ -128,8 +128,8 @@ const gt = (e, i) => {
|
|
|
128
128
|
return te(e, N.state), Ie(e), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
132
|
-
const
|
|
131
|
+
}, Me = (e, i, m, g, T, N) => {
|
|
132
|
+
const p = {
|
|
133
133
|
initialState: i,
|
|
134
134
|
updaterState: Se(
|
|
135
135
|
e,
|
|
@@ -139,7 +139,7 @@ const gt = (e, i) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
Ee(e, p.initialState), fe(e, p.updaterState), te(e, p.state);
|
|
143
143
|
}, Ie = (e) => {
|
|
144
144
|
const i = r.getState().stateComponents.get(e);
|
|
145
145
|
if (!i) return;
|
|
@@ -149,7 +149,7 @@ const gt = (e, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, gt = (e, i) => {
|
|
153
153
|
const m = r.getState().stateComponents.get(e);
|
|
154
154
|
if (m) {
|
|
155
155
|
const g = `${e}////${i}`, T = m.components.get(g);
|
|
@@ -161,18 +161,18 @@ const gt = (e, i) => {
|
|
|
161
161
|
switch (e) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: q(i, g),
|
|
165
|
+
newValue: q(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: q(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: q(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,25 +180,25 @@ const gt = (e, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Ye(e, {
|
|
184
184
|
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: T,
|
|
188
188
|
reactiveDeps: N,
|
|
189
|
-
reactiveType:
|
|
189
|
+
reactiveType: p,
|
|
190
190
|
componentId: v,
|
|
191
191
|
initialState: a,
|
|
192
192
|
syncUpdate: h,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [I] =
|
|
196
|
+
const [H, L] = X({}), { sessionId: R } = ke();
|
|
197
|
+
let F = !i;
|
|
198
|
+
const [I] = X(i ?? pe()), l = r.getState().stateLog[I], le = K(/* @__PURE__ */ new Set()), ee = K(v ?? pe()), P = K(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
P.current = re(I) ?? null, oe(() => {
|
|
202
202
|
if (h && h.stateKey === I && h.path?.[0]) {
|
|
203
203
|
te(I, (o) => ({
|
|
204
204
|
...o,
|
|
@@ -212,25 +212,25 @@ function Ze(e, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [h]), oe(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
Ae(I, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const t =
|
|
219
|
-
if (!(c && !
|
|
218
|
+
const t = P.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
|
|
219
|
+
if (!(c && !z(c, a) || !c) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
const C = s ? Date.now() : 0, $ = u?.lastUpdated || 0,
|
|
226
|
-
s && C > $ ? (
|
|
222
|
+
const E = Q(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
|
|
223
|
+
E && R && (u = me(`${R}-${I}-${E}`));
|
|
224
|
+
let w = a, _ = !1;
|
|
225
|
+
const C = s ? Date.now() : 0, $ = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && C > $ ? (w = t.serverState.data, _ = !0) : u && $ > x && (w = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(w)), r.getState().initializeShadowState(I, a), Me(
|
|
227
227
|
I,
|
|
228
228
|
a,
|
|
229
|
-
|
|
229
|
+
w,
|
|
230
230
|
ae,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
),
|
|
231
|
+
ee.current,
|
|
232
|
+
R
|
|
233
|
+
), _ && E && R && Ce(w, I, t, R, Date.now()), Ie(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || L({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
@@ -238,23 +238,23 @@ function Ze(e, {
|
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), ie(() => {
|
|
241
|
-
|
|
241
|
+
F && Ae(I, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: T,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: P.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const t = `${I}////${
|
|
248
|
+
const t = `${I}////${ee.current}`, o = r.getState().stateComponents.get(I) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return o.components.set(t, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => L({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: N || void 0,
|
|
256
|
-
reactiveType:
|
|
257
|
-
}), r.getState().stateComponents.set(I, o),
|
|
256
|
+
reactiveType: p ?? ["component", "deps"]
|
|
257
|
+
}), r.getState().stateComponents.set(I, o), L({}), () => {
|
|
258
258
|
o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
@@ -265,155 +265,155 @@ function Ze(e, {
|
|
|
265
265
|
}
|
|
266
266
|
const f = r.getState();
|
|
267
267
|
te(I, (u) => {
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
let M = !1, y = f.signalDomElements.get(
|
|
268
|
+
const E = Q(t) ? t(u) : t, w = `${I}-${o.join(".")}`;
|
|
269
|
+
if (w) {
|
|
270
|
+
let M = !1, y = f.signalDomElements.get(w);
|
|
271
271
|
if ((!y || y.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
272
|
+
const V = o.slice(0, -1), b = q(E, V);
|
|
273
|
+
if (Array.isArray(b)) {
|
|
274
274
|
M = !0;
|
|
275
|
-
const
|
|
276
|
-
y = f.signalDomElements.get(
|
|
275
|
+
const A = `${I}-${V.join(".")}`;
|
|
276
|
+
y = f.signalDomElements.get(A);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if (y) {
|
|
280
|
-
const
|
|
281
|
-
y.forEach(({ parentId:
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
280
|
+
const V = M ? q(E, o.slice(0, -1)) : q(E, o);
|
|
281
|
+
y.forEach(({ parentId: b, position: A, effect: D }) => {
|
|
282
|
+
const G = document.querySelector(
|
|
283
|
+
`[data-parent-id="${b}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const B = Array.from(
|
|
287
|
-
if (B[
|
|
288
|
-
const
|
|
289
|
-
B[
|
|
285
|
+
if (G) {
|
|
286
|
+
const B = Array.from(G.childNodes);
|
|
287
|
+
if (B[A]) {
|
|
288
|
+
const O = D ? new Function("state", `return (${D})(state)`)(V) : V;
|
|
289
|
+
B[A].textContent = String(O);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c ||
|
|
296
|
-
(c ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || P.current?.validation?.key) && o && Z(
|
|
296
|
+
(c || P.current?.validation?.key) + "." + o.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([y,
|
|
304
|
-
let
|
|
305
|
-
if (y ==
|
|
306
|
-
let
|
|
307
|
-
|
|
298
|
+
const _ = o.slice(0, o.length - 1);
|
|
299
|
+
s.updateType === "cut" && P.current?.validation?.key && Z(
|
|
300
|
+
P.current?.validation?.key + "." + _.join(".")
|
|
301
|
+
), s.updateType === "insert" && P.current?.validation?.key && Fe(
|
|
302
|
+
P.current?.validation?.key + "." + _.join(".")
|
|
303
|
+
).filter(([y, V]) => {
|
|
304
|
+
let b = y?.split(".").length;
|
|
305
|
+
if (y == _.join(".") && b == _.length - 1) {
|
|
306
|
+
let A = y + "." + _;
|
|
307
|
+
Z(y), We(A, V);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
const C = f.stateComponents.get(I);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", C), C) {
|
|
312
|
-
const M =
|
|
312
|
+
const M = ye(u, E), y = new Set(M), V = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
b,
|
|
315
|
+
A
|
|
316
316
|
] of C.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
317
|
+
let D = !1;
|
|
318
|
+
const G = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", A), !G.includes("none")) {
|
|
320
|
+
if (G.includes("all")) {
|
|
321
|
+
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
324
|
+
if (G.includes("component") && ((A.paths.has(V) || A.paths.has("")) && (D = !0), !D))
|
|
325
325
|
for (const B of y) {
|
|
326
|
-
let
|
|
326
|
+
let O = B;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (A.paths.has(O)) {
|
|
329
|
+
D = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const k = O.lastIndexOf(".");
|
|
333
|
+
if (k !== -1) {
|
|
334
|
+
const U = O.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
k
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(O.substring(k + 1))
|
|
340
|
+
) && A.paths.has(U)) {
|
|
341
|
+
D = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
O = U;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
O = "";
|
|
347
|
+
if (O === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (D) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const B =
|
|
354
|
-
let
|
|
355
|
-
typeof B == "boolean" ? B && (
|
|
352
|
+
if (!D && G.includes("deps") && A.depsFunction) {
|
|
353
|
+
const B = A.depsFunction(E);
|
|
354
|
+
let O = !1;
|
|
355
|
+
typeof B == "boolean" ? B && (O = !0) : z(A.deps, B) || (A.deps = B, O = !0), O && (D = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
D && A.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
const $ = Date.now();
|
|
362
362
|
o = o.map((M, y) => {
|
|
363
|
-
const
|
|
364
|
-
return y === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (
|
|
363
|
+
const V = o.slice(0, -1), b = q(E, V);
|
|
364
|
+
return y === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (b.length - 1).toString() : M;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: x, newValue: j } = Je(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
|
-
|
|
369
|
+
E,
|
|
370
370
|
o
|
|
371
|
-
),
|
|
371
|
+
), J = {
|
|
372
372
|
timeStamp: $,
|
|
373
373
|
stateKey: I,
|
|
374
374
|
path: o,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: x,
|
|
378
|
+
newValue: j
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
f.updateShadowAtPath(I, o,
|
|
382
|
+
f.updateShadowAtPath(I, o, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
const M = o.slice(0, -1);
|
|
386
|
-
f.insertShadowArrayElement(I, M,
|
|
386
|
+
f.insertShadowArrayElement(I, M, j);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const y = o.slice(0, -1),
|
|
390
|
-
f.removeShadowArrayElement(I, y,
|
|
389
|
+
const y = o.slice(0, -1), V = parseInt(o[o.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(I, y, V);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
if (Be(I, (M) => {
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
394
|
+
const V = [...M ?? [], J].reduce((b, A) => {
|
|
395
|
+
const D = `${A.stateKey}:${JSON.stringify(A.path)}`, G = b.get(D);
|
|
396
|
+
return G ? (G.timeStamp = Math.max(G.timeStamp, A.timeStamp), G.newValue = A.newValue, G.oldValue = G.oldValue ?? A.oldValue, G.updateType = A.updateType) : b.set(D, { ...A }), b;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
400
|
-
|
|
398
|
+
return Array.from(V.values());
|
|
399
|
+
}), Ce(
|
|
400
|
+
E,
|
|
401
401
|
I,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
P.current,
|
|
403
|
+
R
|
|
404
|
+
), P.current?.middleware && P.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
407
|
-
}),
|
|
408
|
-
const M = f.serverState[I], y =
|
|
406
|
+
update: J
|
|
407
|
+
}), P.current?.serverSync) {
|
|
408
|
+
const M = f.serverState[I], y = P.current?.serverSync;
|
|
409
409
|
ze(I, {
|
|
410
|
-
syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state:
|
|
410
|
+
syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
412
|
actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
419
|
r.getState().updaterState[I] || (fe(
|
|
@@ -421,37 +421,37 @@ function Ze(e, {
|
|
|
421
421
|
Se(
|
|
422
422
|
I,
|
|
423
423
|
ae,
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
ee.current,
|
|
425
|
+
R
|
|
426
426
|
)
|
|
427
|
-
), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] ||
|
|
428
|
-
const d =
|
|
427
|
+
), r.getState().cogsStateStore[I] || te(I, e), r.getState().initialStateGlobal[I] || Ee(I, e));
|
|
428
|
+
const d = ve(() => Se(
|
|
429
429
|
I,
|
|
430
430
|
ae,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
), [I,
|
|
434
|
-
return [
|
|
431
|
+
ee.current,
|
|
432
|
+
R
|
|
433
|
+
), [I, R]);
|
|
434
|
+
return [be(I), d];
|
|
435
435
|
}
|
|
436
436
|
function Se(e, i, m, g) {
|
|
437
437
|
const T = /* @__PURE__ */ new Map();
|
|
438
438
|
let N = 0;
|
|
439
|
-
const
|
|
439
|
+
const p = (h) => {
|
|
440
440
|
const n = h.join(".");
|
|
441
441
|
for (const [S] of T)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && T.delete(S);
|
|
443
443
|
N++;
|
|
444
444
|
}, v = {
|
|
445
445
|
removeValidation: (h) => {
|
|
446
|
-
h?.validationKey &&
|
|
446
|
+
h?.validationKey && Z(h.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (h) => {
|
|
449
449
|
const n = r.getState().getInitialOptions(e)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Z(n?.key), h?.validationKey && Z(h.validationKey);
|
|
451
451
|
const S = r.getState().initialStateGlobal[e];
|
|
452
452
|
r.getState().clearSelectedIndexesForState(e), T.clear(), N++;
|
|
453
|
-
const
|
|
454
|
-
|
|
453
|
+
const H = a(S, []), L = re(e), R = Q(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, F = `${g}-${e}-${R}`;
|
|
454
|
+
F && localStorage.removeItem(F), fe(e, H), te(e, S);
|
|
455
455
|
const I = r.getState().stateComponents.get(e);
|
|
456
456
|
return I && I.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
@@ -464,15 +464,15 @@ function Se(e, i, m, g) {
|
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = r.getState().initialStateGlobal[e],
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), S = r.getState().initialStateGlobal[e], H = re(e), L = Q(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, R = `${g}-${e}-${L}`;
|
|
468
|
+
return localStorage.getItem(R) && localStorage.removeItem(R), Ve(() => {
|
|
469
|
+
Ee(e, h), r.getState().initializeShadowState(e, h), fe(e, n), te(e, h);
|
|
470
|
+
const F = r.getState().stateComponents.get(e);
|
|
471
|
+
F && F.components.forEach((I) => {
|
|
472
472
|
I.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (F) => n.get()[F]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: r.getState().initialStateGlobal[e],
|
|
@@ -480,19 +480,19 @@ function Se(e, i, m, g) {
|
|
|
480
480
|
_isLoading: r.getState().isLoadingGlobal[e],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const h = r.getState().serverState[e];
|
|
483
|
-
return !!(h &&
|
|
483
|
+
return !!(h && z(h, be(e)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(h, n = [], S) {
|
|
487
|
-
const
|
|
488
|
-
T.get(
|
|
489
|
-
const
|
|
487
|
+
const H = n.map(String).join(".");
|
|
488
|
+
T.get(H);
|
|
489
|
+
const L = function() {
|
|
490
490
|
return r().getNestedState(e, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(v).forEach((I) => {
|
|
493
|
-
|
|
493
|
+
L[I] = v[I];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
495
|
+
const R = {
|
|
496
496
|
apply(I, l, le) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
|
|
@@ -540,7 +540,7 @@ function Se(e, i, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => ye(
|
|
544
544
|
r.getState().cogsStateStore[e],
|
|
545
545
|
r.getState().initialStateGlobal[e]
|
|
546
546
|
);
|
|
@@ -554,8 +554,8 @@ function Se(e, i, m, g) {
|
|
|
554
554
|
const c = await t.action(o);
|
|
555
555
|
if (c && !c.success && c.errors && s) {
|
|
556
556
|
r.getState().removeValidationError(s), c.errors.forEach((u) => {
|
|
557
|
-
const
|
|
558
|
-
r.getState().addValidationError(
|
|
557
|
+
const E = [s, ...u.path].join(".");
|
|
558
|
+
r.getState().addValidationError(E, u.message);
|
|
559
559
|
});
|
|
560
560
|
const f = r.getState().stateComponents.get(e);
|
|
561
561
|
f && f.components.forEach((u) => {
|
|
@@ -568,20 +568,20 @@ function Se(e, i, m, g) {
|
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o =
|
|
572
|
-
return
|
|
571
|
+
const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = q(t, n);
|
|
572
|
+
return z(d, o) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
575
575
|
return function() {
|
|
576
576
|
const d = r().getNestedState(
|
|
577
577
|
e,
|
|
578
578
|
n
|
|
579
|
-
), t = r.getState().initialStateGlobal[e], o =
|
|
580
|
-
return
|
|
579
|
+
), t = r.getState().initialStateGlobal[e], o = q(t, n);
|
|
580
|
+
return z(d, o) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = r.getState().initialStateGlobal[e], t = re(e), o =
|
|
584
|
+
const d = r.getState().initialStateGlobal[e], t = re(e), o = Q(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -622,132 +622,135 @@ function Se(e, i, m, g) {
|
|
|
622
622
|
overscan: s = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = t, u =
|
|
625
|
+
} = t, u = K(null), [E, w] = X({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
628
|
+
}), [_, C] = X("IDLE_AT_TOP"), $ = K(0), x = K(f), [j, J] = X(0);
|
|
629
629
|
oe(() => r.getState().subscribeToShadowState(e, () => {
|
|
630
|
-
|
|
630
|
+
J((k) => k + 1);
|
|
631
631
|
}), [e]);
|
|
632
632
|
const M = r().getNestedState(
|
|
633
633
|
e,
|
|
634
634
|
n
|
|
635
|
-
), y = M.length, { totalHeight:
|
|
636
|
-
const
|
|
637
|
-
let
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
635
|
+
), y = M.length, { totalHeight: V, positions: b } = ve(() => {
|
|
636
|
+
const O = r.getState().getShadowMetadata(e, n) || [];
|
|
637
|
+
let k = 0;
|
|
638
|
+
const U = [];
|
|
639
|
+
for (let W = 0; W < y; W++) {
|
|
640
|
+
U[W] = k;
|
|
641
|
+
const Y = O[W]?.virtualizer?.itemHeight;
|
|
642
|
+
k += Y || o;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: k, positions: U };
|
|
645
645
|
}, [
|
|
646
646
|
y,
|
|
647
647
|
e,
|
|
648
648
|
n.join("."),
|
|
649
649
|
o,
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
650
|
+
j
|
|
651
|
+
]), A = ve(() => {
|
|
652
|
+
const O = Math.max(0, E.startIndex), k = Math.min(y, E.endIndex), U = Array.from(
|
|
653
|
+
{ length: k - O },
|
|
654
|
+
(Y, ne) => O + ne
|
|
655
|
+
), W = U.map((Y) => M[Y]);
|
|
656
|
+
return a(W, n, {
|
|
657
657
|
...S,
|
|
658
|
-
validIndices:
|
|
658
|
+
validIndices: U
|
|
659
659
|
});
|
|
660
|
-
}, [
|
|
660
|
+
}, [E.startIndex, E.endIndex, M, y]);
|
|
661
661
|
ie(() => {
|
|
662
|
-
const
|
|
662
|
+
const O = !z(
|
|
663
663
|
f,
|
|
664
|
-
|
|
665
|
-
),
|
|
666
|
-
if (
|
|
667
|
-
console.log(
|
|
668
|
-
"STATE_TRANSITION: Deps changed. -> WAITING_FOR_ARRAY"
|
|
669
|
-
), C("WAITING_FOR_ARRAY");
|
|
664
|
+
x.current
|
|
665
|
+
), k = y > $.current;
|
|
666
|
+
if (O) {
|
|
667
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), C("IDLE_AT_TOP");
|
|
670
668
|
return;
|
|
671
669
|
}
|
|
672
|
-
|
|
673
|
-
"
|
|
674
|
-
), C("
|
|
670
|
+
k && _ === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
671
|
+
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
672
|
+
), C("GETTING_HEIGHTS")), $.current = y, x.current = f;
|
|
675
673
|
}, [y, ...f]), ie(() => {
|
|
676
|
-
const
|
|
677
|
-
if (!
|
|
678
|
-
let
|
|
679
|
-
if (
|
|
674
|
+
const O = u.current;
|
|
675
|
+
if (!O) return;
|
|
676
|
+
let k;
|
|
677
|
+
if (_ === "IDLE_AT_TOP" && c && y > 0)
|
|
680
678
|
console.log(
|
|
681
|
-
"ACTION:
|
|
682
|
-
), C("
|
|
683
|
-
else if (
|
|
679
|
+
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
680
|
+
), C("GETTING_HEIGHTS");
|
|
681
|
+
else if (_ === "GETTING_HEIGHTS")
|
|
684
682
|
console.log(
|
|
685
|
-
"ACTION:
|
|
686
|
-
),
|
|
683
|
+
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
684
|
+
), w({
|
|
687
685
|
startIndex: Math.max(0, y - 10 - s),
|
|
688
686
|
endIndex: y
|
|
689
|
-
}),
|
|
690
|
-
const
|
|
691
|
-
((r.getState().getShadowMetadata(e, n) || [])[
|
|
692
|
-
"ACTION: Measurement success
|
|
693
|
-
), C("
|
|
687
|
+
}), k = setInterval(() => {
|
|
688
|
+
const U = y - 1;
|
|
689
|
+
((r.getState().getShadowMetadata(e, n) || [])[U]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(k), console.log(
|
|
690
|
+
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
691
|
+
), C("SCROLLING_TO_BOTTOM"));
|
|
694
692
|
}, 100);
|
|
695
|
-
else if (
|
|
696
|
-
console.log(
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
693
|
+
else if (_ === "SCROLLING_TO_BOTTOM") {
|
|
694
|
+
console.log(
|
|
695
|
+
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
696
|
+
);
|
|
697
|
+
const U = $.current === 0 ? "auto" : "smooth";
|
|
698
|
+
O.scrollTo({
|
|
699
|
+
top: O.scrollHeight,
|
|
700
|
+
behavior: U
|
|
701
|
+
});
|
|
702
|
+
const W = setTimeout(
|
|
702
703
|
() => {
|
|
703
704
|
console.log(
|
|
704
|
-
"ACTION: Scroll finished
|
|
705
|
+
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
705
706
|
), C("LOCKED_AT_BOTTOM");
|
|
706
707
|
},
|
|
707
|
-
|
|
708
|
+
U === "smooth" ? 500 : 50
|
|
708
709
|
);
|
|
710
|
+
return () => clearTimeout(W);
|
|
709
711
|
}
|
|
710
712
|
return () => {
|
|
711
|
-
|
|
713
|
+
k && clearInterval(k);
|
|
712
714
|
};
|
|
713
|
-
}, [
|
|
714
|
-
const
|
|
715
|
-
if (!
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
"
|
|
719
|
-
), C("IDLE_NOT_AT_BOTTOM"));
|
|
720
|
-
const { scrollTop:
|
|
721
|
-
let
|
|
722
|
-
for (;
|
|
723
|
-
const
|
|
724
|
-
|
|
715
|
+
}, [_, y, b]), oe(() => {
|
|
716
|
+
const O = u.current;
|
|
717
|
+
if (!O) return;
|
|
718
|
+
const k = () => {
|
|
719
|
+
_ !== "IDLE_NOT_AT_BOTTOM" && (O.scrollHeight - O.scrollTop - O.clientHeight < 1 || (console.log(
|
|
720
|
+
"USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
|
|
721
|
+
), C("IDLE_NOT_AT_BOTTOM")));
|
|
722
|
+
const { scrollTop: U, clientHeight: W } = O;
|
|
723
|
+
let Y = 0, ne = y - 1;
|
|
724
|
+
for (; Y <= ne; ) {
|
|
725
|
+
const ue = Math.floor((Y + ne) / 2);
|
|
726
|
+
b[ue] < U ? Y = ue + 1 : ne = ue - 1;
|
|
725
727
|
}
|
|
726
|
-
const we = Math.max(0,
|
|
727
|
-
let
|
|
728
|
-
const
|
|
729
|
-
for (;
|
|
730
|
-
|
|
731
|
-
|
|
728
|
+
const we = Math.max(0, ne - s);
|
|
729
|
+
let de = we;
|
|
730
|
+
const xe = U + W;
|
|
731
|
+
for (; de < y && b[de] < xe; )
|
|
732
|
+
de++;
|
|
733
|
+
w({
|
|
732
734
|
startIndex: we,
|
|
733
|
-
endIndex: Math.min(y,
|
|
735
|
+
endIndex: Math.min(y, de + s)
|
|
734
736
|
});
|
|
735
737
|
};
|
|
736
|
-
return
|
|
738
|
+
return O.addEventListener("scroll", k, {
|
|
737
739
|
passive: !0
|
|
738
|
-
}), () =>
|
|
739
|
-
}, [y,
|
|
740
|
-
const
|
|
741
|
-
(
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
740
|
+
}), () => O.removeEventListener("scroll", k);
|
|
741
|
+
}, [y, b, _]);
|
|
742
|
+
const D = _e(() => {
|
|
743
|
+
console.log(
|
|
744
|
+
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
745
|
+
), C("SCROLLING_TO_BOTTOM");
|
|
746
|
+
}, []), G = _e(
|
|
747
|
+
(O, k = "smooth") => {
|
|
748
|
+
u.current && b[O] !== void 0 && (C("IDLE_NOT_AT_BOTTOM"), u.current.scrollTo({
|
|
749
|
+
top: b[O],
|
|
750
|
+
behavior: k
|
|
751
|
+
}));
|
|
745
752
|
},
|
|
746
|
-
[]
|
|
747
|
-
), P = Ee(
|
|
748
|
-
(E, b = "smooth") => {
|
|
749
|
-
},
|
|
750
|
-
[R]
|
|
753
|
+
[b]
|
|
751
754
|
), B = {
|
|
752
755
|
outer: {
|
|
753
756
|
ref: u,
|
|
@@ -755,27 +758,27 @@ function Se(e, i, m, g) {
|
|
|
755
758
|
},
|
|
756
759
|
inner: {
|
|
757
760
|
style: {
|
|
758
|
-
height: `${
|
|
761
|
+
height: `${V}px`,
|
|
759
762
|
position: "relative"
|
|
760
763
|
}
|
|
761
764
|
},
|
|
762
765
|
list: {
|
|
763
766
|
style: {
|
|
764
|
-
transform: `translateY(${
|
|
767
|
+
transform: `translateY(${b[E.startIndex] || 0}px)`
|
|
765
768
|
}
|
|
766
769
|
}
|
|
767
770
|
};
|
|
768
771
|
return {
|
|
769
|
-
virtualState:
|
|
772
|
+
virtualState: A,
|
|
770
773
|
virtualizerProps: B,
|
|
771
|
-
scrollToBottom:
|
|
772
|
-
scrollToIndex:
|
|
774
|
+
scrollToBottom: D,
|
|
775
|
+
scrollToIndex: G
|
|
773
776
|
};
|
|
774
777
|
};
|
|
775
778
|
if (l === "stateSort")
|
|
776
779
|
return (t) => {
|
|
777
780
|
const s = [...d()].sort(
|
|
778
|
-
(u,
|
|
781
|
+
(u, E) => t(u.item, E.item)
|
|
779
782
|
), c = s.map(({ item: u }) => u), f = {
|
|
780
783
|
...S,
|
|
781
784
|
validIndices: s.map(
|
|
@@ -787,7 +790,7 @@ function Se(e, i, m, g) {
|
|
|
787
790
|
if (l === "stateFilter")
|
|
788
791
|
return (t) => {
|
|
789
792
|
const s = d().filter(
|
|
790
|
-
({ item: u },
|
|
793
|
+
({ item: u }, E) => t(u, E)
|
|
791
794
|
), c = s.map(({ item: u }) => u), f = {
|
|
792
795
|
...S,
|
|
793
796
|
validIndices: s.map(
|
|
@@ -800,20 +803,20 @@ function Se(e, i, m, g) {
|
|
|
800
803
|
return (t) => {
|
|
801
804
|
const o = r.getState().getNestedState(e, n);
|
|
802
805
|
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
803
|
-
const u = o[c],
|
|
804
|
-
return t(u,
|
|
806
|
+
const u = o[c], E = [...n, c.toString()], w = a(u, E, S);
|
|
807
|
+
return t(u, w, {
|
|
805
808
|
register: () => {
|
|
806
|
-
const [, C] =
|
|
809
|
+
const [, C] = X({}), $ = `${m}-${n.join(".")}-${c}`;
|
|
807
810
|
ie(() => {
|
|
808
|
-
const
|
|
811
|
+
const x = `${e}////${$}`, j = r.getState().stateComponents.get(e) || {
|
|
809
812
|
components: /* @__PURE__ */ new Map()
|
|
810
813
|
};
|
|
811
|
-
return
|
|
814
|
+
return j.components.set(x, {
|
|
812
815
|
forceUpdate: () => C({}),
|
|
813
|
-
paths: /* @__PURE__ */ new Set([
|
|
814
|
-
}), r.getState().stateComponents.set(e,
|
|
815
|
-
const
|
|
816
|
-
|
|
816
|
+
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
817
|
+
}), r.getState().stateComponents.set(e, j), () => {
|
|
818
|
+
const J = r.getState().stateComponents.get(e);
|
|
819
|
+
J && J.components.delete(x);
|
|
817
820
|
};
|
|
818
821
|
}, [e, $]);
|
|
819
822
|
},
|
|
@@ -829,17 +832,17 @@ function Se(e, i, m, g) {
|
|
|
829
832
|
return (t) => h.map((s, c) => {
|
|
830
833
|
let f;
|
|
831
834
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
832
|
-
const u = [...n, f.toString()],
|
|
835
|
+
const u = [...n, f.toString()], E = a(s, u, S);
|
|
833
836
|
return t(
|
|
834
837
|
s,
|
|
835
|
-
|
|
838
|
+
E,
|
|
836
839
|
c,
|
|
837
840
|
h,
|
|
838
841
|
a(h, n, S)
|
|
839
842
|
);
|
|
840
843
|
});
|
|
841
844
|
if (l === "$stateMap")
|
|
842
|
-
return (t) => ce(
|
|
845
|
+
return (t) => ce(Ze, {
|
|
843
846
|
proxy: {
|
|
844
847
|
_stateKey: e,
|
|
845
848
|
_path: n,
|
|
@@ -852,15 +855,15 @@ function Se(e, i, m, g) {
|
|
|
852
855
|
return (t) => {
|
|
853
856
|
const o = r.getState().getNestedState(e, n);
|
|
854
857
|
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
855
|
-
const u = o[c],
|
|
856
|
-
return ce(
|
|
858
|
+
const u = o[c], E = [...n, c.toString()], w = a(u, E, S), _ = `${m}-${n.join(".")}-${c}`;
|
|
859
|
+
return ce(Qe, {
|
|
857
860
|
key: c,
|
|
858
861
|
stateKey: e,
|
|
859
|
-
itemComponentId:
|
|
860
|
-
itemPath:
|
|
862
|
+
itemComponentId: _,
|
|
863
|
+
itemPath: E,
|
|
861
864
|
children: t(
|
|
862
865
|
u,
|
|
863
|
-
|
|
866
|
+
w,
|
|
864
867
|
f,
|
|
865
868
|
o,
|
|
866
869
|
a(o, n, S)
|
|
@@ -896,36 +899,36 @@ function Se(e, i, m, g) {
|
|
|
896
899
|
return a(s, c);
|
|
897
900
|
};
|
|
898
901
|
if (l === "insert")
|
|
899
|
-
return (t) => (
|
|
902
|
+
return (t) => (p(n), he(i, t, n, e), a(
|
|
900
903
|
r.getState().getNestedState(e, n),
|
|
901
904
|
n
|
|
902
905
|
));
|
|
903
906
|
if (l === "uniqueInsert")
|
|
904
907
|
return (t, o, s) => {
|
|
905
|
-
const c = r.getState().getNestedState(e, n), f =
|
|
908
|
+
const c = r.getState().getNestedState(e, n), f = Q(t) ? t(c) : t;
|
|
906
909
|
let u = null;
|
|
907
|
-
if (!c.some((
|
|
910
|
+
if (!c.some((w) => {
|
|
908
911
|
if (o) {
|
|
909
912
|
const C = o.every(
|
|
910
|
-
($) =>
|
|
913
|
+
($) => z(w[$], f[$])
|
|
911
914
|
);
|
|
912
|
-
return C && (u =
|
|
915
|
+
return C && (u = w), C;
|
|
913
916
|
}
|
|
914
|
-
const
|
|
915
|
-
return
|
|
917
|
+
const _ = z(w, f);
|
|
918
|
+
return _ && (u = w), _;
|
|
916
919
|
}))
|
|
917
|
-
|
|
920
|
+
p(n), he(i, f, n, e);
|
|
918
921
|
else if (s && u) {
|
|
919
|
-
const
|
|
920
|
-
(C) =>
|
|
922
|
+
const w = s(u), _ = c.map(
|
|
923
|
+
(C) => z(C, u) ? w : C
|
|
921
924
|
);
|
|
922
|
-
|
|
925
|
+
p(n), se(i, _, n);
|
|
923
926
|
}
|
|
924
927
|
};
|
|
925
928
|
if (l === "cut")
|
|
926
929
|
return (t, o) => {
|
|
927
930
|
if (!o?.waitForSync)
|
|
928
|
-
return
|
|
931
|
+
return p(n), ge(i, n, e, t), a(
|
|
929
932
|
r.getState().getNestedState(e, n),
|
|
930
933
|
n
|
|
931
934
|
);
|
|
@@ -938,7 +941,7 @@ function Se(e, i, m, g) {
|
|
|
938
941
|
if (l === "toggleByValue")
|
|
939
942
|
return (t) => {
|
|
940
943
|
const o = h.findIndex((s) => s === t);
|
|
941
|
-
o > -1 ? ge(i, n, e, o) :
|
|
944
|
+
o > -1 ? ge(i, n, e, o) : he(i, t, n, e);
|
|
942
945
|
};
|
|
943
946
|
if (l === "stateFind")
|
|
944
947
|
return (t) => {
|
|
@@ -959,15 +962,15 @@ function Se(e, i, m, g) {
|
|
|
959
962
|
return a(c.item, f, S);
|
|
960
963
|
};
|
|
961
964
|
}
|
|
962
|
-
const
|
|
963
|
-
if (!isNaN(Number(
|
|
965
|
+
const ee = n[n.length - 1];
|
|
966
|
+
if (!isNaN(Number(ee))) {
|
|
964
967
|
const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
|
|
965
968
|
if (Array.isArray(t) && l === "cut")
|
|
966
969
|
return () => ge(
|
|
967
970
|
i,
|
|
968
971
|
d,
|
|
969
972
|
e,
|
|
970
|
-
Number(
|
|
973
|
+
Number(ee)
|
|
971
974
|
);
|
|
972
975
|
}
|
|
973
976
|
if (l === "get")
|
|
@@ -979,13 +982,13 @@ function Se(e, i, m, g) {
|
|
|
979
982
|
return r.getState().getNestedState(e, n);
|
|
980
983
|
};
|
|
981
984
|
if (l === "$derive")
|
|
982
|
-
return (d) =>
|
|
985
|
+
return (d) => $e({
|
|
983
986
|
_stateKey: e,
|
|
984
987
|
_path: n,
|
|
985
988
|
_effect: d.toString()
|
|
986
989
|
});
|
|
987
990
|
if (l === "$get")
|
|
988
|
-
return () =>
|
|
991
|
+
return () => $e({
|
|
989
992
|
_stateKey: e,
|
|
990
993
|
_path: n
|
|
991
994
|
});
|
|
@@ -1004,7 +1007,7 @@ function Se(e, i, m, g) {
|
|
|
1004
1007
|
const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
|
|
1005
1008
|
d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
|
|
1006
1009
|
const c = r.getState().getNestedState(e, [...t]);
|
|
1007
|
-
se(i, c, t),
|
|
1010
|
+
se(i, c, t), p(t);
|
|
1008
1011
|
};
|
|
1009
1012
|
if (l === "toggleSelected")
|
|
1010
1013
|
return () => {
|
|
@@ -1015,13 +1018,13 @@ function Se(e, i, m, g) {
|
|
|
1015
1018
|
s === t ? void 0 : t
|
|
1016
1019
|
);
|
|
1017
1020
|
const c = r.getState().getNestedState(e, [...d]);
|
|
1018
|
-
se(i, c, d),
|
|
1021
|
+
se(i, c, d), p(d);
|
|
1019
1022
|
};
|
|
1020
1023
|
if (n.length == 0) {
|
|
1021
1024
|
if (l === "applyJsonPatch")
|
|
1022
1025
|
return (d) => {
|
|
1023
|
-
const t = r.getState().cogsStateStore[e], s =
|
|
1024
|
-
|
|
1026
|
+
const t = r.getState().cogsStateStore[e], s = je(t, d).newDocument;
|
|
1027
|
+
Me(
|
|
1025
1028
|
e,
|
|
1026
1029
|
r.getState().initialStateGlobal[e],
|
|
1027
1030
|
s,
|
|
@@ -1031,57 +1034,57 @@ function Se(e, i, m, g) {
|
|
|
1031
1034
|
);
|
|
1032
1035
|
const c = r.getState().stateComponents.get(e);
|
|
1033
1036
|
if (c) {
|
|
1034
|
-
const f =
|
|
1037
|
+
const f = ye(t, s), u = new Set(f);
|
|
1035
1038
|
for (const [
|
|
1036
|
-
|
|
1037
|
-
|
|
1039
|
+
E,
|
|
1040
|
+
w
|
|
1038
1041
|
] of c.components.entries()) {
|
|
1039
|
-
let
|
|
1040
|
-
const C = Array.isArray(
|
|
1042
|
+
let _ = !1;
|
|
1043
|
+
const C = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
1041
1044
|
if (!C.includes("none")) {
|
|
1042
1045
|
if (C.includes("all")) {
|
|
1043
|
-
|
|
1046
|
+
w.forceUpdate();
|
|
1044
1047
|
continue;
|
|
1045
1048
|
}
|
|
1046
|
-
if (C.includes("component") && (
|
|
1049
|
+
if (C.includes("component") && (w.paths.has("") && (_ = !0), !_))
|
|
1047
1050
|
for (const $ of u) {
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
1051
|
+
if (w.paths.has($)) {
|
|
1052
|
+
_ = !0;
|
|
1050
1053
|
break;
|
|
1051
1054
|
}
|
|
1052
|
-
let
|
|
1053
|
-
for (;
|
|
1054
|
-
const
|
|
1055
|
-
if (
|
|
1056
|
-
|
|
1055
|
+
let x = $.lastIndexOf(".");
|
|
1056
|
+
for (; x !== -1; ) {
|
|
1057
|
+
const j = $.substring(0, x);
|
|
1058
|
+
if (w.paths.has(j)) {
|
|
1059
|
+
_ = !0;
|
|
1057
1060
|
break;
|
|
1058
1061
|
}
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1062
|
+
const J = $.substring(
|
|
1063
|
+
x + 1
|
|
1061
1064
|
);
|
|
1062
|
-
if (!isNaN(Number(
|
|
1063
|
-
const M =
|
|
1065
|
+
if (!isNaN(Number(J))) {
|
|
1066
|
+
const M = j.lastIndexOf(".");
|
|
1064
1067
|
if (M !== -1) {
|
|
1065
|
-
const y =
|
|
1068
|
+
const y = j.substring(
|
|
1066
1069
|
0,
|
|
1067
1070
|
M
|
|
1068
1071
|
);
|
|
1069
|
-
if (
|
|
1070
|
-
|
|
1072
|
+
if (w.paths.has(y)) {
|
|
1073
|
+
_ = !0;
|
|
1071
1074
|
break;
|
|
1072
1075
|
}
|
|
1073
1076
|
}
|
|
1074
1077
|
}
|
|
1075
|
-
|
|
1078
|
+
x = j.lastIndexOf(".");
|
|
1076
1079
|
}
|
|
1077
|
-
if (
|
|
1080
|
+
if (_) break;
|
|
1078
1081
|
}
|
|
1079
|
-
if (!
|
|
1080
|
-
const $ =
|
|
1081
|
-
let
|
|
1082
|
-
typeof $ == "boolean" ? $ && (
|
|
1082
|
+
if (!_ && C.includes("deps") && w.depsFunction) {
|
|
1083
|
+
const $ = w.depsFunction(s);
|
|
1084
|
+
let x = !1;
|
|
1085
|
+
typeof $ == "boolean" ? $ && (x = !0) : z(w.deps, $) || (w.deps = $, x = !0), x && (_ = !0);
|
|
1083
1086
|
}
|
|
1084
|
-
|
|
1087
|
+
_ && w.forceUpdate();
|
|
1085
1088
|
}
|
|
1086
1089
|
}
|
|
1087
1090
|
}
|
|
@@ -1093,17 +1096,17 @@ function Se(e, i, m, g) {
|
|
|
1093
1096
|
throw new Error("Zod schema not found");
|
|
1094
1097
|
if (!d?.key)
|
|
1095
1098
|
throw new Error("Validation key not found");
|
|
1096
|
-
|
|
1099
|
+
Z(d.key);
|
|
1097
1100
|
const o = r.getState().cogsStateStore[e];
|
|
1098
1101
|
try {
|
|
1099
1102
|
const s = r.getState().getValidationErrors(d.key);
|
|
1100
1103
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1101
|
-
f && f.startsWith(d.key) &&
|
|
1104
|
+
f && f.startsWith(d.key) && Z(f);
|
|
1102
1105
|
});
|
|
1103
1106
|
const c = d.zodSchema.safeParse(o);
|
|
1104
1107
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1105
|
-
const
|
|
1106
|
-
t(
|
|
1108
|
+
const E = u.path, w = u.message, _ = [d.key, ...E].join(".");
|
|
1109
|
+
t(_, w);
|
|
1107
1110
|
}), Ie(e), !1);
|
|
1108
1111
|
} catch (s) {
|
|
1109
1112
|
return console.error("Zod schema validation failed", s), !1;
|
|
@@ -1131,8 +1134,8 @@ function Se(e, i, m, g) {
|
|
|
1131
1134
|
return ({
|
|
1132
1135
|
children: d,
|
|
1133
1136
|
hideMessage: t
|
|
1134
|
-
}) => /* @__PURE__ */
|
|
1135
|
-
|
|
1137
|
+
}) => /* @__PURE__ */ Te(
|
|
1138
|
+
Re,
|
|
1136
1139
|
{
|
|
1137
1140
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1138
1141
|
path: n,
|
|
@@ -1148,7 +1151,7 @@ function Se(e, i, m, g) {
|
|
|
1148
1151
|
if (l === "update")
|
|
1149
1152
|
return (d, t) => {
|
|
1150
1153
|
if (t?.debounce)
|
|
1151
|
-
|
|
1154
|
+
Le(() => {
|
|
1152
1155
|
se(i, d, n, "");
|
|
1153
1156
|
const o = r.getState().getNestedState(e, n);
|
|
1154
1157
|
t?.afterUpdate && t.afterUpdate(o);
|
|
@@ -1158,11 +1161,11 @@ function Se(e, i, m, g) {
|
|
|
1158
1161
|
const o = r.getState().getNestedState(e, n);
|
|
1159
1162
|
t?.afterUpdate && t.afterUpdate(o);
|
|
1160
1163
|
}
|
|
1161
|
-
|
|
1164
|
+
p(n);
|
|
1162
1165
|
};
|
|
1163
1166
|
if (l === "formElement")
|
|
1164
|
-
return (d, t) => /* @__PURE__ */
|
|
1165
|
-
|
|
1167
|
+
return (d, t) => /* @__PURE__ */ Te(
|
|
1168
|
+
De,
|
|
1166
1169
|
{
|
|
1167
1170
|
setState: i,
|
|
1168
1171
|
stateKey: e,
|
|
@@ -1171,23 +1174,23 @@ function Se(e, i, m, g) {
|
|
|
1171
1174
|
formOpts: t
|
|
1172
1175
|
}
|
|
1173
1176
|
);
|
|
1174
|
-
const
|
|
1175
|
-
return a(ae,
|
|
1177
|
+
const P = [...n, l], ae = r.getState().getNestedState(e, P);
|
|
1178
|
+
return a(ae, P, S);
|
|
1176
1179
|
}
|
|
1177
|
-
},
|
|
1178
|
-
return T.set(
|
|
1179
|
-
proxy:
|
|
1180
|
+
}, F = new Proxy(L, R);
|
|
1181
|
+
return T.set(H, {
|
|
1182
|
+
proxy: F,
|
|
1180
1183
|
stateVersion: N
|
|
1181
|
-
}),
|
|
1184
|
+
}), F;
|
|
1182
1185
|
}
|
|
1183
1186
|
return a(
|
|
1184
1187
|
r.getState().getNestedState(e, [])
|
|
1185
1188
|
);
|
|
1186
1189
|
}
|
|
1187
|
-
function
|
|
1188
|
-
return ce(
|
|
1190
|
+
function $e(e) {
|
|
1191
|
+
return ce(Xe, { proxy: e });
|
|
1189
1192
|
}
|
|
1190
|
-
function
|
|
1193
|
+
function Ze({
|
|
1191
1194
|
proxy: e,
|
|
1192
1195
|
rebuildStateShape: i
|
|
1193
1196
|
}) {
|
|
@@ -1196,23 +1199,23 @@ function Xe({
|
|
|
1196
1199
|
m,
|
|
1197
1200
|
e._path
|
|
1198
1201
|
).stateMapNoRender(
|
|
1199
|
-
(T, N,
|
|
1202
|
+
(T, N, p, v, a) => e._mapFn(T, N, p, v, a)
|
|
1200
1203
|
) : null;
|
|
1201
1204
|
}
|
|
1202
|
-
function
|
|
1205
|
+
function Xe({
|
|
1203
1206
|
proxy: e
|
|
1204
1207
|
}) {
|
|
1205
|
-
const i =
|
|
1208
|
+
const i = K(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1206
1209
|
return oe(() => {
|
|
1207
1210
|
const g = i.current;
|
|
1208
1211
|
if (!g || !g.parentElement) return;
|
|
1209
|
-
const T = g.parentElement,
|
|
1212
|
+
const T = g.parentElement, p = Array.from(T.childNodes).indexOf(g);
|
|
1210
1213
|
let v = T.getAttribute("data-parent-id");
|
|
1211
1214
|
v || (v = `parent-${crypto.randomUUID()}`, T.setAttribute("data-parent-id", v));
|
|
1212
1215
|
const h = {
|
|
1213
1216
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1214
1217
|
parentId: v,
|
|
1215
|
-
position:
|
|
1218
|
+
position: p,
|
|
1216
1219
|
effect: e._effect
|
|
1217
1220
|
};
|
|
1218
1221
|
r.getState().addSignalElement(m, h);
|
|
@@ -1224,22 +1227,22 @@ function Qe({
|
|
|
1224
1227
|
"state",
|
|
1225
1228
|
`return (${e._effect})(state)`
|
|
1226
1229
|
)(n);
|
|
1227
|
-
} catch (
|
|
1228
|
-
console.error("Error evaluating effect function during mount:",
|
|
1230
|
+
} catch (L) {
|
|
1231
|
+
console.error("Error evaluating effect function during mount:", L), S = n;
|
|
1229
1232
|
}
|
|
1230
1233
|
else
|
|
1231
1234
|
S = n;
|
|
1232
1235
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1233
|
-
const
|
|
1234
|
-
g.replaceWith(
|
|
1236
|
+
const H = document.createTextNode(String(S));
|
|
1237
|
+
g.replaceWith(H);
|
|
1235
1238
|
}, [e._stateKey, e._path.join("."), e._effect]), ce("span", {
|
|
1236
1239
|
ref: i,
|
|
1237
1240
|
style: { display: "none" },
|
|
1238
1241
|
"data-signal-id": m
|
|
1239
1242
|
});
|
|
1240
1243
|
}
|
|
1241
|
-
function
|
|
1242
|
-
const i =
|
|
1244
|
+
function ft(e) {
|
|
1245
|
+
const i = Pe(
|
|
1243
1246
|
(m) => {
|
|
1244
1247
|
const g = r.getState().stateComponents.get(e._stateKey) || {
|
|
1245
1248
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1253,20 +1256,20 @@ function St(e) {
|
|
|
1253
1256
|
);
|
|
1254
1257
|
return ce("text", {}, String(i));
|
|
1255
1258
|
}
|
|
1256
|
-
function
|
|
1259
|
+
function Qe({
|
|
1257
1260
|
stateKey: e,
|
|
1258
1261
|
itemComponentId: i,
|
|
1259
1262
|
itemPath: m,
|
|
1260
1263
|
children: g
|
|
1261
1264
|
}) {
|
|
1262
|
-
const [, T] =
|
|
1265
|
+
const [, T] = X({}), [N, p] = He(), v = K(null);
|
|
1263
1266
|
return oe(() => {
|
|
1264
|
-
|
|
1267
|
+
p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
|
|
1265
1268
|
virtualizer: {
|
|
1266
|
-
itemHeight:
|
|
1269
|
+
itemHeight: p.height
|
|
1267
1270
|
}
|
|
1268
1271
|
}));
|
|
1269
|
-
}, [
|
|
1272
|
+
}, [p.height, e, m]), ie(() => {
|
|
1270
1273
|
const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
|
|
1271
1274
|
components: /* @__PURE__ */ new Map()
|
|
1272
1275
|
};
|
|
@@ -1277,14 +1280,14 @@ function Ke({
|
|
|
1277
1280
|
const n = r.getState().stateComponents.get(e);
|
|
1278
1281
|
n && n.components.delete(a);
|
|
1279
1282
|
};
|
|
1280
|
-
}, [e, i, m.join(".")]), /* @__PURE__ */
|
|
1283
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ Te("div", { ref: N, children: g });
|
|
1281
1284
|
}
|
|
1282
1285
|
export {
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1286
|
+
$e as $cogsSignal,
|
|
1287
|
+
ft as $cogsSignalStore,
|
|
1288
|
+
dt as addStateOptions,
|
|
1289
|
+
ut as createCogsState,
|
|
1290
|
+
gt as notifyComponent,
|
|
1291
|
+
Ye as useCogsStateFn
|
|
1289
1292
|
};
|
|
1290
1293
|
//# sourceMappingURL=CogsState.jsx.map
|