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