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