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