cogsbox-state 0.5.198 → 0.5.200
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 +331 -340
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +13 -22
package/dist/CogsState.jsx
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as le, useRef as ee, useEffect as de, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as se, updateFn as Q, cutFunc as K, ValidationWrapper as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as me } from "react/jsx-runtime";
|
|
3
|
+
import { useState as le, useRef as ee, useEffect as de, useLayoutEffect as Ae, useMemo as Te, createElement as re, useSyncExternalStore as Ne, startTransition as Ve } from "react";
|
|
4
|
+
import { transformStateFunc as _e, isDeepEqual as L, isFunction as Z, getNestedValue as q, getDifferences as pe, debounce as Ce } from "./utility.js";
|
|
5
|
+
import { pushFunc as se, updateFn as Q, cutFunc as K, ValidationWrapper as Pe, FormControlComponent as be } from "./Functions.jsx";
|
|
6
|
+
import xe from "superjson";
|
|
7
7
|
import { v4 as ue } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as t, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
function
|
|
9
|
+
import { getGlobalStore as t, formRefStore as ye } from "./store.js";
|
|
10
|
+
import { useCogsConfig as we } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Oe } from "fast-json-patch";
|
|
12
|
+
function ve(e, i) {
|
|
13
13
|
const S = t.getState().getInitialOptions, u = t.getState().setInitialStateOptions, f = S(e) || {};
|
|
14
14
|
u(e, {
|
|
15
15
|
...f,
|
|
16
16
|
...i
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function he({
|
|
20
20
|
stateKey: e,
|
|
21
21
|
options: i,
|
|
22
22
|
initialOptionsPart: S
|
|
23
23
|
}) {
|
|
24
|
-
const u = H(e) || {}, f = S[e] || {}, k = t.getState().setInitialStateOptions,
|
|
24
|
+
const u = H(e) || {}, f = S[e] || {}, k = t.getState().setInitialStateOptions, I = { ...f, ...u };
|
|
25
25
|
let v = !1;
|
|
26
26
|
if (i)
|
|
27
27
|
for (const s in i)
|
|
28
|
-
|
|
29
|
-
!L(
|
|
30
|
-
v && k(e,
|
|
28
|
+
I.hasOwnProperty(s) ? (s == "localStorage" && i[s] && I[s].key !== i[s]?.key && (v = !0, I[s] = i[s]), s == "initialState" && i[s] && I[s] !== i[s] && // Different references
|
|
29
|
+
!L(I[s], i[s]) && (v = !0, I[s] = i[s])) : (v = !0, I[s] = i[s]);
|
|
30
|
+
v && k(e, I);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function et(e, { formElements: i, validation: S }) {
|
|
33
33
|
return { initialState: e, formElements: i, validation: S };
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const tt = (e, i) => {
|
|
36
36
|
let S = e;
|
|
37
|
-
const [u, f] =
|
|
37
|
+
const [u, f] = _e(S);
|
|
38
38
|
(Object.keys(f).length > 0 || i && Object.keys(i).length > 0) && Object.keys(f).forEach((v) => {
|
|
39
39
|
f[v] = f[v] || {}, f[v].formElements = {
|
|
40
40
|
...i?.formElements,
|
|
@@ -46,13 +46,13 @@ const Ke = (e, i) => {
|
|
|
46
46
|
}), t.getState().setInitialStates(u), t.getState().setCreatedState(u);
|
|
47
47
|
const k = (v, s) => {
|
|
48
48
|
const [m] = le(s?.componentId ?? ue());
|
|
49
|
-
|
|
49
|
+
he({
|
|
50
50
|
stateKey: v,
|
|
51
51
|
options: s,
|
|
52
52
|
initialOptionsPart: f
|
|
53
53
|
});
|
|
54
|
-
const n = t.getState().cogsStateStore[v] || u[v],
|
|
55
|
-
|
|
54
|
+
const n = t.getState().cogsStateStore[v] || u[v], h = s?.modifyState ? s.modifyState(n) : n, [M, _] = We(
|
|
55
|
+
h,
|
|
56
56
|
{
|
|
57
57
|
stateKey: v,
|
|
58
58
|
syncUpdate: s?.syncUpdate,
|
|
@@ -69,21 +69,21 @@ const Ke = (e, i) => {
|
|
|
69
69
|
);
|
|
70
70
|
return _;
|
|
71
71
|
};
|
|
72
|
-
function
|
|
73
|
-
|
|
72
|
+
function I(v, s) {
|
|
73
|
+
he({ stateKey: v, options: s, initialOptionsPart: f }), s.localStorage && Me(v, s), oe(v);
|
|
74
74
|
}
|
|
75
|
-
return { useCogsState: k, setCogsOptions:
|
|
75
|
+
return { useCogsState: k, setCogsOptions: I };
|
|
76
76
|
}, {
|
|
77
77
|
setUpdaterState: te,
|
|
78
78
|
setState: Y,
|
|
79
79
|
getInitialOptions: H,
|
|
80
|
-
getKeyState:
|
|
81
|
-
getValidationErrors:
|
|
82
|
-
setStateLog:
|
|
80
|
+
getKeyState: Ee,
|
|
81
|
+
getValidationErrors: Fe,
|
|
82
|
+
setStateLog: je,
|
|
83
83
|
updateInitialStateGlobal: ge,
|
|
84
|
-
addValidationError:
|
|
84
|
+
addValidationError: Re,
|
|
85
85
|
removeValidationError: B,
|
|
86
|
-
setServerSyncActions:
|
|
86
|
+
setServerSyncActions: Ue
|
|
87
87
|
} = t.getState(), Ie = (e, i, S, u, f) => {
|
|
88
88
|
S?.log && console.log(
|
|
89
89
|
"saving to localstorage",
|
|
@@ -93,19 +93,19 @@ const Ke = (e, i) => {
|
|
|
93
93
|
);
|
|
94
94
|
const k = Z(S?.localStorage?.key) ? S.localStorage?.key(e) : S?.localStorage?.key;
|
|
95
95
|
if (k && u) {
|
|
96
|
-
const
|
|
96
|
+
const I = `${u}-${i}-${k}`;
|
|
97
97
|
let v;
|
|
98
98
|
try {
|
|
99
|
-
v = ae(
|
|
99
|
+
v = ae(I)?.lastSyncedWithServer;
|
|
100
100
|
} catch {
|
|
101
101
|
}
|
|
102
102
|
const s = {
|
|
103
103
|
state: e,
|
|
104
104
|
lastUpdated: Date.now(),
|
|
105
105
|
lastSyncedWithServer: f ?? v
|
|
106
|
-
}, m =
|
|
106
|
+
}, m = xe.serialize(s);
|
|
107
107
|
window.localStorage.setItem(
|
|
108
|
-
|
|
108
|
+
I,
|
|
109
109
|
JSON.stringify(m.json)
|
|
110
110
|
);
|
|
111
111
|
}
|
|
@@ -117,8 +117,8 @@ const Ke = (e, i) => {
|
|
|
117
117
|
} catch (i) {
|
|
118
118
|
return console.error("Error loading from localStorage:", i), null;
|
|
119
119
|
}
|
|
120
|
-
},
|
|
121
|
-
const S = t.getState().cogsStateStore[e], { sessionId: u } =
|
|
120
|
+
}, Me = (e, i) => {
|
|
121
|
+
const S = t.getState().cogsStateStore[e], { sessionId: u } = we(), f = Z(i?.localStorage?.key) ? i.localStorage.key(S) : i?.localStorage?.key;
|
|
122
122
|
if (f && u) {
|
|
123
123
|
const k = ae(
|
|
124
124
|
`${u}-${e}-${f}`
|
|
@@ -127,8 +127,8 @@ const Ke = (e, i) => {
|
|
|
127
127
|
return Y(e, k.state), oe(e), !0;
|
|
128
128
|
}
|
|
129
129
|
return !1;
|
|
130
|
-
},
|
|
131
|
-
const
|
|
130
|
+
}, ke = (e, i, S, u, f, k) => {
|
|
131
|
+
const I = {
|
|
132
132
|
initialState: i,
|
|
133
133
|
updaterState: ne(
|
|
134
134
|
e,
|
|
@@ -138,7 +138,7 @@ const Ke = (e, i) => {
|
|
|
138
138
|
),
|
|
139
139
|
state: S
|
|
140
140
|
};
|
|
141
|
-
ge(e,
|
|
141
|
+
ge(e, I.initialState), te(e, I.updaterState), Y(e, I.state);
|
|
142
142
|
}, oe = (e) => {
|
|
143
143
|
const i = t.getState().stateComponents.get(e);
|
|
144
144
|
if (!i) return;
|
|
@@ -148,7 +148,7 @@ const Ke = (e, i) => {
|
|
|
148
148
|
}), queueMicrotask(() => {
|
|
149
149
|
S.forEach((u) => u());
|
|
150
150
|
});
|
|
151
|
-
},
|
|
151
|
+
}, nt = (e, i) => {
|
|
152
152
|
const S = t.getState().stateComponents.get(e);
|
|
153
153
|
if (S) {
|
|
154
154
|
const u = `${e}////${i}`, f = S.components.get(u);
|
|
@@ -156,7 +156,7 @@ const Ke = (e, i) => {
|
|
|
156
156
|
return;
|
|
157
157
|
f && f.forceUpdate();
|
|
158
158
|
}
|
|
159
|
-
},
|
|
159
|
+
}, De = (e, i, S, u) => {
|
|
160
160
|
switch (e) {
|
|
161
161
|
case "update":
|
|
162
162
|
return {
|
|
@@ -179,22 +179,22 @@ const Ke = (e, i) => {
|
|
|
179
179
|
return { oldValue: null, newValue: null };
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
function
|
|
182
|
+
function We(e, {
|
|
183
183
|
stateKey: i,
|
|
184
184
|
serverSync: S,
|
|
185
185
|
localStorage: u,
|
|
186
186
|
formElements: f,
|
|
187
187
|
reactiveDeps: k,
|
|
188
|
-
reactiveType:
|
|
188
|
+
reactiveType: I,
|
|
189
189
|
componentId: v,
|
|
190
190
|
initialState: s,
|
|
191
191
|
syncUpdate: m,
|
|
192
192
|
dependencies: n,
|
|
193
|
-
serverState:
|
|
193
|
+
serverState: h
|
|
194
194
|
} = {}) {
|
|
195
|
-
const [M, _] = le({}), { sessionId: C } =
|
|
195
|
+
const [M, _] = le({}), { sessionId: C } = we();
|
|
196
196
|
let D = !i;
|
|
197
|
-
const [g] = le(i ?? ue()),
|
|
197
|
+
const [g] = le(i ?? ue()), l = t.getState().stateLog[g], X = ee(/* @__PURE__ */ new Set()), J = ee(v ?? ue()), P = ee(
|
|
198
198
|
null
|
|
199
199
|
);
|
|
200
200
|
P.current = H(g) ?? null, de(() => {
|
|
@@ -211,7 +211,7 @@ function Me(e, {
|
|
|
211
211
|
}
|
|
212
212
|
}, [m]), de(() => {
|
|
213
213
|
if (s) {
|
|
214
|
-
|
|
214
|
+
ve(g, {
|
|
215
215
|
initialState: s
|
|
216
216
|
});
|
|
217
217
|
const o = P.current, c = o?.serverState?.id !== void 0 && o?.serverState?.status === "success" && o?.serverState?.data, p = t.getState().initialStateGlobal[g];
|
|
@@ -220,24 +220,24 @@ function Me(e, {
|
|
|
220
220
|
let w = null;
|
|
221
221
|
const $ = Z(o?.localStorage?.key) ? o?.localStorage?.key(s) : o?.localStorage?.key;
|
|
222
222
|
$ && C && (w = ae(`${C}-${g}-${$}`));
|
|
223
|
-
let
|
|
224
|
-
const
|
|
225
|
-
c &&
|
|
223
|
+
let T = s, A = !1;
|
|
224
|
+
const N = c ? Date.now() : 0, O = w?.lastUpdated || 0, b = w?.lastSyncedWithServer || 0;
|
|
225
|
+
c && N > O ? (T = o.serverState.data, A = !0) : w && O > b && (T = w.state, o?.localStorage?.onChange && o?.localStorage?.onChange(T)), ke(
|
|
226
226
|
g,
|
|
227
227
|
s,
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
T,
|
|
229
|
+
d,
|
|
230
230
|
J.current,
|
|
231
231
|
C
|
|
232
|
-
),
|
|
232
|
+
), A && $ && C && Ie(T, g, o, C, Date.now()), oe(g), (Array.isArray(I) ? I : [I || "component"]).includes("none") || _({});
|
|
233
233
|
}
|
|
234
234
|
}, [
|
|
235
235
|
s,
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
h?.status,
|
|
237
|
+
h?.data,
|
|
238
238
|
...n || []
|
|
239
|
-
]),
|
|
240
|
-
D &&
|
|
239
|
+
]), Ae(() => {
|
|
240
|
+
D && ve(g, {
|
|
241
241
|
serverSync: S,
|
|
242
242
|
formElements: f,
|
|
243
243
|
initialState: s,
|
|
@@ -252,13 +252,13 @@ function Me(e, {
|
|
|
252
252
|
paths: /* @__PURE__ */ new Set(),
|
|
253
253
|
deps: [],
|
|
254
254
|
depsFunction: k || void 0,
|
|
255
|
-
reactiveType:
|
|
255
|
+
reactiveType: I ?? ["component", "deps"]
|
|
256
256
|
}), t.getState().stateComponents.set(g, a), _({}), () => {
|
|
257
257
|
const c = `${g}////${J.current}`;
|
|
258
258
|
a && (a.components.delete(c), a.components.size === 0 && t.getState().stateComponents.delete(g));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const d = (o, a, c, p) => {
|
|
262
262
|
if (Array.isArray(a)) {
|
|
263
263
|
const y = `${g}-${a.join(".")}`;
|
|
264
264
|
X.current.add(y);
|
|
@@ -266,25 +266,25 @@ function Me(e, {
|
|
|
266
266
|
Y(g, (y) => {
|
|
267
267
|
const w = Z(o) ? o(y) : o, $ = `${g}-${a.join(".")}`;
|
|
268
268
|
if ($) {
|
|
269
|
-
let
|
|
270
|
-
if ((!
|
|
271
|
-
const
|
|
272
|
-
if (Array.isArray(
|
|
273
|
-
|
|
274
|
-
const E = `${g}-${
|
|
275
|
-
|
|
269
|
+
let R = !1, V = t.getState().signalDomElements.get($);
|
|
270
|
+
if ((!V || V.size === 0) && (c.updateType === "insert" || c.updateType === "cut")) {
|
|
271
|
+
const W = a.slice(0, -1), G = q(w, W);
|
|
272
|
+
if (Array.isArray(G)) {
|
|
273
|
+
R = !0;
|
|
274
|
+
const E = `${g}-${W.join(".")}`;
|
|
275
|
+
V = t.getState().signalDomElements.get(E);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
`[data-parent-id="${
|
|
278
|
+
if (V) {
|
|
279
|
+
const W = R ? q(w, a.slice(0, -1)) : q(w, a);
|
|
280
|
+
V.forEach(({ parentId: G, position: E, effect: j }) => {
|
|
281
|
+
const x = document.querySelector(
|
|
282
|
+
`[data-parent-id="${G}"]`
|
|
283
283
|
);
|
|
284
|
-
if (
|
|
285
|
-
const z = Array.from(
|
|
284
|
+
if (x) {
|
|
285
|
+
const z = Array.from(x.childNodes);
|
|
286
286
|
if (z[E]) {
|
|
287
|
-
const U =
|
|
287
|
+
const U = j ? new Function("state", `return (${j})(state)`)(W) : W;
|
|
288
288
|
z[E].textContent = String(U);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
@@ -294,114 +294,110 @@ function Me(e, {
|
|
|
294
294
|
c.updateType === "update" && (p || P.current?.validation?.key) && a && B(
|
|
295
295
|
(p || P.current?.validation?.key) + "." + a.join(".")
|
|
296
296
|
);
|
|
297
|
-
const
|
|
297
|
+
const T = a.slice(0, a.length - 1);
|
|
298
298
|
c.updateType === "cut" && P.current?.validation?.key && B(
|
|
299
|
-
P.current?.validation?.key + "." +
|
|
300
|
-
), c.updateType === "insert" && P.current?.validation?.key &&
|
|
301
|
-
P.current?.validation?.key + "." +
|
|
302
|
-
).filter(([
|
|
303
|
-
let
|
|
304
|
-
if (
|
|
305
|
-
let E =
|
|
306
|
-
B(
|
|
299
|
+
P.current?.validation?.key + "." + T.join(".")
|
|
300
|
+
), c.updateType === "insert" && P.current?.validation?.key && Fe(
|
|
301
|
+
P.current?.validation?.key + "." + T.join(".")
|
|
302
|
+
).filter(([V, W]) => {
|
|
303
|
+
let G = V?.split(".").length;
|
|
304
|
+
if (V == T.join(".") && G == T.length - 1) {
|
|
305
|
+
let E = V + "." + T;
|
|
306
|
+
B(V), Re(E, W);
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
309
|
+
const A = t.getState().stateComponents.get(g);
|
|
310
|
+
if (A) {
|
|
311
|
+
const R = pe(y, w), V = new Set(R), W = c.updateType === "update" ? a.join(".") : a.slice(0, -1).join(".") || "";
|
|
312
312
|
for (const [
|
|
313
|
-
|
|
313
|
+
G,
|
|
314
314
|
E
|
|
315
|
-
] of
|
|
316
|
-
let
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
if (
|
|
315
|
+
] of A.components.entries()) {
|
|
316
|
+
let j = !1;
|
|
317
|
+
const x = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
318
|
+
if (!x.includes("none")) {
|
|
319
|
+
if (x.includes("all")) {
|
|
320
320
|
E.forceUpdate();
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
324
|
-
for (const z of
|
|
323
|
+
if (x.includes("component") && ((E.paths.has(W) || E.paths.has("")) && (j = !0), !j))
|
|
324
|
+
for (const z of V) {
|
|
325
325
|
let U = z;
|
|
326
326
|
for (; ; ) {
|
|
327
327
|
if (E.paths.has(U)) {
|
|
328
|
-
|
|
328
|
+
j = !0;
|
|
329
329
|
break;
|
|
330
330
|
}
|
|
331
331
|
const ie = U.lastIndexOf(".");
|
|
332
332
|
if (ie !== -1) {
|
|
333
|
-
const
|
|
333
|
+
const Se = U.substring(
|
|
334
334
|
0,
|
|
335
335
|
ie
|
|
336
336
|
);
|
|
337
337
|
if (!isNaN(
|
|
338
338
|
Number(U.substring(ie + 1))
|
|
339
|
-
) && E.paths.has(
|
|
340
|
-
|
|
339
|
+
) && E.paths.has(Se)) {
|
|
340
|
+
j = !0;
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
U =
|
|
343
|
+
U = Se;
|
|
344
344
|
} else
|
|
345
345
|
U = "";
|
|
346
346
|
if (U === "")
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
|
-
if (
|
|
349
|
+
if (j) break;
|
|
350
350
|
}
|
|
351
|
-
if (!
|
|
351
|
+
if (!j && x.includes("deps") && E.depsFunction) {
|
|
352
352
|
const z = E.depsFunction(w);
|
|
353
353
|
let U = !1;
|
|
354
|
-
typeof z == "boolean" ? z && (U = !0) : L(E.deps, z) || (E.deps = z, U = !0), U && (
|
|
354
|
+
typeof z == "boolean" ? z && (U = !0) : L(E.deps, z) || (E.deps = z, U = !0), U && (j = !0);
|
|
355
355
|
}
|
|
356
|
-
|
|
356
|
+
j && E.forceUpdate();
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
w,
|
|
369
|
-
a
|
|
370
|
-
);
|
|
371
|
-
const { oldValue: R, newValue: b } = Ue(
|
|
372
|
-
c.updateType,
|
|
360
|
+
const N = Date.now();
|
|
361
|
+
let O = [...a], b = { ...c };
|
|
362
|
+
if (c.updateType === "insert") {
|
|
363
|
+
const R = q(w, a);
|
|
364
|
+
Array.isArray(R) && R.length > 0 && O.push((R.length - 1).toString());
|
|
365
|
+
}
|
|
366
|
+
const { oldValue: F, newValue: $e } = De(
|
|
367
|
+
b.updateType,
|
|
373
368
|
y,
|
|
374
369
|
w,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
370
|
+
O
|
|
371
|
+
// Use the correctly determined path for logging
|
|
372
|
+
), fe = {
|
|
373
|
+
timeStamp: N,
|
|
378
374
|
stateKey: g,
|
|
379
375
|
path: a,
|
|
380
376
|
updateType: c.updateType,
|
|
381
377
|
status: "new",
|
|
382
|
-
oldValue:
|
|
383
|
-
newValue:
|
|
378
|
+
oldValue: F,
|
|
379
|
+
newValue: $e
|
|
384
380
|
};
|
|
385
|
-
if (
|
|
386
|
-
const
|
|
387
|
-
const
|
|
388
|
-
return
|
|
381
|
+
if (je(g, (R) => {
|
|
382
|
+
const W = [...R ?? [], fe].reduce((G, E) => {
|
|
383
|
+
const j = `${E.stateKey}:${JSON.stringify(E.path)}`, x = G.get(j);
|
|
384
|
+
return x ? (x.timeStamp = Math.max(x.timeStamp, E.timeStamp), x.newValue = E.newValue, x.oldValue = x.oldValue ?? E.oldValue, x.updateType = E.updateType) : G.set(j, { ...E }), G;
|
|
389
385
|
}, /* @__PURE__ */ new Map());
|
|
390
|
-
return Array.from(
|
|
386
|
+
return Array.from(W.values());
|
|
391
387
|
}), Ie(
|
|
392
388
|
w,
|
|
393
389
|
g,
|
|
394
390
|
P.current,
|
|
395
391
|
C
|
|
396
392
|
), P.current?.middleware && P.current.middleware({
|
|
397
|
-
updateLog:
|
|
398
|
-
update:
|
|
393
|
+
updateLog: l,
|
|
394
|
+
update: fe
|
|
399
395
|
}), P.current?.serverSync) {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
syncKey: typeof
|
|
403
|
-
rollBackState:
|
|
404
|
-
actionTimeStamp: Date.now() + (
|
|
396
|
+
const R = t.getState().serverState[g], V = P.current?.serverSync;
|
|
397
|
+
Ue(g, {
|
|
398
|
+
syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: w }),
|
|
399
|
+
rollBackState: R,
|
|
400
|
+
actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
|
|
405
401
|
status: "waiting"
|
|
406
402
|
});
|
|
407
403
|
}
|
|
@@ -412,26 +408,26 @@ function Me(e, {
|
|
|
412
408
|
g,
|
|
413
409
|
ne(
|
|
414
410
|
g,
|
|
415
|
-
|
|
411
|
+
d,
|
|
416
412
|
J.current,
|
|
417
413
|
C
|
|
418
414
|
)
|
|
419
415
|
), t.getState().cogsStateStore[g] || Y(g, e), t.getState().initialStateGlobal[g] || ge(g, e));
|
|
420
|
-
const r =
|
|
416
|
+
const r = Te(() => ne(
|
|
421
417
|
g,
|
|
422
|
-
|
|
418
|
+
d,
|
|
423
419
|
J.current,
|
|
424
420
|
C
|
|
425
421
|
), [g]);
|
|
426
|
-
return [
|
|
422
|
+
return [Ee(g), r];
|
|
427
423
|
}
|
|
428
424
|
function ne(e, i, S, u) {
|
|
429
425
|
const f = /* @__PURE__ */ new Map();
|
|
430
426
|
let k = 0;
|
|
431
|
-
const
|
|
427
|
+
const I = (m) => {
|
|
432
428
|
const n = m.join(".");
|
|
433
|
-
for (const [
|
|
434
|
-
(
|
|
429
|
+
for (const [h] of f)
|
|
430
|
+
(h === n || h.startsWith(n + ".")) && f.delete(h);
|
|
435
431
|
k++;
|
|
436
432
|
}, v = {
|
|
437
433
|
removeValidation: (m) => {
|
|
@@ -440,14 +436,14 @@ function ne(e, i, S, u) {
|
|
|
440
436
|
revertToInitialState: (m) => {
|
|
441
437
|
const n = t.getState().getInitialOptions(e)?.validation;
|
|
442
438
|
n?.key && B(n?.key), m?.validationKey && B(m.validationKey);
|
|
443
|
-
const
|
|
439
|
+
const h = t.getState().initialStateGlobal[e];
|
|
444
440
|
t.getState().clearSelectedIndexesForState(e), f.clear(), k++;
|
|
445
|
-
const M = s(
|
|
446
|
-
D && localStorage.removeItem(D), te(e, M), Y(e,
|
|
441
|
+
const M = s(h, []), _ = H(e), C = Z(_?.localStorage?.key) ? _?.localStorage?.key(h) : _?.localStorage?.key, D = `${u}-${e}-${C}`;
|
|
442
|
+
D && localStorage.removeItem(D), te(e, M), Y(e, h);
|
|
447
443
|
const g = t.getState().stateComponents.get(e);
|
|
448
|
-
return g && g.components.forEach((
|
|
449
|
-
|
|
450
|
-
}),
|
|
444
|
+
return g && g.components.forEach((l) => {
|
|
445
|
+
l.forceUpdate();
|
|
446
|
+
}), h;
|
|
451
447
|
},
|
|
452
448
|
updateInitialState: (m) => {
|
|
453
449
|
f.clear(), k++;
|
|
@@ -456,8 +452,8 @@ function ne(e, i, S, u) {
|
|
|
456
452
|
i,
|
|
457
453
|
S,
|
|
458
454
|
u
|
|
459
|
-
),
|
|
460
|
-
return console.log("removing storage", C), localStorage.getItem(C) && localStorage.removeItem(C),
|
|
455
|
+
), h = t.getState().initialStateGlobal[e], M = H(e), _ = Z(M?.localStorage?.key) ? M?.localStorage?.key(h) : M?.localStorage?.key, C = `${u}-${e}-${_}`;
|
|
456
|
+
return console.log("removing storage", C), localStorage.getItem(C) && localStorage.removeItem(C), Ve(() => {
|
|
461
457
|
ge(e, m), te(e, n), Y(e, m);
|
|
462
458
|
const D = t.getState().stateComponents.get(e);
|
|
463
459
|
D && D.components.forEach((g) => {
|
|
@@ -472,10 +468,10 @@ function ne(e, i, S, u) {
|
|
|
472
468
|
_isLoading: t.getState().isLoadingGlobal[e],
|
|
473
469
|
_isServerSynced: () => {
|
|
474
470
|
const m = t.getState().serverState[e];
|
|
475
|
-
return !!(m && L(m,
|
|
471
|
+
return !!(m && L(m, Ee(e)));
|
|
476
472
|
}
|
|
477
473
|
};
|
|
478
|
-
function s(m, n = [],
|
|
474
|
+
function s(m, n = [], h) {
|
|
479
475
|
const M = n.map(String).join(".");
|
|
480
476
|
f.get(M);
|
|
481
477
|
const _ = function() {
|
|
@@ -485,35 +481,30 @@ function ne(e, i, S, u) {
|
|
|
485
481
|
_[g] = v[g];
|
|
486
482
|
});
|
|
487
483
|
const C = {
|
|
488
|
-
apply(g,
|
|
484
|
+
apply(g, l, X) {
|
|
489
485
|
return console.log(
|
|
490
486
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
|
|
491
487
|
), console.trace("Apply trap stack trace"), t().getNestedState(e, n);
|
|
492
488
|
},
|
|
493
|
-
get(g,
|
|
494
|
-
if (
|
|
495
|
-
const
|
|
496
|
-
console.log(
|
|
497
|
-
".........................................................",
|
|
498
|
-
l
|
|
499
|
-
);
|
|
500
|
-
const o = t.getState().stateComponents.get(e);
|
|
489
|
+
get(g, l) {
|
|
490
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender") {
|
|
491
|
+
const d = n.join("."), r = `${e}////${S}`, o = t.getState().stateComponents.get(e);
|
|
501
492
|
if (o) {
|
|
502
493
|
const a = o.components.get(r);
|
|
503
|
-
a && (n.length > 0 ||
|
|
494
|
+
a && (n.length > 0 || l === "get") && a.paths.add(d);
|
|
504
495
|
}
|
|
505
496
|
}
|
|
506
|
-
if (
|
|
507
|
-
return () =>
|
|
497
|
+
if (l === "getDifferences")
|
|
498
|
+
return () => pe(
|
|
508
499
|
t.getState().cogsStateStore[e],
|
|
509
500
|
t.getState().initialStateGlobal[e]
|
|
510
501
|
);
|
|
511
|
-
if (
|
|
502
|
+
if (l === "sync" && n.length === 0)
|
|
512
503
|
return async function() {
|
|
513
|
-
const
|
|
504
|
+
const d = t.getState().getInitialOptions(e), r = d?.sync;
|
|
514
505
|
if (!r)
|
|
515
506
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
516
|
-
const o = t.getState().getNestedState(e, []), a =
|
|
507
|
+
const o = t.getState().getNestedState(e, []), a = d?.validation?.key;
|
|
517
508
|
try {
|
|
518
509
|
const c = await r.action(o);
|
|
519
510
|
if (c && !c.success && c.errors && a) {
|
|
@@ -531,93 +522,93 @@ function ne(e, i, S, u) {
|
|
|
531
522
|
return r.onError && r.onError(c), { success: !1, error: c };
|
|
532
523
|
}
|
|
533
524
|
};
|
|
534
|
-
if (
|
|
535
|
-
const
|
|
536
|
-
return L(
|
|
525
|
+
if (l === "_status") {
|
|
526
|
+
const d = t.getState().getNestedState(e, n), r = t.getState().initialStateGlobal[e], o = q(r, n);
|
|
527
|
+
return L(d, o) ? "fresh" : "stale";
|
|
537
528
|
}
|
|
538
|
-
if (
|
|
529
|
+
if (l === "getStatus")
|
|
539
530
|
return function() {
|
|
540
|
-
const
|
|
531
|
+
const d = t().getNestedState(
|
|
541
532
|
e,
|
|
542
533
|
n
|
|
543
534
|
), r = t.getState().initialStateGlobal[e], o = q(r, n);
|
|
544
|
-
return L(
|
|
535
|
+
return L(d, o) ? "fresh" : "stale";
|
|
545
536
|
};
|
|
546
|
-
if (
|
|
537
|
+
if (l === "removeStorage")
|
|
547
538
|
return () => {
|
|
548
|
-
const
|
|
539
|
+
const d = t.getState().initialStateGlobal[e], r = H(e), o = Z(r?.localStorage?.key) ? r?.localStorage?.key(d) : r?.localStorage?.key, a = `${u}-${e}-${o}`;
|
|
549
540
|
console.log("removing storage", a), a && localStorage.removeItem(a);
|
|
550
541
|
};
|
|
551
|
-
if (
|
|
542
|
+
if (l === "showValidationErrors")
|
|
552
543
|
return () => {
|
|
553
|
-
const
|
|
554
|
-
if (!
|
|
544
|
+
const d = t.getState().getInitialOptions(e)?.validation;
|
|
545
|
+
if (!d?.key)
|
|
555
546
|
throw new Error("Validation key not found");
|
|
556
|
-
return t.getState().getValidationErrors(
|
|
547
|
+
return t.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
557
548
|
};
|
|
558
549
|
if (Array.isArray(m)) {
|
|
559
|
-
const
|
|
550
|
+
const d = () => h?.validIndices ? m.map((o, a) => ({
|
|
560
551
|
item: o,
|
|
561
|
-
originalIndex:
|
|
552
|
+
originalIndex: h.validIndices[a]
|
|
562
553
|
})) : t.getState().getNestedState(e, n).map((o, a) => ({
|
|
563
554
|
item: o,
|
|
564
555
|
originalIndex: a
|
|
565
556
|
}));
|
|
566
|
-
if (
|
|
557
|
+
if (l === "getSelected")
|
|
567
558
|
return () => {
|
|
568
559
|
const r = t.getState().getSelectedIndex(e, n.join("."));
|
|
569
560
|
if (r !== void 0)
|
|
570
561
|
return s(
|
|
571
562
|
m[r],
|
|
572
563
|
[...n, r.toString()],
|
|
573
|
-
|
|
564
|
+
h
|
|
574
565
|
);
|
|
575
566
|
};
|
|
576
|
-
if (
|
|
567
|
+
if (l === "clearSelected")
|
|
577
568
|
return () => {
|
|
578
569
|
t.getState().clearSelectedIndex({ stateKey: e, path: n });
|
|
579
570
|
};
|
|
580
|
-
if (
|
|
571
|
+
if (l === "getSelectedIndex")
|
|
581
572
|
return () => t.getState().getSelectedIndex(e, n.join(".")) ?? -1;
|
|
582
|
-
if (
|
|
573
|
+
if (l === "stateSort")
|
|
583
574
|
return (r) => {
|
|
584
|
-
const a = [...
|
|
575
|
+
const a = [...d()].sort(
|
|
585
576
|
(y, w) => r(y.item, w.item)
|
|
586
577
|
), c = a.map(({ item: y }) => y), p = {
|
|
587
|
-
...
|
|
578
|
+
...h,
|
|
588
579
|
validIndices: a.map(
|
|
589
580
|
({ originalIndex: y }) => y
|
|
590
581
|
)
|
|
591
582
|
};
|
|
592
583
|
return s(c, n, p);
|
|
593
584
|
};
|
|
594
|
-
if (
|
|
585
|
+
if (l === "stateFilter")
|
|
595
586
|
return (r) => {
|
|
596
|
-
const a =
|
|
587
|
+
const a = d().filter(
|
|
597
588
|
({ item: y }, w) => r(y, w)
|
|
598
589
|
), c = a.map(({ item: y }) => y), p = {
|
|
599
|
-
...
|
|
590
|
+
...h,
|
|
600
591
|
validIndices: a.map(
|
|
601
592
|
({ originalIndex: y }) => y
|
|
602
593
|
)
|
|
603
594
|
};
|
|
604
595
|
return s(c, n, p);
|
|
605
596
|
};
|
|
606
|
-
if (
|
|
597
|
+
if (l === "stateMap" || l === "stateMapNoRender")
|
|
607
598
|
return (r) => m.map((a, c) => {
|
|
608
599
|
let p;
|
|
609
|
-
|
|
610
|
-
const y = [...n, p.toString()], w = s(a, y,
|
|
600
|
+
h?.validIndices && h.validIndices[c] !== void 0 ? p = h.validIndices[c] : p = c;
|
|
601
|
+
const y = [...n, p.toString()], w = s(a, y, h);
|
|
611
602
|
return r(
|
|
612
603
|
a,
|
|
613
604
|
w,
|
|
614
605
|
c,
|
|
615
606
|
m,
|
|
616
|
-
s(m, n,
|
|
607
|
+
s(m, n, h)
|
|
617
608
|
);
|
|
618
609
|
});
|
|
619
|
-
if (
|
|
620
|
-
return (r) => re(
|
|
610
|
+
if (l === "$stateMap")
|
|
611
|
+
return (r) => re(Ge, {
|
|
621
612
|
proxy: {
|
|
622
613
|
_stateKey: e,
|
|
623
614
|
_path: n,
|
|
@@ -626,7 +617,7 @@ function ne(e, i, S, u) {
|
|
|
626
617
|
},
|
|
627
618
|
rebuildStateShape: s
|
|
628
619
|
});
|
|
629
|
-
if (
|
|
620
|
+
if (l === "stateFlattenOn")
|
|
630
621
|
return (r) => {
|
|
631
622
|
const o = m;
|
|
632
623
|
f.clear(), k++;
|
|
@@ -636,151 +627,151 @@ function ne(e, i, S, u) {
|
|
|
636
627
|
return s(
|
|
637
628
|
a,
|
|
638
629
|
[...n, "[*]", r],
|
|
639
|
-
|
|
630
|
+
h
|
|
640
631
|
);
|
|
641
632
|
};
|
|
642
|
-
if (
|
|
633
|
+
if (l === "index")
|
|
643
634
|
return (r) => {
|
|
644
635
|
const o = m[r];
|
|
645
636
|
return s(o, [...n, r.toString()]);
|
|
646
637
|
};
|
|
647
|
-
if (
|
|
638
|
+
if (l === "last")
|
|
648
639
|
return () => {
|
|
649
640
|
const r = t.getState().getNestedState(e, n);
|
|
650
641
|
if (r.length === 0) return;
|
|
651
642
|
const o = r.length - 1, a = r[o], c = [...n, o.toString()];
|
|
652
643
|
return s(a, c);
|
|
653
644
|
};
|
|
654
|
-
if (
|
|
655
|
-
return (r) => (
|
|
645
|
+
if (l === "insert")
|
|
646
|
+
return (r) => (I(n), se(i, r, n, e), s(
|
|
656
647
|
t.getState().getNestedState(e, n),
|
|
657
648
|
n
|
|
658
649
|
));
|
|
659
|
-
if (
|
|
650
|
+
if (l === "uniqueInsert")
|
|
660
651
|
return (r, o, a) => {
|
|
661
652
|
const c = t.getState().getNestedState(e, n), p = Z(r) ? r(c) : r;
|
|
662
653
|
let y = null;
|
|
663
654
|
if (!c.some(($) => {
|
|
664
655
|
if (o) {
|
|
665
|
-
const
|
|
666
|
-
(
|
|
656
|
+
const A = o.every(
|
|
657
|
+
(N) => L($[N], p[N])
|
|
667
658
|
);
|
|
668
|
-
return
|
|
659
|
+
return A && (y = $), A;
|
|
669
660
|
}
|
|
670
|
-
const
|
|
671
|
-
return
|
|
661
|
+
const T = L($, p);
|
|
662
|
+
return T && (y = $), T;
|
|
672
663
|
}))
|
|
673
|
-
|
|
664
|
+
I(n), se(i, p, n, e);
|
|
674
665
|
else if (a && y) {
|
|
675
|
-
const $ = a(y),
|
|
676
|
-
(
|
|
666
|
+
const $ = a(y), T = c.map(
|
|
667
|
+
(A) => L(A, y) ? $ : A
|
|
677
668
|
);
|
|
678
|
-
|
|
669
|
+
I(n), Q(i, T, n);
|
|
679
670
|
}
|
|
680
671
|
};
|
|
681
|
-
if (
|
|
672
|
+
if (l === "cut")
|
|
682
673
|
return (r, o) => {
|
|
683
674
|
if (!o?.waitForSync)
|
|
684
|
-
return
|
|
675
|
+
return I(n), K(i, n, e, r), s(
|
|
685
676
|
t.getState().getNestedState(e, n),
|
|
686
677
|
n
|
|
687
678
|
);
|
|
688
679
|
};
|
|
689
|
-
if (
|
|
680
|
+
if (l === "cutByValue")
|
|
690
681
|
return (r) => {
|
|
691
682
|
for (let o = 0; o < m.length; o++)
|
|
692
683
|
m[o] === r && K(i, n, e, o);
|
|
693
684
|
};
|
|
694
|
-
if (
|
|
685
|
+
if (l === "toggleByValue")
|
|
695
686
|
return (r) => {
|
|
696
687
|
const o = m.findIndex((a) => a === r);
|
|
697
688
|
o > -1 ? K(i, n, e, o) : se(i, r, n, e);
|
|
698
689
|
};
|
|
699
|
-
if (
|
|
690
|
+
if (l === "stateFind")
|
|
700
691
|
return (r) => {
|
|
701
|
-
const a =
|
|
692
|
+
const a = d().find(
|
|
702
693
|
({ item: p }, y) => r(p, y)
|
|
703
694
|
);
|
|
704
695
|
if (!a) return;
|
|
705
696
|
const c = [...n, a.originalIndex.toString()];
|
|
706
|
-
return s(a.item, c,
|
|
697
|
+
return s(a.item, c, h);
|
|
707
698
|
};
|
|
708
|
-
if (
|
|
699
|
+
if (l === "findWith")
|
|
709
700
|
return (r, o) => {
|
|
710
|
-
const c =
|
|
701
|
+
const c = d().find(
|
|
711
702
|
({ item: y }) => y[r] === o
|
|
712
703
|
);
|
|
713
704
|
if (!c) return;
|
|
714
705
|
const p = [...n, c.originalIndex.toString()];
|
|
715
|
-
return s(c.item, p,
|
|
706
|
+
return s(c.item, p, h);
|
|
716
707
|
};
|
|
717
708
|
}
|
|
718
709
|
const X = n[n.length - 1];
|
|
719
710
|
if (!isNaN(Number(X))) {
|
|
720
|
-
const
|
|
721
|
-
if (Array.isArray(r) &&
|
|
711
|
+
const d = n.slice(0, -1), r = t.getState().getNestedState(e, d);
|
|
712
|
+
if (Array.isArray(r) && l === "cut")
|
|
722
713
|
return () => K(
|
|
723
714
|
i,
|
|
724
|
-
|
|
715
|
+
d,
|
|
725
716
|
e,
|
|
726
717
|
Number(X)
|
|
727
718
|
);
|
|
728
719
|
}
|
|
729
|
-
if (
|
|
720
|
+
if (l === "get")
|
|
730
721
|
return () => t.getState().getNestedState(e, n);
|
|
731
|
-
if (
|
|
732
|
-
return (
|
|
722
|
+
if (l === "$derive")
|
|
723
|
+
return (d) => ce({
|
|
733
724
|
_stateKey: e,
|
|
734
725
|
_path: n,
|
|
735
|
-
_effect:
|
|
726
|
+
_effect: d.toString()
|
|
736
727
|
});
|
|
737
|
-
if (
|
|
738
|
-
return (
|
|
728
|
+
if (l === "$derive")
|
|
729
|
+
return (d) => ce({
|
|
739
730
|
_stateKey: e,
|
|
740
731
|
_path: n,
|
|
741
|
-
_effect:
|
|
732
|
+
_effect: d.toString()
|
|
742
733
|
});
|
|
743
|
-
if (
|
|
734
|
+
if (l === "$get")
|
|
744
735
|
return () => ce({
|
|
745
736
|
_stateKey: e,
|
|
746
737
|
_path: n
|
|
747
738
|
});
|
|
748
|
-
if (
|
|
749
|
-
const
|
|
750
|
-
return t.getState().getSyncInfo(
|
|
739
|
+
if (l === "lastSynced") {
|
|
740
|
+
const d = `${e}:${n.join(".")}`;
|
|
741
|
+
return t.getState().getSyncInfo(d);
|
|
751
742
|
}
|
|
752
|
-
if (
|
|
753
|
-
return (
|
|
754
|
-
if (
|
|
755
|
-
const
|
|
743
|
+
if (l == "getLocalStorage")
|
|
744
|
+
return (d) => ae(u + "-" + e + "-" + d);
|
|
745
|
+
if (l === "_selected") {
|
|
746
|
+
const d = n.slice(0, -1), r = d.join("."), o = t.getState().getNestedState(e, d);
|
|
756
747
|
return Array.isArray(o) ? Number(n[n.length - 1]) === t.getState().getSelectedIndex(e, r) : void 0;
|
|
757
748
|
}
|
|
758
|
-
if (
|
|
759
|
-
return (
|
|
749
|
+
if (l === "setSelected")
|
|
750
|
+
return (d) => {
|
|
760
751
|
const r = n.slice(0, -1), o = Number(n[n.length - 1]), a = r.join(".");
|
|
761
|
-
|
|
752
|
+
d ? t.getState().setSelectedIndex(e, a, o) : t.getState().setSelectedIndex(e, a, void 0);
|
|
762
753
|
const c = t.getState().getNestedState(e, [...r]);
|
|
763
|
-
Q(i, c, r),
|
|
754
|
+
Q(i, c, r), I(r);
|
|
764
755
|
};
|
|
765
|
-
if (
|
|
756
|
+
if (l === "toggleSelected")
|
|
766
757
|
return () => {
|
|
767
|
-
const
|
|
758
|
+
const d = n.slice(0, -1), r = Number(n[n.length - 1]), o = d.join("."), a = t.getState().getSelectedIndex(e, o);
|
|
768
759
|
t.getState().setSelectedIndex(
|
|
769
760
|
e,
|
|
770
761
|
o,
|
|
771
762
|
a === r ? void 0 : r
|
|
772
763
|
);
|
|
773
|
-
const c = t.getState().getNestedState(e, [...
|
|
774
|
-
Q(i, c,
|
|
764
|
+
const c = t.getState().getNestedState(e, [...d]);
|
|
765
|
+
Q(i, c, d), I(d);
|
|
775
766
|
};
|
|
776
767
|
if (n.length == 0) {
|
|
777
|
-
if (
|
|
778
|
-
return (
|
|
779
|
-
const r = t.getState().cogsStateStore[e], a =
|
|
768
|
+
if (l === "applyJsonPatch")
|
|
769
|
+
return (d) => {
|
|
770
|
+
const r = t.getState().cogsStateStore[e], a = Oe(r, d).newDocument, c = H(e), p = c?.middleware, y = t.getState().setInitialStateOptions;
|
|
780
771
|
c && p && y(e, {
|
|
781
772
|
...c,
|
|
782
773
|
middleware: void 0
|
|
783
|
-
}),
|
|
774
|
+
}), ke(
|
|
784
775
|
e,
|
|
785
776
|
t.getState().initialStateGlobal[e],
|
|
786
777
|
a,
|
|
@@ -794,141 +785,141 @@ function ne(e, i, S, u) {
|
|
|
794
785
|
const w = t.getState().stateComponents.get(e);
|
|
795
786
|
if (console.log("component update logic stateEntry", w), !w) return;
|
|
796
787
|
const $ = /* @__PURE__ */ new Set();
|
|
797
|
-
console.log("component update logic pathsToCheck", $), Array.isArray(r) && Array.isArray(a) && r.length !== a.length && $.add(""), console.log("component update logic pathsToCheck", $),
|
|
798
|
-
const
|
|
799
|
-
if (
|
|
800
|
-
const b =
|
|
788
|
+
console.log("component update logic pathsToCheck", $), Array.isArray(r) && Array.isArray(a) && r.length !== a.length && $.add(""), console.log("component update logic pathsToCheck", $), d.forEach((T) => {
|
|
789
|
+
const N = T.path.slice(1).split("/");
|
|
790
|
+
if (T.op === "add" || T.op === "remove") {
|
|
791
|
+
const b = N[N.length - 1];
|
|
801
792
|
if (!isNaN(parseInt(b))) {
|
|
802
|
-
const
|
|
803
|
-
$.add(
|
|
793
|
+
const F = N.slice(0, -1).join(".");
|
|
794
|
+
$.add(F), F === "" && $.add("");
|
|
804
795
|
}
|
|
805
796
|
}
|
|
806
|
-
let
|
|
807
|
-
|
|
808
|
-
|
|
797
|
+
let O = "";
|
|
798
|
+
N.forEach((b, F) => {
|
|
799
|
+
F > 0 && (O += "."), O += b, $.add(O);
|
|
809
800
|
}), $.add("");
|
|
810
801
|
});
|
|
811
802
|
for (const [
|
|
812
|
-
|
|
813
|
-
|
|
803
|
+
T,
|
|
804
|
+
A
|
|
814
805
|
] of w.components.entries()) {
|
|
815
|
-
console.log("component update logic component",
|
|
816
|
-
let
|
|
817
|
-
const
|
|
818
|
-
if (!
|
|
819
|
-
if (
|
|
820
|
-
|
|
806
|
+
console.log("component update logic component", A);
|
|
807
|
+
let N = !1;
|
|
808
|
+
const O = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
809
|
+
if (!O.includes("none")) {
|
|
810
|
+
if (O.includes("all")) {
|
|
811
|
+
A.forceUpdate();
|
|
821
812
|
continue;
|
|
822
813
|
}
|
|
823
|
-
if (
|
|
824
|
-
for (const b of
|
|
814
|
+
if (O.includes("component"))
|
|
815
|
+
for (const b of A.paths) {
|
|
825
816
|
if ($.has(b)) {
|
|
826
|
-
|
|
817
|
+
N = !0;
|
|
827
818
|
break;
|
|
828
819
|
}
|
|
829
|
-
for (const
|
|
830
|
-
if (
|
|
831
|
-
|
|
820
|
+
for (const F of $)
|
|
821
|
+
if (F.startsWith(b + ".") || b === "" && F !== "") {
|
|
822
|
+
N = !0;
|
|
832
823
|
break;
|
|
833
824
|
}
|
|
834
|
-
if (
|
|
825
|
+
if (N) break;
|
|
835
826
|
}
|
|
836
|
-
if (!
|
|
837
|
-
const b =
|
|
838
|
-
let
|
|
839
|
-
typeof b == "boolean" ? b && (
|
|
827
|
+
if (!N && O.includes("deps") && A.depsFunction) {
|
|
828
|
+
const b = A.depsFunction(a);
|
|
829
|
+
let F = !1;
|
|
830
|
+
typeof b == "boolean" ? b && (F = !0) : L(A.deps, b) || (A.deps = b, F = !0), F && (N = !0);
|
|
840
831
|
}
|
|
841
|
-
|
|
832
|
+
N && A.forceUpdate();
|
|
842
833
|
}
|
|
843
834
|
}
|
|
844
835
|
};
|
|
845
|
-
if (
|
|
836
|
+
if (l === "validateZodSchema")
|
|
846
837
|
return () => {
|
|
847
|
-
const
|
|
848
|
-
if (!
|
|
838
|
+
const d = t.getState().getInitialOptions(e)?.validation, r = t.getState().addValidationError;
|
|
839
|
+
if (!d?.zodSchema)
|
|
849
840
|
throw new Error("Zod schema not found");
|
|
850
|
-
if (!
|
|
841
|
+
if (!d?.key)
|
|
851
842
|
throw new Error("Validation key not found");
|
|
852
|
-
B(
|
|
843
|
+
B(d.key);
|
|
853
844
|
const o = t.getState().cogsStateStore[e];
|
|
854
845
|
try {
|
|
855
|
-
const a = t.getState().getValidationErrors(
|
|
846
|
+
const a = t.getState().getValidationErrors(d.key);
|
|
856
847
|
a && a.length > 0 && a.forEach(([p]) => {
|
|
857
|
-
p && p.startsWith(
|
|
848
|
+
p && p.startsWith(d.key) && B(p);
|
|
858
849
|
});
|
|
859
|
-
const c =
|
|
850
|
+
const c = d.zodSchema.safeParse(o);
|
|
860
851
|
return c.success ? !0 : (c.error.errors.forEach((y) => {
|
|
861
|
-
const w = y.path, $ = y.message,
|
|
862
|
-
r(
|
|
852
|
+
const w = y.path, $ = y.message, T = [d.key, ...w].join(".");
|
|
853
|
+
r(T, $);
|
|
863
854
|
}), oe(e), !1);
|
|
864
855
|
} catch (a) {
|
|
865
856
|
return console.error("Zod schema validation failed", a), !1;
|
|
866
857
|
}
|
|
867
858
|
};
|
|
868
|
-
if (
|
|
869
|
-
if (
|
|
859
|
+
if (l === "_componentId") return S;
|
|
860
|
+
if (l === "getComponents")
|
|
870
861
|
return () => t().stateComponents.get(e);
|
|
871
|
-
if (
|
|
872
|
-
return () =>
|
|
873
|
-
if (
|
|
862
|
+
if (l === "getAllFormRefs")
|
|
863
|
+
return () => ye.getState().getFormRefsByStateKey(e);
|
|
864
|
+
if (l === "_initialState")
|
|
874
865
|
return t.getState().initialStateGlobal[e];
|
|
875
|
-
if (
|
|
866
|
+
if (l === "_serverState")
|
|
876
867
|
return t.getState().serverState[e];
|
|
877
|
-
if (
|
|
868
|
+
if (l === "_isLoading")
|
|
878
869
|
return t.getState().isLoadingGlobal[e];
|
|
879
|
-
if (
|
|
870
|
+
if (l === "revertToInitialState")
|
|
880
871
|
return v.revertToInitialState;
|
|
881
|
-
if (
|
|
882
|
-
if (
|
|
872
|
+
if (l === "updateInitialState") return v.updateInitialState;
|
|
873
|
+
if (l === "removeValidation") return v.removeValidation;
|
|
883
874
|
}
|
|
884
|
-
if (
|
|
885
|
-
return () =>
|
|
886
|
-
if (
|
|
875
|
+
if (l === "getFormRef")
|
|
876
|
+
return () => ye.getState().getFormRef(e + "." + n.join("."));
|
|
877
|
+
if (l === "validationWrapper")
|
|
887
878
|
return ({
|
|
888
|
-
children:
|
|
879
|
+
children: d,
|
|
889
880
|
hideMessage: r
|
|
890
|
-
}) => /* @__PURE__ */
|
|
891
|
-
|
|
881
|
+
}) => /* @__PURE__ */ me(
|
|
882
|
+
Pe,
|
|
892
883
|
{
|
|
893
884
|
formOpts: r ? { validation: { message: "" } } : void 0,
|
|
894
885
|
path: n,
|
|
895
886
|
validationKey: t.getState().getInitialOptions(e)?.validation?.key || "",
|
|
896
887
|
stateKey: e,
|
|
897
|
-
validIndices:
|
|
898
|
-
children:
|
|
888
|
+
validIndices: h?.validIndices,
|
|
889
|
+
children: d
|
|
899
890
|
}
|
|
900
891
|
);
|
|
901
|
-
if (
|
|
902
|
-
if (
|
|
903
|
-
if (
|
|
904
|
-
if (
|
|
905
|
-
return (
|
|
892
|
+
if (l === "_stateKey") return e;
|
|
893
|
+
if (l === "_path") return n;
|
|
894
|
+
if (l === "_isServerSynced") return v._isServerSynced;
|
|
895
|
+
if (l === "update")
|
|
896
|
+
return (d, r) => {
|
|
906
897
|
if (r?.debounce)
|
|
907
|
-
|
|
908
|
-
Q(i,
|
|
898
|
+
Ce(() => {
|
|
899
|
+
Q(i, d, n, "");
|
|
909
900
|
const o = t.getState().getNestedState(e, n);
|
|
910
901
|
r?.afterUpdate && r.afterUpdate(o);
|
|
911
902
|
}, r.debounce);
|
|
912
903
|
else {
|
|
913
|
-
Q(i,
|
|
904
|
+
Q(i, d, n, "");
|
|
914
905
|
const o = t.getState().getNestedState(e, n);
|
|
915
906
|
r?.afterUpdate && r.afterUpdate(o);
|
|
916
907
|
}
|
|
917
|
-
|
|
908
|
+
I(n);
|
|
918
909
|
};
|
|
919
|
-
if (
|
|
920
|
-
return (
|
|
921
|
-
|
|
910
|
+
if (l === "formElement")
|
|
911
|
+
return (d, r) => /* @__PURE__ */ me(
|
|
912
|
+
be,
|
|
922
913
|
{
|
|
923
914
|
setState: i,
|
|
924
915
|
stateKey: e,
|
|
925
916
|
path: n,
|
|
926
|
-
child:
|
|
917
|
+
child: d,
|
|
927
918
|
formOpts: r
|
|
928
919
|
}
|
|
929
920
|
);
|
|
930
|
-
const J = [...n,
|
|
931
|
-
return s(P, J,
|
|
921
|
+
const J = [...n, l], P = t.getState().getNestedState(e, J);
|
|
922
|
+
return s(P, J, h);
|
|
932
923
|
}
|
|
933
924
|
}, D = new Proxy(_, C);
|
|
934
925
|
return f.set(M, {
|
|
@@ -941,9 +932,9 @@ function ne(e, i, S, u) {
|
|
|
941
932
|
);
|
|
942
933
|
}
|
|
943
934
|
function ce(e) {
|
|
944
|
-
return re(
|
|
935
|
+
return re(Le, { proxy: e });
|
|
945
936
|
}
|
|
946
|
-
function
|
|
937
|
+
function Ge({
|
|
947
938
|
proxy: e,
|
|
948
939
|
rebuildStateShape: i
|
|
949
940
|
}) {
|
|
@@ -952,41 +943,41 @@ function De({
|
|
|
952
943
|
S,
|
|
953
944
|
e._path
|
|
954
945
|
).stateMapNoRender(
|
|
955
|
-
(f, k,
|
|
946
|
+
(f, k, I, v, s) => e._mapFn(f, k, I, v, s)
|
|
956
947
|
) : null;
|
|
957
948
|
}
|
|
958
|
-
function
|
|
949
|
+
function Le({
|
|
959
950
|
proxy: e
|
|
960
951
|
}) {
|
|
961
952
|
const i = ee(null), S = `${e._stateKey}-${e._path.join(".")}`;
|
|
962
953
|
return de(() => {
|
|
963
954
|
const u = i.current;
|
|
964
955
|
if (!u || !u.parentElement) return;
|
|
965
|
-
const f = u.parentElement,
|
|
956
|
+
const f = u.parentElement, I = Array.from(f.childNodes).indexOf(u);
|
|
966
957
|
let v = f.getAttribute("data-parent-id");
|
|
967
958
|
v || (v = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", v));
|
|
968
959
|
const m = {
|
|
969
960
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
970
961
|
parentId: v,
|
|
971
|
-
position:
|
|
962
|
+
position: I,
|
|
972
963
|
effect: e._effect
|
|
973
964
|
};
|
|
974
965
|
t.getState().addSignalElement(S, m);
|
|
975
966
|
const n = t.getState().getNestedState(e._stateKey, e._path);
|
|
976
|
-
let
|
|
967
|
+
let h;
|
|
977
968
|
if (e._effect)
|
|
978
969
|
try {
|
|
979
|
-
|
|
970
|
+
h = new Function(
|
|
980
971
|
"state",
|
|
981
972
|
`return (${e._effect})(state)`
|
|
982
973
|
)(n);
|
|
983
974
|
} catch (_) {
|
|
984
|
-
console.error("Error evaluating effect function during mount:", _),
|
|
975
|
+
console.error("Error evaluating effect function during mount:", _), h = n;
|
|
985
976
|
}
|
|
986
977
|
else
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const M = document.createTextNode(String(
|
|
978
|
+
h = n;
|
|
979
|
+
h !== null && typeof h == "object" && (h = JSON.stringify(h));
|
|
980
|
+
const M = document.createTextNode(String(h));
|
|
990
981
|
u.replaceWith(M);
|
|
991
982
|
}, [e._stateKey, e._path.join("."), e._effect]), re("span", {
|
|
992
983
|
ref: i,
|
|
@@ -994,8 +985,8 @@ function We({
|
|
|
994
985
|
"data-signal-id": S
|
|
995
986
|
});
|
|
996
987
|
}
|
|
997
|
-
function
|
|
998
|
-
const i =
|
|
988
|
+
function rt(e) {
|
|
989
|
+
const i = Ne(
|
|
999
990
|
(S) => {
|
|
1000
991
|
const u = t.getState().stateComponents.get(e._stateKey) || {
|
|
1001
992
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1011,10 +1002,10 @@ function tt(e) {
|
|
|
1011
1002
|
}
|
|
1012
1003
|
export {
|
|
1013
1004
|
ce as $cogsSignal,
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1005
|
+
rt as $cogsSignalStore,
|
|
1006
|
+
et as addStateOptions,
|
|
1007
|
+
tt as createCogsState,
|
|
1008
|
+
nt as notifyComponent,
|
|
1009
|
+
We as useCogsStateFn
|
|
1019
1010
|
};
|
|
1020
1011
|
//# sourceMappingURL=CogsState.jsx.map
|