cogsbox-state 0.5.453 → 0.5.455
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CogsState.d.ts +8 -8
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +523 -540
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +13 -52
package/dist/CogsState.jsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as ot, Fragment as
|
|
3
|
-
import { memo as
|
|
2
|
+
import { jsx as ot, Fragment as Ut } from "react/jsx-runtime";
|
|
3
|
+
import { memo as Ot, useState as K, useRef as q, useCallback as ct, useEffect as Z, useLayoutEffect as dt, useMemo as gt, createElement as lt, startTransition as Rt } from "react";
|
|
4
4
|
import { createRoot as At } from "react-dom/client";
|
|
5
5
|
import { transformStateFunc as Nt, isFunction as at, isArray as Tt, getDifferences as Ct, isDeepEqual as st } from "./utility.js";
|
|
6
|
-
import { ValidationWrapper as
|
|
6
|
+
import { ValidationWrapper as kt } from "./Functions.jsx";
|
|
7
7
|
import Ft from "superjson";
|
|
8
8
|
import { v4 as rt } from "uuid";
|
|
9
9
|
import { getGlobalStore as e, formRefStore as vt } from "./store.js";
|
|
10
|
-
import { useCogsConfig as
|
|
10
|
+
import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { useInView as jt } from "react-intersection-observer";
|
|
12
12
|
function yt(t, n) {
|
|
13
13
|
const S = e.getState().getInitialOptions, g = e.getState().setInitialStateOptions, y = S(t) || {};
|
|
@@ -16,17 +16,17 @@ function yt(t, n) {
|
|
|
16
16
|
...n
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function Vt({
|
|
20
20
|
stateKey: t,
|
|
21
21
|
options: n,
|
|
22
22
|
initialOptionsPart: S
|
|
23
23
|
}) {
|
|
24
|
-
const g = nt(t) || {}, y = S[t] || {},
|
|
25
|
-
let
|
|
24
|
+
const g = nt(t) || {}, y = S[t] || {}, I = e.getState().setInitialStateOptions, V = { ...y, ...g };
|
|
25
|
+
let u = !1;
|
|
26
26
|
if (n)
|
|
27
27
|
for (const f in n)
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
V.hasOwnProperty(f) ? (f == "localStorage" && n[f] && V[f].key !== n[f]?.key && (u = !0, V[f] = n[f]), f == "defaultState" && n[f] && V[f] !== n[f] && !st(V[f], n[f]) && (u = !0, V[f] = n[f])) : (u = !0, V[f] = n[f]);
|
|
29
|
+
u && I(t, V);
|
|
30
30
|
}
|
|
31
31
|
function ie(t, { formElements: n, validation: S }) {
|
|
32
32
|
return { initialState: t, formElements: n, validation: S };
|
|
@@ -34,8 +34,8 @@ function ie(t, { formElements: n, validation: S }) {
|
|
|
34
34
|
const Lt = (t, n) => {
|
|
35
35
|
let S = t;
|
|
36
36
|
const [g, y] = Nt(S);
|
|
37
|
-
n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(g).forEach((
|
|
38
|
-
let f = y[
|
|
37
|
+
n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(g).forEach((u) => {
|
|
38
|
+
let f = y[u] || {};
|
|
39
39
|
const A = {
|
|
40
40
|
...f
|
|
41
41
|
};
|
|
@@ -45,26 +45,26 @@ const Lt = (t, n) => {
|
|
|
45
45
|
}), n?.validation && (A.validation = {
|
|
46
46
|
...n.validation,
|
|
47
47
|
...f.validation || {}
|
|
48
|
-
}, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
...
|
|
48
|
+
}, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${u}`)), Object.keys(A).length > 0) {
|
|
49
|
+
const w = nt(u);
|
|
50
|
+
w ? e.getState().setInitialStateOptions(u, {
|
|
51
|
+
...w,
|
|
52
52
|
...A
|
|
53
|
-
}) : e.getState().setInitialStateOptions(
|
|
53
|
+
}) : e.getState().setInitialStateOptions(u, A);
|
|
54
54
|
}
|
|
55
|
-
}), Object.keys(g).forEach((
|
|
56
|
-
e.getState().initializeShadowState(
|
|
55
|
+
}), Object.keys(g).forEach((u) => {
|
|
56
|
+
e.getState().initializeShadowState(u, g[u]);
|
|
57
57
|
});
|
|
58
|
-
const
|
|
58
|
+
const I = (u, f) => {
|
|
59
59
|
const [A] = K(f?.componentId ?? rt());
|
|
60
|
-
|
|
61
|
-
stateKey:
|
|
60
|
+
Vt({
|
|
61
|
+
stateKey: u,
|
|
62
62
|
options: f,
|
|
63
63
|
initialOptionsPart: y
|
|
64
64
|
});
|
|
65
|
-
const
|
|
65
|
+
const w = e.getState().getShadowValue(u) || g[u], i = f?.modifyState ? f.modifyState(w) : w;
|
|
66
66
|
return zt(i, {
|
|
67
|
-
stateKey:
|
|
67
|
+
stateKey: u,
|
|
68
68
|
syncUpdate: f?.syncUpdate,
|
|
69
69
|
componentId: A,
|
|
70
70
|
localStorage: f?.localStorage,
|
|
@@ -76,35 +76,18 @@ const Lt = (t, n) => {
|
|
|
76
76
|
serverState: f?.serverState
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function V(u, f) {
|
|
80
|
+
Vt({ stateKey: u, options: f, initialOptionsPart: y }), f.localStorage && xt(u, f), it(u);
|
|
81
81
|
}
|
|
82
|
-
return { useCogsState:
|
|
82
|
+
return { useCogsState: I, setCogsOptions: V };
|
|
83
83
|
};
|
|
84
84
|
function ce(t) {
|
|
85
85
|
const n = t.schemas, S = {};
|
|
86
|
-
for (const
|
|
87
|
-
const
|
|
88
|
-
S[
|
|
86
|
+
for (const g in n) {
|
|
87
|
+
const y = n[g];
|
|
88
|
+
S[g] = y?.schemas?.defaultValues || {};
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
__fromSyncSchema: !0,
|
|
92
|
-
__syncNotifications: t.notifications
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
useCogsState: (v, M) => {
|
|
96
|
-
const c = n[v];
|
|
97
|
-
if (c?.apiParamsSchema && M?.apiParams) {
|
|
98
|
-
const f = c.apiParamsSchema.safeParse(M.apiParams);
|
|
99
|
-
if (!f.success)
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Invalid API params for ${String(v)}: ${f.error.message}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return g.useCogsState(v, M);
|
|
105
|
-
},
|
|
106
|
-
setCogsOptions: g.setCogsOptions
|
|
107
|
-
};
|
|
90
|
+
return Lt(S);
|
|
108
91
|
}
|
|
109
92
|
const {
|
|
110
93
|
getInitialOptions: nt,
|
|
@@ -120,24 +103,24 @@ const {
|
|
|
120
103
|
S.localStorage?.key,
|
|
121
104
|
g
|
|
122
105
|
);
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
let
|
|
106
|
+
const I = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
|
|
107
|
+
if (I && g) {
|
|
108
|
+
const V = `${g}-${n}-${I}`;
|
|
109
|
+
let u;
|
|
127
110
|
try {
|
|
128
|
-
|
|
111
|
+
u = St(V)?.lastSyncedWithServer;
|
|
129
112
|
} catch {
|
|
130
113
|
}
|
|
131
114
|
const f = e.getState().getShadowMetadata(n, []), A = {
|
|
132
115
|
state: t,
|
|
133
116
|
lastUpdated: Date.now(),
|
|
134
|
-
lastSyncedWithServer:
|
|
117
|
+
lastSyncedWithServer: u,
|
|
135
118
|
stateSource: f?.stateSource,
|
|
136
119
|
baseServerState: f?.baseServerState
|
|
137
|
-
},
|
|
120
|
+
}, w = Ft.serialize(A);
|
|
138
121
|
window.localStorage.setItem(
|
|
139
|
-
|
|
140
|
-
JSON.stringify(
|
|
122
|
+
V,
|
|
123
|
+
JSON.stringify(w.json)
|
|
141
124
|
);
|
|
142
125
|
}
|
|
143
126
|
}, St = (t) => {
|
|
@@ -149,12 +132,12 @@ const {
|
|
|
149
132
|
return console.error("Error loading from localStorage:", n), null;
|
|
150
133
|
}
|
|
151
134
|
}, xt = (t, n) => {
|
|
152
|
-
const S = e.getState().getShadowValue(t), { sessionId: g } =
|
|
135
|
+
const S = e.getState().getShadowValue(t), { sessionId: g } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
|
|
153
136
|
if (y && g) {
|
|
154
|
-
const
|
|
137
|
+
const I = St(
|
|
155
138
|
`${g}-${t}-${y}`
|
|
156
139
|
);
|
|
157
|
-
if (
|
|
140
|
+
if (I && I.lastUpdated > (I.lastSyncedWithServer || 0))
|
|
158
141
|
return it(t), !0;
|
|
159
142
|
}
|
|
160
143
|
return !1;
|
|
@@ -177,26 +160,26 @@ const {
|
|
|
177
160
|
}
|
|
178
161
|
};
|
|
179
162
|
function wt(t, n, S, g) {
|
|
180
|
-
const y = e.getState(),
|
|
163
|
+
const y = e.getState(), I = y.getShadowMetadata(t, n);
|
|
181
164
|
if (y.setShadowMetadata(t, n, {
|
|
182
|
-
...
|
|
165
|
+
...I,
|
|
183
166
|
isDirty: !1,
|
|
184
167
|
stateSource: "server",
|
|
185
168
|
lastServerSync: g || Date.now()
|
|
186
169
|
}), Array.isArray(S)) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
const A =
|
|
190
|
-
|
|
170
|
+
const V = y.getShadowMetadata(t, n);
|
|
171
|
+
V?.arrayKeys && V.arrayKeys.forEach((u, f) => {
|
|
172
|
+
const A = u.split(".").slice(1), w = S[f];
|
|
173
|
+
w !== void 0 && wt(
|
|
191
174
|
t,
|
|
192
175
|
A,
|
|
193
|
-
|
|
176
|
+
w,
|
|
194
177
|
g
|
|
195
178
|
);
|
|
196
179
|
});
|
|
197
|
-
} else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((
|
|
198
|
-
const
|
|
199
|
-
wt(t,
|
|
180
|
+
} else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((V) => {
|
|
181
|
+
const u = [...n, V], f = S[V];
|
|
182
|
+
wt(t, u, f, g);
|
|
200
183
|
});
|
|
201
184
|
}
|
|
202
185
|
function zt(t, {
|
|
@@ -204,20 +187,20 @@ function zt(t, {
|
|
|
204
187
|
localStorage: S,
|
|
205
188
|
formElements: g,
|
|
206
189
|
reactiveDeps: y,
|
|
207
|
-
reactiveType:
|
|
208
|
-
componentId:
|
|
209
|
-
defaultState:
|
|
190
|
+
reactiveType: I,
|
|
191
|
+
componentId: V,
|
|
192
|
+
defaultState: u,
|
|
210
193
|
syncUpdate: f,
|
|
211
194
|
dependencies: A,
|
|
212
|
-
serverState:
|
|
195
|
+
serverState: w
|
|
213
196
|
} = {}) {
|
|
214
|
-
const [i, h] = K({}), { sessionId:
|
|
197
|
+
const [i, h] = K({}), { sessionId: M } = Pt();
|
|
215
198
|
let z = !n;
|
|
216
|
-
const [
|
|
199
|
+
const [c] = K(n ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(V ?? rt()), W = q(
|
|
217
200
|
null
|
|
218
201
|
);
|
|
219
|
-
W.current = nt(
|
|
220
|
-
if (f && f.stateKey ===
|
|
202
|
+
W.current = nt(c) ?? null, Z(() => {
|
|
203
|
+
if (f && f.stateKey === c && f.path?.[0]) {
|
|
221
204
|
const o = `${f.stateKey}:${f.path.join(".")}`;
|
|
222
205
|
e.getState().setSyncInfo(o, {
|
|
223
206
|
timeStamp: f.timeStamp,
|
|
@@ -227,22 +210,22 @@ function zt(t, {
|
|
|
227
210
|
}, [f]);
|
|
228
211
|
const m = ct(
|
|
229
212
|
(o) => {
|
|
230
|
-
const a = o ? { ...nt(
|
|
213
|
+
const a = o ? { ...nt(c), ...o } : nt(c), d = a?.defaultState || u || t;
|
|
231
214
|
if (a?.serverState?.status === "success" && a?.serverState?.data !== void 0)
|
|
232
215
|
return {
|
|
233
216
|
value: a.serverState.data,
|
|
234
217
|
source: "server",
|
|
235
218
|
timestamp: a.serverState.timestamp || Date.now()
|
|
236
219
|
};
|
|
237
|
-
if (a?.localStorage?.key &&
|
|
238
|
-
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key,
|
|
239
|
-
`${
|
|
220
|
+
if (a?.localStorage?.key && M) {
|
|
221
|
+
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, E = St(
|
|
222
|
+
`${M}-${c}-${p}`
|
|
240
223
|
);
|
|
241
|
-
if (
|
|
224
|
+
if (E && E.lastUpdated > (a?.serverState?.timestamp || 0))
|
|
242
225
|
return {
|
|
243
|
-
value:
|
|
226
|
+
value: E.state,
|
|
244
227
|
source: "localStorage",
|
|
245
|
-
timestamp:
|
|
228
|
+
timestamp: E.lastUpdated
|
|
246
229
|
};
|
|
247
230
|
}
|
|
248
231
|
return {
|
|
@@ -251,36 +234,36 @@ function zt(t, {
|
|
|
251
234
|
timestamp: Date.now()
|
|
252
235
|
};
|
|
253
236
|
},
|
|
254
|
-
[
|
|
237
|
+
[c, u, t, M]
|
|
255
238
|
);
|
|
256
239
|
Z(() => {
|
|
257
|
-
e.getState().setServerStateUpdate(
|
|
258
|
-
}, [
|
|
240
|
+
e.getState().setServerStateUpdate(c, w);
|
|
241
|
+
}, [w, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
|
|
259
242
|
if (r?.type === "SERVER_STATE_UPDATE") {
|
|
260
243
|
const a = r.serverState;
|
|
261
244
|
if (a?.status === "success" && a.data !== void 0) {
|
|
262
|
-
yt(
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
p.map((x) => x[
|
|
267
|
-
), F =
|
|
245
|
+
yt(c, { serverState: a });
|
|
246
|
+
const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), E = a.data;
|
|
247
|
+
if (l && Array.isArray(p) && Array.isArray(E)) {
|
|
248
|
+
const U = l.key || "id", C = new Set(
|
|
249
|
+
p.map((x) => x[U])
|
|
250
|
+
), F = E.filter((x) => !C.has(x[U]));
|
|
268
251
|
F.length > 0 && F.forEach((x) => {
|
|
269
|
-
e.getState().insertShadowArrayElement(
|
|
270
|
-
const N = e.getState().getShadowMetadata(
|
|
252
|
+
e.getState().insertShadowArrayElement(c, [], x);
|
|
253
|
+
const N = e.getState().getShadowMetadata(c, []);
|
|
271
254
|
if (N?.arrayKeys) {
|
|
272
255
|
const j = N.arrayKeys[N.arrayKeys.length - 1];
|
|
273
256
|
if (j) {
|
|
274
257
|
const b = j.split(".").slice(1);
|
|
275
|
-
e.getState().setShadowMetadata(
|
|
258
|
+
e.getState().setShadowMetadata(c, b, {
|
|
276
259
|
isDirty: !1,
|
|
277
260
|
stateSource: "server",
|
|
278
261
|
lastServerSync: a.timestamp || Date.now()
|
|
279
262
|
});
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
e.getState().setShadowMetadata(
|
|
263
|
+
const k = e.getState().getShadowValue(j);
|
|
264
|
+
k && typeof k == "object" && !Array.isArray(k) && Object.keys(k).forEach((P) => {
|
|
265
|
+
const O = [...b, P];
|
|
266
|
+
e.getState().setShadowMetadata(c, O, {
|
|
284
267
|
isDirty: !1,
|
|
285
268
|
stateSource: "server",
|
|
286
269
|
lastServerSync: a.timestamp || Date.now()
|
|
@@ -290,14 +273,14 @@ function zt(t, {
|
|
|
290
273
|
}
|
|
291
274
|
});
|
|
292
275
|
} else
|
|
293
|
-
e.getState().initializeShadowState(
|
|
294
|
-
|
|
276
|
+
e.getState().initializeShadowState(c, E), wt(
|
|
277
|
+
c,
|
|
295
278
|
[],
|
|
296
|
-
|
|
279
|
+
E,
|
|
297
280
|
a.timestamp
|
|
298
281
|
);
|
|
299
|
-
const _ = e.getState().getShadowMetadata(
|
|
300
|
-
e.getState().setShadowMetadata(
|
|
282
|
+
const _ = e.getState().getShadowMetadata(c, []);
|
|
283
|
+
e.getState().setShadowMetadata(c, [], {
|
|
301
284
|
..._,
|
|
302
285
|
stateSource: "server",
|
|
303
286
|
lastServerSync: a.timestamp || Date.now(),
|
|
@@ -305,206 +288,206 @@ function zt(t, {
|
|
|
305
288
|
});
|
|
306
289
|
}
|
|
307
290
|
}
|
|
308
|
-
}), [
|
|
309
|
-
const o = e.getState().getShadowMetadata(
|
|
291
|
+
}), [c, m]), Z(() => {
|
|
292
|
+
const o = e.getState().getShadowMetadata(c, []);
|
|
310
293
|
if (o && o.stateSource)
|
|
311
294
|
return;
|
|
312
|
-
const r = nt(
|
|
313
|
-
if (r?.defaultState !== void 0 ||
|
|
314
|
-
const a = r?.defaultState ||
|
|
315
|
-
r?.defaultState || yt(
|
|
295
|
+
const r = nt(c);
|
|
296
|
+
if (r?.defaultState !== void 0 || u !== void 0) {
|
|
297
|
+
const a = r?.defaultState || u;
|
|
298
|
+
r?.defaultState || yt(c, {
|
|
316
299
|
defaultState: a
|
|
317
300
|
});
|
|
318
|
-
const { value: d, source:
|
|
319
|
-
e.getState().initializeShadowState(
|
|
320
|
-
stateSource:
|
|
321
|
-
lastServerSync:
|
|
301
|
+
const { value: d, source: l, timestamp: p } = m();
|
|
302
|
+
e.getState().initializeShadowState(c, d), e.getState().setShadowMetadata(c, [], {
|
|
303
|
+
stateSource: l,
|
|
304
|
+
lastServerSync: l === "server" ? p : void 0,
|
|
322
305
|
isDirty: !1,
|
|
323
|
-
baseServerState:
|
|
324
|
-
}), it(
|
|
306
|
+
baseServerState: l === "server" ? d : void 0
|
|
307
|
+
}), it(c);
|
|
325
308
|
}
|
|
326
|
-
}, [
|
|
327
|
-
z && yt(
|
|
309
|
+
}, [c, ...A || []]), dt(() => {
|
|
310
|
+
z && yt(c, {
|
|
328
311
|
formElements: g,
|
|
329
|
-
defaultState:
|
|
312
|
+
defaultState: u,
|
|
330
313
|
localStorage: S,
|
|
331
314
|
middleware: W.current?.middleware
|
|
332
315
|
});
|
|
333
|
-
const o = `${
|
|
316
|
+
const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
|
|
334
317
|
return a.set(o, {
|
|
335
318
|
forceUpdate: () => h({}),
|
|
336
|
-
reactiveType:
|
|
319
|
+
reactiveType: I ?? ["component", "deps"],
|
|
337
320
|
paths: /* @__PURE__ */ new Set(),
|
|
338
321
|
depsFunction: y || void 0,
|
|
339
|
-
deps: y ? y(e.getState().getShadowValue(
|
|
340
|
-
prevDeps: y ? y(e.getState().getShadowValue(
|
|
341
|
-
}), e.getState().setShadowMetadata(
|
|
322
|
+
deps: y ? y(e.getState().getShadowValue(c)) : [],
|
|
323
|
+
prevDeps: y ? y(e.getState().getShadowValue(c)) : []
|
|
324
|
+
}), e.getState().setShadowMetadata(c, [], {
|
|
342
325
|
...r,
|
|
343
326
|
components: a
|
|
344
327
|
}), h({}), () => {
|
|
345
|
-
const d = e.getState().getShadowMetadata(
|
|
346
|
-
|
|
347
|
-
const _ = p.split(".").slice(1),
|
|
348
|
-
|
|
349
|
-
}), d?.components && e.getState().setShadowMetadata(
|
|
328
|
+
const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
|
|
329
|
+
l?.paths && l.paths.forEach((p) => {
|
|
330
|
+
const _ = p.split(".").slice(1), U = e.getState().getShadowMetadata(c, _);
|
|
331
|
+
U?.pathComponents && U.pathComponents.size === 0 && (delete U.pathComponents, e.getState().setShadowMetadata(c, _, U));
|
|
332
|
+
}), d?.components && e.getState().setShadowMetadata(c, [], d);
|
|
350
333
|
};
|
|
351
334
|
}, []);
|
|
352
335
|
const Y = q(null), Q = (o, r, a) => {
|
|
353
|
-
const d = [
|
|
336
|
+
const d = [c, ...r].join(".");
|
|
354
337
|
if (Array.isArray(r)) {
|
|
355
|
-
const b = `${
|
|
338
|
+
const b = `${c}-${r.join(".")}`;
|
|
356
339
|
J.current.add(b);
|
|
357
340
|
}
|
|
358
|
-
const
|
|
341
|
+
const l = e.getState(), p = l.getShadowMetadata(c, r), E = l.getShadowValue(d), _ = a.updateType === "insert" && at(o) ? o({ state: E, uuid: rt() }) : at(o) ? o(E) : o, C = {
|
|
359
342
|
timeStamp: Date.now(),
|
|
360
|
-
stateKey:
|
|
343
|
+
stateKey: c,
|
|
361
344
|
path: r,
|
|
362
345
|
updateType: a.updateType,
|
|
363
346
|
status: "new",
|
|
364
|
-
oldValue:
|
|
347
|
+
oldValue: E,
|
|
365
348
|
newValue: _
|
|
366
349
|
};
|
|
367
350
|
switch (a.updateType) {
|
|
368
351
|
case "insert": {
|
|
369
|
-
|
|
370
|
-
const b =
|
|
352
|
+
l.insertShadowArrayElement(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
|
|
353
|
+
const b = l.getShadowMetadata(c, r);
|
|
371
354
|
if (b?.arrayKeys) {
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
374
|
-
const
|
|
375
|
-
|
|
355
|
+
const k = b.arrayKeys[b.arrayKeys.length - 1];
|
|
356
|
+
if (k) {
|
|
357
|
+
const P = k.split(".").slice(1);
|
|
358
|
+
l.markAsDirty(c, P, { bubble: !1 });
|
|
376
359
|
}
|
|
377
360
|
}
|
|
378
361
|
break;
|
|
379
362
|
}
|
|
380
363
|
case "cut": {
|
|
381
364
|
const b = r.slice(0, -1);
|
|
382
|
-
|
|
365
|
+
l.removeShadowArrayElement(c, r), l.markAsDirty(c, b, { bubble: !0 });
|
|
383
366
|
break;
|
|
384
367
|
}
|
|
385
368
|
case "update": {
|
|
386
|
-
|
|
369
|
+
l.updateShadowAtPath(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
|
|
387
370
|
break;
|
|
388
371
|
}
|
|
389
372
|
}
|
|
390
373
|
if (a.sync !== !1 && Y.current && Y.current.connected && Y.current.updateState({ operation: C }), p?.signals && p.signals.length > 0) {
|
|
391
374
|
const b = a.updateType === "cut" ? null : _;
|
|
392
|
-
p.signals.forEach(({ parentId:
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
const
|
|
396
|
-
if (
|
|
375
|
+
p.signals.forEach(({ parentId: k, position: P, effect: O }) => {
|
|
376
|
+
const v = document.querySelector(`[data-parent-id="${k}"]`);
|
|
377
|
+
if (v) {
|
|
378
|
+
const T = Array.from(v.childNodes);
|
|
379
|
+
if (T[P]) {
|
|
397
380
|
let $ = b;
|
|
398
|
-
if (
|
|
381
|
+
if (O && b !== null)
|
|
399
382
|
try {
|
|
400
383
|
$ = new Function(
|
|
401
384
|
"state",
|
|
402
|
-
`return (${
|
|
385
|
+
`return (${O})(state)`
|
|
403
386
|
)(b);
|
|
404
387
|
} catch (D) {
|
|
405
388
|
console.error("Error evaluating effect function:", D);
|
|
406
389
|
}
|
|
407
|
-
$ != null && typeof $ == "object" && ($ = JSON.stringify($)),
|
|
390
|
+
$ != null && typeof $ == "object" && ($ = JSON.stringify($)), T[P].textContent = String($ ?? "");
|
|
408
391
|
}
|
|
409
392
|
}
|
|
410
393
|
});
|
|
411
394
|
}
|
|
412
395
|
if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
|
|
413
|
-
const b =
|
|
414
|
-
[
|
|
396
|
+
const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), O = l.getShadowValue(
|
|
397
|
+
[c, ...r].join(".")
|
|
415
398
|
);
|
|
416
|
-
if (!
|
|
417
|
-
p.mapWrappers.forEach((
|
|
418
|
-
let
|
|
419
|
-
if (
|
|
420
|
-
for (const D of
|
|
421
|
-
if (D.type === "filter" && !D.fn(
|
|
422
|
-
|
|
399
|
+
if (!k || P === void 0) return;
|
|
400
|
+
p.mapWrappers.forEach((v) => {
|
|
401
|
+
let T = !0, $ = -1;
|
|
402
|
+
if (v.meta?.transforms && v.meta.transforms.length > 0) {
|
|
403
|
+
for (const D of v.meta.transforms)
|
|
404
|
+
if (D.type === "filter" && !D.fn(P, -1)) {
|
|
405
|
+
T = !1;
|
|
423
406
|
break;
|
|
424
407
|
}
|
|
425
|
-
if (
|
|
408
|
+
if (T) {
|
|
426
409
|
const D = It(
|
|
427
|
-
|
|
410
|
+
c,
|
|
428
411
|
r,
|
|
429
|
-
|
|
430
|
-
), R =
|
|
412
|
+
v.meta.transforms
|
|
413
|
+
), R = v.meta.transforms.find(
|
|
431
414
|
(L) => L.type === "sort"
|
|
432
415
|
);
|
|
433
416
|
if (R) {
|
|
434
417
|
const L = D.map((G) => ({
|
|
435
418
|
key: G,
|
|
436
|
-
value:
|
|
419
|
+
value: l.getShadowValue(G)
|
|
437
420
|
}));
|
|
438
|
-
L.push({ key:
|
|
439
|
-
(G) => G.key ===
|
|
421
|
+
L.push({ key: k, value: P }), L.sort((G, tt) => R.fn(G.value, tt.value)), $ = L.findIndex(
|
|
422
|
+
(G) => G.key === k
|
|
440
423
|
);
|
|
441
424
|
} else
|
|
442
425
|
$ = D.length;
|
|
443
426
|
}
|
|
444
427
|
} else
|
|
445
|
-
|
|
446
|
-
if (
|
|
428
|
+
T = !0, $ = b.length - 1;
|
|
429
|
+
if (T && v.containerRef && v.containerRef.isConnected) {
|
|
447
430
|
const D = document.createElement("div");
|
|
448
|
-
D.setAttribute("data-item-path",
|
|
449
|
-
const R = Array.from(
|
|
450
|
-
$ >= 0 && $ < R.length ?
|
|
431
|
+
D.setAttribute("data-item-path", k);
|
|
432
|
+
const R = Array.from(v.containerRef.children);
|
|
433
|
+
$ >= 0 && $ < R.length ? v.containerRef.insertBefore(
|
|
451
434
|
D,
|
|
452
435
|
R[$]
|
|
453
|
-
) :
|
|
454
|
-
const L = At(D), G = rt(), tt =
|
|
455
|
-
path:
|
|
456
|
-
currentState:
|
|
457
|
-
componentId:
|
|
458
|
-
meta:
|
|
436
|
+
) : v.containerRef.appendChild(D);
|
|
437
|
+
const L = At(D), G = rt(), tt = k.split(".").slice(1), et = v.rebuildStateShape({
|
|
438
|
+
path: v.path,
|
|
439
|
+
currentState: O,
|
|
440
|
+
componentId: v.componentId,
|
|
441
|
+
meta: v.meta
|
|
459
442
|
});
|
|
460
443
|
L.render(
|
|
461
444
|
lt(Mt, {
|
|
462
|
-
stateKey:
|
|
445
|
+
stateKey: c,
|
|
463
446
|
itemComponentId: G,
|
|
464
447
|
itemPath: tt,
|
|
465
448
|
localIndex: $,
|
|
466
449
|
arraySetter: et,
|
|
467
|
-
rebuildStateShape:
|
|
468
|
-
renderFn:
|
|
450
|
+
rebuildStateShape: v.rebuildStateShape,
|
|
451
|
+
renderFn: v.mapFn
|
|
469
452
|
})
|
|
470
453
|
);
|
|
471
454
|
}
|
|
472
455
|
});
|
|
473
456
|
}
|
|
474
457
|
if (a.updateType === "cut") {
|
|
475
|
-
const b = r.slice(0, -1),
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
const
|
|
458
|
+
const b = r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
459
|
+
k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
|
|
460
|
+
if (P.containerRef && P.containerRef.isConnected) {
|
|
461
|
+
const O = P.containerRef.querySelector(
|
|
479
462
|
`[data-item-path="${d}"]`
|
|
480
463
|
);
|
|
481
|
-
|
|
464
|
+
O && O.remove();
|
|
482
465
|
}
|
|
483
466
|
});
|
|
484
467
|
}
|
|
485
|
-
const x = e.getState().getShadowValue(
|
|
468
|
+
const x = e.getState().getShadowValue(c), N = e.getState().getShadowMetadata(c, []), j = /* @__PURE__ */ new Set();
|
|
486
469
|
if (console.log(
|
|
487
470
|
"rootMeta",
|
|
488
|
-
|
|
471
|
+
c,
|
|
489
472
|
e.getState().shadowStateStore
|
|
490
473
|
), !N?.components)
|
|
491
474
|
return x;
|
|
492
475
|
if (a.updateType === "update") {
|
|
493
476
|
let b = [...r];
|
|
494
477
|
for (; ; ) {
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
497
|
-
if (j.has(
|
|
478
|
+
const k = l.getShadowMetadata(c, b);
|
|
479
|
+
if (k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
480
|
+
if (j.has(P))
|
|
498
481
|
return;
|
|
499
|
-
const
|
|
500
|
-
|
|
482
|
+
const O = N.components?.get(P);
|
|
483
|
+
O && ((Array.isArray(O.reactiveType) ? O.reactiveType : [O.reactiveType || "component"]).includes("none") || (O.forceUpdate(), j.add(P)));
|
|
501
484
|
}), b.length === 0)
|
|
502
485
|
break;
|
|
503
486
|
b.pop();
|
|
504
487
|
}
|
|
505
|
-
_ && typeof _ == "object" && !Tt(_) &&
|
|
506
|
-
const
|
|
507
|
-
|
|
488
|
+
_ && typeof _ == "object" && !Tt(_) && E && typeof E == "object" && !Tt(E) && Ct(_, E).forEach((P) => {
|
|
489
|
+
const O = P.split("."), v = [...r, ...O], T = l.getShadowMetadata(c, v);
|
|
490
|
+
T?.pathComponents && T.pathComponents.forEach(($) => {
|
|
508
491
|
if (j.has($))
|
|
509
492
|
return;
|
|
510
493
|
const D = N.components?.get($);
|
|
@@ -512,74 +495,74 @@ function zt(t, {
|
|
|
512
495
|
});
|
|
513
496
|
});
|
|
514
497
|
} else if (a.updateType === "insert" || a.updateType === "cut") {
|
|
515
|
-
const b = a.updateType === "insert" ? r : r.slice(0, -1),
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
|
|
498
|
+
const b = a.updateType === "insert" ? r : r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
499
|
+
if (k?.signals && k.signals.length > 0) {
|
|
500
|
+
const P = [c, ...b].join("."), O = l.getShadowValue(P);
|
|
501
|
+
k.signals.forEach(({ parentId: v, position: T, effect: $ }) => {
|
|
519
502
|
const D = document.querySelector(
|
|
520
|
-
`[data-parent-id="${
|
|
503
|
+
`[data-parent-id="${v}"]`
|
|
521
504
|
);
|
|
522
505
|
if (D) {
|
|
523
506
|
const R = Array.from(D.childNodes);
|
|
524
|
-
if (R[
|
|
525
|
-
let L =
|
|
507
|
+
if (R[T]) {
|
|
508
|
+
let L = O;
|
|
526
509
|
if ($)
|
|
527
510
|
try {
|
|
528
511
|
L = new Function(
|
|
529
512
|
"state",
|
|
530
513
|
`return (${$})(state)`
|
|
531
|
-
)(
|
|
514
|
+
)(O);
|
|
532
515
|
} catch (G) {
|
|
533
|
-
console.error("Error evaluating effect function:", G), L =
|
|
516
|
+
console.error("Error evaluating effect function:", G), L = O;
|
|
534
517
|
}
|
|
535
|
-
L != null && typeof L == "object" && (L = JSON.stringify(L)), R[
|
|
518
|
+
L != null && typeof L == "object" && (L = JSON.stringify(L)), R[T].textContent = String(L ?? "");
|
|
536
519
|
}
|
|
537
520
|
}
|
|
538
521
|
});
|
|
539
522
|
}
|
|
540
|
-
|
|
541
|
-
if (!j.has(
|
|
542
|
-
const
|
|
543
|
-
|
|
523
|
+
k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
524
|
+
if (!j.has(P)) {
|
|
525
|
+
const O = N.components?.get(P);
|
|
526
|
+
O && (O.forceUpdate(), j.add(P));
|
|
544
527
|
}
|
|
545
528
|
});
|
|
546
529
|
}
|
|
547
|
-
return N.components.forEach((b,
|
|
548
|
-
if (j.has(
|
|
530
|
+
return N.components.forEach((b, k) => {
|
|
531
|
+
if (j.has(k))
|
|
549
532
|
return;
|
|
550
|
-
const
|
|
551
|
-
if (
|
|
552
|
-
b.forceUpdate(), j.add(
|
|
533
|
+
const P = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
|
|
534
|
+
if (P.includes("all")) {
|
|
535
|
+
b.forceUpdate(), j.add(k);
|
|
553
536
|
return;
|
|
554
537
|
}
|
|
555
|
-
if (
|
|
556
|
-
const
|
|
557
|
-
let
|
|
558
|
-
|
|
538
|
+
if (P.includes("deps") && b.depsFunction) {
|
|
539
|
+
const O = l.getShadowValue(c), v = b.depsFunction(O);
|
|
540
|
+
let T = !1;
|
|
541
|
+
v === !0 ? T = !0 : Array.isArray(v) && (st(b.prevDeps, v) || (b.prevDeps = v, T = !0)), T && (b.forceUpdate(), j.add(k));
|
|
559
542
|
}
|
|
560
|
-
}), j.clear(), Wt(
|
|
561
|
-
const
|
|
562
|
-
return
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
}), Array.from(
|
|
543
|
+
}), j.clear(), Wt(c, (b) => {
|
|
544
|
+
const k = [...b ?? [], C], P = /* @__PURE__ */ new Map();
|
|
545
|
+
return k.forEach((O) => {
|
|
546
|
+
const v = `${O.stateKey}:${JSON.stringify(O.path)}`, T = P.get(v);
|
|
547
|
+
T ? (T.timeStamp = Math.max(T.timeStamp, O.timeStamp), T.newValue = O.newValue, T.oldValue = T.oldValue ?? O.oldValue, T.updateType = O.updateType) : P.set(v, { ...O });
|
|
548
|
+
}), Array.from(P.values());
|
|
566
549
|
}), Ht(
|
|
567
550
|
_,
|
|
568
|
-
|
|
551
|
+
c,
|
|
569
552
|
W.current,
|
|
570
|
-
|
|
553
|
+
M
|
|
571
554
|
), W.current?.middleware && W.current.middleware({
|
|
572
555
|
updateLog: B,
|
|
573
556
|
update: C
|
|
574
557
|
}), x;
|
|
575
558
|
};
|
|
576
|
-
e.getState().initialStateGlobal[
|
|
559
|
+
e.getState().initialStateGlobal[c] || _t(c, t);
|
|
577
560
|
const X = gt(() => Dt(
|
|
578
|
-
|
|
561
|
+
c,
|
|
579
562
|
Q,
|
|
580
563
|
H.current,
|
|
581
|
-
|
|
582
|
-
), [
|
|
564
|
+
M
|
|
565
|
+
), [c, M]), s = W.current?.cogsSync;
|
|
583
566
|
return s && (Y.current = s(X)), X;
|
|
584
567
|
}
|
|
585
568
|
function Bt(t) {
|
|
@@ -594,53 +577,53 @@ const It = (t, n, S) => {
|
|
|
594
577
|
let g = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
|
|
595
578
|
if (!S || S.length === 0)
|
|
596
579
|
return g;
|
|
597
|
-
let y = g.map((
|
|
598
|
-
key:
|
|
599
|
-
value: e.getState().getShadowValue(
|
|
580
|
+
let y = g.map((I) => ({
|
|
581
|
+
key: I,
|
|
582
|
+
value: e.getState().getShadowValue(I)
|
|
600
583
|
}));
|
|
601
|
-
for (const
|
|
602
|
-
|
|
603
|
-
({ value:
|
|
604
|
-
) :
|
|
605
|
-
return y.map(({ key:
|
|
606
|
-
},
|
|
607
|
-
const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata:
|
|
608
|
-
!
|
|
584
|
+
for (const I of S)
|
|
585
|
+
I.type === "filter" ? y = y.filter(
|
|
586
|
+
({ value: V }, u) => I.fn(V, u)
|
|
587
|
+
) : I.type === "sort" && y.sort((V, u) => I.fn(V.value, u.value));
|
|
588
|
+
return y.map(({ key: I }) => I);
|
|
589
|
+
}, Et = (t, n, S) => {
|
|
590
|
+
const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), u = I(t, [])?.components?.get(g);
|
|
591
|
+
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, S, g);
|
|
609
592
|
}, ft = (t, n, S) => {
|
|
610
|
-
const g = e.getState(), y = g.getShadowMetadata(t, []),
|
|
611
|
-
y?.components && y.components.forEach((
|
|
612
|
-
(Array.isArray(
|
|
613
|
-
}), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((
|
|
614
|
-
y?.components?.get(
|
|
593
|
+
const g = e.getState(), y = g.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
|
|
594
|
+
y?.components && y.components.forEach((u, f) => {
|
|
595
|
+
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), I.add(f));
|
|
596
|
+
}), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
|
|
597
|
+
y?.components?.get(u)?.forceUpdate();
|
|
615
598
|
});
|
|
616
|
-
const
|
|
617
|
-
for (let
|
|
618
|
-
const f =
|
|
599
|
+
const V = g.getShadowMetadata(t, n);
|
|
600
|
+
for (let u of V?.arrayKeys || []) {
|
|
601
|
+
const f = u + ".selected", A = g.getShadowMetadata(
|
|
619
602
|
t,
|
|
620
603
|
f.split(".").slice(1)
|
|
621
604
|
);
|
|
622
|
-
|
|
623
|
-
y?.components?.get(
|
|
605
|
+
u == S && A?.pathComponents?.forEach((w) => {
|
|
606
|
+
y?.components?.get(w)?.forceUpdate();
|
|
624
607
|
});
|
|
625
608
|
}
|
|
626
609
|
};
|
|
627
610
|
function Dt(t, n, S, g) {
|
|
628
611
|
const y = /* @__PURE__ */ new Map();
|
|
629
|
-
let
|
|
630
|
-
const
|
|
631
|
-
const i =
|
|
612
|
+
let I = 0;
|
|
613
|
+
const V = (w) => {
|
|
614
|
+
const i = w.join(".");
|
|
632
615
|
for (const [h] of y)
|
|
633
616
|
(h === i || h.startsWith(i + ".")) && y.delete(h);
|
|
634
|
-
|
|
617
|
+
I++;
|
|
635
618
|
};
|
|
636
|
-
function
|
|
637
|
-
currentState:
|
|
619
|
+
function u({
|
|
620
|
+
currentState: w,
|
|
638
621
|
path: i = [],
|
|
639
622
|
meta: h,
|
|
640
|
-
componentId:
|
|
623
|
+
componentId: M
|
|
641
624
|
}) {
|
|
642
|
-
const z = i.map(String).join("."),
|
|
643
|
-
|
|
625
|
+
const z = i.map(String).join("."), c = [t, ...i].join(".");
|
|
626
|
+
w = e.getState().getShadowValue(c, h?.validIds);
|
|
644
627
|
const B = function() {
|
|
645
628
|
return e().getShadowValue(t, i);
|
|
646
629
|
}, J = {
|
|
@@ -648,7 +631,7 @@ function Dt(t, n, S, g) {
|
|
|
648
631
|
},
|
|
649
632
|
get(W, m) {
|
|
650
633
|
if (m === "_rebuildStateShape")
|
|
651
|
-
return
|
|
634
|
+
return u;
|
|
652
635
|
if (Object.getOwnPropertyNames(f).includes(m) && i.length === 0)
|
|
653
636
|
return f[m];
|
|
654
637
|
if (m === "getDifferences")
|
|
@@ -665,13 +648,13 @@ function Dt(t, n, S, g) {
|
|
|
665
648
|
const r = e.getState().getShadowValue(t, []), a = s?.validation?.key;
|
|
666
649
|
try {
|
|
667
650
|
const d = await o.action(r);
|
|
668
|
-
if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((
|
|
669
|
-
const p = [a, ...
|
|
670
|
-
e.getState().addValidationError(p,
|
|
651
|
+
if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((l) => {
|
|
652
|
+
const p = [a, ...l.path].join(".");
|
|
653
|
+
e.getState().addValidationError(p, l.message);
|
|
671
654
|
}), it(t)), d?.success) {
|
|
672
|
-
const
|
|
655
|
+
const l = e.getState().getShadowMetadata(t, []);
|
|
673
656
|
e.getState().setShadowMetadata(t, [], {
|
|
674
|
-
...
|
|
657
|
+
...l,
|
|
675
658
|
isDirty: !1,
|
|
676
659
|
lastServerSync: Date.now(),
|
|
677
660
|
stateSource: "server",
|
|
@@ -686,7 +669,7 @@ function Dt(t, n, S, g) {
|
|
|
686
669
|
};
|
|
687
670
|
if (m === "_status" || m === "getStatus") {
|
|
688
671
|
const s = () => {
|
|
689
|
-
const o = e.getState().getShadowMetadata(t, i), r = e.getState().getShadowValue(
|
|
672
|
+
const o = e.getState().getShadowMetadata(t, i), r = e.getState().getShadowValue(c);
|
|
690
673
|
return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" : r !== void 0 && !o ? "fresh" : "unknown";
|
|
691
674
|
};
|
|
692
675
|
return m === "_status" ? s() : s;
|
|
@@ -701,11 +684,11 @@ function Dt(t, n, S, g) {
|
|
|
701
684
|
const s = e.getState().getShadowMetadata(t, i);
|
|
702
685
|
return s?.validation?.status === "VALIDATION_FAILED" && s.validation.message ? [s.validation.message] : [];
|
|
703
686
|
};
|
|
704
|
-
if (Array.isArray(
|
|
687
|
+
if (Array.isArray(w)) {
|
|
705
688
|
if (m === "getSelected")
|
|
706
689
|
return () => {
|
|
707
690
|
const s = t + "." + i.join(".");
|
|
708
|
-
|
|
691
|
+
Et(t, M, [
|
|
709
692
|
...i,
|
|
710
693
|
"getSelected"
|
|
711
694
|
]);
|
|
@@ -717,10 +700,10 @@ function Dt(t, n, S, g) {
|
|
|
717
700
|
return;
|
|
718
701
|
const a = e.getState().getShadowValue(r);
|
|
719
702
|
if (a)
|
|
720
|
-
return
|
|
703
|
+
return u({
|
|
721
704
|
currentState: a,
|
|
722
705
|
path: r.split(".").slice(1),
|
|
723
|
-
componentId:
|
|
706
|
+
componentId: M
|
|
724
707
|
});
|
|
725
708
|
};
|
|
726
709
|
if (m === "getSelectedIndex")
|
|
@@ -741,10 +724,10 @@ function Dt(t, n, S, g) {
|
|
|
741
724
|
overscan: r = 6,
|
|
742
725
|
stickToBottom: a = !1,
|
|
743
726
|
scrollStickTolerance: d = 75
|
|
744
|
-
} = s,
|
|
727
|
+
} = s, l = q(null), [p, E] = K({
|
|
745
728
|
startIndex: 0,
|
|
746
729
|
endIndex: 10
|
|
747
|
-
}), [_,
|
|
730
|
+
}), [_, U] = K({}), C = q(!0), F = q({
|
|
748
731
|
isUserScrolling: !1,
|
|
749
732
|
lastScrollTop: 0,
|
|
750
733
|
scrollUpCount: 0,
|
|
@@ -753,60 +736,60 @@ function Dt(t, n, S, g) {
|
|
|
753
736
|
/* @__PURE__ */ new Map()
|
|
754
737
|
);
|
|
755
738
|
dt(() => {
|
|
756
|
-
if (!a || !
|
|
739
|
+
if (!a || !l.current || F.current.isUserScrolling)
|
|
757
740
|
return;
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
top:
|
|
741
|
+
const v = l.current;
|
|
742
|
+
v.scrollTo({
|
|
743
|
+
top: v.scrollHeight,
|
|
761
744
|
behavior: C.current ? "instant" : "smooth"
|
|
762
745
|
});
|
|
763
746
|
}, [_, a]);
|
|
764
747
|
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } = gt(() => {
|
|
765
|
-
let
|
|
766
|
-
const
|
|
748
|
+
let v = 0;
|
|
749
|
+
const T = /* @__PURE__ */ new Map();
|
|
767
750
|
return (e.getState().getShadowMetadata(t, i)?.arrayKeys || []).forEach((D) => {
|
|
768
751
|
const R = D.split(".").slice(1), L = e.getState().getShadowMetadata(t, R)?.virtualizer?.itemHeight || o;
|
|
769
|
-
|
|
752
|
+
T.set(D, {
|
|
770
753
|
height: L,
|
|
771
|
-
offset:
|
|
772
|
-
}),
|
|
773
|
-
}), x.current =
|
|
754
|
+
offset: v
|
|
755
|
+
}), v += L;
|
|
756
|
+
}), x.current = T, { totalHeight: v, itemOffsets: T };
|
|
774
757
|
}, [N.length, o]);
|
|
775
758
|
dt(() => {
|
|
776
|
-
if (a && N.length > 0 &&
|
|
777
|
-
const
|
|
778
|
-
if (
|
|
759
|
+
if (a && N.length > 0 && l.current && !F.current.isUserScrolling && C.current) {
|
|
760
|
+
const v = l.current, T = () => {
|
|
761
|
+
if (v.clientHeight > 0) {
|
|
779
762
|
const $ = Math.ceil(
|
|
780
|
-
|
|
763
|
+
v.clientHeight / o
|
|
781
764
|
), D = N.length - 1, R = Math.max(
|
|
782
765
|
0,
|
|
783
766
|
D - $ - r
|
|
784
767
|
);
|
|
785
|
-
|
|
786
|
-
|
|
768
|
+
E({ startIndex: R, endIndex: D }), requestAnimationFrame(() => {
|
|
769
|
+
P("instant"), C.current = !1;
|
|
787
770
|
});
|
|
788
771
|
} else
|
|
789
|
-
requestAnimationFrame(
|
|
772
|
+
requestAnimationFrame(T);
|
|
790
773
|
};
|
|
791
|
-
|
|
774
|
+
T();
|
|
792
775
|
}
|
|
793
776
|
}, [N.length, a, o, r]);
|
|
794
|
-
const
|
|
795
|
-
const
|
|
796
|
-
if (!
|
|
797
|
-
const
|
|
798
|
-
R.isNearBottom = L <= d,
|
|
777
|
+
const k = ct(() => {
|
|
778
|
+
const v = l.current;
|
|
779
|
+
if (!v) return;
|
|
780
|
+
const T = v.scrollTop, { scrollHeight: $, clientHeight: D } = v, R = F.current, L = $ - (T + D), G = R.isNearBottom;
|
|
781
|
+
R.isNearBottom = L <= d, T < R.lastScrollTop ? (R.scrollUpCount++, R.scrollUpCount > 3 && G && (R.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : R.isNearBottom && (R.isUserScrolling = !1, R.scrollUpCount = 0), R.lastScrollTop = T;
|
|
799
782
|
let tt = 0;
|
|
800
783
|
for (let et = 0; et < N.length; et++) {
|
|
801
784
|
const ht = N[et], mt = x.current.get(ht);
|
|
802
|
-
if (mt && mt.offset + mt.height >
|
|
785
|
+
if (mt && mt.offset + mt.height > T) {
|
|
803
786
|
tt = et;
|
|
804
787
|
break;
|
|
805
788
|
}
|
|
806
789
|
}
|
|
807
790
|
if (tt !== p.startIndex) {
|
|
808
791
|
const et = Math.ceil(D / o);
|
|
809
|
-
|
|
792
|
+
E({
|
|
810
793
|
startIndex: Math.max(0, tt - r),
|
|
811
794
|
endIndex: Math.min(
|
|
812
795
|
N.length - 1,
|
|
@@ -822,28 +805,28 @@ function Dt(t, n, S, g) {
|
|
|
822
805
|
d
|
|
823
806
|
]);
|
|
824
807
|
Z(() => {
|
|
825
|
-
const
|
|
826
|
-
if (!(!
|
|
827
|
-
return
|
|
808
|
+
const v = l.current;
|
|
809
|
+
if (!(!v || !a))
|
|
810
|
+
return v.addEventListener("scroll", k, {
|
|
828
811
|
passive: !0
|
|
829
812
|
}), () => {
|
|
830
|
-
|
|
813
|
+
v.removeEventListener("scroll", k);
|
|
831
814
|
};
|
|
832
|
-
}, [
|
|
833
|
-
const
|
|
834
|
-
(
|
|
835
|
-
const
|
|
836
|
-
if (!
|
|
815
|
+
}, [k, a]);
|
|
816
|
+
const P = ct(
|
|
817
|
+
(v = "smooth") => {
|
|
818
|
+
const T = l.current;
|
|
819
|
+
if (!T) return;
|
|
837
820
|
F.current.isUserScrolling = !1, F.current.isNearBottom = !0, F.current.scrollUpCount = 0;
|
|
838
821
|
const $ = () => {
|
|
839
822
|
const D = (R = 0) => {
|
|
840
823
|
if (R > 5) return;
|
|
841
|
-
const L =
|
|
842
|
-
G + tt >= L - 1 || (
|
|
824
|
+
const L = T.scrollHeight, G = T.scrollTop, tt = T.clientHeight;
|
|
825
|
+
G + tt >= L - 1 || (T.scrollTo({
|
|
843
826
|
top: L,
|
|
844
|
-
behavior:
|
|
827
|
+
behavior: v
|
|
845
828
|
}), setTimeout(() => {
|
|
846
|
-
const et =
|
|
829
|
+
const et = T.scrollHeight, ht = T.scrollTop;
|
|
847
830
|
(et !== L || ht + tt < et - 1) && D(R + 1);
|
|
848
831
|
}, 50));
|
|
849
832
|
};
|
|
@@ -856,19 +839,19 @@ function Dt(t, n, S, g) {
|
|
|
856
839
|
[]
|
|
857
840
|
);
|
|
858
841
|
return Z(() => {
|
|
859
|
-
if (!a || !
|
|
860
|
-
const
|
|
842
|
+
if (!a || !l.current) return;
|
|
843
|
+
const v = l.current, T = F.current;
|
|
861
844
|
let $;
|
|
862
845
|
const D = () => {
|
|
863
846
|
clearTimeout($), $ = setTimeout(() => {
|
|
864
|
-
!
|
|
847
|
+
!T.isUserScrolling && T.isNearBottom && P(
|
|
865
848
|
C.current ? "instant" : "smooth"
|
|
866
849
|
);
|
|
867
850
|
}, 100);
|
|
868
851
|
}, R = new MutationObserver(() => {
|
|
869
|
-
|
|
852
|
+
T.isUserScrolling || D();
|
|
870
853
|
});
|
|
871
|
-
R.observe(
|
|
854
|
+
R.observe(v, {
|
|
872
855
|
childList: !0,
|
|
873
856
|
subtree: !0,
|
|
874
857
|
attributes: !0,
|
|
@@ -876,34 +859,34 @@ function Dt(t, n, S, g) {
|
|
|
876
859
|
// More specific than just 'height'
|
|
877
860
|
});
|
|
878
861
|
const L = (G) => {
|
|
879
|
-
G.target instanceof HTMLImageElement && !
|
|
862
|
+
G.target instanceof HTMLImageElement && !T.isUserScrolling && D();
|
|
880
863
|
};
|
|
881
|
-
return
|
|
882
|
-
|
|
864
|
+
return v.addEventListener("load", L, !0), C.current ? setTimeout(() => {
|
|
865
|
+
P("instant");
|
|
883
866
|
}, 0) : D(), () => {
|
|
884
|
-
clearTimeout($), R.disconnect(),
|
|
867
|
+
clearTimeout($), R.disconnect(), v.removeEventListener("load", L, !0);
|
|
885
868
|
};
|
|
886
|
-
}, [a, N.length,
|
|
869
|
+
}, [a, N.length, P]), {
|
|
887
870
|
virtualState: gt(() => {
|
|
888
|
-
const
|
|
871
|
+
const v = e.getState(), T = v.getShadowValue(
|
|
889
872
|
[t, ...i].join(".")
|
|
890
|
-
), $ =
|
|
873
|
+
), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D = T.slice(
|
|
891
874
|
p.startIndex,
|
|
892
875
|
p.endIndex + 1
|
|
893
876
|
), R = $.slice(
|
|
894
877
|
p.startIndex,
|
|
895
878
|
p.endIndex + 1
|
|
896
879
|
);
|
|
897
|
-
return
|
|
880
|
+
return u({
|
|
898
881
|
currentState: D,
|
|
899
882
|
path: i,
|
|
900
|
-
componentId:
|
|
883
|
+
componentId: M,
|
|
901
884
|
meta: { ...h, validIds: R }
|
|
902
885
|
});
|
|
903
886
|
}, [p.startIndex, p.endIndex, N.length]),
|
|
904
887
|
virtualizerProps: {
|
|
905
888
|
outer: {
|
|
906
|
-
ref:
|
|
889
|
+
ref: l,
|
|
907
890
|
style: {
|
|
908
891
|
overflowY: "auto",
|
|
909
892
|
height: "100%",
|
|
@@ -924,11 +907,11 @@ function Dt(t, n, S, g) {
|
|
|
924
907
|
}
|
|
925
908
|
}
|
|
926
909
|
},
|
|
927
|
-
scrollToBottom:
|
|
928
|
-
scrollToIndex: (
|
|
929
|
-
if (
|
|
930
|
-
const $ = x.current.get(N[
|
|
931
|
-
|
|
910
|
+
scrollToBottom: P,
|
|
911
|
+
scrollToIndex: (v, T = "smooth") => {
|
|
912
|
+
if (l.current && N[v]) {
|
|
913
|
+
const $ = x.current.get(N[v])?.offset || 0;
|
|
914
|
+
l.current.scrollTo({ top: $, behavior: T });
|
|
932
915
|
}
|
|
933
916
|
}
|
|
934
917
|
};
|
|
@@ -937,20 +920,20 @@ function Dt(t, n, S, g) {
|
|
|
937
920
|
return (s) => {
|
|
938
921
|
const [o, r] = K(
|
|
939
922
|
h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys
|
|
940
|
-
), a = e.getState().getShadowValue(
|
|
923
|
+
), a = e.getState().getShadowValue(c, h?.validIds);
|
|
941
924
|
if (!o)
|
|
942
925
|
throw new Error("No array keys found for mapping");
|
|
943
|
-
const d =
|
|
926
|
+
const d = u({
|
|
944
927
|
currentState: a,
|
|
945
928
|
path: i,
|
|
946
|
-
componentId:
|
|
929
|
+
componentId: M,
|
|
947
930
|
meta: h
|
|
948
931
|
});
|
|
949
|
-
return a.map((
|
|
950
|
-
const
|
|
951
|
-
currentState:
|
|
952
|
-
path:
|
|
953
|
-
componentId:
|
|
932
|
+
return a.map((l, p) => {
|
|
933
|
+
const E = o[p]?.split(".").slice(1), _ = u({
|
|
934
|
+
currentState: l,
|
|
935
|
+
path: E,
|
|
936
|
+
componentId: M,
|
|
954
937
|
meta: h
|
|
955
938
|
});
|
|
956
939
|
return s(
|
|
@@ -968,7 +951,7 @@ function Dt(t, n, S, g) {
|
|
|
968
951
|
_mapFn: s,
|
|
969
952
|
_meta: h
|
|
970
953
|
},
|
|
971
|
-
rebuildStateShape:
|
|
954
|
+
rebuildStateShape: u
|
|
972
955
|
});
|
|
973
956
|
if (m === "stateFind")
|
|
974
957
|
return (s) => {
|
|
@@ -979,11 +962,11 @@ function Dt(t, n, S, g) {
|
|
|
979
962
|
if (!a) continue;
|
|
980
963
|
const d = e.getState().getShadowValue(a);
|
|
981
964
|
if (s(d, r)) {
|
|
982
|
-
const
|
|
983
|
-
return
|
|
965
|
+
const l = a.split(".").slice(1);
|
|
966
|
+
return u({
|
|
984
967
|
currentState: d,
|
|
985
|
-
path:
|
|
986
|
-
componentId:
|
|
968
|
+
path: l,
|
|
969
|
+
componentId: M,
|
|
987
970
|
meta: h
|
|
988
971
|
// Pass along meta for potential further chaining
|
|
989
972
|
});
|
|
@@ -995,13 +978,13 @@ function Dt(t, n, S, g) {
|
|
|
995
978
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
996
979
|
if (!o)
|
|
997
980
|
throw new Error("No array keys found for filtering.");
|
|
998
|
-
const r = [], a =
|
|
999
|
-
(d,
|
|
981
|
+
const r = [], a = w.filter(
|
|
982
|
+
(d, l) => s(d, l) ? (r.push(o[l]), !0) : !1
|
|
1000
983
|
);
|
|
1001
|
-
return
|
|
984
|
+
return u({
|
|
1002
985
|
currentState: a,
|
|
1003
986
|
path: i,
|
|
1004
|
-
componentId:
|
|
987
|
+
componentId: M,
|
|
1005
988
|
meta: {
|
|
1006
989
|
validIds: r,
|
|
1007
990
|
transforms: [
|
|
@@ -1019,14 +1002,14 @@ function Dt(t, n, S, g) {
|
|
|
1019
1002
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1020
1003
|
if (!o)
|
|
1021
1004
|
throw new Error("No array keys found for sorting");
|
|
1022
|
-
const r =
|
|
1005
|
+
const r = w.map((a, d) => ({
|
|
1023
1006
|
item: a,
|
|
1024
1007
|
key: o[d]
|
|
1025
1008
|
}));
|
|
1026
|
-
return r.sort((a, d) => s(a.item, d.item)).filter(Boolean),
|
|
1009
|
+
return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), u({
|
|
1027
1010
|
currentState: r.map((a) => a.item),
|
|
1028
1011
|
path: i,
|
|
1029
|
-
componentId:
|
|
1012
|
+
componentId: M,
|
|
1030
1013
|
meta: {
|
|
1031
1014
|
validIds: r.map((a) => a.key),
|
|
1032
1015
|
transforms: [
|
|
@@ -1043,11 +1026,11 @@ function Dt(t, n, S, g) {
|
|
|
1043
1026
|
flushInterval: r = 100,
|
|
1044
1027
|
bufferStrategy: a = "accumulate",
|
|
1045
1028
|
store: d,
|
|
1046
|
-
onFlush:
|
|
1029
|
+
onFlush: l
|
|
1047
1030
|
} = s;
|
|
1048
|
-
let p = [],
|
|
1049
|
-
const
|
|
1050
|
-
if (!
|
|
1031
|
+
let p = [], E = !1, _ = null;
|
|
1032
|
+
const U = (j) => {
|
|
1033
|
+
if (!E) {
|
|
1051
1034
|
if (a === "sliding" && p.length >= o)
|
|
1052
1035
|
p.shift();
|
|
1053
1036
|
else if (a === "dropping" && p.length >= o)
|
|
@@ -1059,8 +1042,8 @@ function Dt(t, n, S, g) {
|
|
|
1059
1042
|
const j = [...p];
|
|
1060
1043
|
if (p = [], d) {
|
|
1061
1044
|
const b = d(j);
|
|
1062
|
-
b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((
|
|
1063
|
-
n(
|
|
1045
|
+
b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((P) => {
|
|
1046
|
+
n(P, i, {
|
|
1064
1047
|
updateType: "insert"
|
|
1065
1048
|
});
|
|
1066
1049
|
});
|
|
@@ -1070,7 +1053,7 @@ function Dt(t, n, S, g) {
|
|
|
1070
1053
|
updateType: "insert"
|
|
1071
1054
|
});
|
|
1072
1055
|
});
|
|
1073
|
-
|
|
1056
|
+
l?.(j);
|
|
1074
1057
|
};
|
|
1075
1058
|
r > 0 && (_ = setInterval(C, r));
|
|
1076
1059
|
const F = rt(), x = e.getState().getShadowMetadata(t, i) || {}, N = x.streams || /* @__PURE__ */ new Map();
|
|
@@ -1078,14 +1061,14 @@ function Dt(t, n, S, g) {
|
|
|
1078
1061
|
...x,
|
|
1079
1062
|
streams: N
|
|
1080
1063
|
}), {
|
|
1081
|
-
write: (j) =>
|
|
1082
|
-
writeMany: (j) => j.forEach(
|
|
1064
|
+
write: (j) => U(j),
|
|
1065
|
+
writeMany: (j) => j.forEach(U),
|
|
1083
1066
|
flush: () => C(),
|
|
1084
1067
|
pause: () => {
|
|
1085
|
-
|
|
1068
|
+
E = !0;
|
|
1086
1069
|
},
|
|
1087
1070
|
resume: () => {
|
|
1088
|
-
|
|
1071
|
+
E = !1, p.length > 0 && C();
|
|
1089
1072
|
},
|
|
1090
1073
|
close: () => {
|
|
1091
1074
|
C(), _ && clearInterval(_);
|
|
@@ -1096,10 +1079,10 @@ function Dt(t, n, S, g) {
|
|
|
1096
1079
|
};
|
|
1097
1080
|
if (m === "stateList")
|
|
1098
1081
|
return (s) => /* @__PURE__ */ ot(() => {
|
|
1099
|
-
const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${
|
|
1100
|
-
const
|
|
1082
|
+
const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${M}-${Bt(h.transforms)}` : `${M}-base`, [d, l] = K({}), { validIds: p, arrayValues: E } = gt(() => {
|
|
1083
|
+
const U = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
|
|
1101
1084
|
let C;
|
|
1102
|
-
|
|
1085
|
+
U && U.validIds ? C = U.validIds : (C = It(
|
|
1103
1086
|
t,
|
|
1104
1087
|
i,
|
|
1105
1088
|
h?.transforms
|
|
@@ -1108,37 +1091,37 @@ function Dt(t, n, S, g) {
|
|
|
1108
1091
|
computedAt: Date.now(),
|
|
1109
1092
|
transforms: h?.transforms || []
|
|
1110
1093
|
}));
|
|
1111
|
-
const F = e.getState().getShadowValue(
|
|
1094
|
+
const F = e.getState().getShadowValue(c, C);
|
|
1112
1095
|
return {
|
|
1113
1096
|
validIds: C,
|
|
1114
1097
|
arrayValues: F || []
|
|
1115
1098
|
};
|
|
1116
1099
|
}, [a, d]);
|
|
1117
1100
|
if (Z(() => {
|
|
1118
|
-
const
|
|
1101
|
+
const U = e.getState().subscribeToPath(c, (C) => {
|
|
1119
1102
|
if (C.type === "GET_SELECTED")
|
|
1120
1103
|
return;
|
|
1121
1104
|
const x = e.getState().getShadowMetadata(t, i)?.transformCaches;
|
|
1122
1105
|
if (x)
|
|
1123
1106
|
for (const N of x.keys())
|
|
1124
|
-
N.startsWith(
|
|
1125
|
-
(C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") &&
|
|
1107
|
+
N.startsWith(M) && x.delete(N);
|
|
1108
|
+
(C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") && l({});
|
|
1126
1109
|
});
|
|
1127
1110
|
return () => {
|
|
1128
|
-
|
|
1111
|
+
U();
|
|
1129
1112
|
};
|
|
1130
|
-
}, [
|
|
1113
|
+
}, [M, c]), !Array.isArray(E))
|
|
1131
1114
|
return null;
|
|
1132
|
-
const _ =
|
|
1133
|
-
currentState:
|
|
1115
|
+
const _ = u({
|
|
1116
|
+
currentState: E,
|
|
1134
1117
|
path: i,
|
|
1135
|
-
componentId:
|
|
1118
|
+
componentId: M,
|
|
1136
1119
|
meta: {
|
|
1137
1120
|
...h,
|
|
1138
1121
|
validIds: p
|
|
1139
1122
|
}
|
|
1140
1123
|
});
|
|
1141
|
-
return /* @__PURE__ */ ot(
|
|
1124
|
+
return /* @__PURE__ */ ot(Ut, { children: E.map((U, C) => {
|
|
1142
1125
|
const F = p[C];
|
|
1143
1126
|
if (!F)
|
|
1144
1127
|
return null;
|
|
@@ -1152,36 +1135,36 @@ function Dt(t, n, S, g) {
|
|
|
1152
1135
|
itemPath: N,
|
|
1153
1136
|
localIndex: C,
|
|
1154
1137
|
arraySetter: _,
|
|
1155
|
-
rebuildStateShape:
|
|
1138
|
+
rebuildStateShape: u,
|
|
1156
1139
|
renderFn: s
|
|
1157
1140
|
});
|
|
1158
1141
|
}) });
|
|
1159
1142
|
}, {});
|
|
1160
1143
|
if (m === "stateFlattenOn")
|
|
1161
1144
|
return (s) => {
|
|
1162
|
-
const o =
|
|
1163
|
-
y.clear(),
|
|
1145
|
+
const o = w;
|
|
1146
|
+
y.clear(), I++;
|
|
1164
1147
|
const r = o.flatMap(
|
|
1165
1148
|
(a) => a[s] ?? []
|
|
1166
1149
|
);
|
|
1167
|
-
return
|
|
1150
|
+
return u({
|
|
1168
1151
|
currentState: r,
|
|
1169
1152
|
path: [...i, "[*]", s],
|
|
1170
|
-
componentId:
|
|
1153
|
+
componentId: M,
|
|
1171
1154
|
meta: h
|
|
1172
1155
|
});
|
|
1173
1156
|
};
|
|
1174
1157
|
if (m === "index")
|
|
1175
1158
|
return (s) => {
|
|
1176
1159
|
const r = e.getState().getShadowMetadata(t, i)?.arrayKeys?.filter(
|
|
1177
|
-
(
|
|
1160
|
+
(l) => !h?.validIds || h?.validIds && h?.validIds?.includes(l)
|
|
1178
1161
|
)?.[s];
|
|
1179
1162
|
if (!r) return;
|
|
1180
1163
|
const a = e.getState().getShadowValue(r, h?.validIds);
|
|
1181
|
-
return
|
|
1164
|
+
return u({
|
|
1182
1165
|
currentState: a,
|
|
1183
1166
|
path: r.split(".").slice(1),
|
|
1184
|
-
componentId:
|
|
1167
|
+
componentId: M,
|
|
1185
1168
|
meta: h
|
|
1186
1169
|
});
|
|
1187
1170
|
};
|
|
@@ -1190,36 +1173,36 @@ function Dt(t, n, S, g) {
|
|
|
1190
1173
|
const s = e.getState().getShadowValue(t, i);
|
|
1191
1174
|
if (s.length === 0) return;
|
|
1192
1175
|
const o = s.length - 1, r = s[o], a = [...i, o.toString()];
|
|
1193
|
-
return
|
|
1176
|
+
return u({
|
|
1194
1177
|
currentState: r,
|
|
1195
1178
|
path: a,
|
|
1196
|
-
componentId:
|
|
1179
|
+
componentId: M,
|
|
1197
1180
|
meta: h
|
|
1198
1181
|
});
|
|
1199
1182
|
};
|
|
1200
1183
|
if (m === "insert")
|
|
1201
|
-
return (s, o) => (n(s, i, { updateType: "insert" }),
|
|
1184
|
+
return (s, o) => (n(s, i, { updateType: "insert" }), u({
|
|
1202
1185
|
currentState: e.getState().getShadowValue(t, i),
|
|
1203
1186
|
path: i,
|
|
1204
|
-
componentId:
|
|
1187
|
+
componentId: M,
|
|
1205
1188
|
meta: h
|
|
1206
1189
|
}));
|
|
1207
1190
|
if (m === "uniqueInsert")
|
|
1208
1191
|
return (s, o, r) => {
|
|
1209
1192
|
const a = e.getState().getShadowValue(t, i), d = at(s) ? s(a) : s;
|
|
1210
|
-
let
|
|
1211
|
-
if (!a.some((
|
|
1193
|
+
let l = null;
|
|
1194
|
+
if (!a.some((E) => {
|
|
1212
1195
|
const _ = o ? o.every(
|
|
1213
|
-
(
|
|
1214
|
-
) : st(
|
|
1215
|
-
return _ && (
|
|
1196
|
+
(U) => st(E[U], d[U])
|
|
1197
|
+
) : st(E, d);
|
|
1198
|
+
return _ && (l = E), _;
|
|
1216
1199
|
}))
|
|
1217
|
-
|
|
1218
|
-
else if (r &&
|
|
1219
|
-
const
|
|
1220
|
-
(
|
|
1200
|
+
V(i), n(d, i, { updateType: "insert" });
|
|
1201
|
+
else if (r && l) {
|
|
1202
|
+
const E = r(l), _ = a.map(
|
|
1203
|
+
(U) => st(U, l) ? E : U
|
|
1221
1204
|
);
|
|
1222
|
-
|
|
1205
|
+
V(i), n(_, i, {
|
|
1223
1206
|
updateType: "update"
|
|
1224
1207
|
});
|
|
1225
1208
|
}
|
|
@@ -1230,8 +1213,8 @@ function Dt(t, n, S, g) {
|
|
|
1230
1213
|
if (!r || r.length === 0) return;
|
|
1231
1214
|
const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
|
|
1232
1215
|
if (!d) return;
|
|
1233
|
-
const
|
|
1234
|
-
n(
|
|
1216
|
+
const l = d.split(".").slice(1);
|
|
1217
|
+
n(w, l, {
|
|
1235
1218
|
updateType: "cut"
|
|
1236
1219
|
});
|
|
1237
1220
|
};
|
|
@@ -1243,14 +1226,14 @@ function Dt(t, n, S, g) {
|
|
|
1243
1226
|
h?.transforms
|
|
1244
1227
|
);
|
|
1245
1228
|
if (!s || s.length === 0) return;
|
|
1246
|
-
const o = e.getState().selectedIndicesMap.get(
|
|
1229
|
+
const o = e.getState().selectedIndicesMap.get(c);
|
|
1247
1230
|
let r = s.findIndex(
|
|
1248
|
-
(
|
|
1231
|
+
(l) => l === o
|
|
1249
1232
|
);
|
|
1250
1233
|
const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
|
|
1251
|
-
e.getState().clearSelectedIndex({ arrayKey:
|
|
1234
|
+
e.getState().clearSelectedIndex({ arrayKey: c });
|
|
1252
1235
|
const d = a?.slice(0, -1);
|
|
1253
|
-
ft(t, d), n(
|
|
1236
|
+
ft(t, d), n(w, a, {
|
|
1254
1237
|
updateType: "cut"
|
|
1255
1238
|
});
|
|
1256
1239
|
};
|
|
@@ -1275,8 +1258,8 @@ function Dt(t, n, S, g) {
|
|
|
1275
1258
|
if (!r) return;
|
|
1276
1259
|
let a = null;
|
|
1277
1260
|
for (const d of r) {
|
|
1278
|
-
const
|
|
1279
|
-
if (console.log("itemValue sdasdasdasd",
|
|
1261
|
+
const l = e.getState().getShadowValue(d);
|
|
1262
|
+
if (console.log("itemValue sdasdasdasd", l), l === s) {
|
|
1280
1263
|
a = d;
|
|
1281
1264
|
break;
|
|
1282
1265
|
}
|
|
@@ -1295,17 +1278,17 @@ function Dt(t, n, S, g) {
|
|
|
1295
1278
|
if (!r)
|
|
1296
1279
|
throw new Error("No array keys found for sorting");
|
|
1297
1280
|
let a = null, d = [];
|
|
1298
|
-
for (const
|
|
1299
|
-
let p = e.getState().getShadowValue(
|
|
1281
|
+
for (const l of r) {
|
|
1282
|
+
let p = e.getState().getShadowValue(l, h?.validIds);
|
|
1300
1283
|
if (p && p[s] === o) {
|
|
1301
|
-
a = p, d =
|
|
1284
|
+
a = p, d = l.split(".").slice(1);
|
|
1302
1285
|
break;
|
|
1303
1286
|
}
|
|
1304
1287
|
}
|
|
1305
|
-
return
|
|
1288
|
+
return u({
|
|
1306
1289
|
currentState: a,
|
|
1307
1290
|
path: d,
|
|
1308
|
-
componentId:
|
|
1291
|
+
componentId: M,
|
|
1309
1292
|
meta: h
|
|
1310
1293
|
});
|
|
1311
1294
|
};
|
|
@@ -1317,9 +1300,9 @@ function Dt(t, n, S, g) {
|
|
|
1317
1300
|
};
|
|
1318
1301
|
}
|
|
1319
1302
|
if (m === "get")
|
|
1320
|
-
return () => (
|
|
1303
|
+
return () => (Et(t, M, i), e.getState().getShadowValue(c, h?.validIds));
|
|
1321
1304
|
if (m === "getState")
|
|
1322
|
-
return () => e.getState().getShadowValue(
|
|
1305
|
+
return () => e.getState().getShadowValue(c, h?.validIds);
|
|
1323
1306
|
if (m === "$derive")
|
|
1324
1307
|
return (s) => bt({
|
|
1325
1308
|
_stateKey: t,
|
|
@@ -1357,7 +1340,7 @@ function Dt(t, n, S, g) {
|
|
|
1357
1340
|
e.getState().selectedIndicesMap.get(o) === r ? e.getState().clearSelectedIndex({ arrayKey: o }) : e.getState().setSelectedIndex(o, r);
|
|
1358
1341
|
};
|
|
1359
1342
|
if (m === "_componentId")
|
|
1360
|
-
return
|
|
1343
|
+
return M;
|
|
1361
1344
|
if (i.length == 0) {
|
|
1362
1345
|
if (m === "addValidation")
|
|
1363
1346
|
return (s) => {
|
|
@@ -1372,21 +1355,21 @@ function Dt(t, n, S, g) {
|
|
|
1372
1355
|
return (s) => {
|
|
1373
1356
|
const o = e.getState(), r = o.getShadowMetadata(t, []);
|
|
1374
1357
|
if (!r?.components) return;
|
|
1375
|
-
const a = (
|
|
1376
|
-
for (const
|
|
1377
|
-
const p = a(
|
|
1378
|
-
switch (
|
|
1358
|
+
const a = (l) => !l || l === "/" ? [] : l.split("/").slice(1).map((p) => p.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
|
|
1359
|
+
for (const l of s) {
|
|
1360
|
+
const p = a(l.path);
|
|
1361
|
+
switch (l.op) {
|
|
1379
1362
|
case "add":
|
|
1380
1363
|
case "replace": {
|
|
1381
|
-
const { value:
|
|
1382
|
-
o.updateShadowAtPath(t, p,
|
|
1364
|
+
const { value: E } = l;
|
|
1365
|
+
o.updateShadowAtPath(t, p, E), o.markAsDirty(t, p, { bubble: !0 });
|
|
1383
1366
|
let _ = [...p];
|
|
1384
1367
|
for (; ; ) {
|
|
1385
|
-
const
|
|
1368
|
+
const U = o.getShadowMetadata(
|
|
1386
1369
|
t,
|
|
1387
1370
|
_
|
|
1388
1371
|
);
|
|
1389
|
-
if (console.log("pathMeta",
|
|
1372
|
+
if (console.log("pathMeta", U), U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1390
1373
|
if (!d.has(C)) {
|
|
1391
1374
|
const F = r.components?.get(C);
|
|
1392
1375
|
F && (F.forceUpdate(), d.add(C));
|
|
@@ -1397,15 +1380,15 @@ function Dt(t, n, S, g) {
|
|
|
1397
1380
|
break;
|
|
1398
1381
|
}
|
|
1399
1382
|
case "remove": {
|
|
1400
|
-
const
|
|
1401
|
-
o.removeShadowArrayElement(t, p), o.markAsDirty(t,
|
|
1402
|
-
let _ = [...
|
|
1383
|
+
const E = p.slice(0, -1);
|
|
1384
|
+
o.removeShadowArrayElement(t, p), o.markAsDirty(t, E, { bubble: !0 });
|
|
1385
|
+
let _ = [...E];
|
|
1403
1386
|
for (; ; ) {
|
|
1404
|
-
const
|
|
1387
|
+
const U = o.getShadowMetadata(
|
|
1405
1388
|
t,
|
|
1406
1389
|
_
|
|
1407
1390
|
);
|
|
1408
|
-
if (
|
|
1391
|
+
if (U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1409
1392
|
if (!d.has(C)) {
|
|
1410
1393
|
const F = r.components?.get(C);
|
|
1411
1394
|
F && (F.forceUpdate(), d.add(C));
|
|
@@ -1428,11 +1411,11 @@ function Dt(t, n, S, g) {
|
|
|
1428
1411
|
ut(s.key);
|
|
1429
1412
|
const r = e.getState().getShadowValue(t), a = o.safeParse(r);
|
|
1430
1413
|
return a.success ? !0 : ("issues" in a.error ? a.error.issues.forEach((d) => {
|
|
1431
|
-
const
|
|
1432
|
-
pt(
|
|
1414
|
+
const l = [s.key, ...d.path].join(".");
|
|
1415
|
+
pt(l, d.message);
|
|
1433
1416
|
}) : a.error.errors.forEach((d) => {
|
|
1434
|
-
const
|
|
1435
|
-
pt(
|
|
1417
|
+
const l = [s.key, ...d.path].join(".");
|
|
1418
|
+
pt(l, d.message);
|
|
1436
1419
|
}), it(t), !1);
|
|
1437
1420
|
};
|
|
1438
1421
|
if (m === "getComponents")
|
|
@@ -1447,7 +1430,7 @@ function Dt(t, n, S, g) {
|
|
|
1447
1430
|
children: s,
|
|
1448
1431
|
hideMessage: o
|
|
1449
1432
|
}) => /* @__PURE__ */ ot(
|
|
1450
|
-
|
|
1433
|
+
kt,
|
|
1451
1434
|
{
|
|
1452
1435
|
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
1453
1436
|
path: i,
|
|
@@ -1482,7 +1465,7 @@ function Dt(t, n, S, g) {
|
|
|
1482
1465
|
});
|
|
1483
1466
|
if (m === "toggle") {
|
|
1484
1467
|
const s = e.getState().getShadowValue([t, ...i].join("."));
|
|
1485
|
-
if (console.log("currentValueAtPath", s), typeof
|
|
1468
|
+
if (console.log("currentValueAtPath", s), typeof w != "boolean")
|
|
1486
1469
|
throw new Error("toggle() can only be used on boolean values");
|
|
1487
1470
|
return () => {
|
|
1488
1471
|
n(!s, i, {
|
|
@@ -1496,58 +1479,58 @@ function Dt(t, n, S, g) {
|
|
|
1496
1479
|
{
|
|
1497
1480
|
stateKey: t,
|
|
1498
1481
|
path: i,
|
|
1499
|
-
rebuildStateShape:
|
|
1482
|
+
rebuildStateShape: u,
|
|
1500
1483
|
setState: n,
|
|
1501
1484
|
formOpts: o,
|
|
1502
1485
|
renderFn: s
|
|
1503
1486
|
}
|
|
1504
1487
|
);
|
|
1505
1488
|
const Q = [...i, m], X = e.getState().getShadowValue(t, Q);
|
|
1506
|
-
return
|
|
1489
|
+
return u({
|
|
1507
1490
|
currentState: X,
|
|
1508
1491
|
path: Q,
|
|
1509
|
-
componentId:
|
|
1492
|
+
componentId: M,
|
|
1510
1493
|
meta: h
|
|
1511
1494
|
});
|
|
1512
1495
|
}
|
|
1513
1496
|
}, H = new Proxy(B, J);
|
|
1514
1497
|
return y.set(z, {
|
|
1515
1498
|
proxy: H,
|
|
1516
|
-
stateVersion:
|
|
1499
|
+
stateVersion: I
|
|
1517
1500
|
}), H;
|
|
1518
1501
|
}
|
|
1519
1502
|
const f = {
|
|
1520
|
-
removeValidation: (
|
|
1521
|
-
|
|
1503
|
+
removeValidation: (w) => {
|
|
1504
|
+
w?.validationKey && ut(w.validationKey);
|
|
1522
1505
|
},
|
|
1523
|
-
revertToInitialState: (
|
|
1506
|
+
revertToInitialState: (w) => {
|
|
1524
1507
|
const i = e.getState().getInitialOptions(t)?.validation;
|
|
1525
|
-
i?.key && ut(i.key),
|
|
1508
|
+
i?.key && ut(i.key), w?.validationKey && ut(w.validationKey);
|
|
1526
1509
|
const h = e.getState().getShadowMetadata(t, []);
|
|
1527
1510
|
h?.stateSource === "server" && h.baseServerState ? h.baseServerState : e.getState().initialStateGlobal[t];
|
|
1528
|
-
const
|
|
1529
|
-
e.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
1530
|
-
currentState:
|
|
1511
|
+
const M = e.getState().initialStateGlobal[t];
|
|
1512
|
+
e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, M), u({
|
|
1513
|
+
currentState: M,
|
|
1531
1514
|
path: [],
|
|
1532
1515
|
componentId: S
|
|
1533
1516
|
});
|
|
1534
|
-
const z = nt(t),
|
|
1517
|
+
const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${g}-${t}-${c}`;
|
|
1535
1518
|
B && localStorage.removeItem(B);
|
|
1536
1519
|
const J = e.getState().getShadowMetadata(t, []);
|
|
1537
1520
|
return J && J?.components?.forEach((H) => {
|
|
1538
1521
|
H.forceUpdate();
|
|
1539
|
-
}),
|
|
1522
|
+
}), M;
|
|
1540
1523
|
},
|
|
1541
|
-
updateInitialState: (
|
|
1542
|
-
y.clear(),
|
|
1524
|
+
updateInitialState: (w) => {
|
|
1525
|
+
y.clear(), I++;
|
|
1543
1526
|
const i = Dt(
|
|
1544
1527
|
t,
|
|
1545
1528
|
n,
|
|
1546
1529
|
S,
|
|
1547
1530
|
g
|
|
1548
|
-
), h = e.getState().initialStateGlobal[t],
|
|
1549
|
-
return localStorage.getItem(
|
|
1550
|
-
_t(t,
|
|
1531
|
+
), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${g}-${t}-${z}`;
|
|
1532
|
+
return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
|
|
1533
|
+
_t(t, w), e.getState().initializeShadowState(t, w);
|
|
1551
1534
|
const B = e.getState().getShadowMetadata(t, []);
|
|
1552
1535
|
B && B?.components?.forEach((J) => {
|
|
1553
1536
|
J.forceUpdate();
|
|
@@ -1557,7 +1540,7 @@ function Dt(t, n, S, g) {
|
|
|
1557
1540
|
};
|
|
1558
1541
|
}
|
|
1559
1542
|
};
|
|
1560
|
-
return
|
|
1543
|
+
return u({
|
|
1561
1544
|
currentState: e.getState().getShadowValue(t, []),
|
|
1562
1545
|
componentId: S,
|
|
1563
1546
|
path: []
|
|
@@ -1570,64 +1553,64 @@ function qt({
|
|
|
1570
1553
|
proxy: t,
|
|
1571
1554
|
rebuildStateShape: n
|
|
1572
1555
|
}) {
|
|
1573
|
-
const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1),
|
|
1556
|
+
const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), I = q(/* @__PURE__ */ new Map());
|
|
1574
1557
|
Z(() => {
|
|
1575
|
-
const
|
|
1576
|
-
if (!
|
|
1558
|
+
const u = S.current;
|
|
1559
|
+
if (!u || y.current) return;
|
|
1577
1560
|
const f = setTimeout(() => {
|
|
1578
|
-
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {},
|
|
1579
|
-
|
|
1561
|
+
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, w = A.mapWrappers || [];
|
|
1562
|
+
w.push({
|
|
1580
1563
|
instanceId: g.current,
|
|
1581
1564
|
mapFn: t._mapFn,
|
|
1582
|
-
containerRef:
|
|
1565
|
+
containerRef: u,
|
|
1583
1566
|
rebuildStateShape: n,
|
|
1584
1567
|
path: t._path,
|
|
1585
1568
|
componentId: g.current,
|
|
1586
1569
|
meta: t._meta
|
|
1587
1570
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1588
1571
|
...A,
|
|
1589
|
-
mapWrappers:
|
|
1590
|
-
}), y.current = !0,
|
|
1572
|
+
mapWrappers: w
|
|
1573
|
+
}), y.current = !0, V();
|
|
1591
1574
|
}, 0);
|
|
1592
1575
|
return () => {
|
|
1593
1576
|
if (clearTimeout(f), g.current) {
|
|
1594
1577
|
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1595
1578
|
A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
|
|
1596
|
-
(
|
|
1579
|
+
(w) => w.instanceId !== g.current
|
|
1597
1580
|
), e.getState().setShadowMetadata(t._stateKey, t._path, A));
|
|
1598
1581
|
}
|
|
1599
|
-
|
|
1582
|
+
I.current.forEach((A) => A.unmount());
|
|
1600
1583
|
};
|
|
1601
1584
|
}, []);
|
|
1602
|
-
const
|
|
1603
|
-
const
|
|
1604
|
-
if (!
|
|
1585
|
+
const V = () => {
|
|
1586
|
+
const u = S.current;
|
|
1587
|
+
if (!u) return;
|
|
1605
1588
|
const f = e.getState().getShadowValue(
|
|
1606
1589
|
[t._stateKey, ...t._path].join("."),
|
|
1607
1590
|
t._meta?.validIds
|
|
1608
1591
|
);
|
|
1609
1592
|
if (!Array.isArray(f)) return;
|
|
1610
|
-
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [],
|
|
1593
|
+
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w = n({
|
|
1611
1594
|
currentState: f,
|
|
1612
1595
|
path: t._path,
|
|
1613
1596
|
componentId: g.current,
|
|
1614
1597
|
meta: t._meta
|
|
1615
1598
|
});
|
|
1616
1599
|
f.forEach((i, h) => {
|
|
1617
|
-
const
|
|
1618
|
-
if (!
|
|
1619
|
-
const z = rt(),
|
|
1620
|
-
|
|
1621
|
-
const B = At(
|
|
1622
|
-
|
|
1623
|
-
const J =
|
|
1600
|
+
const M = A[h];
|
|
1601
|
+
if (!M) return;
|
|
1602
|
+
const z = rt(), c = document.createElement("div");
|
|
1603
|
+
c.setAttribute("data-item-path", M), u.appendChild(c);
|
|
1604
|
+
const B = At(c);
|
|
1605
|
+
I.current.set(M, B);
|
|
1606
|
+
const J = M.split(".").slice(1);
|
|
1624
1607
|
B.render(
|
|
1625
1608
|
lt(Mt, {
|
|
1626
1609
|
stateKey: t._stateKey,
|
|
1627
1610
|
itemComponentId: z,
|
|
1628
1611
|
itemPath: J,
|
|
1629
1612
|
localIndex: h,
|
|
1630
|
-
arraySetter:
|
|
1613
|
+
arraySetter: w,
|
|
1631
1614
|
rebuildStateShape: n,
|
|
1632
1615
|
renderFn: t._mapFn
|
|
1633
1616
|
})
|
|
@@ -1639,47 +1622,47 @@ function qt({
|
|
|
1639
1622
|
function Gt({
|
|
1640
1623
|
proxy: t
|
|
1641
1624
|
}) {
|
|
1642
|
-
const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`,
|
|
1625
|
+
const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, I = e.getState().getShadowValue(
|
|
1643
1626
|
[t._stateKey, ...t._path].join("."),
|
|
1644
1627
|
t._meta?.validIds
|
|
1645
1628
|
);
|
|
1646
1629
|
return Z(() => {
|
|
1647
|
-
const
|
|
1648
|
-
if (!
|
|
1649
|
-
const
|
|
1650
|
-
if (!
|
|
1630
|
+
const V = n.current;
|
|
1631
|
+
if (!V || g.current) return;
|
|
1632
|
+
const u = setTimeout(() => {
|
|
1633
|
+
if (!V.parentElement) {
|
|
1651
1634
|
console.warn("Parent element not found for signal", y);
|
|
1652
1635
|
return;
|
|
1653
1636
|
}
|
|
1654
|
-
const f =
|
|
1637
|
+
const f = V.parentElement, w = Array.from(f.childNodes).indexOf(V);
|
|
1655
1638
|
let i = f.getAttribute("data-parent-id");
|
|
1656
1639
|
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), S.current = `instance-${crypto.randomUUID()}`;
|
|
1657
|
-
const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {},
|
|
1658
|
-
|
|
1640
|
+
const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
|
|
1641
|
+
M.push({
|
|
1659
1642
|
instanceId: S.current,
|
|
1660
1643
|
parentId: i,
|
|
1661
|
-
position:
|
|
1644
|
+
position: w,
|
|
1662
1645
|
effect: t._effect
|
|
1663
1646
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1664
1647
|
...h,
|
|
1665
|
-
signals:
|
|
1648
|
+
signals: M
|
|
1666
1649
|
});
|
|
1667
|
-
let z =
|
|
1650
|
+
let z = I;
|
|
1668
1651
|
if (t._effect)
|
|
1669
1652
|
try {
|
|
1670
1653
|
z = new Function(
|
|
1671
1654
|
"state",
|
|
1672
1655
|
`return (${t._effect})(state)`
|
|
1673
|
-
)(
|
|
1656
|
+
)(I);
|
|
1674
1657
|
} catch (B) {
|
|
1675
1658
|
console.error("Error evaluating effect function:", B);
|
|
1676
1659
|
}
|
|
1677
1660
|
z !== null && typeof z == "object" && (z = JSON.stringify(z));
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1661
|
+
const c = document.createTextNode(String(z ?? ""));
|
|
1662
|
+
V.replaceWith(c), g.current = !0;
|
|
1680
1663
|
}, 0);
|
|
1681
1664
|
return () => {
|
|
1682
|
-
if (clearTimeout(
|
|
1665
|
+
if (clearTimeout(u), S.current) {
|
|
1683
1666
|
const f = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1684
1667
|
f.signals && (f.signals = f.signals.filter(
|
|
1685
1668
|
(A) => A.instanceId !== S.current
|
|
@@ -1692,7 +1675,7 @@ function Gt({
|
|
|
1692
1675
|
"data-signal-id": y
|
|
1693
1676
|
});
|
|
1694
1677
|
}
|
|
1695
|
-
const Mt =
|
|
1678
|
+
const Mt = Ot(
|
|
1696
1679
|
Yt,
|
|
1697
1680
|
(t, n) => t.itemPath.join(".") === n.itemPath.join(".") && t.stateKey === n.stateKey && t.itemComponentId === n.itemComponentId && t.localIndex === n.localIndex
|
|
1698
1681
|
), Jt = (t) => {
|
|
@@ -1708,14 +1691,14 @@ const Mt = Ut(
|
|
|
1708
1691
|
return;
|
|
1709
1692
|
}
|
|
1710
1693
|
let y = 0;
|
|
1711
|
-
const
|
|
1694
|
+
const I = () => {
|
|
1712
1695
|
y++, y === g.length && S(!0);
|
|
1713
1696
|
};
|
|
1714
|
-
return g.forEach((
|
|
1715
|
-
|
|
1697
|
+
return g.forEach((V) => {
|
|
1698
|
+
V.complete ? I() : (V.addEventListener("load", I), V.addEventListener("error", I));
|
|
1716
1699
|
}), () => {
|
|
1717
|
-
g.forEach((
|
|
1718
|
-
|
|
1700
|
+
g.forEach((V) => {
|
|
1701
|
+
V.removeEventListener("load", I), V.removeEventListener("error", I);
|
|
1719
1702
|
});
|
|
1720
1703
|
};
|
|
1721
1704
|
}, [t.current]), n;
|
|
@@ -1726,25 +1709,25 @@ function Yt({
|
|
|
1726
1709
|
itemPath: S,
|
|
1727
1710
|
localIndex: g,
|
|
1728
1711
|
arraySetter: y,
|
|
1729
|
-
rebuildStateShape:
|
|
1730
|
-
renderFn:
|
|
1712
|
+
rebuildStateShape: I,
|
|
1713
|
+
renderFn: V
|
|
1731
1714
|
}) {
|
|
1732
|
-
const [,
|
|
1733
|
-
$t(t, n,
|
|
1715
|
+
const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...S].join(".");
|
|
1716
|
+
$t(t, n, u);
|
|
1734
1717
|
const z = ct(
|
|
1735
1718
|
(W) => {
|
|
1736
|
-
|
|
1719
|
+
w.current = W, f(W);
|
|
1737
1720
|
},
|
|
1738
1721
|
[f]
|
|
1739
1722
|
);
|
|
1740
1723
|
Z(() => {
|
|
1741
|
-
e.getState().subscribeToPath(
|
|
1742
|
-
|
|
1724
|
+
e.getState().subscribeToPath(M, (W) => {
|
|
1725
|
+
u({});
|
|
1743
1726
|
});
|
|
1744
1727
|
}, []), Z(() => {
|
|
1745
1728
|
if (!A || !i || h.current)
|
|
1746
1729
|
return;
|
|
1747
|
-
const W =
|
|
1730
|
+
const W = w.current;
|
|
1748
1731
|
if (W && W.offsetHeight > 0) {
|
|
1749
1732
|
h.current = !0;
|
|
1750
1733
|
const m = W.offsetHeight;
|
|
@@ -1758,18 +1741,18 @@ function Yt({
|
|
|
1758
1741
|
e.getState().notifyPathSubscribers(Q, {
|
|
1759
1742
|
type: "ITEMHEIGHT",
|
|
1760
1743
|
itemKey: S.join("."),
|
|
1761
|
-
ref:
|
|
1744
|
+
ref: w.current
|
|
1762
1745
|
});
|
|
1763
1746
|
}
|
|
1764
1747
|
}, [A, i, t, S]);
|
|
1765
|
-
const
|
|
1748
|
+
const c = [t, ...S].join("."), B = e.getState().getShadowValue(c);
|
|
1766
1749
|
if (B === void 0)
|
|
1767
1750
|
return null;
|
|
1768
|
-
const J =
|
|
1751
|
+
const J = I({
|
|
1769
1752
|
currentState: B,
|
|
1770
1753
|
path: S,
|
|
1771
1754
|
componentId: n
|
|
1772
|
-
}), H =
|
|
1755
|
+
}), H = V(J, g, y);
|
|
1773
1756
|
return /* @__PURE__ */ ot("div", { ref: z, children: H });
|
|
1774
1757
|
}
|
|
1775
1758
|
function Zt({
|
|
@@ -1778,27 +1761,27 @@ function Zt({
|
|
|
1778
1761
|
rebuildStateShape: S,
|
|
1779
1762
|
renderFn: g,
|
|
1780
1763
|
formOpts: y,
|
|
1781
|
-
setState:
|
|
1764
|
+
setState: I
|
|
1782
1765
|
}) {
|
|
1783
|
-
const [
|
|
1784
|
-
$t(t,
|
|
1785
|
-
const A = e.getState().getShadowValue(f), [
|
|
1766
|
+
const [V] = K(() => rt()), [, u] = K({}), f = [t, ...n].join(".");
|
|
1767
|
+
$t(t, V, u);
|
|
1768
|
+
const A = e.getState().getShadowValue(f), [w, i] = K(A), h = q(!1), M = q(null);
|
|
1786
1769
|
Z(() => {
|
|
1787
|
-
!h.current && !st(A,
|
|
1770
|
+
!h.current && !st(A, w) && i(A);
|
|
1788
1771
|
}, [A]), Z(() => {
|
|
1789
1772
|
const H = e.getState().subscribeToPath(f, (W) => {
|
|
1790
|
-
!h.current &&
|
|
1773
|
+
!h.current && w !== W && u({});
|
|
1791
1774
|
});
|
|
1792
1775
|
return () => {
|
|
1793
|
-
H(),
|
|
1776
|
+
H(), M.current && (clearTimeout(M.current), h.current = !1);
|
|
1794
1777
|
};
|
|
1795
1778
|
}, []);
|
|
1796
1779
|
const z = ct(
|
|
1797
1780
|
(H) => {
|
|
1798
|
-
typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0,
|
|
1781
|
+
typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
|
|
1799
1782
|
const m = y?.debounceTime ?? 200;
|
|
1800
|
-
|
|
1801
|
-
h.current = !1,
|
|
1783
|
+
M.current = setTimeout(() => {
|
|
1784
|
+
h.current = !1, I(H, n, { updateType: "update" });
|
|
1802
1785
|
const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
|
|
1803
1786
|
if (o) {
|
|
1804
1787
|
const r = e.getState().getShadowValue(t), a = o.safeParse(r), d = X(t, n) || {};
|
|
@@ -1812,7 +1795,7 @@ function Zt({
|
|
|
1812
1795
|
});
|
|
1813
1796
|
else {
|
|
1814
1797
|
const p = ("issues" in a.error ? a.error.issues : a.error.errors).filter(
|
|
1815
|
-
(
|
|
1798
|
+
(E) => JSON.stringify(E.path) === JSON.stringify(n)
|
|
1816
1799
|
);
|
|
1817
1800
|
p.length > 0 ? Q(t, n, {
|
|
1818
1801
|
...d,
|
|
@@ -1830,11 +1813,11 @@ function Zt({
|
|
|
1830
1813
|
});
|
|
1831
1814
|
}
|
|
1832
1815
|
}
|
|
1833
|
-
}, m),
|
|
1816
|
+
}, m), u({});
|
|
1834
1817
|
},
|
|
1835
|
-
[
|
|
1836
|
-
),
|
|
1837
|
-
console.log("handleBlur triggered"),
|
|
1818
|
+
[I, n, y?.debounceTime, t]
|
|
1819
|
+
), c = ct(async () => {
|
|
1820
|
+
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w, n, { updateType: "update" }));
|
|
1838
1821
|
const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
|
|
1839
1822
|
if (!m) return;
|
|
1840
1823
|
const Y = e.getState().getShadowMetadata(t, n);
|
|
@@ -1842,7 +1825,7 @@ function Zt({
|
|
|
1842
1825
|
...Y,
|
|
1843
1826
|
validation: {
|
|
1844
1827
|
status: "DIRTY",
|
|
1845
|
-
validatedValue:
|
|
1828
|
+
validatedValue: w
|
|
1846
1829
|
}
|
|
1847
1830
|
});
|
|
1848
1831
|
const Q = e.getState().getShadowValue(t), X = m.safeParse(Q);
|
|
@@ -1851,7 +1834,7 @@ function Zt({
|
|
|
1851
1834
|
...Y,
|
|
1852
1835
|
validation: {
|
|
1853
1836
|
status: "VALID_PENDING_SYNC",
|
|
1854
|
-
validatedValue:
|
|
1837
|
+
validatedValue: w
|
|
1855
1838
|
}
|
|
1856
1839
|
});
|
|
1857
1840
|
else {
|
|
@@ -1862,16 +1845,16 @@ function Zt({
|
|
|
1862
1845
|
console.log("Detected array path with ULID");
|
|
1863
1846
|
const d = n[0].startsWith("id:") ? [] : n.slice(0, -1);
|
|
1864
1847
|
console.log("Parent path:", d);
|
|
1865
|
-
const
|
|
1866
|
-
if (console.log("Array metadata:",
|
|
1867
|
-
const p = [t, ...n.slice(0, -1)].join("."),
|
|
1868
|
-
console.log("Item key:", p, "Index:",
|
|
1869
|
-
const _ = [...d,
|
|
1848
|
+
const l = e.getState().getShadowMetadata(t, d);
|
|
1849
|
+
if (console.log("Array metadata:", l), l?.arrayKeys) {
|
|
1850
|
+
const p = [t, ...n.slice(0, -1)].join("."), E = l.arrayKeys.indexOf(p);
|
|
1851
|
+
console.log("Item key:", p, "Index:", E);
|
|
1852
|
+
const _ = [...d, E, ...n.slice(-1)], U = JSON.stringify(r.path) === JSON.stringify(_);
|
|
1870
1853
|
return console.log("Zod path comparison:", {
|
|
1871
1854
|
zodPath: _,
|
|
1872
1855
|
errorPath: r.path,
|
|
1873
|
-
match:
|
|
1874
|
-
}),
|
|
1856
|
+
match: U
|
|
1857
|
+
}), U;
|
|
1875
1858
|
}
|
|
1876
1859
|
}
|
|
1877
1860
|
const a = JSON.stringify(r.path) === JSON.stringify(n);
|
|
@@ -1886,40 +1869,40 @@ function Zt({
|
|
|
1886
1869
|
validation: {
|
|
1887
1870
|
status: "VALIDATION_FAILED",
|
|
1888
1871
|
message: o[0]?.message,
|
|
1889
|
-
validatedValue:
|
|
1872
|
+
validatedValue: w
|
|
1890
1873
|
}
|
|
1891
1874
|
});
|
|
1892
1875
|
}
|
|
1893
|
-
|
|
1894
|
-
}, [t, n,
|
|
1876
|
+
u({});
|
|
1877
|
+
}, [t, n, w, I]), B = S({
|
|
1895
1878
|
currentState: A,
|
|
1896
1879
|
path: n,
|
|
1897
|
-
componentId:
|
|
1880
|
+
componentId: V
|
|
1898
1881
|
}), J = new Proxy(B, {
|
|
1899
1882
|
get(H, W) {
|
|
1900
1883
|
return W === "inputProps" ? {
|
|
1901
|
-
value:
|
|
1884
|
+
value: w ?? "",
|
|
1902
1885
|
onChange: (m) => {
|
|
1903
1886
|
z(m.target.value);
|
|
1904
1887
|
},
|
|
1905
1888
|
// 5. Wire the new onBlur handler to the input props.
|
|
1906
|
-
onBlur:
|
|
1889
|
+
onBlur: c,
|
|
1907
1890
|
ref: vt.getState().getFormRef(t + "." + n.join("."))
|
|
1908
1891
|
} : H[W];
|
|
1909
1892
|
}
|
|
1910
1893
|
});
|
|
1911
|
-
return /* @__PURE__ */ ot(
|
|
1894
|
+
return /* @__PURE__ */ ot(kt, { formOpts: y, path: n, stateKey: t, children: g(J) });
|
|
1912
1895
|
}
|
|
1913
1896
|
function $t(t, n, S) {
|
|
1914
1897
|
const g = `${t}////${n}`;
|
|
1915
1898
|
dt(() => {
|
|
1916
|
-
const { registerComponent: y, unregisterComponent:
|
|
1899
|
+
const { registerComponent: y, unregisterComponent: I } = e.getState();
|
|
1917
1900
|
return y(t, g, {
|
|
1918
1901
|
forceUpdate: () => S({}),
|
|
1919
1902
|
paths: /* @__PURE__ */ new Set(),
|
|
1920
1903
|
reactiveType: ["component"]
|
|
1921
1904
|
}), () => {
|
|
1922
|
-
|
|
1905
|
+
I(t, g);
|
|
1923
1906
|
};
|
|
1924
1907
|
}, [t, g]);
|
|
1925
1908
|
}
|