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