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