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