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