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