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