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