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