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