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