cogsbox-state 0.5.440 → 0.5.442
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 +9 -18
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +362 -365
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +35 -83
package/dist/CogsState.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
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
|
|
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";
|
|
@@ -9,60 +9,60 @@ 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,
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
function yt(t, n) {
|
|
13
|
+
const S = e.getState().getInitialOptions, g = e.getState().setInitialStateOptions, y = S(t) || {};
|
|
14
|
+
g(t, {
|
|
15
15
|
...y,
|
|
16
|
-
...
|
|
16
|
+
...n
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function Vt({
|
|
20
20
|
stateKey: t,
|
|
21
|
-
options:
|
|
22
|
-
initialOptionsPart:
|
|
21
|
+
options: n,
|
|
22
|
+
initialOptionsPart: S
|
|
23
23
|
}) {
|
|
24
|
-
const
|
|
24
|
+
const g = nt(t) || {}, y = S[t] || {}, I = e.getState().setInitialStateOptions, V = { ...y, ...g };
|
|
25
25
|
let u = !1;
|
|
26
|
-
if (
|
|
27
|
-
for (const f in
|
|
28
|
-
|
|
29
|
-
u && I(t,
|
|
26
|
+
if (n)
|
|
27
|
+
for (const f in n)
|
|
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
|
-
function ie(t, { formElements:
|
|
32
|
-
return { initialState: t, formElements:
|
|
31
|
+
function ie(t, { formElements: n, validation: S }) {
|
|
32
|
+
return { initialState: t, formElements: n, validation: S };
|
|
33
33
|
}
|
|
34
|
-
const Lt = (t,
|
|
35
|
-
let
|
|
36
|
-
const [
|
|
37
|
-
|
|
34
|
+
const Lt = (t, n) => {
|
|
35
|
+
let S = t;
|
|
36
|
+
const [g, y] = Nt(S);
|
|
37
|
+
n?.__fromSyncSchema && n?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", n.__syncNotifications), Object.keys(g).forEach((u) => {
|
|
38
38
|
let f = y[u] || {};
|
|
39
39
|
const A = {
|
|
40
40
|
...f
|
|
41
41
|
};
|
|
42
|
-
if (
|
|
43
|
-
...
|
|
42
|
+
if (n?.formElements && (A.formElements = {
|
|
43
|
+
...n.formElements,
|
|
44
44
|
...f.formElements || {}
|
|
45
|
-
}),
|
|
46
|
-
...
|
|
45
|
+
}), n?.validation && (A.validation = {
|
|
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
49
|
const w = nt(u);
|
|
50
50
|
w ? e.getState().setInitialStateOptions(u, {
|
|
51
51
|
...w,
|
|
52
52
|
...A
|
|
53
53
|
}) : e.getState().setInitialStateOptions(u, A);
|
|
54
54
|
}
|
|
55
|
-
}), Object.keys(
|
|
56
|
-
e.getState().initializeShadowState(u,
|
|
55
|
+
}), Object.keys(g).forEach((u) => {
|
|
56
|
+
e.getState().initializeShadowState(u, g[u]);
|
|
57
57
|
});
|
|
58
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 w = e.getState().getShadowValue(u) ||
|
|
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,21 +76,18 @@ const Lt = (t, r) => {
|
|
|
76
76
|
serverState: f?.serverState
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function V(u, f) {
|
|
80
|
+
Vt({ stateKey: u, options: f, initialOptionsPart: y }), f.localStorage && xt(u, f), it(u);
|
|
81
81
|
}
|
|
82
|
-
return { useCogsState: I, setCogsOptions:
|
|
82
|
+
return { useCogsState: I, setCogsOptions: V };
|
|
83
83
|
};
|
|
84
84
|
function ce(t) {
|
|
85
|
-
const
|
|
86
|
-
for (const g in
|
|
87
|
-
const
|
|
88
|
-
S
|
|
85
|
+
const n = t.schemas, S = {};
|
|
86
|
+
for (const g in n) {
|
|
87
|
+
const y = n[g];
|
|
88
|
+
S[g] = y?.schemas?.defaultValues || {};
|
|
89
89
|
}
|
|
90
|
-
return Lt(
|
|
91
|
-
__fromSyncSchema: !0,
|
|
92
|
-
__syncNotifications: t.notifications
|
|
93
|
-
});
|
|
90
|
+
return Lt(S);
|
|
94
91
|
}
|
|
95
92
|
const {
|
|
96
93
|
getInitialOptions: nt,
|
|
@@ -99,22 +96,22 @@ const {
|
|
|
99
96
|
updateInitialStateGlobal: _t,
|
|
100
97
|
addValidationError: pt,
|
|
101
98
|
removeValidationError: ut
|
|
102
|
-
} = e.getState(), Ht = (t,
|
|
103
|
-
|
|
99
|
+
} = e.getState(), Ht = (t, n, S, g, y) => {
|
|
100
|
+
S?.log && console.log(
|
|
104
101
|
"saving to localstorage",
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
n,
|
|
103
|
+
S.localStorage?.key,
|
|
104
|
+
g
|
|
108
105
|
);
|
|
109
|
-
const I = at(
|
|
110
|
-
if (I &&
|
|
111
|
-
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}`;
|
|
112
109
|
let u;
|
|
113
110
|
try {
|
|
114
|
-
u =
|
|
111
|
+
u = St(V)?.lastSyncedWithServer;
|
|
115
112
|
} catch {
|
|
116
113
|
}
|
|
117
|
-
const f = e.getState().getShadowMetadata(
|
|
114
|
+
const f = e.getState().getShadowMetadata(n, []), A = {
|
|
118
115
|
state: t,
|
|
119
116
|
lastUpdated: Date.now(),
|
|
120
117
|
lastSyncedWithServer: u,
|
|
@@ -122,84 +119,84 @@ const {
|
|
|
122
119
|
baseServerState: f?.baseServerState
|
|
123
120
|
}, w = Ft.serialize(A);
|
|
124
121
|
window.localStorage.setItem(
|
|
125
|
-
|
|
122
|
+
V,
|
|
126
123
|
JSON.stringify(w.json)
|
|
127
124
|
);
|
|
128
125
|
}
|
|
129
|
-
},
|
|
126
|
+
}, St = (t) => {
|
|
130
127
|
if (!t) return null;
|
|
131
128
|
try {
|
|
132
|
-
const
|
|
133
|
-
return
|
|
134
|
-
} catch (
|
|
135
|
-
return console.error("Error loading from localStorage:",
|
|
129
|
+
const n = window.localStorage.getItem(t);
|
|
130
|
+
return n ? JSON.parse(n) : null;
|
|
131
|
+
} catch (n) {
|
|
132
|
+
return console.error("Error loading from localStorage:", n), null;
|
|
136
133
|
}
|
|
137
|
-
}, xt = (t,
|
|
138
|
-
const
|
|
139
|
-
if (y &&
|
|
140
|
-
const I =
|
|
141
|
-
`${
|
|
134
|
+
}, xt = (t, n) => {
|
|
135
|
+
const S = e.getState().getShadowValue(t), { sessionId: g } = Pt(), y = at(n?.localStorage?.key) ? n.localStorage.key(S) : n?.localStorage?.key;
|
|
136
|
+
if (y && g) {
|
|
137
|
+
const I = St(
|
|
138
|
+
`${g}-${t}-${y}`
|
|
142
139
|
);
|
|
143
140
|
if (I && I.lastUpdated > (I.lastSyncedWithServer || 0))
|
|
144
141
|
return it(t), !0;
|
|
145
142
|
}
|
|
146
143
|
return !1;
|
|
147
144
|
}, it = (t) => {
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
(
|
|
145
|
+
const n = e.getState().getShadowMetadata(t, []);
|
|
146
|
+
if (!n) return;
|
|
147
|
+
const S = /* @__PURE__ */ new Set();
|
|
148
|
+
n?.components?.forEach((g) => {
|
|
149
|
+
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || S.add(() => g.forceUpdate());
|
|
153
150
|
}), queueMicrotask(() => {
|
|
154
|
-
|
|
151
|
+
S.forEach((g) => g());
|
|
155
152
|
});
|
|
156
|
-
}, ue = (t,
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
153
|
+
}, ue = (t, n) => {
|
|
154
|
+
const S = e.getState().getShadowMetadata(t, []);
|
|
155
|
+
if (S) {
|
|
156
|
+
const g = `${t}////${n}`, y = S?.components?.get(g);
|
|
160
157
|
if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
|
|
161
158
|
return;
|
|
162
159
|
y && y.forceUpdate();
|
|
163
160
|
}
|
|
164
161
|
};
|
|
165
|
-
function wt(t,
|
|
166
|
-
const y = e.getState(), I = y.getShadowMetadata(t,
|
|
167
|
-
if (y.setShadowMetadata(t,
|
|
162
|
+
function wt(t, n, S, g) {
|
|
163
|
+
const y = e.getState(), I = y.getShadowMetadata(t, n);
|
|
164
|
+
if (y.setShadowMetadata(t, n, {
|
|
168
165
|
...I,
|
|
169
166
|
isDirty: !1,
|
|
170
167
|
stateSource: "server",
|
|
171
|
-
lastServerSync:
|
|
172
|
-
}), Array.isArray(
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
const A = u.split(".").slice(1), w =
|
|
168
|
+
lastServerSync: g || Date.now()
|
|
169
|
+
}), Array.isArray(S)) {
|
|
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];
|
|
176
173
|
w !== void 0 && wt(
|
|
177
174
|
t,
|
|
178
175
|
A,
|
|
179
176
|
w,
|
|
180
|
-
|
|
177
|
+
g
|
|
181
178
|
);
|
|
182
179
|
});
|
|
183
|
-
} else
|
|
184
|
-
const u = [...
|
|
185
|
-
wt(t, u, f,
|
|
180
|
+
} else S && typeof S == "object" && S.constructor === Object && Object.keys(S).forEach((V) => {
|
|
181
|
+
const u = [...n, V], f = S[V];
|
|
182
|
+
wt(t, u, f, g);
|
|
186
183
|
});
|
|
187
184
|
}
|
|
188
185
|
function zt(t, {
|
|
189
|
-
stateKey:
|
|
190
|
-
localStorage:
|
|
191
|
-
formElements:
|
|
186
|
+
stateKey: n,
|
|
187
|
+
localStorage: S,
|
|
188
|
+
formElements: g,
|
|
192
189
|
reactiveDeps: y,
|
|
193
190
|
reactiveType: I,
|
|
194
|
-
componentId:
|
|
191
|
+
componentId: V,
|
|
195
192
|
defaultState: u,
|
|
196
193
|
syncUpdate: f,
|
|
197
194
|
dependencies: A,
|
|
198
195
|
serverState: w
|
|
199
196
|
} = {}) {
|
|
200
197
|
const [i, h] = K({}), { sessionId: M } = Pt();
|
|
201
|
-
let z = !
|
|
202
|
-
const [c] = K(
|
|
198
|
+
let z = !n;
|
|
199
|
+
const [c] = K(n ?? rt()), B = e.getState().stateLog[c], J = q(/* @__PURE__ */ new Set()), H = q(V ?? rt()), W = q(
|
|
203
200
|
null
|
|
204
201
|
);
|
|
205
202
|
W.current = nt(c) ?? null, Z(() => {
|
|
@@ -221,14 +218,14 @@ function zt(t, {
|
|
|
221
218
|
timestamp: a.serverState.timestamp || Date.now()
|
|
222
219
|
};
|
|
223
220
|
if (a?.localStorage?.key && M) {
|
|
224
|
-
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key,
|
|
221
|
+
const p = at(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, E = St(
|
|
225
222
|
`${M}-${c}-${p}`
|
|
226
223
|
);
|
|
227
|
-
if (
|
|
224
|
+
if (E && E.lastUpdated > (a?.serverState?.timestamp || 0))
|
|
228
225
|
return {
|
|
229
|
-
value:
|
|
226
|
+
value: E.state,
|
|
230
227
|
source: "localStorage",
|
|
231
|
-
timestamp:
|
|
228
|
+
timestamp: E.lastUpdated
|
|
232
229
|
};
|
|
233
230
|
}
|
|
234
231
|
return {
|
|
@@ -241,16 +238,16 @@ function zt(t, {
|
|
|
241
238
|
);
|
|
242
239
|
Z(() => {
|
|
243
240
|
e.getState().setServerStateUpdate(c, w);
|
|
244
|
-
}, [w, c]), Z(() => e.getState().subscribeToPath(c, (
|
|
245
|
-
if (
|
|
246
|
-
const a =
|
|
241
|
+
}, [w, c]), Z(() => e.getState().subscribeToPath(c, (r) => {
|
|
242
|
+
if (r?.type === "SERVER_STATE_UPDATE") {
|
|
243
|
+
const a = r.serverState;
|
|
247
244
|
if (a?.status === "success" && a.data !== void 0) {
|
|
248
245
|
yt(c, { serverState: a });
|
|
249
|
-
const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c),
|
|
250
|
-
if (l && Array.isArray(p) && Array.isArray(
|
|
246
|
+
const l = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, p = e.getState().getShadowValue(c), E = a.data;
|
|
247
|
+
if (l && Array.isArray(p) && Array.isArray(E)) {
|
|
251
248
|
const U = l.key || "id", C = new Set(
|
|
252
249
|
p.map((x) => x[U])
|
|
253
|
-
), F =
|
|
250
|
+
), F = E.filter((x) => !C.has(x[U]));
|
|
254
251
|
F.length > 0 && F.forEach((x) => {
|
|
255
252
|
e.getState().insertShadowArrayElement(c, [], x);
|
|
256
253
|
const N = e.getState().getShadowMetadata(c, []);
|
|
@@ -276,10 +273,10 @@ function zt(t, {
|
|
|
276
273
|
}
|
|
277
274
|
});
|
|
278
275
|
} else
|
|
279
|
-
e.getState().initializeShadowState(c,
|
|
276
|
+
e.getState().initializeShadowState(c, E), wt(
|
|
280
277
|
c,
|
|
281
278
|
[],
|
|
282
|
-
|
|
279
|
+
E,
|
|
283
280
|
a.timestamp
|
|
284
281
|
);
|
|
285
282
|
const _ = e.getState().getShadowMetadata(c, []);
|
|
@@ -295,10 +292,10 @@ function zt(t, {
|
|
|
295
292
|
const o = e.getState().getShadowMetadata(c, []);
|
|
296
293
|
if (o && o.stateSource)
|
|
297
294
|
return;
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
const a =
|
|
301
|
-
|
|
295
|
+
const r = nt(c);
|
|
296
|
+
if (r?.defaultState !== void 0 || u !== void 0) {
|
|
297
|
+
const a = r?.defaultState || u;
|
|
298
|
+
r?.defaultState || yt(c, {
|
|
302
299
|
defaultState: a
|
|
303
300
|
});
|
|
304
301
|
const { value: d, source: l, timestamp: p } = m();
|
|
@@ -311,12 +308,12 @@ function zt(t, {
|
|
|
311
308
|
}
|
|
312
309
|
}, [c, ...A || []]), dt(() => {
|
|
313
310
|
z && yt(c, {
|
|
314
|
-
formElements:
|
|
311
|
+
formElements: g,
|
|
315
312
|
defaultState: u,
|
|
316
|
-
localStorage:
|
|
313
|
+
localStorage: S,
|
|
317
314
|
middleware: W.current?.middleware
|
|
318
315
|
});
|
|
319
|
-
const o = `${c}////${H.current}`,
|
|
316
|
+
const o = `${c}////${H.current}`, r = e.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
|
|
320
317
|
return a.set(o, {
|
|
321
318
|
forceUpdate: () => h({}),
|
|
322
319
|
reactiveType: I ?? ["component", "deps"],
|
|
@@ -325,7 +322,7 @@ function zt(t, {
|
|
|
325
322
|
deps: y ? y(e.getState().getShadowValue(c)) : [],
|
|
326
323
|
prevDeps: y ? y(e.getState().getShadowValue(c)) : []
|
|
327
324
|
}), e.getState().setShadowMetadata(c, [], {
|
|
328
|
-
...
|
|
325
|
+
...r,
|
|
329
326
|
components: a
|
|
330
327
|
}), h({}), () => {
|
|
331
328
|
const d = e.getState().getShadowMetadata(c, []), l = d?.components?.get(o);
|
|
@@ -335,25 +332,25 @@ function zt(t, {
|
|
|
335
332
|
}), d?.components && e.getState().setShadowMetadata(c, [], d);
|
|
336
333
|
};
|
|
337
334
|
}, []);
|
|
338
|
-
const Y = q(null), Q = (o,
|
|
339
|
-
const d = [c, ...
|
|
340
|
-
if (Array.isArray(
|
|
341
|
-
const b = `${c}-${
|
|
335
|
+
const Y = q(null), Q = (o, r, a) => {
|
|
336
|
+
const d = [c, ...r].join(".");
|
|
337
|
+
if (Array.isArray(r)) {
|
|
338
|
+
const b = `${c}-${r.join(".")}`;
|
|
342
339
|
J.current.add(b);
|
|
343
340
|
}
|
|
344
|
-
const l = e.getState(), p = l.getShadowMetadata(c,
|
|
341
|
+
const l = e.getState(), p = l.getShadowMetadata(c, r), E = l.getShadowValue(d), _ = a.updateType === "insert" && at(o) ? o({ state: E, uuid: rt() }) : at(o) ? o(E) : o, C = {
|
|
345
342
|
timeStamp: Date.now(),
|
|
346
343
|
stateKey: c,
|
|
347
|
-
path:
|
|
344
|
+
path: r,
|
|
348
345
|
updateType: a.updateType,
|
|
349
346
|
status: "new",
|
|
350
|
-
oldValue:
|
|
347
|
+
oldValue: E,
|
|
351
348
|
newValue: _
|
|
352
349
|
};
|
|
353
350
|
switch (a.updateType) {
|
|
354
351
|
case "insert": {
|
|
355
|
-
l.insertShadowArrayElement(c,
|
|
356
|
-
const b = l.getShadowMetadata(c,
|
|
352
|
+
l.insertShadowArrayElement(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
|
|
353
|
+
const b = l.getShadowMetadata(c, r);
|
|
357
354
|
if (b?.arrayKeys) {
|
|
358
355
|
const k = b.arrayKeys[b.arrayKeys.length - 1];
|
|
359
356
|
if (k) {
|
|
@@ -364,12 +361,12 @@ function zt(t, {
|
|
|
364
361
|
break;
|
|
365
362
|
}
|
|
366
363
|
case "cut": {
|
|
367
|
-
const b =
|
|
368
|
-
l.removeShadowArrayElement(c,
|
|
364
|
+
const b = r.slice(0, -1);
|
|
365
|
+
l.removeShadowArrayElement(c, r), l.markAsDirty(c, b, { bubble: !0 });
|
|
369
366
|
break;
|
|
370
367
|
}
|
|
371
368
|
case "update": {
|
|
372
|
-
l.updateShadowAtPath(c,
|
|
369
|
+
l.updateShadowAtPath(c, r, C.newValue), l.markAsDirty(c, r, { bubble: !0 });
|
|
373
370
|
break;
|
|
374
371
|
}
|
|
375
372
|
}
|
|
@@ -396,8 +393,8 @@ function zt(t, {
|
|
|
396
393
|
});
|
|
397
394
|
}
|
|
398
395
|
if (a.updateType === "insert" && p?.mapWrappers && p.mapWrappers.length > 0) {
|
|
399
|
-
const b = l.getShadowMetadata(c,
|
|
400
|
-
[c, ...
|
|
396
|
+
const b = l.getShadowMetadata(c, r)?.arrayKeys || [], k = b[b.length - 1], P = l.getShadowValue(k), O = l.getShadowValue(
|
|
397
|
+
[c, ...r].join(".")
|
|
401
398
|
);
|
|
402
399
|
if (!k || P === void 0) return;
|
|
403
400
|
p.mapWrappers.forEach((v) => {
|
|
@@ -411,7 +408,7 @@ function zt(t, {
|
|
|
411
408
|
if (T) {
|
|
412
409
|
const D = It(
|
|
413
410
|
c,
|
|
414
|
-
|
|
411
|
+
r,
|
|
415
412
|
v.meta.transforms
|
|
416
413
|
), R = v.meta.transforms.find(
|
|
417
414
|
(L) => L.type === "sort"
|
|
@@ -458,7 +455,7 @@ function zt(t, {
|
|
|
458
455
|
});
|
|
459
456
|
}
|
|
460
457
|
if (a.updateType === "cut") {
|
|
461
|
-
const b =
|
|
458
|
+
const b = r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
462
459
|
k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((P) => {
|
|
463
460
|
if (P.containerRef && P.containerRef.isConnected) {
|
|
464
461
|
const O = P.containerRef.querySelector(
|
|
@@ -476,7 +473,7 @@ function zt(t, {
|
|
|
476
473
|
), !N?.components)
|
|
477
474
|
return x;
|
|
478
475
|
if (a.updateType === "update") {
|
|
479
|
-
let b = [...
|
|
476
|
+
let b = [...r];
|
|
480
477
|
for (; ; ) {
|
|
481
478
|
const k = l.getShadowMetadata(c, b);
|
|
482
479
|
if (k?.pathComponents && k.pathComponents.forEach((P) => {
|
|
@@ -488,8 +485,8 @@ function zt(t, {
|
|
|
488
485
|
break;
|
|
489
486
|
b.pop();
|
|
490
487
|
}
|
|
491
|
-
_ && typeof _ == "object" && !Tt(_) &&
|
|
492
|
-
const O = P.split("."), v = [...
|
|
488
|
+
_ && typeof _ == "object" && !Tt(_) && E && typeof E == "object" && !Tt(E) && Ct(_, E).forEach((P) => {
|
|
489
|
+
const O = P.split("."), v = [...r, ...O], T = l.getShadowMetadata(c, v);
|
|
493
490
|
T?.pathComponents && T.pathComponents.forEach(($) => {
|
|
494
491
|
if (j.has($))
|
|
495
492
|
return;
|
|
@@ -498,7 +495,7 @@ function zt(t, {
|
|
|
498
495
|
});
|
|
499
496
|
});
|
|
500
497
|
} else if (a.updateType === "insert" || a.updateType === "cut") {
|
|
501
|
-
const b = a.updateType === "insert" ?
|
|
498
|
+
const b = a.updateType === "insert" ? r : r.slice(0, -1), k = l.getShadowMetadata(c, b);
|
|
502
499
|
if (k?.signals && k.signals.length > 0) {
|
|
503
500
|
const P = [c, ...b].join("."), O = l.getShadowValue(P);
|
|
504
501
|
k.signals.forEach(({ parentId: v, position: T, effect: $ }) => {
|
|
@@ -560,7 +557,7 @@ function zt(t, {
|
|
|
560
557
|
}), x;
|
|
561
558
|
};
|
|
562
559
|
e.getState().initialStateGlobal[c] || _t(c, t);
|
|
563
|
-
const X =
|
|
560
|
+
const X = gt(() => Dt(
|
|
564
561
|
c,
|
|
565
562
|
Q,
|
|
566
563
|
H.current,
|
|
@@ -570,50 +567,50 @@ function zt(t, {
|
|
|
570
567
|
}
|
|
571
568
|
function Bt(t) {
|
|
572
569
|
return !t || t.length === 0 ? "" : t.map(
|
|
573
|
-
(
|
|
570
|
+
(n) => (
|
|
574
571
|
// Safely stringify dependencies. An empty array becomes '[]'.
|
|
575
|
-
`${
|
|
572
|
+
`${n.type}${JSON.stringify(n.dependencies || [])}`
|
|
576
573
|
)
|
|
577
574
|
).join("");
|
|
578
575
|
}
|
|
579
|
-
const It = (t,
|
|
580
|
-
let
|
|
581
|
-
if (!
|
|
582
|
-
return
|
|
583
|
-
let y =
|
|
576
|
+
const It = (t, n, S) => {
|
|
577
|
+
let g = e.getState().getShadowMetadata(t, n)?.arrayKeys || [];
|
|
578
|
+
if (!S || S.length === 0)
|
|
579
|
+
return g;
|
|
580
|
+
let y = g.map((I) => ({
|
|
584
581
|
key: I,
|
|
585
582
|
value: e.getState().getShadowValue(I)
|
|
586
583
|
}));
|
|
587
|
-
for (const I of
|
|
584
|
+
for (const I of S)
|
|
588
585
|
I.type === "filter" ? y = y.filter(
|
|
589
|
-
({ value:
|
|
590
|
-
) : I.type === "sort" && y.sort((
|
|
586
|
+
({ value: V }, u) => I.fn(V, u)
|
|
587
|
+
) : I.type === "sort" && y.sort((V, u) => I.fn(V.value, u.value));
|
|
591
588
|
return y.map(({ key: I }) => I);
|
|
592
|
-
},
|
|
593
|
-
const
|
|
594
|
-
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t,
|
|
595
|
-
}, ft = (t,
|
|
596
|
-
const
|
|
589
|
+
}, Et = (t, n, S) => {
|
|
590
|
+
const g = `${t}////${n}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), u = I(t, [])?.components?.get(g);
|
|
591
|
+
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || y(t, S, g);
|
|
592
|
+
}, ft = (t, n, S) => {
|
|
593
|
+
const g = e.getState(), y = g.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
|
|
597
594
|
y?.components && y.components.forEach((u, f) => {
|
|
598
595
|
(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), I.add(f));
|
|
599
|
-
}),
|
|
596
|
+
}), g.getShadowMetadata(t, [...n, "getSelected"])?.pathComponents?.forEach((u) => {
|
|
600
597
|
y?.components?.get(u)?.forceUpdate();
|
|
601
598
|
});
|
|
602
|
-
const
|
|
603
|
-
for (let u of
|
|
604
|
-
const f = u + ".selected", A =
|
|
599
|
+
const V = g.getShadowMetadata(t, n);
|
|
600
|
+
for (let u of V?.arrayKeys || []) {
|
|
601
|
+
const f = u + ".selected", A = g.getShadowMetadata(
|
|
605
602
|
t,
|
|
606
603
|
f.split(".").slice(1)
|
|
607
604
|
);
|
|
608
|
-
u ==
|
|
605
|
+
u == S && A?.pathComponents?.forEach((w) => {
|
|
609
606
|
y?.components?.get(w)?.forceUpdate();
|
|
610
607
|
});
|
|
611
608
|
}
|
|
612
609
|
};
|
|
613
|
-
function Dt(t,
|
|
610
|
+
function Dt(t, n, S, g) {
|
|
614
611
|
const y = /* @__PURE__ */ new Map();
|
|
615
612
|
let I = 0;
|
|
616
|
-
const
|
|
613
|
+
const V = (w) => {
|
|
617
614
|
const i = w.join(".");
|
|
618
615
|
for (const [h] of y)
|
|
619
616
|
(h === i || h.startsWith(i + ".")) && y.delete(h);
|
|
@@ -640,17 +637,17 @@ function Dt(t, r, g, S) {
|
|
|
640
637
|
if (m === "getDifferences")
|
|
641
638
|
return () => {
|
|
642
639
|
const s = e.getState().getShadowMetadata(t, []), o = e.getState().getShadowValue(t);
|
|
643
|
-
let
|
|
644
|
-
return s?.stateSource === "server" && s.baseServerState ?
|
|
640
|
+
let r;
|
|
641
|
+
return s?.stateSource === "server" && s.baseServerState ? r = s.baseServerState : r = e.getState().initialStateGlobal[t], Ct(o, r);
|
|
645
642
|
};
|
|
646
643
|
if (m === "sync" && i.length === 0)
|
|
647
644
|
return async function() {
|
|
648
645
|
const s = e.getState().getInitialOptions(t), o = s?.sync;
|
|
649
646
|
if (!o)
|
|
650
647
|
return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
|
|
651
|
-
const
|
|
648
|
+
const r = e.getState().getShadowValue(t, []), a = s?.validation?.key;
|
|
652
649
|
try {
|
|
653
|
-
const d = await o.action(
|
|
650
|
+
const d = await o.action(r);
|
|
654
651
|
if (d && !d.success && d.errors && a && (e.getState().removeValidationError(a), d.errors.forEach((l) => {
|
|
655
652
|
const p = [a, ...l.path].join(".");
|
|
656
653
|
e.getState().addValidationError(p, l.message);
|
|
@@ -661,7 +658,7 @@ function Dt(t, r, g, S) {
|
|
|
661
658
|
isDirty: !1,
|
|
662
659
|
lastServerSync: Date.now(),
|
|
663
660
|
stateSource: "server",
|
|
664
|
-
baseServerState:
|
|
661
|
+
baseServerState: r
|
|
665
662
|
// Update base server state
|
|
666
663
|
}), o.onSuccess && o.onSuccess(d.data);
|
|
667
664
|
} else !d?.success && o.onError && o.onError(d.error);
|
|
@@ -672,14 +669,14 @@ function Dt(t, r, g, S) {
|
|
|
672
669
|
};
|
|
673
670
|
if (m === "_status" || m === "getStatus") {
|
|
674
671
|
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" :
|
|
672
|
+
const o = e.getState().getShadowMetadata(t, i), r = e.getState().getShadowValue(c);
|
|
673
|
+
return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" : r !== void 0 && !o ? "fresh" : "unknown";
|
|
677
674
|
};
|
|
678
675
|
return m === "_status" ? s() : s;
|
|
679
676
|
}
|
|
680
677
|
if (m === "removeStorage")
|
|
681
678
|
return () => {
|
|
682
|
-
const s = e.getState().initialStateGlobal[t], o = nt(t),
|
|
679
|
+
const s = e.getState().initialStateGlobal[t], o = nt(t), r = at(o?.localStorage?.key) ? o.localStorage.key(s) : o?.localStorage?.key, a = `${g}-${t}-${r}`;
|
|
683
680
|
a && localStorage.removeItem(a);
|
|
684
681
|
};
|
|
685
682
|
if (m === "showValidationErrors")
|
|
@@ -691,21 +688,21 @@ function Dt(t, r, g, S) {
|
|
|
691
688
|
if (m === "getSelected")
|
|
692
689
|
return () => {
|
|
693
690
|
const s = t + "." + i.join(".");
|
|
694
|
-
|
|
691
|
+
Et(t, M, [
|
|
695
692
|
...i,
|
|
696
693
|
"getSelected"
|
|
697
694
|
]);
|
|
698
695
|
const o = e.getState().selectedIndicesMap;
|
|
699
696
|
if (!o || !o.has(s))
|
|
700
697
|
return;
|
|
701
|
-
const
|
|
702
|
-
if (h?.validIds && !h.validIds.includes(
|
|
698
|
+
const r = o.get(s);
|
|
699
|
+
if (h?.validIds && !h.validIds.includes(r))
|
|
703
700
|
return;
|
|
704
|
-
const a = e.getState().getShadowValue(
|
|
701
|
+
const a = e.getState().getShadowValue(r);
|
|
705
702
|
if (a)
|
|
706
703
|
return u({
|
|
707
704
|
currentState: a,
|
|
708
|
-
path:
|
|
705
|
+
path: r.split(".").slice(1),
|
|
709
706
|
componentId: M
|
|
710
707
|
});
|
|
711
708
|
};
|
|
@@ -724,10 +721,10 @@ function Dt(t, r, g, S) {
|
|
|
724
721
|
return (s) => {
|
|
725
722
|
const {
|
|
726
723
|
itemHeight: o = 50,
|
|
727
|
-
overscan:
|
|
724
|
+
overscan: r = 6,
|
|
728
725
|
stickToBottom: a = !1,
|
|
729
726
|
scrollStickTolerance: d = 75
|
|
730
|
-
} = s, l = q(null), [p,
|
|
727
|
+
} = s, l = q(null), [p, E] = K({
|
|
731
728
|
startIndex: 0,
|
|
732
729
|
endIndex: 10
|
|
733
730
|
}), [_, U] = K({}), C = q(!0), F = q({
|
|
@@ -747,7 +744,7 @@ function Dt(t, r, g, S) {
|
|
|
747
744
|
behavior: C.current ? "instant" : "smooth"
|
|
748
745
|
});
|
|
749
746
|
}, [_, a]);
|
|
750
|
-
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } =
|
|
747
|
+
const N = e.getState().getShadowMetadata(t, i)?.arrayKeys || [], { totalHeight: j, itemOffsets: b } = gt(() => {
|
|
751
748
|
let v = 0;
|
|
752
749
|
const T = /* @__PURE__ */ new Map();
|
|
753
750
|
return (e.getState().getShadowMetadata(t, i)?.arrayKeys || []).forEach((D) => {
|
|
@@ -766,9 +763,9 @@ function Dt(t, r, g, S) {
|
|
|
766
763
|
v.clientHeight / o
|
|
767
764
|
), D = N.length - 1, R = Math.max(
|
|
768
765
|
0,
|
|
769
|
-
D - $ -
|
|
766
|
+
D - $ - r
|
|
770
767
|
);
|
|
771
|
-
|
|
768
|
+
E({ startIndex: R, endIndex: D }), requestAnimationFrame(() => {
|
|
772
769
|
P("instant"), C.current = !1;
|
|
773
770
|
});
|
|
774
771
|
} else
|
|
@@ -776,7 +773,7 @@ function Dt(t, r, g, S) {
|
|
|
776
773
|
};
|
|
777
774
|
T();
|
|
778
775
|
}
|
|
779
|
-
}, [N.length, a, o,
|
|
776
|
+
}, [N.length, a, o, r]);
|
|
780
777
|
const k = ct(() => {
|
|
781
778
|
const v = l.current;
|
|
782
779
|
if (!v) return;
|
|
@@ -792,11 +789,11 @@ function Dt(t, r, g, S) {
|
|
|
792
789
|
}
|
|
793
790
|
if (tt !== p.startIndex) {
|
|
794
791
|
const et = Math.ceil(D / o);
|
|
795
|
-
|
|
796
|
-
startIndex: Math.max(0, tt -
|
|
792
|
+
E({
|
|
793
|
+
startIndex: Math.max(0, tt - r),
|
|
797
794
|
endIndex: Math.min(
|
|
798
795
|
N.length - 1,
|
|
799
|
-
tt + et +
|
|
796
|
+
tt + et + r
|
|
800
797
|
)
|
|
801
798
|
});
|
|
802
799
|
}
|
|
@@ -804,7 +801,7 @@ function Dt(t, r, g, S) {
|
|
|
804
801
|
N.length,
|
|
805
802
|
p.startIndex,
|
|
806
803
|
o,
|
|
807
|
-
|
|
804
|
+
r,
|
|
808
805
|
d
|
|
809
806
|
]);
|
|
810
807
|
Z(() => {
|
|
@@ -870,7 +867,7 @@ function Dt(t, r, g, S) {
|
|
|
870
867
|
clearTimeout($), R.disconnect(), v.removeEventListener("load", L, !0);
|
|
871
868
|
};
|
|
872
869
|
}, [a, N.length, P]), {
|
|
873
|
-
virtualState:
|
|
870
|
+
virtualState: gt(() => {
|
|
874
871
|
const v = e.getState(), T = v.getShadowValue(
|
|
875
872
|
[t, ...i].join(".")
|
|
876
873
|
), $ = v.getShadowMetadata(t, i)?.arrayKeys || [], D = T.slice(
|
|
@@ -921,7 +918,7 @@ function Dt(t, r, g, S) {
|
|
|
921
918
|
};
|
|
922
919
|
if (m === "stateMap")
|
|
923
920
|
return (s) => {
|
|
924
|
-
const [o,
|
|
921
|
+
const [o, r] = K(
|
|
925
922
|
h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys
|
|
926
923
|
), a = e.getState().getShadowValue(c, h?.validIds);
|
|
927
924
|
if (!o)
|
|
@@ -933,9 +930,9 @@ function Dt(t, r, g, S) {
|
|
|
933
930
|
meta: h
|
|
934
931
|
});
|
|
935
932
|
return a.map((l, p) => {
|
|
936
|
-
const
|
|
933
|
+
const E = o[p]?.split(".").slice(1), _ = u({
|
|
937
934
|
currentState: l,
|
|
938
|
-
path:
|
|
935
|
+
path: E,
|
|
939
936
|
componentId: M,
|
|
940
937
|
meta: h
|
|
941
938
|
});
|
|
@@ -960,11 +957,11 @@ function Dt(t, r, g, S) {
|
|
|
960
957
|
return (s) => {
|
|
961
958
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
962
959
|
if (o)
|
|
963
|
-
for (let
|
|
964
|
-
const a = o[
|
|
960
|
+
for (let r = 0; r < o.length; r++) {
|
|
961
|
+
const a = o[r];
|
|
965
962
|
if (!a) continue;
|
|
966
963
|
const d = e.getState().getShadowValue(a);
|
|
967
|
-
if (s(d,
|
|
964
|
+
if (s(d, r)) {
|
|
968
965
|
const l = a.split(".").slice(1);
|
|
969
966
|
return u({
|
|
970
967
|
currentState: d,
|
|
@@ -981,15 +978,15 @@ function Dt(t, r, g, S) {
|
|
|
981
978
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
982
979
|
if (!o)
|
|
983
980
|
throw new Error("No array keys found for filtering.");
|
|
984
|
-
const
|
|
985
|
-
(d, l) => s(d, l) ? (
|
|
981
|
+
const r = [], a = w.filter(
|
|
982
|
+
(d, l) => s(d, l) ? (r.push(o[l]), !0) : !1
|
|
986
983
|
);
|
|
987
984
|
return u({
|
|
988
985
|
currentState: a,
|
|
989
986
|
path: i,
|
|
990
987
|
componentId: M,
|
|
991
988
|
meta: {
|
|
992
|
-
validIds:
|
|
989
|
+
validIds: r,
|
|
993
990
|
transforms: [
|
|
994
991
|
...h?.transforms || [],
|
|
995
992
|
{
|
|
@@ -1005,16 +1002,16 @@ function Dt(t, r, g, S) {
|
|
|
1005
1002
|
const o = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1006
1003
|
if (!o)
|
|
1007
1004
|
throw new Error("No array keys found for sorting");
|
|
1008
|
-
const
|
|
1005
|
+
const r = w.map((a, d) => ({
|
|
1009
1006
|
item: a,
|
|
1010
1007
|
key: o[d]
|
|
1011
1008
|
}));
|
|
1012
|
-
return
|
|
1013
|
-
currentState:
|
|
1009
|
+
return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), u({
|
|
1010
|
+
currentState: r.map((a) => a.item),
|
|
1014
1011
|
path: i,
|
|
1015
1012
|
componentId: M,
|
|
1016
1013
|
meta: {
|
|
1017
|
-
validIds:
|
|
1014
|
+
validIds: r.map((a) => a.key),
|
|
1018
1015
|
transforms: [
|
|
1019
1016
|
...h?.transforms || [],
|
|
1020
1017
|
{ type: "sort", fn: s }
|
|
@@ -1026,14 +1023,14 @@ function Dt(t, r, g, S) {
|
|
|
1026
1023
|
return function(s = {}) {
|
|
1027
1024
|
const {
|
|
1028
1025
|
bufferSize: o = 100,
|
|
1029
|
-
flushInterval:
|
|
1026
|
+
flushInterval: r = 100,
|
|
1030
1027
|
bufferStrategy: a = "accumulate",
|
|
1031
1028
|
store: d,
|
|
1032
1029
|
onFlush: l
|
|
1033
1030
|
} = s;
|
|
1034
|
-
let p = [],
|
|
1031
|
+
let p = [], E = !1, _ = null;
|
|
1035
1032
|
const U = (j) => {
|
|
1036
|
-
if (!
|
|
1033
|
+
if (!E) {
|
|
1037
1034
|
if (a === "sliding" && p.length >= o)
|
|
1038
1035
|
p.shift();
|
|
1039
1036
|
else if (a === "dropping" && p.length >= o)
|
|
@@ -1046,19 +1043,19 @@ function Dt(t, r, g, S) {
|
|
|
1046
1043
|
if (p = [], d) {
|
|
1047
1044
|
const b = d(j);
|
|
1048
1045
|
b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((P) => {
|
|
1049
|
-
|
|
1046
|
+
n(P, i, {
|
|
1050
1047
|
updateType: "insert"
|
|
1051
1048
|
});
|
|
1052
1049
|
});
|
|
1053
1050
|
} else
|
|
1054
1051
|
j.forEach((b) => {
|
|
1055
|
-
|
|
1052
|
+
n(b, i, {
|
|
1056
1053
|
updateType: "insert"
|
|
1057
1054
|
});
|
|
1058
1055
|
});
|
|
1059
1056
|
l?.(j);
|
|
1060
1057
|
};
|
|
1061
|
-
|
|
1058
|
+
r > 0 && (_ = setInterval(C, r));
|
|
1062
1059
|
const F = rt(), x = e.getState().getShadowMetadata(t, i) || {}, N = x.streams || /* @__PURE__ */ new Map();
|
|
1063
1060
|
return N.set(F, { buffer: p, flushTimer: _ }), e.getState().setShadowMetadata(t, i, {
|
|
1064
1061
|
...x,
|
|
@@ -1068,10 +1065,10 @@ function Dt(t, r, g, S) {
|
|
|
1068
1065
|
writeMany: (j) => j.forEach(U),
|
|
1069
1066
|
flush: () => C(),
|
|
1070
1067
|
pause: () => {
|
|
1071
|
-
|
|
1068
|
+
E = !0;
|
|
1072
1069
|
},
|
|
1073
1070
|
resume: () => {
|
|
1074
|
-
|
|
1071
|
+
E = !1, p.length > 0 && C();
|
|
1075
1072
|
},
|
|
1076
1073
|
close: () => {
|
|
1077
1074
|
C(), _ && clearInterval(_);
|
|
@@ -1082,7 +1079,7 @@ function Dt(t, r, g, S) {
|
|
|
1082
1079
|
};
|
|
1083
1080
|
if (m === "stateList")
|
|
1084
1081
|
return (s) => /* @__PURE__ */ ot(() => {
|
|
1085
|
-
const
|
|
1082
|
+
const r = q(/* @__PURE__ */ new Map()), a = h?.transforms && h.transforms.length > 0 ? `${M}-${Bt(h.transforms)}` : `${M}-base`, [d, l] = K({}), { validIds: p, arrayValues: E } = gt(() => {
|
|
1086
1083
|
const U = e.getState().getShadowMetadata(t, i)?.transformCaches?.get(a);
|
|
1087
1084
|
let C;
|
|
1088
1085
|
U && U.validIds ? C = U.validIds : (C = It(
|
|
@@ -1113,10 +1110,10 @@ function Dt(t, r, g, S) {
|
|
|
1113
1110
|
return () => {
|
|
1114
1111
|
U();
|
|
1115
1112
|
};
|
|
1116
|
-
}, [M, c]), !Array.isArray(
|
|
1113
|
+
}, [M, c]), !Array.isArray(E))
|
|
1117
1114
|
return null;
|
|
1118
1115
|
const _ = u({
|
|
1119
|
-
currentState:
|
|
1116
|
+
currentState: E,
|
|
1120
1117
|
path: i,
|
|
1121
1118
|
componentId: M,
|
|
1122
1119
|
meta: {
|
|
@@ -1124,12 +1121,12 @@ function Dt(t, r, g, S) {
|
|
|
1124
1121
|
validIds: p
|
|
1125
1122
|
}
|
|
1126
1123
|
});
|
|
1127
|
-
return /* @__PURE__ */ ot(Ut, { children:
|
|
1124
|
+
return /* @__PURE__ */ ot(Ut, { children: E.map((U, C) => {
|
|
1128
1125
|
const F = p[C];
|
|
1129
1126
|
if (!F)
|
|
1130
1127
|
return null;
|
|
1131
|
-
let x =
|
|
1132
|
-
x || (x = rt(),
|
|
1128
|
+
let x = r.current.get(F);
|
|
1129
|
+
x || (x = rt(), r.current.set(F, x));
|
|
1133
1130
|
const N = F.split(".").slice(1);
|
|
1134
1131
|
return lt(Mt, {
|
|
1135
1132
|
key: F,
|
|
@@ -1147,11 +1144,11 @@ function Dt(t, r, g, S) {
|
|
|
1147
1144
|
return (s) => {
|
|
1148
1145
|
const o = w;
|
|
1149
1146
|
y.clear(), I++;
|
|
1150
|
-
const
|
|
1147
|
+
const r = o.flatMap(
|
|
1151
1148
|
(a) => a[s] ?? []
|
|
1152
1149
|
);
|
|
1153
1150
|
return u({
|
|
1154
|
-
currentState:
|
|
1151
|
+
currentState: r,
|
|
1155
1152
|
path: [...i, "[*]", s],
|
|
1156
1153
|
componentId: M,
|
|
1157
1154
|
meta: h
|
|
@@ -1159,14 +1156,14 @@ function Dt(t, r, g, S) {
|
|
|
1159
1156
|
};
|
|
1160
1157
|
if (m === "index")
|
|
1161
1158
|
return (s) => {
|
|
1162
|
-
const
|
|
1159
|
+
const r = e.getState().getShadowMetadata(t, i)?.arrayKeys?.filter(
|
|
1163
1160
|
(l) => !h?.validIds || h?.validIds && h?.validIds?.includes(l)
|
|
1164
1161
|
)?.[s];
|
|
1165
|
-
if (!
|
|
1166
|
-
const a = e.getState().getShadowValue(
|
|
1162
|
+
if (!r) return;
|
|
1163
|
+
const a = e.getState().getShadowValue(r, h?.validIds);
|
|
1167
1164
|
return u({
|
|
1168
1165
|
currentState: a,
|
|
1169
|
-
path:
|
|
1166
|
+
path: r.split(".").slice(1),
|
|
1170
1167
|
componentId: M,
|
|
1171
1168
|
meta: h
|
|
1172
1169
|
});
|
|
@@ -1175,49 +1172,49 @@ function Dt(t, r, g, S) {
|
|
|
1175
1172
|
return () => {
|
|
1176
1173
|
const s = e.getState().getShadowValue(t, i);
|
|
1177
1174
|
if (s.length === 0) return;
|
|
1178
|
-
const o = s.length - 1,
|
|
1175
|
+
const o = s.length - 1, r = s[o], a = [...i, o.toString()];
|
|
1179
1176
|
return u({
|
|
1180
|
-
currentState:
|
|
1177
|
+
currentState: r,
|
|
1181
1178
|
path: a,
|
|
1182
1179
|
componentId: M,
|
|
1183
1180
|
meta: h
|
|
1184
1181
|
});
|
|
1185
1182
|
};
|
|
1186
1183
|
if (m === "insert")
|
|
1187
|
-
return (s, o) => (
|
|
1184
|
+
return (s, o) => (n(s, i, { updateType: "insert" }), u({
|
|
1188
1185
|
currentState: e.getState().getShadowValue(t, i),
|
|
1189
1186
|
path: i,
|
|
1190
1187
|
componentId: M,
|
|
1191
1188
|
meta: h
|
|
1192
1189
|
}));
|
|
1193
1190
|
if (m === "uniqueInsert")
|
|
1194
|
-
return (s, o,
|
|
1191
|
+
return (s, o, r) => {
|
|
1195
1192
|
const a = e.getState().getShadowValue(t, i), d = at(s) ? s(a) : s;
|
|
1196
1193
|
let l = null;
|
|
1197
|
-
if (!a.some((
|
|
1194
|
+
if (!a.some((E) => {
|
|
1198
1195
|
const _ = o ? o.every(
|
|
1199
|
-
(U) => st(
|
|
1200
|
-
) : st(
|
|
1201
|
-
return _ && (l =
|
|
1196
|
+
(U) => st(E[U], d[U])
|
|
1197
|
+
) : st(E, d);
|
|
1198
|
+
return _ && (l = E), _;
|
|
1202
1199
|
}))
|
|
1203
|
-
|
|
1204
|
-
else if (
|
|
1205
|
-
const
|
|
1206
|
-
(U) => st(U, l) ?
|
|
1200
|
+
V(i), n(d, i, { updateType: "insert" });
|
|
1201
|
+
else if (r && l) {
|
|
1202
|
+
const E = r(l), _ = a.map(
|
|
1203
|
+
(U) => st(U, l) ? E : U
|
|
1207
1204
|
);
|
|
1208
|
-
|
|
1205
|
+
V(i), n(_, i, {
|
|
1209
1206
|
updateType: "update"
|
|
1210
1207
|
});
|
|
1211
1208
|
}
|
|
1212
1209
|
};
|
|
1213
1210
|
if (m === "cut")
|
|
1214
1211
|
return (s, o) => {
|
|
1215
|
-
const
|
|
1216
|
-
if (!
|
|
1217
|
-
const a = s == -1 ?
|
|
1212
|
+
const r = h?.validIds ?? e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1213
|
+
if (!r || r.length === 0) return;
|
|
1214
|
+
const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
|
|
1218
1215
|
if (!d) return;
|
|
1219
1216
|
const l = d.split(".").slice(1);
|
|
1220
|
-
|
|
1217
|
+
n(w, l, {
|
|
1221
1218
|
updateType: "cut"
|
|
1222
1219
|
});
|
|
1223
1220
|
};
|
|
@@ -1230,37 +1227,37 @@ function Dt(t, r, g, S) {
|
|
|
1230
1227
|
);
|
|
1231
1228
|
if (!s || s.length === 0) return;
|
|
1232
1229
|
const o = e.getState().selectedIndicesMap.get(c);
|
|
1233
|
-
let
|
|
1230
|
+
let r = s.findIndex(
|
|
1234
1231
|
(l) => l === o
|
|
1235
1232
|
);
|
|
1236
|
-
const a = s[
|
|
1233
|
+
const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
|
|
1237
1234
|
e.getState().clearSelectedIndex({ arrayKey: c });
|
|
1238
1235
|
const d = a?.slice(0, -1);
|
|
1239
|
-
ft(t, d),
|
|
1236
|
+
ft(t, d), n(w, a, {
|
|
1240
1237
|
updateType: "cut"
|
|
1241
1238
|
});
|
|
1242
1239
|
};
|
|
1243
1240
|
if (m === "cutByValue")
|
|
1244
1241
|
return (s) => {
|
|
1245
|
-
const o = e.getState().getShadowMetadata(t, i),
|
|
1246
|
-
if (!
|
|
1242
|
+
const o = e.getState().getShadowMetadata(t, i), r = h?.validIds ?? o?.arrayKeys;
|
|
1243
|
+
if (!r) return;
|
|
1247
1244
|
let a = null;
|
|
1248
|
-
for (const d of
|
|
1245
|
+
for (const d of r)
|
|
1249
1246
|
if (e.getState().getShadowValue(d) === s) {
|
|
1250
1247
|
a = d;
|
|
1251
1248
|
break;
|
|
1252
1249
|
}
|
|
1253
1250
|
if (a) {
|
|
1254
1251
|
const d = a.split(".").slice(1);
|
|
1255
|
-
|
|
1252
|
+
n(null, d, { updateType: "cut" });
|
|
1256
1253
|
}
|
|
1257
1254
|
};
|
|
1258
1255
|
if (m === "toggleByValue")
|
|
1259
1256
|
return (s) => {
|
|
1260
|
-
const o = e.getState().getShadowMetadata(t, i),
|
|
1261
|
-
if (!
|
|
1257
|
+
const o = e.getState().getShadowMetadata(t, i), r = h?.validIds ?? o?.arrayKeys;
|
|
1258
|
+
if (!r) return;
|
|
1262
1259
|
let a = null;
|
|
1263
|
-
for (const d of
|
|
1260
|
+
for (const d of r) {
|
|
1264
1261
|
const l = e.getState().getShadowValue(d);
|
|
1265
1262
|
if (console.log("itemValue sdasdasdasd", l), l === s) {
|
|
1266
1263
|
a = d;
|
|
@@ -1269,19 +1266,19 @@ function Dt(t, r, g, S) {
|
|
|
1269
1266
|
}
|
|
1270
1267
|
if (console.log("itemValue keyToCut", a), a) {
|
|
1271
1268
|
const d = a.split(".").slice(1);
|
|
1272
|
-
console.log("itemValue keyToCut", a),
|
|
1269
|
+
console.log("itemValue keyToCut", a), n(s, d, {
|
|
1273
1270
|
updateType: "cut"
|
|
1274
1271
|
});
|
|
1275
1272
|
} else
|
|
1276
|
-
|
|
1273
|
+
n(s, i, { updateType: "insert" });
|
|
1277
1274
|
};
|
|
1278
1275
|
if (m === "findWith")
|
|
1279
1276
|
return (s, o) => {
|
|
1280
|
-
const
|
|
1281
|
-
if (!
|
|
1277
|
+
const r = e.getState().getShadowMetadata(t, i)?.arrayKeys;
|
|
1278
|
+
if (!r)
|
|
1282
1279
|
throw new Error("No array keys found for sorting");
|
|
1283
1280
|
let a = null, d = [];
|
|
1284
|
-
for (const l of
|
|
1281
|
+
for (const l of r) {
|
|
1285
1282
|
let p = e.getState().getShadowValue(l, h?.validIds);
|
|
1286
1283
|
if (p && p[s] === o) {
|
|
1287
1284
|
a = p, d = l.split(".").slice(1);
|
|
@@ -1299,11 +1296,11 @@ function Dt(t, r, g, S) {
|
|
|
1299
1296
|
if (m === "cut") {
|
|
1300
1297
|
let s = e.getState().getShadowValue(i.join("."));
|
|
1301
1298
|
return () => {
|
|
1302
|
-
|
|
1299
|
+
n(s, i, { updateType: "cut" });
|
|
1303
1300
|
};
|
|
1304
1301
|
}
|
|
1305
1302
|
if (m === "get")
|
|
1306
|
-
return () => (
|
|
1303
|
+
return () => (Et(t, M, i), e.getState().getShadowValue(c, h?.validIds));
|
|
1307
1304
|
if (m === "getState")
|
|
1308
1305
|
return () => e.getState().getShadowValue(c, h?.validIds);
|
|
1309
1306
|
if (m === "$derive")
|
|
@@ -1320,27 +1317,27 @@ function Dt(t, r, g, S) {
|
|
|
1320
1317
|
return e.getState().getSyncInfo(s);
|
|
1321
1318
|
}
|
|
1322
1319
|
if (m == "getLocalStorage")
|
|
1323
|
-
return (s) =>
|
|
1320
|
+
return (s) => St(g + "-" + t + "-" + s);
|
|
1324
1321
|
if (m === "isSelected") {
|
|
1325
1322
|
const s = [t, ...i].slice(0, -1);
|
|
1326
1323
|
if (ft(t, i, void 0), Array.isArray(
|
|
1327
1324
|
e.getState().getShadowValue(s.join("."), h?.validIds)
|
|
1328
1325
|
)) {
|
|
1329
1326
|
i[i.length - 1];
|
|
1330
|
-
const o = s.join("."),
|
|
1331
|
-
return
|
|
1327
|
+
const o = s.join("."), r = e.getState().selectedIndicesMap.get(o), a = t + "." + i.join(".");
|
|
1328
|
+
return r === a;
|
|
1332
1329
|
}
|
|
1333
1330
|
return;
|
|
1334
1331
|
}
|
|
1335
1332
|
if (m === "setSelected")
|
|
1336
1333
|
return (s) => {
|
|
1337
|
-
const o = i.slice(0, -1),
|
|
1338
|
-
ft(t, o, void 0), e.getState().selectedIndicesMap.get(
|
|
1334
|
+
const o = i.slice(0, -1), r = t + "." + o.join("."), a = t + "." + i.join(".");
|
|
1335
|
+
ft(t, o, void 0), e.getState().selectedIndicesMap.get(r), s && e.getState().setSelectedIndex(r, a);
|
|
1339
1336
|
};
|
|
1340
1337
|
if (m === "toggleSelected")
|
|
1341
1338
|
return () => {
|
|
1342
|
-
const s = i.slice(0, -1), o = t + "." + s.join("."),
|
|
1343
|
-
e.getState().selectedIndicesMap.get(o) ===
|
|
1339
|
+
const s = i.slice(0, -1), o = t + "." + s.join("."), r = t + "." + i.join(".");
|
|
1340
|
+
e.getState().selectedIndicesMap.get(o) === r ? e.getState().clearSelectedIndex({ arrayKey: o }) : e.getState().setSelectedIndex(o, r);
|
|
1344
1341
|
};
|
|
1345
1342
|
if (m === "_componentId")
|
|
1346
1343
|
return M;
|
|
@@ -1349,23 +1346,23 @@ function Dt(t, r, g, S) {
|
|
|
1349
1346
|
return (s) => {
|
|
1350
1347
|
const o = e.getState().getInitialOptions(t)?.validation;
|
|
1351
1348
|
if (!o?.key) throw new Error("Validation key not found");
|
|
1352
|
-
ut(o.key), s.forEach((
|
|
1353
|
-
const a = [o.key, ...
|
|
1354
|
-
pt(a,
|
|
1349
|
+
ut(o.key), s.forEach((r) => {
|
|
1350
|
+
const a = [o.key, ...r.path].join(".");
|
|
1351
|
+
pt(a, r.message);
|
|
1355
1352
|
}), it(t);
|
|
1356
1353
|
};
|
|
1357
1354
|
if (m === "applyJsonPatch")
|
|
1358
1355
|
return (s) => {
|
|
1359
|
-
const o = e.getState(),
|
|
1360
|
-
if (!
|
|
1356
|
+
const o = e.getState(), r = o.getShadowMetadata(t, []);
|
|
1357
|
+
if (!r?.components) return;
|
|
1361
1358
|
const a = (l) => !l || l === "/" ? [] : l.split("/").slice(1).map((p) => p.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
|
|
1362
1359
|
for (const l of s) {
|
|
1363
1360
|
const p = a(l.path);
|
|
1364
1361
|
switch (l.op) {
|
|
1365
1362
|
case "add":
|
|
1366
1363
|
case "replace": {
|
|
1367
|
-
const { value:
|
|
1368
|
-
o.updateShadowAtPath(t, p,
|
|
1364
|
+
const { value: E } = l;
|
|
1365
|
+
o.updateShadowAtPath(t, p, E), o.markAsDirty(t, p, { bubble: !0 });
|
|
1369
1366
|
let _ = [...p];
|
|
1370
1367
|
for (; ; ) {
|
|
1371
1368
|
const U = o.getShadowMetadata(
|
|
@@ -1374,7 +1371,7 @@ function Dt(t, r, g, S) {
|
|
|
1374
1371
|
);
|
|
1375
1372
|
if (console.log("pathMeta", U), U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1376
1373
|
if (!d.has(C)) {
|
|
1377
|
-
const F =
|
|
1374
|
+
const F = r.components?.get(C);
|
|
1378
1375
|
F && (F.forceUpdate(), d.add(C));
|
|
1379
1376
|
}
|
|
1380
1377
|
}), _.length === 0) break;
|
|
@@ -1383,9 +1380,9 @@ function Dt(t, r, g, S) {
|
|
|
1383
1380
|
break;
|
|
1384
1381
|
}
|
|
1385
1382
|
case "remove": {
|
|
1386
|
-
const
|
|
1387
|
-
o.removeShadowArrayElement(t, p), o.markAsDirty(t,
|
|
1388
|
-
let _ = [...
|
|
1383
|
+
const E = p.slice(0, -1);
|
|
1384
|
+
o.removeShadowArrayElement(t, p), o.markAsDirty(t, E, { bubble: !0 });
|
|
1385
|
+
let _ = [...E];
|
|
1389
1386
|
for (; ; ) {
|
|
1390
1387
|
const U = o.getShadowMetadata(
|
|
1391
1388
|
t,
|
|
@@ -1393,7 +1390,7 @@ function Dt(t, r, g, S) {
|
|
|
1393
1390
|
);
|
|
1394
1391
|
if (U?.pathComponents && U.pathComponents.forEach((C) => {
|
|
1395
1392
|
if (!d.has(C)) {
|
|
1396
|
-
const F =
|
|
1393
|
+
const F = r.components?.get(C);
|
|
1397
1394
|
F && (F.forceUpdate(), d.add(C));
|
|
1398
1395
|
}
|
|
1399
1396
|
}), _.length === 0) break;
|
|
@@ -1412,7 +1409,7 @@ function Dt(t, r, g, S) {
|
|
|
1412
1409
|
"Zod schema (v3 or v4) or validation key not found"
|
|
1413
1410
|
);
|
|
1414
1411
|
ut(s.key);
|
|
1415
|
-
const
|
|
1412
|
+
const r = e.getState().getShadowValue(t), a = o.safeParse(r);
|
|
1416
1413
|
return a.success ? !0 : ("issues" in a.error ? a.error.issues.forEach((d) => {
|
|
1417
1414
|
const l = [s.key, ...d.path].join(".");
|
|
1418
1415
|
pt(l, d.message);
|
|
@@ -1444,7 +1441,7 @@ function Dt(t, r, g, S) {
|
|
|
1444
1441
|
if (m === "_stateKey") return t;
|
|
1445
1442
|
if (m === "_path") return i;
|
|
1446
1443
|
if (m === "update")
|
|
1447
|
-
return (s) => (
|
|
1444
|
+
return (s) => (n(s, i, { updateType: "update" }), {
|
|
1448
1445
|
/**
|
|
1449
1446
|
* Marks this specific item, which was just updated, as 'synced' (not dirty).
|
|
1450
1447
|
*/
|
|
@@ -1459,8 +1456,8 @@ function Dt(t, r, g, S) {
|
|
|
1459
1456
|
lastServerSync: Date.now()
|
|
1460
1457
|
// Add timestamp
|
|
1461
1458
|
});
|
|
1462
|
-
const
|
|
1463
|
-
e.getState().notifyPathSubscribers(
|
|
1459
|
+
const r = [t, ...i].join(".");
|
|
1460
|
+
e.getState().notifyPathSubscribers(r, {
|
|
1464
1461
|
type: "SYNC_STATUS_CHANGE",
|
|
1465
1462
|
isDirty: !1
|
|
1466
1463
|
});
|
|
@@ -1471,7 +1468,7 @@ function Dt(t, r, g, S) {
|
|
|
1471
1468
|
if (console.log("currentValueAtPath", s), typeof w != "boolean")
|
|
1472
1469
|
throw new Error("toggle() can only be used on boolean values");
|
|
1473
1470
|
return () => {
|
|
1474
|
-
|
|
1471
|
+
n(!s, i, {
|
|
1475
1472
|
updateType: "update"
|
|
1476
1473
|
});
|
|
1477
1474
|
};
|
|
@@ -1483,7 +1480,7 @@ function Dt(t, r, g, S) {
|
|
|
1483
1480
|
stateKey: t,
|
|
1484
1481
|
path: i,
|
|
1485
1482
|
rebuildStateShape: u,
|
|
1486
|
-
setState:
|
|
1483
|
+
setState: n,
|
|
1487
1484
|
formOpts: o,
|
|
1488
1485
|
renderFn: s
|
|
1489
1486
|
}
|
|
@@ -1515,9 +1512,9 @@ function Dt(t, r, g, S) {
|
|
|
1515
1512
|
e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, M), u({
|
|
1516
1513
|
currentState: M,
|
|
1517
1514
|
path: [],
|
|
1518
|
-
componentId:
|
|
1515
|
+
componentId: S
|
|
1519
1516
|
});
|
|
1520
|
-
const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${
|
|
1517
|
+
const z = nt(t), c = at(z?.localStorage?.key) ? z?.localStorage?.key(M) : z?.localStorage?.key, B = `${g}-${t}-${c}`;
|
|
1521
1518
|
B && localStorage.removeItem(B);
|
|
1522
1519
|
const J = e.getState().getShadowMetadata(t, []);
|
|
1523
1520
|
return J && J?.components?.forEach((H) => {
|
|
@@ -1528,10 +1525,10 @@ function Dt(t, r, g, S) {
|
|
|
1528
1525
|
y.clear(), I++;
|
|
1529
1526
|
const i = Dt(
|
|
1530
1527
|
t,
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
), h = e.getState().initialStateGlobal[t], M = nt(t), z = at(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, c = `${
|
|
1528
|
+
n,
|
|
1529
|
+
S,
|
|
1530
|
+
g
|
|
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}`;
|
|
1535
1532
|
return localStorage.getItem(c) && localStorage.removeItem(c), Rt(() => {
|
|
1536
1533
|
_t(t, w), e.getState().initializeShadowState(t, w);
|
|
1537
1534
|
const B = e.getState().getShadowMetadata(t, []);
|
|
@@ -1545,7 +1542,7 @@ function Dt(t, r, g, S) {
|
|
|
1545
1542
|
};
|
|
1546
1543
|
return u({
|
|
1547
1544
|
currentState: e.getState().getShadowValue(t, []),
|
|
1548
|
-
componentId:
|
|
1545
|
+
componentId: S,
|
|
1549
1546
|
path: []
|
|
1550
1547
|
});
|
|
1551
1548
|
}
|
|
@@ -1554,49 +1551,49 @@ function bt(t) {
|
|
|
1554
1551
|
}
|
|
1555
1552
|
function qt({
|
|
1556
1553
|
proxy: t,
|
|
1557
|
-
rebuildStateShape:
|
|
1554
|
+
rebuildStateShape: n
|
|
1558
1555
|
}) {
|
|
1559
|
-
const
|
|
1556
|
+
const S = q(null), g = q(`map-${crypto.randomUUID()}`), y = q(!1), I = q(/* @__PURE__ */ new Map());
|
|
1560
1557
|
Z(() => {
|
|
1561
|
-
const u =
|
|
1558
|
+
const u = S.current;
|
|
1562
1559
|
if (!u || y.current) return;
|
|
1563
1560
|
const f = setTimeout(() => {
|
|
1564
1561
|
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, w = A.mapWrappers || [];
|
|
1565
1562
|
w.push({
|
|
1566
|
-
instanceId:
|
|
1563
|
+
instanceId: g.current,
|
|
1567
1564
|
mapFn: t._mapFn,
|
|
1568
1565
|
containerRef: u,
|
|
1569
|
-
rebuildStateShape:
|
|
1566
|
+
rebuildStateShape: n,
|
|
1570
1567
|
path: t._path,
|
|
1571
|
-
componentId:
|
|
1568
|
+
componentId: g.current,
|
|
1572
1569
|
meta: t._meta
|
|
1573
1570
|
}), e.getState().setShadowMetadata(t._stateKey, t._path, {
|
|
1574
1571
|
...A,
|
|
1575
1572
|
mapWrappers: w
|
|
1576
|
-
}), y.current = !0,
|
|
1573
|
+
}), y.current = !0, V();
|
|
1577
1574
|
}, 0);
|
|
1578
1575
|
return () => {
|
|
1579
|
-
if (clearTimeout(f),
|
|
1576
|
+
if (clearTimeout(f), g.current) {
|
|
1580
1577
|
const A = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1581
1578
|
A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
|
|
1582
|
-
(w) => w.instanceId !==
|
|
1579
|
+
(w) => w.instanceId !== g.current
|
|
1583
1580
|
), e.getState().setShadowMetadata(t._stateKey, t._path, A));
|
|
1584
1581
|
}
|
|
1585
1582
|
I.current.forEach((A) => A.unmount());
|
|
1586
1583
|
};
|
|
1587
1584
|
}, []);
|
|
1588
|
-
const
|
|
1589
|
-
const u =
|
|
1585
|
+
const V = () => {
|
|
1586
|
+
const u = S.current;
|
|
1590
1587
|
if (!u) return;
|
|
1591
1588
|
const f = e.getState().getShadowValue(
|
|
1592
1589
|
[t._stateKey, ...t._path].join("."),
|
|
1593
1590
|
t._meta?.validIds
|
|
1594
1591
|
);
|
|
1595
1592
|
if (!Array.isArray(f)) return;
|
|
1596
|
-
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w =
|
|
1593
|
+
const A = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], w = n({
|
|
1597
1594
|
currentState: f,
|
|
1598
1595
|
path: t._path,
|
|
1599
|
-
componentId:
|
|
1596
|
+
componentId: g.current,
|
|
1600
1597
|
meta: t._meta
|
|
1601
1598
|
});
|
|
1602
1599
|
f.forEach((i, h) => {
|
|
@@ -1614,35 +1611,35 @@ function qt({
|
|
|
1614
1611
|
itemPath: J,
|
|
1615
1612
|
localIndex: h,
|
|
1616
1613
|
arraySetter: w,
|
|
1617
|
-
rebuildStateShape:
|
|
1614
|
+
rebuildStateShape: n,
|
|
1618
1615
|
renderFn: t._mapFn
|
|
1619
1616
|
})
|
|
1620
1617
|
);
|
|
1621
1618
|
});
|
|
1622
1619
|
};
|
|
1623
|
-
return /* @__PURE__ */ ot("div", { ref:
|
|
1620
|
+
return /* @__PURE__ */ ot("div", { ref: S, "data-map-container": g.current });
|
|
1624
1621
|
}
|
|
1625
1622
|
function Gt({
|
|
1626
1623
|
proxy: t
|
|
1627
1624
|
}) {
|
|
1628
|
-
const
|
|
1625
|
+
const n = q(null), S = q(null), g = q(!1), y = `${t._stateKey}-${t._path.join(".")}`, I = e.getState().getShadowValue(
|
|
1629
1626
|
[t._stateKey, ...t._path].join("."),
|
|
1630
1627
|
t._meta?.validIds
|
|
1631
1628
|
);
|
|
1632
1629
|
return Z(() => {
|
|
1633
|
-
const
|
|
1634
|
-
if (!
|
|
1630
|
+
const V = n.current;
|
|
1631
|
+
if (!V || g.current) return;
|
|
1635
1632
|
const u = setTimeout(() => {
|
|
1636
|
-
if (!
|
|
1633
|
+
if (!V.parentElement) {
|
|
1637
1634
|
console.warn("Parent element not found for signal", y);
|
|
1638
1635
|
return;
|
|
1639
1636
|
}
|
|
1640
|
-
const f =
|
|
1637
|
+
const f = V.parentElement, w = Array.from(f.childNodes).indexOf(V);
|
|
1641
1638
|
let i = f.getAttribute("data-parent-id");
|
|
1642
|
-
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)),
|
|
1639
|
+
i || (i = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", i)), S.current = `instance-${crypto.randomUUID()}`;
|
|
1643
1640
|
const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, M = h.signals || [];
|
|
1644
1641
|
M.push({
|
|
1645
|
-
instanceId:
|
|
1642
|
+
instanceId: S.current,
|
|
1646
1643
|
parentId: i,
|
|
1647
1644
|
position: w,
|
|
1648
1645
|
effect: t._effect
|
|
@@ -1662,61 +1659,61 @@ function Gt({
|
|
|
1662
1659
|
}
|
|
1663
1660
|
z !== null && typeof z == "object" && (z = JSON.stringify(z));
|
|
1664
1661
|
const c = document.createTextNode(String(z ?? ""));
|
|
1665
|
-
|
|
1662
|
+
V.replaceWith(c), g.current = !0;
|
|
1666
1663
|
}, 0);
|
|
1667
1664
|
return () => {
|
|
1668
|
-
if (clearTimeout(u),
|
|
1665
|
+
if (clearTimeout(u), S.current) {
|
|
1669
1666
|
const f = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
|
|
1670
1667
|
f.signals && (f.signals = f.signals.filter(
|
|
1671
|
-
(A) => A.instanceId !==
|
|
1668
|
+
(A) => A.instanceId !== S.current
|
|
1672
1669
|
), e.getState().setShadowMetadata(t._stateKey, t._path, f));
|
|
1673
1670
|
}
|
|
1674
1671
|
};
|
|
1675
1672
|
}, []), lt("span", {
|
|
1676
|
-
ref:
|
|
1673
|
+
ref: n,
|
|
1677
1674
|
style: { display: "contents" },
|
|
1678
1675
|
"data-signal-id": y
|
|
1679
1676
|
});
|
|
1680
1677
|
}
|
|
1681
1678
|
const Mt = Ot(
|
|
1682
1679
|
Yt,
|
|
1683
|
-
(t,
|
|
1680
|
+
(t, n) => t.itemPath.join(".") === n.itemPath.join(".") && t.stateKey === n.stateKey && t.itemComponentId === n.itemComponentId && t.localIndex === n.localIndex
|
|
1684
1681
|
), Jt = (t) => {
|
|
1685
|
-
const [
|
|
1682
|
+
const [n, S] = K(!1);
|
|
1686
1683
|
return dt(() => {
|
|
1687
1684
|
if (!t.current) {
|
|
1688
|
-
|
|
1685
|
+
S(!0);
|
|
1689
1686
|
return;
|
|
1690
1687
|
}
|
|
1691
|
-
const
|
|
1692
|
-
if (
|
|
1693
|
-
|
|
1688
|
+
const g = Array.from(t.current.querySelectorAll("img"));
|
|
1689
|
+
if (g.length === 0) {
|
|
1690
|
+
S(!0);
|
|
1694
1691
|
return;
|
|
1695
1692
|
}
|
|
1696
1693
|
let y = 0;
|
|
1697
1694
|
const I = () => {
|
|
1698
|
-
y++, y ===
|
|
1695
|
+
y++, y === g.length && S(!0);
|
|
1699
1696
|
};
|
|
1700
|
-
return
|
|
1701
|
-
|
|
1697
|
+
return g.forEach((V) => {
|
|
1698
|
+
V.complete ? I() : (V.addEventListener("load", I), V.addEventListener("error", I));
|
|
1702
1699
|
}), () => {
|
|
1703
|
-
|
|
1704
|
-
|
|
1700
|
+
g.forEach((V) => {
|
|
1701
|
+
V.removeEventListener("load", I), V.removeEventListener("error", I);
|
|
1705
1702
|
});
|
|
1706
1703
|
};
|
|
1707
|
-
}, [t.current]),
|
|
1704
|
+
}, [t.current]), n;
|
|
1708
1705
|
};
|
|
1709
1706
|
function Yt({
|
|
1710
1707
|
stateKey: t,
|
|
1711
|
-
itemComponentId:
|
|
1712
|
-
itemPath:
|
|
1713
|
-
localIndex:
|
|
1708
|
+
itemComponentId: n,
|
|
1709
|
+
itemPath: S,
|
|
1710
|
+
localIndex: g,
|
|
1714
1711
|
arraySetter: y,
|
|
1715
1712
|
rebuildStateShape: I,
|
|
1716
|
-
renderFn:
|
|
1713
|
+
renderFn: V
|
|
1717
1714
|
}) {
|
|
1718
|
-
const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...
|
|
1719
|
-
$t(t,
|
|
1715
|
+
const [, u] = K({}), { ref: f, inView: A } = jt(), w = q(null), i = Jt(w), h = q(!1), M = [t, ...S].join(".");
|
|
1716
|
+
$t(t, n, u);
|
|
1720
1717
|
const z = ct(
|
|
1721
1718
|
(W) => {
|
|
1722
1719
|
w.current = W, f(W);
|
|
@@ -1734,40 +1731,40 @@ function Yt({
|
|
|
1734
1731
|
if (W && W.offsetHeight > 0) {
|
|
1735
1732
|
h.current = !0;
|
|
1736
1733
|
const m = W.offsetHeight;
|
|
1737
|
-
e.getState().setShadowMetadata(t,
|
|
1734
|
+
e.getState().setShadowMetadata(t, S, {
|
|
1738
1735
|
virtualizer: {
|
|
1739
1736
|
itemHeight: m,
|
|
1740
1737
|
domRef: W
|
|
1741
1738
|
}
|
|
1742
1739
|
});
|
|
1743
|
-
const Y =
|
|
1740
|
+
const Y = S.slice(0, -1), Q = [t, ...Y].join(".");
|
|
1744
1741
|
e.getState().notifyPathSubscribers(Q, {
|
|
1745
1742
|
type: "ITEMHEIGHT",
|
|
1746
|
-
itemKey:
|
|
1743
|
+
itemKey: S.join("."),
|
|
1747
1744
|
ref: w.current
|
|
1748
1745
|
});
|
|
1749
1746
|
}
|
|
1750
|
-
}, [A, i, t,
|
|
1751
|
-
const c = [t, ...
|
|
1747
|
+
}, [A, i, t, S]);
|
|
1748
|
+
const c = [t, ...S].join("."), B = e.getState().getShadowValue(c);
|
|
1752
1749
|
if (B === void 0)
|
|
1753
1750
|
return null;
|
|
1754
1751
|
const J = I({
|
|
1755
1752
|
currentState: B,
|
|
1756
|
-
path:
|
|
1757
|
-
componentId:
|
|
1758
|
-
}), H =
|
|
1753
|
+
path: S,
|
|
1754
|
+
componentId: n
|
|
1755
|
+
}), H = V(J, g, y);
|
|
1759
1756
|
return /* @__PURE__ */ ot("div", { ref: z, children: H });
|
|
1760
1757
|
}
|
|
1761
1758
|
function Zt({
|
|
1762
1759
|
stateKey: t,
|
|
1763
|
-
path:
|
|
1764
|
-
rebuildStateShape:
|
|
1765
|
-
renderFn:
|
|
1760
|
+
path: n,
|
|
1761
|
+
rebuildStateShape: S,
|
|
1762
|
+
renderFn: g,
|
|
1766
1763
|
formOpts: y,
|
|
1767
1764
|
setState: I
|
|
1768
1765
|
}) {
|
|
1769
|
-
const [
|
|
1770
|
-
$t(t,
|
|
1766
|
+
const [V] = K(() => rt()), [, u] = K({}), f = [t, ...n].join(".");
|
|
1767
|
+
$t(t, V, u);
|
|
1771
1768
|
const A = e.getState().getShadowValue(f), [w, i] = K(A), h = q(!1), M = q(null);
|
|
1772
1769
|
Z(() => {
|
|
1773
1770
|
!h.current && !st(A, w) && i(A);
|
|
@@ -1784,12 +1781,12 @@ function Zt({
|
|
|
1784
1781
|
typeof A === "number" && typeof H == "string" && (H = H === "" ? 0 : Number(H)), i(H), h.current = !0, M.current && clearTimeout(M.current);
|
|
1785
1782
|
const m = y?.debounceTime ?? 200;
|
|
1786
1783
|
M.current = setTimeout(() => {
|
|
1787
|
-
h.current = !1, I(H,
|
|
1784
|
+
h.current = !1, I(H, n, { updateType: "update" });
|
|
1788
1785
|
const { getInitialOptions: Y, setShadowMetadata: Q, getShadowMetadata: X } = e.getState(), s = Y(t)?.validation, o = s?.zodSchemaV4 || s?.zodSchemaV3;
|
|
1789
1786
|
if (o) {
|
|
1790
|
-
const
|
|
1787
|
+
const r = e.getState().getShadowValue(t), a = o.safeParse(r), d = X(t, n) || {};
|
|
1791
1788
|
if (a.success)
|
|
1792
|
-
Q(t,
|
|
1789
|
+
Q(t, n, {
|
|
1793
1790
|
...d,
|
|
1794
1791
|
validation: {
|
|
1795
1792
|
status: "VALID_LIVE",
|
|
@@ -1798,16 +1795,16 @@ function Zt({
|
|
|
1798
1795
|
});
|
|
1799
1796
|
else {
|
|
1800
1797
|
const p = ("issues" in a.error ? a.error.issues : a.error.errors).filter(
|
|
1801
|
-
(
|
|
1798
|
+
(E) => JSON.stringify(E.path) === JSON.stringify(n)
|
|
1802
1799
|
);
|
|
1803
|
-
p.length > 0 ? Q(t,
|
|
1800
|
+
p.length > 0 ? Q(t, n, {
|
|
1804
1801
|
...d,
|
|
1805
1802
|
validation: {
|
|
1806
1803
|
status: "INVALID_LIVE",
|
|
1807
1804
|
message: p[0]?.message,
|
|
1808
1805
|
validatedValue: H
|
|
1809
1806
|
}
|
|
1810
|
-
}) : Q(t,
|
|
1807
|
+
}) : Q(t, n, {
|
|
1811
1808
|
...d,
|
|
1812
1809
|
validation: {
|
|
1813
1810
|
status: "VALID_LIVE",
|
|
@@ -1818,13 +1815,13 @@ function Zt({
|
|
|
1818
1815
|
}
|
|
1819
1816
|
}, m), u({});
|
|
1820
1817
|
},
|
|
1821
|
-
[I,
|
|
1818
|
+
[I, n, y?.debounceTime, t]
|
|
1822
1819
|
), c = ct(async () => {
|
|
1823
|
-
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w,
|
|
1820
|
+
console.log("handleBlur triggered"), M.current && (clearTimeout(M.current), M.current = null, h.current = !1, I(w, n, { updateType: "update" }));
|
|
1824
1821
|
const { getInitialOptions: H } = e.getState(), W = H(t)?.validation, m = W?.zodSchemaV4 || W?.zodSchemaV3;
|
|
1825
1822
|
if (!m) return;
|
|
1826
|
-
const Y = e.getState().getShadowMetadata(t,
|
|
1827
|
-
e.getState().setShadowMetadata(t,
|
|
1823
|
+
const Y = e.getState().getShadowMetadata(t, n);
|
|
1824
|
+
e.getState().setShadowMetadata(t, n, {
|
|
1828
1825
|
...Y,
|
|
1829
1826
|
validation: {
|
|
1830
1827
|
status: "DIRTY",
|
|
@@ -1833,7 +1830,7 @@ function Zt({
|
|
|
1833
1830
|
});
|
|
1834
1831
|
const Q = e.getState().getShadowValue(t), X = m.safeParse(Q);
|
|
1835
1832
|
if (console.log("result ", X), X.success)
|
|
1836
|
-
e.getState().setShadowMetadata(t,
|
|
1833
|
+
e.getState().setShadowMetadata(t, n, {
|
|
1837
1834
|
...Y,
|
|
1838
1835
|
validation: {
|
|
1839
1836
|
status: "VALID_PENDING_SYNC",
|
|
@@ -1842,32 +1839,32 @@ function Zt({
|
|
|
1842
1839
|
});
|
|
1843
1840
|
else {
|
|
1844
1841
|
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:",
|
|
1842
|
+
console.log("All validation errors:", s), console.log("Current blur path:", n);
|
|
1843
|
+
const o = s.filter((r) => {
|
|
1844
|
+
if (console.log("Processing error:", r), n.some((d) => d.startsWith("id:"))) {
|
|
1848
1845
|
console.log("Detected array path with ULID");
|
|
1849
|
-
const d =
|
|
1846
|
+
const d = n[0].startsWith("id:") ? [] : n.slice(0, -1);
|
|
1850
1847
|
console.log("Parent path:", d);
|
|
1851
1848
|
const l = e.getState().getShadowMetadata(t, d);
|
|
1852
1849
|
if (console.log("Array metadata:", l), l?.arrayKeys) {
|
|
1853
|
-
const p = [t, ...
|
|
1854
|
-
console.log("Item key:", p, "Index:",
|
|
1855
|
-
const _ = [...d,
|
|
1850
|
+
const p = [t, ...n.slice(0, -1)].join("."), E = l.arrayKeys.indexOf(p);
|
|
1851
|
+
console.log("Item key:", p, "Index:", E);
|
|
1852
|
+
const _ = [...d, E, ...n.slice(-1)], U = JSON.stringify(r.path) === JSON.stringify(_);
|
|
1856
1853
|
return console.log("Zod path comparison:", {
|
|
1857
1854
|
zodPath: _,
|
|
1858
|
-
errorPath:
|
|
1855
|
+
errorPath: r.path,
|
|
1859
1856
|
match: U
|
|
1860
1857
|
}), U;
|
|
1861
1858
|
}
|
|
1862
1859
|
}
|
|
1863
|
-
const a = JSON.stringify(
|
|
1860
|
+
const a = JSON.stringify(r.path) === JSON.stringify(n);
|
|
1864
1861
|
return console.log("Direct path comparison:", {
|
|
1865
|
-
errorPath:
|
|
1866
|
-
currentPath:
|
|
1862
|
+
errorPath: r.path,
|
|
1863
|
+
currentPath: n,
|
|
1867
1864
|
match: a
|
|
1868
1865
|
}), a;
|
|
1869
1866
|
});
|
|
1870
|
-
console.log("Filtered path errors:", o), e.getState().setShadowMetadata(t,
|
|
1867
|
+
console.log("Filtered path errors:", o), e.getState().setShadowMetadata(t, n, {
|
|
1871
1868
|
...Y,
|
|
1872
1869
|
validation: {
|
|
1873
1870
|
status: "VALIDATION_FAILED",
|
|
@@ -1877,10 +1874,10 @@ function Zt({
|
|
|
1877
1874
|
});
|
|
1878
1875
|
}
|
|
1879
1876
|
u({});
|
|
1880
|
-
}, [t,
|
|
1877
|
+
}, [t, n, w, I]), B = S({
|
|
1881
1878
|
currentState: A,
|
|
1882
|
-
path:
|
|
1883
|
-
componentId:
|
|
1879
|
+
path: n,
|
|
1880
|
+
componentId: V
|
|
1884
1881
|
}), J = new Proxy(B, {
|
|
1885
1882
|
get(H, W) {
|
|
1886
1883
|
return W === "inputProps" ? {
|
|
@@ -1890,24 +1887,24 @@ function Zt({
|
|
|
1890
1887
|
},
|
|
1891
1888
|
// 5. Wire the new onBlur handler to the input props.
|
|
1892
1889
|
onBlur: c,
|
|
1893
|
-
ref: vt.getState().getFormRef(t + "." +
|
|
1890
|
+
ref: vt.getState().getFormRef(t + "." + n.join("."))
|
|
1894
1891
|
} : H[W];
|
|
1895
1892
|
}
|
|
1896
1893
|
});
|
|
1897
|
-
return /* @__PURE__ */ ot(kt, { formOpts: y, path:
|
|
1894
|
+
return /* @__PURE__ */ ot(kt, { formOpts: y, path: n, stateKey: t, children: g(J) });
|
|
1898
1895
|
}
|
|
1899
|
-
function $t(t,
|
|
1900
|
-
const
|
|
1896
|
+
function $t(t, n, S) {
|
|
1897
|
+
const g = `${t}////${n}`;
|
|
1901
1898
|
dt(() => {
|
|
1902
1899
|
const { registerComponent: y, unregisterComponent: I } = e.getState();
|
|
1903
|
-
return y(t,
|
|
1904
|
-
forceUpdate: () =>
|
|
1900
|
+
return y(t, g, {
|
|
1901
|
+
forceUpdate: () => S({}),
|
|
1905
1902
|
paths: /* @__PURE__ */ new Set(),
|
|
1906
1903
|
reactiveType: ["component"]
|
|
1907
1904
|
}), () => {
|
|
1908
|
-
I(t,
|
|
1905
|
+
I(t, g);
|
|
1909
1906
|
};
|
|
1910
|
-
}, [t,
|
|
1907
|
+
}, [t, g]);
|
|
1911
1908
|
}
|
|
1912
1909
|
export {
|
|
1913
1910
|
bt as $cogsSignal,
|