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