cogsbox-state 0.5.162 → 0.5.164
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 +280 -280
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as me } from "react/jsx-runtime";
|
|
3
|
+
import { useState as le, useRef as Q, useEffect as de, useLayoutEffect as Ne, useMemo as ke, createElement as te, useSyncExternalStore as we, startTransition as Ae } from "react";
|
|
4
|
+
import { transformStateFunc as Te, isDeepEqual as U, isFunction as G, getNestedValue as W, getDifferences as he, debounce as xe } from "./utility.js";
|
|
5
|
+
import { pushFunc as se, updateFn as Z, cutFunc as X, ValidationWrapper as Ve, FormControlComponent as Ce } from "./Functions.jsx";
|
|
6
|
+
import be from "./node_modules/superjson/dist/index.js";
|
|
7
7
|
import "zod";
|
|
8
|
-
import { getGlobalStore as a, formRefStore as
|
|
8
|
+
import { getGlobalStore as a, formRefStore as ye } from "./store.js";
|
|
9
9
|
import { useCogsConfig as _e } from "./CogsStateClient.jsx";
|
|
10
|
-
import
|
|
11
|
-
function
|
|
12
|
-
const m = a.getState().getInitialOptions,
|
|
13
|
-
|
|
10
|
+
import ge from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
11
|
+
function ve(e, c) {
|
|
12
|
+
const m = a.getState().getInitialOptions, g = a.getState().setInitialStateOptions, d = m(e) || {};
|
|
13
|
+
g(e, {
|
|
14
14
|
...d,
|
|
15
15
|
...c
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function Ie({
|
|
19
19
|
stateKey: e,
|
|
20
20
|
options: c,
|
|
21
21
|
initialOptionsPart: m
|
|
22
22
|
}) {
|
|
23
|
-
const
|
|
23
|
+
const g = z(e) || {}, d = m[e] || {}, I = a.getState().setInitialStateOptions, E = { ...d, ...g };
|
|
24
24
|
let f = !1;
|
|
25
25
|
if (c)
|
|
26
26
|
for (const l in c)
|
|
@@ -33,7 +33,7 @@ function Ye(e, { formElements: c, validation: m }) {
|
|
|
33
33
|
}
|
|
34
34
|
const Xe = (e, c) => {
|
|
35
35
|
let m = e;
|
|
36
|
-
const [
|
|
36
|
+
const [g, d] = Te(m);
|
|
37
37
|
(Object.keys(d).length > 0 || c && Object.keys(c).length > 0) && Object.keys(d).forEach((f) => {
|
|
38
38
|
d[f] = d[f] || {}, d[f].formElements = {
|
|
39
39
|
...c?.formElements,
|
|
@@ -42,15 +42,15 @@ const Xe = (e, c) => {
|
|
|
42
42
|
...d[f].formElements || {}
|
|
43
43
|
// State-specific overrides
|
|
44
44
|
}, z(f) || a.getState().setInitialStateOptions(f, d[f]);
|
|
45
|
-
}), a.getState().setInitialStates(
|
|
45
|
+
}), a.getState().setInitialStates(g), a.getState().setCreatedState(g);
|
|
46
46
|
const I = (f, l) => {
|
|
47
|
-
const [S] =
|
|
48
|
-
|
|
47
|
+
const [S] = le(l?.componentId ?? ge());
|
|
48
|
+
Ie({
|
|
49
49
|
stateKey: f,
|
|
50
50
|
options: l,
|
|
51
51
|
initialOptionsPart: d
|
|
52
52
|
});
|
|
53
|
-
const t = a.getState().cogsStateStore[f] ||
|
|
53
|
+
const t = a.getState().cogsStateStore[f] || g[f], v = l?.modifyState ? l.modifyState(t) : t, [T, b] = De(
|
|
54
54
|
v,
|
|
55
55
|
{
|
|
56
56
|
stateKey: f,
|
|
@@ -66,49 +66,49 @@ const Xe = (e, c) => {
|
|
|
66
66
|
serverState: l?.serverState
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
|
-
return
|
|
69
|
+
return b;
|
|
70
70
|
};
|
|
71
71
|
function E(f, l) {
|
|
72
|
-
|
|
72
|
+
Ie({ stateKey: f, options: l, initialOptionsPart: d }), l.localStorage && Fe(f, l), re(f);
|
|
73
73
|
}
|
|
74
74
|
return { useCogsState: I, setCogsOptions: E };
|
|
75
75
|
}, {
|
|
76
|
-
setUpdaterState:
|
|
76
|
+
setUpdaterState: K,
|
|
77
77
|
setState: q,
|
|
78
78
|
getInitialOptions: z,
|
|
79
|
-
getKeyState:
|
|
80
|
-
getValidationErrors:
|
|
81
|
-
setStateLog:
|
|
82
|
-
updateInitialStateGlobal:
|
|
83
|
-
addValidationError:
|
|
79
|
+
getKeyState: $e,
|
|
80
|
+
getValidationErrors: Pe,
|
|
81
|
+
setStateLog: je,
|
|
82
|
+
updateInitialStateGlobal: ue,
|
|
83
|
+
addValidationError: Oe,
|
|
84
84
|
removeValidationError: M,
|
|
85
|
-
setServerSyncActions:
|
|
86
|
-
} = a.getState(),
|
|
85
|
+
setServerSyncActions: pe
|
|
86
|
+
} = a.getState(), Ee = (e, c, m, g, d) => {
|
|
87
87
|
m?.log && console.log(
|
|
88
88
|
"saving to localstorage",
|
|
89
89
|
c,
|
|
90
90
|
m.localStorage?.key,
|
|
91
|
-
|
|
91
|
+
g
|
|
92
92
|
);
|
|
93
93
|
const I = G(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
94
|
-
if (I &&
|
|
95
|
-
const E = `${
|
|
94
|
+
if (I && g) {
|
|
95
|
+
const E = `${g}-${c}-${I}`;
|
|
96
96
|
let f;
|
|
97
97
|
try {
|
|
98
|
-
f =
|
|
98
|
+
f = ne(E)?.lastSyncedWithServer;
|
|
99
99
|
} catch {
|
|
100
100
|
}
|
|
101
101
|
const l = {
|
|
102
102
|
state: e,
|
|
103
103
|
lastUpdated: Date.now(),
|
|
104
104
|
lastSyncedWithServer: d ?? f
|
|
105
|
-
}, S =
|
|
105
|
+
}, S = be.serialize(l);
|
|
106
106
|
window.localStorage.setItem(
|
|
107
107
|
E,
|
|
108
108
|
JSON.stringify(S.json)
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, ne = (e) => {
|
|
112
112
|
if (!e) return null;
|
|
113
113
|
try {
|
|
114
114
|
const c = window.localStorage.getItem(e);
|
|
@@ -116,50 +116,50 @@ const Xe = (e, c) => {
|
|
|
116
116
|
} catch (c) {
|
|
117
117
|
return console.error("Error loading from localStorage:", c), null;
|
|
118
118
|
}
|
|
119
|
-
},
|
|
120
|
-
const m = a.getState().cogsStateStore[e], { sessionId:
|
|
121
|
-
if (d &&
|
|
122
|
-
const I =
|
|
123
|
-
`${
|
|
119
|
+
}, Fe = (e, c) => {
|
|
120
|
+
const m = a.getState().cogsStateStore[e], { sessionId: g } = _e(), d = G(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
121
|
+
if (d && g) {
|
|
122
|
+
const I = ne(
|
|
123
|
+
`${g}-${e}-${d}`
|
|
124
124
|
);
|
|
125
125
|
if (I && I.lastUpdated > (I.lastSyncedWithServer || 0))
|
|
126
|
-
return q(e, I.state),
|
|
126
|
+
return q(e, I.state), re(e), !0;
|
|
127
127
|
}
|
|
128
128
|
return !1;
|
|
129
|
-
},
|
|
129
|
+
}, Re = (e, c, m, g, d, I) => {
|
|
130
130
|
const E = {
|
|
131
131
|
initialState: c,
|
|
132
|
-
updaterState:
|
|
132
|
+
updaterState: ee(
|
|
133
133
|
e,
|
|
134
|
-
|
|
134
|
+
g,
|
|
135
135
|
d,
|
|
136
136
|
I
|
|
137
137
|
),
|
|
138
138
|
state: m
|
|
139
139
|
};
|
|
140
|
-
|
|
141
|
-
},
|
|
140
|
+
ue(e, E.initialState), K(e, E.updaterState), q(e, E.state);
|
|
141
|
+
}, re = (e) => {
|
|
142
142
|
const c = a.getState().stateComponents.get(e);
|
|
143
143
|
if (!c) return;
|
|
144
144
|
const m = /* @__PURE__ */ new Set();
|
|
145
|
-
c.components.forEach((
|
|
146
|
-
(
|
|
145
|
+
c.components.forEach((g) => {
|
|
146
|
+
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || m.add(() => g.forceUpdate());
|
|
147
147
|
}), queueMicrotask(() => {
|
|
148
|
-
m.forEach((
|
|
148
|
+
m.forEach((g) => g());
|
|
149
149
|
});
|
|
150
150
|
}, Qe = (e, c) => {
|
|
151
151
|
const m = a.getState().stateComponents.get(e);
|
|
152
152
|
if (m) {
|
|
153
|
-
const
|
|
153
|
+
const g = `${e}////${c}`, d = m.components.get(g);
|
|
154
154
|
if ((d ? Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"] : null)?.includes("none"))
|
|
155
155
|
return;
|
|
156
156
|
d && d.forceUpdate();
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
|
-
function
|
|
159
|
+
function De(e, {
|
|
160
160
|
stateKey: c,
|
|
161
161
|
serverSync: m,
|
|
162
|
-
localStorage:
|
|
162
|
+
localStorage: g,
|
|
163
163
|
formElements: d,
|
|
164
164
|
middleware: I,
|
|
165
165
|
reactiveDeps: E,
|
|
@@ -170,12 +170,12 @@ function Re(e, {
|
|
|
170
170
|
dependencies: v,
|
|
171
171
|
serverState: T
|
|
172
172
|
} = {}) {
|
|
173
|
-
const [
|
|
174
|
-
let
|
|
175
|
-
const [r] =
|
|
173
|
+
const [b, j] = le({}), { sessionId: $ } = _e();
|
|
174
|
+
let O = !c;
|
|
175
|
+
const [r] = le(c ?? ge()), J = a.getState().stateLog[r], H = Q(/* @__PURE__ */ new Set()), L = Q(l ?? ge()), n = Q(
|
|
176
176
|
null
|
|
177
177
|
);
|
|
178
|
-
n.current = z(r) ?? null,
|
|
178
|
+
n.current = z(r) ?? null, de(() => {
|
|
179
179
|
if (t && t.stateKey === r && t.path?.[0]) {
|
|
180
180
|
q(r, (i) => ({
|
|
181
181
|
...i,
|
|
@@ -187,27 +187,27 @@ function Re(e, {
|
|
|
187
187
|
userId: t.userId
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
}, [t]),
|
|
190
|
+
}, [t]), de(() => {
|
|
191
191
|
if (S) {
|
|
192
|
-
|
|
192
|
+
ve(r, {
|
|
193
193
|
initialState: S
|
|
194
194
|
});
|
|
195
|
-
const s = n.current;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
));
|
|
201
|
-
let
|
|
202
|
-
const
|
|
203
|
-
|
|
195
|
+
const s = n.current, y = s?.serverState?.id !== void 0 && s?.serverState?.status === "success" && s?.serverState?.data, k = a.getState().initialStateGlobal[r];
|
|
196
|
+
if (!(k && !U(k, S) || !k) && !y)
|
|
197
|
+
return;
|
|
198
|
+
let _ = null;
|
|
199
|
+
const x = G(s?.localStorage?.key) ? s?.localStorage?.key(S) : s?.localStorage?.key;
|
|
200
|
+
x && $ && (_ = ne(`${$}-${r}-${x}`));
|
|
201
|
+
let V = S, Y = !1;
|
|
202
|
+
const ae = y ? Date.now() : 0, B = _?.lastUpdated || 0, fe = _?.lastSyncedWithServer || 0;
|
|
203
|
+
y && ae > B ? (V = s.serverState.data, Y = !0) : _ && B > fe && (V = _.state, s?.localStorage?.onChange && s?.localStorage?.onChange(V)), Re(
|
|
204
204
|
r,
|
|
205
205
|
S,
|
|
206
|
-
|
|
206
|
+
V,
|
|
207
207
|
o,
|
|
208
208
|
L.current,
|
|
209
|
-
|
|
210
|
-
),
|
|
209
|
+
$
|
|
210
|
+
), Y && x && $ && Ee(V, r, s, $, Date.now()), re(r), (Array.isArray(f) ? f : [f || "component"]).includes("none") || j({});
|
|
211
211
|
}
|
|
212
212
|
}, [
|
|
213
213
|
S,
|
|
@@ -215,181 +215,181 @@ function Re(e, {
|
|
|
215
215
|
T?.data,
|
|
216
216
|
...v || []
|
|
217
217
|
]), Ne(() => {
|
|
218
|
-
|
|
218
|
+
O && ve(r, {
|
|
219
219
|
serverSync: m,
|
|
220
220
|
formElements: d,
|
|
221
221
|
initialState: S,
|
|
222
|
-
localStorage:
|
|
222
|
+
localStorage: g,
|
|
223
223
|
middleware: I
|
|
224
224
|
});
|
|
225
225
|
const s = `${r}////${L.current}`, i = a.getState().stateComponents.get(r) || {
|
|
226
226
|
components: /* @__PURE__ */ new Map()
|
|
227
227
|
};
|
|
228
228
|
return i.components.set(s, {
|
|
229
|
-
forceUpdate: () =>
|
|
229
|
+
forceUpdate: () => j({}),
|
|
230
230
|
paths: /* @__PURE__ */ new Set(),
|
|
231
231
|
deps: [],
|
|
232
232
|
depsFunction: E || void 0,
|
|
233
233
|
reactiveType: f ?? ["component", "deps"]
|
|
234
|
-
}), a.getState().stateComponents.set(r, i),
|
|
234
|
+
}), a.getState().stateComponents.set(r, i), j({}), () => {
|
|
235
235
|
const y = `${r}////${L.current}`;
|
|
236
236
|
i && (i.components.delete(y), i.components.size === 0 && a.getState().stateComponents.delete(r));
|
|
237
237
|
};
|
|
238
238
|
}, []);
|
|
239
|
-
const o = (s, i, y,
|
|
239
|
+
const o = (s, i, y, k) => {
|
|
240
240
|
if (Array.isArray(i)) {
|
|
241
|
-
const
|
|
242
|
-
|
|
241
|
+
const w = `${r}-${i.join(".")}`;
|
|
242
|
+
H.current.add(w);
|
|
243
243
|
}
|
|
244
|
-
q(r, (
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
let R = !1,
|
|
248
|
-
if ((!
|
|
249
|
-
const
|
|
244
|
+
q(r, (w) => {
|
|
245
|
+
const _ = G(s) ? s(w) : s, x = `${r}-${i.join(".")}`;
|
|
246
|
+
if (x) {
|
|
247
|
+
let R = !1, N = a.getState().signalDomElements.get(x);
|
|
248
|
+
if ((!N || N.size === 0) && (y.updateType === "insert" || y.updateType === "cut")) {
|
|
249
|
+
const p = i.slice(0, -1), F = W(_, p);
|
|
250
250
|
if (Array.isArray(F)) {
|
|
251
251
|
R = !0;
|
|
252
|
-
const
|
|
253
|
-
|
|
252
|
+
const h = `${r}-${p.join(".")}`;
|
|
253
|
+
N = a.getState().signalDomElements.get(h);
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
if (
|
|
257
|
-
const
|
|
258
|
-
|
|
256
|
+
if (N) {
|
|
257
|
+
const p = R ? W(_, i.slice(0, -1)) : W(_, i);
|
|
258
|
+
N.forEach(({ parentId: F, position: h, effect: C }) => {
|
|
259
259
|
const A = document.querySelector(
|
|
260
260
|
`[data-parent-id="${F}"]`
|
|
261
261
|
);
|
|
262
262
|
if (A) {
|
|
263
263
|
const D = Array.from(A.childNodes);
|
|
264
|
-
if (D[
|
|
265
|
-
const
|
|
266
|
-
D[
|
|
264
|
+
if (D[h]) {
|
|
265
|
+
const P = C ? new Function("state", `return (${C})(state)`)(p) : p;
|
|
266
|
+
D[h].textContent = String(P);
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
y.updateType === "update" && (
|
|
273
|
-
(
|
|
272
|
+
y.updateType === "update" && (k || n.current?.validation?.key) && i && M(
|
|
273
|
+
(k || n.current?.validation?.key) + "." + i.join(".")
|
|
274
274
|
);
|
|
275
|
-
const
|
|
275
|
+
const V = i.slice(0, i.length - 1);
|
|
276
276
|
y.updateType === "cut" && n.current?.validation?.key && M(
|
|
277
|
-
n.current?.validation?.key + "." +
|
|
278
|
-
), y.updateType === "insert" && n.current?.validation?.key &&
|
|
279
|
-
n.current?.validation?.key + "." +
|
|
280
|
-
).filter(([
|
|
281
|
-
let F =
|
|
282
|
-
if (
|
|
283
|
-
let
|
|
284
|
-
M(
|
|
277
|
+
n.current?.validation?.key + "." + V.join(".")
|
|
278
|
+
), y.updateType === "insert" && n.current?.validation?.key && Pe(
|
|
279
|
+
n.current?.validation?.key + "." + V.join(".")
|
|
280
|
+
).filter(([N, p]) => {
|
|
281
|
+
let F = N?.split(".").length;
|
|
282
|
+
if (N == V.join(".") && F == V.length - 1) {
|
|
283
|
+
let h = N + "." + V;
|
|
284
|
+
M(N), Oe(h, p);
|
|
285
285
|
}
|
|
286
286
|
});
|
|
287
|
-
const
|
|
287
|
+
const Y = W(w, i), ae = W(_, i);
|
|
288
288
|
y.updateType === "update" ? i.join(".") : [...i].slice(0, -1).join(".");
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
const R =
|
|
289
|
+
const B = a.getState().stateComponents.get(r);
|
|
290
|
+
if (B) {
|
|
291
|
+
const R = he(w, _), N = new Set(R), p = y.updateType === "update" ? i.join(".") : i.slice(0, -1).join(".") || "";
|
|
292
292
|
for (const [
|
|
293
293
|
F,
|
|
294
|
-
|
|
295
|
-
] of
|
|
296
|
-
let
|
|
297
|
-
const A = Array.isArray(
|
|
294
|
+
h
|
|
295
|
+
] of B.components.entries()) {
|
|
296
|
+
let C = !1;
|
|
297
|
+
const A = Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"];
|
|
298
298
|
if (!A.includes("none")) {
|
|
299
299
|
if (A.includes("all")) {
|
|
300
|
-
|
|
300
|
+
h.forceUpdate();
|
|
301
301
|
continue;
|
|
302
302
|
}
|
|
303
|
-
if (A.includes("component") && ((
|
|
304
|
-
for (const D of
|
|
305
|
-
let
|
|
303
|
+
if (A.includes("component") && ((h.paths.has(p) || h.paths.has("")) && (C = !0), !C))
|
|
304
|
+
for (const D of N) {
|
|
305
|
+
let P = D;
|
|
306
306
|
for (; ; ) {
|
|
307
|
-
if (
|
|
308
|
-
|
|
307
|
+
if (h.paths.has(P)) {
|
|
308
|
+
C = !0;
|
|
309
309
|
break;
|
|
310
310
|
}
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
313
|
-
const
|
|
311
|
+
const ie = P.lastIndexOf(".");
|
|
312
|
+
if (ie !== -1) {
|
|
313
|
+
const Se = P.substring(
|
|
314
314
|
0,
|
|
315
|
-
|
|
315
|
+
ie
|
|
316
316
|
);
|
|
317
317
|
if (!isNaN(
|
|
318
|
-
Number(
|
|
319
|
-
) &&
|
|
320
|
-
|
|
318
|
+
Number(P.substring(ie + 1))
|
|
319
|
+
) && h.paths.has(Se)) {
|
|
320
|
+
C = !0;
|
|
321
321
|
break;
|
|
322
322
|
}
|
|
323
|
-
|
|
323
|
+
P = Se;
|
|
324
324
|
} else
|
|
325
|
-
|
|
326
|
-
if (
|
|
325
|
+
P = "";
|
|
326
|
+
if (P === "")
|
|
327
327
|
break;
|
|
328
328
|
}
|
|
329
|
-
if (
|
|
329
|
+
if (C) break;
|
|
330
330
|
}
|
|
331
|
-
if (!
|
|
332
|
-
const D =
|
|
333
|
-
let
|
|
334
|
-
typeof D == "boolean" ? D && (
|
|
331
|
+
if (!C && A.includes("deps") && h.depsFunction) {
|
|
332
|
+
const D = h.depsFunction(_);
|
|
333
|
+
let P = !1;
|
|
334
|
+
typeof D == "boolean" ? D && (P = !0) : U(h.deps, D) || (h.deps = D, P = !0), P && (C = !0);
|
|
335
335
|
}
|
|
336
|
-
|
|
336
|
+
C && h.forceUpdate();
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
-
const
|
|
340
|
+
const oe = {
|
|
341
341
|
timeStamp: Date.now(),
|
|
342
342
|
stateKey: r,
|
|
343
343
|
path: i,
|
|
344
344
|
updateType: y.updateType,
|
|
345
345
|
status: "new",
|
|
346
|
-
oldValue:
|
|
347
|
-
newValue:
|
|
346
|
+
oldValue: Y,
|
|
347
|
+
newValue: ae
|
|
348
348
|
};
|
|
349
|
-
if (
|
|
350
|
-
const
|
|
351
|
-
const
|
|
352
|
-
return A ? (A.timeStamp = Math.max(A.timeStamp,
|
|
349
|
+
if (je(r, (R) => {
|
|
350
|
+
const p = [...R ?? [], oe].reduce((F, h) => {
|
|
351
|
+
const C = `${h.stateKey}:${JSON.stringify(h.path)}`, A = F.get(C);
|
|
352
|
+
return A ? (A.timeStamp = Math.max(A.timeStamp, h.timeStamp), A.newValue = h.newValue, A.oldValue = A.oldValue ?? h.oldValue, A.updateType = h.updateType) : F.set(C, { ...h }), F;
|
|
353
353
|
}, /* @__PURE__ */ new Map());
|
|
354
|
-
return Array.from(
|
|
355
|
-
}),
|
|
356
|
-
|
|
354
|
+
return Array.from(p.values());
|
|
355
|
+
}), Ee(
|
|
356
|
+
_,
|
|
357
357
|
r,
|
|
358
358
|
n.current,
|
|
359
|
-
|
|
359
|
+
$
|
|
360
360
|
), I && I({
|
|
361
361
|
updateLog: J,
|
|
362
|
-
update:
|
|
362
|
+
update: oe
|
|
363
363
|
}), n.current?.serverSync) {
|
|
364
|
-
const R = a.getState().serverState[r],
|
|
365
|
-
|
|
366
|
-
syncKey: typeof
|
|
364
|
+
const R = a.getState().serverState[r], N = n.current?.serverSync;
|
|
365
|
+
pe(r, {
|
|
366
|
+
syncKey: typeof N.syncKey == "string" ? N.syncKey : N.syncKey({ state: _ }),
|
|
367
367
|
rollBackState: R,
|
|
368
|
-
actionTimeStamp: Date.now() + (
|
|
368
|
+
actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
|
|
369
369
|
status: "waiting"
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
return
|
|
372
|
+
return _;
|
|
373
373
|
});
|
|
374
374
|
};
|
|
375
|
-
a.getState().updaterState[r] || (
|
|
375
|
+
a.getState().updaterState[r] || (K(
|
|
376
376
|
r,
|
|
377
|
-
|
|
377
|
+
ee(
|
|
378
378
|
r,
|
|
379
379
|
o,
|
|
380
380
|
L.current,
|
|
381
|
-
|
|
381
|
+
$
|
|
382
382
|
)
|
|
383
|
-
), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] ||
|
|
384
|
-
const
|
|
383
|
+
), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] || ue(r, e));
|
|
384
|
+
const u = ke(() => ee(
|
|
385
385
|
r,
|
|
386
386
|
o,
|
|
387
387
|
L.current,
|
|
388
|
-
|
|
388
|
+
$
|
|
389
389
|
), [r]);
|
|
390
|
-
return [
|
|
390
|
+
return [$e(r), u];
|
|
391
391
|
}
|
|
392
|
-
function
|
|
392
|
+
function ee(e, c, m, g) {
|
|
393
393
|
const d = /* @__PURE__ */ new Map();
|
|
394
394
|
let I = 0;
|
|
395
395
|
const E = (S) => {
|
|
@@ -406,29 +406,29 @@ function Q(e, c, m, u) {
|
|
|
406
406
|
t?.key && M(t?.key), S?.validationKey && M(S.validationKey);
|
|
407
407
|
const v = a.getState().initialStateGlobal[e];
|
|
408
408
|
a.getState().clearSelectedIndexesForState(e), d.clear(), I++;
|
|
409
|
-
const T = l(v, []),
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
return
|
|
409
|
+
const T = l(v, []), b = z(e), j = G(b?.localStorage?.key) ? b?.localStorage?.key(v) : b?.localStorage?.key, $ = `${g}-${e}-${j}`;
|
|
410
|
+
$ && localStorage.removeItem($), K(e, T), q(e, v);
|
|
411
|
+
const O = a.getState().stateComponents.get(e);
|
|
412
|
+
return O && O.components.forEach((r) => {
|
|
413
413
|
r.forceUpdate();
|
|
414
414
|
}), v;
|
|
415
415
|
},
|
|
416
416
|
updateInitialState: (S) => {
|
|
417
417
|
d.clear(), I++;
|
|
418
|
-
const t =
|
|
418
|
+
const t = ee(
|
|
419
419
|
e,
|
|
420
420
|
c,
|
|
421
421
|
m,
|
|
422
|
-
|
|
423
|
-
), v = a.getState().initialStateGlobal[e], T = z(e),
|
|
424
|
-
return console.log("removing storage",
|
|
425
|
-
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
422
|
+
g
|
|
423
|
+
), v = a.getState().initialStateGlobal[e], T = z(e), b = G(T?.localStorage?.key) ? T?.localStorage?.key(v) : T?.localStorage?.key, j = `${g}-${e}-${b}`;
|
|
424
|
+
return console.log("removing storage", j), localStorage.getItem(j) && localStorage.removeItem(j), Ae(() => {
|
|
425
|
+
ue(e, S), K(e, t), q(e, S);
|
|
426
|
+
const $ = a.getState().stateComponents.get(e);
|
|
427
|
+
$ && $.components.forEach((O) => {
|
|
428
|
+
O.forceUpdate();
|
|
429
429
|
});
|
|
430
430
|
}), {
|
|
431
|
-
fetchId: (
|
|
431
|
+
fetchId: ($) => t.get()[$]
|
|
432
432
|
};
|
|
433
433
|
},
|
|
434
434
|
_initialState: a.getState().initialStateGlobal[e],
|
|
@@ -436,34 +436,34 @@ function Q(e, c, m, u) {
|
|
|
436
436
|
_isLoading: a.getState().isLoadingGlobal[e],
|
|
437
437
|
_isServerSynced: () => {
|
|
438
438
|
const S = a.getState().serverState[e];
|
|
439
|
-
return !!(S && U(S,
|
|
439
|
+
return !!(S && U(S, $e(e)));
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
function l(S, t = [], v) {
|
|
443
443
|
const T = t.map(String).join(".");
|
|
444
444
|
d.get(T);
|
|
445
|
-
const
|
|
445
|
+
const b = function() {
|
|
446
446
|
return a().getNestedState(e, t);
|
|
447
447
|
};
|
|
448
|
-
Object.keys(f).forEach((
|
|
449
|
-
|
|
448
|
+
Object.keys(f).forEach((O) => {
|
|
449
|
+
b[O] = f[O];
|
|
450
450
|
});
|
|
451
|
-
const
|
|
452
|
-
apply(
|
|
451
|
+
const j = {
|
|
452
|
+
apply(O, r, J) {
|
|
453
453
|
return console.log(
|
|
454
454
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${t.join(".")}`
|
|
455
455
|
), console.trace("Apply trap stack trace"), a().getNestedState(e, t);
|
|
456
456
|
},
|
|
457
|
-
get(
|
|
457
|
+
get(O, r) {
|
|
458
458
|
if (r !== "then" && !r.startsWith("$") && r !== "stateMapNoRender") {
|
|
459
|
-
const n = t.join("."), o = `${e}////${m}`,
|
|
460
|
-
if (
|
|
461
|
-
const s =
|
|
459
|
+
const n = t.join("."), o = `${e}////${m}`, u = a.getState().stateComponents.get(e);
|
|
460
|
+
if (u) {
|
|
461
|
+
const s = u.components.get(o);
|
|
462
462
|
s && (t.length > 0 || r === "get") && s.paths.add(n);
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
if (r === "getDifferences")
|
|
466
|
-
return () =>
|
|
466
|
+
return () => he(
|
|
467
467
|
a.getState().cogsStateStore[e],
|
|
468
468
|
a.getState().initialStateGlobal[e]
|
|
469
469
|
);
|
|
@@ -472,17 +472,17 @@ function Q(e, c, m, u) {
|
|
|
472
472
|
const n = a.getState().getInitialOptions(e), o = n?.sync;
|
|
473
473
|
if (!o)
|
|
474
474
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
475
|
-
const
|
|
475
|
+
const u = a.getState().getNestedState(e, []), s = n?.validation?.key;
|
|
476
476
|
try {
|
|
477
|
-
const i = await o.action(
|
|
477
|
+
const i = await o.action(u);
|
|
478
478
|
if (i && !i.success && i.errors && s) {
|
|
479
|
-
a.getState().removeValidationError(s), i.errors.forEach((
|
|
480
|
-
const
|
|
481
|
-
a.getState().addValidationError(
|
|
479
|
+
a.getState().removeValidationError(s), i.errors.forEach((k) => {
|
|
480
|
+
const w = [s, ...k.path].join(".");
|
|
481
|
+
a.getState().addValidationError(w, k.message);
|
|
482
482
|
});
|
|
483
483
|
const y = a.getState().stateComponents.get(e);
|
|
484
|
-
y && y.components.forEach((
|
|
485
|
-
|
|
484
|
+
y && y.components.forEach((k) => {
|
|
485
|
+
k.forceUpdate();
|
|
486
486
|
});
|
|
487
487
|
}
|
|
488
488
|
return i?.success && o.onSuccess ? o.onSuccess(i.data) : !i?.success && o.onError && o.onError(i.error), i;
|
|
@@ -491,20 +491,20 @@ function Q(e, c, m, u) {
|
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
493
|
if (r === "_status") {
|
|
494
|
-
const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e],
|
|
495
|
-
return U(n,
|
|
494
|
+
const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e], u = W(o, t);
|
|
495
|
+
return U(n, u) ? "fresh" : "stale";
|
|
496
496
|
}
|
|
497
497
|
if (r === "getStatus")
|
|
498
498
|
return function() {
|
|
499
499
|
const n = a().getNestedState(
|
|
500
500
|
e,
|
|
501
501
|
t
|
|
502
|
-
), o = a.getState().initialStateGlobal[e],
|
|
503
|
-
return U(n,
|
|
502
|
+
), o = a.getState().initialStateGlobal[e], u = W(o, t);
|
|
503
|
+
return U(n, u) ? "fresh" : "stale";
|
|
504
504
|
};
|
|
505
505
|
if (r === "removeStorage")
|
|
506
506
|
return () => {
|
|
507
|
-
const n = a.getState().initialStateGlobal[e], o = z(e),
|
|
507
|
+
const n = a.getState().initialStateGlobal[e], o = z(e), u = G(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key, s = `${g}-${e}-${u}`;
|
|
508
508
|
console.log("removing storage", s), s && localStorage.removeItem(s);
|
|
509
509
|
};
|
|
510
510
|
if (r === "showValidationErrors")
|
|
@@ -548,16 +548,16 @@ function Q(e, c, m, u) {
|
|
|
548
548
|
return (n) => {
|
|
549
549
|
const o = v?.filtered?.some(
|
|
550
550
|
(s) => s.join(".") === t.join(".")
|
|
551
|
-
),
|
|
552
|
-
return r !== "stateMapNoRender" && (d.clear(), I++),
|
|
553
|
-
const y = o && s.__origIndex ? s.__origIndex : i,
|
|
551
|
+
), u = o ? S : a.getState().getNestedState(e, t);
|
|
552
|
+
return r !== "stateMapNoRender" && (d.clear(), I++), u.map((s, i) => {
|
|
553
|
+
const y = o && s.__origIndex ? s.__origIndex : i, k = l(
|
|
554
554
|
s,
|
|
555
555
|
[...t, y.toString()],
|
|
556
556
|
v
|
|
557
557
|
);
|
|
558
558
|
return n(
|
|
559
559
|
s,
|
|
560
|
-
|
|
560
|
+
k,
|
|
561
561
|
i,
|
|
562
562
|
S,
|
|
563
563
|
l(S, t, v)
|
|
@@ -565,7 +565,7 @@ function Q(e, c, m, u) {
|
|
|
565
565
|
});
|
|
566
566
|
};
|
|
567
567
|
if (r === "$stateMap")
|
|
568
|
-
return (n) =>
|
|
568
|
+
return (n) => te(Ue, {
|
|
569
569
|
proxy: {
|
|
570
570
|
_stateKey: e,
|
|
571
571
|
_path: t,
|
|
@@ -576,11 +576,11 @@ function Q(e, c, m, u) {
|
|
|
576
576
|
});
|
|
577
577
|
if (r === "stateFlattenOn")
|
|
578
578
|
return (n) => {
|
|
579
|
-
const
|
|
579
|
+
const u = v?.filtered?.some(
|
|
580
580
|
(i) => i.join(".") === t.join(".")
|
|
581
581
|
) ? S : a.getState().getNestedState(e, t);
|
|
582
582
|
d.clear(), I++;
|
|
583
|
-
const s =
|
|
583
|
+
const s = u.flatMap(
|
|
584
584
|
(i, y) => i[n] ?? []
|
|
585
585
|
);
|
|
586
586
|
return l(
|
|
@@ -591,9 +591,9 @@ function Q(e, c, m, u) {
|
|
|
591
591
|
};
|
|
592
592
|
if (r === "findWith")
|
|
593
593
|
return (n, o) => {
|
|
594
|
-
const
|
|
595
|
-
if (
|
|
596
|
-
const s = S[
|
|
594
|
+
const u = S.findIndex((y) => y[n] === o);
|
|
595
|
+
if (u === -1) return;
|
|
596
|
+
const s = S[u], i = [...t, u.toString()];
|
|
597
597
|
return d.clear(), I++, l(s, i);
|
|
598
598
|
};
|
|
599
599
|
if (r === "index")
|
|
@@ -605,40 +605,40 @@ function Q(e, c, m, u) {
|
|
|
605
605
|
return () => {
|
|
606
606
|
const n = a.getState().getNestedState(e, t);
|
|
607
607
|
if (n.length === 0) return;
|
|
608
|
-
const o = n.length - 1,
|
|
609
|
-
return l(
|
|
608
|
+
const o = n.length - 1, u = n[o], s = [...t, o.toString()];
|
|
609
|
+
return l(u, s);
|
|
610
610
|
};
|
|
611
611
|
if (r === "insert")
|
|
612
|
-
return (n) => (E(t),
|
|
612
|
+
return (n) => (E(t), se(c, n, t, e), l(
|
|
613
613
|
a.getState().getNestedState(e, t),
|
|
614
614
|
t
|
|
615
615
|
));
|
|
616
616
|
if (r === "uniqueInsert")
|
|
617
|
-
return (n, o,
|
|
617
|
+
return (n, o, u) => {
|
|
618
618
|
const s = a.getState().getNestedState(e, t), i = G(n) ? n(s) : n;
|
|
619
619
|
let y = null;
|
|
620
|
-
if (!s.some((
|
|
620
|
+
if (!s.some((w) => {
|
|
621
621
|
if (o) {
|
|
622
|
-
const
|
|
623
|
-
(
|
|
622
|
+
const x = o.every(
|
|
623
|
+
(V) => U(w[V], i[V])
|
|
624
624
|
);
|
|
625
|
-
return
|
|
625
|
+
return x && (y = w), x;
|
|
626
626
|
}
|
|
627
|
-
const
|
|
628
|
-
return
|
|
627
|
+
const _ = U(w, i);
|
|
628
|
+
return _ && (y = w), _;
|
|
629
629
|
}))
|
|
630
|
-
E(t),
|
|
631
|
-
else if (
|
|
632
|
-
const
|
|
633
|
-
(
|
|
630
|
+
E(t), se(c, i, t, e);
|
|
631
|
+
else if (u && y) {
|
|
632
|
+
const w = u(y), _ = s.map(
|
|
633
|
+
(x) => U(x, y) ? w : x
|
|
634
634
|
);
|
|
635
|
-
E(t),
|
|
635
|
+
E(t), Z(c, _, t);
|
|
636
636
|
}
|
|
637
637
|
};
|
|
638
638
|
if (r === "cut")
|
|
639
639
|
return (n, o) => {
|
|
640
640
|
if (!o?.waitForSync)
|
|
641
|
-
return E(t),
|
|
641
|
+
return E(t), X(c, t, e, n), l(
|
|
642
642
|
a.getState().getNestedState(e, t),
|
|
643
643
|
t
|
|
644
644
|
);
|
|
@@ -646,24 +646,24 @@ function Q(e, c, m, u) {
|
|
|
646
646
|
if (r === "cutByValue")
|
|
647
647
|
return (n) => {
|
|
648
648
|
for (let o = 0; o < S.length; o++)
|
|
649
|
-
S[o] === n &&
|
|
649
|
+
S[o] === n && X(c, t, e, o);
|
|
650
650
|
};
|
|
651
651
|
if (r === "toggleByValue")
|
|
652
652
|
return (n) => {
|
|
653
|
-
const o = S.findIndex((
|
|
654
|
-
o > -1 ?
|
|
653
|
+
const o = S.findIndex((u) => u === n);
|
|
654
|
+
o > -1 ? X(c, t, e, o) : se(c, n, t, e);
|
|
655
655
|
};
|
|
656
656
|
if (r === "stateFilter")
|
|
657
657
|
return (n) => {
|
|
658
658
|
const o = S.map((i, y) => ({
|
|
659
659
|
...i,
|
|
660
660
|
__origIndex: y.toString()
|
|
661
|
-
})),
|
|
661
|
+
})), u = [], s = [];
|
|
662
662
|
for (let i = 0; i < o.length; i++)
|
|
663
|
-
n(o[i], i) && (
|
|
663
|
+
n(o[i], i) && (u.push(i), s.push(o[i]));
|
|
664
664
|
return d.clear(), I++, l(s, t, {
|
|
665
665
|
filtered: [...v?.filtered || [], t],
|
|
666
|
-
validIndices:
|
|
666
|
+
validIndices: u
|
|
667
667
|
// Always pass validIndices, even if empty
|
|
668
668
|
});
|
|
669
669
|
};
|
|
@@ -672,7 +672,7 @@ function Q(e, c, m, u) {
|
|
|
672
672
|
if (!isNaN(Number(J))) {
|
|
673
673
|
const n = t.slice(0, -1), o = a.getState().getNestedState(e, n);
|
|
674
674
|
if (Array.isArray(o) && r === "cut")
|
|
675
|
-
return () =>
|
|
675
|
+
return () => X(
|
|
676
676
|
c,
|
|
677
677
|
n,
|
|
678
678
|
e,
|
|
@@ -682,19 +682,19 @@ function Q(e, c, m, u) {
|
|
|
682
682
|
if (r === "get")
|
|
683
683
|
return () => a.getState().getNestedState(e, t);
|
|
684
684
|
if (r === "$derive")
|
|
685
|
-
return (n) =>
|
|
685
|
+
return (n) => ce({
|
|
686
686
|
_stateKey: e,
|
|
687
687
|
_path: t,
|
|
688
688
|
_effect: n.toString()
|
|
689
689
|
});
|
|
690
690
|
if (r === "$derive")
|
|
691
|
-
return (n) =>
|
|
691
|
+
return (n) => ce({
|
|
692
692
|
_stateKey: e,
|
|
693
693
|
_path: t,
|
|
694
694
|
_effect: n.toString()
|
|
695
695
|
});
|
|
696
696
|
if (r === "$get")
|
|
697
|
-
return () =>
|
|
697
|
+
return () => ce({
|
|
698
698
|
_stateKey: e,
|
|
699
699
|
_path: t
|
|
700
700
|
});
|
|
@@ -703,28 +703,28 @@ function Q(e, c, m, u) {
|
|
|
703
703
|
return a.getState().getSyncInfo(n);
|
|
704
704
|
}
|
|
705
705
|
if (r == "getLocalStorage")
|
|
706
|
-
return (n) =>
|
|
706
|
+
return (n) => ne(g + "-" + e + "-" + n);
|
|
707
707
|
if (r === "_selected") {
|
|
708
|
-
const n = t.slice(0, -1), o = n.join("."),
|
|
709
|
-
return Array.isArray(
|
|
708
|
+
const n = t.slice(0, -1), o = n.join("."), u = a.getState().getNestedState(e, n);
|
|
709
|
+
return Array.isArray(u) ? Number(t[t.length - 1]) === a.getState().getSelectedIndex(e, o) : void 0;
|
|
710
710
|
}
|
|
711
711
|
if (r === "setSelected")
|
|
712
712
|
return (n) => {
|
|
713
|
-
const o = t.slice(0, -1),
|
|
714
|
-
n ? a.getState().setSelectedIndex(e, s,
|
|
713
|
+
const o = t.slice(0, -1), u = Number(t[t.length - 1]), s = o.join(".");
|
|
714
|
+
n ? a.getState().setSelectedIndex(e, s, u) : a.getState().setSelectedIndex(e, s, void 0);
|
|
715
715
|
const i = a.getState().getNestedState(e, [...o]);
|
|
716
|
-
|
|
716
|
+
Z(c, i, o), E(o);
|
|
717
717
|
};
|
|
718
718
|
if (r === "toggleSelected")
|
|
719
719
|
return () => {
|
|
720
|
-
const n = t.slice(0, -1), o = Number(t[t.length - 1]),
|
|
720
|
+
const n = t.slice(0, -1), o = Number(t[t.length - 1]), u = n.join("."), s = a.getState().getSelectedIndex(e, u);
|
|
721
721
|
a.getState().setSelectedIndex(
|
|
722
722
|
e,
|
|
723
|
-
|
|
723
|
+
u,
|
|
724
724
|
s === o ? void 0 : o
|
|
725
725
|
);
|
|
726
726
|
const i = a.getState().getNestedState(e, [...n]);
|
|
727
|
-
|
|
727
|
+
Z(c, i, n), E(n);
|
|
728
728
|
};
|
|
729
729
|
if (t.length == 0) {
|
|
730
730
|
if (r === "validateZodSchema")
|
|
@@ -735,17 +735,17 @@ function Q(e, c, m, u) {
|
|
|
735
735
|
if (!n?.key)
|
|
736
736
|
throw new Error("Validation key not found");
|
|
737
737
|
M(n.key);
|
|
738
|
-
const
|
|
738
|
+
const u = a.getState().cogsStateStore[e];
|
|
739
739
|
try {
|
|
740
740
|
const s = a.getState().getValidationErrors(n.key);
|
|
741
741
|
s && s.length > 0 && s.forEach(([y]) => {
|
|
742
742
|
y && y.startsWith(n.key) && M(y);
|
|
743
743
|
});
|
|
744
|
-
const i = n.zodSchema.safeParse(
|
|
745
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
746
|
-
const
|
|
747
|
-
o(
|
|
748
|
-
}),
|
|
744
|
+
const i = n.zodSchema.safeParse(u);
|
|
745
|
+
return i.success ? !0 : (i.error.errors.forEach((k) => {
|
|
746
|
+
const w = k.path, _ = k.message, x = [n.key, ...w].join(".");
|
|
747
|
+
o(x, _);
|
|
748
|
+
}), re(e), !1);
|
|
749
749
|
} catch (s) {
|
|
750
750
|
return console.error("Zod schema validation failed", s), !1;
|
|
751
751
|
}
|
|
@@ -754,7 +754,7 @@ function Q(e, c, m, u) {
|
|
|
754
754
|
if (r === "getComponents")
|
|
755
755
|
return () => a().stateComponents.get(e);
|
|
756
756
|
if (r === "getAllFormRefs")
|
|
757
|
-
return () =>
|
|
757
|
+
return () => ye.getState().getFormRefsByStateKey(e);
|
|
758
758
|
if (r === "_initialState")
|
|
759
759
|
return a.getState().initialStateGlobal[e];
|
|
760
760
|
if (r === "_serverState")
|
|
@@ -767,13 +767,13 @@ function Q(e, c, m, u) {
|
|
|
767
767
|
if (r === "removeValidation") return f.removeValidation;
|
|
768
768
|
}
|
|
769
769
|
if (r === "getFormRef")
|
|
770
|
-
return () =>
|
|
770
|
+
return () => ye.getState().getFormRef(e + "." + t.join("."));
|
|
771
771
|
if (r === "validationWrapper")
|
|
772
772
|
return ({
|
|
773
773
|
children: n,
|
|
774
774
|
hideMessage: o
|
|
775
|
-
}) => /* @__PURE__ */
|
|
776
|
-
|
|
775
|
+
}) => /* @__PURE__ */ me(
|
|
776
|
+
Ve,
|
|
777
777
|
{
|
|
778
778
|
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
779
779
|
path: t,
|
|
@@ -789,21 +789,21 @@ function Q(e, c, m, u) {
|
|
|
789
789
|
if (r === "update")
|
|
790
790
|
return (n, o) => {
|
|
791
791
|
if (o?.debounce)
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const
|
|
795
|
-
o?.afterUpdate && o.afterUpdate(
|
|
792
|
+
xe(() => {
|
|
793
|
+
Z(c, n, t, "");
|
|
794
|
+
const u = a.getState().getNestedState(e, t);
|
|
795
|
+
o?.afterUpdate && o.afterUpdate(u);
|
|
796
796
|
}, o.debounce);
|
|
797
797
|
else {
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
o?.afterUpdate && o.afterUpdate(
|
|
798
|
+
Z(c, n, t, "");
|
|
799
|
+
const u = a.getState().getNestedState(e, t);
|
|
800
|
+
o?.afterUpdate && o.afterUpdate(u);
|
|
801
801
|
}
|
|
802
802
|
E(t);
|
|
803
803
|
};
|
|
804
804
|
if (r === "formElement")
|
|
805
|
-
return (n, o) => /* @__PURE__ */
|
|
806
|
-
|
|
805
|
+
return (n, o) => /* @__PURE__ */ me(
|
|
806
|
+
Ce,
|
|
807
807
|
{
|
|
808
808
|
setState: c,
|
|
809
809
|
stateKey: e,
|
|
@@ -812,23 +812,23 @@ function Q(e, c, m, u) {
|
|
|
812
812
|
formOpts: o
|
|
813
813
|
}
|
|
814
814
|
);
|
|
815
|
-
const
|
|
816
|
-
return l(L,
|
|
815
|
+
const H = [...t, r], L = a.getState().getNestedState(e, H);
|
|
816
|
+
return l(L, H, v);
|
|
817
817
|
}
|
|
818
|
-
},
|
|
818
|
+
}, $ = new Proxy(b, j);
|
|
819
819
|
return d.set(T, {
|
|
820
|
-
proxy:
|
|
820
|
+
proxy: $,
|
|
821
821
|
stateVersion: I
|
|
822
|
-
}),
|
|
822
|
+
}), $;
|
|
823
823
|
}
|
|
824
824
|
return l(
|
|
825
825
|
a.getState().getNestedState(e, [])
|
|
826
826
|
);
|
|
827
827
|
}
|
|
828
|
-
function
|
|
829
|
-
return
|
|
828
|
+
function ce(e) {
|
|
829
|
+
return te(Me, { proxy: e });
|
|
830
830
|
}
|
|
831
|
-
function
|
|
831
|
+
function Ue({
|
|
832
832
|
proxy: e,
|
|
833
833
|
rebuildStateShape: c
|
|
834
834
|
}) {
|
|
@@ -840,14 +840,14 @@ function De({
|
|
|
840
840
|
(d, I, E, f, l) => e._mapFn(d, I, E, f, l)
|
|
841
841
|
) : null;
|
|
842
842
|
}
|
|
843
|
-
function
|
|
843
|
+
function Me({
|
|
844
844
|
proxy: e
|
|
845
845
|
}) {
|
|
846
|
-
const c =
|
|
847
|
-
return
|
|
848
|
-
const
|
|
849
|
-
if (!
|
|
850
|
-
const d =
|
|
846
|
+
const c = Q(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
847
|
+
return de(() => {
|
|
848
|
+
const g = c.current;
|
|
849
|
+
if (!g || !g.parentElement) return;
|
|
850
|
+
const d = g.parentElement, E = Array.from(d.childNodes).indexOf(g);
|
|
851
851
|
let f = d.getAttribute("data-parent-id");
|
|
852
852
|
f || (f = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", f));
|
|
853
853
|
const S = {
|
|
@@ -865,41 +865,41 @@ function Ue({
|
|
|
865
865
|
"state",
|
|
866
866
|
`return (${e._effect})(state)`
|
|
867
867
|
)(t);
|
|
868
|
-
} catch (
|
|
869
|
-
console.error("Error evaluating effect function during mount:",
|
|
868
|
+
} catch (b) {
|
|
869
|
+
console.error("Error evaluating effect function during mount:", b), v = t;
|
|
870
870
|
}
|
|
871
871
|
else
|
|
872
872
|
v = t;
|
|
873
873
|
v !== null && typeof v == "object" && (v = JSON.stringify(v));
|
|
874
874
|
const T = document.createTextNode(String(v));
|
|
875
|
-
|
|
876
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
875
|
+
g.replaceWith(T);
|
|
876
|
+
}, [e._stateKey, e._path.join("."), e._effect]), te("span", {
|
|
877
877
|
ref: c,
|
|
878
878
|
style: { display: "none" },
|
|
879
879
|
"data-signal-id": m
|
|
880
880
|
});
|
|
881
881
|
}
|
|
882
882
|
function Ke(e) {
|
|
883
|
-
const c =
|
|
883
|
+
const c = we(
|
|
884
884
|
(m) => {
|
|
885
|
-
const
|
|
885
|
+
const g = a.getState().stateComponents.get(e._stateKey) || {
|
|
886
886
|
components: /* @__PURE__ */ new Map()
|
|
887
887
|
};
|
|
888
|
-
return
|
|
888
|
+
return g.components.set(e._stateKey, {
|
|
889
889
|
forceUpdate: m,
|
|
890
890
|
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
891
|
-
}), () =>
|
|
891
|
+
}), () => g.components.delete(e._stateKey);
|
|
892
892
|
},
|
|
893
893
|
() => a.getState().getNestedState(e._stateKey, e._path)
|
|
894
894
|
);
|
|
895
|
-
return
|
|
895
|
+
return te("text", {}, String(c));
|
|
896
896
|
}
|
|
897
897
|
export {
|
|
898
|
-
|
|
898
|
+
ce as $cogsSignal,
|
|
899
899
|
Ke as $cogsSignalStore,
|
|
900
900
|
Ye as addStateOptions,
|
|
901
901
|
Xe as createCogsState,
|
|
902
902
|
Qe as notifyComponent,
|
|
903
|
-
|
|
903
|
+
De as useCogsStateFn
|
|
904
904
|
};
|
|
905
905
|
//# sourceMappingURL=CogsState.jsx.map
|