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