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