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