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