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