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