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