cogsbox-state 0.5.422 → 0.5.423
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.jsx +395 -389
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +30 -18
package/dist/CogsState.jsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as yt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as
|
|
3
|
+
import { useState as st, useRef as J, useEffect as nt, useLayoutEffect as xt, useMemo as It, createElement as lt, useSyncExternalStore as Mt, startTransition as Ot, useCallback as ft } from "react";
|
|
4
4
|
import { transformStateFunc as jt, isDeepEqual as q, isFunction as K, getNestedValue as Y, getDifferences as wt, debounce as Ut } from "./utility.js";
|
|
5
|
-
import { pushFunc as vt, updateFn as
|
|
5
|
+
import { pushFunc as vt, updateFn as ct, cutFunc as gt, ValidationWrapper as Ft, FormControlComponent as Dt } from "./Functions.jsx";
|
|
6
6
|
import Lt from "superjson";
|
|
7
7
|
import { v4 as pt } from "uuid";
|
|
8
8
|
import "zod";
|
|
@@ -10,158 +10,158 @@ import { getGlobalStore as o, formRefStore as kt } from "./store.js";
|
|
|
10
10
|
import { useCogsConfig as Nt } from "./CogsStateClient.jsx";
|
|
11
11
|
import { applyPatch as Gt } from "fast-json-patch";
|
|
12
12
|
import Wt from "react-use-measure";
|
|
13
|
-
function At(t,
|
|
14
|
-
const S = o.getState().getInitialOptions, u = o.getState().setInitialStateOptions,
|
|
13
|
+
function At(t, i) {
|
|
14
|
+
const S = o.getState().getInitialOptions, u = o.getState().setInitialStateOptions, h = S(t) || {};
|
|
15
15
|
u(t, {
|
|
16
|
-
...
|
|
17
|
-
...
|
|
16
|
+
...h,
|
|
17
|
+
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
function bt({
|
|
21
21
|
stateKey: t,
|
|
22
|
-
options:
|
|
22
|
+
options: i,
|
|
23
23
|
initialOptionsPart: S
|
|
24
24
|
}) {
|
|
25
|
-
const u =
|
|
25
|
+
const u = at(t) || {}, h = S[t] || {}, V = o.getState().setInitialStateOptions, I = { ...h, ...u };
|
|
26
26
|
let y = !1;
|
|
27
|
-
if (
|
|
28
|
-
for (const
|
|
29
|
-
I.hasOwnProperty(
|
|
30
|
-
!q(I[
|
|
27
|
+
if (i)
|
|
28
|
+
for (const s in i)
|
|
29
|
+
I.hasOwnProperty(s) ? (s == "localStorage" && i[s] && I[s].key !== i[s]?.key && (y = !0, I[s] = i[s]), s == "initialState" && i[s] && I[s] !== i[s] && // Different references
|
|
30
|
+
!q(I[s], i[s]) && (y = !0, I[s] = i[s])) : (y = !0, I[s] = i[s]);
|
|
31
31
|
y && V(t, I);
|
|
32
32
|
}
|
|
33
|
-
function de(t, { formElements:
|
|
34
|
-
return { initialState: t, formElements:
|
|
33
|
+
function de(t, { formElements: i, validation: S }) {
|
|
34
|
+
return { initialState: t, formElements: i, validation: S };
|
|
35
35
|
}
|
|
36
|
-
const ue = (t,
|
|
36
|
+
const ue = (t, i) => {
|
|
37
37
|
let S = t;
|
|
38
|
-
const [u,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
41
|
-
...
|
|
38
|
+
const [u, h] = jt(S);
|
|
39
|
+
(Object.keys(h).length > 0 || i && Object.keys(i).length > 0) && Object.keys(h).forEach((y) => {
|
|
40
|
+
h[y] = h[y] || {}, h[y].formElements = {
|
|
41
|
+
...i?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
|
-
...
|
|
44
|
-
...
|
|
43
|
+
...i?.validation,
|
|
44
|
+
...h[y].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
46
|
+
}, at(y) || o.getState().setInitialStateOptions(y, h[y]);
|
|
47
47
|
}), o.getState().setInitialStates(u), o.getState().setCreatedState(u);
|
|
48
|
-
const V = (y,
|
|
49
|
-
const [
|
|
48
|
+
const V = (y, s) => {
|
|
49
|
+
const [m] = st(s?.componentId ?? pt());
|
|
50
50
|
bt({
|
|
51
51
|
stateKey: y,
|
|
52
|
-
options:
|
|
53
|
-
initialOptionsPart:
|
|
52
|
+
options: s,
|
|
53
|
+
initialOptionsPart: h
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[y] || u[y], g =
|
|
55
|
+
const n = o.getState().cogsStateStore[y] || u[y], g = s?.modifyState ? s.modifyState(n) : n, [D, j] = Yt(
|
|
56
56
|
g,
|
|
57
57
|
{
|
|
58
58
|
stateKey: y,
|
|
59
|
-
syncUpdate:
|
|
60
|
-
componentId:
|
|
61
|
-
localStorage:
|
|
62
|
-
middleware:
|
|
63
|
-
enabledSync:
|
|
64
|
-
reactiveType:
|
|
65
|
-
reactiveDeps:
|
|
66
|
-
initialState:
|
|
67
|
-
dependencies:
|
|
68
|
-
serverState:
|
|
59
|
+
syncUpdate: s?.syncUpdate,
|
|
60
|
+
componentId: m,
|
|
61
|
+
localStorage: s?.localStorage,
|
|
62
|
+
middleware: s?.middleware,
|
|
63
|
+
enabledSync: s?.enabledSync,
|
|
64
|
+
reactiveType: s?.reactiveType,
|
|
65
|
+
reactiveDeps: s?.reactiveDeps,
|
|
66
|
+
initialState: s?.initialState,
|
|
67
|
+
dependencies: s?.dependencies,
|
|
68
|
+
serverState: s?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return j;
|
|
72
72
|
};
|
|
73
|
-
function I(y,
|
|
74
|
-
bt({ stateKey: y, options:
|
|
73
|
+
function I(y, s) {
|
|
74
|
+
bt({ stateKey: y, options: s, initialOptionsPart: h }), s.localStorage && qt(y, s), dt(y);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: V, setCogsOptions: I };
|
|
77
77
|
}, {
|
|
78
78
|
setUpdaterState: St,
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
79
|
+
setState: rt,
|
|
80
|
+
getInitialOptions: at,
|
|
81
81
|
getKeyState: Pt,
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
82
|
+
getValidationErrors: Ht,
|
|
83
|
+
setStateLog: zt,
|
|
84
84
|
updateInitialStateGlobal: Et,
|
|
85
85
|
addValidationError: Ct,
|
|
86
86
|
removeValidationError: X,
|
|
87
87
|
setServerSyncActions: Bt
|
|
88
|
-
} = o.getState(), Vt = (t,
|
|
88
|
+
} = o.getState(), Vt = (t, i, S, u, h) => {
|
|
89
89
|
S?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
|
-
|
|
91
|
+
i,
|
|
92
92
|
S.localStorage?.key,
|
|
93
93
|
u
|
|
94
94
|
);
|
|
95
95
|
const V = K(S?.localStorage?.key) ? S.localStorage?.key(t) : S?.localStorage?.key;
|
|
96
96
|
if (V && u) {
|
|
97
|
-
const I = `${u}-${
|
|
97
|
+
const I = `${u}-${i}-${V}`;
|
|
98
98
|
let y;
|
|
99
99
|
try {
|
|
100
100
|
y = ht(I)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
const s = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: h ?? y
|
|
107
|
+
}, m = Lt.serialize(s);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
I,
|
|
110
|
-
JSON.stringify(
|
|
110
|
+
JSON.stringify(m.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
}, ht = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
|
-
const
|
|
117
|
-
return
|
|
118
|
-
} catch (
|
|
119
|
-
return console.error("Error loading from localStorage:",
|
|
116
|
+
const i = window.localStorage.getItem(t);
|
|
117
|
+
return i ? JSON.parse(i) : null;
|
|
118
|
+
} catch (i) {
|
|
119
|
+
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
|
-
}, qt = (t,
|
|
122
|
-
const S = o.getState().cogsStateStore[t], { sessionId: u } = Nt(),
|
|
123
|
-
if (
|
|
121
|
+
}, qt = (t, i) => {
|
|
122
|
+
const S = o.getState().cogsStateStore[t], { sessionId: u } = Nt(), h = K(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
|
|
123
|
+
if (h && u) {
|
|
124
124
|
const V = ht(
|
|
125
|
-
`${u}-${t}-${
|
|
125
|
+
`${u}-${t}-${h}`
|
|
126
126
|
);
|
|
127
127
|
if (V && V.lastUpdated > (V.lastSyncedWithServer || 0))
|
|
128
|
-
return
|
|
128
|
+
return rt(t, V.state), dt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, _t = (t,
|
|
131
|
+
}, _t = (t, i, S, u, h, V) => {
|
|
132
132
|
const I = {
|
|
133
|
-
initialState:
|
|
133
|
+
initialState: i,
|
|
134
134
|
updaterState: mt(
|
|
135
135
|
t,
|
|
136
136
|
u,
|
|
137
|
-
|
|
137
|
+
h,
|
|
138
138
|
V
|
|
139
139
|
),
|
|
140
140
|
state: S
|
|
141
141
|
};
|
|
142
|
-
Et(t, I.initialState), St(t, I.updaterState),
|
|
143
|
-
},
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
142
|
+
Et(t, I.initialState), St(t, I.updaterState), rt(t, I.state);
|
|
143
|
+
}, dt = (t) => {
|
|
144
|
+
const i = o.getState().stateComponents.get(t);
|
|
145
|
+
if (!i) return;
|
|
146
146
|
const S = /* @__PURE__ */ new Set();
|
|
147
|
-
|
|
147
|
+
i.components.forEach((u) => {
|
|
148
148
|
(u ? Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"] : null)?.includes("none") || S.add(() => u.forceUpdate());
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
S.forEach((u) => u());
|
|
151
151
|
});
|
|
152
|
-
}, ge = (t,
|
|
152
|
+
}, ge = (t, i) => {
|
|
153
153
|
const S = o.getState().stateComponents.get(t);
|
|
154
154
|
if (S) {
|
|
155
|
-
const u = `${t}////${
|
|
156
|
-
if ((
|
|
155
|
+
const u = `${t}////${i}`, h = S.components.get(u);
|
|
156
|
+
if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
|
-
|
|
158
|
+
h && h.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
}, Jt = (t,
|
|
160
|
+
}, Jt = (t, i, S, u) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue: Y(
|
|
164
|
+
oldValue: Y(i, u),
|
|
165
165
|
newValue: Y(S, u)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
@@ -172,7 +172,7 @@ const ue = (t, s) => {
|
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue: Y(
|
|
175
|
+
oldValue: Y(i, u),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -181,93 +181,93 @@ const ue = (t, s) => {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
function Yt(t, {
|
|
184
|
-
stateKey:
|
|
184
|
+
stateKey: i,
|
|
185
185
|
serverSync: S,
|
|
186
186
|
localStorage: u,
|
|
187
|
-
formElements:
|
|
187
|
+
formElements: h,
|
|
188
188
|
reactiveDeps: V,
|
|
189
189
|
reactiveType: I,
|
|
190
190
|
componentId: y,
|
|
191
|
-
initialState:
|
|
192
|
-
syncUpdate:
|
|
191
|
+
initialState: s,
|
|
192
|
+
syncUpdate: m,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: g
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [f] =
|
|
196
|
+
const [D, j] = st({}), { sessionId: U } = Nt();
|
|
197
|
+
let W = !i;
|
|
198
|
+
const [f] = st(i ?? pt()), l = o.getState().stateLog[f], ut = J(/* @__PURE__ */ new Set()), tt = J(y ?? pt()), O = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
201
|
+
O.current = at(f) ?? null, nt(() => {
|
|
202
|
+
if (m && m.stateKey === f && m.path?.[0]) {
|
|
203
|
+
rt(f, (r) => ({
|
|
204
204
|
...r,
|
|
205
|
-
[
|
|
205
|
+
[m.path[0]]: m.newValue
|
|
206
206
|
}));
|
|
207
|
-
const e = `${
|
|
207
|
+
const e = `${m.stateKey}:${m.path.join(".")}`;
|
|
208
208
|
o.getState().setSyncInfo(e, {
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
209
|
+
timeStamp: m.timeStamp,
|
|
210
|
+
userId: m.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
214
|
-
if (
|
|
213
|
+
}, [m]), nt(() => {
|
|
214
|
+
if (s) {
|
|
215
215
|
At(f, {
|
|
216
|
-
initialState:
|
|
216
|
+
initialState: s
|
|
217
217
|
});
|
|
218
|
-
const e =
|
|
219
|
-
if (!(c && !q(c,
|
|
218
|
+
const e = O.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[f];
|
|
219
|
+
if (!(c && !q(c, s) || !c) && !a)
|
|
220
220
|
return;
|
|
221
|
-
let
|
|
222
|
-
const k = K(e?.localStorage?.key) ? e?.localStorage?.key(
|
|
223
|
-
k &&
|
|
224
|
-
let
|
|
225
|
-
const _ = a ? Date.now() : 0,
|
|
226
|
-
a && _ >
|
|
221
|
+
let v = null;
|
|
222
|
+
const k = K(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
223
|
+
k && U && (v = ht(`${U}-${f}-${k}`));
|
|
224
|
+
let E = s, b = !1;
|
|
225
|
+
const _ = a ? Date.now() : 0, C = v?.lastUpdated || 0, R = v?.lastSyncedWithServer || 0;
|
|
226
|
+
a && _ > C ? (E = e.serverState.data, b = !0) : v && C > R && (E = v.state, e?.localStorage?.onChange && e?.localStorage?.onChange(E)), o.getState().initializeShadowState(f, s), _t(
|
|
227
227
|
f,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
s,
|
|
229
|
+
E,
|
|
230
|
+
it,
|
|
231
231
|
tt.current,
|
|
232
|
-
|
|
233
|
-
), b && k &&
|
|
232
|
+
U
|
|
233
|
+
), b && k && U && Vt(E, f, e, U, Date.now()), dt(f), (Array.isArray(I) ? I : [I || "component"]).includes("none") || j({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
|
-
|
|
236
|
+
s,
|
|
237
237
|
g?.status,
|
|
238
238
|
g?.data,
|
|
239
239
|
...n || []
|
|
240
240
|
]), xt(() => {
|
|
241
|
-
|
|
241
|
+
W && At(f, {
|
|
242
242
|
serverSync: S,
|
|
243
|
-
formElements:
|
|
244
|
-
initialState:
|
|
243
|
+
formElements: h,
|
|
244
|
+
initialState: s,
|
|
245
245
|
localStorage: u,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: O.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const e = `${f}////${tt.current}`, r = o.getState().stateComponents.get(f) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => j({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: V || void 0,
|
|
256
256
|
reactiveType: I ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(f, r),
|
|
257
|
+
}), o.getState().stateComponents.set(f, r), j({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(f));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const it = (e, r, a, c) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
|
-
const
|
|
264
|
-
|
|
263
|
+
const v = `${f}-${r.join(".")}`;
|
|
264
|
+
ut.current.add(v);
|
|
265
265
|
}
|
|
266
266
|
const w = o.getState();
|
|
267
|
-
|
|
268
|
-
const k = K(e) ? e(
|
|
269
|
-
if (
|
|
270
|
-
let T = !1, $ = w.signalDomElements.get(
|
|
267
|
+
rt(f, (v) => {
|
|
268
|
+
const k = K(e) ? e(v) : e, E = `${f}-${r.join(".")}`;
|
|
269
|
+
if (E) {
|
|
270
|
+
let T = !1, $ = w.signalDomElements.get(E);
|
|
271
271
|
if ((!$ || $.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
272
272
|
const x = r.slice(0, -1), G = Y(k, x);
|
|
273
273
|
if (Array.isArray(G)) {
|
|
@@ -278,28 +278,28 @@ function Yt(t, {
|
|
|
278
278
|
}
|
|
279
279
|
if ($) {
|
|
280
280
|
const x = T ? Y(k, r.slice(0, -1)) : Y(k, r);
|
|
281
|
-
$.forEach(({ parentId: G, position: A, effect:
|
|
282
|
-
const
|
|
281
|
+
$.forEach(({ parentId: G, position: A, effect: F }) => {
|
|
282
|
+
const M = document.querySelector(
|
|
283
283
|
`[data-parent-id="${G}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (M) {
|
|
286
|
+
const z = Array.from(M.childNodes);
|
|
287
|
+
if (z[A]) {
|
|
288
|
+
const p = F ? new Function("state", `return (${F})(state)`)(x) : x;
|
|
289
|
+
z[A].textContent = String(p);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (c ||
|
|
296
|
-
(c ||
|
|
295
|
+
console.log("shadowState", w.shadowStateStore), a.updateType === "update" && (c || O.current?.validation?.key) && r && X(
|
|
296
|
+
(c || O.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
298
|
const b = r.slice(0, r.length - 1);
|
|
299
|
-
a.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), a.updateType === "insert" &&
|
|
302
|
-
|
|
299
|
+
a.updateType === "cut" && O.current?.validation?.key && X(
|
|
300
|
+
O.current?.validation?.key + "." + b.join(".")
|
|
301
|
+
), a.updateType === "insert" && O.current?.validation?.key && Ht(
|
|
302
|
+
O.current?.validation?.key + "." + b.join(".")
|
|
303
303
|
).filter(([$, x]) => {
|
|
304
304
|
let G = $?.split(".").length;
|
|
305
305
|
if ($ == b.join(".") && G == b.length - 1) {
|
|
@@ -309,67 +309,67 @@ function Yt(t, {
|
|
|
309
309
|
});
|
|
310
310
|
const _ = w.stateComponents.get(f);
|
|
311
311
|
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
|
|
312
|
-
const T = wt(
|
|
312
|
+
const T = wt(v, k), $ = new Set(T), x = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
314
|
G,
|
|
315
315
|
A
|
|
316
316
|
] of _.components.entries()) {
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", A), !
|
|
320
|
-
if (
|
|
317
|
+
let F = !1;
|
|
318
|
+
const M = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", A), !M.includes("none")) {
|
|
320
|
+
if (M.includes("all")) {
|
|
321
321
|
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (M.includes("component") && ((A.paths.has(x) || A.paths.has("")) && (F = !0), !F))
|
|
325
|
+
for (const z of $) {
|
|
326
|
+
let p = z;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (A.paths.has(
|
|
329
|
-
|
|
328
|
+
if (A.paths.has(p)) {
|
|
329
|
+
F = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const N =
|
|
332
|
+
const N = p.lastIndexOf(".");
|
|
333
333
|
if (N !== -1) {
|
|
334
|
-
const
|
|
334
|
+
const P = p.substring(
|
|
335
335
|
0,
|
|
336
336
|
N
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && A.paths.has(
|
|
341
|
-
|
|
339
|
+
Number(p.substring(N + 1))
|
|
340
|
+
) && A.paths.has(P)) {
|
|
341
|
+
F = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
p = P;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
p = "";
|
|
347
|
+
if (p === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (F) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!F && M.includes("deps") && A.depsFunction) {
|
|
353
|
+
const z = A.depsFunction(k);
|
|
354
|
+
let p = !1;
|
|
355
|
+
typeof z == "boolean" ? z && (p = !0) : q(A.deps, z) || (A.deps = z, p = !0), p && (F = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
F && A.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
361
|
+
const C = Date.now();
|
|
362
362
|
r = r.map((T, $) => {
|
|
363
363
|
const x = r.slice(0, -1), G = Y(k, x);
|
|
364
364
|
return $ === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (G.length - 1).toString() : T;
|
|
365
365
|
});
|
|
366
366
|
const { oldValue: R, newValue: H } = Jt(
|
|
367
367
|
a.updateType,
|
|
368
|
-
|
|
368
|
+
v,
|
|
369
369
|
k,
|
|
370
370
|
r
|
|
371
371
|
), Q = {
|
|
372
|
-
timeStamp:
|
|
372
|
+
timeStamp: C,
|
|
373
373
|
stateKey: f,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: a.updateType,
|
|
@@ -390,22 +390,22 @@ function Yt(t, {
|
|
|
390
390
|
w.removeShadowArrayElement(f, $, x);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
393
|
+
if (zt(f, (T) => {
|
|
394
394
|
const x = [...T ?? [], Q].reduce((G, A) => {
|
|
395
|
-
const
|
|
396
|
-
return
|
|
395
|
+
const F = `${A.stateKey}:${JSON.stringify(A.path)}`, M = G.get(F);
|
|
396
|
+
return M ? (M.timeStamp = Math.max(M.timeStamp, A.timeStamp), M.newValue = A.newValue, M.oldValue = M.oldValue ?? A.oldValue, M.updateType = A.updateType) : G.set(F, { ...A }), G;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
398
|
return Array.from(x.values());
|
|
399
399
|
}), Vt(
|
|
400
400
|
k,
|
|
401
401
|
f,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
O.current,
|
|
403
|
+
U
|
|
404
|
+
), O.current?.middleware && O.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
406
|
update: Q
|
|
407
|
-
}),
|
|
408
|
-
const T = w.serverState[f], $ =
|
|
407
|
+
}), O.current?.serverSync) {
|
|
408
|
+
const T = w.serverState[f], $ = O.current?.serverSync;
|
|
409
409
|
Bt(f, {
|
|
410
410
|
syncKey: typeof $.syncKey == "string" ? $.syncKey : $.syncKey({ state: k }),
|
|
411
411
|
rollBackState: T,
|
|
@@ -420,87 +420,87 @@ function Yt(t, {
|
|
|
420
420
|
f,
|
|
421
421
|
mt(
|
|
422
422
|
f,
|
|
423
|
-
|
|
423
|
+
it,
|
|
424
424
|
tt.current,
|
|
425
|
-
|
|
425
|
+
U
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[f] ||
|
|
427
|
+
), o.getState().cogsStateStore[f] || rt(f, t), o.getState().initialStateGlobal[f] || Et(f, t));
|
|
428
428
|
const d = It(() => mt(
|
|
429
429
|
f,
|
|
430
|
-
|
|
430
|
+
it,
|
|
431
431
|
tt.current,
|
|
432
|
-
|
|
433
|
-
), [f,
|
|
432
|
+
U
|
|
433
|
+
), [f, U]);
|
|
434
434
|
return [Pt(f), d];
|
|
435
435
|
}
|
|
436
|
-
function mt(t,
|
|
437
|
-
const
|
|
436
|
+
function mt(t, i, S, u) {
|
|
437
|
+
const h = /* @__PURE__ */ new Map();
|
|
438
438
|
let V = 0;
|
|
439
|
-
const I = (
|
|
440
|
-
const n =
|
|
441
|
-
for (const [g] of
|
|
442
|
-
(g === n || g.startsWith(n + ".")) &&
|
|
439
|
+
const I = (m) => {
|
|
440
|
+
const n = m.join(".");
|
|
441
|
+
for (const [g] of h)
|
|
442
|
+
(g === n || g.startsWith(n + ".")) && h.delete(g);
|
|
443
443
|
V++;
|
|
444
444
|
}, y = {
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
445
|
+
removeValidation: (m) => {
|
|
446
|
+
m?.validationKey && X(m.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
448
|
+
revertToInitialState: (m) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key && X(n?.key),
|
|
450
|
+
n?.key && X(n?.key), m?.validationKey && X(m.validationKey);
|
|
451
451
|
const g = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t),
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), h.clear(), V++;
|
|
453
|
+
const D = s(g, []), j = at(t), U = K(j?.localStorage?.key) ? j?.localStorage?.key(g) : j?.localStorage?.key, W = `${u}-${t}-${U}`;
|
|
454
|
+
W && localStorage.removeItem(W), St(t, D), rt(t, g);
|
|
455
455
|
const f = o.getState().stateComponents.get(t);
|
|
456
456
|
return f && f.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), g;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
460
|
+
updateInitialState: (m) => {
|
|
461
|
+
h.clear(), V++;
|
|
462
462
|
const n = mt(
|
|
463
463
|
t,
|
|
464
|
-
|
|
464
|
+
i,
|
|
465
465
|
S,
|
|
466
466
|
u
|
|
467
|
-
), g = o.getState().initialStateGlobal[t],
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
Et(t,
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), g = o.getState().initialStateGlobal[t], D = at(t), j = K(D?.localStorage?.key) ? D?.localStorage?.key(g) : D?.localStorage?.key, U = `${u}-${t}-${j}`;
|
|
468
|
+
return localStorage.getItem(U) && localStorage.removeItem(U), Ot(() => {
|
|
469
|
+
Et(t, m), o.getState().initializeShadowState(t, m), St(t, n), rt(t, m);
|
|
470
|
+
const W = o.getState().stateComponents.get(t);
|
|
471
|
+
W && W.components.forEach((f) => {
|
|
472
472
|
f.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (W) => n.get()[W]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
479
479
|
_serverState: o.getState().serverState[t],
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const m = o.getState().serverState[t];
|
|
483
|
+
return !!(m && q(m, Pt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
const
|
|
486
|
+
function s(m, n = [], g) {
|
|
487
|
+
const D = n.map(String).join(".");
|
|
488
|
+
h.get(D);
|
|
489
|
+
const j = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(y).forEach((f) => {
|
|
493
|
-
|
|
493
|
+
j[f] = y[f];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(f, l,
|
|
495
|
+
const U = {
|
|
496
|
+
apply(f, l, ut) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
501
|
get(f, l) {
|
|
502
|
-
g?.validIndices && !Array.isArray(
|
|
503
|
-
const
|
|
502
|
+
g?.validIndices && !Array.isArray(m) && (g = { ...g, validIndices: void 0 });
|
|
503
|
+
const ut = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function mt(t, s, S, u) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ut.has(l)) {
|
|
527
527
|
const d = `${t}////${S}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const r = e.components.get(d);
|
|
@@ -553,13 +553,13 @@ function mt(t, s, S, u) {
|
|
|
553
553
|
try {
|
|
554
554
|
const c = await e.action(r);
|
|
555
555
|
if (c && !c.success && c.errors && a) {
|
|
556
|
-
o.getState().removeValidationError(a), c.errors.forEach((
|
|
557
|
-
const k = [a, ...
|
|
558
|
-
o.getState().addValidationError(k,
|
|
556
|
+
o.getState().removeValidationError(a), c.errors.forEach((v) => {
|
|
557
|
+
const k = [a, ...v.path].join(".");
|
|
558
|
+
o.getState().addValidationError(k, v.message);
|
|
559
559
|
});
|
|
560
560
|
const w = o.getState().stateComponents.get(t);
|
|
561
|
-
w && w.components.forEach((
|
|
562
|
-
|
|
561
|
+
w && w.components.forEach((v) => {
|
|
562
|
+
v.forceUpdate();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
565
|
return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
|
|
@@ -581,7 +581,7 @@ function mt(t, s, S, u) {
|
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = at(t), r = K(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${u}-${t}-${r}`;
|
|
585
585
|
a && localStorage.removeItem(a);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -591,8 +591,8 @@ function mt(t, s, S, u) {
|
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => g?.validIndices ?
|
|
594
|
+
if (Array.isArray(m)) {
|
|
595
|
+
const d = () => g?.validIndices ? m.map((r, a) => ({
|
|
596
596
|
item: r,
|
|
597
597
|
originalIndex: g.validIndices[a]
|
|
598
598
|
})) : o.getState().getNestedState(t, n).map((r, a) => ({
|
|
@@ -603,8 +603,8 @@ function mt(t, s, S, u) {
|
|
|
603
603
|
return () => {
|
|
604
604
|
const e = o.getState().getSelectedIndex(t, n.join("."));
|
|
605
605
|
if (e !== void 0)
|
|
606
|
-
return
|
|
607
|
-
|
|
606
|
+
return s(
|
|
607
|
+
m[e],
|
|
608
608
|
[...n, e.toString()],
|
|
609
609
|
g
|
|
610
610
|
);
|
|
@@ -622,26 +622,26 @@ function mt(t, s, S, u) {
|
|
|
622
622
|
overscan: a = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: w = []
|
|
625
|
-
} = e,
|
|
625
|
+
} = e, v = J(null), [k, E] = st({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [b, _] =
|
|
629
|
-
|
|
628
|
+
}), [b, _] = st(0), C = J(!0), R = J(!1), H = J(0);
|
|
629
|
+
nt(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
630
|
_((N) => N + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const Q = o().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
n
|
|
635
635
|
), T = Q.length, { totalHeight: $, positions: x } = It(() => {
|
|
636
|
-
const
|
|
636
|
+
const p = o.getState().getShadowMetadata(t, n) || [];
|
|
637
637
|
let N = 0;
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
N +=
|
|
638
|
+
const P = [];
|
|
639
|
+
for (let L = 0; L < T; L++) {
|
|
640
|
+
P[L] = N;
|
|
641
|
+
const B = p[L]?.virtualizer?.itemHeight;
|
|
642
|
+
N += B || r;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight: N, positions:
|
|
644
|
+
return { totalHeight: N, positions: P };
|
|
645
645
|
}, [
|
|
646
646
|
T,
|
|
647
647
|
t,
|
|
@@ -649,22 +649,22 @@ function mt(t, s, S, u) {
|
|
|
649
649
|
r,
|
|
650
650
|
b
|
|
651
651
|
]), G = It(() => {
|
|
652
|
-
const
|
|
653
|
-
{ length: N -
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return
|
|
652
|
+
const p = Math.max(0, k.startIndex), N = Math.min(T, k.endIndex), P = Array.from(
|
|
653
|
+
{ length: N - p },
|
|
654
|
+
(B, ot) => p + ot
|
|
655
|
+
), L = P.map((B) => Q[B]);
|
|
656
|
+
return s(L, n, {
|
|
657
657
|
...g,
|
|
658
|
-
validIndices:
|
|
658
|
+
validIndices: P
|
|
659
659
|
});
|
|
660
660
|
}, [k.startIndex, k.endIndex, Q, T]), A = ft(() => {
|
|
661
|
-
const
|
|
661
|
+
const p = o.getState().getShadowMetadata(t, n) || [], N = T - 1;
|
|
662
662
|
if (N >= 0) {
|
|
663
|
-
const
|
|
664
|
-
if (
|
|
665
|
-
const
|
|
666
|
-
if (
|
|
667
|
-
return
|
|
663
|
+
const P = p[N];
|
|
664
|
+
if (P?.virtualizer?.domRef) {
|
|
665
|
+
const L = P.virtualizer.domRef;
|
|
666
|
+
if (L && L.scrollIntoView)
|
|
667
|
+
return L.scrollIntoView({
|
|
668
668
|
behavior: "auto",
|
|
669
669
|
block: "end",
|
|
670
670
|
inline: "nearest"
|
|
@@ -673,78 +673,84 @@ function mt(t, s, S, u) {
|
|
|
673
673
|
}
|
|
674
674
|
return !1;
|
|
675
675
|
}, [t, n, T]);
|
|
676
|
-
|
|
676
|
+
nt(() => {
|
|
677
677
|
if (!c || T === 0) return;
|
|
678
|
-
const
|
|
679
|
-
if ((
|
|
680
|
-
const
|
|
681
|
-
(
|
|
682
|
-
),
|
|
678
|
+
const p = T > H.current, N = H.current === 0 && T > 0;
|
|
679
|
+
if ((p || N) && C.current && !R.current) {
|
|
680
|
+
const P = Math.ceil(
|
|
681
|
+
(v.current?.clientHeight || 0) / r
|
|
682
|
+
), L = {
|
|
683
683
|
startIndex: Math.max(
|
|
684
684
|
0,
|
|
685
|
-
T -
|
|
685
|
+
T - P - a
|
|
686
686
|
),
|
|
687
687
|
endIndex: T
|
|
688
688
|
};
|
|
689
|
-
|
|
690
|
-
const
|
|
691
|
-
|
|
689
|
+
E(L);
|
|
690
|
+
const B = setTimeout(() => {
|
|
691
|
+
M(T - 1, "smooth");
|
|
692
692
|
}, 50);
|
|
693
|
-
return () => clearTimeout(
|
|
693
|
+
return () => clearTimeout(B);
|
|
694
694
|
}
|
|
695
695
|
H.current = T;
|
|
696
|
-
}, [T, r, a]),
|
|
697
|
-
const
|
|
698
|
-
if (!
|
|
696
|
+
}, [T, r, a]), nt(() => {
|
|
697
|
+
const p = v.current;
|
|
698
|
+
if (!p) return;
|
|
699
699
|
const N = () => {
|
|
700
|
-
const { scrollTop:
|
|
701
|
-
|
|
702
|
-
let
|
|
700
|
+
const { scrollTop: P, scrollHeight: L, clientHeight: B } = p, ot = L - P - B;
|
|
701
|
+
C.current = ot < 5, ot > 100 && (R.current = !0), ot < 5 && (R.current = !1);
|
|
702
|
+
let et = 0;
|
|
703
703
|
for (let Z = 0; Z < x.length; Z++)
|
|
704
|
-
if (x[Z] >
|
|
705
|
-
|
|
704
|
+
if (x[Z] > P - r * a) {
|
|
705
|
+
et = Math.max(0, Z - 1);
|
|
706
706
|
break;
|
|
707
707
|
}
|
|
708
|
-
let Tt =
|
|
709
|
-
const Rt =
|
|
710
|
-
for (let Z =
|
|
708
|
+
let Tt = et;
|
|
709
|
+
const Rt = P + B;
|
|
710
|
+
for (let Z = et; Z < x.length && !(x[Z] > Rt + r * a); Z++)
|
|
711
711
|
Tt = Z;
|
|
712
|
-
|
|
713
|
-
startIndex: Math.max(0,
|
|
712
|
+
E({
|
|
713
|
+
startIndex: Math.max(0, et),
|
|
714
714
|
endIndex: Math.min(T, Tt + 1 + a)
|
|
715
715
|
});
|
|
716
716
|
};
|
|
717
|
-
if (
|
|
717
|
+
if (p.addEventListener("scroll", N, {
|
|
718
718
|
passive: !0
|
|
719
719
|
}), c && T > 0 && !R.current) {
|
|
720
|
-
const { scrollTop:
|
|
721
|
-
|
|
720
|
+
const { scrollTop: P } = p;
|
|
721
|
+
P === 0 && (p.scrollTop = p.scrollHeight, C.current = !0);
|
|
722
722
|
}
|
|
723
723
|
return N(), () => {
|
|
724
|
-
|
|
724
|
+
p.removeEventListener("scroll", N);
|
|
725
725
|
};
|
|
726
726
|
}, [x, T, r, a, c]);
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
}, [A]),
|
|
730
|
-
(
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
727
|
+
const F = ft(() => {
|
|
728
|
+
C.current = !0, R.current = !1, !A() && v.current && (v.current.scrollTop = v.current.scrollHeight);
|
|
729
|
+
}, [A]), M = ft(
|
|
730
|
+
(p, N = "smooth") => {
|
|
731
|
+
const P = v.current;
|
|
732
|
+
if (!P) return;
|
|
733
|
+
if (p === T - 1) {
|
|
734
|
+
P.scrollTo({
|
|
735
|
+
top: P.scrollHeight,
|
|
736
|
+
behavior: N
|
|
737
|
+
});
|
|
738
|
+
return;
|
|
738
739
|
}
|
|
739
|
-
|
|
740
|
-
|
|
740
|
+
const et = (o.getState().getShadowMetadata(t, n) || [])[p]?.virtualizer?.domRef;
|
|
741
|
+
et ? et.scrollIntoView({
|
|
742
|
+
behavior: N,
|
|
743
|
+
block: "center"
|
|
744
|
+
}) : x[p] !== void 0 && P.scrollTo({
|
|
745
|
+
top: x[p],
|
|
741
746
|
behavior: N
|
|
742
747
|
});
|
|
743
748
|
},
|
|
744
|
-
[x, t, n]
|
|
745
|
-
|
|
749
|
+
[x, t, n, T]
|
|
750
|
+
// Add totalCount to the dependencies
|
|
751
|
+
), z = {
|
|
746
752
|
outer: {
|
|
747
|
-
ref:
|
|
753
|
+
ref: v,
|
|
748
754
|
style: { overflowY: "auto", height: "100%" }
|
|
749
755
|
},
|
|
750
756
|
inner: {
|
|
@@ -761,50 +767,50 @@ function mt(t, s, S, u) {
|
|
|
761
767
|
};
|
|
762
768
|
return {
|
|
763
769
|
virtualState: G,
|
|
764
|
-
virtualizerProps:
|
|
765
|
-
scrollToBottom:
|
|
766
|
-
scrollToIndex:
|
|
770
|
+
virtualizerProps: z,
|
|
771
|
+
scrollToBottom: F,
|
|
772
|
+
scrollToIndex: M
|
|
767
773
|
};
|
|
768
774
|
};
|
|
769
775
|
if (l === "stateMapNoRender")
|
|
770
|
-
return (e) =>
|
|
776
|
+
return (e) => m.map((a, c) => {
|
|
771
777
|
let w;
|
|
772
778
|
g?.validIndices && g.validIndices[c] !== void 0 ? w = g.validIndices[c] : w = c;
|
|
773
|
-
const
|
|
779
|
+
const v = [...n, w.toString()], k = s(a, v, g);
|
|
774
780
|
return e(
|
|
775
781
|
a,
|
|
776
782
|
k,
|
|
777
783
|
c,
|
|
778
|
-
|
|
779
|
-
|
|
784
|
+
m,
|
|
785
|
+
s(m, n, g)
|
|
780
786
|
);
|
|
781
787
|
});
|
|
782
788
|
if (l === "$stateMap")
|
|
783
|
-
return (e) =>
|
|
789
|
+
return (e) => lt(Zt, {
|
|
784
790
|
proxy: {
|
|
785
791
|
_stateKey: t,
|
|
786
792
|
_path: n,
|
|
787
793
|
_mapFn: e
|
|
788
794
|
// Pass the actual function, not string
|
|
789
795
|
},
|
|
790
|
-
rebuildStateShape:
|
|
796
|
+
rebuildStateShape: s
|
|
791
797
|
});
|
|
792
798
|
if (l === "stateList")
|
|
793
799
|
return (e) => {
|
|
794
800
|
const r = o.getState().getNestedState(t, n);
|
|
795
801
|
return Array.isArray(r) ? (g?.validIndices || Array.from({ length: r.length }, (c, w) => w)).map((c, w) => {
|
|
796
|
-
const
|
|
797
|
-
return
|
|
802
|
+
const v = r[c], k = [...n, c.toString()], E = s(v, k, g), b = `${S}-${n.join(".")}-${c}`;
|
|
803
|
+
return lt(Qt, {
|
|
798
804
|
key: c,
|
|
799
805
|
stateKey: t,
|
|
800
806
|
itemComponentId: b,
|
|
801
807
|
itemPath: k,
|
|
802
808
|
children: e(
|
|
803
|
-
|
|
804
|
-
|
|
809
|
+
v,
|
|
810
|
+
E,
|
|
805
811
|
{ localIndex: w, originalIndex: c },
|
|
806
812
|
r,
|
|
807
|
-
|
|
813
|
+
s(r, n, g)
|
|
808
814
|
)
|
|
809
815
|
});
|
|
810
816
|
}) : (console.warn(
|
|
@@ -813,12 +819,12 @@ function mt(t, s, S, u) {
|
|
|
813
819
|
};
|
|
814
820
|
if (l === "stateFlattenOn")
|
|
815
821
|
return (e) => {
|
|
816
|
-
const r =
|
|
817
|
-
|
|
822
|
+
const r = m;
|
|
823
|
+
h.clear(), V++;
|
|
818
824
|
const a = r.flatMap(
|
|
819
825
|
(c) => c[e] ?? []
|
|
820
826
|
);
|
|
821
|
-
return
|
|
827
|
+
return s(
|
|
822
828
|
a,
|
|
823
829
|
[...n, "[*]", e],
|
|
824
830
|
g
|
|
@@ -826,78 +832,78 @@ function mt(t, s, S, u) {
|
|
|
826
832
|
};
|
|
827
833
|
if (l === "index")
|
|
828
834
|
return (e) => {
|
|
829
|
-
const r =
|
|
830
|
-
return
|
|
835
|
+
const r = m[e];
|
|
836
|
+
return s(r, [...n, e.toString()]);
|
|
831
837
|
};
|
|
832
838
|
if (l === "last")
|
|
833
839
|
return () => {
|
|
834
840
|
const e = o.getState().getNestedState(t, n);
|
|
835
841
|
if (e.length === 0) return;
|
|
836
842
|
const r = e.length - 1, a = e[r], c = [...n, r.toString()];
|
|
837
|
-
return
|
|
843
|
+
return s(a, c);
|
|
838
844
|
};
|
|
839
845
|
if (l === "insert")
|
|
840
|
-
return (e) => (I(n), vt(
|
|
846
|
+
return (e) => (I(n), vt(i, e, n, t), s(
|
|
841
847
|
o.getState().getNestedState(t, n),
|
|
842
848
|
n
|
|
843
849
|
));
|
|
844
850
|
if (l === "uniqueInsert")
|
|
845
851
|
return (e, r, a) => {
|
|
846
852
|
const c = o.getState().getNestedState(t, n), w = K(e) ? e(c) : e;
|
|
847
|
-
let
|
|
848
|
-
if (!c.some((
|
|
853
|
+
let v = null;
|
|
854
|
+
if (!c.some((E) => {
|
|
849
855
|
if (r) {
|
|
850
856
|
const _ = r.every(
|
|
851
|
-
(
|
|
857
|
+
(C) => q(E[C], w[C])
|
|
852
858
|
);
|
|
853
|
-
return _ && (
|
|
859
|
+
return _ && (v = E), _;
|
|
854
860
|
}
|
|
855
|
-
const b = q(
|
|
856
|
-
return b && (
|
|
861
|
+
const b = q(E, w);
|
|
862
|
+
return b && (v = E), b;
|
|
857
863
|
}))
|
|
858
|
-
I(n), vt(
|
|
859
|
-
else if (a &&
|
|
860
|
-
const
|
|
861
|
-
(_) => q(_,
|
|
864
|
+
I(n), vt(i, w, n, t);
|
|
865
|
+
else if (a && v) {
|
|
866
|
+
const E = a(v), b = c.map(
|
|
867
|
+
(_) => q(_, v) ? E : _
|
|
862
868
|
);
|
|
863
|
-
I(n),
|
|
869
|
+
I(n), ct(i, b, n);
|
|
864
870
|
}
|
|
865
871
|
};
|
|
866
872
|
if (l === "cut")
|
|
867
873
|
return (e, r) => {
|
|
868
874
|
if (!r?.waitForSync)
|
|
869
|
-
return I(n), gt(
|
|
875
|
+
return I(n), gt(i, n, t, e), s(
|
|
870
876
|
o.getState().getNestedState(t, n),
|
|
871
877
|
n
|
|
872
878
|
);
|
|
873
879
|
};
|
|
874
880
|
if (l === "cutByValue")
|
|
875
881
|
return (e) => {
|
|
876
|
-
for (let r = 0; r <
|
|
877
|
-
|
|
882
|
+
for (let r = 0; r < m.length; r++)
|
|
883
|
+
m[r] === e && gt(i, n, t, r);
|
|
878
884
|
};
|
|
879
885
|
if (l === "toggleByValue")
|
|
880
886
|
return (e) => {
|
|
881
|
-
const r =
|
|
882
|
-
r > -1 ? gt(
|
|
887
|
+
const r = m.findIndex((a) => a === e);
|
|
888
|
+
r > -1 ? gt(i, n, t, r) : vt(i, e, n, t);
|
|
883
889
|
};
|
|
884
890
|
if (l === "stateFind")
|
|
885
891
|
return (e) => {
|
|
886
892
|
const a = d().find(
|
|
887
|
-
({ item: w },
|
|
893
|
+
({ item: w }, v) => e(w, v)
|
|
888
894
|
);
|
|
889
895
|
if (!a) return;
|
|
890
896
|
const c = [...n, a.originalIndex.toString()];
|
|
891
|
-
return
|
|
897
|
+
return s(a.item, c, g);
|
|
892
898
|
};
|
|
893
899
|
if (l === "findWith")
|
|
894
900
|
return (e, r) => {
|
|
895
901
|
const c = d().find(
|
|
896
|
-
({ item:
|
|
902
|
+
({ item: v }) => v[e] === r
|
|
897
903
|
);
|
|
898
904
|
if (!c) return;
|
|
899
905
|
const w = [...n, c.originalIndex.toString()];
|
|
900
|
-
return
|
|
906
|
+
return s(c.item, w, g);
|
|
901
907
|
};
|
|
902
908
|
}
|
|
903
909
|
const tt = n[n.length - 1];
|
|
@@ -905,7 +911,7 @@ function mt(t, s, S, u) {
|
|
|
905
911
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
906
912
|
if (Array.isArray(e) && l === "cut")
|
|
907
913
|
return () => gt(
|
|
908
|
-
|
|
914
|
+
i,
|
|
909
915
|
d,
|
|
910
916
|
t,
|
|
911
917
|
Number(tt)
|
|
@@ -913,7 +919,7 @@ function mt(t, s, S, u) {
|
|
|
913
919
|
}
|
|
914
920
|
if (l === "get")
|
|
915
921
|
return () => {
|
|
916
|
-
if (g?.validIndices && Array.isArray(
|
|
922
|
+
if (g?.validIndices && Array.isArray(m)) {
|
|
917
923
|
const d = o.getState().getNestedState(t, n);
|
|
918
924
|
return g.validIndices.map((e) => d[e]);
|
|
919
925
|
}
|
|
@@ -945,7 +951,7 @@ function mt(t, s, S, u) {
|
|
|
945
951
|
const e = n.slice(0, -1), r = Number(n[n.length - 1]), a = e.join(".");
|
|
946
952
|
d ? o.getState().setSelectedIndex(t, a, r) : o.getState().setSelectedIndex(t, a, void 0);
|
|
947
953
|
const c = o.getState().getNestedState(t, [...e]);
|
|
948
|
-
|
|
954
|
+
ct(i, c, e), I(e);
|
|
949
955
|
};
|
|
950
956
|
if (l === "toggleSelected")
|
|
951
957
|
return () => {
|
|
@@ -956,7 +962,7 @@ function mt(t, s, S, u) {
|
|
|
956
962
|
a === e ? void 0 : e
|
|
957
963
|
);
|
|
958
964
|
const c = o.getState().getNestedState(t, [...d]);
|
|
959
|
-
|
|
965
|
+
ct(i, c, d), I(d);
|
|
960
966
|
};
|
|
961
967
|
if (n.length == 0) {
|
|
962
968
|
if (l === "addValidation")
|
|
@@ -967,7 +973,7 @@ function mt(t, s, S, u) {
|
|
|
967
973
|
X(e.key), console.log("addValidationError", d), d.forEach((r) => {
|
|
968
974
|
const a = [e.key, ...r.path].join(".");
|
|
969
975
|
console.log("fullErrorPath", a), Ct(a, r.message);
|
|
970
|
-
}),
|
|
976
|
+
}), dt(t);
|
|
971
977
|
};
|
|
972
978
|
if (l === "applyJsonPatch")
|
|
973
979
|
return (d) => {
|
|
@@ -976,38 +982,38 @@ function mt(t, s, S, u) {
|
|
|
976
982
|
t,
|
|
977
983
|
o.getState().initialStateGlobal[t],
|
|
978
984
|
a,
|
|
979
|
-
|
|
985
|
+
i,
|
|
980
986
|
S,
|
|
981
987
|
u
|
|
982
988
|
);
|
|
983
989
|
const c = o.getState().stateComponents.get(t);
|
|
984
990
|
if (c) {
|
|
985
|
-
const w = wt(e, a),
|
|
991
|
+
const w = wt(e, a), v = new Set(w);
|
|
986
992
|
for (const [
|
|
987
993
|
k,
|
|
988
|
-
|
|
994
|
+
E
|
|
989
995
|
] of c.components.entries()) {
|
|
990
996
|
let b = !1;
|
|
991
|
-
const _ = Array.isArray(
|
|
997
|
+
const _ = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
992
998
|
if (!_.includes("none")) {
|
|
993
999
|
if (_.includes("all")) {
|
|
994
|
-
|
|
1000
|
+
E.forceUpdate();
|
|
995
1001
|
continue;
|
|
996
1002
|
}
|
|
997
|
-
if (_.includes("component") && (
|
|
998
|
-
for (const
|
|
999
|
-
if (
|
|
1003
|
+
if (_.includes("component") && (E.paths.has("") && (b = !0), !b))
|
|
1004
|
+
for (const C of v) {
|
|
1005
|
+
if (E.paths.has(C)) {
|
|
1000
1006
|
b = !0;
|
|
1001
1007
|
break;
|
|
1002
1008
|
}
|
|
1003
|
-
let R =
|
|
1009
|
+
let R = C.lastIndexOf(".");
|
|
1004
1010
|
for (; R !== -1; ) {
|
|
1005
|
-
const H =
|
|
1006
|
-
if (
|
|
1011
|
+
const H = C.substring(0, R);
|
|
1012
|
+
if (E.paths.has(H)) {
|
|
1007
1013
|
b = !0;
|
|
1008
1014
|
break;
|
|
1009
1015
|
}
|
|
1010
|
-
const Q =
|
|
1016
|
+
const Q = C.substring(
|
|
1011
1017
|
R + 1
|
|
1012
1018
|
);
|
|
1013
1019
|
if (!isNaN(Number(Q))) {
|
|
@@ -1017,7 +1023,7 @@ function mt(t, s, S, u) {
|
|
|
1017
1023
|
0,
|
|
1018
1024
|
T
|
|
1019
1025
|
);
|
|
1020
|
-
if (
|
|
1026
|
+
if (E.paths.has($)) {
|
|
1021
1027
|
b = !0;
|
|
1022
1028
|
break;
|
|
1023
1029
|
}
|
|
@@ -1027,12 +1033,12 @@ function mt(t, s, S, u) {
|
|
|
1027
1033
|
}
|
|
1028
1034
|
if (b) break;
|
|
1029
1035
|
}
|
|
1030
|
-
if (!b && _.includes("deps") &&
|
|
1031
|
-
const
|
|
1036
|
+
if (!b && _.includes("deps") && E.depsFunction) {
|
|
1037
|
+
const C = E.depsFunction(a);
|
|
1032
1038
|
let R = !1;
|
|
1033
|
-
typeof
|
|
1039
|
+
typeof C == "boolean" ? C && (R = !0) : q(E.deps, C) || (E.deps = C, R = !0), R && (b = !0);
|
|
1034
1040
|
}
|
|
1035
|
-
b &&
|
|
1041
|
+
b && E.forceUpdate();
|
|
1036
1042
|
}
|
|
1037
1043
|
}
|
|
1038
1044
|
}
|
|
@@ -1052,10 +1058,10 @@ function mt(t, s, S, u) {
|
|
|
1052
1058
|
w && w.startsWith(d.key) && X(w);
|
|
1053
1059
|
});
|
|
1054
1060
|
const c = d.zodSchema.safeParse(r);
|
|
1055
|
-
return c.success ? !0 : (c.error.errors.forEach((
|
|
1056
|
-
const k =
|
|
1057
|
-
e(b,
|
|
1058
|
-
}),
|
|
1061
|
+
return c.success ? !0 : (c.error.errors.forEach((v) => {
|
|
1062
|
+
const k = v.path, E = v.message, b = [d.key, ...k].join(".");
|
|
1063
|
+
e(b, E);
|
|
1064
|
+
}), dt(t), !1);
|
|
1059
1065
|
} catch (a) {
|
|
1060
1066
|
return console.error("Zod schema validation failed", a), !1;
|
|
1061
1067
|
}
|
|
@@ -1100,12 +1106,12 @@ function mt(t, s, S, u) {
|
|
|
1100
1106
|
return (d, e) => {
|
|
1101
1107
|
if (e?.debounce)
|
|
1102
1108
|
Ut(() => {
|
|
1103
|
-
|
|
1109
|
+
ct(i, d, n, "");
|
|
1104
1110
|
const r = o.getState().getNestedState(t, n);
|
|
1105
1111
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1106
1112
|
}, e.debounce);
|
|
1107
1113
|
else {
|
|
1108
|
-
|
|
1114
|
+
ct(i, d, n, "");
|
|
1109
1115
|
const r = o.getState().getNestedState(t, n);
|
|
1110
1116
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1111
1117
|
}
|
|
@@ -1115,58 +1121,58 @@ function mt(t, s, S, u) {
|
|
|
1115
1121
|
return (d, e) => /* @__PURE__ */ yt(
|
|
1116
1122
|
Dt,
|
|
1117
1123
|
{
|
|
1118
|
-
setState:
|
|
1124
|
+
setState: i,
|
|
1119
1125
|
stateKey: t,
|
|
1120
1126
|
path: n,
|
|
1121
1127
|
child: d,
|
|
1122
1128
|
formOpts: e
|
|
1123
1129
|
}
|
|
1124
1130
|
);
|
|
1125
|
-
const
|
|
1126
|
-
return
|
|
1131
|
+
const O = [...n, l], it = o.getState().getNestedState(t, O);
|
|
1132
|
+
return s(it, O, g);
|
|
1127
1133
|
}
|
|
1128
|
-
},
|
|
1129
|
-
return
|
|
1130
|
-
proxy:
|
|
1134
|
+
}, W = new Proxy(j, U);
|
|
1135
|
+
return h.set(D, {
|
|
1136
|
+
proxy: W,
|
|
1131
1137
|
stateVersion: V
|
|
1132
|
-
}),
|
|
1138
|
+
}), W;
|
|
1133
1139
|
}
|
|
1134
|
-
return
|
|
1140
|
+
return s(
|
|
1135
1141
|
o.getState().getNestedState(t, [])
|
|
1136
1142
|
);
|
|
1137
1143
|
}
|
|
1138
1144
|
function $t(t) {
|
|
1139
|
-
return
|
|
1145
|
+
return lt(Xt, { proxy: t });
|
|
1140
1146
|
}
|
|
1141
1147
|
function Zt({
|
|
1142
1148
|
proxy: t,
|
|
1143
|
-
rebuildStateShape:
|
|
1149
|
+
rebuildStateShape: i
|
|
1144
1150
|
}) {
|
|
1145
1151
|
const S = o().getNestedState(t._stateKey, t._path);
|
|
1146
|
-
return Array.isArray(S) ?
|
|
1152
|
+
return Array.isArray(S) ? i(
|
|
1147
1153
|
S,
|
|
1148
1154
|
t._path
|
|
1149
1155
|
).stateMapNoRender(
|
|
1150
|
-
(
|
|
1156
|
+
(h, V, I, y, s) => t._mapFn(h, V, I, y, s)
|
|
1151
1157
|
) : null;
|
|
1152
1158
|
}
|
|
1153
1159
|
function Xt({
|
|
1154
1160
|
proxy: t
|
|
1155
1161
|
}) {
|
|
1156
|
-
const
|
|
1157
|
-
return
|
|
1158
|
-
const u =
|
|
1162
|
+
const i = J(null), S = `${t._stateKey}-${t._path.join(".")}`;
|
|
1163
|
+
return nt(() => {
|
|
1164
|
+
const u = i.current;
|
|
1159
1165
|
if (!u || !u.parentElement) return;
|
|
1160
|
-
const
|
|
1161
|
-
let y =
|
|
1162
|
-
y || (y = `parent-${crypto.randomUUID()}`,
|
|
1163
|
-
const
|
|
1166
|
+
const h = u.parentElement, I = Array.from(h.childNodes).indexOf(u);
|
|
1167
|
+
let y = h.getAttribute("data-parent-id");
|
|
1168
|
+
y || (y = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", y));
|
|
1169
|
+
const m = {
|
|
1164
1170
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1165
1171
|
parentId: y,
|
|
1166
1172
|
position: I,
|
|
1167
1173
|
effect: t._effect
|
|
1168
1174
|
};
|
|
1169
|
-
o.getState().addSignalElement(S,
|
|
1175
|
+
o.getState().addSignalElement(S, m);
|
|
1170
1176
|
const n = o.getState().getNestedState(t._stateKey, t._path);
|
|
1171
1177
|
let g;
|
|
1172
1178
|
if (t._effect)
|
|
@@ -1175,22 +1181,22 @@ function Xt({
|
|
|
1175
1181
|
"state",
|
|
1176
1182
|
`return (${t._effect})(state)`
|
|
1177
1183
|
)(n);
|
|
1178
|
-
} catch (
|
|
1179
|
-
console.error("Error evaluating effect function during mount:",
|
|
1184
|
+
} catch (j) {
|
|
1185
|
+
console.error("Error evaluating effect function during mount:", j), g = n;
|
|
1180
1186
|
}
|
|
1181
1187
|
else
|
|
1182
1188
|
g = n;
|
|
1183
1189
|
g !== null && typeof g == "object" && (g = JSON.stringify(g));
|
|
1184
|
-
const
|
|
1185
|
-
u.replaceWith(
|
|
1186
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1187
|
-
ref:
|
|
1190
|
+
const D = document.createTextNode(String(g));
|
|
1191
|
+
u.replaceWith(D);
|
|
1192
|
+
}, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
|
|
1193
|
+
ref: i,
|
|
1188
1194
|
style: { display: "none" },
|
|
1189
1195
|
"data-signal-id": S
|
|
1190
1196
|
});
|
|
1191
1197
|
}
|
|
1192
1198
|
function fe(t) {
|
|
1193
|
-
const
|
|
1199
|
+
const i = Mt(
|
|
1194
1200
|
(S) => {
|
|
1195
1201
|
const u = o.getState().stateComponents.get(t._stateKey) || {
|
|
1196
1202
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1202,22 +1208,22 @@ function fe(t) {
|
|
|
1202
1208
|
},
|
|
1203
1209
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1204
1210
|
);
|
|
1205
|
-
return
|
|
1211
|
+
return lt("text", {}, String(i));
|
|
1206
1212
|
}
|
|
1207
1213
|
function Qt({
|
|
1208
1214
|
stateKey: t,
|
|
1209
|
-
itemComponentId:
|
|
1215
|
+
itemComponentId: i,
|
|
1210
1216
|
itemPath: S,
|
|
1211
1217
|
children: u
|
|
1212
1218
|
}) {
|
|
1213
|
-
const [,
|
|
1219
|
+
const [, h] = st({}), [V, I] = Wt(), y = J(null), s = J(null), m = ft(
|
|
1214
1220
|
(n) => {
|
|
1215
1221
|
V(n), y.current = n;
|
|
1216
1222
|
},
|
|
1217
1223
|
[V]
|
|
1218
1224
|
);
|
|
1219
|
-
return
|
|
1220
|
-
I.height > 0 && I.height !==
|
|
1225
|
+
return nt(() => {
|
|
1226
|
+
I.height > 0 && I.height !== s.current && (s.current = I.height, o.getState().setShadowMetadata(t, S, {
|
|
1221
1227
|
virtualizer: {
|
|
1222
1228
|
itemHeight: I.height,
|
|
1223
1229
|
domRef: y.current
|
|
@@ -1225,17 +1231,17 @@ function Qt({
|
|
|
1225
1231
|
}
|
|
1226
1232
|
}));
|
|
1227
1233
|
}, [I.height, t, S]), xt(() => {
|
|
1228
|
-
const n = `${t}////${
|
|
1234
|
+
const n = `${t}////${i}`, g = o.getState().stateComponents.get(t) || {
|
|
1229
1235
|
components: /* @__PURE__ */ new Map()
|
|
1230
1236
|
};
|
|
1231
1237
|
return g.components.set(n, {
|
|
1232
|
-
forceUpdate: () =>
|
|
1238
|
+
forceUpdate: () => h({}),
|
|
1233
1239
|
paths: /* @__PURE__ */ new Set([S.join(".")])
|
|
1234
1240
|
}), o.getState().stateComponents.set(t, g), () => {
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1241
|
+
const D = o.getState().stateComponents.get(t);
|
|
1242
|
+
D && D.components.delete(n);
|
|
1237
1243
|
};
|
|
1238
|
-
}, [t,
|
|
1244
|
+
}, [t, i, S.join(".")]), /* @__PURE__ */ yt("div", { ref: m, children: u });
|
|
1239
1245
|
}
|
|
1240
1246
|
export {
|
|
1241
1247
|
$t as $cogsSignal,
|