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