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