cogsbox-state 0.5.283 → 0.5.285
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 +470 -452
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +75 -38
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,140 @@ 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.getState().getNestedState(t, n);
|
|
633
|
+
let b = 0;
|
|
634
|
+
const G = [];
|
|
635
|
+
for (let z = 0; z < $.length; z++)
|
|
636
|
+
G[z] = b, b += w(z);
|
|
637
|
+
return { totalHeight: b, positions: G };
|
|
638
|
+
}, [w]), V = Z(i), C = Z(0), x = Z(!0), U = o().getNestedState(
|
|
630
639
|
t,
|
|
631
|
-
|
|
632
|
-
),
|
|
633
|
-
const
|
|
634
|
-
{ length:
|
|
635
|
-
(
|
|
636
|
-
),
|
|
637
|
-
return a(
|
|
640
|
+
n
|
|
641
|
+
), D = U.length, P = xt(() => {
|
|
642
|
+
const $ = Math.max(0, u.startIndex), b = Math.min(D, u.endIndex), G = Array.from(
|
|
643
|
+
{ length: b - $ },
|
|
644
|
+
(K, st) => $ + st
|
|
645
|
+
), z = G.map((K) => U[K]);
|
|
646
|
+
return a(z, n, {
|
|
638
647
|
...S,
|
|
639
|
-
validIndices:
|
|
648
|
+
validIndices: G
|
|
640
649
|
});
|
|
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
|
-
|
|
650
|
+
}, [u.startIndex, u.endIndex, U, D]);
|
|
651
|
+
ft(() => {
|
|
652
|
+
const $ = g.current;
|
|
653
|
+
if (!$) return;
|
|
654
|
+
const b = V.current, G = D > C.current;
|
|
655
|
+
C.current = D;
|
|
656
|
+
const { totalHeight: z, positions: K } = A(), st = () => {
|
|
657
|
+
const { scrollTop: vt, clientHeight: $t, scrollHeight: jt } = $;
|
|
658
|
+
V.current = jt - vt - $t < 10;
|
|
659
|
+
let J = 0, It = K.length - 1;
|
|
660
|
+
for (; J < It; ) {
|
|
661
|
+
const et = Math.floor((J + It) / 2);
|
|
662
|
+
K[et] < vt ? J = et + 1 : It = et;
|
|
663
|
+
}
|
|
664
|
+
J = Math.max(0, J - s);
|
|
665
|
+
const Ot = vt + $t;
|
|
666
|
+
let tt = J;
|
|
667
|
+
for (; tt < K.length && K[tt] < Ot; )
|
|
668
|
+
tt++;
|
|
669
|
+
tt = Math.min(D, tt + s), E((et) => et.startIndex !== J || et.endIndex !== tt ? { startIndex: J, endIndex: tt } : et);
|
|
658
670
|
};
|
|
659
|
-
return
|
|
671
|
+
return $.addEventListener("scroll", st, {
|
|
660
672
|
passive: !0
|
|
661
|
-
}), i && (x.current ?
|
|
662
|
-
top:
|
|
673
|
+
}), i && (x.current ? $.scrollTo({
|
|
674
|
+
top: $.scrollHeight,
|
|
663
675
|
behavior: "auto"
|
|
664
|
-
}) :
|
|
665
|
-
|
|
666
|
-
top:
|
|
676
|
+
}) : b && G && requestAnimationFrame(() => {
|
|
677
|
+
$.scrollTo({
|
|
678
|
+
top: $.scrollHeight,
|
|
667
679
|
behavior: "smooth"
|
|
668
680
|
});
|
|
669
|
-
})), x.current = !1,
|
|
670
|
-
}, [
|
|
671
|
-
const
|
|
672
|
-
(
|
|
681
|
+
})), x.current = !1, st(), () => $.removeEventListener("scroll", st);
|
|
682
|
+
}, [D, A, s, i]);
|
|
683
|
+
const N = dt(
|
|
684
|
+
($ = "smooth") => {
|
|
673
685
|
g.current && g.current.scrollTo({
|
|
674
686
|
top: g.current.scrollHeight,
|
|
675
|
-
behavior:
|
|
687
|
+
behavior: $
|
|
676
688
|
});
|
|
677
689
|
},
|
|
678
690
|
[]
|
|
679
|
-
), M =
|
|
680
|
-
(
|
|
681
|
-
g.current
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
691
|
+
), M = dt(
|
|
692
|
+
($, b = "smooth") => {
|
|
693
|
+
if (g.current) {
|
|
694
|
+
const { positions: G } = A();
|
|
695
|
+
g.current.scrollTo({
|
|
696
|
+
top: G[$] || 0,
|
|
697
|
+
behavior: b
|
|
698
|
+
});
|
|
699
|
+
}
|
|
685
700
|
},
|
|
686
|
-
[
|
|
687
|
-
),
|
|
701
|
+
[A]
|
|
702
|
+
), {
|
|
703
|
+
totalHeight: W,
|
|
704
|
+
positions: T
|
|
705
|
+
} = A(), F = T[u.startIndex] || 0, j = {
|
|
688
706
|
outer: {
|
|
689
707
|
ref: g,
|
|
690
708
|
style: { overflowY: "auto", height: "100%" }
|
|
691
709
|
},
|
|
692
710
|
inner: {
|
|
693
711
|
style: {
|
|
694
|
-
height: `${
|
|
712
|
+
height: `${W}px`,
|
|
695
713
|
position: "relative"
|
|
696
714
|
}
|
|
697
715
|
},
|
|
698
716
|
list: {
|
|
699
717
|
style: {
|
|
700
|
-
transform: `translateY(${
|
|
718
|
+
transform: `translateY(${F}px)`
|
|
701
719
|
}
|
|
702
720
|
}
|
|
703
721
|
};
|
|
704
722
|
return {
|
|
705
|
-
virtualState:
|
|
706
|
-
virtualizerProps:
|
|
707
|
-
scrollToBottom:
|
|
723
|
+
virtualState: P,
|
|
724
|
+
virtualizerProps: j,
|
|
725
|
+
scrollToBottom: N,
|
|
708
726
|
scrollToIndex: M
|
|
709
727
|
};
|
|
710
728
|
};
|
|
@@ -718,7 +736,7 @@ function lt(t, c, h, f) {
|
|
|
718
736
|
({ originalIndex: u }) => u
|
|
719
737
|
)
|
|
720
738
|
};
|
|
721
|
-
return a(i,
|
|
739
|
+
return a(i, n, g);
|
|
722
740
|
};
|
|
723
741
|
if (l === "stateFilter")
|
|
724
742
|
return (e) => {
|
|
@@ -730,26 +748,26 @@ function lt(t, c, h, f) {
|
|
|
730
748
|
({ originalIndex: u }) => u
|
|
731
749
|
)
|
|
732
750
|
};
|
|
733
|
-
return a(i,
|
|
751
|
+
return a(i, n, g);
|
|
734
752
|
};
|
|
735
753
|
if (l === "stateMap")
|
|
736
754
|
return (e) => {
|
|
737
|
-
const
|
|
738
|
-
return Array.isArray(
|
|
739
|
-
const u =
|
|
755
|
+
const r = o.getState().getNestedState(t, n);
|
|
756
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
757
|
+
const u = r[i], E = [...n, i.toString()], w = a(u, E, S);
|
|
740
758
|
return e(u, w, {
|
|
741
759
|
register: () => {
|
|
742
|
-
const [,
|
|
743
|
-
|
|
744
|
-
const
|
|
760
|
+
const [, V] = ot({}), C = `${h}-${n.join(".")}-${i}`;
|
|
761
|
+
ft(() => {
|
|
762
|
+
const x = `${t}////${C}`, U = o.getState().stateComponents.get(t) || {
|
|
745
763
|
components: /* @__PURE__ */ new Map()
|
|
746
764
|
};
|
|
747
|
-
return
|
|
748
|
-
forceUpdate: () =>
|
|
765
|
+
return U.components.set(x, {
|
|
766
|
+
forceUpdate: () => V({}),
|
|
749
767
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
750
|
-
}), o.getState().stateComponents.set(t,
|
|
751
|
-
const
|
|
752
|
-
|
|
768
|
+
}), o.getState().stateComponents.set(t, U), () => {
|
|
769
|
+
const D = o.getState().stateComponents.get(t);
|
|
770
|
+
D && D.components.delete(x);
|
|
753
771
|
};
|
|
754
772
|
}, [t, C]);
|
|
755
773
|
},
|
|
@@ -757,28 +775,28 @@ function lt(t, c, h, f) {
|
|
|
757
775
|
originalIndex: i
|
|
758
776
|
});
|
|
759
777
|
}) : (console.warn(
|
|
760
|
-
`stateMap called on a non-array value at path: ${
|
|
761
|
-
|
|
778
|
+
`stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
|
|
779
|
+
r
|
|
762
780
|
), null);
|
|
763
781
|
};
|
|
764
782
|
if (l === "stateMapNoRender")
|
|
765
783
|
return (e) => y.map((s, i) => {
|
|
766
784
|
let g;
|
|
767
785
|
S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
|
|
768
|
-
const u = [...
|
|
786
|
+
const u = [...n, g.toString()], E = a(s, u, S);
|
|
769
787
|
return e(
|
|
770
788
|
s,
|
|
771
789
|
E,
|
|
772
790
|
i,
|
|
773
791
|
y,
|
|
774
|
-
a(y,
|
|
792
|
+
a(y, n, S)
|
|
775
793
|
);
|
|
776
794
|
});
|
|
777
795
|
if (l === "$stateMap")
|
|
778
|
-
return (e) =>
|
|
796
|
+
return (e) => ct(Kt, {
|
|
779
797
|
proxy: {
|
|
780
798
|
_stateKey: t,
|
|
781
|
-
_path:
|
|
799
|
+
_path: n,
|
|
782
800
|
_mapFn: e
|
|
783
801
|
// Pass the actual function, not string
|
|
784
802
|
},
|
|
@@ -786,95 +804,95 @@ function lt(t, c, h, f) {
|
|
|
786
804
|
});
|
|
787
805
|
if (l === "stateList")
|
|
788
806
|
return (e) => {
|
|
789
|
-
const
|
|
790
|
-
return Array.isArray(
|
|
791
|
-
const u =
|
|
792
|
-
return
|
|
807
|
+
const r = o.getState().getNestedState(t, n);
|
|
808
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
809
|
+
const u = r[i], E = [...n, i.toString()], w = a(u, E, S), A = `${h}-${n.join(".")}-${i}`;
|
|
810
|
+
return ct(ee, {
|
|
793
811
|
key: i,
|
|
794
812
|
stateKey: t,
|
|
795
|
-
itemComponentId:
|
|
813
|
+
itemComponentId: A,
|
|
796
814
|
itemPath: E,
|
|
797
815
|
children: e(
|
|
798
816
|
u,
|
|
799
817
|
w,
|
|
800
818
|
g,
|
|
801
|
-
|
|
802
|
-
a(
|
|
819
|
+
r,
|
|
820
|
+
a(r, n, S)
|
|
803
821
|
)
|
|
804
822
|
});
|
|
805
823
|
}) : (console.warn(
|
|
806
|
-
`stateList called on a non-array value at path: ${
|
|
824
|
+
`stateList called on a non-array value at path: ${n.join(".")}.`
|
|
807
825
|
), null);
|
|
808
826
|
};
|
|
809
827
|
if (l === "stateFlattenOn")
|
|
810
828
|
return (e) => {
|
|
811
|
-
const
|
|
829
|
+
const r = y;
|
|
812
830
|
v.clear(), k++;
|
|
813
|
-
const s =
|
|
831
|
+
const s = r.flatMap(
|
|
814
832
|
(i) => i[e] ?? []
|
|
815
833
|
);
|
|
816
834
|
return a(
|
|
817
835
|
s,
|
|
818
|
-
[...
|
|
836
|
+
[...n, "[*]", e],
|
|
819
837
|
S
|
|
820
838
|
);
|
|
821
839
|
};
|
|
822
840
|
if (l === "index")
|
|
823
841
|
return (e) => {
|
|
824
|
-
const
|
|
825
|
-
return a(
|
|
842
|
+
const r = y[e];
|
|
843
|
+
return a(r, [...n, e.toString()]);
|
|
826
844
|
};
|
|
827
845
|
if (l === "last")
|
|
828
846
|
return () => {
|
|
829
|
-
const e = o.getState().getNestedState(t,
|
|
847
|
+
const e = o.getState().getNestedState(t, n);
|
|
830
848
|
if (e.length === 0) return;
|
|
831
|
-
const
|
|
849
|
+
const r = e.length - 1, s = e[r], i = [...n, r.toString()];
|
|
832
850
|
return a(s, i);
|
|
833
851
|
};
|
|
834
852
|
if (l === "insert")
|
|
835
|
-
return (e) => (p(
|
|
836
|
-
o.getState().getNestedState(t,
|
|
837
|
-
|
|
853
|
+
return (e) => (p(n), pt(c, e, n, t), a(
|
|
854
|
+
o.getState().getNestedState(t, n),
|
|
855
|
+
n
|
|
838
856
|
));
|
|
839
857
|
if (l === "uniqueInsert")
|
|
840
|
-
return (e,
|
|
841
|
-
const i = o.getState().getNestedState(t,
|
|
858
|
+
return (e, r, s) => {
|
|
859
|
+
const i = o.getState().getNestedState(t, n), g = X(e) ? e(i) : e;
|
|
842
860
|
let u = null;
|
|
843
861
|
if (!i.some((w) => {
|
|
844
|
-
if (
|
|
845
|
-
const
|
|
846
|
-
(C) =>
|
|
862
|
+
if (r) {
|
|
863
|
+
const V = r.every(
|
|
864
|
+
(C) => B(w[C], g[C])
|
|
847
865
|
);
|
|
848
|
-
return
|
|
866
|
+
return V && (u = w), V;
|
|
849
867
|
}
|
|
850
|
-
const
|
|
851
|
-
return
|
|
868
|
+
const A = B(w, g);
|
|
869
|
+
return A && (u = w), A;
|
|
852
870
|
}))
|
|
853
|
-
p(
|
|
871
|
+
p(n), pt(c, g, n, t);
|
|
854
872
|
else if (s && u) {
|
|
855
|
-
const w = s(u),
|
|
856
|
-
(
|
|
873
|
+
const w = s(u), A = i.map(
|
|
874
|
+
(V) => B(V, u) ? w : V
|
|
857
875
|
);
|
|
858
|
-
p(
|
|
876
|
+
p(n), it(c, A, n);
|
|
859
877
|
}
|
|
860
878
|
};
|
|
861
879
|
if (l === "cut")
|
|
862
|
-
return (e,
|
|
863
|
-
if (!
|
|
864
|
-
return p(
|
|
865
|
-
o.getState().getNestedState(t,
|
|
866
|
-
|
|
880
|
+
return (e, r) => {
|
|
881
|
+
if (!r?.waitForSync)
|
|
882
|
+
return p(n), ut(c, n, t, e), a(
|
|
883
|
+
o.getState().getNestedState(t, n),
|
|
884
|
+
n
|
|
867
885
|
);
|
|
868
886
|
};
|
|
869
887
|
if (l === "cutByValue")
|
|
870
888
|
return (e) => {
|
|
871
|
-
for (let
|
|
872
|
-
y[
|
|
889
|
+
for (let r = 0; r < y.length; r++)
|
|
890
|
+
y[r] === e && ut(c, n, t, r);
|
|
873
891
|
};
|
|
874
892
|
if (l === "toggleByValue")
|
|
875
893
|
return (e) => {
|
|
876
|
-
const
|
|
877
|
-
|
|
894
|
+
const r = y.findIndex((s) => s === e);
|
|
895
|
+
r > -1 ? ut(c, n, t, r) : pt(c, e, n, t);
|
|
878
896
|
};
|
|
879
897
|
if (l === "stateFind")
|
|
880
898
|
return (e) => {
|
|
@@ -882,82 +900,82 @@ function lt(t, c, h, f) {
|
|
|
882
900
|
({ item: g }, u) => e(g, u)
|
|
883
901
|
);
|
|
884
902
|
if (!s) return;
|
|
885
|
-
const i = [...
|
|
903
|
+
const i = [...n, s.originalIndex.toString()];
|
|
886
904
|
return a(s.item, i, S);
|
|
887
905
|
};
|
|
888
906
|
if (l === "findWith")
|
|
889
|
-
return (e,
|
|
907
|
+
return (e, r) => {
|
|
890
908
|
const i = d().find(
|
|
891
|
-
({ item: u }) => u[e] ===
|
|
909
|
+
({ item: u }) => u[e] === r
|
|
892
910
|
);
|
|
893
911
|
if (!i) return;
|
|
894
|
-
const g = [...
|
|
912
|
+
const g = [...n, i.originalIndex.toString()];
|
|
895
913
|
return a(i.item, g, S);
|
|
896
914
|
};
|
|
897
915
|
}
|
|
898
|
-
const
|
|
899
|
-
if (!isNaN(Number(
|
|
900
|
-
const d =
|
|
916
|
+
const Q = n[n.length - 1];
|
|
917
|
+
if (!isNaN(Number(Q))) {
|
|
918
|
+
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
901
919
|
if (Array.isArray(e) && l === "cut")
|
|
902
|
-
return () =>
|
|
920
|
+
return () => ut(
|
|
903
921
|
c,
|
|
904
922
|
d,
|
|
905
923
|
t,
|
|
906
|
-
Number(
|
|
924
|
+
Number(Q)
|
|
907
925
|
);
|
|
908
926
|
}
|
|
909
927
|
if (l === "get")
|
|
910
928
|
return () => {
|
|
911
929
|
if (S?.validIndices && Array.isArray(y)) {
|
|
912
|
-
const d = o.getState().getNestedState(t,
|
|
930
|
+
const d = o.getState().getNestedState(t, n);
|
|
913
931
|
return S.validIndices.map((e) => d[e]);
|
|
914
932
|
}
|
|
915
|
-
return o.getState().getNestedState(t,
|
|
933
|
+
return o.getState().getNestedState(t, n);
|
|
916
934
|
};
|
|
917
935
|
if (l === "$derive")
|
|
918
|
-
return (d) =>
|
|
936
|
+
return (d) => Vt({
|
|
919
937
|
_stateKey: t,
|
|
920
|
-
_path:
|
|
938
|
+
_path: n,
|
|
921
939
|
_effect: d.toString()
|
|
922
940
|
});
|
|
923
941
|
if (l === "$get")
|
|
924
|
-
return () =>
|
|
942
|
+
return () => Vt({
|
|
925
943
|
_stateKey: t,
|
|
926
|
-
_path:
|
|
944
|
+
_path: n
|
|
927
945
|
});
|
|
928
946
|
if (l === "lastSynced") {
|
|
929
|
-
const d = `${t}:${
|
|
947
|
+
const d = `${t}:${n.join(".")}`;
|
|
930
948
|
return o.getState().getSyncInfo(d);
|
|
931
949
|
}
|
|
932
950
|
if (l == "getLocalStorage")
|
|
933
|
-
return (d) =>
|
|
951
|
+
return (d) => ht(f + "-" + t + "-" + d);
|
|
934
952
|
if (l === "_selected") {
|
|
935
|
-
const d =
|
|
936
|
-
return Array.isArray(
|
|
953
|
+
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
954
|
+
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
937
955
|
}
|
|
938
956
|
if (l === "setSelected")
|
|
939
957
|
return (d) => {
|
|
940
|
-
const e =
|
|
941
|
-
d ? o.getState().setSelectedIndex(t, s,
|
|
958
|
+
const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
|
|
959
|
+
d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
|
|
942
960
|
const i = o.getState().getNestedState(t, [...e]);
|
|
943
|
-
|
|
961
|
+
it(c, i, e), p(e);
|
|
944
962
|
};
|
|
945
963
|
if (l === "toggleSelected")
|
|
946
964
|
return () => {
|
|
947
|
-
const d =
|
|
965
|
+
const d = n.slice(0, -1), e = Number(n[n.length - 1]), r = d.join("."), s = o.getState().getSelectedIndex(t, r);
|
|
948
966
|
o.getState().setSelectedIndex(
|
|
949
967
|
t,
|
|
950
|
-
|
|
968
|
+
r,
|
|
951
969
|
s === e ? void 0 : e
|
|
952
970
|
);
|
|
953
971
|
const i = o.getState().getNestedState(t, [...d]);
|
|
954
|
-
|
|
972
|
+
it(c, i, d), p(d);
|
|
955
973
|
};
|
|
956
|
-
if (
|
|
974
|
+
if (n.length == 0) {
|
|
957
975
|
if (l === "applyJsonPatch")
|
|
958
976
|
return (d) => {
|
|
959
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
960
|
-
|
|
977
|
+
const e = o.getState().cogsStateStore[t], s = Ht(e, d).newDocument;
|
|
978
|
+
Mt(
|
|
961
979
|
t,
|
|
962
980
|
o.getState().initialStateGlobal[t],
|
|
963
981
|
s,
|
|
@@ -967,57 +985,57 @@ function lt(t, c, h, f) {
|
|
|
967
985
|
);
|
|
968
986
|
const i = o.getState().stateComponents.get(t);
|
|
969
987
|
if (i) {
|
|
970
|
-
const g =
|
|
988
|
+
const g = Et(e, s), u = new Set(g);
|
|
971
989
|
for (const [
|
|
972
990
|
E,
|
|
973
991
|
w
|
|
974
992
|
] of i.components.entries()) {
|
|
975
|
-
let
|
|
976
|
-
const
|
|
977
|
-
if (!
|
|
978
|
-
if (
|
|
993
|
+
let A = !1;
|
|
994
|
+
const V = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
995
|
+
if (!V.includes("none")) {
|
|
996
|
+
if (V.includes("all")) {
|
|
979
997
|
w.forceUpdate();
|
|
980
998
|
continue;
|
|
981
999
|
}
|
|
982
|
-
if (
|
|
1000
|
+
if (V.includes("component") && (w.paths.has("") && (A = !0), !A))
|
|
983
1001
|
for (const C of u) {
|
|
984
1002
|
if (w.paths.has(C)) {
|
|
985
|
-
|
|
1003
|
+
A = !0;
|
|
986
1004
|
break;
|
|
987
1005
|
}
|
|
988
|
-
let
|
|
989
|
-
for (;
|
|
990
|
-
const
|
|
991
|
-
if (w.paths.has(
|
|
992
|
-
|
|
1006
|
+
let x = C.lastIndexOf(".");
|
|
1007
|
+
for (; x !== -1; ) {
|
|
1008
|
+
const U = C.substring(0, x);
|
|
1009
|
+
if (w.paths.has(U)) {
|
|
1010
|
+
A = !0;
|
|
993
1011
|
break;
|
|
994
1012
|
}
|
|
995
|
-
const
|
|
996
|
-
|
|
1013
|
+
const D = C.substring(
|
|
1014
|
+
x + 1
|
|
997
1015
|
);
|
|
998
|
-
if (!isNaN(Number(
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
const N =
|
|
1016
|
+
if (!isNaN(Number(D))) {
|
|
1017
|
+
const P = U.lastIndexOf(".");
|
|
1018
|
+
if (P !== -1) {
|
|
1019
|
+
const N = U.substring(
|
|
1002
1020
|
0,
|
|
1003
|
-
|
|
1021
|
+
P
|
|
1004
1022
|
);
|
|
1005
1023
|
if (w.paths.has(N)) {
|
|
1006
|
-
|
|
1024
|
+
A = !0;
|
|
1007
1025
|
break;
|
|
1008
1026
|
}
|
|
1009
1027
|
}
|
|
1010
1028
|
}
|
|
1011
|
-
|
|
1029
|
+
x = U.lastIndexOf(".");
|
|
1012
1030
|
}
|
|
1013
|
-
if (
|
|
1031
|
+
if (A) break;
|
|
1014
1032
|
}
|
|
1015
|
-
if (
|
|
1033
|
+
if (!A && V.includes("deps") && w.depsFunction) {
|
|
1016
1034
|
const C = w.depsFunction(s);
|
|
1017
|
-
let
|
|
1018
|
-
typeof C == "boolean" ? C && (
|
|
1035
|
+
let x = !1;
|
|
1036
|
+
typeof C == "boolean" ? C && (x = !0) : B(w.deps, C) || (w.deps = C, x = !0), x && (A = !0);
|
|
1019
1037
|
}
|
|
1020
|
-
|
|
1038
|
+
A && w.forceUpdate();
|
|
1021
1039
|
}
|
|
1022
1040
|
}
|
|
1023
1041
|
}
|
|
@@ -1029,18 +1047,18 @@ function lt(t, c, h, f) {
|
|
|
1029
1047
|
throw new Error("Zod schema not found");
|
|
1030
1048
|
if (!d?.key)
|
|
1031
1049
|
throw new Error("Validation key not found");
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1050
|
+
Y(d.key);
|
|
1051
|
+
const r = o.getState().cogsStateStore[t];
|
|
1034
1052
|
try {
|
|
1035
1053
|
const s = o.getState().getValidationErrors(d.key);
|
|
1036
1054
|
s && s.length > 0 && s.forEach(([g]) => {
|
|
1037
|
-
g && g.startsWith(d.key) &&
|
|
1055
|
+
g && g.startsWith(d.key) && Y(g);
|
|
1038
1056
|
});
|
|
1039
|
-
const i = d.zodSchema.safeParse(
|
|
1057
|
+
const i = d.zodSchema.safeParse(r);
|
|
1040
1058
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1041
|
-
const E = u.path, w = u.message,
|
|
1042
|
-
e(
|
|
1043
|
-
}),
|
|
1059
|
+
const E = u.path, w = u.message, A = [d.key, ...E].join(".");
|
|
1060
|
+
e(A, w);
|
|
1061
|
+
}), yt(t), !1);
|
|
1044
1062
|
} catch (s) {
|
|
1045
1063
|
return console.error("Zod schema validation failed", s), !1;
|
|
1046
1064
|
}
|
|
@@ -1049,7 +1067,7 @@ function lt(t, c, h, f) {
|
|
|
1049
1067
|
if (l === "getComponents")
|
|
1050
1068
|
return () => o().stateComponents.get(t);
|
|
1051
1069
|
if (l === "getAllFormRefs")
|
|
1052
|
-
return () =>
|
|
1070
|
+
return () => kt.getState().getFormRefsByStateKey(t);
|
|
1053
1071
|
if (l === "_initialState")
|
|
1054
1072
|
return o.getState().initialStateGlobal[t];
|
|
1055
1073
|
if (l === "_serverState")
|
|
@@ -1062,16 +1080,16 @@ function lt(t, c, h, f) {
|
|
|
1062
1080
|
if (l === "removeValidation") return I.removeValidation;
|
|
1063
1081
|
}
|
|
1064
1082
|
if (l === "getFormRef")
|
|
1065
|
-
return () =>
|
|
1083
|
+
return () => kt.getState().getFormRef(t + "." + n.join("."));
|
|
1066
1084
|
if (l === "validationWrapper")
|
|
1067
1085
|
return ({
|
|
1068
1086
|
children: d,
|
|
1069
1087
|
hideMessage: e
|
|
1070
|
-
}) => /* @__PURE__ */
|
|
1071
|
-
|
|
1088
|
+
}) => /* @__PURE__ */ wt(
|
|
1089
|
+
Wt,
|
|
1072
1090
|
{
|
|
1073
1091
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1074
|
-
path:
|
|
1092
|
+
path: n,
|
|
1075
1093
|
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1076
1094
|
stateKey: t,
|
|
1077
1095
|
validIndices: S?.validIndices,
|
|
@@ -1079,51 +1097,51 @@ function lt(t, c, h, f) {
|
|
|
1079
1097
|
}
|
|
1080
1098
|
);
|
|
1081
1099
|
if (l === "_stateKey") return t;
|
|
1082
|
-
if (l === "_path") return
|
|
1100
|
+
if (l === "_path") return n;
|
|
1083
1101
|
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1084
1102
|
if (l === "update")
|
|
1085
1103
|
return (d, e) => {
|
|
1086
1104
|
if (e?.debounce)
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const
|
|
1090
|
-
e?.afterUpdate && e.afterUpdate(
|
|
1105
|
+
Dt(() => {
|
|
1106
|
+
it(c, d, n, "");
|
|
1107
|
+
const r = o.getState().getNestedState(t, n);
|
|
1108
|
+
e?.afterUpdate && e.afterUpdate(r);
|
|
1091
1109
|
}, e.debounce);
|
|
1092
1110
|
else {
|
|
1093
|
-
|
|
1094
|
-
const
|
|
1095
|
-
e?.afterUpdate && e.afterUpdate(
|
|
1111
|
+
it(c, d, n, "");
|
|
1112
|
+
const r = o.getState().getNestedState(t, n);
|
|
1113
|
+
e?.afterUpdate && e.afterUpdate(r);
|
|
1096
1114
|
}
|
|
1097
|
-
p(
|
|
1115
|
+
p(n);
|
|
1098
1116
|
};
|
|
1099
1117
|
if (l === "formElement")
|
|
1100
|
-
return (d, e) => /* @__PURE__ */
|
|
1101
|
-
|
|
1118
|
+
return (d, e) => /* @__PURE__ */ wt(
|
|
1119
|
+
Gt,
|
|
1102
1120
|
{
|
|
1103
1121
|
setState: c,
|
|
1104
1122
|
stateKey: t,
|
|
1105
|
-
path:
|
|
1123
|
+
path: n,
|
|
1106
1124
|
child: d,
|
|
1107
1125
|
formOpts: e
|
|
1108
1126
|
}
|
|
1109
1127
|
);
|
|
1110
|
-
const
|
|
1111
|
-
return a(
|
|
1128
|
+
const _ = [...n, l], at = o.getState().getNestedState(t, _);
|
|
1129
|
+
return a(at, _, S);
|
|
1112
1130
|
}
|
|
1113
|
-
},
|
|
1114
|
-
return v.set(
|
|
1115
|
-
proxy:
|
|
1131
|
+
}, H = new Proxy(O, R);
|
|
1132
|
+
return v.set(L, {
|
|
1133
|
+
proxy: H,
|
|
1116
1134
|
stateVersion: k
|
|
1117
|
-
}),
|
|
1135
|
+
}), H;
|
|
1118
1136
|
}
|
|
1119
1137
|
return a(
|
|
1120
1138
|
o.getState().getNestedState(t, [])
|
|
1121
1139
|
);
|
|
1122
1140
|
}
|
|
1123
|
-
function
|
|
1124
|
-
return
|
|
1141
|
+
function Vt(t) {
|
|
1142
|
+
return ct(te, { proxy: t });
|
|
1125
1143
|
}
|
|
1126
|
-
function
|
|
1144
|
+
function Kt({
|
|
1127
1145
|
proxy: t,
|
|
1128
1146
|
rebuildStateShape: c
|
|
1129
1147
|
}) {
|
|
@@ -1135,11 +1153,11 @@ function zt({
|
|
|
1135
1153
|
(v, k, p, I, a) => t._mapFn(v, k, p, I, a)
|
|
1136
1154
|
) : null;
|
|
1137
1155
|
}
|
|
1138
|
-
function
|
|
1156
|
+
function te({
|
|
1139
1157
|
proxy: t
|
|
1140
1158
|
}) {
|
|
1141
|
-
const c =
|
|
1142
|
-
return
|
|
1159
|
+
const c = Z(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1160
|
+
return gt(() => {
|
|
1143
1161
|
const f = c.current;
|
|
1144
1162
|
if (!f || !f.parentElement) return;
|
|
1145
1163
|
const v = f.parentElement, p = Array.from(v.childNodes).indexOf(f);
|
|
@@ -1152,30 +1170,30 @@ function Bt({
|
|
|
1152
1170
|
effect: t._effect
|
|
1153
1171
|
};
|
|
1154
1172
|
o.getState().addSignalElement(h, y);
|
|
1155
|
-
const
|
|
1173
|
+
const n = o.getState().getNestedState(t._stateKey, t._path);
|
|
1156
1174
|
let S;
|
|
1157
1175
|
if (t._effect)
|
|
1158
1176
|
try {
|
|
1159
1177
|
S = new Function(
|
|
1160
1178
|
"state",
|
|
1161
1179
|
`return (${t._effect})(state)`
|
|
1162
|
-
)(
|
|
1180
|
+
)(n);
|
|
1163
1181
|
} catch (O) {
|
|
1164
|
-
console.error("Error evaluating effect function during mount:", O), S =
|
|
1182
|
+
console.error("Error evaluating effect function during mount:", O), S = n;
|
|
1165
1183
|
}
|
|
1166
1184
|
else
|
|
1167
|
-
S =
|
|
1185
|
+
S = n;
|
|
1168
1186
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1169
|
-
const
|
|
1170
|
-
f.replaceWith(
|
|
1171
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1187
|
+
const L = document.createTextNode(String(S));
|
|
1188
|
+
f.replaceWith(L);
|
|
1189
|
+
}, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
|
|
1172
1190
|
ref: c,
|
|
1173
1191
|
style: { display: "none" },
|
|
1174
1192
|
"data-signal-id": h
|
|
1175
1193
|
});
|
|
1176
1194
|
}
|
|
1177
|
-
function
|
|
1178
|
-
const c =
|
|
1195
|
+
function he(t) {
|
|
1196
|
+
const c = Rt(
|
|
1179
1197
|
(h) => {
|
|
1180
1198
|
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1181
1199
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1187,22 +1205,22 @@ function ie(t) {
|
|
|
1187
1205
|
},
|
|
1188
1206
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1189
1207
|
);
|
|
1190
|
-
return
|
|
1208
|
+
return ct("text", {}, String(c));
|
|
1191
1209
|
}
|
|
1192
|
-
function
|
|
1210
|
+
function ee({
|
|
1193
1211
|
stateKey: t,
|
|
1194
1212
|
itemComponentId: c,
|
|
1195
1213
|
itemPath: h,
|
|
1196
1214
|
children: f
|
|
1197
1215
|
}) {
|
|
1198
|
-
const [, v] =
|
|
1199
|
-
return
|
|
1216
|
+
const [, v] = ot({}), [k, p] = zt();
|
|
1217
|
+
return gt(() => {
|
|
1200
1218
|
p.height > 0 && o.getState().setShadowMetadata(t, h, {
|
|
1201
1219
|
virtualizer: {
|
|
1202
1220
|
itemHeight: p.height
|
|
1203
1221
|
}
|
|
1204
1222
|
});
|
|
1205
|
-
}, [p.height]),
|
|
1223
|
+
}, [p.height]), ft(() => {
|
|
1206
1224
|
const I = `${t}////${c}`, a = o.getState().stateComponents.get(t) || {
|
|
1207
1225
|
components: /* @__PURE__ */ new Map()
|
|
1208
1226
|
};
|
|
@@ -1213,14 +1231,14 @@ function Ht({
|
|
|
1213
1231
|
const y = o.getState().stateComponents.get(t);
|
|
1214
1232
|
y && y.components.delete(I);
|
|
1215
1233
|
};
|
|
1216
|
-
}, [t, c, h.join(".")]), /* @__PURE__ */
|
|
1234
|
+
}, [t, c, h.join(".")]), /* @__PURE__ */ wt("div", { ref: k, children: f });
|
|
1217
1235
|
}
|
|
1218
1236
|
export {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1237
|
+
Vt as $cogsSignal,
|
|
1238
|
+
he as $cogsSignalStore,
|
|
1239
|
+
fe as addStateOptions,
|
|
1240
|
+
Se as createCogsState,
|
|
1241
|
+
me as notifyComponent,
|
|
1242
|
+
Qt as useCogsStateFn
|
|
1225
1243
|
};
|
|
1226
1244
|
//# sourceMappingURL=CogsState.jsx.map
|