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