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