cogsbox-state 0.5.163 → 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 +291 -286
- 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,
|
|
@@ -168,14 +168,14 @@ function Re(e, {
|
|
|
168
168
|
initialState: S,
|
|
169
169
|
syncUpdate: t,
|
|
170
170
|
dependencies: v,
|
|
171
|
-
serverState:
|
|
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,204 +187,209 @@ 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
|
-
}, [
|
|
213
|
-
|
|
212
|
+
}, [
|
|
213
|
+
S,
|
|
214
|
+
T?.status,
|
|
215
|
+
T?.data,
|
|
216
|
+
...v || []
|
|
217
|
+
]), Ne(() => {
|
|
218
|
+
O && ve(r, {
|
|
214
219
|
serverSync: m,
|
|
215
220
|
formElements: d,
|
|
216
221
|
initialState: S,
|
|
217
|
-
localStorage:
|
|
222
|
+
localStorage: g,
|
|
218
223
|
middleware: I
|
|
219
224
|
});
|
|
220
225
|
const s = `${r}////${L.current}`, i = a.getState().stateComponents.get(r) || {
|
|
221
226
|
components: /* @__PURE__ */ new Map()
|
|
222
227
|
};
|
|
223
228
|
return i.components.set(s, {
|
|
224
|
-
forceUpdate: () =>
|
|
229
|
+
forceUpdate: () => j({}),
|
|
225
230
|
paths: /* @__PURE__ */ new Set(),
|
|
226
231
|
deps: [],
|
|
227
232
|
depsFunction: E || void 0,
|
|
228
233
|
reactiveType: f ?? ["component", "deps"]
|
|
229
|
-
}), a.getState().stateComponents.set(r, i),
|
|
234
|
+
}), a.getState().stateComponents.set(r, i), j({}), () => {
|
|
230
235
|
const y = `${r}////${L.current}`;
|
|
231
236
|
i && (i.components.delete(y), i.components.size === 0 && a.getState().stateComponents.delete(r));
|
|
232
237
|
};
|
|
233
238
|
}, []);
|
|
234
|
-
const o = (s, i, y,
|
|
239
|
+
const o = (s, i, y, k) => {
|
|
235
240
|
if (Array.isArray(i)) {
|
|
236
|
-
const
|
|
237
|
-
|
|
241
|
+
const w = `${r}-${i.join(".")}`;
|
|
242
|
+
H.current.add(w);
|
|
238
243
|
}
|
|
239
|
-
q(r, (
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
242
|
-
let R = !1,
|
|
243
|
-
if ((!
|
|
244
|
-
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);
|
|
245
250
|
if (Array.isArray(F)) {
|
|
246
251
|
R = !0;
|
|
247
|
-
const
|
|
248
|
-
|
|
252
|
+
const h = `${r}-${p.join(".")}`;
|
|
253
|
+
N = a.getState().signalDomElements.get(h);
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
|
-
if (
|
|
252
|
-
const
|
|
253
|
-
|
|
256
|
+
if (N) {
|
|
257
|
+
const p = R ? W(_, i.slice(0, -1)) : W(_, i);
|
|
258
|
+
N.forEach(({ parentId: F, position: h, effect: C }) => {
|
|
254
259
|
const A = document.querySelector(
|
|
255
260
|
`[data-parent-id="${F}"]`
|
|
256
261
|
);
|
|
257
262
|
if (A) {
|
|
258
263
|
const D = Array.from(A.childNodes);
|
|
259
|
-
if (D[
|
|
260
|
-
const
|
|
261
|
-
D[
|
|
264
|
+
if (D[h]) {
|
|
265
|
+
const P = C ? new Function("state", `return (${C})(state)`)(p) : p;
|
|
266
|
+
D[h].textContent = String(P);
|
|
262
267
|
}
|
|
263
268
|
}
|
|
264
269
|
});
|
|
265
270
|
}
|
|
266
271
|
}
|
|
267
|
-
y.updateType === "update" && (
|
|
268
|
-
(
|
|
272
|
+
y.updateType === "update" && (k || n.current?.validation?.key) && i && M(
|
|
273
|
+
(k || n.current?.validation?.key) + "." + i.join(".")
|
|
269
274
|
);
|
|
270
|
-
const
|
|
275
|
+
const V = i.slice(0, i.length - 1);
|
|
271
276
|
y.updateType === "cut" && n.current?.validation?.key && M(
|
|
272
|
-
n.current?.validation?.key + "." +
|
|
273
|
-
), y.updateType === "insert" && n.current?.validation?.key &&
|
|
274
|
-
n.current?.validation?.key + "." +
|
|
275
|
-
).filter(([
|
|
276
|
-
let F =
|
|
277
|
-
if (
|
|
278
|
-
let
|
|
279
|
-
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);
|
|
280
285
|
}
|
|
281
286
|
});
|
|
282
|
-
const
|
|
287
|
+
const Y = W(w, i), ae = W(_, i);
|
|
283
288
|
y.updateType === "update" ? i.join(".") : [...i].slice(0, -1).join(".");
|
|
284
|
-
const
|
|
285
|
-
if (
|
|
286
|
-
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(".") || "";
|
|
287
292
|
for (const [
|
|
288
293
|
F,
|
|
289
|
-
|
|
290
|
-
] of
|
|
291
|
-
let
|
|
292
|
-
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"];
|
|
293
298
|
if (!A.includes("none")) {
|
|
294
299
|
if (A.includes("all")) {
|
|
295
|
-
|
|
300
|
+
h.forceUpdate();
|
|
296
301
|
continue;
|
|
297
302
|
}
|
|
298
|
-
if (A.includes("component") && ((
|
|
299
|
-
for (const D of
|
|
300
|
-
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;
|
|
301
306
|
for (; ; ) {
|
|
302
|
-
if (
|
|
303
|
-
|
|
307
|
+
if (h.paths.has(P)) {
|
|
308
|
+
C = !0;
|
|
304
309
|
break;
|
|
305
310
|
}
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
311
|
+
const ie = P.lastIndexOf(".");
|
|
312
|
+
if (ie !== -1) {
|
|
313
|
+
const Se = P.substring(
|
|
309
314
|
0,
|
|
310
|
-
|
|
315
|
+
ie
|
|
311
316
|
);
|
|
312
317
|
if (!isNaN(
|
|
313
|
-
Number(
|
|
314
|
-
) &&
|
|
315
|
-
|
|
318
|
+
Number(P.substring(ie + 1))
|
|
319
|
+
) && h.paths.has(Se)) {
|
|
320
|
+
C = !0;
|
|
316
321
|
break;
|
|
317
322
|
}
|
|
318
|
-
|
|
323
|
+
P = Se;
|
|
319
324
|
} else
|
|
320
|
-
|
|
321
|
-
if (
|
|
325
|
+
P = "";
|
|
326
|
+
if (P === "")
|
|
322
327
|
break;
|
|
323
328
|
}
|
|
324
|
-
if (
|
|
329
|
+
if (C) break;
|
|
325
330
|
}
|
|
326
|
-
if (!
|
|
327
|
-
const D =
|
|
328
|
-
let
|
|
329
|
-
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);
|
|
330
335
|
}
|
|
331
|
-
|
|
336
|
+
C && h.forceUpdate();
|
|
332
337
|
}
|
|
333
338
|
}
|
|
334
339
|
}
|
|
335
|
-
const
|
|
340
|
+
const oe = {
|
|
336
341
|
timeStamp: Date.now(),
|
|
337
342
|
stateKey: r,
|
|
338
343
|
path: i,
|
|
339
344
|
updateType: y.updateType,
|
|
340
345
|
status: "new",
|
|
341
|
-
oldValue:
|
|
342
|
-
newValue:
|
|
346
|
+
oldValue: Y,
|
|
347
|
+
newValue: ae
|
|
343
348
|
};
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
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;
|
|
348
353
|
}, /* @__PURE__ */ new Map());
|
|
349
|
-
return Array.from(
|
|
350
|
-
}),
|
|
351
|
-
|
|
354
|
+
return Array.from(p.values());
|
|
355
|
+
}), Ee(
|
|
356
|
+
_,
|
|
352
357
|
r,
|
|
353
358
|
n.current,
|
|
354
|
-
|
|
359
|
+
$
|
|
355
360
|
), I && I({
|
|
356
361
|
updateLog: J,
|
|
357
|
-
update:
|
|
362
|
+
update: oe
|
|
358
363
|
}), n.current?.serverSync) {
|
|
359
|
-
const R = a.getState().serverState[r],
|
|
360
|
-
|
|
361
|
-
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: _ }),
|
|
362
367
|
rollBackState: R,
|
|
363
|
-
actionTimeStamp: Date.now() + (
|
|
368
|
+
actionTimeStamp: Date.now() + (N.debounce ?? 3e3),
|
|
364
369
|
status: "waiting"
|
|
365
370
|
});
|
|
366
371
|
}
|
|
367
|
-
return
|
|
372
|
+
return _;
|
|
368
373
|
});
|
|
369
374
|
};
|
|
370
|
-
a.getState().updaterState[r] || (
|
|
375
|
+
a.getState().updaterState[r] || (K(
|
|
371
376
|
r,
|
|
372
|
-
|
|
377
|
+
ee(
|
|
373
378
|
r,
|
|
374
379
|
o,
|
|
375
380
|
L.current,
|
|
376
|
-
|
|
381
|
+
$
|
|
377
382
|
)
|
|
378
|
-
), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] ||
|
|
379
|
-
const
|
|
383
|
+
), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] || ue(r, e));
|
|
384
|
+
const u = ke(() => ee(
|
|
380
385
|
r,
|
|
381
386
|
o,
|
|
382
387
|
L.current,
|
|
383
|
-
|
|
388
|
+
$
|
|
384
389
|
), [r]);
|
|
385
|
-
return [
|
|
390
|
+
return [$e(r), u];
|
|
386
391
|
}
|
|
387
|
-
function
|
|
392
|
+
function ee(e, c, m, g) {
|
|
388
393
|
const d = /* @__PURE__ */ new Map();
|
|
389
394
|
let I = 0;
|
|
390
395
|
const E = (S) => {
|
|
@@ -401,29 +406,29 @@ function Q(e, c, m, u) {
|
|
|
401
406
|
t?.key && M(t?.key), S?.validationKey && M(S.validationKey);
|
|
402
407
|
const v = a.getState().initialStateGlobal[e];
|
|
403
408
|
a.getState().clearSelectedIndexesForState(e), d.clear(), I++;
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
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) => {
|
|
408
413
|
r.forceUpdate();
|
|
409
414
|
}), v;
|
|
410
415
|
},
|
|
411
416
|
updateInitialState: (S) => {
|
|
412
417
|
d.clear(), I++;
|
|
413
|
-
const t =
|
|
418
|
+
const t = ee(
|
|
414
419
|
e,
|
|
415
420
|
c,
|
|
416
421
|
m,
|
|
417
|
-
|
|
418
|
-
), v = a.getState().initialStateGlobal[e],
|
|
419
|
-
return console.log("removing storage",
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
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();
|
|
424
429
|
});
|
|
425
430
|
}), {
|
|
426
|
-
fetchId: (
|
|
431
|
+
fetchId: ($) => t.get()[$]
|
|
427
432
|
};
|
|
428
433
|
},
|
|
429
434
|
_initialState: a.getState().initialStateGlobal[e],
|
|
@@ -431,34 +436,34 @@ function Q(e, c, m, u) {
|
|
|
431
436
|
_isLoading: a.getState().isLoadingGlobal[e],
|
|
432
437
|
_isServerSynced: () => {
|
|
433
438
|
const S = a.getState().serverState[e];
|
|
434
|
-
return !!(S && U(S,
|
|
439
|
+
return !!(S && U(S, $e(e)));
|
|
435
440
|
}
|
|
436
441
|
};
|
|
437
442
|
function l(S, t = [], v) {
|
|
438
|
-
const
|
|
439
|
-
d.get(
|
|
440
|
-
const
|
|
443
|
+
const T = t.map(String).join(".");
|
|
444
|
+
d.get(T);
|
|
445
|
+
const b = function() {
|
|
441
446
|
return a().getNestedState(e, t);
|
|
442
447
|
};
|
|
443
|
-
Object.keys(f).forEach((
|
|
444
|
-
|
|
448
|
+
Object.keys(f).forEach((O) => {
|
|
449
|
+
b[O] = f[O];
|
|
445
450
|
});
|
|
446
|
-
const
|
|
447
|
-
apply(
|
|
451
|
+
const j = {
|
|
452
|
+
apply(O, r, J) {
|
|
448
453
|
return console.log(
|
|
449
454
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${t.join(".")}`
|
|
450
455
|
), console.trace("Apply trap stack trace"), a().getNestedState(e, t);
|
|
451
456
|
},
|
|
452
|
-
get(
|
|
457
|
+
get(O, r) {
|
|
453
458
|
if (r !== "then" && !r.startsWith("$") && r !== "stateMapNoRender") {
|
|
454
|
-
const n = t.join("."), o = `${e}////${m}`,
|
|
455
|
-
if (
|
|
456
|
-
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);
|
|
457
462
|
s && (t.length > 0 || r === "get") && s.paths.add(n);
|
|
458
463
|
}
|
|
459
464
|
}
|
|
460
465
|
if (r === "getDifferences")
|
|
461
|
-
return () =>
|
|
466
|
+
return () => he(
|
|
462
467
|
a.getState().cogsStateStore[e],
|
|
463
468
|
a.getState().initialStateGlobal[e]
|
|
464
469
|
);
|
|
@@ -467,17 +472,17 @@ function Q(e, c, m, u) {
|
|
|
467
472
|
const n = a.getState().getInitialOptions(e), o = n?.sync;
|
|
468
473
|
if (!o)
|
|
469
474
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
470
|
-
const
|
|
475
|
+
const u = a.getState().getNestedState(e, []), s = n?.validation?.key;
|
|
471
476
|
try {
|
|
472
|
-
const i = await o.action(
|
|
477
|
+
const i = await o.action(u);
|
|
473
478
|
if (i && !i.success && i.errors && s) {
|
|
474
|
-
a.getState().removeValidationError(s), i.errors.forEach((
|
|
475
|
-
const
|
|
476
|
-
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);
|
|
477
482
|
});
|
|
478
483
|
const y = a.getState().stateComponents.get(e);
|
|
479
|
-
y && y.components.forEach((
|
|
480
|
-
|
|
484
|
+
y && y.components.forEach((k) => {
|
|
485
|
+
k.forceUpdate();
|
|
481
486
|
});
|
|
482
487
|
}
|
|
483
488
|
return i?.success && o.onSuccess ? o.onSuccess(i.data) : !i?.success && o.onError && o.onError(i.error), i;
|
|
@@ -486,20 +491,20 @@ function Q(e, c, m, u) {
|
|
|
486
491
|
}
|
|
487
492
|
};
|
|
488
493
|
if (r === "_status") {
|
|
489
|
-
const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e],
|
|
490
|
-
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";
|
|
491
496
|
}
|
|
492
497
|
if (r === "getStatus")
|
|
493
498
|
return function() {
|
|
494
499
|
const n = a().getNestedState(
|
|
495
500
|
e,
|
|
496
501
|
t
|
|
497
|
-
), o = a.getState().initialStateGlobal[e],
|
|
498
|
-
return U(n,
|
|
502
|
+
), o = a.getState().initialStateGlobal[e], u = W(o, t);
|
|
503
|
+
return U(n, u) ? "fresh" : "stale";
|
|
499
504
|
};
|
|
500
505
|
if (r === "removeStorage")
|
|
501
506
|
return () => {
|
|
502
|
-
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}`;
|
|
503
508
|
console.log("removing storage", s), s && localStorage.removeItem(s);
|
|
504
509
|
};
|
|
505
510
|
if (r === "showValidationErrors")
|
|
@@ -543,16 +548,16 @@ function Q(e, c, m, u) {
|
|
|
543
548
|
return (n) => {
|
|
544
549
|
const o = v?.filtered?.some(
|
|
545
550
|
(s) => s.join(".") === t.join(".")
|
|
546
|
-
),
|
|
547
|
-
return r !== "stateMapNoRender" && (d.clear(), I++),
|
|
548
|
-
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(
|
|
549
554
|
s,
|
|
550
555
|
[...t, y.toString()],
|
|
551
556
|
v
|
|
552
557
|
);
|
|
553
558
|
return n(
|
|
554
559
|
s,
|
|
555
|
-
|
|
560
|
+
k,
|
|
556
561
|
i,
|
|
557
562
|
S,
|
|
558
563
|
l(S, t, v)
|
|
@@ -560,7 +565,7 @@ function Q(e, c, m, u) {
|
|
|
560
565
|
});
|
|
561
566
|
};
|
|
562
567
|
if (r === "$stateMap")
|
|
563
|
-
return (n) =>
|
|
568
|
+
return (n) => te(Ue, {
|
|
564
569
|
proxy: {
|
|
565
570
|
_stateKey: e,
|
|
566
571
|
_path: t,
|
|
@@ -571,11 +576,11 @@ function Q(e, c, m, u) {
|
|
|
571
576
|
});
|
|
572
577
|
if (r === "stateFlattenOn")
|
|
573
578
|
return (n) => {
|
|
574
|
-
const
|
|
579
|
+
const u = v?.filtered?.some(
|
|
575
580
|
(i) => i.join(".") === t.join(".")
|
|
576
581
|
) ? S : a.getState().getNestedState(e, t);
|
|
577
582
|
d.clear(), I++;
|
|
578
|
-
const s =
|
|
583
|
+
const s = u.flatMap(
|
|
579
584
|
(i, y) => i[n] ?? []
|
|
580
585
|
);
|
|
581
586
|
return l(
|
|
@@ -586,9 +591,9 @@ function Q(e, c, m, u) {
|
|
|
586
591
|
};
|
|
587
592
|
if (r === "findWith")
|
|
588
593
|
return (n, o) => {
|
|
589
|
-
const
|
|
590
|
-
if (
|
|
591
|
-
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()];
|
|
592
597
|
return d.clear(), I++, l(s, i);
|
|
593
598
|
};
|
|
594
599
|
if (r === "index")
|
|
@@ -600,40 +605,40 @@ function Q(e, c, m, u) {
|
|
|
600
605
|
return () => {
|
|
601
606
|
const n = a.getState().getNestedState(e, t);
|
|
602
607
|
if (n.length === 0) return;
|
|
603
|
-
const o = n.length - 1,
|
|
604
|
-
return l(
|
|
608
|
+
const o = n.length - 1, u = n[o], s = [...t, o.toString()];
|
|
609
|
+
return l(u, s);
|
|
605
610
|
};
|
|
606
611
|
if (r === "insert")
|
|
607
|
-
return (n) => (E(t),
|
|
612
|
+
return (n) => (E(t), se(c, n, t, e), l(
|
|
608
613
|
a.getState().getNestedState(e, t),
|
|
609
614
|
t
|
|
610
615
|
));
|
|
611
616
|
if (r === "uniqueInsert")
|
|
612
|
-
return (n, o,
|
|
617
|
+
return (n, o, u) => {
|
|
613
618
|
const s = a.getState().getNestedState(e, t), i = G(n) ? n(s) : n;
|
|
614
619
|
let y = null;
|
|
615
|
-
if (!s.some((
|
|
620
|
+
if (!s.some((w) => {
|
|
616
621
|
if (o) {
|
|
617
|
-
const
|
|
618
|
-
(
|
|
622
|
+
const x = o.every(
|
|
623
|
+
(V) => U(w[V], i[V])
|
|
619
624
|
);
|
|
620
|
-
return
|
|
625
|
+
return x && (y = w), x;
|
|
621
626
|
}
|
|
622
|
-
const
|
|
623
|
-
return
|
|
627
|
+
const _ = U(w, i);
|
|
628
|
+
return _ && (y = w), _;
|
|
624
629
|
}))
|
|
625
|
-
E(t),
|
|
626
|
-
else if (
|
|
627
|
-
const
|
|
628
|
-
(
|
|
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
|
|
629
634
|
);
|
|
630
|
-
E(t),
|
|
635
|
+
E(t), Z(c, _, t);
|
|
631
636
|
}
|
|
632
637
|
};
|
|
633
638
|
if (r === "cut")
|
|
634
639
|
return (n, o) => {
|
|
635
640
|
if (!o?.waitForSync)
|
|
636
|
-
return E(t),
|
|
641
|
+
return E(t), X(c, t, e, n), l(
|
|
637
642
|
a.getState().getNestedState(e, t),
|
|
638
643
|
t
|
|
639
644
|
);
|
|
@@ -641,24 +646,24 @@ function Q(e, c, m, u) {
|
|
|
641
646
|
if (r === "cutByValue")
|
|
642
647
|
return (n) => {
|
|
643
648
|
for (let o = 0; o < S.length; o++)
|
|
644
|
-
S[o] === n &&
|
|
649
|
+
S[o] === n && X(c, t, e, o);
|
|
645
650
|
};
|
|
646
651
|
if (r === "toggleByValue")
|
|
647
652
|
return (n) => {
|
|
648
|
-
const o = S.findIndex((
|
|
649
|
-
o > -1 ?
|
|
653
|
+
const o = S.findIndex((u) => u === n);
|
|
654
|
+
o > -1 ? X(c, t, e, o) : se(c, n, t, e);
|
|
650
655
|
};
|
|
651
656
|
if (r === "stateFilter")
|
|
652
657
|
return (n) => {
|
|
653
658
|
const o = S.map((i, y) => ({
|
|
654
659
|
...i,
|
|
655
660
|
__origIndex: y.toString()
|
|
656
|
-
})),
|
|
661
|
+
})), u = [], s = [];
|
|
657
662
|
for (let i = 0; i < o.length; i++)
|
|
658
|
-
n(o[i], i) && (
|
|
663
|
+
n(o[i], i) && (u.push(i), s.push(o[i]));
|
|
659
664
|
return d.clear(), I++, l(s, t, {
|
|
660
665
|
filtered: [...v?.filtered || [], t],
|
|
661
|
-
validIndices:
|
|
666
|
+
validIndices: u
|
|
662
667
|
// Always pass validIndices, even if empty
|
|
663
668
|
});
|
|
664
669
|
};
|
|
@@ -667,7 +672,7 @@ function Q(e, c, m, u) {
|
|
|
667
672
|
if (!isNaN(Number(J))) {
|
|
668
673
|
const n = t.slice(0, -1), o = a.getState().getNestedState(e, n);
|
|
669
674
|
if (Array.isArray(o) && r === "cut")
|
|
670
|
-
return () =>
|
|
675
|
+
return () => X(
|
|
671
676
|
c,
|
|
672
677
|
n,
|
|
673
678
|
e,
|
|
@@ -677,19 +682,19 @@ function Q(e, c, m, u) {
|
|
|
677
682
|
if (r === "get")
|
|
678
683
|
return () => a.getState().getNestedState(e, t);
|
|
679
684
|
if (r === "$derive")
|
|
680
|
-
return (n) =>
|
|
685
|
+
return (n) => ce({
|
|
681
686
|
_stateKey: e,
|
|
682
687
|
_path: t,
|
|
683
688
|
_effect: n.toString()
|
|
684
689
|
});
|
|
685
690
|
if (r === "$derive")
|
|
686
|
-
return (n) =>
|
|
691
|
+
return (n) => ce({
|
|
687
692
|
_stateKey: e,
|
|
688
693
|
_path: t,
|
|
689
694
|
_effect: n.toString()
|
|
690
695
|
});
|
|
691
696
|
if (r === "$get")
|
|
692
|
-
return () =>
|
|
697
|
+
return () => ce({
|
|
693
698
|
_stateKey: e,
|
|
694
699
|
_path: t
|
|
695
700
|
});
|
|
@@ -698,28 +703,28 @@ function Q(e, c, m, u) {
|
|
|
698
703
|
return a.getState().getSyncInfo(n);
|
|
699
704
|
}
|
|
700
705
|
if (r == "getLocalStorage")
|
|
701
|
-
return (n) =>
|
|
706
|
+
return (n) => ne(g + "-" + e + "-" + n);
|
|
702
707
|
if (r === "_selected") {
|
|
703
|
-
const n = t.slice(0, -1), o = n.join("."),
|
|
704
|
-
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;
|
|
705
710
|
}
|
|
706
711
|
if (r === "setSelected")
|
|
707
712
|
return (n) => {
|
|
708
|
-
const o = t.slice(0, -1),
|
|
709
|
-
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);
|
|
710
715
|
const i = a.getState().getNestedState(e, [...o]);
|
|
711
|
-
|
|
716
|
+
Z(c, i, o), E(o);
|
|
712
717
|
};
|
|
713
718
|
if (r === "toggleSelected")
|
|
714
719
|
return () => {
|
|
715
|
-
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);
|
|
716
721
|
a.getState().setSelectedIndex(
|
|
717
722
|
e,
|
|
718
|
-
|
|
723
|
+
u,
|
|
719
724
|
s === o ? void 0 : o
|
|
720
725
|
);
|
|
721
726
|
const i = a.getState().getNestedState(e, [...n]);
|
|
722
|
-
|
|
727
|
+
Z(c, i, n), E(n);
|
|
723
728
|
};
|
|
724
729
|
if (t.length == 0) {
|
|
725
730
|
if (r === "validateZodSchema")
|
|
@@ -730,17 +735,17 @@ function Q(e, c, m, u) {
|
|
|
730
735
|
if (!n?.key)
|
|
731
736
|
throw new Error("Validation key not found");
|
|
732
737
|
M(n.key);
|
|
733
|
-
const
|
|
738
|
+
const u = a.getState().cogsStateStore[e];
|
|
734
739
|
try {
|
|
735
740
|
const s = a.getState().getValidationErrors(n.key);
|
|
736
741
|
s && s.length > 0 && s.forEach(([y]) => {
|
|
737
742
|
y && y.startsWith(n.key) && M(y);
|
|
738
743
|
});
|
|
739
|
-
const i = n.zodSchema.safeParse(
|
|
740
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
741
|
-
const
|
|
742
|
-
o(
|
|
743
|
-
}),
|
|
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);
|
|
744
749
|
} catch (s) {
|
|
745
750
|
return console.error("Zod schema validation failed", s), !1;
|
|
746
751
|
}
|
|
@@ -749,7 +754,7 @@ function Q(e, c, m, u) {
|
|
|
749
754
|
if (r === "getComponents")
|
|
750
755
|
return () => a().stateComponents.get(e);
|
|
751
756
|
if (r === "getAllFormRefs")
|
|
752
|
-
return () =>
|
|
757
|
+
return () => ye.getState().getFormRefsByStateKey(e);
|
|
753
758
|
if (r === "_initialState")
|
|
754
759
|
return a.getState().initialStateGlobal[e];
|
|
755
760
|
if (r === "_serverState")
|
|
@@ -762,13 +767,13 @@ function Q(e, c, m, u) {
|
|
|
762
767
|
if (r === "removeValidation") return f.removeValidation;
|
|
763
768
|
}
|
|
764
769
|
if (r === "getFormRef")
|
|
765
|
-
return () =>
|
|
770
|
+
return () => ye.getState().getFormRef(e + "." + t.join("."));
|
|
766
771
|
if (r === "validationWrapper")
|
|
767
772
|
return ({
|
|
768
773
|
children: n,
|
|
769
774
|
hideMessage: o
|
|
770
|
-
}) => /* @__PURE__ */
|
|
771
|
-
|
|
775
|
+
}) => /* @__PURE__ */ me(
|
|
776
|
+
Ve,
|
|
772
777
|
{
|
|
773
778
|
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
774
779
|
path: t,
|
|
@@ -784,21 +789,21 @@ function Q(e, c, m, u) {
|
|
|
784
789
|
if (r === "update")
|
|
785
790
|
return (n, o) => {
|
|
786
791
|
if (o?.debounce)
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
const
|
|
790
|
-
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);
|
|
791
796
|
}, o.debounce);
|
|
792
797
|
else {
|
|
793
|
-
|
|
794
|
-
const
|
|
795
|
-
o?.afterUpdate && o.afterUpdate(
|
|
798
|
+
Z(c, n, t, "");
|
|
799
|
+
const u = a.getState().getNestedState(e, t);
|
|
800
|
+
o?.afterUpdate && o.afterUpdate(u);
|
|
796
801
|
}
|
|
797
802
|
E(t);
|
|
798
803
|
};
|
|
799
804
|
if (r === "formElement")
|
|
800
|
-
return (n, o) => /* @__PURE__ */
|
|
801
|
-
|
|
805
|
+
return (n, o) => /* @__PURE__ */ me(
|
|
806
|
+
Ce,
|
|
802
807
|
{
|
|
803
808
|
setState: c,
|
|
804
809
|
stateKey: e,
|
|
@@ -807,23 +812,23 @@ function Q(e, c, m, u) {
|
|
|
807
812
|
formOpts: o
|
|
808
813
|
}
|
|
809
814
|
);
|
|
810
|
-
const
|
|
811
|
-
return l(L,
|
|
815
|
+
const H = [...t, r], L = a.getState().getNestedState(e, H);
|
|
816
|
+
return l(L, H, v);
|
|
812
817
|
}
|
|
813
|
-
},
|
|
814
|
-
return d.set(
|
|
815
|
-
proxy:
|
|
818
|
+
}, $ = new Proxy(b, j);
|
|
819
|
+
return d.set(T, {
|
|
820
|
+
proxy: $,
|
|
816
821
|
stateVersion: I
|
|
817
|
-
}),
|
|
822
|
+
}), $;
|
|
818
823
|
}
|
|
819
824
|
return l(
|
|
820
825
|
a.getState().getNestedState(e, [])
|
|
821
826
|
);
|
|
822
827
|
}
|
|
823
|
-
function
|
|
824
|
-
return
|
|
828
|
+
function ce(e) {
|
|
829
|
+
return te(Me, { proxy: e });
|
|
825
830
|
}
|
|
826
|
-
function
|
|
831
|
+
function Ue({
|
|
827
832
|
proxy: e,
|
|
828
833
|
rebuildStateShape: c
|
|
829
834
|
}) {
|
|
@@ -835,14 +840,14 @@ function De({
|
|
|
835
840
|
(d, I, E, f, l) => e._mapFn(d, I, E, f, l)
|
|
836
841
|
) : null;
|
|
837
842
|
}
|
|
838
|
-
function
|
|
843
|
+
function Me({
|
|
839
844
|
proxy: e
|
|
840
845
|
}) {
|
|
841
|
-
const c =
|
|
842
|
-
return
|
|
843
|
-
const
|
|
844
|
-
if (!
|
|
845
|
-
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);
|
|
846
851
|
let f = d.getAttribute("data-parent-id");
|
|
847
852
|
f || (f = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", f));
|
|
848
853
|
const S = {
|
|
@@ -860,41 +865,41 @@ function Ue({
|
|
|
860
865
|
"state",
|
|
861
866
|
`return (${e._effect})(state)`
|
|
862
867
|
)(t);
|
|
863
|
-
} catch (
|
|
864
|
-
console.error("Error evaluating effect function during mount:",
|
|
868
|
+
} catch (b) {
|
|
869
|
+
console.error("Error evaluating effect function during mount:", b), v = t;
|
|
865
870
|
}
|
|
866
871
|
else
|
|
867
872
|
v = t;
|
|
868
873
|
v !== null && typeof v == "object" && (v = JSON.stringify(v));
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
874
|
+
const T = document.createTextNode(String(v));
|
|
875
|
+
g.replaceWith(T);
|
|
876
|
+
}, [e._stateKey, e._path.join("."), e._effect]), te("span", {
|
|
872
877
|
ref: c,
|
|
873
878
|
style: { display: "none" },
|
|
874
879
|
"data-signal-id": m
|
|
875
880
|
});
|
|
876
881
|
}
|
|
877
882
|
function Ke(e) {
|
|
878
|
-
const c =
|
|
883
|
+
const c = we(
|
|
879
884
|
(m) => {
|
|
880
|
-
const
|
|
885
|
+
const g = a.getState().stateComponents.get(e._stateKey) || {
|
|
881
886
|
components: /* @__PURE__ */ new Map()
|
|
882
887
|
};
|
|
883
|
-
return
|
|
888
|
+
return g.components.set(e._stateKey, {
|
|
884
889
|
forceUpdate: m,
|
|
885
890
|
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
886
|
-
}), () =>
|
|
891
|
+
}), () => g.components.delete(e._stateKey);
|
|
887
892
|
},
|
|
888
893
|
() => a.getState().getNestedState(e._stateKey, e._path)
|
|
889
894
|
);
|
|
890
|
-
return
|
|
895
|
+
return te("text", {}, String(c));
|
|
891
896
|
}
|
|
892
897
|
export {
|
|
893
|
-
|
|
898
|
+
ce as $cogsSignal,
|
|
894
899
|
Ke as $cogsSignalStore,
|
|
895
900
|
Ye as addStateOptions,
|
|
896
901
|
Xe as createCogsState,
|
|
897
902
|
Qe as notifyComponent,
|
|
898
|
-
|
|
903
|
+
De as useCogsStateFn
|
|
899
904
|
};
|
|
900
905
|
//# sourceMappingURL=CogsState.jsx.map
|