cogsbox-state 0.5.389 → 0.5.391
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 +500 -490
- package/dist/CogsState.jsx.map +1 -1
- package/dist/utility.js +1 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +28 -0
- package/src/utility.ts +1 -1
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,96 +180,96 @@ 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
|
-
L.current =
|
|
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
225
|
const C = a ? Date.now() : 0, A = u?.lastUpdated || 0, b = u?.lastSyncedWithServer || 0;
|
|
226
|
-
a && C > A ? (y =
|
|
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
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
270
|
let M = !1, $ = f.signalDomElements.get(y);
|
|
271
271
|
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
|
-
const R =
|
|
272
|
+
const R = n.slice(0, -1), V = Z(E, R);
|
|
273
273
|
if (Array.isArray(V)) {
|
|
274
274
|
M = !0;
|
|
275
275
|
const O = `${h}-${R.join(".")}`;
|
|
@@ -277,7 +277,7 @@ function nt(e, {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
if ($) {
|
|
280
|
-
const R = M ? Z(E,
|
|
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}"]`
|
|
@@ -292,24 +292,24 @@ function nt(e, {
|
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), a.updateType === "update" && (c || L.current?.validation?.key) &&
|
|
296
|
-
(c || L.current?.validation?.key) + "." +
|
|
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" && L.current?.validation?.key &&
|
|
298
|
+
const w = n.slice(0, n.length - 1);
|
|
299
|
+
a.updateType === "cut" && L.current?.validation?.key && X(
|
|
300
300
|
L.current?.validation?.key + "." + w.join(".")
|
|
301
|
-
), a.updateType === "insert" && L.current?.validation?.key &&
|
|
301
|
+
), a.updateType === "insert" && L.current?.validation?.key && Xt(
|
|
302
302
|
L.current?.validation?.key + "." + w.join(".")
|
|
303
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 M =
|
|
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
|
|
@@ -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,19 +359,19 @@ function nt(e, {
|
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
const A = Date.now();
|
|
362
|
-
|
|
363
|
-
const R =
|
|
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: b, newValue: F } =
|
|
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
377
|
oldValue: b,
|
|
@@ -379,34 +379,34 @@ function nt(e, {
|
|
|
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 M =
|
|
385
|
+
const M = n.slice(0, -1);
|
|
386
386
|
f.insertShadowArrayElement(h, M, F);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const $ =
|
|
389
|
+
const $ = n.slice(0, -1), R = parseInt(n[n.length - 1]);
|
|
390
390
|
f.removeShadowArrayElement(h, $, R);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
393
|
+
if (Qt(h, (M) => {
|
|
394
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
398
|
return Array.from(R.values());
|
|
399
|
-
}),
|
|
399
|
+
}), Pt(
|
|
400
400
|
E,
|
|
401
401
|
h,
|
|
402
402
|
L.current,
|
|
403
|
-
|
|
403
|
+
U
|
|
404
404
|
), L.current?.middleware && L.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Y
|
|
407
407
|
}), L.current?.serverSync) {
|
|
408
408
|
const M = f.serverState[h], $ = L.current?.serverSync;
|
|
409
|
-
|
|
409
|
+
Kt(h, {
|
|
410
410
|
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: E }),
|
|
411
411
|
rollBackState: M,
|
|
412
412
|
actionTimeStamp: Date.now() + ($.debounce ?? 3e3),
|
|
@@ -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,142 +523,142 @@ 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
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
|
-
|
|
629
|
+
ot(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
630
|
R((x) => x + 1);
|
|
631
|
-
}), [
|
|
631
|
+
}), [t]);
|
|
632
632
|
const O = o().getNestedState(
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
), _ = O.length, { totalHeight: D, positions: G } =
|
|
636
|
-
const k = o.getState().getShadowMetadata(
|
|
633
|
+
t,
|
|
634
|
+
r
|
|
635
|
+
), _ = O.length, { totalHeight: D, positions: G } = wt(() => {
|
|
636
|
+
const k = o.getState().getShadowMetadata(t, r) || [];
|
|
637
637
|
let x = 0;
|
|
638
638
|
const H = [];
|
|
639
639
|
for (let P = 0; P < _; P++) {
|
|
640
640
|
H[P] = x;
|
|
641
|
-
const
|
|
642
|
-
x +=
|
|
641
|
+
const Q = k[P]?.virtualizer?.itemHeight;
|
|
642
|
+
x += Q || n;
|
|
643
643
|
}
|
|
644
644
|
return { totalHeight: x, positions: H };
|
|
645
645
|
}, [
|
|
646
646
|
_,
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
647
|
+
t,
|
|
648
|
+
r.join("."),
|
|
649
|
+
n,
|
|
650
650
|
$
|
|
651
|
-
]), B =
|
|
651
|
+
]), B = wt(() => {
|
|
652
652
|
const k = Math.max(0, y.startIndex), x = Math.min(_, y.endIndex), H = Array.from(
|
|
653
653
|
{ length: x - k },
|
|
654
|
-
(
|
|
655
|
-
), P = H.map((
|
|
656
|
-
return s(P,
|
|
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
|
-
|
|
661
|
+
ct(() => {
|
|
662
662
|
const k = E.current;
|
|
663
663
|
if (!k) return;
|
|
664
664
|
const x = _ > F.current;
|
|
@@ -682,7 +682,7 @@ function Te(e, i, m, g) {
|
|
|
682
682
|
), A("GETTING_HEIGHTS"));
|
|
683
683
|
}
|
|
684
684
|
F.current = _, Y.current = f;
|
|
685
|
-
}, [_, ...f]),
|
|
685
|
+
}, [_, ...f]), ct(() => {
|
|
686
686
|
const k = E.current;
|
|
687
687
|
if (!k) return;
|
|
688
688
|
let x;
|
|
@@ -698,7 +698,7 @@ function Te(e, i, m, g) {
|
|
|
698
698
|
endIndex: _
|
|
699
699
|
}), x = setInterval(() => {
|
|
700
700
|
const H = _ - 1;
|
|
701
|
-
((o.getState().getShadowMetadata(
|
|
701
|
+
((o.getState().getShadowMetadata(t, r) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(x), u.current || (console.log(
|
|
702
702
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
703
703
|
), A("SCROLLING_TO_BOTTOM")));
|
|
704
704
|
}, 100);
|
|
@@ -724,45 +724,45 @@ function Te(e, i, m, g) {
|
|
|
724
724
|
return () => {
|
|
725
725
|
x && clearInterval(x);
|
|
726
726
|
};
|
|
727
|
-
}, [C, _, G]),
|
|
727
|
+
}, [C, _, G]), ot(() => {
|
|
728
728
|
const k = E.current;
|
|
729
729
|
if (!k) return;
|
|
730
|
-
const x =
|
|
730
|
+
const x = n, H = () => {
|
|
731
731
|
if (b.current)
|
|
732
732
|
return;
|
|
733
|
-
const { scrollTop: P, scrollHeight:
|
|
734
|
-
if (
|
|
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
735
|
top: P,
|
|
736
|
-
height:
|
|
736
|
+
height: Q
|
|
737
737
|
}), Math.abs(P - M.current) < x)
|
|
738
738
|
return;
|
|
739
739
|
console.log(
|
|
740
740
|
`Threshold passed at ${P}px. Recalculating range...`
|
|
741
741
|
);
|
|
742
|
-
let
|
|
743
|
-
for (;
|
|
744
|
-
const
|
|
745
|
-
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;
|
|
746
746
|
}
|
|
747
|
-
const $
|
|
748
|
-
let
|
|
749
|
-
const
|
|
750
|
-
for (;
|
|
751
|
-
|
|
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++;
|
|
752
752
|
w({
|
|
753
|
-
startIndex: $
|
|
754
|
-
endIndex: Math.min(_,
|
|
753
|
+
startIndex: $t,
|
|
754
|
+
endIndex: Math.min(_, St + a)
|
|
755
755
|
}), M.current = P;
|
|
756
756
|
};
|
|
757
757
|
return k.addEventListener("scroll", H, {
|
|
758
758
|
passive: !0
|
|
759
759
|
}), () => k.removeEventListener("scroll", H);
|
|
760
|
-
}, [_, G,
|
|
761
|
-
const
|
|
760
|
+
}, [_, G, n, a, C]);
|
|
761
|
+
const st = kt(() => {
|
|
762
762
|
console.log(
|
|
763
763
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
764
764
|
), A("SCROLLING_TO_BOTTOM");
|
|
765
|
-
}, []),
|
|
765
|
+
}, []), gt = kt(
|
|
766
766
|
(k, x = "smooth") => {
|
|
767
767
|
E.current && G[k] !== void 0 && (A("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
768
768
|
top: G[k],
|
|
@@ -770,7 +770,7 @@ function Te(e, i, m, g) {
|
|
|
770
770
|
}));
|
|
771
771
|
},
|
|
772
772
|
[G]
|
|
773
|
-
),
|
|
773
|
+
), jt = {
|
|
774
774
|
outer: {
|
|
775
775
|
ref: E,
|
|
776
776
|
style: { overflowY: "auto", height: "100%" }
|
|
@@ -789,146 +789,146 @@ function Te(e, i, m, g) {
|
|
|
789
789
|
};
|
|
790
790
|
return {
|
|
791
791
|
virtualState: B,
|
|
792
|
-
virtualizerProps:
|
|
793
|
-
scrollToBottom:
|
|
794
|
-
scrollToIndex:
|
|
792
|
+
virtualizerProps: jt,
|
|
793
|
+
scrollToBottom: st,
|
|
794
|
+
scrollToIndex: gt
|
|
795
795
|
};
|
|
796
796
|
};
|
|
797
797
|
if (l === "stateSort")
|
|
798
|
-
return (
|
|
798
|
+
return (e) => {
|
|
799
799
|
const a = [...d()].sort(
|
|
800
|
-
(u, E) =>
|
|
800
|
+
(u, E) => e(u.item, E.item)
|
|
801
801
|
), c = a.map(({ item: u }) => u), f = {
|
|
802
802
|
...S,
|
|
803
803
|
validIndices: a.map(
|
|
804
804
|
({ originalIndex: u }) => u
|
|
805
805
|
)
|
|
806
806
|
};
|
|
807
|
-
return s(c,
|
|
807
|
+
return s(c, r, f);
|
|
808
808
|
};
|
|
809
809
|
if (l === "stateFilter")
|
|
810
|
-
return (
|
|
810
|
+
return (e) => {
|
|
811
811
|
const a = d().filter(
|
|
812
|
-
({ item: u }, E) =>
|
|
812
|
+
({ item: u }, E) => e(u, E)
|
|
813
813
|
), c = a.map(({ item: u }) => u), f = {
|
|
814
814
|
...S,
|
|
815
815
|
validIndices: a.map(
|
|
816
816
|
({ originalIndex: u }) => u
|
|
817
817
|
)
|
|
818
818
|
};
|
|
819
|
-
return s(c,
|
|
819
|
+
return s(c, r, f);
|
|
820
820
|
};
|
|
821
821
|
if (l === "stateMap")
|
|
822
|
-
return (
|
|
823
|
-
const
|
|
824
|
-
return Array.isArray(
|
|
825
|
-
const u =
|
|
826
|
-
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, {
|
|
827
827
|
register: () => {
|
|
828
|
-
const [, C] = K({}), A = `${m}-${
|
|
829
|
-
|
|
830
|
-
const b = `${
|
|
828
|
+
const [, C] = K({}), A = `${m}-${r.join(".")}-${c}`;
|
|
829
|
+
ct(() => {
|
|
830
|
+
const b = `${t}////${A}`, F = o.getState().stateComponents.get(t) || {
|
|
831
831
|
components: /* @__PURE__ */ new Map()
|
|
832
832
|
};
|
|
833
833
|
return F.components.set(b, {
|
|
834
834
|
forceUpdate: () => C({}),
|
|
835
835
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
836
|
-
}), o.getState().stateComponents.set(
|
|
837
|
-
const Y = o.getState().stateComponents.get(
|
|
836
|
+
}), o.getState().stateComponents.set(t, F), () => {
|
|
837
|
+
const Y = o.getState().stateComponents.get(t);
|
|
838
838
|
Y && Y.components.delete(b);
|
|
839
839
|
};
|
|
840
|
-
}, [
|
|
840
|
+
}, [t, A]);
|
|
841
841
|
},
|
|
842
842
|
index: f,
|
|
843
843
|
originalIndex: c
|
|
844
844
|
});
|
|
845
845
|
}) : (console.warn(
|
|
846
|
-
`stateMap called on a non-array value at path: ${
|
|
847
|
-
|
|
846
|
+
`stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
|
|
847
|
+
n
|
|
848
848
|
), null);
|
|
849
849
|
};
|
|
850
850
|
if (l === "stateMapNoRender")
|
|
851
|
-
return (
|
|
851
|
+
return (e) => I.map((a, c) => {
|
|
852
852
|
let f;
|
|
853
853
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
854
|
-
const u = [...
|
|
855
|
-
return
|
|
854
|
+
const u = [...r, f.toString()], E = s(a, u, S);
|
|
855
|
+
return e(
|
|
856
856
|
a,
|
|
857
857
|
E,
|
|
858
858
|
c,
|
|
859
|
-
|
|
860
|
-
s(
|
|
859
|
+
I,
|
|
860
|
+
s(I, r, S)
|
|
861
861
|
);
|
|
862
862
|
});
|
|
863
863
|
if (l === "$stateMap")
|
|
864
|
-
return (
|
|
864
|
+
return (e) => lt(re, {
|
|
865
865
|
proxy: {
|
|
866
|
-
_stateKey:
|
|
867
|
-
_path:
|
|
868
|
-
_mapFn:
|
|
866
|
+
_stateKey: t,
|
|
867
|
+
_path: r,
|
|
868
|
+
_mapFn: e
|
|
869
869
|
// Pass the actual function, not string
|
|
870
870
|
},
|
|
871
871
|
rebuildStateShape: s
|
|
872
872
|
});
|
|
873
873
|
if (l === "stateList")
|
|
874
|
-
return (
|
|
875
|
-
const
|
|
876
|
-
return Array.isArray(
|
|
877
|
-
const u =
|
|
878
|
-
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, {
|
|
879
879
|
key: c,
|
|
880
|
-
stateKey:
|
|
880
|
+
stateKey: t,
|
|
881
881
|
itemComponentId: w,
|
|
882
882
|
itemPath: E,
|
|
883
|
-
children:
|
|
883
|
+
children: e(
|
|
884
884
|
u,
|
|
885
885
|
y,
|
|
886
886
|
f,
|
|
887
|
-
|
|
888
|
-
s(
|
|
887
|
+
n,
|
|
888
|
+
s(n, r, S)
|
|
889
889
|
)
|
|
890
890
|
});
|
|
891
891
|
}) : (console.warn(
|
|
892
|
-
`stateList called on a non-array value at path: ${
|
|
892
|
+
`stateList called on a non-array value at path: ${r.join(".")}.`
|
|
893
893
|
), null);
|
|
894
894
|
};
|
|
895
895
|
if (l === "stateFlattenOn")
|
|
896
|
-
return (
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
const a =
|
|
900
|
-
(c) => c[
|
|
896
|
+
return (e) => {
|
|
897
|
+
const n = I;
|
|
898
|
+
T.clear(), N++;
|
|
899
|
+
const a = n.flatMap(
|
|
900
|
+
(c) => c[e] ?? []
|
|
901
901
|
);
|
|
902
902
|
return s(
|
|
903
903
|
a,
|
|
904
|
-
[...
|
|
904
|
+
[...r, "[*]", e],
|
|
905
905
|
S
|
|
906
906
|
);
|
|
907
907
|
};
|
|
908
908
|
if (l === "index")
|
|
909
|
-
return (
|
|
910
|
-
const
|
|
911
|
-
return s(
|
|
909
|
+
return (e) => {
|
|
910
|
+
const n = I[e];
|
|
911
|
+
return s(n, [...r, e.toString()]);
|
|
912
912
|
};
|
|
913
913
|
if (l === "last")
|
|
914
914
|
return () => {
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
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()];
|
|
918
918
|
return s(a, c);
|
|
919
919
|
};
|
|
920
920
|
if (l === "insert")
|
|
921
|
-
return (
|
|
922
|
-
o.getState().getNestedState(
|
|
923
|
-
|
|
921
|
+
return (e) => (p(r), Et(i, e, r, t), s(
|
|
922
|
+
o.getState().getNestedState(t, r),
|
|
923
|
+
r
|
|
924
924
|
));
|
|
925
925
|
if (l === "uniqueInsert")
|
|
926
|
-
return (
|
|
927
|
-
const c = o.getState().getNestedState(
|
|
926
|
+
return (e, n, a) => {
|
|
927
|
+
const c = o.getState().getNestedState(t, r), f = tt(e) ? e(c) : e;
|
|
928
928
|
let u = null;
|
|
929
929
|
if (!c.some((y) => {
|
|
930
|
-
if (
|
|
931
|
-
const C =
|
|
930
|
+
if (n) {
|
|
931
|
+
const C = n.every(
|
|
932
932
|
(A) => J(y[A], f[A])
|
|
933
933
|
);
|
|
934
934
|
return C && (u = y), C;
|
|
@@ -936,124 +936,134 @@ function Te(e, i, m, g) {
|
|
|
936
936
|
const w = J(y, f);
|
|
937
937
|
return w && (u = y), w;
|
|
938
938
|
}))
|
|
939
|
-
p(
|
|
939
|
+
p(r), Et(i, f, r, t);
|
|
940
940
|
else if (a && u) {
|
|
941
941
|
const y = a(u), w = c.map(
|
|
942
942
|
(C) => J(C, u) ? y : C
|
|
943
943
|
);
|
|
944
|
-
p(
|
|
944
|
+
p(r), it(i, w, r);
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
947
|
if (l === "cut")
|
|
948
|
-
return (
|
|
949
|
-
if (!
|
|
950
|
-
return p(
|
|
951
|
-
o.getState().getNestedState(
|
|
952
|
-
|
|
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
|
|
953
953
|
);
|
|
954
954
|
};
|
|
955
955
|
if (l === "cutByValue")
|
|
956
|
-
return (
|
|
957
|
-
for (let
|
|
958
|
-
|
|
956
|
+
return (e) => {
|
|
957
|
+
for (let n = 0; n < I.length; n++)
|
|
958
|
+
I[n] === e && ht(i, r, t, n);
|
|
959
959
|
};
|
|
960
960
|
if (l === "toggleByValue")
|
|
961
|
-
return (
|
|
962
|
-
const
|
|
963
|
-
|
|
961
|
+
return (e) => {
|
|
962
|
+
const n = I.findIndex((a) => a === e);
|
|
963
|
+
n > -1 ? ht(i, r, t, n) : Et(i, e, r, t);
|
|
964
964
|
};
|
|
965
965
|
if (l === "stateFind")
|
|
966
|
-
return (
|
|
966
|
+
return (e) => {
|
|
967
967
|
const a = d().find(
|
|
968
|
-
({ item: f }, u) =>
|
|
968
|
+
({ item: f }, u) => e(f, u)
|
|
969
969
|
);
|
|
970
970
|
if (!a) return;
|
|
971
|
-
const c = [...
|
|
971
|
+
const c = [...r, a.originalIndex.toString()];
|
|
972
972
|
return s(a.item, c, S);
|
|
973
973
|
};
|
|
974
974
|
if (l === "findWith")
|
|
975
|
-
return (
|
|
975
|
+
return (e, n) => {
|
|
976
976
|
const c = d().find(
|
|
977
|
-
({ item: u }) => u[
|
|
977
|
+
({ item: u }) => u[e] === n
|
|
978
978
|
);
|
|
979
979
|
if (!c) return;
|
|
980
|
-
const f = [...
|
|
980
|
+
const f = [...r, c.originalIndex.toString()];
|
|
981
981
|
return s(c.item, f, S);
|
|
982
982
|
};
|
|
983
983
|
}
|
|
984
|
-
const
|
|
985
|
-
if (!isNaN(Number(
|
|
986
|
-
const d =
|
|
987
|
-
if (Array.isArray(
|
|
988
|
-
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(
|
|
989
989
|
i,
|
|
990
990
|
d,
|
|
991
|
-
|
|
992
|
-
Number(
|
|
991
|
+
t,
|
|
992
|
+
Number(et)
|
|
993
993
|
);
|
|
994
994
|
}
|
|
995
995
|
if (l === "get")
|
|
996
996
|
return () => {
|
|
997
|
-
if (S?.validIndices && Array.isArray(
|
|
998
|
-
const d = o.getState().getNestedState(
|
|
999
|
-
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]);
|
|
1000
1000
|
}
|
|
1001
|
-
return o.getState().getNestedState(
|
|
1001
|
+
return o.getState().getNestedState(t, r);
|
|
1002
1002
|
};
|
|
1003
1003
|
if (l === "$derive")
|
|
1004
|
-
return (d) =>
|
|
1005
|
-
_stateKey:
|
|
1006
|
-
_path:
|
|
1004
|
+
return (d) => Vt({
|
|
1005
|
+
_stateKey: t,
|
|
1006
|
+
_path: r,
|
|
1007
1007
|
_effect: d.toString()
|
|
1008
1008
|
});
|
|
1009
1009
|
if (l === "$get")
|
|
1010
|
-
return () =>
|
|
1011
|
-
_stateKey:
|
|
1012
|
-
_path:
|
|
1010
|
+
return () => Vt({
|
|
1011
|
+
_stateKey: t,
|
|
1012
|
+
_path: r
|
|
1013
1013
|
});
|
|
1014
1014
|
if (l === "lastSynced") {
|
|
1015
|
-
const d = `${
|
|
1015
|
+
const d = `${t}:${r.join(".")}`;
|
|
1016
1016
|
return o.getState().getSyncInfo(d);
|
|
1017
1017
|
}
|
|
1018
1018
|
if (l == "getLocalStorage")
|
|
1019
|
-
return (d) =>
|
|
1019
|
+
return (d) => vt(g + "-" + t + "-" + d);
|
|
1020
1020
|
if (l === "_selected") {
|
|
1021
|
-
const d =
|
|
1022
|
-
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;
|
|
1023
1023
|
}
|
|
1024
1024
|
if (l === "setSelected")
|
|
1025
1025
|
return (d) => {
|
|
1026
|
-
const
|
|
1027
|
-
d ? o.getState().setSelectedIndex(
|
|
1028
|
-
const c = o.getState().getNestedState(
|
|
1029
|
-
|
|
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);
|
|
1030
1030
|
};
|
|
1031
1031
|
if (l === "toggleSelected")
|
|
1032
1032
|
return () => {
|
|
1033
|
-
const d =
|
|
1033
|
+
const d = r.slice(0, -1), e = Number(r[r.length - 1]), n = d.join("."), a = o.getState().getSelectedIndex(t, n);
|
|
1034
1034
|
o.getState().setSelectedIndex(
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
a ===
|
|
1035
|
+
t,
|
|
1036
|
+
n,
|
|
1037
|
+
a === e ? void 0 : e
|
|
1038
1038
|
);
|
|
1039
|
-
const c = o.getState().getNestedState(
|
|
1040
|
-
|
|
1039
|
+
const c = o.getState().getNestedState(t, [...d]);
|
|
1040
|
+
it(i, c, d), p(d);
|
|
1041
1041
|
};
|
|
1042
|
-
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
|
+
};
|
|
1043
1053
|
if (l === "applyJsonPatch")
|
|
1044
1054
|
return (d) => {
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
o.getState().initialStateGlobal[
|
|
1055
|
+
const e = o.getState().cogsStateStore[t], a = Yt(e, d).newDocument;
|
|
1056
|
+
Dt(
|
|
1057
|
+
t,
|
|
1058
|
+
o.getState().initialStateGlobal[t],
|
|
1049
1059
|
a,
|
|
1050
1060
|
i,
|
|
1051
1061
|
m,
|
|
1052
1062
|
g
|
|
1053
1063
|
);
|
|
1054
|
-
const c = o.getState().stateComponents.get(
|
|
1064
|
+
const c = o.getState().stateComponents.get(t);
|
|
1055
1065
|
if (c) {
|
|
1056
|
-
const f =
|
|
1066
|
+
const f = _t(e, a), u = new Set(f);
|
|
1057
1067
|
for (const [
|
|
1058
1068
|
E,
|
|
1059
1069
|
y
|
|
@@ -1110,203 +1120,203 @@ function Te(e, i, m, g) {
|
|
|
1110
1120
|
};
|
|
1111
1121
|
if (l === "validateZodSchema")
|
|
1112
1122
|
return () => {
|
|
1113
|
-
const d = o.getState().getInitialOptions(
|
|
1123
|
+
const d = o.getState().getInitialOptions(t)?.validation, e = o.getState().addValidationError;
|
|
1114
1124
|
if (!d?.zodSchema)
|
|
1115
1125
|
throw new Error("Zod schema not found");
|
|
1116
1126
|
if (!d?.key)
|
|
1117
1127
|
throw new Error("Validation key not found");
|
|
1118
|
-
|
|
1119
|
-
const
|
|
1128
|
+
X(d.key);
|
|
1129
|
+
const n = o.getState().cogsStateStore[t];
|
|
1120
1130
|
try {
|
|
1121
1131
|
const a = o.getState().getValidationErrors(d.key);
|
|
1122
1132
|
a && a.length > 0 && a.forEach(([f]) => {
|
|
1123
|
-
f && f.startsWith(d.key) &&
|
|
1133
|
+
f && f.startsWith(d.key) && X(f);
|
|
1124
1134
|
});
|
|
1125
|
-
const c = d.zodSchema.safeParse(
|
|
1135
|
+
const c = d.zodSchema.safeParse(n);
|
|
1126
1136
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1127
1137
|
const E = u.path, y = u.message, w = [d.key, ...E].join(".");
|
|
1128
|
-
|
|
1129
|
-
}),
|
|
1138
|
+
e(w, y);
|
|
1139
|
+
}), dt(t), !1);
|
|
1130
1140
|
} catch (a) {
|
|
1131
1141
|
return console.error("Zod schema validation failed", a), !1;
|
|
1132
1142
|
}
|
|
1133
1143
|
};
|
|
1134
1144
|
if (l === "_componentId") return m;
|
|
1135
1145
|
if (l === "getComponents")
|
|
1136
|
-
return () => o().stateComponents.get(
|
|
1146
|
+
return () => o().stateComponents.get(t);
|
|
1137
1147
|
if (l === "getAllFormRefs")
|
|
1138
|
-
return () =>
|
|
1148
|
+
return () => bt.getState().getFormRefsByStateKey(t);
|
|
1139
1149
|
if (l === "_initialState")
|
|
1140
|
-
return o.getState().initialStateGlobal[
|
|
1150
|
+
return o.getState().initialStateGlobal[t];
|
|
1141
1151
|
if (l === "_serverState")
|
|
1142
|
-
return o.getState().serverState[
|
|
1152
|
+
return o.getState().serverState[t];
|
|
1143
1153
|
if (l === "_isLoading")
|
|
1144
|
-
return o.getState().isLoadingGlobal[
|
|
1154
|
+
return o.getState().isLoadingGlobal[t];
|
|
1145
1155
|
if (l === "revertToInitialState")
|
|
1146
1156
|
return v.revertToInitialState;
|
|
1147
1157
|
if (l === "updateInitialState") return v.updateInitialState;
|
|
1148
1158
|
if (l === "removeValidation") return v.removeValidation;
|
|
1149
1159
|
}
|
|
1150
1160
|
if (l === "getFormRef")
|
|
1151
|
-
return () =>
|
|
1161
|
+
return () => bt.getState().getFormRef(t + "." + r.join("."));
|
|
1152
1162
|
if (l === "validationWrapper")
|
|
1153
1163
|
return ({
|
|
1154
1164
|
children: d,
|
|
1155
|
-
hideMessage:
|
|
1156
|
-
}) => /* @__PURE__ */
|
|
1157
|
-
|
|
1165
|
+
hideMessage: e
|
|
1166
|
+
}) => /* @__PURE__ */ Ot(
|
|
1167
|
+
zt,
|
|
1158
1168
|
{
|
|
1159
|
-
formOpts:
|
|
1160
|
-
path:
|
|
1161
|
-
validationKey: o.getState().getInitialOptions(
|
|
1162
|
-
stateKey:
|
|
1169
|
+
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1170
|
+
path: r,
|
|
1171
|
+
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1172
|
+
stateKey: t,
|
|
1163
1173
|
validIndices: S?.validIndices,
|
|
1164
1174
|
children: d
|
|
1165
1175
|
}
|
|
1166
1176
|
);
|
|
1167
|
-
if (l === "_stateKey") return
|
|
1168
|
-
if (l === "_path") return
|
|
1177
|
+
if (l === "_stateKey") return t;
|
|
1178
|
+
if (l === "_path") return r;
|
|
1169
1179
|
if (l === "_isServerSynced") return v._isServerSynced;
|
|
1170
1180
|
if (l === "update")
|
|
1171
|
-
return (d,
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1177
|
-
},
|
|
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);
|
|
1178
1188
|
else {
|
|
1179
|
-
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1189
|
+
it(i, d, r, "");
|
|
1190
|
+
const n = o.getState().getNestedState(t, r);
|
|
1191
|
+
e?.afterUpdate && e.afterUpdate(n);
|
|
1182
1192
|
}
|
|
1183
|
-
p(
|
|
1193
|
+
p(r);
|
|
1184
1194
|
};
|
|
1185
1195
|
if (l === "formElement")
|
|
1186
|
-
return (d,
|
|
1187
|
-
|
|
1196
|
+
return (d, e) => /* @__PURE__ */ Ot(
|
|
1197
|
+
qt,
|
|
1188
1198
|
{
|
|
1189
1199
|
setState: i,
|
|
1190
|
-
stateKey:
|
|
1191
|
-
path:
|
|
1200
|
+
stateKey: t,
|
|
1201
|
+
path: r,
|
|
1192
1202
|
child: d,
|
|
1193
|
-
formOpts:
|
|
1203
|
+
formOpts: e
|
|
1194
1204
|
}
|
|
1195
1205
|
);
|
|
1196
|
-
const L = [...
|
|
1197
|
-
return s(
|
|
1206
|
+
const L = [...r, l], at = o.getState().getNestedState(t, L);
|
|
1207
|
+
return s(at, L, S);
|
|
1198
1208
|
}
|
|
1199
|
-
}, z = new Proxy(
|
|
1200
|
-
return
|
|
1209
|
+
}, z = new Proxy(j, U);
|
|
1210
|
+
return T.set(W, {
|
|
1201
1211
|
proxy: z,
|
|
1202
1212
|
stateVersion: N
|
|
1203
1213
|
}), z;
|
|
1204
1214
|
}
|
|
1205
1215
|
return s(
|
|
1206
|
-
o.getState().getNestedState(
|
|
1216
|
+
o.getState().getNestedState(t, [])
|
|
1207
1217
|
);
|
|
1208
1218
|
}
|
|
1209
|
-
function
|
|
1210
|
-
return
|
|
1219
|
+
function Vt(t) {
|
|
1220
|
+
return lt(oe, { proxy: t });
|
|
1211
1221
|
}
|
|
1212
|
-
function
|
|
1213
|
-
proxy:
|
|
1222
|
+
function re({
|
|
1223
|
+
proxy: t,
|
|
1214
1224
|
rebuildStateShape: i
|
|
1215
1225
|
}) {
|
|
1216
|
-
const m = o().getNestedState(
|
|
1226
|
+
const m = o().getNestedState(t._stateKey, t._path);
|
|
1217
1227
|
return Array.isArray(m) ? i(
|
|
1218
1228
|
m,
|
|
1219
|
-
|
|
1229
|
+
t._path
|
|
1220
1230
|
).stateMapNoRender(
|
|
1221
|
-
(
|
|
1231
|
+
(T, N, p, v, s) => t._mapFn(T, N, p, v, s)
|
|
1222
1232
|
) : null;
|
|
1223
1233
|
}
|
|
1224
|
-
function
|
|
1225
|
-
proxy:
|
|
1234
|
+
function oe({
|
|
1235
|
+
proxy: t
|
|
1226
1236
|
}) {
|
|
1227
|
-
const i = q(null), m = `${
|
|
1228
|
-
return
|
|
1237
|
+
const i = q(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1238
|
+
return ot(() => {
|
|
1229
1239
|
const g = i.current;
|
|
1230
1240
|
if (!g || !g.parentElement) return;
|
|
1231
|
-
const
|
|
1232
|
-
let v =
|
|
1233
|
-
v || (v = `parent-${crypto.randomUUID()}`,
|
|
1234
|
-
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 = {
|
|
1235
1245
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1236
1246
|
parentId: v,
|
|
1237
1247
|
position: p,
|
|
1238
|
-
effect:
|
|
1248
|
+
effect: t._effect
|
|
1239
1249
|
};
|
|
1240
|
-
o.getState().addSignalElement(m,
|
|
1241
|
-
const
|
|
1250
|
+
o.getState().addSignalElement(m, I);
|
|
1251
|
+
const r = o.getState().getNestedState(t._stateKey, t._path);
|
|
1242
1252
|
let S;
|
|
1243
|
-
if (
|
|
1253
|
+
if (t._effect)
|
|
1244
1254
|
try {
|
|
1245
1255
|
S = new Function(
|
|
1246
1256
|
"state",
|
|
1247
|
-
`return (${
|
|
1248
|
-
)(
|
|
1249
|
-
} catch (
|
|
1250
|
-
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;
|
|
1251
1261
|
}
|
|
1252
1262
|
else
|
|
1253
|
-
S =
|
|
1263
|
+
S = r;
|
|
1254
1264
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1255
1265
|
const W = document.createTextNode(String(S));
|
|
1256
1266
|
g.replaceWith(W);
|
|
1257
|
-
}, [
|
|
1267
|
+
}, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
|
|
1258
1268
|
ref: i,
|
|
1259
1269
|
style: { display: "none" },
|
|
1260
1270
|
"data-signal-id": m
|
|
1261
1271
|
});
|
|
1262
1272
|
}
|
|
1263
|
-
function
|
|
1264
|
-
const i =
|
|
1273
|
+
function pe(t) {
|
|
1274
|
+
const i = Ht(
|
|
1265
1275
|
(m) => {
|
|
1266
|
-
const g = o.getState().stateComponents.get(
|
|
1276
|
+
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1267
1277
|
components: /* @__PURE__ */ new Map()
|
|
1268
1278
|
};
|
|
1269
|
-
return g.components.set(
|
|
1279
|
+
return g.components.set(t._stateKey, {
|
|
1270
1280
|
forceUpdate: m,
|
|
1271
|
-
paths: /* @__PURE__ */ new Set([
|
|
1272
|
-
}), () => g.components.delete(
|
|
1281
|
+
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1282
|
+
}), () => g.components.delete(t._stateKey);
|
|
1273
1283
|
},
|
|
1274
|
-
() => o.getState().getNestedState(
|
|
1284
|
+
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1275
1285
|
);
|
|
1276
|
-
return
|
|
1286
|
+
return lt("text", {}, String(i));
|
|
1277
1287
|
}
|
|
1278
|
-
function
|
|
1279
|
-
stateKey:
|
|
1288
|
+
function ae({
|
|
1289
|
+
stateKey: t,
|
|
1280
1290
|
itemComponentId: i,
|
|
1281
1291
|
itemPath: m,
|
|
1282
1292
|
children: g
|
|
1283
1293
|
}) {
|
|
1284
|
-
const [,
|
|
1285
|
-
return
|
|
1286
|
-
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, {
|
|
1287
1297
|
virtualizer: {
|
|
1288
1298
|
itemHeight: p.height
|
|
1289
1299
|
}
|
|
1290
1300
|
}));
|
|
1291
|
-
}, [p.height,
|
|
1292
|
-
const s = `${
|
|
1301
|
+
}, [p.height, t, m]), ct(() => {
|
|
1302
|
+
const s = `${t}////${i}`, I = o.getState().stateComponents.get(t) || {
|
|
1293
1303
|
components: /* @__PURE__ */ new Map()
|
|
1294
1304
|
};
|
|
1295
|
-
return
|
|
1296
|
-
forceUpdate: () =>
|
|
1305
|
+
return I.components.set(s, {
|
|
1306
|
+
forceUpdate: () => T({}),
|
|
1297
1307
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1298
|
-
}), o.getState().stateComponents.set(
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1308
|
+
}), o.getState().stateComponents.set(t, I), () => {
|
|
1309
|
+
const r = o.getState().stateComponents.get(t);
|
|
1310
|
+
r && r.components.delete(s);
|
|
1301
1311
|
};
|
|
1302
|
-
}, [
|
|
1312
|
+
}, [t, i, m.join(".")]), /* @__PURE__ */ Ot("div", { ref: N, children: g });
|
|
1303
1313
|
}
|
|
1304
1314
|
export {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1315
|
+
Vt as $cogsSignal,
|
|
1316
|
+
pe as $cogsSignalStore,
|
|
1317
|
+
Te as addStateOptions,
|
|
1318
|
+
ve as createCogsState,
|
|
1319
|
+
ye as notifyComponent,
|
|
1320
|
+
ne as useCogsStateFn
|
|
1311
1321
|
};
|
|
1312
1322
|
//# sourceMappingURL=CogsState.jsx.map
|