cogsbox-state 0.5.50 → 0.5.52
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 +335 -349
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -4,85 +4,71 @@ import { useState as Y, useRef as z, useEffect as K, useLayoutEffect as vt, useM
|
|
|
4
4
|
import { transformStateFunc as _t, isFunction as ft, getNestedValue as L, isDeepEqual as G, debounce as pt } from "./utility.js";
|
|
5
5
|
import { pushFunc as st, updateFn as q, cutFunc as ct, ValidationWrapper as wt, FormControlComponent as Nt } from "./Functions.jsx";
|
|
6
6
|
import "zod";
|
|
7
|
-
import { getGlobalStore as
|
|
7
|
+
import { getGlobalStore as a, formRefStore as lt } from "./store.js";
|
|
8
8
|
import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
|
|
9
9
|
import tt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
|
-
function dt(t,
|
|
11
|
-
const
|
|
12
|
-
return console.log("setAndMergeOptions", t,
|
|
13
|
-
...
|
|
14
|
-
...
|
|
10
|
+
function dt(t, o) {
|
|
11
|
+
const u = a.getState().getInitialOptions, f = a.getState().setInitialStateOptions, c = u(t) || {};
|
|
12
|
+
return console.log("setAndMergeOptions", t, c, o), f(t, {
|
|
13
|
+
...c,
|
|
14
|
+
...o
|
|
15
15
|
}), {
|
|
16
|
-
...
|
|
17
|
-
...
|
|
16
|
+
...c,
|
|
17
|
+
...o
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
function ut({
|
|
21
21
|
stateKey: t,
|
|
22
|
-
options:
|
|
23
|
-
initialOptionsPart:
|
|
22
|
+
options: o,
|
|
23
|
+
initialOptionsPart: u
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
25
|
+
const f = et(t) || {}, c = u[t] || {}, p = a.getState().setInitialStateOptions, _ = { ...c, ...f };
|
|
26
26
|
let y = !1;
|
|
27
|
-
if (
|
|
28
|
-
for (const
|
|
29
|
-
_.hasOwnProperty(
|
|
30
|
-
"localStorage needToAdd",
|
|
31
|
-
l,
|
|
32
|
-
a[l]
|
|
33
|
-
), y = !0, _[l] = a[l]) : (y = !0, console.log(
|
|
34
|
-
"setOptions needToAdd",
|
|
35
|
-
l,
|
|
36
|
-
a[l]
|
|
37
|
-
), _[l] = a[l]);
|
|
27
|
+
if (o)
|
|
28
|
+
for (const g in o)
|
|
29
|
+
_.hasOwnProperty(g) ? g == "localStorage" && _[g] !== o[g] && (y = !0, _[g] = o[g]) : (y = !0, _[g] = o[g]);
|
|
38
30
|
return y && p(t, _), _;
|
|
39
31
|
}
|
|
40
|
-
function Wt(t, { formElements:
|
|
41
|
-
return { initialState: t, formElements:
|
|
32
|
+
function Wt(t, { formElements: o, validation: u }) {
|
|
33
|
+
return { initialState: t, formElements: o, validation: u };
|
|
42
34
|
}
|
|
43
|
-
const qt = (t,
|
|
44
|
-
let
|
|
45
|
-
const [
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
...
|
|
35
|
+
const qt = (t, o) => {
|
|
36
|
+
let u = t;
|
|
37
|
+
const [f, c] = _t(u);
|
|
38
|
+
(o?.formElements || o?.validation) && Object.keys(c).forEach((y) => {
|
|
39
|
+
c[y] = c[y] || {}, c[y].formElements = {
|
|
40
|
+
...o.formElements,
|
|
49
41
|
// Global defaults first
|
|
50
|
-
...
|
|
51
|
-
...
|
|
42
|
+
...o?.validation,
|
|
43
|
+
...c[y].formElements || {}
|
|
52
44
|
// State-specific overrides
|
|
53
45
|
};
|
|
54
|
-
}),
|
|
55
|
-
const p = (y,
|
|
56
|
-
const [w] = Y(
|
|
46
|
+
}), a.getState().setInitialStates(f);
|
|
47
|
+
const p = (y, g) => {
|
|
48
|
+
const [w] = Y(g?.componentId ?? tt());
|
|
49
|
+
ut({
|
|
57
50
|
stateKey: y,
|
|
58
|
-
options:
|
|
59
|
-
initialOptionsPart:
|
|
51
|
+
options: g,
|
|
52
|
+
initialOptionsPart: c
|
|
60
53
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
y,
|
|
64
|
-
l,
|
|
65
|
-
s,
|
|
66
|
-
c
|
|
67
|
-
);
|
|
68
|
-
const e = o.getState().cogsStateStore[y] || g[y], v = l?.modifyState ? l.modifyState(e) : e, [V, F] = jt(
|
|
69
|
-
v,
|
|
54
|
+
const s = a.getState().cogsStateStore[y] || f[y], e = g?.modifyState ? g.modifyState(s) : s, [I, V] = jt(
|
|
55
|
+
e,
|
|
70
56
|
{
|
|
71
57
|
stateKey: y,
|
|
72
|
-
syncUpdate:
|
|
58
|
+
syncUpdate: g?.syncUpdate,
|
|
73
59
|
componentId: w,
|
|
74
|
-
localStorage:
|
|
75
|
-
middleware:
|
|
76
|
-
enabledSync:
|
|
77
|
-
reactiveType:
|
|
78
|
-
reactiveDeps:
|
|
79
|
-
initState:
|
|
60
|
+
localStorage: g?.localStorage,
|
|
61
|
+
middleware: g?.middleware,
|
|
62
|
+
enabledSync: g?.enabledSync,
|
|
63
|
+
reactiveType: g?.reactiveType,
|
|
64
|
+
reactiveDeps: g?.reactiveDeps,
|
|
65
|
+
initState: g?.initState
|
|
80
66
|
}
|
|
81
67
|
);
|
|
82
|
-
return
|
|
68
|
+
return V;
|
|
83
69
|
};
|
|
84
|
-
function _(y,
|
|
85
|
-
ut({ stateKey: y, options:
|
|
70
|
+
function _(y, g) {
|
|
71
|
+
ut({ stateKey: y, options: g, initialOptionsPart: c });
|
|
86
72
|
}
|
|
87
73
|
return { useCogsState: p, setCogsOptions: _ };
|
|
88
74
|
}, {
|
|
@@ -94,364 +80,364 @@ const qt = (t, a) => {
|
|
|
94
80
|
setStateLog: ht,
|
|
95
81
|
updateInitialStateGlobal: nt,
|
|
96
82
|
addValidationError: At,
|
|
97
|
-
removeValidationError:
|
|
98
|
-
setServerSyncActions:
|
|
99
|
-
} =
|
|
83
|
+
removeValidationError: O,
|
|
84
|
+
setServerSyncActions: Ct
|
|
85
|
+
} = a.getState(), St = (t) => {
|
|
100
86
|
if (!t) return null;
|
|
101
87
|
try {
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
} catch (
|
|
105
|
-
return console.error("Error loading from localStorage:",
|
|
88
|
+
const o = window.localStorage.getItem(t);
|
|
89
|
+
return o ? JSON.parse(o) : null;
|
|
90
|
+
} catch (o) {
|
|
91
|
+
return console.error("Error loading from localStorage:", o), null;
|
|
106
92
|
}
|
|
107
|
-
},
|
|
108
|
-
if (
|
|
93
|
+
}, Tt = (t, o, u, f) => {
|
|
94
|
+
if (u.log && console.log(
|
|
109
95
|
"saving to localstorage",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
),
|
|
114
|
-
const
|
|
96
|
+
o,
|
|
97
|
+
u.localStorage?.key,
|
|
98
|
+
f
|
|
99
|
+
), u.localStorage?.key && f) {
|
|
100
|
+
const c = {
|
|
115
101
|
state: t,
|
|
116
102
|
lastUpdated: Date.now(),
|
|
117
|
-
lastSyncedWithServer:
|
|
118
|
-
baseServerState:
|
|
119
|
-
}, p = `${
|
|
120
|
-
window.localStorage.setItem(p, JSON.stringify(
|
|
103
|
+
lastSyncedWithServer: a.getState().serverSyncLog[o]?.[0]?.timeStamp,
|
|
104
|
+
baseServerState: a.getState().serverState[o]
|
|
105
|
+
}, p = `${f}-${o}-${u.localStorage?.key}`;
|
|
106
|
+
window.localStorage.setItem(p, JSON.stringify(c));
|
|
121
107
|
}
|
|
122
|
-
}, Ft = (t,
|
|
108
|
+
}, Ft = (t, o, u, f, c, p) => {
|
|
123
109
|
const _ = {
|
|
124
|
-
initialState:
|
|
110
|
+
initialState: o,
|
|
125
111
|
updaterState: Z(
|
|
126
112
|
t,
|
|
127
|
-
|
|
128
|
-
|
|
113
|
+
f,
|
|
114
|
+
c,
|
|
129
115
|
p
|
|
130
116
|
),
|
|
131
|
-
state:
|
|
117
|
+
state: u
|
|
132
118
|
};
|
|
133
119
|
J(() => {
|
|
134
120
|
nt(t, _.initialState), B(t, _.updaterState), x(t, _.state);
|
|
135
121
|
});
|
|
136
122
|
}, mt = (t) => {
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
const o = a.getState().stateComponents.get(t);
|
|
124
|
+
if (!o) return;
|
|
125
|
+
const u = /* @__PURE__ */ new Set();
|
|
126
|
+
o.components.forEach((f) => {
|
|
127
|
+
u.add(() => f.forceUpdate());
|
|
142
128
|
}), queueMicrotask(() => {
|
|
143
129
|
J(() => {
|
|
144
|
-
|
|
130
|
+
u.forEach((f) => f());
|
|
145
131
|
});
|
|
146
132
|
});
|
|
147
|
-
}, zt = (t,
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
const
|
|
151
|
-
|
|
133
|
+
}, zt = (t, o) => {
|
|
134
|
+
const u = a.getState().stateComponents.get(t);
|
|
135
|
+
if (u) {
|
|
136
|
+
const f = `${t}////${o}`, c = u.components.get(f);
|
|
137
|
+
c && c.forceUpdate();
|
|
152
138
|
}
|
|
153
139
|
};
|
|
154
140
|
function jt(t, {
|
|
155
|
-
stateKey:
|
|
156
|
-
serverSync:
|
|
157
|
-
localStorage:
|
|
158
|
-
formElements:
|
|
141
|
+
stateKey: o,
|
|
142
|
+
serverSync: u,
|
|
143
|
+
localStorage: f,
|
|
144
|
+
formElements: c,
|
|
159
145
|
middleware: p,
|
|
160
146
|
reactiveDeps: _,
|
|
161
147
|
reactiveType: y,
|
|
162
|
-
componentId:
|
|
148
|
+
componentId: g,
|
|
163
149
|
initState: w,
|
|
164
|
-
syncUpdate:
|
|
150
|
+
syncUpdate: s
|
|
165
151
|
} = {}) {
|
|
166
|
-
const [e,
|
|
167
|
-
let
|
|
168
|
-
const [
|
|
169
|
-
$.current = et(
|
|
170
|
-
if (
|
|
171
|
-
x(
|
|
152
|
+
const [e, I] = Y({}), { sessionId: V } = Vt();
|
|
153
|
+
let k = !o;
|
|
154
|
+
const [l] = Y(o ?? tt()), U = a.getState().stateLog[l], P = z(/* @__PURE__ */ new Set()), i = z(g ?? tt()), $ = z(null);
|
|
155
|
+
$.current = et(l), K(() => {
|
|
156
|
+
if (s && s.stateKey === l && s.path?.[0]) {
|
|
157
|
+
x(l, (r) => ({
|
|
172
158
|
...r,
|
|
173
|
-
[
|
|
159
|
+
[s.path[0]]: s.newValue
|
|
174
160
|
}));
|
|
175
|
-
const n = `${
|
|
176
|
-
|
|
177
|
-
timeStamp:
|
|
178
|
-
userId:
|
|
161
|
+
const n = `${s.stateKey}:${s.path.join(".")}`;
|
|
162
|
+
a.getState().setSyncInfo(n, {
|
|
163
|
+
timeStamp: s.timeStamp,
|
|
164
|
+
userId: s.userId
|
|
179
165
|
});
|
|
180
166
|
}
|
|
181
|
-
}, [
|
|
182
|
-
dt(
|
|
167
|
+
}, [s]), K(() => {
|
|
168
|
+
dt(l, {
|
|
183
169
|
initState: w
|
|
184
170
|
});
|
|
185
171
|
const n = $.current;
|
|
186
172
|
let r = null;
|
|
187
173
|
n.log && console.log("newoptions", n), n.localStorage?.key && V && (r = St(
|
|
188
|
-
V + "-" +
|
|
174
|
+
V + "-" + l + "-" + n.localStorage?.key
|
|
189
175
|
));
|
|
190
|
-
let
|
|
191
|
-
w?.initialState && (
|
|
192
|
-
|
|
176
|
+
let d = null;
|
|
177
|
+
w?.initialState && (d = w?.initialState, r && r.lastUpdated > (r.lastSyncedWithServer || 0) && (d = r.state), Ft(
|
|
178
|
+
l,
|
|
193
179
|
w?.initialState,
|
|
194
|
-
|
|
180
|
+
d,
|
|
195
181
|
R,
|
|
196
182
|
i.current,
|
|
197
183
|
V
|
|
198
|
-
), mt(
|
|
184
|
+
), mt(l), I({}));
|
|
199
185
|
}, [...w?.dependencies || []]), vt(() => {
|
|
200
|
-
|
|
201
|
-
serverSync:
|
|
202
|
-
formElements:
|
|
186
|
+
k && dt(l, {
|
|
187
|
+
serverSync: u,
|
|
188
|
+
formElements: c,
|
|
203
189
|
initState: w,
|
|
204
|
-
localStorage:
|
|
190
|
+
localStorage: f,
|
|
205
191
|
middleware: p
|
|
206
192
|
});
|
|
207
|
-
const n = `${
|
|
193
|
+
const n = `${l}////${i.current}`, r = a.getState().stateComponents.get(l) || {
|
|
208
194
|
components: /* @__PURE__ */ new Map()
|
|
209
195
|
};
|
|
210
196
|
return r.components.set(n, {
|
|
211
|
-
forceUpdate: () =>
|
|
197
|
+
forceUpdate: () => I({}),
|
|
212
198
|
paths: /* @__PURE__ */ new Set(),
|
|
213
199
|
deps: [],
|
|
214
200
|
depsFunction: _ || void 0,
|
|
215
201
|
reactiveType: y ?? ["component", "deps"]
|
|
216
|
-
}),
|
|
217
|
-
const
|
|
218
|
-
r && (r.components.delete(
|
|
202
|
+
}), a.getState().stateComponents.set(l, r), I({}), () => {
|
|
203
|
+
const d = `${l}////${i.current}`;
|
|
204
|
+
r && (r.components.delete(d), r.components.size === 0 && a.getState().stateComponents.delete(l));
|
|
219
205
|
};
|
|
220
206
|
}, []);
|
|
221
|
-
const R = (n, r,
|
|
207
|
+
const R = (n, r, d, S) => {
|
|
222
208
|
if (Array.isArray(r)) {
|
|
223
|
-
const m = `${
|
|
209
|
+
const m = `${l}-${r.join(".")}`;
|
|
224
210
|
P.current.add(m);
|
|
225
211
|
}
|
|
226
|
-
x(
|
|
227
|
-
const E = ft(n) ? n(m) : n,
|
|
228
|
-
if (
|
|
229
|
-
let
|
|
230
|
-
if ((!
|
|
231
|
-
const h = r.slice(0, -1),
|
|
232
|
-
if (Array.isArray(
|
|
233
|
-
|
|
234
|
-
const N = `${
|
|
235
|
-
|
|
212
|
+
x(l, (m) => {
|
|
213
|
+
const E = ft(n) ? n(m) : n, j = `${l}-${r.join(".")}`;
|
|
214
|
+
if (j) {
|
|
215
|
+
let b = !1, v = a.getState().signalDomElements.get(j);
|
|
216
|
+
if ((!v || v.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
|
|
217
|
+
const h = r.slice(0, -1), C = L(E, h);
|
|
218
|
+
if (Array.isArray(C)) {
|
|
219
|
+
b = !0;
|
|
220
|
+
const N = `${l}-${h.join(".")}`;
|
|
221
|
+
v = a.getState().signalDomElements.get(N);
|
|
236
222
|
}
|
|
237
223
|
}
|
|
238
|
-
if (
|
|
239
|
-
const h =
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
`[data-parent-id="${
|
|
224
|
+
if (v) {
|
|
225
|
+
const h = b ? L(E, r.slice(0, -1)) : L(E, r);
|
|
226
|
+
v.forEach(({ parentId: C, position: N, effect: D }) => {
|
|
227
|
+
const T = document.querySelector(
|
|
228
|
+
`[data-parent-id="${C}"]`
|
|
243
229
|
);
|
|
244
|
-
if (
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
230
|
+
if (T) {
|
|
231
|
+
const ot = Array.from(T.childNodes);
|
|
232
|
+
if (ot[N]) {
|
|
247
233
|
const yt = D ? new Function("state", `return (${D})(state)`)(h) : h;
|
|
248
|
-
|
|
234
|
+
ot[N].textContent = String(yt);
|
|
249
235
|
}
|
|
250
236
|
}
|
|
251
237
|
});
|
|
252
238
|
}
|
|
253
239
|
}
|
|
254
|
-
|
|
240
|
+
d.updateType === "update" && (S || $.current?.validationKey) && r && O(
|
|
255
241
|
(S || $.current?.validationKey) + "." + r.join(".")
|
|
256
242
|
);
|
|
257
243
|
const A = r.slice(0, r.length - 1);
|
|
258
|
-
|
|
244
|
+
d.updateType === "cut" && $.current?.validationKey && O(
|
|
259
245
|
$.current?.validationKey + "." + A.join(".")
|
|
260
|
-
),
|
|
246
|
+
), d.updateType === "insert" && $.current?.validationKey && $t(
|
|
261
247
|
$.current?.validationKey + "." + A.join(".")
|
|
262
|
-
).filter(([
|
|
263
|
-
let
|
|
264
|
-
if (
|
|
265
|
-
let N =
|
|
266
|
-
|
|
248
|
+
).filter(([v, h]) => {
|
|
249
|
+
let C = v?.split(".").length;
|
|
250
|
+
if (v == A.join(".") && C == A.length - 1) {
|
|
251
|
+
let N = v + "." + A;
|
|
252
|
+
O(v), At(N, h);
|
|
267
253
|
}
|
|
268
254
|
});
|
|
269
|
-
const
|
|
255
|
+
const M = L(m, r), F = L(E, r), W = d.updateType === "update" ? r.join(".") : [...r].slice(0, -1).join("."), rt = a.getState().stateComponents.get(l);
|
|
270
256
|
if (rt)
|
|
271
|
-
for (const [
|
|
257
|
+
for (const [b, v] of rt.components.entries()) {
|
|
272
258
|
let h = !1;
|
|
273
|
-
const
|
|
274
|
-
if (!
|
|
275
|
-
if (
|
|
276
|
-
|
|
259
|
+
const C = Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"];
|
|
260
|
+
if (!C.includes("none")) {
|
|
261
|
+
if (C.includes("all")) {
|
|
262
|
+
v.forceUpdate();
|
|
277
263
|
continue;
|
|
278
264
|
}
|
|
279
|
-
if (
|
|
280
|
-
const N =
|
|
281
|
-
typeof N == "boolean" ? N && (h = !0) : G(
|
|
265
|
+
if (C.includes("component") && v.paths && (v.paths.has(W) || v.paths.has("")) && (h = !0), !h && C.includes("deps") && v.depsFunction) {
|
|
266
|
+
const N = v.depsFunction(E);
|
|
267
|
+
typeof N == "boolean" ? N && (h = !0) : G(v.deps, N) || (v.deps = N, h = !0);
|
|
282
268
|
}
|
|
283
|
-
h &&
|
|
269
|
+
h && v.forceUpdate();
|
|
284
270
|
}
|
|
285
271
|
}
|
|
286
|
-
const
|
|
272
|
+
const at = {
|
|
287
273
|
timeStamp: Date.now(),
|
|
288
|
-
stateKey:
|
|
274
|
+
stateKey: l,
|
|
289
275
|
path: r,
|
|
290
|
-
updateType:
|
|
276
|
+
updateType: d.updateType,
|
|
291
277
|
status: "new",
|
|
292
|
-
oldValue:
|
|
293
|
-
newValue:
|
|
278
|
+
oldValue: M,
|
|
279
|
+
newValue: F
|
|
294
280
|
};
|
|
295
|
-
if (ht(
|
|
296
|
-
const h = [...
|
|
297
|
-
const D = `${N.stateKey}:${JSON.stringify(N.path)}`,
|
|
298
|
-
return
|
|
281
|
+
if (ht(l, (b) => {
|
|
282
|
+
const h = [...b ?? [], at].reduce((C, N) => {
|
|
283
|
+
const D = `${N.stateKey}:${JSON.stringify(N.path)}`, T = C.get(D);
|
|
284
|
+
return T ? (T.timeStamp = Math.max(T.timeStamp, N.timeStamp), T.newValue = N.newValue, T.oldValue = T.oldValue ?? N.oldValue, T.updateType = N.updateType) : C.set(D, { ...N }), C;
|
|
299
285
|
}, /* @__PURE__ */ new Map());
|
|
300
286
|
return Array.from(h.values());
|
|
301
|
-
}),
|
|
287
|
+
}), Tt(
|
|
302
288
|
E,
|
|
303
|
-
|
|
289
|
+
l,
|
|
304
290
|
$.current,
|
|
305
291
|
V
|
|
306
292
|
), p && p({
|
|
307
293
|
updateLog: U,
|
|
308
|
-
update:
|
|
294
|
+
update: at
|
|
309
295
|
}), $.current?.serverSync) {
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
syncKey: typeof
|
|
313
|
-
rollBackState:
|
|
314
|
-
actionTimeStamp: Date.now() + (
|
|
296
|
+
const b = a.getState().serverState[l], v = $.current?.serverSync;
|
|
297
|
+
Ct(l, {
|
|
298
|
+
syncKey: typeof v.syncKey == "string" ? v.syncKey : v.syncKey({ state: E }),
|
|
299
|
+
rollBackState: b,
|
|
300
|
+
actionTimeStamp: Date.now() + (v.debounce ?? 3e3),
|
|
315
301
|
status: "waiting"
|
|
316
302
|
});
|
|
317
303
|
}
|
|
318
304
|
return E;
|
|
319
305
|
});
|
|
320
306
|
};
|
|
321
|
-
|
|
322
|
-
|
|
307
|
+
a.getState().updaterState[l] || (B(
|
|
308
|
+
l,
|
|
323
309
|
Z(
|
|
324
|
-
|
|
310
|
+
l,
|
|
325
311
|
R,
|
|
326
312
|
i.current,
|
|
327
313
|
V
|
|
328
314
|
)
|
|
329
|
-
),
|
|
315
|
+
), a.getState().cogsStateStore[l] || x(l, t), a.getState().initialStateGlobal[l] || nt(l, t));
|
|
330
316
|
const Q = It(() => Z(
|
|
331
|
-
|
|
317
|
+
l,
|
|
332
318
|
R,
|
|
333
319
|
i.current,
|
|
334
320
|
V
|
|
335
|
-
), [
|
|
336
|
-
return [gt(
|
|
321
|
+
), [l]);
|
|
322
|
+
return [gt(l), Q];
|
|
337
323
|
}
|
|
338
|
-
function Z(t,
|
|
339
|
-
const
|
|
324
|
+
function Z(t, o, u, f) {
|
|
325
|
+
const c = /* @__PURE__ */ new Map();
|
|
340
326
|
let p = 0;
|
|
341
|
-
const _ = (
|
|
342
|
-
const e =
|
|
343
|
-
for (const [
|
|
344
|
-
(
|
|
327
|
+
const _ = (s) => {
|
|
328
|
+
const e = s.join(".");
|
|
329
|
+
for (const [I] of c)
|
|
330
|
+
(I === e || I.startsWith(e + ".")) && c.delete(I);
|
|
345
331
|
p++;
|
|
346
|
-
}, y = /* @__PURE__ */ new Map(),
|
|
347
|
-
removeValidation: (
|
|
348
|
-
|
|
332
|
+
}, y = /* @__PURE__ */ new Map(), g = {
|
|
333
|
+
removeValidation: (s) => {
|
|
334
|
+
s?.validationKey && O(s.validationKey);
|
|
349
335
|
},
|
|
350
|
-
revertToInitialState: (
|
|
351
|
-
const e =
|
|
352
|
-
e?.key &&
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
const V = w(
|
|
336
|
+
revertToInitialState: (s) => {
|
|
337
|
+
const e = a.getState().getInitialOptions(t)?.validation;
|
|
338
|
+
e?.key && O(e?.key), s?.validationKey && O(s.validationKey);
|
|
339
|
+
const I = a.getState().initialStateGlobal[t];
|
|
340
|
+
c.clear(), p++;
|
|
341
|
+
const V = w(I, []);
|
|
356
342
|
J(() => {
|
|
357
|
-
B(t, V), x(t,
|
|
358
|
-
const
|
|
359
|
-
|
|
343
|
+
B(t, V), x(t, I);
|
|
344
|
+
const k = a.getState().stateComponents.get(t);
|
|
345
|
+
k && k.components.forEach((U) => {
|
|
360
346
|
U.forceUpdate();
|
|
361
347
|
});
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
348
|
+
const l = et(t);
|
|
349
|
+
l?.localStorage?.key && localStorage.removeItem(
|
|
350
|
+
l?.initState ? f + "-" + t + "-" + l?.localStorage?.key : t
|
|
365
351
|
), localStorage.removeItem(t);
|
|
366
352
|
});
|
|
367
353
|
},
|
|
368
|
-
updateInitialState: (
|
|
369
|
-
|
|
354
|
+
updateInitialState: (s) => {
|
|
355
|
+
c.clear(), p++;
|
|
370
356
|
const e = Z(
|
|
371
357
|
t,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
358
|
+
o,
|
|
359
|
+
u,
|
|
360
|
+
f
|
|
375
361
|
);
|
|
376
362
|
return J(() => {
|
|
377
|
-
nt(t,
|
|
378
|
-
const
|
|
379
|
-
|
|
363
|
+
nt(t, s), B(t, e), x(t, s);
|
|
364
|
+
const I = a.getState().stateComponents.get(t);
|
|
365
|
+
I && I.components.forEach((V) => {
|
|
380
366
|
V.forceUpdate();
|
|
381
367
|
}), localStorage.removeItem(t);
|
|
382
368
|
}), {
|
|
383
|
-
fetchId: (
|
|
369
|
+
fetchId: (I) => e.get()[I]
|
|
384
370
|
};
|
|
385
371
|
},
|
|
386
|
-
_initialState:
|
|
387
|
-
_serverState:
|
|
388
|
-
_isLoading:
|
|
372
|
+
_initialState: a.getState().initialStateGlobal[t],
|
|
373
|
+
_serverState: a.getState().serverState[t],
|
|
374
|
+
_isLoading: a.getState().isLoadingGlobal[t],
|
|
389
375
|
_isServerSynced: () => {
|
|
390
|
-
const
|
|
391
|
-
return !!(
|
|
376
|
+
const s = a.getState().serverState[t];
|
|
377
|
+
return !!(s && G(s, gt(t)));
|
|
392
378
|
}
|
|
393
379
|
};
|
|
394
|
-
function w(
|
|
380
|
+
function w(s, e = [], I) {
|
|
395
381
|
const V = e.map(String).join(".");
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
return
|
|
382
|
+
c.get(V);
|
|
383
|
+
const k = function() {
|
|
384
|
+
return a().getNestedState(t, e);
|
|
399
385
|
};
|
|
400
|
-
Object.keys(
|
|
401
|
-
|
|
386
|
+
Object.keys(g).forEach((P) => {
|
|
387
|
+
k[P] = g[P];
|
|
402
388
|
});
|
|
403
|
-
const
|
|
389
|
+
const l = {
|
|
404
390
|
apply(P, i, $) {
|
|
405
|
-
return
|
|
391
|
+
return a().getNestedState(t, e);
|
|
406
392
|
},
|
|
407
393
|
get(P, i) {
|
|
408
394
|
if (i !== "then" && !i.startsWith("$") && i !== "stateMapNoRender") {
|
|
409
|
-
const n = e.join("."), r = `${t}////${
|
|
410
|
-
if (
|
|
411
|
-
const S =
|
|
395
|
+
const n = e.join("."), r = `${t}////${u}`, d = a.getState().stateComponents.get(t);
|
|
396
|
+
if (d) {
|
|
397
|
+
const S = d.components.get(r);
|
|
412
398
|
S && (e.length > 0 || i === "get") && S.paths.add(n);
|
|
413
399
|
}
|
|
414
400
|
}
|
|
415
401
|
if (i === "showValidationErrors")
|
|
416
402
|
return () => {
|
|
417
|
-
const n =
|
|
403
|
+
const n = a.getState().getInitialOptions(t)?.validation;
|
|
418
404
|
if (!n?.key)
|
|
419
405
|
throw new Error("Validation key not found");
|
|
420
|
-
return
|
|
406
|
+
return a.getState().getValidationErrors(n.key + "." + e.join("."));
|
|
421
407
|
};
|
|
422
|
-
if (Array.isArray(
|
|
408
|
+
if (Array.isArray(s)) {
|
|
423
409
|
if (i === "getSelected")
|
|
424
410
|
return () => {
|
|
425
411
|
const n = y.get(e.join("."));
|
|
426
412
|
if (n !== void 0)
|
|
427
413
|
return w(
|
|
428
|
-
|
|
414
|
+
s[n],
|
|
429
415
|
[...e, n.toString()],
|
|
430
|
-
|
|
416
|
+
I
|
|
431
417
|
);
|
|
432
418
|
};
|
|
433
419
|
if (i === "stateMap" || i === "stateMapNoRender")
|
|
434
420
|
return (n) => {
|
|
435
|
-
const r =
|
|
421
|
+
const r = I?.filtered?.some(
|
|
436
422
|
(S) => S.join(".") === e.join(".")
|
|
437
|
-
),
|
|
438
|
-
return i !== "stateMapNoRender" && (
|
|
439
|
-
const E = r && S.__origIndex ? S.__origIndex : m,
|
|
423
|
+
), d = r ? s : a.getState().getNestedState(t, e);
|
|
424
|
+
return i !== "stateMapNoRender" && (c.clear(), p++), d.map((S, m) => {
|
|
425
|
+
const E = r && S.__origIndex ? S.__origIndex : m, j = w(
|
|
440
426
|
S,
|
|
441
427
|
[...e, E.toString()],
|
|
442
|
-
|
|
428
|
+
I
|
|
443
429
|
);
|
|
444
430
|
return n(
|
|
445
431
|
S,
|
|
446
|
-
|
|
432
|
+
j,
|
|
447
433
|
m,
|
|
448
|
-
|
|
449
|
-
w(
|
|
434
|
+
s,
|
|
435
|
+
w(s, e, I)
|
|
450
436
|
);
|
|
451
437
|
});
|
|
452
438
|
};
|
|
453
439
|
if (i === "$stateMap")
|
|
454
|
-
return (n) => H(
|
|
440
|
+
return (n) => H(Mt, {
|
|
455
441
|
proxy: {
|
|
456
442
|
_stateKey: t,
|
|
457
443
|
_path: e,
|
|
@@ -462,92 +448,92 @@ function Z(t, a, f, g) {
|
|
|
462
448
|
});
|
|
463
449
|
if (i === "stateFlattenOn")
|
|
464
450
|
return (n) => {
|
|
465
|
-
const
|
|
451
|
+
const d = I?.filtered?.some(
|
|
466
452
|
(m) => m.join(".") === e.join(".")
|
|
467
|
-
) ?
|
|
468
|
-
|
|
469
|
-
const S =
|
|
453
|
+
) ? s : a.getState().getNestedState(t, e);
|
|
454
|
+
c.clear(), p++;
|
|
455
|
+
const S = d.flatMap(
|
|
470
456
|
(m, E) => m[n] ?? []
|
|
471
457
|
);
|
|
472
458
|
return w(
|
|
473
459
|
S,
|
|
474
460
|
[...e, "[*]", n],
|
|
475
|
-
|
|
461
|
+
I
|
|
476
462
|
);
|
|
477
463
|
};
|
|
478
464
|
if (i === "findWith")
|
|
479
465
|
return (n, r) => {
|
|
480
|
-
const
|
|
466
|
+
const d = s.findIndex(
|
|
481
467
|
(E) => E[n] === r
|
|
482
468
|
);
|
|
483
|
-
if (
|
|
484
|
-
const S =
|
|
485
|
-
return
|
|
469
|
+
if (d === -1) return;
|
|
470
|
+
const S = s[d], m = [...e, d.toString()];
|
|
471
|
+
return c.clear(), p++, c.clear(), p++, w(S, m);
|
|
486
472
|
};
|
|
487
473
|
if (i === "index")
|
|
488
474
|
return (n) => {
|
|
489
|
-
const r =
|
|
475
|
+
const r = s[n];
|
|
490
476
|
return w(r, [...e, n.toString()]);
|
|
491
477
|
};
|
|
492
478
|
if (i === "insert")
|
|
493
|
-
return (n) => (_(e), st(
|
|
494
|
-
|
|
479
|
+
return (n) => (_(e), st(o, n, e, t), w(
|
|
480
|
+
a.getState().cogsStateStore[t],
|
|
495
481
|
[]
|
|
496
482
|
));
|
|
497
483
|
if (i === "uniqueInsert")
|
|
498
|
-
return (n, r,
|
|
499
|
-
const S =
|
|
484
|
+
return (n, r, d) => {
|
|
485
|
+
const S = a.getState().getNestedState(t, e), m = ft(n) ? n(S) : n;
|
|
500
486
|
let E = null;
|
|
501
487
|
if (!S.some((A) => {
|
|
502
488
|
if (r) {
|
|
503
|
-
const
|
|
489
|
+
const F = r.every(
|
|
504
490
|
(W) => G(A[W], m[W])
|
|
505
491
|
);
|
|
506
|
-
return
|
|
492
|
+
return F && (E = A), F;
|
|
507
493
|
}
|
|
508
|
-
const
|
|
509
|
-
return
|
|
494
|
+
const M = G(A, m);
|
|
495
|
+
return M && (E = A), M;
|
|
510
496
|
}))
|
|
511
|
-
_(e), st(
|
|
512
|
-
else if (
|
|
513
|
-
const A =
|
|
514
|
-
(
|
|
497
|
+
_(e), st(o, m, e, t);
|
|
498
|
+
else if (d && E) {
|
|
499
|
+
const A = d(E), M = S.map(
|
|
500
|
+
(F) => G(F, E) ? A : F
|
|
515
501
|
);
|
|
516
|
-
_(e), q(
|
|
502
|
+
_(e), q(o, M, e);
|
|
517
503
|
}
|
|
518
504
|
};
|
|
519
505
|
if (i === "cut")
|
|
520
506
|
return (n, r) => {
|
|
521
|
-
r?.waitForSync || (_(e), ct(
|
|
507
|
+
r?.waitForSync || (_(e), ct(o, e, t, n));
|
|
522
508
|
};
|
|
523
509
|
if (i === "stateFilter")
|
|
524
510
|
return (n) => {
|
|
525
|
-
const r =
|
|
511
|
+
const r = s.map((m, E) => ({
|
|
526
512
|
...m,
|
|
527
513
|
__origIndex: E.toString()
|
|
528
|
-
})),
|
|
514
|
+
})), d = [], S = [];
|
|
529
515
|
for (let m = 0; m < r.length; m++)
|
|
530
|
-
n(r[m], m) && (
|
|
531
|
-
return
|
|
532
|
-
filtered: [...
|
|
533
|
-
validIndices:
|
|
516
|
+
n(r[m], m) && (d.push(m), S.push(r[m]));
|
|
517
|
+
return c.clear(), p++, w(S, e, {
|
|
518
|
+
filtered: [...I?.filtered || [], e],
|
|
519
|
+
validIndices: d
|
|
534
520
|
// Always pass validIndices, even if empty
|
|
535
521
|
});
|
|
536
522
|
};
|
|
537
523
|
}
|
|
538
524
|
const $ = e[e.length - 1];
|
|
539
525
|
if (!isNaN(Number($))) {
|
|
540
|
-
const n = e.slice(0, -1), r =
|
|
526
|
+
const n = e.slice(0, -1), r = a.getState().getNestedState(t, n);
|
|
541
527
|
if (Array.isArray(r) && i === "cut")
|
|
542
528
|
return () => ct(
|
|
543
|
-
|
|
529
|
+
o,
|
|
544
530
|
n,
|
|
545
531
|
t,
|
|
546
532
|
Number($)
|
|
547
533
|
);
|
|
548
534
|
}
|
|
549
535
|
if (i === "get")
|
|
550
|
-
return () =>
|
|
536
|
+
return () => a.getState().getNestedState(t, e);
|
|
551
537
|
if (i === "$derive")
|
|
552
538
|
return (n) => X({
|
|
553
539
|
_stateKey: t,
|
|
@@ -567,60 +553,60 @@ function Z(t, a, f, g) {
|
|
|
567
553
|
});
|
|
568
554
|
if (i === "lastSynced") {
|
|
569
555
|
const n = `${t}:${e.join(".")}`;
|
|
570
|
-
return
|
|
556
|
+
return a.getState().getSyncInfo(n);
|
|
571
557
|
}
|
|
572
558
|
if (i === "_selected") {
|
|
573
|
-
const n = e.slice(0, -1), r = n.join("."),
|
|
574
|
-
return Array.isArray(
|
|
559
|
+
const n = e.slice(0, -1), r = n.join("."), d = a.getState().getNestedState(t, n);
|
|
560
|
+
return Array.isArray(d) ? Number(e[e.length - 1]) === y.get(r) : void 0;
|
|
575
561
|
}
|
|
576
562
|
if (i == "getLocalStorage")
|
|
577
|
-
return (n) => St(
|
|
563
|
+
return (n) => St(f + "-" + t + "-" + n);
|
|
578
564
|
if (i === "setSelected")
|
|
579
565
|
return (n) => {
|
|
580
|
-
const r = e.slice(0, -1),
|
|
581
|
-
n ? y.set(S,
|
|
582
|
-
const m =
|
|
583
|
-
q(
|
|
566
|
+
const r = e.slice(0, -1), d = Number(e[e.length - 1]), S = r.join(".");
|
|
567
|
+
n ? y.set(S, d) : y.delete(S);
|
|
568
|
+
const m = a.getState().getNestedState(t, [...r]);
|
|
569
|
+
q(o, m, r), _(r);
|
|
584
570
|
};
|
|
585
571
|
if (e.length == 0) {
|
|
586
572
|
if (i === "validateZodSchema")
|
|
587
573
|
return () => {
|
|
588
|
-
const n =
|
|
574
|
+
const n = a.getState().getInitialOptions(t)?.validation, r = a.getState().addValidationError;
|
|
589
575
|
if (!n?.zodSchema)
|
|
590
576
|
throw new Error("Zod schema not found");
|
|
591
577
|
if (!n?.key)
|
|
592
578
|
throw new Error("Validation key not found");
|
|
593
|
-
|
|
594
|
-
const
|
|
579
|
+
O(n.key);
|
|
580
|
+
const d = a.getState().cogsStateStore[t];
|
|
595
581
|
try {
|
|
596
|
-
const S =
|
|
582
|
+
const S = a.getState().getValidationErrors(n.key);
|
|
597
583
|
S && S.length > 0 && S.forEach(([E]) => {
|
|
598
|
-
E && E.startsWith(n.key) &&
|
|
584
|
+
E && E.startsWith(n.key) && O(E);
|
|
599
585
|
});
|
|
600
|
-
const m = n.zodSchema.safeParse(
|
|
601
|
-
return m.success ? !0 : (m.error.errors.forEach((
|
|
602
|
-
const A =
|
|
603
|
-
r(
|
|
586
|
+
const m = n.zodSchema.safeParse(d);
|
|
587
|
+
return m.success ? !0 : (m.error.errors.forEach((j) => {
|
|
588
|
+
const A = j.path, M = j.message, F = [n.key, ...A].join(".");
|
|
589
|
+
r(F, M);
|
|
604
590
|
}), mt(t), !1);
|
|
605
591
|
} catch (S) {
|
|
606
592
|
return console.error("Zod schema validation failed", S), !1;
|
|
607
593
|
}
|
|
608
594
|
};
|
|
609
|
-
if (i === "_componentId") return
|
|
595
|
+
if (i === "_componentId") return u;
|
|
610
596
|
if (i === "getComponents")
|
|
611
|
-
return () =>
|
|
597
|
+
return () => a().stateComponents.get(t);
|
|
612
598
|
if (i === "getAllFormRefs")
|
|
613
599
|
return () => lt.getState().getFormRefsByStateKey(t);
|
|
614
600
|
if (i === "_initialState")
|
|
615
|
-
return
|
|
601
|
+
return a.getState().initialStateGlobal[t];
|
|
616
602
|
if (i === "_serverState")
|
|
617
|
-
return
|
|
603
|
+
return a.getState().serverState[t];
|
|
618
604
|
if (i === "_isLoading")
|
|
619
|
-
return
|
|
605
|
+
return a.getState().isLoadingGlobal[t];
|
|
620
606
|
if (i === "revertToInitialState")
|
|
621
|
-
return
|
|
622
|
-
if (i === "updateInitialState") return
|
|
623
|
-
if (i === "removeValidation") return
|
|
607
|
+
return g.revertToInitialState;
|
|
608
|
+
if (i === "updateInitialState") return g.updateInitialState;
|
|
609
|
+
if (i === "removeValidation") return g.removeValidation;
|
|
624
610
|
}
|
|
625
611
|
if (i === "getFormRef")
|
|
626
612
|
return () => lt.getState().getFormRef(t + "." + e.join("."));
|
|
@@ -633,27 +619,27 @@ function Z(t, a, f, g) {
|
|
|
633
619
|
{
|
|
634
620
|
formOpts: r ? { validation: { message: "" } } : void 0,
|
|
635
621
|
path: e,
|
|
636
|
-
validationKey:
|
|
622
|
+
validationKey: a.getState().getInitialOptions(t)?.validation?.key || "",
|
|
637
623
|
stateKey: t,
|
|
638
|
-
validIndices:
|
|
624
|
+
validIndices: I?.validIndices,
|
|
639
625
|
children: n
|
|
640
626
|
}
|
|
641
627
|
);
|
|
642
628
|
if (i === "_stateKey") return t;
|
|
643
629
|
if (i === "_path") return e;
|
|
644
|
-
if (i === "_isServerSynced") return
|
|
630
|
+
if (i === "_isServerSynced") return g._isServerSynced;
|
|
645
631
|
if (i === "update")
|
|
646
632
|
return (n, r) => {
|
|
647
633
|
if (r?.debounce)
|
|
648
634
|
pt(() => {
|
|
649
|
-
q(
|
|
650
|
-
const
|
|
651
|
-
r?.afterUpdate && r.afterUpdate(
|
|
635
|
+
q(o, n, e, "");
|
|
636
|
+
const d = a.getState().getNestedState(t, e);
|
|
637
|
+
r?.afterUpdate && r.afterUpdate(d);
|
|
652
638
|
}, r.debounce);
|
|
653
639
|
else {
|
|
654
|
-
q(
|
|
655
|
-
const
|
|
656
|
-
r?.afterUpdate && r.afterUpdate(
|
|
640
|
+
q(o, n, e, "");
|
|
641
|
+
const d = a.getState().getNestedState(t, e);
|
|
642
|
+
r?.afterUpdate && r.afterUpdate(d);
|
|
657
643
|
}
|
|
658
644
|
_(e);
|
|
659
645
|
};
|
|
@@ -661,94 +647,94 @@ function Z(t, a, f, g) {
|
|
|
661
647
|
return (n, r) => /* @__PURE__ */ it(
|
|
662
648
|
Nt,
|
|
663
649
|
{
|
|
664
|
-
setState:
|
|
650
|
+
setState: o,
|
|
665
651
|
stateKey: t,
|
|
666
652
|
path: e,
|
|
667
653
|
child: n,
|
|
668
654
|
formOpts: r
|
|
669
655
|
}
|
|
670
656
|
);
|
|
671
|
-
const R = [...e, i], Q =
|
|
672
|
-
return w(Q, R,
|
|
657
|
+
const R = [...e, i], Q = a.getState().getNestedState(t, R);
|
|
658
|
+
return w(Q, R, I);
|
|
673
659
|
}
|
|
674
|
-
}, U = new Proxy(
|
|
675
|
-
return
|
|
660
|
+
}, U = new Proxy(k, l);
|
|
661
|
+
return c.set(V, {
|
|
676
662
|
proxy: U,
|
|
677
663
|
stateVersion: p
|
|
678
664
|
}), U;
|
|
679
665
|
}
|
|
680
666
|
return w(
|
|
681
|
-
|
|
667
|
+
a.getState().getNestedState(t, [])
|
|
682
668
|
);
|
|
683
669
|
}
|
|
684
670
|
function X(t) {
|
|
685
671
|
return H(bt, { proxy: t });
|
|
686
672
|
}
|
|
687
|
-
function
|
|
673
|
+
function Mt({
|
|
688
674
|
proxy: t,
|
|
689
|
-
rebuildStateShape:
|
|
675
|
+
rebuildStateShape: o
|
|
690
676
|
}) {
|
|
691
|
-
const
|
|
692
|
-
return Array.isArray(
|
|
693
|
-
|
|
677
|
+
const u = a().getNestedState(t._stateKey, t._path);
|
|
678
|
+
return Array.isArray(u) ? o(
|
|
679
|
+
u,
|
|
694
680
|
t._path
|
|
695
681
|
).stateMapNoRender(
|
|
696
|
-
(
|
|
682
|
+
(c, p, _, y, g) => t._mapFn(c, p, _, y, g)
|
|
697
683
|
) : null;
|
|
698
684
|
}
|
|
699
685
|
function bt({
|
|
700
686
|
proxy: t
|
|
701
687
|
}) {
|
|
702
|
-
const
|
|
688
|
+
const o = z(null), u = `${t._stateKey}-${t._path.join(".")}`;
|
|
703
689
|
return K(() => {
|
|
704
|
-
const
|
|
705
|
-
if (!
|
|
706
|
-
const
|
|
707
|
-
let y =
|
|
708
|
-
y || (y = `parent-${crypto.randomUUID()}`,
|
|
690
|
+
const f = o.current;
|
|
691
|
+
if (!f || !f.parentElement) return;
|
|
692
|
+
const c = f.parentElement, _ = Array.from(c.childNodes).indexOf(f);
|
|
693
|
+
let y = c.getAttribute("data-parent-id");
|
|
694
|
+
y || (y = `parent-${crypto.randomUUID()}`, c.setAttribute("data-parent-id", y));
|
|
709
695
|
const w = {
|
|
710
696
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
711
697
|
parentId: y,
|
|
712
698
|
position: _,
|
|
713
699
|
effect: t._effect
|
|
714
700
|
};
|
|
715
|
-
|
|
716
|
-
const
|
|
701
|
+
a.getState().addSignalElement(u, w);
|
|
702
|
+
const s = a.getState().getNestedState(t._stateKey, t._path);
|
|
717
703
|
let e;
|
|
718
704
|
if (t._effect)
|
|
719
705
|
try {
|
|
720
706
|
e = new Function(
|
|
721
707
|
"state",
|
|
722
708
|
`return (${t._effect})(state)`
|
|
723
|
-
)(
|
|
709
|
+
)(s);
|
|
724
710
|
} catch (V) {
|
|
725
|
-
console.error("Error evaluating effect function during mount:", V), e =
|
|
711
|
+
console.error("Error evaluating effect function during mount:", V), e = s;
|
|
726
712
|
}
|
|
727
713
|
else
|
|
728
|
-
e =
|
|
714
|
+
e = s;
|
|
729
715
|
e !== null && typeof e == "object" && (e = JSON.stringify(e));
|
|
730
|
-
const
|
|
731
|
-
|
|
716
|
+
const I = document.createTextNode(String(e));
|
|
717
|
+
f.replaceWith(I);
|
|
732
718
|
}, [t._stateKey, t._path.join("."), t._effect]), H("span", {
|
|
733
|
-
ref:
|
|
719
|
+
ref: o,
|
|
734
720
|
style: { display: "none" },
|
|
735
|
-
"data-signal-id":
|
|
721
|
+
"data-signal-id": u
|
|
736
722
|
});
|
|
737
723
|
}
|
|
738
724
|
function Jt(t) {
|
|
739
|
-
const
|
|
740
|
-
(
|
|
741
|
-
const
|
|
725
|
+
const o = Et(
|
|
726
|
+
(u) => {
|
|
727
|
+
const f = a.getState().stateComponents.get(t._stateKey) || {
|
|
742
728
|
components: /* @__PURE__ */ new Map()
|
|
743
729
|
};
|
|
744
|
-
return
|
|
745
|
-
forceUpdate:
|
|
730
|
+
return f.components.set(t._stateKey, {
|
|
731
|
+
forceUpdate: u,
|
|
746
732
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
747
|
-
}), () =>
|
|
733
|
+
}), () => f.components.delete(t._stateKey);
|
|
748
734
|
},
|
|
749
|
-
() =>
|
|
735
|
+
() => a.getState().getNestedState(t._stateKey, t._path)
|
|
750
736
|
);
|
|
751
|
-
return H("text", {}, String(
|
|
737
|
+
return H("text", {}, String(o));
|
|
752
738
|
}
|
|
753
739
|
export {
|
|
754
740
|
X as $cogsSignal,
|