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