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