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