cogsbox-state 0.5.447 → 0.5.449
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 +19 -15
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +220 -213
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +47 -33
package/dist/CogsState.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as ot, Fragment as
|
|
3
|
-
import { memo as
|
|
2
|
+
import { jsx as ot, Fragment as Ot } from "react/jsx-runtime";
|
|
3
|
+
import { memo as Ut, 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
6
|
import { ValidationWrapper as kt } from "./Functions.jsx";
|
|
@@ -21,12 +21,12 @@ function Vt({
|
|
|
21
21
|
options: n,
|
|
22
22
|
initialOptionsPart: S
|
|
23
23
|
}) {
|
|
24
|
-
const g = nt(t) || {}, y = S[t] || {},
|
|
24
|
+
const g = nt(t) || {}, y = S[t] || {}, w = e.getState().setInitialStateOptions, T = { ...y, ...g };
|
|
25
25
|
let u = !1;
|
|
26
26
|
if (n)
|
|
27
27
|
for (const f in n)
|
|
28
|
-
|
|
29
|
-
u &&
|
|
28
|
+
T.hasOwnProperty(f) ? (f == "localStorage" && n[f] && T[f].key !== n[f]?.key && (u = !0, T[f] = n[f]), f == "defaultState" && n[f] && T[f] !== n[f] && !st(T[f], n[f]) && (u = !0, T[f] = n[f])) : (u = !0, T[f] = n[f]);
|
|
29
|
+
u && w(t, T);
|
|
30
30
|
}
|
|
31
31
|
function ie(t, { formElements: n, validation: S }) {
|
|
32
32
|
return { initialState: t, formElements: n, validation: S };
|
|
@@ -46,23 +46,23 @@ const Lt = (t, n) => {
|
|
|
46
46
|
...n.validation,
|
|
47
47
|
...f.validation || {}
|
|
48
48
|
}, n.validation.key && !f.validation?.key && (A.validation.key = `${n.validation.key}.${u}`)), Object.keys(A).length > 0) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
...
|
|
49
|
+
const I = nt(u);
|
|
50
|
+
I ? e.getState().setInitialStateOptions(u, {
|
|
51
|
+
...I,
|
|
52
52
|
...A
|
|
53
53
|
}) : e.getState().setInitialStateOptions(u, A);
|
|
54
54
|
}
|
|
55
55
|
}), Object.keys(g).forEach((u) => {
|
|
56
56
|
e.getState().initializeShadowState(u, g[u]);
|
|
57
57
|
});
|
|
58
|
-
const
|
|
58
|
+
const w = (u, f) => {
|
|
59
59
|
const [A] = K(f?.componentId ?? rt());
|
|
60
60
|
Vt({
|
|
61
61
|
stateKey: u,
|
|
62
62
|
options: f,
|
|
63
63
|
initialOptionsPart: y
|
|
64
64
|
});
|
|
65
|
-
const
|
|
65
|
+
const I = e.getState().getShadowValue(u) || g[u], i = f?.modifyState ? f.modifyState(I) : I;
|
|
66
66
|
return zt(i, {
|
|
67
67
|
stateKey: u,
|
|
68
68
|
syncUpdate: f?.syncUpdate,
|
|
@@ -76,18 +76,25 @@ const Lt = (t, n) => {
|
|
|
76
76
|
serverState: f?.serverState
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
-
function
|
|
79
|
+
function T(u, f) {
|
|
80
80
|
Vt({ stateKey: u, options: f, initialOptionsPart: y }), f.localStorage && xt(u, f), it(u);
|
|
81
81
|
}
|
|
82
|
-
return { useCogsState:
|
|
82
|
+
return { useCogsState: w, setCogsOptions: T };
|
|
83
83
|
};
|
|
84
84
|
function ce(t) {
|
|
85
85
|
const n = t.schemas, S = {};
|
|
86
|
-
for (const
|
|
87
|
-
const
|
|
88
|
-
S[
|
|
86
|
+
for (const w in n) {
|
|
87
|
+
const T = n[w];
|
|
88
|
+
S[w] = T?.schemas?.defaultValues || {};
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
const g = Lt(S, {
|
|
91
|
+
__fromSyncSchema: !0,
|
|
92
|
+
__syncNotifications: t.notifications
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
useCogsState: (w, T) => g.useCogsState(w, T),
|
|
96
|
+
setCogsOptions: g.setCogsOptions
|
|
97
|
+
};
|
|
91
98
|
}
|
|
92
99
|
const {
|
|
93
100
|
getInitialOptions: nt,
|
|
@@ -103,12 +110,12 @@ const {
|
|
|
103
110
|
S.localStorage?.key,
|
|
104
111
|
g
|
|
105
112
|
);
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
113
|
+
const w = at(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
|
|
114
|
+
if (w && g) {
|
|
115
|
+
const T = `${g}-${n}-${w}`;
|
|
109
116
|
let u;
|
|
110
117
|
try {
|
|
111
|
-
u = St(
|
|
118
|
+
u = St(T)?.lastSyncedWithServer;
|
|
112
119
|
} catch {
|
|
113
120
|
}
|
|
114
121
|
const f = e.getState().getShadowMetadata(n, []), A = {
|
|
@@ -117,10 +124,10 @@ const {
|
|
|
117
124
|
lastSyncedWithServer: u,
|
|
118
125
|
stateSource: f?.stateSource,
|
|
119
126
|
baseServerState: f?.baseServerState
|
|
120
|
-
},
|
|
127
|
+
}, I = Ft.serialize(A);
|
|
121
128
|
window.localStorage.setItem(
|
|
122
|
-
|
|
123
|
-
JSON.stringify(
|
|
129
|
+
T,
|
|
130
|
+
JSON.stringify(I.json)
|
|
124
131
|
);
|
|
125
132
|
}
|
|
126
133
|
}, St = (t) => {
|
|
@@ -134,10 +141,10 @@ const {
|
|
|
134
141
|
}, xt = (t, n) => {
|
|
135
142
|
const S = e.getState().getShadowValue(t), { sessionId: g } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
|
|
136
143
|
if (y && g) {
|
|
137
|
-
const
|
|
144
|
+
const w = St(
|
|
138
145
|
`${g}-${t}-${y}`
|
|
139
146
|
);
|
|
140
|
-
if (
|
|
147
|
+
if (w && w.lastUpdated > (w.lastSyncedWithServer || 0))
|
|
141
148
|
return it(t), !0;
|
|
142
149
|
}
|
|
143
150
|
return !1;
|
|
@@ -160,25 +167,25 @@ const {
|
|
|
160
167
|
}
|
|
161
168
|
};
|
|
162
169
|
function wt(t, n, S, g) {
|
|
163
|
-
const y = e.getState(),
|
|
170
|
+
const y = e.getState(), w = y.getShadowMetadata(t, n);
|
|
164
171
|
if (y.setShadowMetadata(t, n, {
|
|
165
|
-
...
|
|
172
|
+
...w,
|
|
166
173
|
isDirty: !1,
|
|
167
174
|
stateSource: "server",
|
|
168
175
|
lastServerSync: g || Date.now()
|
|
169
176
|
}), Array.isArray(S)) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
const A = u.split(".").slice(1),
|
|
173
|
-
|
|
177
|
+
const T = y.getShadowMetadata(t, n);
|
|
178
|
+
T?.arrayKeys && T.arrayKeys.forEach((u, f) => {
|
|
179
|
+
const A = u.split(".").slice(1), I = S[f];
|
|
180
|
+
I !== void 0 && wt(
|
|
174
181
|
t,
|
|
175
182
|
A,
|
|
176
|
-
|
|
183
|
+
I,
|
|
177
184
|
g
|
|
178
185
|
);
|
|
179
186
|
});
|
|
180
|
-
} else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((
|
|
181
|
-
const u = [...n,
|
|
187
|
+
} else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((T) => {
|
|
188
|
+
const u = [...n, T], f = S[T];
|
|
182
189
|
wt(t, u, f, g);
|
|
183
190
|
});
|
|
184
191
|
}
|
|
@@ -187,16 +194,16 @@ function zt(t, {
|
|
|
187
194
|
localStorage: S,
|
|
188
195
|
formElements: g,
|
|
189
196
|
reactiveDeps: y,
|
|
190
|
-
reactiveType:
|
|
191
|
-
componentId:
|
|
197
|
+
reactiveType: w,
|
|
198
|
+
componentId: T,
|
|
192
199
|
defaultState: u,
|
|
193
200
|
syncUpdate: f,
|
|
194
201
|
dependencies: A,
|
|
195
|
-
serverState:
|
|
202
|
+
serverState: I
|
|
196
203
|
} = {}) {
|
|
197
204
|
const [i, h] = K({}), { sessionId: M } = Pt();
|
|
198
205
|
let z = !n;
|
|
199
|
-
const [c] = K(n ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(
|
|
206
|
+
const [c] = K(n ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(T ?? rt()), W = q(
|
|
200
207
|
null
|
|
201
208
|
);
|
|
202
209
|
W.current = nt(c) ?? null, Z(() => {
|
|
@@ -237,17 +244,17 @@ function zt(t, {
|
|
|
237
244
|
[c, u, t, M]
|
|
238
245
|
);
|
|
239
246
|
Z(() => {
|
|
240
|
-
e.getState().setServerStateUpdate(c,
|
|
241
|
-
}, [
|
|
247
|
+
e.getState().setServerStateUpdate(c, I);
|
|
248
|
+
}, [I, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
|
|
242
249
|
if (r?.type === "SERVER_STATE_UPDATE") {
|
|
243
250
|
const a = r.serverState;
|
|
244
251
|
if (a?.status === "success" && a.data !== void 0) {
|
|
245
252
|
yt(c, { serverState: a });
|
|
246
253
|
const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), E = a.data;
|
|
247
254
|
if (l && Array.isArray(p) && Array.isArray(E)) {
|
|
248
|
-
const
|
|
249
|
-
p.map((x) => x[
|
|
250
|
-
), F = E.filter((x) => !C.has(x[
|
|
255
|
+
const O = l.key || "id", C = new Set(
|
|
256
|
+
p.map((x) => x[O])
|
|
257
|
+
), F = E.filter((x) => !C.has(x[O]));
|
|
251
258
|
F.length > 0 && F.forEach((x) => {
|
|
252
259
|
e.getState().insertShadowArrayElement(c, [], x);
|
|
253
260
|
const N = e.getState().getShadowMetadata(c, []);
|
|
@@ -262,8 +269,8 @@ function zt(t, {
|
|
|
262
269
|
});
|
|
263
270
|
const k = e.getState().getShadowValue(j);
|
|
264
271
|
k && typeof k == "object" && !Array.isArray(k) && Object.keys(k).forEach((P) => {
|
|
265
|
-
const
|
|
266
|
-
e.getState().setShadowMetadata(c,
|
|
272
|
+
const U = [...b, P];
|
|
273
|
+
e.getState().setShadowMetadata(c, U, {
|
|
267
274
|
isDirty: !1,
|
|
268
275
|
stateSource: "server",
|
|
269
276
|
lastServerSync: a.timestamp || Date.now()
|
|
@@ -316,7 +323,7 @@ function zt(t, {
|
|
|
316
323
|
const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
|
|
317
324
|
return a.set(o, {
|
|
318
325
|
forceUpdate: () => h({}),
|
|
319
|
-
reactiveType:
|
|
326
|
+
reactiveType: w ?? ["component", "deps"],
|
|
320
327
|
paths: /* @__PURE__ */ new Set(),
|
|
321
328
|
depsFunction: y || void 0,
|
|
322
329
|
deps: y ? y(e.getState().getShadowValue(c)) : [],
|
|
@@ -327,8 +334,8 @@ function zt(t, {
|
|
|
327
334
|
}), h({}), () => {
|
|
328
335
|
const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
|
|
329
336
|
l?.paths && l.paths.forEach((p) => {
|
|
330
|
-
const _ = p.split(".").slice(1),
|
|
331
|
-
|
|
337
|
+
const _ = p.split(".").slice(1), O = e.getState().getShadowMetadata(c, _);
|
|
338
|
+
O?.pathComponents && O.pathComponents.size === 0 && (delete O.pathComponents, e.getState().setShadowMetadata(c, _, O));
|
|
332
339
|
}), d?.components && e.getState().setShadowMetadata(c, [], d);
|
|
333
340
|
};
|
|
334
341
|
}, []);
|
|
@@ -372,40 +379,40 @@ function zt(t, {
|
|
|
372
379
|
}
|
|
373
380
|
if (a.sync !== !1 && Y.current && Y.current.connected && Y.current.updateState({ operation: C }), p?.signals && p.signals.length > 0) {
|
|
374
381
|
const b = a.updateType === "cut" ? null : _;
|
|
375
|
-
p.signals.forEach(({ parentId: k, position: P, effect:
|
|
382
|
+
p.signals.forEach(({ parentId: k, position: P, effect: U }) => {
|
|
376
383
|
const v = document.querySelector(`[data-parent-id="${k}"]`);
|
|
377
384
|
if (v) {
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
385
|
+
const V = Array.from(v.childNodes);
|
|
386
|
+
if (V[P]) {
|
|
380
387
|
let $ = b;
|
|
381
|
-
if (
|
|
388
|
+
if (U && b !== null)
|
|
382
389
|
try {
|
|
383
390
|
$ = new Function(
|
|
384
391
|
"state",
|
|
385
|
-
`return (${
|
|
392
|
+
`return (${U})(state)`
|
|
386
393
|
)(b);
|
|
387
394
|
} catch (D) {
|
|
388
395
|
console.error("Error evaluating effect function:", D);
|
|
389
396
|
}
|
|
390
|
-
$ != null && typeof $ == "object" && ($ = JSON.stringify($)),
|
|
397
|
+
$ != null && typeof $ == "object" && ($ = JSON.stringify($)), V[P].textContent = String($ ?? "");
|
|
391
398
|
}
|
|
392
399
|
}
|
|
393
400
|
});
|
|
394
401
|
}
|
|
395
402
|
if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
|
|
396
|
-
const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k),
|
|
403
|
+
const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), U = l.getShadowValue(
|
|
397
404
|
[c, ...r].join(".")
|
|
398
405
|
);
|
|
399
406
|
if (!k || P === void 0) return;
|
|
400
407
|
p.mapWrappers.forEach((v) => {
|
|
401
|
-
let
|
|
408
|
+
let V = !0, $ = -1;
|
|
402
409
|
if (v.meta?.transforms && v.meta.transforms.length > 0) {
|
|
403
410
|
for (const D of v.meta.transforms)
|
|
404
411
|
if (D.type === "filter" && !D.fn(P, -1)) {
|
|
405
|
-
|
|
412
|
+
V = !1;
|
|
406
413
|
break;
|
|
407
414
|
}
|
|
408
|
-
if (
|
|
415
|
+
if (V) {
|
|
409
416
|
const D = It(
|
|
410
417
|
c,
|
|
411
418
|
r,
|
|
@@ -425,8 +432,8 @@ function zt(t, {
|
|
|
425
432
|
$ = D.length;
|
|
426
433
|
}
|
|
427
434
|
} else
|
|
428
|
-
|
|
429
|
-
if (
|
|
435
|
+
V = !0, $ = b.length - 1;
|
|
436
|
+
if (V && v.containerRef && v.containerRef.isConnected) {
|
|
430
437
|
const D = document.createElement("div");
|
|
431
438
|
D.setAttribute("data-item-path", k);
|
|
432
439
|
const R = Array.from(v.containerRef.children);
|
|
@@ -436,7 +443,7 @@ function zt(t, {
|
|
|
436
443
|
) : v.containerRef.appendChild(D);
|
|
437
444
|
const L = At(D), G = rt(), tt = k.split(".").slice(1), et = v.rebuildStateShape({
|
|
438
445
|
path: v.path,
|
|
439
|
-
currentState:
|
|
446
|
+
currentState: U,
|
|
440
447
|
componentId: v.componentId,
|
|
441
448
|
meta: v.meta
|
|
442
449
|
});
|
|
@@ -458,10 +465,10 @@ function zt(t, {
|
|
|
458
465
|
const b = r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
459
466
|
k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
|
|
460
467
|
if (P.containerRef && P.containerRef.isConnected) {
|
|
461
|
-
const
|
|
468
|
+
const U = P.containerRef.querySelector(
|
|
462
469
|
`[data-item-path="${d}"]`
|
|
463
470
|
);
|
|
464
|
-
|
|
471
|
+
U && U.remove();
|
|
465
472
|
}
|
|
466
473
|
});
|
|
467
474
|
}
|
|
@@ -479,15 +486,15 @@ function zt(t, {
|
|
|
479
486
|
if (k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
480
487
|
if (j.has(P))
|
|
481
488
|
return;
|
|
482
|
-
const
|
|
483
|
-
|
|
489
|
+
const U = N.components?.get(P);
|
|
490
|
+
U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || (U.forceUpdate(), j.add(P)));
|
|
484
491
|
}), b.length === 0)
|
|
485
492
|
break;
|
|
486
493
|
b.pop();
|
|
487
494
|
}
|
|
488
495
|
_ && typeof _ == "object" && !Tt(_) && E && typeof E == "object" && !Tt(E) && Ct(_, E).forEach((P) => {
|
|
489
|
-
const
|
|
490
|
-
|
|
496
|
+
const U = P.split("."), v = [...r, ...U], V = l.getShadowMetadata(c, v);
|
|
497
|
+
V?.pathComponents && V.pathComponents.forEach(($) => {
|
|
491
498
|
if (j.has($))
|
|
492
499
|
return;
|
|
493
500
|
const D = N.components?.get($);
|
|
@@ -497,33 +504,33 @@ function zt(t, {
|
|
|
497
504
|
} else if (a.updateType === "insert" || a.updateType === "cut") {
|
|
498
505
|
const b = a.updateType === "insert" ? r : r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
499
506
|
if (k?.signals && k.signals.length > 0) {
|
|
500
|
-
const P = [c, ...b].join("."),
|
|
501
|
-
k.signals.forEach(({ parentId: v, position:
|
|
507
|
+
const P = [c, ...b].join("."), U = l.getShadowValue(P);
|
|
508
|
+
k.signals.forEach(({ parentId: v, position: V, effect: $ }) => {
|
|
502
509
|
const D = document.querySelector(
|
|
503
510
|
`[data-parent-id="${v}"]`
|
|
504
511
|
);
|
|
505
512
|
if (D) {
|
|
506
513
|
const R = Array.from(D.childNodes);
|
|
507
|
-
if (R[
|
|
508
|
-
let L =
|
|
514
|
+
if (R[V]) {
|
|
515
|
+
let L = U;
|
|
509
516
|
if ($)
|
|
510
517
|
try {
|
|
511
518
|
L = new Function(
|
|
512
519
|
"state",
|
|
513
520
|
`return (${$})(state)`
|
|
514
|
-
)(
|
|
521
|
+
)(U);
|
|
515
522
|
} catch (G) {
|
|
516
|
-
console.error("Error evaluating effect function:", G), L =
|
|
523
|
+
console.error("Error evaluating effect function:", G), L = U;
|
|
517
524
|
}
|
|
518
|
-
L != null && typeof L == "object" && (L = JSON.stringify(L)), R[
|
|
525
|
+
L != null && typeof L == "object" && (L = JSON.stringify(L)), R[V].textContent = String(L ?? "");
|
|
519
526
|
}
|
|
520
527
|
}
|
|
521
528
|
});
|
|
522
529
|
}
|
|
523
530
|
k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
524
531
|
if (!j.has(P)) {
|
|
525
|
-
const
|
|
526
|
-
|
|
532
|
+
const U = N.components?.get(P);
|
|
533
|
+
U && (U.forceUpdate(), j.add(P));
|
|
527
534
|
}
|
|
528
535
|
});
|
|
529
536
|
}
|
|
@@ -536,15 +543,15 @@ function zt(t, {
|
|
|
536
543
|
return;
|
|
537
544
|
}
|
|
538
545
|
if (P.includes("deps") && b.depsFunction) {
|
|
539
|
-
const
|
|
540
|
-
let
|
|
541
|
-
v === !0 ?
|
|
546
|
+
const U = l.getShadowValue(c), v = b.depsFunction(U);
|
|
547
|
+
let V = !1;
|
|
548
|
+
v === !0 ? V = !0 : Array.isArray(v) && (st(b.prevDeps, v) || (b.prevDeps = v, V = !0)), V && (b.forceUpdate(), j.add(k));
|
|
542
549
|
}
|
|
543
550
|
}), j.clear(), Wt(c, (b) => {
|
|
544
551
|
const k = [...b ?? [], C], P = /* @__PURE__ */ new Map();
|
|
545
|
-
return k.forEach((
|
|
546
|
-
const v = `${
|
|
547
|
-
|
|
552
|
+
return k.forEach((U) => {
|
|
553
|
+
const v = `${U.stateKey}:${JSON.stringify(U.path)}`, V = P.get(v);
|
|
554
|
+
V ? (V.timeStamp = Math.max(V.timeStamp, U.timeStamp), V.newValue = U.newValue, V.oldValue = V.oldValue ?? U.oldValue, V.updateType = U.updateType) : P.set(v, { ...U });
|
|
548
555
|
}), Array.from(P.values());
|
|
549
556
|
}), Ht(
|
|
550
557
|
_,
|
|
@@ -577,53 +584,53 @@ const It = (t, n, S) => {
|
|
|
577
584
|
let g = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
|
|
578
585
|
if (!S || S.length === 0)
|
|
579
586
|
return g;
|
|
580
|
-
let y = g.map((
|
|
581
|
-
key:
|
|
582
|
-
value: e.getState().getShadowValue(
|
|
587
|
+
let y = g.map((w) => ({
|
|
588
|
+
key: w,
|
|
589
|
+
value: e.getState().getShadowValue(w)
|
|
583
590
|
}));
|
|
584
|
-
for (const
|
|
585
|
-
|
|
586
|
-
({ value:
|
|
587
|
-
) :
|
|
588
|
-
return y.map(({ key:
|
|
591
|
+
for (const w of S)
|
|
592
|
+
w.type === "filter" ? y = y.filter(
|
|
593
|
+
({ value: T }, u) => w.fn(T, u)
|
|
594
|
+
) : w.type === "sort" && y.sort((T, u) => w.fn(T.value, u.value));
|
|
595
|
+
return y.map(({ key: w }) => w);
|
|
589
596
|
}, Et = (t, n, S) => {
|
|
590
|
-
const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata:
|
|
597
|
+
const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: w } = e.getState(), u = w(t, [])?.components?.get(g);
|
|
591
598
|
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, S, g);
|
|
592
599
|
}, ft = (t, n, S) => {
|
|
593
|
-
const g = e.getState(), y = g.getShadowMetadata(t, []),
|
|
600
|
+
const g = e.getState(), y = g.getShadowMetadata(t, []), w = /* @__PURE__ */ new Set();
|
|
594
601
|
y?.components && y.components.forEach((u, f) => {
|
|
595
|
-
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(),
|
|
602
|
+
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), w.add(f));
|
|
596
603
|
}), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
|
|
597
604
|
y?.components?.get(u)?.forceUpdate();
|
|
598
605
|
});
|
|
599
|
-
const
|
|
600
|
-
for (let u of
|
|
606
|
+
const T = g.getShadowMetadata(t, n);
|
|
607
|
+
for (let u of T?.arrayKeys || []) {
|
|
601
608
|
const f = u + ".selected", A = g.getShadowMetadata(
|
|
602
609
|
t,
|
|
603
610
|
f.split(".").slice(1)
|
|
604
611
|
);
|
|
605
|
-
u == S && A?.pathComponents?.forEach((
|
|
606
|
-
y?.components?.get(
|
|
612
|
+
u == S && A?.pathComponents?.forEach((I) => {
|
|
613
|
+
y?.components?.get(I)?.forceUpdate();
|
|
607
614
|
});
|
|
608
615
|
}
|
|
609
616
|
};
|
|
610
617
|
function Dt(t, n, S, g) {
|
|
611
618
|
const y = /* @__PURE__ */ new Map();
|
|
612
|
-
let
|
|
613
|
-
const
|
|
614
|
-
const i =
|
|
619
|
+
let w = 0;
|
|
620
|
+
const T = (I) => {
|
|
621
|
+
const i = I.join(".");
|
|
615
622
|
for (const [h] of y)
|
|
616
623
|
(h === i || h.startsWith(i + ".")) && y.delete(h);
|
|
617
|
-
|
|
624
|
+
w++;
|
|
618
625
|
};
|
|
619
626
|
function u({
|
|
620
|
-
currentState:
|
|
627
|
+
currentState: I,
|
|
621
628
|
path: i = [],
|
|
622
629
|
meta: h,
|
|
623
630
|
componentId: M
|
|
624
631
|
}) {
|
|
625
632
|
const z = i.map(String).join("."), c = [t, ...i].join(".");
|
|
626
|
-
|
|
633
|
+
I = e.getState().getShadowValue(c, h?.validIds);
|
|
627
634
|
const B = function() {
|
|
628
635
|
return e().getShadowValue(t, i);
|
|
629
636
|
}, J = {
|
|
@@ -684,7 +691,7 @@ function Dt(t, n, S, g) {
|
|
|
684
691
|
const s = e.getState().getShadowMetadata(t, i);
|
|
685
692
|
return s?.validation?.status === "VALIDATION_FAILED" && s.validation.message ? [s.validation.message] : [];
|
|
686
693
|
};
|
|
687
|
-
if (Array.isArray(
|
|
694
|
+
if (Array.isArray(I)) {
|
|
688
695
|
if (m === "getSelected")
|
|
689
696
|
return () => {
|
|
690
697
|
const s = t + "." + i.join(".");
|
|
@@ -727,7 +734,7 @@ function Dt(t, n, S, g) {
|
|
|
727
734
|
} = s, l = q(null), [p, E] = K({
|
|
728
735
|
startIndex: 0,
|
|
729
736
|
endIndex: 10
|
|
730
|
-
}), [_,
|
|
737
|
+
}), [_, O] = K({}), C = q(!0), F = q({
|
|
731
738
|
isUserScrolling: !1,
|
|
732
739
|
lastScrollTop: 0,
|
|
733
740
|
scrollUpCount: 0,
|
|
@@ -746,18 +753,18 @@ function Dt(t, n, S, g) {
|
|
|
746
753
|
}, [_, a]);
|
|
747
754
|
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } = gt(() => {
|
|
748
755
|
let v = 0;
|
|
749
|
-
const
|
|
756
|
+
const V = /* @__PURE__ */ new Map();
|
|
750
757
|
return (e.getState().getShadowMetadata(t, i)?.arrayKeys || []).forEach((D) => {
|
|
751
758
|
const R = D.split(".").slice(1), L = e.getState().getShadowMetadata(t, R)?.virtualizer?.itemHeight || o;
|
|
752
|
-
|
|
759
|
+
V.set(D, {
|
|
753
760
|
height: L,
|
|
754
761
|
offset: v
|
|
755
762
|
}), v += L;
|
|
756
|
-
}), x.current =
|
|
763
|
+
}), x.current = V, { totalHeight: v, itemOffsets: V };
|
|
757
764
|
}, [N.length, o]);
|
|
758
765
|
dt(() => {
|
|
759
766
|
if (a && N.length > 0 && l.current && !F.current.isUserScrolling && C.current) {
|
|
760
|
-
const v = l.current,
|
|
767
|
+
const v = l.current, V = () => {
|
|
761
768
|
if (v.clientHeight > 0) {
|
|
762
769
|
const $ = Math.ceil(
|
|
763
770
|
v.clientHeight / o
|
|
@@ -769,20 +776,20 @@ function Dt(t, n, S, g) {
|
|
|
769
776
|
P("instant"), C.current = !1;
|
|
770
777
|
});
|
|
771
778
|
} else
|
|
772
|
-
requestAnimationFrame(
|
|
779
|
+
requestAnimationFrame(V);
|
|
773
780
|
};
|
|
774
|
-
|
|
781
|
+
V();
|
|
775
782
|
}
|
|
776
783
|
}, [N.length, a, o, r]);
|
|
777
784
|
const k = ct(() => {
|
|
778
785
|
const v = l.current;
|
|
779
786
|
if (!v) return;
|
|
780
|
-
const
|
|
781
|
-
R.isNearBottom = L <= d,
|
|
787
|
+
const V = v.scrollTop, { scrollHeight: $, clientHeight: D } = v, R = F.current, L = $ - (V + D), G = R.isNearBottom;
|
|
788
|
+
R.isNearBottom = L <= d, V < 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 = V;
|
|
782
789
|
let tt = 0;
|
|
783
790
|
for (let et = 0; et < N.length; et++) {
|
|
784
791
|
const ht = N[et], mt = x.current.get(ht);
|
|
785
|
-
if (mt && mt.offset + mt.height >
|
|
792
|
+
if (mt && mt.offset + mt.height > V) {
|
|
786
793
|
tt = et;
|
|
787
794
|
break;
|
|
788
795
|
}
|
|
@@ -815,18 +822,18 @@ function Dt(t, n, S, g) {
|
|
|
815
822
|
}, [k, a]);
|
|
816
823
|
const P = ct(
|
|
817
824
|
(v = "smooth") => {
|
|
818
|
-
const
|
|
819
|
-
if (!
|
|
825
|
+
const V = l.current;
|
|
826
|
+
if (!V) return;
|
|
820
827
|
F.current.isUserScrolling = !1, F.current.isNearBottom = !0, F.current.scrollUpCount = 0;
|
|
821
828
|
const $ = () => {
|
|
822
829
|
const D = (R = 0) => {
|
|
823
830
|
if (R > 5) return;
|
|
824
|
-
const L =
|
|
825
|
-
G + tt >= L - 1 || (
|
|
831
|
+
const L = V.scrollHeight, G = V.scrollTop, tt = V.clientHeight;
|
|
832
|
+
G + tt >= L - 1 || (V.scrollTo({
|
|
826
833
|
top: L,
|
|
827
834
|
behavior: v
|
|
828
835
|
}), setTimeout(() => {
|
|
829
|
-
const et =
|
|
836
|
+
const et = V.scrollHeight, ht = V.scrollTop;
|
|
830
837
|
(et !== L || ht + tt < et - 1) && D(R + 1);
|
|
831
838
|
}, 50));
|
|
832
839
|
};
|
|
@@ -840,16 +847,16 @@ function Dt(t, n, S, g) {
|
|
|
840
847
|
);
|
|
841
848
|
return Z(() => {
|
|
842
849
|
if (!a || !l.current) return;
|
|
843
|
-
const v = l.current,
|
|
850
|
+
const v = l.current, V = F.current;
|
|
844
851
|
let $;
|
|
845
852
|
const D = () => {
|
|
846
853
|
clearTimeout($), $ = setTimeout(() => {
|
|
847
|
-
!
|
|
854
|
+
!V.isUserScrolling && V.isNearBottom && P(
|
|
848
855
|
C.current ? "instant" : "smooth"
|
|
849
856
|
);
|
|
850
857
|
}, 100);
|
|
851
858
|
}, R = new MutationObserver(() => {
|
|
852
|
-
|
|
859
|
+
V.isUserScrolling || D();
|
|
853
860
|
});
|
|
854
861
|
R.observe(v, {
|
|
855
862
|
childList: !0,
|
|
@@ -859,7 +866,7 @@ function Dt(t, n, S, g) {
|
|
|
859
866
|
// More specific than just 'height'
|
|
860
867
|
});
|
|
861
868
|
const L = (G) => {
|
|
862
|
-
G.target instanceof HTMLImageElement && !
|
|
869
|
+
G.target instanceof HTMLImageElement && !V.isUserScrolling && D();
|
|
863
870
|
};
|
|
864
871
|
return v.addEventListener("load", L, !0), C.current ? setTimeout(() => {
|
|
865
872
|
P("instant");
|
|
@@ -868,9 +875,9 @@ function Dt(t, n, S, g) {
|
|
|
868
875
|
};
|
|
869
876
|
}, [a, N.length, P]), {
|
|
870
877
|
virtualState: gt(() => {
|
|
871
|
-
const v = e.getState(),
|
|
878
|
+
const v = e.getState(), V = v.getShadowValue(
|
|
872
879
|
[t, ...i].join(".")
|
|
873
|
-
), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D =
|
|
880
|
+
), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D = V.slice(
|
|
874
881
|
p.startIndex,
|
|
875
882
|
p.endIndex + 1
|
|
876
883
|
), R = $.slice(
|
|
@@ -908,10 +915,10 @@ function Dt(t, n, S, g) {
|
|
|
908
915
|
}
|
|
909
916
|
},
|
|
910
917
|
scrollToBottom: P,
|
|
911
|
-
scrollToIndex: (v,
|
|
918
|
+
scrollToIndex: (v, V = "smooth") => {
|
|
912
919
|
if (l.current && N[v]) {
|
|
913
920
|
const $ = x.current.get(N[v])?.offset || 0;
|
|
914
|
-
l.current.scrollTo({ top: $, behavior:
|
|
921
|
+
l.current.scrollTo({ top: $, behavior: V });
|
|
915
922
|
}
|
|
916
923
|
}
|
|
917
924
|
};
|
|
@@ -978,7 +985,7 @@ function Dt(t, n, S, g) {
|
|
|
978
985
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
979
986
|
if (!o)
|
|
980
987
|
throw new Error("No array keys found for filtering.");
|
|
981
|
-
const r = [], a =
|
|
988
|
+
const r = [], a = I.filter(
|
|
982
989
|
(d, l) => s(d, l) ? (r.push(o[l]), !0) : !1
|
|
983
990
|
);
|
|
984
991
|
return u({
|
|
@@ -1002,7 +1009,7 @@ function Dt(t, n, S, g) {
|
|
|
1002
1009
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1003
1010
|
if (!o)
|
|
1004
1011
|
throw new Error("No array keys found for sorting");
|
|
1005
|
-
const r =
|
|
1012
|
+
const r = I.map((a, d) => ({
|
|
1006
1013
|
item: a,
|
|
1007
1014
|
key: o[d]
|
|
1008
1015
|
}));
|
|
@@ -1029,7 +1036,7 @@ function Dt(t, n, S, g) {
|
|
|
1029
1036
|
onFlush: l
|
|
1030
1037
|
} = s;
|
|
1031
1038
|
let p = [], E = !1, _ = null;
|
|
1032
|
-
const
|
|
1039
|
+
const O = (j) => {
|
|
1033
1040
|
if (!E) {
|
|
1034
1041
|
if (a === "sliding" && p.length >= o)
|
|
1035
1042
|
p.shift();
|
|
@@ -1061,8 +1068,8 @@ function Dt(t, n, S, g) {
|
|
|
1061
1068
|
...x,
|
|
1062
1069
|
streams: N
|
|
1063
1070
|
}), {
|
|
1064
|
-
write: (j) =>
|
|
1065
|
-
writeMany: (j) => j.forEach(
|
|
1071
|
+
write: (j) => O(j),
|
|
1072
|
+
writeMany: (j) => j.forEach(O),
|
|
1066
1073
|
flush: () => C(),
|
|
1067
1074
|
pause: () => {
|
|
1068
1075
|
E = !0;
|
|
@@ -1080,9 +1087,9 @@ function Dt(t, n, S, g) {
|
|
|
1080
1087
|
if (m === "stateList")
|
|
1081
1088
|
return (s) => /* @__PURE__ */ ot(() => {
|
|
1082
1089
|
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
|
|
1090
|
+
const O = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
|
|
1084
1091
|
let C;
|
|
1085
|
-
|
|
1092
|
+
O && O.validIds ? C = O.validIds : (C = It(
|
|
1086
1093
|
t,
|
|
1087
1094
|
i,
|
|
1088
1095
|
h?.transforms
|
|
@@ -1098,7 +1105,7 @@ function Dt(t, n, S, g) {
|
|
|
1098
1105
|
};
|
|
1099
1106
|
}, [a, d]);
|
|
1100
1107
|
if (Z(() => {
|
|
1101
|
-
const
|
|
1108
|
+
const O = e.getState().subscribeToPath(c, (C) => {
|
|
1102
1109
|
if (C.type === "GET_SELECTED")
|
|
1103
1110
|
return;
|
|
1104
1111
|
const x = e.getState().getShadowMetadata(t, i)?.transformCaches;
|
|
@@ -1108,7 +1115,7 @@ function Dt(t, n, S, g) {
|
|
|
1108
1115
|
(C.type === "INSERT" || C.type === "REMOVE" || C.type === "CLEAR_SELECTION") && l({});
|
|
1109
1116
|
});
|
|
1110
1117
|
return () => {
|
|
1111
|
-
|
|
1118
|
+
O();
|
|
1112
1119
|
};
|
|
1113
1120
|
}, [M, c]), !Array.isArray(E))
|
|
1114
1121
|
return null;
|
|
@@ -1121,7 +1128,7 @@ function Dt(t, n, S, g) {
|
|
|
1121
1128
|
validIds: p
|
|
1122
1129
|
}
|
|
1123
1130
|
});
|
|
1124
|
-
return /* @__PURE__ */ ot(
|
|
1131
|
+
return /* @__PURE__ */ ot(Ot, { children: E.map((O, C) => {
|
|
1125
1132
|
const F = p[C];
|
|
1126
1133
|
if (!F)
|
|
1127
1134
|
return null;
|
|
@@ -1142,8 +1149,8 @@ function Dt(t, n, S, g) {
|
|
|
1142
1149
|
}, {});
|
|
1143
1150
|
if (m === "stateFlattenOn")
|
|
1144
1151
|
return (s) => {
|
|
1145
|
-
const o =
|
|
1146
|
-
y.clear(),
|
|
1152
|
+
const o = I;
|
|
1153
|
+
y.clear(), w++;
|
|
1147
1154
|
const r = o.flatMap(
|
|
1148
1155
|
(a) => a[s] ?? []
|
|
1149
1156
|
);
|
|
@@ -1193,16 +1200,16 @@ function Dt(t, n, S, g) {
|
|
|
1193
1200
|
let l = null;
|
|
1194
1201
|
if (!a.some((E) => {
|
|
1195
1202
|
const _ = o ? o.every(
|
|
1196
|
-
(
|
|
1203
|
+
(O) => st(E[O], d[O])
|
|
1197
1204
|
) : st(E, d);
|
|
1198
1205
|
return _ && (l = E), _;
|
|
1199
1206
|
}))
|
|
1200
|
-
|
|
1207
|
+
T(i), n(d, i, { updateType: "insert" });
|
|
1201
1208
|
else if (r && l) {
|
|
1202
1209
|
const E = r(l), _ = a.map(
|
|
1203
|
-
(
|
|
1210
|
+
(O) => st(O, l) ? E : O
|
|
1204
1211
|
);
|
|
1205
|
-
|
|
1212
|
+
T(i), n(_, i, {
|
|
1206
1213
|
updateType: "update"
|
|
1207
1214
|
});
|
|
1208
1215
|
}
|
|
@@ -1214,7 +1221,7 @@ function Dt(t, n, S, g) {
|
|
|
1214
1221
|
const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
|
|
1215
1222
|
if (!d) return;
|
|
1216
1223
|
const l = d.split(".").slice(1);
|
|
1217
|
-
n(
|
|
1224
|
+
n(I, l, {
|
|
1218
1225
|
updateType: "cut"
|
|
1219
1226
|
});
|
|
1220
1227
|
};
|
|
@@ -1233,7 +1240,7 @@ function Dt(t, n, S, g) {
|
|
|
1233
1240
|
const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
|
|
1234
1241
|
e.getState().clearSelectedIndex({ arrayKey: c });
|
|
1235
1242
|
const d = a?.slice(0, -1);
|
|
1236
|
-
ft(t, d), n(
|
|
1243
|
+
ft(t, d), n(I, a, {
|
|
1237
1244
|
updateType: "cut"
|
|
1238
1245
|
});
|
|
1239
1246
|
};
|
|
@@ -1365,11 +1372,11 @@ function Dt(t, n, S, g) {
|
|
|
1365
1372
|
o.updateShadowAtPath(t, p, E), o.markAsDirty(t, p, { bubble: !0 });
|
|
1366
1373
|
let _ = [...p];
|
|
1367
1374
|
for (; ; ) {
|
|
1368
|
-
const
|
|
1375
|
+
const O = o.getShadowMetadata(
|
|
1369
1376
|
t,
|
|
1370
1377
|
_
|
|
1371
1378
|
);
|
|
1372
|
-
if (console.log("pathMeta",
|
|
1379
|
+
if (console.log("pathMeta", O), O?.pathComponents && O.pathComponents.forEach((C) => {
|
|
1373
1380
|
if (!d.has(C)) {
|
|
1374
1381
|
const F = r.components?.get(C);
|
|
1375
1382
|
F && (F.forceUpdate(), d.add(C));
|
|
@@ -1384,11 +1391,11 @@ function Dt(t, n, S, g) {
|
|
|
1384
1391
|
o.removeShadowArrayElement(t, p), o.markAsDirty(t, E, { bubble: !0 });
|
|
1385
1392
|
let _ = [...E];
|
|
1386
1393
|
for (; ; ) {
|
|
1387
|
-
const
|
|
1394
|
+
const O = o.getShadowMetadata(
|
|
1388
1395
|
t,
|
|
1389
1396
|
_
|
|
1390
1397
|
);
|
|
1391
|
-
if (
|
|
1398
|
+
if (O?.pathComponents && O.pathComponents.forEach((C) => {
|
|
1392
1399
|
if (!d.has(C)) {
|
|
1393
1400
|
const F = r.components?.get(C);
|
|
1394
1401
|
F && (F.forceUpdate(), d.add(C));
|
|
@@ -1465,7 +1472,7 @@ function Dt(t, n, S, g) {
|
|
|
1465
1472
|
});
|
|
1466
1473
|
if (m === "toggle") {
|
|
1467
1474
|
const s = e.getState().getShadowValue([t, ...i].join("."));
|
|
1468
|
-
if (console.log("currentValueAtPath", s), typeof
|
|
1475
|
+
if (console.log("currentValueAtPath", s), typeof I != "boolean")
|
|
1469
1476
|
throw new Error("toggle() can only be used on boolean values");
|
|
1470
1477
|
return () => {
|
|
1471
1478
|
n(!s, i, {
|
|
@@ -1496,20 +1503,20 @@ function Dt(t, n, S, g) {
|
|
|
1496
1503
|
}, H = new Proxy(B, J);
|
|
1497
1504
|
return y.set(z, {
|
|
1498
1505
|
proxy: H,
|
|
1499
|
-
stateVersion:
|
|
1506
|
+
stateVersion: w
|
|
1500
1507
|
}), H;
|
|
1501
1508
|
}
|
|
1502
1509
|
const f = {
|
|
1503
|
-
removeValidation: (
|
|
1504
|
-
|
|
1510
|
+
removeValidation: (I) => {
|
|
1511
|
+
I?.validationKey && ut(I.validationKey);
|
|
1505
1512
|
},
|
|
1506
|
-
revertToInitialState: (
|
|
1513
|
+
revertToInitialState: (I) => {
|
|
1507
1514
|
const i = e.getState().getInitialOptions(t)?.validation;
|
|
1508
|
-
i?.key && ut(i.key),
|
|
1515
|
+
i?.key && ut(i.key), I?.validationKey && ut(I.validationKey);
|
|
1509
1516
|
const h = e.getState().getShadowMetadata(t, []);
|
|
1510
1517
|
h?.stateSource === "server" && h.baseServerState ? h.baseServerState : e.getState().initialStateGlobal[t];
|
|
1511
1518
|
const M = e.getState().initialStateGlobal[t];
|
|
1512
|
-
e.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
1519
|
+
e.getState().clearSelectedIndexesForState(t), y.clear(), w++, e.getState().initializeShadowState(t, M), u({
|
|
1513
1520
|
currentState: M,
|
|
1514
1521
|
path: [],
|
|
1515
1522
|
componentId: S
|
|
@@ -1521,8 +1528,8 @@ function Dt(t, n, S, g) {
|
|
|
1521
1528
|
H.forceUpdate();
|
|
1522
1529
|
}), M;
|
|
1523
1530
|
},
|
|
1524
|
-
updateInitialState: (
|
|
1525
|
-
y.clear(),
|
|
1531
|
+
updateInitialState: (I) => {
|
|
1532
|
+
y.clear(), w++;
|
|
1526
1533
|
const i = Dt(
|
|
1527
1534
|
t,
|
|
1528
1535
|
n,
|
|
@@ -1530,7 +1537,7 @@ function Dt(t, n, S, g) {
|
|
|
1530
1537
|
g
|
|
1531
1538
|
), 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
1539
|
return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
|
|
1533
|
-
_t(t,
|
|
1540
|
+
_t(t, I), e.getState().initializeShadowState(t, I);
|
|
1534
1541
|
const B = e.getState().getShadowMetadata(t, []);
|
|
1535
1542
|
B && B?.components?.forEach((J) => {
|
|
1536
1543
|
J.forceUpdate();
|
|
@@ -1553,13 +1560,13 @@ function qt({
|
|
|
1553
1560
|
proxy: t,
|
|
1554
1561
|
rebuildStateShape: n
|
|
1555
1562
|
}) {
|
|
1556
|
-
const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1),
|
|
1563
|
+
const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), w = q(/* @__PURE__ */ new Map());
|
|
1557
1564
|
Z(() => {
|
|
1558
1565
|
const u = S.current;
|
|
1559
1566
|
if (!u || y.current) return;
|
|
1560
1567
|
const f = setTimeout(() => {
|
|
1561
|
-
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {},
|
|
1562
|
-
|
|
1568
|
+
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, I = A.mapWrappers || [];
|
|
1569
|
+
I.push({
|
|
1563
1570
|
instanceId: g.current,
|
|
1564
1571
|
mapFn: t._mapFn,
|
|
1565
1572
|
containerRef: u,
|
|
@@ -1569,20 +1576,20 @@ function qt({
|
|
|
1569
1576
|
meta: t._meta
|
|
1570
1577
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1571
1578
|
...A,
|
|
1572
|
-
mapWrappers:
|
|
1573
|
-
}), y.current = !0,
|
|
1579
|
+
mapWrappers: I
|
|
1580
|
+
}), y.current = !0, T();
|
|
1574
1581
|
}, 0);
|
|
1575
1582
|
return () => {
|
|
1576
1583
|
if (clearTimeout(f), g.current) {
|
|
1577
1584
|
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1578
1585
|
A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
|
|
1579
|
-
(
|
|
1586
|
+
(I) => I.instanceId !== g.current
|
|
1580
1587
|
), e.getState().setShadowMetadata(t._stateKey, t._path, A));
|
|
1581
1588
|
}
|
|
1582
|
-
|
|
1589
|
+
w.current.forEach((A) => A.unmount());
|
|
1583
1590
|
};
|
|
1584
1591
|
}, []);
|
|
1585
|
-
const
|
|
1592
|
+
const T = () => {
|
|
1586
1593
|
const u = S.current;
|
|
1587
1594
|
if (!u) return;
|
|
1588
1595
|
const f = e.getState().getShadowValue(
|
|
@@ -1590,7 +1597,7 @@ function qt({
|
|
|
1590
1597
|
t._meta?.validIds
|
|
1591
1598
|
);
|
|
1592
1599
|
if (!Array.isArray(f)) return;
|
|
1593
|
-
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [],
|
|
1600
|
+
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], I = n({
|
|
1594
1601
|
currentState: f,
|
|
1595
1602
|
path: t._path,
|
|
1596
1603
|
componentId: g.current,
|
|
@@ -1602,7 +1609,7 @@ function qt({
|
|
|
1602
1609
|
const z = rt(), c = document.createElement("div");
|
|
1603
1610
|
c.setAttribute("data-item-path", M), u.appendChild(c);
|
|
1604
1611
|
const B = At(c);
|
|
1605
|
-
|
|
1612
|
+
w.current.set(M, B);
|
|
1606
1613
|
const J = M.split(".").slice(1);
|
|
1607
1614
|
B.render(
|
|
1608
1615
|
lt(Mt, {
|
|
@@ -1610,7 +1617,7 @@ function qt({
|
|
|
1610
1617
|
itemComponentId: z,
|
|
1611
1618
|
itemPath: J,
|
|
1612
1619
|
localIndex: h,
|
|
1613
|
-
arraySetter:
|
|
1620
|
+
arraySetter: I,
|
|
1614
1621
|
rebuildStateShape: n,
|
|
1615
1622
|
renderFn: t._mapFn
|
|
1616
1623
|
})
|
|
@@ -1622,44 +1629,44 @@ function qt({
|
|
|
1622
1629
|
function Gt({
|
|
1623
1630
|
proxy: t
|
|
1624
1631
|
}) {
|
|
1625
|
-
const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`,
|
|
1632
|
+
const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, w = e.getState().getShadowValue(
|
|
1626
1633
|
[t._stateKey, ...t._path].join("."),
|
|
1627
1634
|
t._meta?.validIds
|
|
1628
1635
|
);
|
|
1629
1636
|
return Z(() => {
|
|
1630
|
-
const
|
|
1631
|
-
if (!
|
|
1637
|
+
const T = n.current;
|
|
1638
|
+
if (!T || g.current) return;
|
|
1632
1639
|
const u = setTimeout(() => {
|
|
1633
|
-
if (!
|
|
1640
|
+
if (!T.parentElement) {
|
|
1634
1641
|
console.warn("Parent element not found for signal", y);
|
|
1635
1642
|
return;
|
|
1636
1643
|
}
|
|
1637
|
-
const f =
|
|
1644
|
+
const f = T.parentElement, I = Array.from(f.childNodes).indexOf(T);
|
|
1638
1645
|
let i = f.getAttribute("data-parent-id");
|
|
1639
1646
|
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), S.current = `instance-${crypto.randomUUID()}`;
|
|
1640
1647
|
const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
|
|
1641
1648
|
M.push({
|
|
1642
1649
|
instanceId: S.current,
|
|
1643
1650
|
parentId: i,
|
|
1644
|
-
position:
|
|
1651
|
+
position: I,
|
|
1645
1652
|
effect: t._effect
|
|
1646
1653
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1647
1654
|
...h,
|
|
1648
1655
|
signals: M
|
|
1649
1656
|
});
|
|
1650
|
-
let z =
|
|
1657
|
+
let z = w;
|
|
1651
1658
|
if (t._effect)
|
|
1652
1659
|
try {
|
|
1653
1660
|
z = new Function(
|
|
1654
1661
|
"state",
|
|
1655
1662
|
`return (${t._effect})(state)`
|
|
1656
|
-
)(
|
|
1663
|
+
)(w);
|
|
1657
1664
|
} catch (B) {
|
|
1658
1665
|
console.error("Error evaluating effect function:", B);
|
|
1659
1666
|
}
|
|
1660
1667
|
z !== null && typeof z == "object" && (z = JSON.stringify(z));
|
|
1661
1668
|
const c = document.createTextNode(String(z ?? ""));
|
|
1662
|
-
|
|
1669
|
+
T.replaceWith(c), g.current = !0;
|
|
1663
1670
|
}, 0);
|
|
1664
1671
|
return () => {
|
|
1665
1672
|
if (clearTimeout(u), S.current) {
|
|
@@ -1675,7 +1682,7 @@ function Gt({
|
|
|
1675
1682
|
"data-signal-id": y
|
|
1676
1683
|
});
|
|
1677
1684
|
}
|
|
1678
|
-
const Mt =
|
|
1685
|
+
const Mt = Ut(
|
|
1679
1686
|
Yt,
|
|
1680
1687
|
(t, n) => t.itemPath.join(".") === n.itemPath.join(".") && t.stateKey === n.stateKey && t.itemComponentId === n.itemComponentId && t.localIndex === n.localIndex
|
|
1681
1688
|
), Jt = (t) => {
|
|
@@ -1691,14 +1698,14 @@ const Mt = Ot(
|
|
|
1691
1698
|
return;
|
|
1692
1699
|
}
|
|
1693
1700
|
let y = 0;
|
|
1694
|
-
const
|
|
1701
|
+
const w = () => {
|
|
1695
1702
|
y++, y === g.length && S(!0);
|
|
1696
1703
|
};
|
|
1697
|
-
return g.forEach((
|
|
1698
|
-
|
|
1704
|
+
return g.forEach((T) => {
|
|
1705
|
+
T.complete ? w() : (T.addEventListener("load", w), T.addEventListener("error", w));
|
|
1699
1706
|
}), () => {
|
|
1700
|
-
g.forEach((
|
|
1701
|
-
|
|
1707
|
+
g.forEach((T) => {
|
|
1708
|
+
T.removeEventListener("load", w), T.removeEventListener("error", w);
|
|
1702
1709
|
});
|
|
1703
1710
|
};
|
|
1704
1711
|
}, [t.current]), n;
|
|
@@ -1709,14 +1716,14 @@ function Yt({
|
|
|
1709
1716
|
itemPath: S,
|
|
1710
1717
|
localIndex: g,
|
|
1711
1718
|
arraySetter: y,
|
|
1712
|
-
rebuildStateShape:
|
|
1713
|
-
renderFn:
|
|
1719
|
+
rebuildStateShape: w,
|
|
1720
|
+
renderFn: T
|
|
1714
1721
|
}) {
|
|
1715
|
-
const [, u] = K({}), { ref: f, inView: A } = jt(),
|
|
1722
|
+
const [, u] = K({}), { ref: f, inView: A } = jt(), I = q(null), i = Jt(I), h = q(!1), M = [t, ...S].join(".");
|
|
1716
1723
|
$t(t, n, u);
|
|
1717
1724
|
const z = ct(
|
|
1718
1725
|
(W) => {
|
|
1719
|
-
|
|
1726
|
+
I.current = W, f(W);
|
|
1720
1727
|
},
|
|
1721
1728
|
[f]
|
|
1722
1729
|
);
|
|
@@ -1727,7 +1734,7 @@ function Yt({
|
|
|
1727
1734
|
}, []), Z(() => {
|
|
1728
1735
|
if (!A || !i || h.current)
|
|
1729
1736
|
return;
|
|
1730
|
-
const W =
|
|
1737
|
+
const W = I.current;
|
|
1731
1738
|
if (W && W.offsetHeight > 0) {
|
|
1732
1739
|
h.current = !0;
|
|
1733
1740
|
const m = W.offsetHeight;
|
|
@@ -1741,18 +1748,18 @@ function Yt({
|
|
|
1741
1748
|
e.getState().notifyPathSubscribers(Q, {
|
|
1742
1749
|
type: "ITEMHEIGHT",
|
|
1743
1750
|
itemKey: S.join("."),
|
|
1744
|
-
ref:
|
|
1751
|
+
ref: I.current
|
|
1745
1752
|
});
|
|
1746
1753
|
}
|
|
1747
1754
|
}, [A, i, t, S]);
|
|
1748
1755
|
const c = [t, ...S].join("."), B = e.getState().getShadowValue(c);
|
|
1749
1756
|
if (B === void 0)
|
|
1750
1757
|
return null;
|
|
1751
|
-
const J =
|
|
1758
|
+
const J = w({
|
|
1752
1759
|
currentState: B,
|
|
1753
1760
|
path: S,
|
|
1754
1761
|
componentId: n
|
|
1755
|
-
}), H =
|
|
1762
|
+
}), H = T(J, g, y);
|
|
1756
1763
|
return /* @__PURE__ */ ot("div", { ref: z, children: H });
|
|
1757
1764
|
}
|
|
1758
1765
|
function Zt({
|
|
@@ -1761,16 +1768,16 @@ function Zt({
|
|
|
1761
1768
|
rebuildStateShape: S,
|
|
1762
1769
|
renderFn: g,
|
|
1763
1770
|
formOpts: y,
|
|
1764
|
-
setState:
|
|
1771
|
+
setState: w
|
|
1765
1772
|
}) {
|
|
1766
|
-
const [
|
|
1767
|
-
$t(t,
|
|
1768
|
-
const A = e.getState().getShadowValue(f), [
|
|
1773
|
+
const [T] = K(() => rt()), [, u] = K({}), f = [t, ...n].join(".");
|
|
1774
|
+
$t(t, T, u);
|
|
1775
|
+
const A = e.getState().getShadowValue(f), [I, i] = K(A), h = q(!1), M = q(null);
|
|
1769
1776
|
Z(() => {
|
|
1770
|
-
!h.current && !st(A,
|
|
1777
|
+
!h.current && !st(A, I) && i(A);
|
|
1771
1778
|
}, [A]), Z(() => {
|
|
1772
1779
|
const H = e.getState().subscribeToPath(f, (W) => {
|
|
1773
|
-
!h.current &&
|
|
1780
|
+
!h.current && I !== W && u({});
|
|
1774
1781
|
});
|
|
1775
1782
|
return () => {
|
|
1776
1783
|
H(), M.current && (clearTimeout(M.current), h.current = !1);
|
|
@@ -1781,7 +1788,7 @@ function Zt({
|
|
|
1781
1788
|
typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
|
|
1782
1789
|
const m = y?.debounceTime ?? 200;
|
|
1783
1790
|
M.current = setTimeout(() => {
|
|
1784
|
-
h.current = !1,
|
|
1791
|
+
h.current = !1, w(H, n, { updateType: "update" });
|
|
1785
1792
|
const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
|
|
1786
1793
|
if (o) {
|
|
1787
1794
|
const r = e.getState().getShadowValue(t), a = o.safeParse(r), d = X(t, n) || {};
|
|
@@ -1815,9 +1822,9 @@ function Zt({
|
|
|
1815
1822
|
}
|
|
1816
1823
|
}, m), u({});
|
|
1817
1824
|
},
|
|
1818
|
-
[
|
|
1825
|
+
[w, n, y?.debounceTime, t]
|
|
1819
1826
|
), c = ct(async () => {
|
|
1820
|
-
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I
|
|
1827
|
+
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, w(I, n, { updateType: "update" }));
|
|
1821
1828
|
const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
|
|
1822
1829
|
if (!m) return;
|
|
1823
1830
|
const Y = e.getState().getShadowMetadata(t, n);
|
|
@@ -1825,7 +1832,7 @@ function Zt({
|
|
|
1825
1832
|
...Y,
|
|
1826
1833
|
validation: {
|
|
1827
1834
|
status: "DIRTY",
|
|
1828
|
-
validatedValue:
|
|
1835
|
+
validatedValue: I
|
|
1829
1836
|
}
|
|
1830
1837
|
});
|
|
1831
1838
|
const Q = e.getState().getShadowValue(t), X = m.safeParse(Q);
|
|
@@ -1834,7 +1841,7 @@ function Zt({
|
|
|
1834
1841
|
...Y,
|
|
1835
1842
|
validation: {
|
|
1836
1843
|
status: "VALID_PENDING_SYNC",
|
|
1837
|
-
validatedValue:
|
|
1844
|
+
validatedValue: I
|
|
1838
1845
|
}
|
|
1839
1846
|
});
|
|
1840
1847
|
else {
|
|
@@ -1849,12 +1856,12 @@ function Zt({
|
|
|
1849
1856
|
if (console.log("Array metadata:", l), l?.arrayKeys) {
|
|
1850
1857
|
const p = [t, ...n.slice(0, -1)].join("."), E = l.arrayKeys.indexOf(p);
|
|
1851
1858
|
console.log("Item key:", p, "Index:", E);
|
|
1852
|
-
const _ = [...d, E, ...n.slice(-1)],
|
|
1859
|
+
const _ = [...d, E, ...n.slice(-1)], O = JSON.stringify(r.path) === JSON.stringify(_);
|
|
1853
1860
|
return console.log("Zod path comparison:", {
|
|
1854
1861
|
zodPath: _,
|
|
1855
1862
|
errorPath: r.path,
|
|
1856
|
-
match:
|
|
1857
|
-
}),
|
|
1863
|
+
match: O
|
|
1864
|
+
}), O;
|
|
1858
1865
|
}
|
|
1859
1866
|
}
|
|
1860
1867
|
const a = JSON.stringify(r.path) === JSON.stringify(n);
|
|
@@ -1869,19 +1876,19 @@ function Zt({
|
|
|
1869
1876
|
validation: {
|
|
1870
1877
|
status: "VALIDATION_FAILED",
|
|
1871
1878
|
message: o[0]?.message,
|
|
1872
|
-
validatedValue:
|
|
1879
|
+
validatedValue: I
|
|
1873
1880
|
}
|
|
1874
1881
|
});
|
|
1875
1882
|
}
|
|
1876
1883
|
u({});
|
|
1877
|
-
}, [t, n,
|
|
1884
|
+
}, [t, n, I, w]), B = S({
|
|
1878
1885
|
currentState: A,
|
|
1879
1886
|
path: n,
|
|
1880
|
-
componentId:
|
|
1887
|
+
componentId: T
|
|
1881
1888
|
}), J = new Proxy(B, {
|
|
1882
1889
|
get(H, W) {
|
|
1883
1890
|
return W === "inputProps" ? {
|
|
1884
|
-
value:
|
|
1891
|
+
value: I ?? "",
|
|
1885
1892
|
onChange: (m) => {
|
|
1886
1893
|
z(m.target.value);
|
|
1887
1894
|
},
|
|
@@ -1896,13 +1903,13 @@ function Zt({
|
|
|
1896
1903
|
function $t(t, n, S) {
|
|
1897
1904
|
const g = `${t}////${n}`;
|
|
1898
1905
|
dt(() => {
|
|
1899
|
-
const { registerComponent: y, unregisterComponent:
|
|
1906
|
+
const { registerComponent: y, unregisterComponent: w } = e.getState();
|
|
1900
1907
|
return y(t, g, {
|
|
1901
1908
|
forceUpdate: () => S({}),
|
|
1902
1909
|
paths: /* @__PURE__ */ new Set(),
|
|
1903
1910
|
reactiveType: ["component"]
|
|
1904
1911
|
}), () => {
|
|
1905
|
-
|
|
1912
|
+
w(t, g);
|
|
1906
1913
|
};
|
|
1907
1914
|
}, [t, g]);
|
|
1908
1915
|
}
|