cogsbox-state 0.5.438 → 0.5.440
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 -3
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +211 -211
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +35 -11
package/dist/CogsState.jsx
CHANGED
|
@@ -9,43 +9,43 @@ import { v4 as rt } from "uuid";
|
|
|
9
9
|
import { getGlobalStore as e, formRefStore as vt } from "./store.js";
|
|
10
10
|
import { useCogsConfig as Pt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { useInView as jt } from "react-intersection-observer";
|
|
12
|
-
function yt(t,
|
|
12
|
+
function yt(t, r) {
|
|
13
13
|
const g = e.getState().getInitialOptions, S = e.getState().setInitialStateOptions, y = g(t) || {};
|
|
14
14
|
S(t, {
|
|
15
15
|
...y,
|
|
16
|
-
...
|
|
16
|
+
...r
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function Et({
|
|
20
20
|
stateKey: t,
|
|
21
|
-
options:
|
|
21
|
+
options: r,
|
|
22
22
|
initialOptionsPart: g
|
|
23
23
|
}) {
|
|
24
24
|
const S = nt(t) || {}, y = g[t] || {}, I = e.getState().setInitialStateOptions, E = { ...y, ...S };
|
|
25
25
|
let u = !1;
|
|
26
|
-
if (
|
|
27
|
-
for (const f in
|
|
28
|
-
E.hasOwnProperty(f) ? (f == "localStorage" &&
|
|
26
|
+
if (r)
|
|
27
|
+
for (const f in r)
|
|
28
|
+
E.hasOwnProperty(f) ? (f == "localStorage" && r[f] && E[f].key !== r[f]?.key && (u = !0, E[f] = r[f]), f == "defaultState" && r[f] && E[f] !== r[f] && !st(E[f], r[f]) && (u = !0, E[f] = r[f])) : (u = !0, E[f] = r[f]);
|
|
29
29
|
u && I(t, E);
|
|
30
30
|
}
|
|
31
|
-
function ie(t, { formElements:
|
|
32
|
-
return { initialState: t, formElements:
|
|
31
|
+
function ie(t, { formElements: r, validation: g }) {
|
|
32
|
+
return { initialState: t, formElements: r, validation: g };
|
|
33
33
|
}
|
|
34
|
-
const Lt = (t,
|
|
34
|
+
const Lt = (t, r) => {
|
|
35
35
|
let g = t;
|
|
36
36
|
const [S, y] = Nt(g);
|
|
37
|
-
|
|
37
|
+
r?.__fromSyncSchema && r?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", r.__syncNotifications), Object.keys(S).forEach((u) => {
|
|
38
38
|
let f = y[u] || {};
|
|
39
39
|
const A = {
|
|
40
40
|
...f
|
|
41
41
|
};
|
|
42
|
-
if (
|
|
43
|
-
...
|
|
42
|
+
if (r?.formElements && (A.formElements = {
|
|
43
|
+
...r.formElements,
|
|
44
44
|
...f.formElements || {}
|
|
45
|
-
}),
|
|
46
|
-
...
|
|
45
|
+
}), r?.validation && (A.validation = {
|
|
46
|
+
...r.validation,
|
|
47
47
|
...f.validation || {}
|
|
48
|
-
},
|
|
48
|
+
}, r.validation.key && !f.validation?.key && (A.validation.key = `${r.validation.key}.${u}`)), Object.keys(A).length > 0) {
|
|
49
49
|
const w = nt(u);
|
|
50
50
|
w ? e.getState().setInitialStateOptions(u, {
|
|
51
51
|
...w,
|
|
@@ -82,12 +82,12 @@ const Lt = (t, n) => {
|
|
|
82
82
|
return { useCogsState: I, setCogsOptions: E };
|
|
83
83
|
};
|
|
84
84
|
function ce(t) {
|
|
85
|
-
const
|
|
85
|
+
const r = {};
|
|
86
86
|
for (const g in t.schemas) {
|
|
87
87
|
const S = t.schemas[g];
|
|
88
|
-
S.rawSchema ?
|
|
88
|
+
S.rawSchema ? r[g] = S.rawSchema : S.schemas?.defaults ? r[g] = S.schemas.defaults : S._tableName ? r[g] = S : r[g] = {};
|
|
89
89
|
}
|
|
90
|
-
return Lt(
|
|
90
|
+
return Lt(r, {
|
|
91
91
|
__fromSyncSchema: !0,
|
|
92
92
|
__syncNotifications: t.notifications
|
|
93
93
|
});
|
|
@@ -99,22 +99,22 @@ const {
|
|
|
99
99
|
updateInitialStateGlobal: _t,
|
|
100
100
|
addValidationError: pt,
|
|
101
101
|
removeValidationError: ut
|
|
102
|
-
} = e.getState(), Ht = (t,
|
|
102
|
+
} = e.getState(), Ht = (t, r, g, S, y) => {
|
|
103
103
|
g?.log && console.log(
|
|
104
104
|
"saving to localstorage",
|
|
105
|
-
|
|
105
|
+
r,
|
|
106
106
|
g.localStorage?.key,
|
|
107
107
|
S
|
|
108
108
|
);
|
|
109
109
|
const I = at(g?.localStorage?.key) ? g.localStorage?.key(t) : g?.localStorage?.key;
|
|
110
110
|
if (I && S) {
|
|
111
|
-
const E = `${S}-${
|
|
111
|
+
const E = `${S}-${r}-${I}`;
|
|
112
112
|
let u;
|
|
113
113
|
try {
|
|
114
114
|
u = gt(E)?.lastSyncedWithServer;
|
|
115
115
|
} catch {
|
|
116
116
|
}
|
|
117
|
-
const f = e.getState().getShadowMetadata(
|
|
117
|
+
const f = e.getState().getShadowMetadata(r, []), A = {
|
|
118
118
|
state: t,
|
|
119
119
|
lastUpdated: Date.now(),
|
|
120
120
|
lastSyncedWithServer: u,
|
|
@@ -129,13 +129,13 @@ const {
|
|
|
129
129
|
}, gt = (t) => {
|
|
130
130
|
if (!t) return null;
|
|
131
131
|
try {
|
|
132
|
-
const
|
|
133
|
-
return
|
|
134
|
-
} catch (
|
|
135
|
-
return console.error("Error loading from localStorage:",
|
|
132
|
+
const r = window.localStorage.getItem(t);
|
|
133
|
+
return r ? JSON.parse(r) : null;
|
|
134
|
+
} catch (r) {
|
|
135
|
+
return console.error("Error loading from localStorage:", r), null;
|
|
136
136
|
}
|
|
137
|
-
}, xt = (t,
|
|
138
|
-
const g = e.getState().getShadowValue(t), { sessionId: S } = Pt(), y = at(
|
|
137
|
+
}, xt = (t, r) => {
|
|
138
|
+
const g = e.getState().getShadowValue(t), { sessionId: S } = Pt(), y = at(r?.localStorage?.key) ? r.localStorage.key(g) : r?.localStorage?.key;
|
|
139
139
|
if (y && S) {
|
|
140
140
|
const I = gt(
|
|
141
141
|
`${S}-${t}-${y}`
|
|
@@ -145,32 +145,32 @@ const {
|
|
|
145
145
|
}
|
|
146
146
|
return !1;
|
|
147
147
|
}, it = (t) => {
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
148
|
+
const r = e.getState().getShadowMetadata(t, []);
|
|
149
|
+
if (!r) return;
|
|
150
150
|
const g = /* @__PURE__ */ new Set();
|
|
151
|
-
|
|
151
|
+
r?.components?.forEach((S) => {
|
|
152
152
|
(S ? Array.isArray(S.reactiveType) ? S.reactiveType : [S.reactiveType || "component"] : null)?.includes("none") || g.add(() => S.forceUpdate());
|
|
153
153
|
}), queueMicrotask(() => {
|
|
154
154
|
g.forEach((S) => S());
|
|
155
155
|
});
|
|
156
|
-
}, ue = (t,
|
|
156
|
+
}, ue = (t, r) => {
|
|
157
157
|
const g = e.getState().getShadowMetadata(t, []);
|
|
158
158
|
if (g) {
|
|
159
|
-
const S = `${t}////${
|
|
159
|
+
const S = `${t}////${r}`, y = g?.components?.get(S);
|
|
160
160
|
if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
|
|
161
161
|
return;
|
|
162
162
|
y && y.forceUpdate();
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
|
-
function wt(t,
|
|
166
|
-
const y = e.getState(), I = y.getShadowMetadata(t,
|
|
167
|
-
if (y.setShadowMetadata(t,
|
|
165
|
+
function wt(t, r, g, S) {
|
|
166
|
+
const y = e.getState(), I = y.getShadowMetadata(t, r);
|
|
167
|
+
if (y.setShadowMetadata(t, r, {
|
|
168
168
|
...I,
|
|
169
169
|
isDirty: !1,
|
|
170
170
|
stateSource: "server",
|
|
171
171
|
lastServerSync: S || Date.now()
|
|
172
172
|
}), Array.isArray(g)) {
|
|
173
|
-
const E = y.getShadowMetadata(t,
|
|
173
|
+
const E = y.getShadowMetadata(t, r);
|
|
174
174
|
E?.arrayKeys && E.arrayKeys.forEach((u, f) => {
|
|
175
175
|
const A = u.split(".").slice(1), w = g[f];
|
|
176
176
|
w !== void 0 && wt(
|
|
@@ -181,12 +181,12 @@ function wt(t, n, g, S) {
|
|
|
181
181
|
);
|
|
182
182
|
});
|
|
183
183
|
} else g && typeof g == "object" && g.constructor === Object && Object.keys(g).forEach((E) => {
|
|
184
|
-
const u = [...
|
|
184
|
+
const u = [...r, E], f = g[E];
|
|
185
185
|
wt(t, u, f, S);
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
function zt(t, {
|
|
189
|
-
stateKey:
|
|
189
|
+
stateKey: r,
|
|
190
190
|
localStorage: g,
|
|
191
191
|
formElements: S,
|
|
192
192
|
reactiveDeps: y,
|
|
@@ -198,8 +198,8 @@ function zt(t, {
|
|
|
198
198
|
serverState: w
|
|
199
199
|
} = {}) {
|
|
200
200
|
const [i, h] = K({}), { sessionId: M } = Pt();
|
|
201
|
-
let z = !
|
|
202
|
-
const [c] = K(
|
|
201
|
+
let z = !r;
|
|
202
|
+
const [c] = K(r ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(E ?? rt()), W = q(
|
|
203
203
|
null
|
|
204
204
|
);
|
|
205
205
|
W.current = nt(c) ?? null, Z(() => {
|
|
@@ -241,9 +241,9 @@ function zt(t, {
|
|
|
241
241
|
);
|
|
242
242
|
Z(() => {
|
|
243
243
|
e.getState().setServerStateUpdate(c, w);
|
|
244
|
-
}, [w, c]), Z(() => e.getState().subscribeToPath(c, (
|
|
245
|
-
if (
|
|
246
|
-
const a =
|
|
244
|
+
}, [w, c]), Z(() => e.getState().subscribeToPath(c, (n) => {
|
|
245
|
+
if (n?.type === "SERVER_STATE_UPDATE") {
|
|
246
|
+
const a = n.serverState;
|
|
247
247
|
if (a?.status === "success" && a.data !== void 0) {
|
|
248
248
|
yt(c, { serverState: a });
|
|
249
249
|
const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), V = a.data;
|
|
@@ -295,10 +295,10 @@ function zt(t, {
|
|
|
295
295
|
const o = e.getState().getShadowMetadata(c, []);
|
|
296
296
|
if (o && o.stateSource)
|
|
297
297
|
return;
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
const a =
|
|
301
|
-
|
|
298
|
+
const n = nt(c);
|
|
299
|
+
if (n?.defaultState !== void 0 || u !== void 0) {
|
|
300
|
+
const a = n?.defaultState || u;
|
|
301
|
+
n?.defaultState || yt(c, {
|
|
302
302
|
defaultState: a
|
|
303
303
|
});
|
|
304
304
|
const { value: d, source: l, timestamp: p } = m();
|
|
@@ -316,7 +316,7 @@ function zt(t, {
|
|
|
316
316
|
localStorage: g,
|
|
317
317
|
middleware: W.current?.middleware
|
|
318
318
|
});
|
|
319
|
-
const o = `${c}////${H.current}`,
|
|
319
|
+
const o = `${c}////${H.current}`, n = e.getState().getShadowMetadata(c, []), a = n?.components || /* @__PURE__ */ new Map();
|
|
320
320
|
return a.set(o, {
|
|
321
321
|
forceUpdate: () => h({}),
|
|
322
322
|
reactiveType: I ?? ["component", "deps"],
|
|
@@ -325,7 +325,7 @@ function zt(t, {
|
|
|
325
325
|
deps: y ? y(e.getState().getShadowValue(c)) : [],
|
|
326
326
|
prevDeps: y ? y(e.getState().getShadowValue(c)) : []
|
|
327
327
|
}), e.getState().setShadowMetadata(c, [], {
|
|
328
|
-
...
|
|
328
|
+
...n,
|
|
329
329
|
components: a
|
|
330
330
|
}), h({}), () => {
|
|
331
331
|
const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
|
|
@@ -335,16 +335,16 @@ function zt(t, {
|
|
|
335
335
|
}), d?.components && e.getState().setShadowMetadata(c, [], d);
|
|
336
336
|
};
|
|
337
337
|
}, []);
|
|
338
|
-
const Y = q(null), Q = (o,
|
|
339
|
-
const d = [c, ...
|
|
340
|
-
if (Array.isArray(
|
|
341
|
-
const b = `${c}-${
|
|
338
|
+
const Y = q(null), Q = (o, n, a) => {
|
|
339
|
+
const d = [c, ...n].join(".");
|
|
340
|
+
if (Array.isArray(n)) {
|
|
341
|
+
const b = `${c}-${n.join(".")}`;
|
|
342
342
|
J.current.add(b);
|
|
343
343
|
}
|
|
344
|
-
const l = e.getState(), p = l.getShadowMetadata(c,
|
|
344
|
+
const l = e.getState(), p = l.getShadowMetadata(c, n), V = l.getShadowValue(d), _ = a.updateType === "insert" && at(o) ? o({ state: V, uuid: rt() }) : at(o) ? o(V) : o, C = {
|
|
345
345
|
timeStamp: Date.now(),
|
|
346
346
|
stateKey: c,
|
|
347
|
-
path:
|
|
347
|
+
path: n,
|
|
348
348
|
updateType: a.updateType,
|
|
349
349
|
status: "new",
|
|
350
350
|
oldValue: V,
|
|
@@ -352,8 +352,8 @@ function zt(t, {
|
|
|
352
352
|
};
|
|
353
353
|
switch (a.updateType) {
|
|
354
354
|
case "insert": {
|
|
355
|
-
l.insertShadowArrayElement(c,
|
|
356
|
-
const b = l.getShadowMetadata(c,
|
|
355
|
+
l.insertShadowArrayElement(c, n, C.newValue), l.markAsDirty(c, n, { bubble: !0 });
|
|
356
|
+
const b = l.getShadowMetadata(c, n);
|
|
357
357
|
if (b?.arrayKeys) {
|
|
358
358
|
const k = b.arrayKeys[b.arrayKeys.length - 1];
|
|
359
359
|
if (k) {
|
|
@@ -364,12 +364,12 @@ function zt(t, {
|
|
|
364
364
|
break;
|
|
365
365
|
}
|
|
366
366
|
case "cut": {
|
|
367
|
-
const b =
|
|
368
|
-
l.removeShadowArrayElement(c,
|
|
367
|
+
const b = n.slice(0, -1);
|
|
368
|
+
l.removeShadowArrayElement(c, n), l.markAsDirty(c, b, { bubble: !0 });
|
|
369
369
|
break;
|
|
370
370
|
}
|
|
371
371
|
case "update": {
|
|
372
|
-
l.updateShadowAtPath(c,
|
|
372
|
+
l.updateShadowAtPath(c, n, C.newValue), l.markAsDirty(c, n, { bubble: !0 });
|
|
373
373
|
break;
|
|
374
374
|
}
|
|
375
375
|
}
|
|
@@ -396,8 +396,8 @@ function zt(t, {
|
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
398
|
if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
|
|
399
|
-
const b = l.getShadowMetadata(c,
|
|
400
|
-
[c, ...
|
|
399
|
+
const b = l.getShadowMetadata(c, n)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), O = l.getShadowValue(
|
|
400
|
+
[c, ...n].join(".")
|
|
401
401
|
);
|
|
402
402
|
if (!k || P === void 0) return;
|
|
403
403
|
p.mapWrappers.forEach((v) => {
|
|
@@ -411,7 +411,7 @@ function zt(t, {
|
|
|
411
411
|
if (T) {
|
|
412
412
|
const D = It(
|
|
413
413
|
c,
|
|
414
|
-
|
|
414
|
+
n,
|
|
415
415
|
v.meta.transforms
|
|
416
416
|
), R = v.meta.transforms.find(
|
|
417
417
|
(L) => L.type === "sort"
|
|
@@ -458,7 +458,7 @@ function zt(t, {
|
|
|
458
458
|
});
|
|
459
459
|
}
|
|
460
460
|
if (a.updateType === "cut") {
|
|
461
|
-
const b =
|
|
461
|
+
const b = n.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
462
462
|
k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
|
|
463
463
|
if (P.containerRef && P.containerRef.isConnected) {
|
|
464
464
|
const O = P.containerRef.querySelector(
|
|
@@ -476,7 +476,7 @@ function zt(t, {
|
|
|
476
476
|
), !N?.components)
|
|
477
477
|
return x;
|
|
478
478
|
if (a.updateType === "update") {
|
|
479
|
-
let b = [...
|
|
479
|
+
let b = [...n];
|
|
480
480
|
for (; ; ) {
|
|
481
481
|
const k = l.getShadowMetadata(c, b);
|
|
482
482
|
if (k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
@@ -489,7 +489,7 @@ function zt(t, {
|
|
|
489
489
|
b.pop();
|
|
490
490
|
}
|
|
491
491
|
_ && typeof _ == "object" && !Tt(_) && V && typeof V == "object" && !Tt(V) && Ct(_, V).forEach((P) => {
|
|
492
|
-
const O = P.split("."), v = [...
|
|
492
|
+
const O = P.split("."), v = [...n, ...O], T = l.getShadowMetadata(c, v);
|
|
493
493
|
T?.pathComponents && T.pathComponents.forEach(($) => {
|
|
494
494
|
if (j.has($))
|
|
495
495
|
return;
|
|
@@ -498,7 +498,7 @@ function zt(t, {
|
|
|
498
498
|
});
|
|
499
499
|
});
|
|
500
500
|
} else if (a.updateType === "insert" || a.updateType === "cut") {
|
|
501
|
-
const b = a.updateType === "insert" ?
|
|
501
|
+
const b = a.updateType === "insert" ? n : n.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
502
502
|
if (k?.signals && k.signals.length > 0) {
|
|
503
503
|
const P = [c, ...b].join("."), O = l.getShadowValue(P);
|
|
504
504
|
k.signals.forEach(({ parentId: v, position: T, effect: $ }) => {
|
|
@@ -570,14 +570,14 @@ function zt(t, {
|
|
|
570
570
|
}
|
|
571
571
|
function Bt(t) {
|
|
572
572
|
return !t || t.length === 0 ? "" : t.map(
|
|
573
|
-
(
|
|
573
|
+
(r) => (
|
|
574
574
|
// Safely stringify dependencies. An empty array becomes '[]'.
|
|
575
|
-
`${
|
|
575
|
+
`${r.type}${JSON.stringify(r.dependencies || [])}`
|
|
576
576
|
)
|
|
577
577
|
).join("");
|
|
578
578
|
}
|
|
579
|
-
const It = (t,
|
|
580
|
-
let S = e.getState().getShadowMetadata(t,
|
|
579
|
+
const It = (t, r, g) => {
|
|
580
|
+
let S = e.getState().getShadowMetadata(t, r)?.arrayKeys || [];
|
|
581
581
|
if (!g || g.length === 0)
|
|
582
582
|
return S;
|
|
583
583
|
let y = S.map((I) => ({
|
|
@@ -589,17 +589,17 @@ const It = (t, n, g) => {
|
|
|
589
589
|
({ value: E }, u) => I.fn(E, u)
|
|
590
590
|
) : I.type === "sort" && y.sort((E, u) => I.fn(E.value, u.value));
|
|
591
591
|
return y.map(({ key: I }) => I);
|
|
592
|
-
}, Vt = (t,
|
|
593
|
-
const S = `${t}////${
|
|
592
|
+
}, Vt = (t, r, g) => {
|
|
593
|
+
const S = `${t}////${r}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), u = I(t, [])?.components?.get(S);
|
|
594
594
|
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, g, S);
|
|
595
|
-
}, ft = (t,
|
|
595
|
+
}, ft = (t, r, g) => {
|
|
596
596
|
const S = e.getState(), y = S.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
|
|
597
597
|
y?.components && y.components.forEach((u, f) => {
|
|
598
598
|
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), I.add(f));
|
|
599
|
-
}), S.getShadowMetadata(t, [...
|
|
599
|
+
}), S.getShadowMetadata(t, [...r, "getSelected"])?.pathComponents?.forEach((u) => {
|
|
600
600
|
y?.components?.get(u)?.forceUpdate();
|
|
601
601
|
});
|
|
602
|
-
const E = S.getShadowMetadata(t,
|
|
602
|
+
const E = S.getShadowMetadata(t, r);
|
|
603
603
|
for (let u of E?.arrayKeys || []) {
|
|
604
604
|
const f = u + ".selected", A = S.getShadowMetadata(
|
|
605
605
|
t,
|
|
@@ -610,7 +610,7 @@ const It = (t, n, g) => {
|
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
612
|
};
|
|
613
|
-
function Dt(t,
|
|
613
|
+
function Dt(t, r, g, S) {
|
|
614
614
|
const y = /* @__PURE__ */ new Map();
|
|
615
615
|
let I = 0;
|
|
616
616
|
const E = (w) => {
|
|
@@ -640,17 +640,17 @@ function Dt(t, n, g, S) {
|
|
|
640
640
|
if (m === "getDifferences")
|
|
641
641
|
return () => {
|
|
642
642
|
const s = e.getState().getShadowMetadata(t, []), o = e.getState().getShadowValue(t);
|
|
643
|
-
let
|
|
644
|
-
return s?.stateSource === "server" && s.baseServerState ?
|
|
643
|
+
let n;
|
|
644
|
+
return s?.stateSource === "server" && s.baseServerState ? n = s.baseServerState : n = e.getState().initialStateGlobal[t], Ct(o, n);
|
|
645
645
|
};
|
|
646
646
|
if (m === "sync" && i.length === 0)
|
|
647
647
|
return async function() {
|
|
648
648
|
const s = e.getState().getInitialOptions(t), o = s?.sync;
|
|
649
649
|
if (!o)
|
|
650
650
|
return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
|
|
651
|
-
const
|
|
651
|
+
const n = e.getState().getShadowValue(t, []), a = s?.validation?.key;
|
|
652
652
|
try {
|
|
653
|
-
const d = await o.action(
|
|
653
|
+
const d = await o.action(n);
|
|
654
654
|
if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((l) => {
|
|
655
655
|
const p = [a, ...l.path].join(".");
|
|
656
656
|
e.getState().addValidationError(p, l.message);
|
|
@@ -661,7 +661,7 @@ function Dt(t, n, g, S) {
|
|
|
661
661
|
isDirty: !1,
|
|
662
662
|
lastServerSync: Date.now(),
|
|
663
663
|
stateSource: "server",
|
|
664
|
-
baseServerState:
|
|
664
|
+
baseServerState: n
|
|
665
665
|
// Update base server state
|
|
666
666
|
}), o.onSuccess && o.onSuccess(d.data);
|
|
667
667
|
} else !d?.success && o.onError && o.onError(d.error);
|
|
@@ -672,14 +672,14 @@ function Dt(t, n, g, S) {
|
|
|
672
672
|
};
|
|
673
673
|
if (m === "_status" || m === "getStatus") {
|
|
674
674
|
const s = () => {
|
|
675
|
-
const o = e.getState().getShadowMetadata(t, i),
|
|
676
|
-
return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" :
|
|
675
|
+
const o = e.getState().getShadowMetadata(t, i), n = e.getState().getShadowValue(c);
|
|
676
|
+
return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" : n !== void 0 && !o ? "fresh" : "unknown";
|
|
677
677
|
};
|
|
678
678
|
return m === "_status" ? s() : s;
|
|
679
679
|
}
|
|
680
680
|
if (m === "removeStorage")
|
|
681
681
|
return () => {
|
|
682
|
-
const s = e.getState().initialStateGlobal[t], o = nt(t),
|
|
682
|
+
const s = e.getState().initialStateGlobal[t], o = nt(t), n = at(o?.localStorage?.key) ? o.localStorage.key(s) : o?.localStorage?.key, a = `${S}-${t}-${n}`;
|
|
683
683
|
a && localStorage.removeItem(a);
|
|
684
684
|
};
|
|
685
685
|
if (m === "showValidationErrors")
|
|
@@ -698,14 +698,14 @@ function Dt(t, n, g, S) {
|
|
|
698
698
|
const o = e.getState().selectedIndicesMap;
|
|
699
699
|
if (!o || !o.has(s))
|
|
700
700
|
return;
|
|
701
|
-
const
|
|
702
|
-
if (h?.validIds && !h.validIds.includes(
|
|
701
|
+
const n = o.get(s);
|
|
702
|
+
if (h?.validIds && !h.validIds.includes(n))
|
|
703
703
|
return;
|
|
704
|
-
const a = e.getState().getShadowValue(
|
|
704
|
+
const a = e.getState().getShadowValue(n);
|
|
705
705
|
if (a)
|
|
706
706
|
return u({
|
|
707
707
|
currentState: a,
|
|
708
|
-
path:
|
|
708
|
+
path: n.split(".").slice(1),
|
|
709
709
|
componentId: M
|
|
710
710
|
});
|
|
711
711
|
};
|
|
@@ -724,7 +724,7 @@ function Dt(t, n, g, S) {
|
|
|
724
724
|
return (s) => {
|
|
725
725
|
const {
|
|
726
726
|
itemHeight: o = 50,
|
|
727
|
-
overscan:
|
|
727
|
+
overscan: n = 6,
|
|
728
728
|
stickToBottom: a = !1,
|
|
729
729
|
scrollStickTolerance: d = 75
|
|
730
730
|
} = s, l = q(null), [p, V] = K({
|
|
@@ -766,7 +766,7 @@ function Dt(t, n, g, S) {
|
|
|
766
766
|
v.clientHeight / o
|
|
767
767
|
), D = N.length - 1, R = Math.max(
|
|
768
768
|
0,
|
|
769
|
-
D - $ -
|
|
769
|
+
D - $ - n
|
|
770
770
|
);
|
|
771
771
|
V({ startIndex: R, endIndex: D }), requestAnimationFrame(() => {
|
|
772
772
|
P("instant"), C.current = !1;
|
|
@@ -776,7 +776,7 @@ function Dt(t, n, g, S) {
|
|
|
776
776
|
};
|
|
777
777
|
T();
|
|
778
778
|
}
|
|
779
|
-
}, [N.length, a, o,
|
|
779
|
+
}, [N.length, a, o, n]);
|
|
780
780
|
const k = ct(() => {
|
|
781
781
|
const v = l.current;
|
|
782
782
|
if (!v) return;
|
|
@@ -793,10 +793,10 @@ function Dt(t, n, g, S) {
|
|
|
793
793
|
if (tt !== p.startIndex) {
|
|
794
794
|
const et = Math.ceil(D / o);
|
|
795
795
|
V({
|
|
796
|
-
startIndex: Math.max(0, tt -
|
|
796
|
+
startIndex: Math.max(0, tt - n),
|
|
797
797
|
endIndex: Math.min(
|
|
798
798
|
N.length - 1,
|
|
799
|
-
tt + et +
|
|
799
|
+
tt + et + n
|
|
800
800
|
)
|
|
801
801
|
});
|
|
802
802
|
}
|
|
@@ -804,7 +804,7 @@ function Dt(t, n, g, S) {
|
|
|
804
804
|
N.length,
|
|
805
805
|
p.startIndex,
|
|
806
806
|
o,
|
|
807
|
-
|
|
807
|
+
n,
|
|
808
808
|
d
|
|
809
809
|
]);
|
|
810
810
|
Z(() => {
|
|
@@ -921,7 +921,7 @@ function Dt(t, n, g, S) {
|
|
|
921
921
|
};
|
|
922
922
|
if (m === "stateMap")
|
|
923
923
|
return (s) => {
|
|
924
|
-
const [o,
|
|
924
|
+
const [o, n] = K(
|
|
925
925
|
h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys
|
|
926
926
|
), a = e.getState().getShadowValue(c, h?.validIds);
|
|
927
927
|
if (!o)
|
|
@@ -960,11 +960,11 @@ function Dt(t, n, g, S) {
|
|
|
960
960
|
return (s) => {
|
|
961
961
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
962
962
|
if (o)
|
|
963
|
-
for (let
|
|
964
|
-
const a = o[
|
|
963
|
+
for (let n = 0; n < o.length; n++) {
|
|
964
|
+
const a = o[n];
|
|
965
965
|
if (!a) continue;
|
|
966
966
|
const d = e.getState().getShadowValue(a);
|
|
967
|
-
if (s(d,
|
|
967
|
+
if (s(d, n)) {
|
|
968
968
|
const l = a.split(".").slice(1);
|
|
969
969
|
return u({
|
|
970
970
|
currentState: d,
|
|
@@ -981,15 +981,15 @@ function Dt(t, n, g, S) {
|
|
|
981
981
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
982
982
|
if (!o)
|
|
983
983
|
throw new Error("No array keys found for filtering.");
|
|
984
|
-
const
|
|
985
|
-
(d, l) => s(d, l) ? (
|
|
984
|
+
const n = [], a = w.filter(
|
|
985
|
+
(d, l) => s(d, l) ? (n.push(o[l]), !0) : !1
|
|
986
986
|
);
|
|
987
987
|
return u({
|
|
988
988
|
currentState: a,
|
|
989
989
|
path: i,
|
|
990
990
|
componentId: M,
|
|
991
991
|
meta: {
|
|
992
|
-
validIds:
|
|
992
|
+
validIds: n,
|
|
993
993
|
transforms: [
|
|
994
994
|
...h?.transforms || [],
|
|
995
995
|
{
|
|
@@ -1005,16 +1005,16 @@ function Dt(t, n, g, S) {
|
|
|
1005
1005
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1006
1006
|
if (!o)
|
|
1007
1007
|
throw new Error("No array keys found for sorting");
|
|
1008
|
-
const
|
|
1008
|
+
const n = w.map((a, d) => ({
|
|
1009
1009
|
item: a,
|
|
1010
1010
|
key: o[d]
|
|
1011
1011
|
}));
|
|
1012
|
-
return
|
|
1013
|
-
currentState:
|
|
1012
|
+
return n.sort((a, d) => s(a.item, d.item)).filter(Boolean), u({
|
|
1013
|
+
currentState: n.map((a) => a.item),
|
|
1014
1014
|
path: i,
|
|
1015
1015
|
componentId: M,
|
|
1016
1016
|
meta: {
|
|
1017
|
-
validIds:
|
|
1017
|
+
validIds: n.map((a) => a.key),
|
|
1018
1018
|
transforms: [
|
|
1019
1019
|
...h?.transforms || [],
|
|
1020
1020
|
{ type: "sort", fn: s }
|
|
@@ -1026,7 +1026,7 @@ function Dt(t, n, g, S) {
|
|
|
1026
1026
|
return function(s = {}) {
|
|
1027
1027
|
const {
|
|
1028
1028
|
bufferSize: o = 100,
|
|
1029
|
-
flushInterval:
|
|
1029
|
+
flushInterval: n = 100,
|
|
1030
1030
|
bufferStrategy: a = "accumulate",
|
|
1031
1031
|
store: d,
|
|
1032
1032
|
onFlush: l
|
|
@@ -1046,19 +1046,19 @@ function Dt(t, n, g, S) {
|
|
|
1046
1046
|
if (p = [], d) {
|
|
1047
1047
|
const b = d(j);
|
|
1048
1048
|
b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((P) => {
|
|
1049
|
-
|
|
1049
|
+
r(P, i, {
|
|
1050
1050
|
updateType: "insert"
|
|
1051
1051
|
});
|
|
1052
1052
|
});
|
|
1053
1053
|
} else
|
|
1054
1054
|
j.forEach((b) => {
|
|
1055
|
-
|
|
1055
|
+
r(b, i, {
|
|
1056
1056
|
updateType: "insert"
|
|
1057
1057
|
});
|
|
1058
1058
|
});
|
|
1059
1059
|
l?.(j);
|
|
1060
1060
|
};
|
|
1061
|
-
|
|
1061
|
+
n > 0 && (_ = setInterval(C, n));
|
|
1062
1062
|
const F = rt(), x = e.getState().getShadowMetadata(t, i) || {}, N = x.streams || /* @__PURE__ */ new Map();
|
|
1063
1063
|
return N.set(F, { buffer: p, flushTimer: _ }), e.getState().setShadowMetadata(t, i, {
|
|
1064
1064
|
...x,
|
|
@@ -1082,7 +1082,7 @@ function Dt(t, n, g, S) {
|
|
|
1082
1082
|
};
|
|
1083
1083
|
if (m === "stateList")
|
|
1084
1084
|
return (s) => /* @__PURE__ */ ot(() => {
|
|
1085
|
-
const
|
|
1085
|
+
const n = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${M}-${Bt(h.transforms)}` : `${M}-base`, [d, l] = K({}), { validIds: p, arrayValues: V } = St(() => {
|
|
1086
1086
|
const U = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
|
|
1087
1087
|
let C;
|
|
1088
1088
|
U && U.validIds ? C = U.validIds : (C = It(
|
|
@@ -1128,8 +1128,8 @@ function Dt(t, n, g, S) {
|
|
|
1128
1128
|
const F = p[C];
|
|
1129
1129
|
if (!F)
|
|
1130
1130
|
return null;
|
|
1131
|
-
let x =
|
|
1132
|
-
x || (x = rt(),
|
|
1131
|
+
let x = n.current.get(F);
|
|
1132
|
+
x || (x = rt(), n.current.set(F, x));
|
|
1133
1133
|
const N = F.split(".").slice(1);
|
|
1134
1134
|
return lt(Mt, {
|
|
1135
1135
|
key: F,
|
|
@@ -1147,11 +1147,11 @@ function Dt(t, n, g, S) {
|
|
|
1147
1147
|
return (s) => {
|
|
1148
1148
|
const o = w;
|
|
1149
1149
|
y.clear(), I++;
|
|
1150
|
-
const
|
|
1150
|
+
const n = o.flatMap(
|
|
1151
1151
|
(a) => a[s] ?? []
|
|
1152
1152
|
);
|
|
1153
1153
|
return u({
|
|
1154
|
-
currentState:
|
|
1154
|
+
currentState: n,
|
|
1155
1155
|
path: [...i, "[*]", s],
|
|
1156
1156
|
componentId: M,
|
|
1157
1157
|
meta: h
|
|
@@ -1159,14 +1159,14 @@ function Dt(t, n, g, S) {
|
|
|
1159
1159
|
};
|
|
1160
1160
|
if (m === "index")
|
|
1161
1161
|
return (s) => {
|
|
1162
|
-
const
|
|
1162
|
+
const n = e.getState().getShadowMetadata(t, i)?.arrayKeys?.filter(
|
|
1163
1163
|
(l) => !h?.validIds || h?.validIds && h?.validIds?.includes(l)
|
|
1164
1164
|
)?.[s];
|
|
1165
|
-
if (!
|
|
1166
|
-
const a = e.getState().getShadowValue(
|
|
1165
|
+
if (!n) return;
|
|
1166
|
+
const a = e.getState().getShadowValue(n, h?.validIds);
|
|
1167
1167
|
return u({
|
|
1168
1168
|
currentState: a,
|
|
1169
|
-
path:
|
|
1169
|
+
path: n.split(".").slice(1),
|
|
1170
1170
|
componentId: M,
|
|
1171
1171
|
meta: h
|
|
1172
1172
|
});
|
|
@@ -1175,23 +1175,23 @@ function Dt(t, n, g, S) {
|
|
|
1175
1175
|
return () => {
|
|
1176
1176
|
const s = e.getState().getShadowValue(t, i);
|
|
1177
1177
|
if (s.length === 0) return;
|
|
1178
|
-
const o = s.length - 1,
|
|
1178
|
+
const o = s.length - 1, n = s[o], a = [...i, o.toString()];
|
|
1179
1179
|
return u({
|
|
1180
|
-
currentState:
|
|
1180
|
+
currentState: n,
|
|
1181
1181
|
path: a,
|
|
1182
1182
|
componentId: M,
|
|
1183
1183
|
meta: h
|
|
1184
1184
|
});
|
|
1185
1185
|
};
|
|
1186
1186
|
if (m === "insert")
|
|
1187
|
-
return (s, o) => (
|
|
1187
|
+
return (s, o) => (r(s, i, { updateType: "insert" }), u({
|
|
1188
1188
|
currentState: e.getState().getShadowValue(t, i),
|
|
1189
1189
|
path: i,
|
|
1190
1190
|
componentId: M,
|
|
1191
1191
|
meta: h
|
|
1192
1192
|
}));
|
|
1193
1193
|
if (m === "uniqueInsert")
|
|
1194
|
-
return (s, o,
|
|
1194
|
+
return (s, o, n) => {
|
|
1195
1195
|
const a = e.getState().getShadowValue(t, i), d = at(s) ? s(a) : s;
|
|
1196
1196
|
let l = null;
|
|
1197
1197
|
if (!a.some((V) => {
|
|
@@ -1200,24 +1200,24 @@ function Dt(t, n, g, S) {
|
|
|
1200
1200
|
) : st(V, d);
|
|
1201
1201
|
return _ && (l = V), _;
|
|
1202
1202
|
}))
|
|
1203
|
-
E(i),
|
|
1204
|
-
else if (
|
|
1205
|
-
const V =
|
|
1203
|
+
E(i), r(d, i, { updateType: "insert" });
|
|
1204
|
+
else if (n && l) {
|
|
1205
|
+
const V = n(l), _ = a.map(
|
|
1206
1206
|
(U) => st(U, l) ? V : U
|
|
1207
1207
|
);
|
|
1208
|
-
E(i),
|
|
1208
|
+
E(i), r(_, i, {
|
|
1209
1209
|
updateType: "update"
|
|
1210
1210
|
});
|
|
1211
1211
|
}
|
|
1212
1212
|
};
|
|
1213
1213
|
if (m === "cut")
|
|
1214
1214
|
return (s, o) => {
|
|
1215
|
-
const
|
|
1216
|
-
if (!
|
|
1217
|
-
const a = s == -1 ?
|
|
1215
|
+
const n = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1216
|
+
if (!n || n.length === 0) return;
|
|
1217
|
+
const a = s == -1 ? n.length - 1 : s !== void 0 ? s : n.length - 1, d = n[a];
|
|
1218
1218
|
if (!d) return;
|
|
1219
1219
|
const l = d.split(".").slice(1);
|
|
1220
|
-
|
|
1220
|
+
r(w, l, {
|
|
1221
1221
|
updateType: "cut"
|
|
1222
1222
|
});
|
|
1223
1223
|
};
|
|
@@ -1230,37 +1230,37 @@ function Dt(t, n, g, S) {
|
|
|
1230
1230
|
);
|
|
1231
1231
|
if (!s || s.length === 0) return;
|
|
1232
1232
|
const o = e.getState().selectedIndicesMap.get(c);
|
|
1233
|
-
let
|
|
1233
|
+
let n = s.findIndex(
|
|
1234
1234
|
(l) => l === o
|
|
1235
1235
|
);
|
|
1236
|
-
const a = s[
|
|
1236
|
+
const a = s[n == -1 ? s.length - 1 : n]?.split(".").slice(1);
|
|
1237
1237
|
e.getState().clearSelectedIndex({ arrayKey: c });
|
|
1238
1238
|
const d = a?.slice(0, -1);
|
|
1239
|
-
ft(t, d),
|
|
1239
|
+
ft(t, d), r(w, a, {
|
|
1240
1240
|
updateType: "cut"
|
|
1241
1241
|
});
|
|
1242
1242
|
};
|
|
1243
1243
|
if (m === "cutByValue")
|
|
1244
1244
|
return (s) => {
|
|
1245
|
-
const o = e.getState().getShadowMetadata(t, i),
|
|
1246
|
-
if (!
|
|
1245
|
+
const o = e.getState().getShadowMetadata(t, i), n = h?.validIds ?? o?.arrayKeys;
|
|
1246
|
+
if (!n) return;
|
|
1247
1247
|
let a = null;
|
|
1248
|
-
for (const d of
|
|
1248
|
+
for (const d of n)
|
|
1249
1249
|
if (e.getState().getShadowValue(d) === s) {
|
|
1250
1250
|
a = d;
|
|
1251
1251
|
break;
|
|
1252
1252
|
}
|
|
1253
1253
|
if (a) {
|
|
1254
1254
|
const d = a.split(".").slice(1);
|
|
1255
|
-
|
|
1255
|
+
r(null, d, { updateType: "cut" });
|
|
1256
1256
|
}
|
|
1257
1257
|
};
|
|
1258
1258
|
if (m === "toggleByValue")
|
|
1259
1259
|
return (s) => {
|
|
1260
|
-
const o = e.getState().getShadowMetadata(t, i),
|
|
1261
|
-
if (!
|
|
1260
|
+
const o = e.getState().getShadowMetadata(t, i), n = h?.validIds ?? o?.arrayKeys;
|
|
1261
|
+
if (!n) return;
|
|
1262
1262
|
let a = null;
|
|
1263
|
-
for (const d of
|
|
1263
|
+
for (const d of n) {
|
|
1264
1264
|
const l = e.getState().getShadowValue(d);
|
|
1265
1265
|
if (console.log("itemValue sdasdasdasd", l), l === s) {
|
|
1266
1266
|
a = d;
|
|
@@ -1269,19 +1269,19 @@ function Dt(t, n, g, S) {
|
|
|
1269
1269
|
}
|
|
1270
1270
|
if (console.log("itemValue keyToCut", a), a) {
|
|
1271
1271
|
const d = a.split(".").slice(1);
|
|
1272
|
-
console.log("itemValue keyToCut", a),
|
|
1272
|
+
console.log("itemValue keyToCut", a), r(s, d, {
|
|
1273
1273
|
updateType: "cut"
|
|
1274
1274
|
});
|
|
1275
1275
|
} else
|
|
1276
|
-
|
|
1276
|
+
r(s, i, { updateType: "insert" });
|
|
1277
1277
|
};
|
|
1278
1278
|
if (m === "findWith")
|
|
1279
1279
|
return (s, o) => {
|
|
1280
|
-
const
|
|
1281
|
-
if (!
|
|
1280
|
+
const n = e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1281
|
+
if (!n)
|
|
1282
1282
|
throw new Error("No array keys found for sorting");
|
|
1283
1283
|
let a = null, d = [];
|
|
1284
|
-
for (const l of
|
|
1284
|
+
for (const l of n) {
|
|
1285
1285
|
let p = e.getState().getShadowValue(l, h?.validIds);
|
|
1286
1286
|
if (p && p[s] === o) {
|
|
1287
1287
|
a = p, d = l.split(".").slice(1);
|
|
@@ -1299,7 +1299,7 @@ function Dt(t, n, g, S) {
|
|
|
1299
1299
|
if (m === "cut") {
|
|
1300
1300
|
let s = e.getState().getShadowValue(i.join("."));
|
|
1301
1301
|
return () => {
|
|
1302
|
-
|
|
1302
|
+
r(s, i, { updateType: "cut" });
|
|
1303
1303
|
};
|
|
1304
1304
|
}
|
|
1305
1305
|
if (m === "get")
|
|
@@ -1327,20 +1327,20 @@ function Dt(t, n, g, S) {
|
|
|
1327
1327
|
e.getState().getShadowValue(s.join("."), h?.validIds)
|
|
1328
1328
|
)) {
|
|
1329
1329
|
i[i.length - 1];
|
|
1330
|
-
const o = s.join("."),
|
|
1331
|
-
return
|
|
1330
|
+
const o = s.join("."), n = e.getState().selectedIndicesMap.get(o), a = t + "." + i.join(".");
|
|
1331
|
+
return n === a;
|
|
1332
1332
|
}
|
|
1333
1333
|
return;
|
|
1334
1334
|
}
|
|
1335
1335
|
if (m === "setSelected")
|
|
1336
1336
|
return (s) => {
|
|
1337
|
-
const o = i.slice(0, -1),
|
|
1338
|
-
ft(t, o, void 0), e.getState().selectedIndicesMap.get(
|
|
1337
|
+
const o = i.slice(0, -1), n = t + "." + o.join("."), a = t + "." + i.join(".");
|
|
1338
|
+
ft(t, o, void 0), e.getState().selectedIndicesMap.get(n), s && e.getState().setSelectedIndex(n, a);
|
|
1339
1339
|
};
|
|
1340
1340
|
if (m === "toggleSelected")
|
|
1341
1341
|
return () => {
|
|
1342
|
-
const s = i.slice(0, -1), o = t + "." + s.join("."),
|
|
1343
|
-
e.getState().selectedIndicesMap.get(o) ===
|
|
1342
|
+
const s = i.slice(0, -1), o = t + "." + s.join("."), n = t + "." + i.join(".");
|
|
1343
|
+
e.getState().selectedIndicesMap.get(o) === n ? e.getState().clearSelectedIndex({ arrayKey: o }) : e.getState().setSelectedIndex(o, n);
|
|
1344
1344
|
};
|
|
1345
1345
|
if (m === "_componentId")
|
|
1346
1346
|
return M;
|
|
@@ -1349,15 +1349,15 @@ function Dt(t, n, g, S) {
|
|
|
1349
1349
|
return (s) => {
|
|
1350
1350
|
const o = e.getState().getInitialOptions(t)?.validation;
|
|
1351
1351
|
if (!o?.key) throw new Error("Validation key not found");
|
|
1352
|
-
ut(o.key), s.forEach((
|
|
1353
|
-
const a = [o.key, ...
|
|
1354
|
-
pt(a,
|
|
1352
|
+
ut(o.key), s.forEach((n) => {
|
|
1353
|
+
const a = [o.key, ...n.path].join(".");
|
|
1354
|
+
pt(a, n.message);
|
|
1355
1355
|
}), it(t);
|
|
1356
1356
|
};
|
|
1357
1357
|
if (m === "applyJsonPatch")
|
|
1358
1358
|
return (s) => {
|
|
1359
|
-
const o = e.getState(),
|
|
1360
|
-
if (!
|
|
1359
|
+
const o = e.getState(), n = o.getShadowMetadata(t, []);
|
|
1360
|
+
if (!n?.components) return;
|
|
1361
1361
|
const a = (l) => !l || l === "/" ? [] : l.split("/").slice(1).map((p) => p.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
|
|
1362
1362
|
for (const l of s) {
|
|
1363
1363
|
const p = a(l.path);
|
|
@@ -1374,7 +1374,7 @@ function Dt(t, n, g, S) {
|
|
|
1374
1374
|
);
|
|
1375
1375
|
if (console.log("pathMeta", U), U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1376
1376
|
if (!d.has(C)) {
|
|
1377
|
-
const F =
|
|
1377
|
+
const F = n.components?.get(C);
|
|
1378
1378
|
F && (F.forceUpdate(), d.add(C));
|
|
1379
1379
|
}
|
|
1380
1380
|
}), _.length === 0) break;
|
|
@@ -1393,7 +1393,7 @@ function Dt(t, n, g, S) {
|
|
|
1393
1393
|
);
|
|
1394
1394
|
if (U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1395
1395
|
if (!d.has(C)) {
|
|
1396
|
-
const F =
|
|
1396
|
+
const F = n.components?.get(C);
|
|
1397
1397
|
F && (F.forceUpdate(), d.add(C));
|
|
1398
1398
|
}
|
|
1399
1399
|
}), _.length === 0) break;
|
|
@@ -1412,7 +1412,7 @@ function Dt(t, n, g, S) {
|
|
|
1412
1412
|
"Zod schema (v3 or v4) or validation key not found"
|
|
1413
1413
|
);
|
|
1414
1414
|
ut(s.key);
|
|
1415
|
-
const
|
|
1415
|
+
const n = e.getState().getShadowValue(t), a = o.safeParse(n);
|
|
1416
1416
|
return a.success ? !0 : ("issues" in a.error ? a.error.issues.forEach((d) => {
|
|
1417
1417
|
const l = [s.key, ...d.path].join(".");
|
|
1418
1418
|
pt(l, d.message);
|
|
@@ -1444,7 +1444,7 @@ function Dt(t, n, g, S) {
|
|
|
1444
1444
|
if (m === "_stateKey") return t;
|
|
1445
1445
|
if (m === "_path") return i;
|
|
1446
1446
|
if (m === "update")
|
|
1447
|
-
return (s) => (
|
|
1447
|
+
return (s) => (r(s, i, { updateType: "update" }), {
|
|
1448
1448
|
/**
|
|
1449
1449
|
* Marks this specific item, which was just updated, as 'synced' (not dirty).
|
|
1450
1450
|
*/
|
|
@@ -1459,8 +1459,8 @@ function Dt(t, n, g, S) {
|
|
|
1459
1459
|
lastServerSync: Date.now()
|
|
1460
1460
|
// Add timestamp
|
|
1461
1461
|
});
|
|
1462
|
-
const
|
|
1463
|
-
e.getState().notifyPathSubscribers(
|
|
1462
|
+
const n = [t, ...i].join(".");
|
|
1463
|
+
e.getState().notifyPathSubscribers(n, {
|
|
1464
1464
|
type: "SYNC_STATUS_CHANGE",
|
|
1465
1465
|
isDirty: !1
|
|
1466
1466
|
});
|
|
@@ -1471,7 +1471,7 @@ function Dt(t, n, g, S) {
|
|
|
1471
1471
|
if (console.log("currentValueAtPath", s), typeof w != "boolean")
|
|
1472
1472
|
throw new Error("toggle() can only be used on boolean values");
|
|
1473
1473
|
return () => {
|
|
1474
|
-
|
|
1474
|
+
r(!s, i, {
|
|
1475
1475
|
updateType: "update"
|
|
1476
1476
|
});
|
|
1477
1477
|
};
|
|
@@ -1483,7 +1483,7 @@ function Dt(t, n, g, S) {
|
|
|
1483
1483
|
stateKey: t,
|
|
1484
1484
|
path: i,
|
|
1485
1485
|
rebuildStateShape: u,
|
|
1486
|
-
setState:
|
|
1486
|
+
setState: r,
|
|
1487
1487
|
formOpts: o,
|
|
1488
1488
|
renderFn: s
|
|
1489
1489
|
}
|
|
@@ -1528,7 +1528,7 @@ function Dt(t, n, g, S) {
|
|
|
1528
1528
|
y.clear(), I++;
|
|
1529
1529
|
const i = Dt(
|
|
1530
1530
|
t,
|
|
1531
|
-
|
|
1531
|
+
r,
|
|
1532
1532
|
g,
|
|
1533
1533
|
S
|
|
1534
1534
|
), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${S}-${t}-${z}`;
|
|
@@ -1554,7 +1554,7 @@ function bt(t) {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
function qt({
|
|
1556
1556
|
proxy: t,
|
|
1557
|
-
rebuildStateShape:
|
|
1557
|
+
rebuildStateShape: r
|
|
1558
1558
|
}) {
|
|
1559
1559
|
const g = q(null), S = q(`map-${crypto.randomUUID()}`), y = q(!1), I = q(/* @__PURE__ */ new Map());
|
|
1560
1560
|
Z(() => {
|
|
@@ -1566,7 +1566,7 @@ function qt({
|
|
|
1566
1566
|
instanceId: S.current,
|
|
1567
1567
|
mapFn: t._mapFn,
|
|
1568
1568
|
containerRef: u,
|
|
1569
|
-
rebuildStateShape:
|
|
1569
|
+
rebuildStateShape: r,
|
|
1570
1570
|
path: t._path,
|
|
1571
1571
|
componentId: S.current,
|
|
1572
1572
|
meta: t._meta
|
|
@@ -1593,7 +1593,7 @@ function qt({
|
|
|
1593
1593
|
t._meta?.validIds
|
|
1594
1594
|
);
|
|
1595
1595
|
if (!Array.isArray(f)) return;
|
|
1596
|
-
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w =
|
|
1596
|
+
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w = r({
|
|
1597
1597
|
currentState: f,
|
|
1598
1598
|
path: t._path,
|
|
1599
1599
|
componentId: S.current,
|
|
@@ -1614,7 +1614,7 @@ function qt({
|
|
|
1614
1614
|
itemPath: J,
|
|
1615
1615
|
localIndex: h,
|
|
1616
1616
|
arraySetter: w,
|
|
1617
|
-
rebuildStateShape:
|
|
1617
|
+
rebuildStateShape: r,
|
|
1618
1618
|
renderFn: t._mapFn
|
|
1619
1619
|
})
|
|
1620
1620
|
);
|
|
@@ -1625,12 +1625,12 @@ function qt({
|
|
|
1625
1625
|
function Gt({
|
|
1626
1626
|
proxy: t
|
|
1627
1627
|
}) {
|
|
1628
|
-
const
|
|
1628
|
+
const r = q(null), g = q(null), S = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, I = e.getState().getShadowValue(
|
|
1629
1629
|
[t._stateKey, ...t._path].join("."),
|
|
1630
1630
|
t._meta?.validIds
|
|
1631
1631
|
);
|
|
1632
1632
|
return Z(() => {
|
|
1633
|
-
const E =
|
|
1633
|
+
const E = r.current;
|
|
1634
1634
|
if (!E || S.current) return;
|
|
1635
1635
|
const u = setTimeout(() => {
|
|
1636
1636
|
if (!E.parentElement) {
|
|
@@ -1673,16 +1673,16 @@ function Gt({
|
|
|
1673
1673
|
}
|
|
1674
1674
|
};
|
|
1675
1675
|
}, []), lt("span", {
|
|
1676
|
-
ref:
|
|
1676
|
+
ref: r,
|
|
1677
1677
|
style: { display: "contents" },
|
|
1678
1678
|
"data-signal-id": y
|
|
1679
1679
|
});
|
|
1680
1680
|
}
|
|
1681
1681
|
const Mt = Ot(
|
|
1682
1682
|
Yt,
|
|
1683
|
-
(t,
|
|
1683
|
+
(t, r) => t.itemPath.join(".") === r.itemPath.join(".") && t.stateKey === r.stateKey && t.itemComponentId === r.itemComponentId && t.localIndex === r.localIndex
|
|
1684
1684
|
), Jt = (t) => {
|
|
1685
|
-
const [
|
|
1685
|
+
const [r, g] = K(!1);
|
|
1686
1686
|
return dt(() => {
|
|
1687
1687
|
if (!t.current) {
|
|
1688
1688
|
g(!0);
|
|
@@ -1704,11 +1704,11 @@ const Mt = Ot(
|
|
|
1704
1704
|
E.removeEventListener("load", I), E.removeEventListener("error", I);
|
|
1705
1705
|
});
|
|
1706
1706
|
};
|
|
1707
|
-
}, [t.current]),
|
|
1707
|
+
}, [t.current]), r;
|
|
1708
1708
|
};
|
|
1709
1709
|
function Yt({
|
|
1710
1710
|
stateKey: t,
|
|
1711
|
-
itemComponentId:
|
|
1711
|
+
itemComponentId: r,
|
|
1712
1712
|
itemPath: g,
|
|
1713
1713
|
localIndex: S,
|
|
1714
1714
|
arraySetter: y,
|
|
@@ -1716,7 +1716,7 @@ function Yt({
|
|
|
1716
1716
|
renderFn: E
|
|
1717
1717
|
}) {
|
|
1718
1718
|
const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...g].join(".");
|
|
1719
|
-
$t(t,
|
|
1719
|
+
$t(t, r, u);
|
|
1720
1720
|
const z = ct(
|
|
1721
1721
|
(W) => {
|
|
1722
1722
|
w.current = W, f(W);
|
|
@@ -1754,19 +1754,19 @@ function Yt({
|
|
|
1754
1754
|
const J = I({
|
|
1755
1755
|
currentState: B,
|
|
1756
1756
|
path: g,
|
|
1757
|
-
componentId:
|
|
1757
|
+
componentId: r
|
|
1758
1758
|
}), H = E(J, S, y);
|
|
1759
1759
|
return /* @__PURE__ */ ot("div", { ref: z, children: H });
|
|
1760
1760
|
}
|
|
1761
1761
|
function Zt({
|
|
1762
1762
|
stateKey: t,
|
|
1763
|
-
path:
|
|
1763
|
+
path: r,
|
|
1764
1764
|
rebuildStateShape: g,
|
|
1765
1765
|
renderFn: S,
|
|
1766
1766
|
formOpts: y,
|
|
1767
1767
|
setState: I
|
|
1768
1768
|
}) {
|
|
1769
|
-
const [E] = K(() => rt()), [, u] = K({}), f = [t, ...
|
|
1769
|
+
const [E] = K(() => rt()), [, u] = K({}), f = [t, ...r].join(".");
|
|
1770
1770
|
$t(t, E, u);
|
|
1771
1771
|
const A = e.getState().getShadowValue(f), [w, i] = K(A), h = q(!1), M = q(null);
|
|
1772
1772
|
Z(() => {
|
|
@@ -1784,12 +1784,12 @@ function Zt({
|
|
|
1784
1784
|
typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
|
|
1785
1785
|
const m = y?.debounceTime ?? 200;
|
|
1786
1786
|
M.current = setTimeout(() => {
|
|
1787
|
-
h.current = !1, I(H,
|
|
1787
|
+
h.current = !1, I(H, r, { updateType: "update" });
|
|
1788
1788
|
const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
|
|
1789
1789
|
if (o) {
|
|
1790
|
-
const
|
|
1790
|
+
const n = e.getState().getShadowValue(t), a = o.safeParse(n), d = X(t, r) || {};
|
|
1791
1791
|
if (a.success)
|
|
1792
|
-
Q(t,
|
|
1792
|
+
Q(t, r, {
|
|
1793
1793
|
...d,
|
|
1794
1794
|
validation: {
|
|
1795
1795
|
status: "VALID_LIVE",
|
|
@@ -1798,16 +1798,16 @@ function Zt({
|
|
|
1798
1798
|
});
|
|
1799
1799
|
else {
|
|
1800
1800
|
const p = ("issues" in a.error ? a.error.issues : a.error.errors).filter(
|
|
1801
|
-
(V) => JSON.stringify(V.path) === JSON.stringify(
|
|
1801
|
+
(V) => JSON.stringify(V.path) === JSON.stringify(r)
|
|
1802
1802
|
);
|
|
1803
|
-
p.length > 0 ? Q(t,
|
|
1803
|
+
p.length > 0 ? Q(t, r, {
|
|
1804
1804
|
...d,
|
|
1805
1805
|
validation: {
|
|
1806
1806
|
status: "INVALID_LIVE",
|
|
1807
1807
|
message: p[0]?.message,
|
|
1808
1808
|
validatedValue: H
|
|
1809
1809
|
}
|
|
1810
|
-
}) : Q(t,
|
|
1810
|
+
}) : Q(t, r, {
|
|
1811
1811
|
...d,
|
|
1812
1812
|
validation: {
|
|
1813
1813
|
status: "VALID_LIVE",
|
|
@@ -1818,13 +1818,13 @@ function Zt({
|
|
|
1818
1818
|
}
|
|
1819
1819
|
}, m), u({});
|
|
1820
1820
|
},
|
|
1821
|
-
[I,
|
|
1821
|
+
[I, r, y?.debounceTime, t]
|
|
1822
1822
|
), c = ct(async () => {
|
|
1823
|
-
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w,
|
|
1823
|
+
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w, r, { updateType: "update" }));
|
|
1824
1824
|
const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
|
|
1825
1825
|
if (!m) return;
|
|
1826
|
-
const Y = e.getState().getShadowMetadata(t,
|
|
1827
|
-
e.getState().setShadowMetadata(t,
|
|
1826
|
+
const Y = e.getState().getShadowMetadata(t, r);
|
|
1827
|
+
e.getState().setShadowMetadata(t, r, {
|
|
1828
1828
|
...Y,
|
|
1829
1829
|
validation: {
|
|
1830
1830
|
status: "DIRTY",
|
|
@@ -1833,7 +1833,7 @@ function Zt({
|
|
|
1833
1833
|
});
|
|
1834
1834
|
const Q = e.getState().getShadowValue(t), X = m.safeParse(Q);
|
|
1835
1835
|
if (console.log("result ", X), X.success)
|
|
1836
|
-
e.getState().setShadowMetadata(t,
|
|
1836
|
+
e.getState().setShadowMetadata(t, r, {
|
|
1837
1837
|
...Y,
|
|
1838
1838
|
validation: {
|
|
1839
1839
|
status: "VALID_PENDING_SYNC",
|
|
@@ -1842,32 +1842,32 @@ function Zt({
|
|
|
1842
1842
|
});
|
|
1843
1843
|
else {
|
|
1844
1844
|
const s = "issues" in X.error ? X.error.issues : X.error.errors;
|
|
1845
|
-
console.log("All validation errors:", s), console.log("Current blur path:",
|
|
1846
|
-
const o = s.filter((
|
|
1847
|
-
if (console.log("Processing error:",
|
|
1845
|
+
console.log("All validation errors:", s), console.log("Current blur path:", r);
|
|
1846
|
+
const o = s.filter((n) => {
|
|
1847
|
+
if (console.log("Processing error:", n), r.some((d) => d.startsWith("id:"))) {
|
|
1848
1848
|
console.log("Detected array path with ULID");
|
|
1849
|
-
const d =
|
|
1849
|
+
const d = r[0].startsWith("id:") ? [] : r.slice(0, -1);
|
|
1850
1850
|
console.log("Parent path:", d);
|
|
1851
1851
|
const l = e.getState().getShadowMetadata(t, d);
|
|
1852
1852
|
if (console.log("Array metadata:", l), l?.arrayKeys) {
|
|
1853
|
-
const p = [t, ...
|
|
1853
|
+
const p = [t, ...r.slice(0, -1)].join("."), V = l.arrayKeys.indexOf(p);
|
|
1854
1854
|
console.log("Item key:", p, "Index:", V);
|
|
1855
|
-
const _ = [...d, V, ...
|
|
1855
|
+
const _ = [...d, V, ...r.slice(-1)], U = JSON.stringify(n.path) === JSON.stringify(_);
|
|
1856
1856
|
return console.log("Zod path comparison:", {
|
|
1857
1857
|
zodPath: _,
|
|
1858
|
-
errorPath:
|
|
1858
|
+
errorPath: n.path,
|
|
1859
1859
|
match: U
|
|
1860
1860
|
}), U;
|
|
1861
1861
|
}
|
|
1862
1862
|
}
|
|
1863
|
-
const a = JSON.stringify(
|
|
1863
|
+
const a = JSON.stringify(n.path) === JSON.stringify(r);
|
|
1864
1864
|
return console.log("Direct path comparison:", {
|
|
1865
|
-
errorPath:
|
|
1866
|
-
currentPath:
|
|
1865
|
+
errorPath: n.path,
|
|
1866
|
+
currentPath: r,
|
|
1867
1867
|
match: a
|
|
1868
1868
|
}), a;
|
|
1869
1869
|
});
|
|
1870
|
-
console.log("Filtered path errors:", o), e.getState().setShadowMetadata(t,
|
|
1870
|
+
console.log("Filtered path errors:", o), e.getState().setShadowMetadata(t, r, {
|
|
1871
1871
|
...Y,
|
|
1872
1872
|
validation: {
|
|
1873
1873
|
status: "VALIDATION_FAILED",
|
|
@@ -1877,9 +1877,9 @@ function Zt({
|
|
|
1877
1877
|
});
|
|
1878
1878
|
}
|
|
1879
1879
|
u({});
|
|
1880
|
-
}, [t,
|
|
1880
|
+
}, [t, r, w, I]), B = g({
|
|
1881
1881
|
currentState: A,
|
|
1882
|
-
path:
|
|
1882
|
+
path: r,
|
|
1883
1883
|
componentId: E
|
|
1884
1884
|
}), J = new Proxy(B, {
|
|
1885
1885
|
get(H, W) {
|
|
@@ -1890,14 +1890,14 @@ function Zt({
|
|
|
1890
1890
|
},
|
|
1891
1891
|
// 5. Wire the new onBlur handler to the input props.
|
|
1892
1892
|
onBlur: c,
|
|
1893
|
-
ref: vt.getState().getFormRef(t + "." +
|
|
1893
|
+
ref: vt.getState().getFormRef(t + "." + r.join("."))
|
|
1894
1894
|
} : H[W];
|
|
1895
1895
|
}
|
|
1896
1896
|
});
|
|
1897
|
-
return /* @__PURE__ */ ot(kt, { formOpts: y, path:
|
|
1897
|
+
return /* @__PURE__ */ ot(kt, { formOpts: y, path: r, stateKey: t, children: S(J) });
|
|
1898
1898
|
}
|
|
1899
|
-
function $t(t,
|
|
1900
|
-
const S = `${t}////${
|
|
1899
|
+
function $t(t, r, g) {
|
|
1900
|
+
const S = `${t}////${r}`;
|
|
1901
1901
|
dt(() => {
|
|
1902
1902
|
const { registerComponent: y, unregisterComponent: I } = e.getState();
|
|
1903
1903
|
return y(t, S, {
|