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