cogsbox-state 0.5.71 → 0.5.72
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 +233 -233
- 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
2
|
import { jsx as ct } from "react/jsx-runtime";
|
|
3
3
|
import { useState as et, useRef as Z, useEffect as nt, useLayoutEffect as It, useMemo as _t, createElement as Q, useSyncExternalStore as Et, startTransition as H } from "react";
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as K, updateFn as B, cutFunc as J, ValidationWrapper as
|
|
4
|
+
import { transformStateFunc as $t, isFunction as G, getNestedValue as U, isDeepEqual as M, debounce as wt } from "./utility.js";
|
|
5
|
+
import { pushFunc as K, updateFn as B, cutFunc as J, ValidationWrapper as Nt, FormControlComponent as Vt } from "./Functions.jsx";
|
|
6
6
|
import "zod";
|
|
7
7
|
import { getGlobalStore as r, formRefStore as lt } from "./store.js";
|
|
8
8
|
import { useCogsConfig as At } from "./CogsStateClient.jsx";
|
|
9
9
|
import rt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
10
|
function dt(t, i) {
|
|
11
|
-
const S = r.getState().getInitialOptions,
|
|
12
|
-
|
|
11
|
+
const S = r.getState().getInitialOptions, m = r.getState().setInitialStateOptions, g = S(t) || {};
|
|
12
|
+
m(t, {
|
|
13
13
|
...g,
|
|
14
14
|
...i
|
|
15
15
|
});
|
|
@@ -19,19 +19,19 @@ function ut({
|
|
|
19
19
|
options: i,
|
|
20
20
|
initialOptionsPart: S
|
|
21
21
|
}) {
|
|
22
|
-
const
|
|
22
|
+
const m = q(t) || {}, g = S[t] || {}, $ = r.getState().setInitialStateOptions, _ = { ...g, ...m };
|
|
23
23
|
let v = !1;
|
|
24
24
|
if (i)
|
|
25
|
-
for (const
|
|
26
|
-
_.hasOwnProperty(
|
|
27
|
-
v &&
|
|
25
|
+
for (const d in i)
|
|
26
|
+
_.hasOwnProperty(d) ? d == "localStorage" && i[d] && _[d].key !== i[d]?.key && (v = !0, _[d] = i[d]) : (v = !0, _[d] = i[d]);
|
|
27
|
+
v && $(t, _);
|
|
28
28
|
}
|
|
29
29
|
function qt(t, { formElements: i, validation: S }) {
|
|
30
30
|
return { initialState: t, formElements: i, validation: S };
|
|
31
31
|
}
|
|
32
32
|
const zt = (t, i) => {
|
|
33
33
|
let S = t;
|
|
34
|
-
const [
|
|
34
|
+
const [m, g] = $t(S);
|
|
35
35
|
(i?.formElements || i?.validation) && Object.keys(g).forEach((v) => {
|
|
36
36
|
g[v] = g[v] || {}, g[v].formElements = {
|
|
37
37
|
...i.formElements,
|
|
@@ -40,35 +40,35 @@ const zt = (t, i) => {
|
|
|
40
40
|
...g[v].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
42
|
};
|
|
43
|
-
}), r.getState().setInitialStates(
|
|
44
|
-
const
|
|
45
|
-
const [f] = et(
|
|
43
|
+
}), r.getState().setInitialStates(m);
|
|
44
|
+
const $ = (v, d) => {
|
|
45
|
+
const [f] = et(d?.componentId ?? rt());
|
|
46
46
|
ut({
|
|
47
47
|
stateKey: v,
|
|
48
|
-
options:
|
|
48
|
+
options: d,
|
|
49
49
|
initialOptionsPart: g
|
|
50
50
|
});
|
|
51
|
-
const e = r.getState().cogsStateStore[v] ||
|
|
52
|
-
|
|
51
|
+
const e = r.getState().cogsStateStore[v] || m[v], y = d?.modifyState ? d.modifyState(e) : e, [b, N] = Ft(
|
|
52
|
+
y,
|
|
53
53
|
{
|
|
54
54
|
stateKey: v,
|
|
55
|
-
syncUpdate:
|
|
55
|
+
syncUpdate: d?.syncUpdate,
|
|
56
56
|
componentId: f,
|
|
57
|
-
localStorage:
|
|
58
|
-
middleware:
|
|
59
|
-
enabledSync:
|
|
60
|
-
reactiveType:
|
|
61
|
-
reactiveDeps:
|
|
62
|
-
initialState:
|
|
63
|
-
dependencies:
|
|
57
|
+
localStorage: d?.localStorage,
|
|
58
|
+
middleware: d?.middleware,
|
|
59
|
+
enabledSync: d?.enabledSync,
|
|
60
|
+
reactiveType: d?.reactiveType,
|
|
61
|
+
reactiveDeps: d?.reactiveDeps,
|
|
62
|
+
initialState: d?.initialState,
|
|
63
|
+
dependencies: d?.dependencies
|
|
64
64
|
}
|
|
65
65
|
);
|
|
66
|
-
return
|
|
66
|
+
return N;
|
|
67
67
|
};
|
|
68
|
-
function _(v,
|
|
69
|
-
ut({ stateKey: v, options:
|
|
68
|
+
function _(v, d) {
|
|
69
|
+
ut({ stateKey: v, options: d, initialOptionsPart: g });
|
|
70
70
|
}
|
|
71
|
-
return { useCogsState:
|
|
71
|
+
return { useCogsState: $, setCogsOptions: _ };
|
|
72
72
|
}, {
|
|
73
73
|
setUpdaterState: Y,
|
|
74
74
|
setState: L,
|
|
@@ -88,31 +88,31 @@ const zt = (t, i) => {
|
|
|
88
88
|
} catch (i) {
|
|
89
89
|
return console.error("Error loading from localStorage:", i), null;
|
|
90
90
|
}
|
|
91
|
-
}, ht = (t, i, S,
|
|
91
|
+
}, ht = (t, i, S, m) => {
|
|
92
92
|
S.log && console.log(
|
|
93
93
|
"saving to localstorage",
|
|
94
94
|
i,
|
|
95
95
|
S.localStorage?.key,
|
|
96
|
-
|
|
96
|
+
m
|
|
97
97
|
);
|
|
98
98
|
const g = G(S.localStorage?.key) ? S.localStorage?.key(t) : S.localStorage?.key;
|
|
99
|
-
if (g &&
|
|
100
|
-
const
|
|
99
|
+
if (g && m) {
|
|
100
|
+
const $ = {
|
|
101
101
|
state: t,
|
|
102
102
|
lastUpdated: Date.now(),
|
|
103
103
|
lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
|
|
104
104
|
baseServerState: r.getState().serverState[i]
|
|
105
|
-
}, _ = `${
|
|
106
|
-
window.localStorage.setItem(_, JSON.stringify(
|
|
105
|
+
}, _ = `${m}-${i}-${g}`;
|
|
106
|
+
window.localStorage.setItem(_, JSON.stringify($));
|
|
107
107
|
}
|
|
108
|
-
}, bt = (t, i, S,
|
|
108
|
+
}, bt = (t, i, S, m, g, $) => {
|
|
109
109
|
const _ = {
|
|
110
110
|
initialState: i,
|
|
111
111
|
updaterState: X(
|
|
112
112
|
t,
|
|
113
|
-
|
|
113
|
+
m,
|
|
114
114
|
g,
|
|
115
|
-
|
|
115
|
+
$
|
|
116
116
|
),
|
|
117
117
|
state: S
|
|
118
118
|
};
|
|
@@ -123,39 +123,39 @@ const zt = (t, i) => {
|
|
|
123
123
|
const i = r.getState().stateComponents.get(t);
|
|
124
124
|
if (!i) return;
|
|
125
125
|
const S = /* @__PURE__ */ new Set();
|
|
126
|
-
i.components.forEach((
|
|
127
|
-
S.add(() =>
|
|
126
|
+
i.components.forEach((m) => {
|
|
127
|
+
S.add(() => m.forceUpdate());
|
|
128
128
|
}), queueMicrotask(() => {
|
|
129
129
|
H(() => {
|
|
130
|
-
S.forEach((
|
|
130
|
+
S.forEach((m) => m());
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
}, Bt = (t, i) => {
|
|
134
134
|
const S = r.getState().stateComponents.get(t);
|
|
135
135
|
if (S) {
|
|
136
|
-
const
|
|
136
|
+
const m = `${t}////${i}`, g = S.components.get(m);
|
|
137
137
|
g && g.forceUpdate();
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
function Ft(t, {
|
|
141
141
|
stateKey: i,
|
|
142
142
|
serverSync: S,
|
|
143
|
-
localStorage:
|
|
143
|
+
localStorage: m,
|
|
144
144
|
formElements: g,
|
|
145
|
-
middleware:
|
|
145
|
+
middleware: $,
|
|
146
146
|
reactiveDeps: _,
|
|
147
147
|
reactiveType: v,
|
|
148
|
-
componentId:
|
|
148
|
+
componentId: d,
|
|
149
149
|
initialState: f,
|
|
150
150
|
syncUpdate: e,
|
|
151
|
-
dependencies:
|
|
151
|
+
dependencies: y
|
|
152
152
|
} = {}) {
|
|
153
|
-
const [
|
|
154
|
-
let
|
|
155
|
-
const [
|
|
156
|
-
C.current = q(
|
|
157
|
-
if (e && e.stateKey ===
|
|
158
|
-
L(
|
|
153
|
+
const [b, N] = et({}), { sessionId: p } = At();
|
|
154
|
+
let h = !i;
|
|
155
|
+
const [l] = et(i ?? rt()), s = r.getState().stateLog[l], D = Z(/* @__PURE__ */ new Set()), x = Z(d ?? rt()), C = Z(null);
|
|
156
|
+
C.current = q(l), nt(() => {
|
|
157
|
+
if (e && e.stateKey === l && e.path?.[0]) {
|
|
158
|
+
L(l, (o) => ({
|
|
159
159
|
...o,
|
|
160
160
|
[e.path[0]]: e.newValue
|
|
161
161
|
}));
|
|
@@ -166,172 +166,172 @@ function Ft(t, {
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
}, [e]), nt(() => {
|
|
169
|
-
dt(
|
|
169
|
+
dt(l, {
|
|
170
170
|
initialState: f
|
|
171
171
|
});
|
|
172
172
|
const c = C.current;
|
|
173
173
|
let o = null;
|
|
174
174
|
c.log && console.log("newoptions", c);
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const u = G(c.localStorage?.key) ? c.localStorage?.key(f) : c.localStorage?.key;
|
|
176
|
+
u && p && (o = ft(
|
|
177
|
+
p + "-" + l + "-" + u
|
|
178
178
|
));
|
|
179
179
|
let E = null;
|
|
180
180
|
f && (E = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state), bt(
|
|
181
|
-
|
|
181
|
+
l,
|
|
182
182
|
f,
|
|
183
183
|
E,
|
|
184
184
|
n,
|
|
185
185
|
x.current,
|
|
186
|
-
|
|
187
|
-
), St(
|
|
188
|
-
}, [f, ...
|
|
189
|
-
|
|
186
|
+
p
|
|
187
|
+
), St(l), N({}));
|
|
188
|
+
}, [f, ...y || []]), It(() => {
|
|
189
|
+
h && dt(l, {
|
|
190
190
|
serverSync: S,
|
|
191
191
|
formElements: g,
|
|
192
192
|
initialState: f,
|
|
193
|
-
localStorage:
|
|
194
|
-
middleware:
|
|
193
|
+
localStorage: m,
|
|
194
|
+
middleware: $
|
|
195
195
|
});
|
|
196
|
-
const c = `${
|
|
196
|
+
const c = `${l}////${x.current}`, o = r.getState().stateComponents.get(l) || {
|
|
197
197
|
components: /* @__PURE__ */ new Map()
|
|
198
198
|
};
|
|
199
199
|
return o.components.set(c, {
|
|
200
|
-
forceUpdate: () =>
|
|
200
|
+
forceUpdate: () => N({}),
|
|
201
201
|
paths: /* @__PURE__ */ new Set(),
|
|
202
202
|
deps: [],
|
|
203
203
|
depsFunction: _ || void 0,
|
|
204
204
|
reactiveType: v ?? ["component", "deps"]
|
|
205
|
-
}), r.getState().stateComponents.set(
|
|
206
|
-
const
|
|
207
|
-
o && (o.components.delete(
|
|
205
|
+
}), r.getState().stateComponents.set(l, o), N({}), () => {
|
|
206
|
+
const u = `${l}////${x.current}`;
|
|
207
|
+
o && (o.components.delete(u), o.components.size === 0 && r.getState().stateComponents.delete(l));
|
|
208
208
|
};
|
|
209
209
|
}, []);
|
|
210
|
-
const n = (c, o,
|
|
210
|
+
const n = (c, o, u, E) => {
|
|
211
211
|
if (Array.isArray(o)) {
|
|
212
|
-
const
|
|
213
|
-
D.current.add(
|
|
212
|
+
const F = `${l}-${o.join(".")}`;
|
|
213
|
+
D.current.add(F);
|
|
214
214
|
}
|
|
215
|
-
L(
|
|
216
|
-
const
|
|
215
|
+
L(l, (F) => {
|
|
216
|
+
const V = G(c) ? c(F) : c, O = `${l}-${o.join(".")}`;
|
|
217
217
|
if (O) {
|
|
218
218
|
let P = !1, I = r.getState().signalDomElements.get(O);
|
|
219
|
-
if ((!I || I.size === 0) && (
|
|
220
|
-
const
|
|
221
|
-
if (Array.isArray(
|
|
219
|
+
if ((!I || I.size === 0) && (u.updateType === "insert" || u.updateType === "cut")) {
|
|
220
|
+
const A = o.slice(0, -1), k = U(V, A);
|
|
221
|
+
if (Array.isArray(k)) {
|
|
222
222
|
P = !0;
|
|
223
|
-
const
|
|
224
|
-
I = r.getState().signalDomElements.get(
|
|
223
|
+
const w = `${l}-${A.join(".")}`;
|
|
224
|
+
I = r.getState().signalDomElements.get(w);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
if (I) {
|
|
228
|
-
const
|
|
229
|
-
I.forEach(({ parentId:
|
|
230
|
-
const
|
|
231
|
-
`[data-parent-id="${
|
|
228
|
+
const A = P ? U(V, o.slice(0, -1)) : U(V, o);
|
|
229
|
+
I.forEach(({ parentId: k, position: w, effect: W }) => {
|
|
230
|
+
const j = document.querySelector(
|
|
231
|
+
`[data-parent-id="${k}"]`
|
|
232
232
|
);
|
|
233
|
-
if (
|
|
234
|
-
const st = Array.from(
|
|
235
|
-
if (st[
|
|
236
|
-
const vt = W ? new Function("state", `return (${W})(state)`)(
|
|
237
|
-
st[
|
|
233
|
+
if (j) {
|
|
234
|
+
const st = Array.from(j.childNodes);
|
|
235
|
+
if (st[w]) {
|
|
236
|
+
const vt = W ? new Function("state", `return (${W})(state)`)(A) : A;
|
|
237
|
+
st[w].textContent = String(vt);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
u.updateType === "update" && (E || C.current?.validationKey) && o && R(
|
|
244
244
|
(E || C.current?.validationKey) + "." + o.join(".")
|
|
245
245
|
);
|
|
246
246
|
const T = o.slice(0, o.length - 1);
|
|
247
|
-
|
|
247
|
+
u.updateType === "cut" && C.current?.validationKey && R(
|
|
248
248
|
C.current?.validationKey + "." + T.join(".")
|
|
249
|
-
),
|
|
249
|
+
), u.updateType === "insert" && C.current?.validationKey && kt(
|
|
250
250
|
C.current?.validationKey + "." + T.join(".")
|
|
251
|
-
).filter(([I,
|
|
252
|
-
let
|
|
253
|
-
if (I == T.join(".") &&
|
|
254
|
-
let
|
|
255
|
-
R(I), Ct(
|
|
251
|
+
).filter(([I, A]) => {
|
|
252
|
+
let k = I?.split(".").length;
|
|
253
|
+
if (I == T.join(".") && k == T.length - 1) {
|
|
254
|
+
let w = I + "." + T;
|
|
255
|
+
R(I), Ct(w, A);
|
|
256
256
|
}
|
|
257
257
|
});
|
|
258
|
-
const z = U(
|
|
258
|
+
const z = U(F, o), mt = U(V, o), yt = u.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), at = r.getState().stateComponents.get(l);
|
|
259
259
|
if (at)
|
|
260
260
|
for (const [P, I] of at.components.entries()) {
|
|
261
|
-
let
|
|
262
|
-
const
|
|
263
|
-
if (!
|
|
264
|
-
if (
|
|
261
|
+
let A = !1;
|
|
262
|
+
const k = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
|
|
263
|
+
if (!k.includes("none")) {
|
|
264
|
+
if (k.includes("all")) {
|
|
265
265
|
I.forceUpdate();
|
|
266
266
|
continue;
|
|
267
267
|
}
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
typeof
|
|
268
|
+
if (k.includes("component") && I.paths && (I.paths.has(yt) || I.paths.has("")) && (A = !0), !A && k.includes("deps") && I.depsFunction) {
|
|
269
|
+
const w = I.depsFunction(V);
|
|
270
|
+
typeof w == "boolean" ? w && (A = !0) : M(I.deps, w) || (I.deps = w, A = !0);
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
A && I.forceUpdate();
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
const it = {
|
|
276
276
|
timeStamp: Date.now(),
|
|
277
|
-
stateKey:
|
|
277
|
+
stateKey: l,
|
|
278
278
|
path: o,
|
|
279
|
-
updateType:
|
|
279
|
+
updateType: u.updateType,
|
|
280
280
|
status: "new",
|
|
281
281
|
oldValue: z,
|
|
282
282
|
newValue: mt
|
|
283
283
|
};
|
|
284
|
-
if (pt(
|
|
285
|
-
const
|
|
286
|
-
const W = `${
|
|
287
|
-
return
|
|
284
|
+
if (pt(l, (P) => {
|
|
285
|
+
const A = [...P ?? [], it].reduce((k, w) => {
|
|
286
|
+
const W = `${w.stateKey}:${JSON.stringify(w.path)}`, j = k.get(W);
|
|
287
|
+
return j ? (j.timeStamp = Math.max(j.timeStamp, w.timeStamp), j.newValue = w.newValue, j.oldValue = j.oldValue ?? w.oldValue, j.updateType = w.updateType) : k.set(W, { ...w }), k;
|
|
288
288
|
}, /* @__PURE__ */ new Map());
|
|
289
|
-
return Array.from(
|
|
289
|
+
return Array.from(A.values());
|
|
290
290
|
}), ht(
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
V,
|
|
292
|
+
l,
|
|
293
293
|
C.current,
|
|
294
|
-
|
|
295
|
-
),
|
|
294
|
+
p
|
|
295
|
+
), $ && $({
|
|
296
296
|
updateLog: s,
|
|
297
297
|
update: it
|
|
298
298
|
}), C.current?.serverSync) {
|
|
299
|
-
const P = r.getState().serverState[
|
|
300
|
-
Tt(
|
|
301
|
-
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state:
|
|
299
|
+
const P = r.getState().serverState[l], I = C.current?.serverSync;
|
|
300
|
+
Tt(l, {
|
|
301
|
+
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: V }),
|
|
302
302
|
rollBackState: P,
|
|
303
303
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
304
304
|
status: "waiting"
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
return
|
|
307
|
+
return V;
|
|
308
308
|
});
|
|
309
309
|
};
|
|
310
|
-
r.getState().updaterState[
|
|
311
|
-
|
|
310
|
+
r.getState().updaterState[l] || (Y(
|
|
311
|
+
l,
|
|
312
312
|
X(
|
|
313
|
-
|
|
313
|
+
l,
|
|
314
314
|
n,
|
|
315
315
|
x.current,
|
|
316
|
-
|
|
316
|
+
p
|
|
317
317
|
)
|
|
318
|
-
), r.getState().cogsStateStore[
|
|
318
|
+
), r.getState().cogsStateStore[l] || L(l, t), r.getState().initialStateGlobal[l] || ot(l, t));
|
|
319
319
|
const a = _t(() => X(
|
|
320
|
-
|
|
320
|
+
l,
|
|
321
321
|
n,
|
|
322
322
|
x.current,
|
|
323
|
-
|
|
324
|
-
), [
|
|
325
|
-
return [gt(
|
|
323
|
+
p
|
|
324
|
+
), [l]);
|
|
325
|
+
return [gt(l), a];
|
|
326
326
|
}
|
|
327
|
-
function X(t, i, S,
|
|
327
|
+
function X(t, i, S, m) {
|
|
328
328
|
const g = /* @__PURE__ */ new Map();
|
|
329
|
-
let
|
|
329
|
+
let $ = 0;
|
|
330
330
|
const _ = (f) => {
|
|
331
331
|
const e = f.join(".");
|
|
332
|
-
for (const [
|
|
333
|
-
(
|
|
334
|
-
|
|
332
|
+
for (const [y] of g)
|
|
333
|
+
(y === e || y.startsWith(e + ".")) && g.delete(y);
|
|
334
|
+
$++;
|
|
335
335
|
}, v = {
|
|
336
336
|
removeValidation: (f) => {
|
|
337
337
|
f?.validationKey && R(f.validationKey);
|
|
@@ -339,35 +339,35 @@ function X(t, i, S, y) {
|
|
|
339
339
|
revertToInitialState: (f) => {
|
|
340
340
|
const e = r.getState().getInitialOptions(t)?.validation;
|
|
341
341
|
e?.key && R(e?.key), f?.validationKey && R(f.validationKey);
|
|
342
|
-
const
|
|
343
|
-
g.clear(),
|
|
344
|
-
const
|
|
345
|
-
return
|
|
346
|
-
Y(t,
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
342
|
+
const y = r.getState().initialStateGlobal[t];
|
|
343
|
+
g.clear(), $++;
|
|
344
|
+
const b = d(y, []), N = q(t), p = G(N?.localStorage?.key) ? N?.localStorage?.key(y) : N?.localStorage?.key, h = `${m}-${t}-${p}`;
|
|
345
|
+
return h && localStorage.removeItem(h), H(() => {
|
|
346
|
+
Y(t, b), L(t, y);
|
|
347
|
+
const l = r.getState().stateComponents.get(t);
|
|
348
|
+
l && l.components.forEach((s) => {
|
|
349
|
+
s.forceUpdate();
|
|
350
350
|
});
|
|
351
|
-
}),
|
|
351
|
+
}), y;
|
|
352
352
|
},
|
|
353
353
|
updateInitialState: (f) => {
|
|
354
|
-
g.clear(),
|
|
355
|
-
const e = r.getState().initialStateGlobal[t],
|
|
356
|
-
|
|
357
|
-
const
|
|
354
|
+
g.clear(), $++;
|
|
355
|
+
const e = r.getState().initialStateGlobal[t], y = q(t), b = G(y?.localStorage?.key) ? y?.localStorage?.key(e) : y?.localStorage?.key, N = `${m}-${t}-${b}`;
|
|
356
|
+
N && localStorage.removeItem(N);
|
|
357
|
+
const p = X(
|
|
358
358
|
t,
|
|
359
359
|
i,
|
|
360
360
|
S,
|
|
361
|
-
|
|
361
|
+
m
|
|
362
362
|
);
|
|
363
363
|
return H(() => {
|
|
364
|
-
ot(t, f), Y(t,
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
364
|
+
ot(t, f), Y(t, p), L(t, f);
|
|
365
|
+
const h = r.getState().stateComponents.get(t);
|
|
366
|
+
h && h.components.forEach((l) => {
|
|
367
|
+
l.forceUpdate();
|
|
368
368
|
});
|
|
369
369
|
}), {
|
|
370
|
-
fetchId: (
|
|
370
|
+
fetchId: (h) => p.get()[h]
|
|
371
371
|
};
|
|
372
372
|
},
|
|
373
373
|
_initialState: r.getState().initialStateGlobal[t],
|
|
@@ -378,22 +378,22 @@ function X(t, i, S, y) {
|
|
|
378
378
|
return !!(f && M(f, gt(t)));
|
|
379
379
|
}
|
|
380
380
|
};
|
|
381
|
-
function
|
|
382
|
-
const
|
|
383
|
-
g.get(
|
|
384
|
-
const
|
|
381
|
+
function d(f, e = [], y) {
|
|
382
|
+
const b = e.map(String).join(".");
|
|
383
|
+
g.get(b);
|
|
384
|
+
const N = function() {
|
|
385
385
|
return r().getNestedState(t, e);
|
|
386
386
|
};
|
|
387
|
-
Object.keys(v).forEach((
|
|
388
|
-
|
|
387
|
+
Object.keys(v).forEach((l) => {
|
|
388
|
+
N[l] = v[l];
|
|
389
389
|
});
|
|
390
|
-
const
|
|
391
|
-
apply(
|
|
390
|
+
const p = {
|
|
391
|
+
apply(l, s, D) {
|
|
392
392
|
return console.log(
|
|
393
393
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
|
|
394
394
|
), console.trace("Apply trap stack trace"), r().getNestedState(t, e);
|
|
395
395
|
},
|
|
396
|
-
get(
|
|
396
|
+
get(l, s) {
|
|
397
397
|
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
398
398
|
const n = e.join("."), a = `${t}////${S}`, c = r.getState().stateComponents.get(t);
|
|
399
399
|
if (c) {
|
|
@@ -415,8 +415,8 @@ function X(t, i, S, y) {
|
|
|
415
415
|
};
|
|
416
416
|
if (s === "removeStorage")
|
|
417
417
|
return () => {
|
|
418
|
-
const n = r.getState().initialStateGlobal[t], a = q(t), c = G(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key
|
|
419
|
-
|
|
418
|
+
const n = r.getState().initialStateGlobal[t], a = q(t), c = G(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${m}-${t}-${c}`;
|
|
419
|
+
o && localStorage.removeItem(o);
|
|
420
420
|
};
|
|
421
421
|
if (s === "showValidationErrors")
|
|
422
422
|
return () => {
|
|
@@ -430,42 +430,42 @@ function X(t, i, S, y) {
|
|
|
430
430
|
return () => {
|
|
431
431
|
const n = r.getState().getSelectedIndex(t, e.join("."));
|
|
432
432
|
if (n !== void 0)
|
|
433
|
-
return
|
|
433
|
+
return d(
|
|
434
434
|
f[n],
|
|
435
435
|
[...e, n.toString()],
|
|
436
|
-
|
|
436
|
+
y
|
|
437
437
|
);
|
|
438
438
|
};
|
|
439
439
|
if (s === "stateSort")
|
|
440
440
|
return (n) => {
|
|
441
|
-
const o = [...r.getState().getNestedState(t, e).map((
|
|
442
|
-
...
|
|
441
|
+
const o = [...r.getState().getNestedState(t, e).map((u, E) => ({
|
|
442
|
+
...u,
|
|
443
443
|
__origIndex: E.toString()
|
|
444
444
|
}))].sort(n);
|
|
445
|
-
return g.clear(),
|
|
446
|
-
filtered: [...
|
|
445
|
+
return g.clear(), $++, d(o, e, {
|
|
446
|
+
filtered: [...y?.filtered || [], e],
|
|
447
447
|
validIndices: o.map(
|
|
448
|
-
(
|
|
448
|
+
(u) => parseInt(u.__origIndex)
|
|
449
449
|
)
|
|
450
450
|
});
|
|
451
451
|
};
|
|
452
452
|
if (s === "stateMap" || s === "stateMapNoRender")
|
|
453
453
|
return (n) => {
|
|
454
|
-
const a =
|
|
454
|
+
const a = y?.filtered?.some(
|
|
455
455
|
(o) => o.join(".") === e.join(".")
|
|
456
456
|
), c = a ? f : r.getState().getNestedState(t, e);
|
|
457
|
-
return s !== "stateMapNoRender" && (g.clear(),
|
|
458
|
-
const E = a && o.__origIndex ? o.__origIndex :
|
|
457
|
+
return s !== "stateMapNoRender" && (g.clear(), $++), c.map((o, u) => {
|
|
458
|
+
const E = a && o.__origIndex ? o.__origIndex : u, F = d(
|
|
459
459
|
o,
|
|
460
460
|
[...e, E.toString()],
|
|
461
|
-
|
|
461
|
+
y
|
|
462
462
|
);
|
|
463
463
|
return n(
|
|
464
464
|
o,
|
|
465
|
-
|
|
466
|
-
|
|
465
|
+
F,
|
|
466
|
+
u,
|
|
467
467
|
f,
|
|
468
|
-
|
|
468
|
+
d(f, e, y)
|
|
469
469
|
);
|
|
470
470
|
});
|
|
471
471
|
};
|
|
@@ -477,21 +477,21 @@ function X(t, i, S, y) {
|
|
|
477
477
|
_mapFn: n
|
|
478
478
|
// Pass the actual function, not string
|
|
479
479
|
},
|
|
480
|
-
rebuildStateShape:
|
|
480
|
+
rebuildStateShape: d
|
|
481
481
|
});
|
|
482
482
|
if (s === "stateFlattenOn")
|
|
483
483
|
return (n) => {
|
|
484
|
-
const c =
|
|
485
|
-
(
|
|
484
|
+
const c = y?.filtered?.some(
|
|
485
|
+
(u) => u.join(".") === e.join(".")
|
|
486
486
|
) ? f : r.getState().getNestedState(t, e);
|
|
487
|
-
g.clear(),
|
|
487
|
+
g.clear(), $++;
|
|
488
488
|
const o = c.flatMap(
|
|
489
|
-
(
|
|
489
|
+
(u, E) => u[n] ?? []
|
|
490
490
|
);
|
|
491
|
-
return
|
|
491
|
+
return d(
|
|
492
492
|
o,
|
|
493
493
|
[...e, "[*]", n],
|
|
494
|
-
|
|
494
|
+
y
|
|
495
495
|
);
|
|
496
496
|
};
|
|
497
497
|
if (s === "findWith")
|
|
@@ -500,37 +500,37 @@ function X(t, i, S, y) {
|
|
|
500
500
|
(E) => E[n] === a
|
|
501
501
|
);
|
|
502
502
|
if (c === -1) return;
|
|
503
|
-
const o = f[c],
|
|
504
|
-
return g.clear(),
|
|
503
|
+
const o = f[c], u = [...e, c.toString()];
|
|
504
|
+
return g.clear(), $++, g.clear(), $++, d(o, u);
|
|
505
505
|
};
|
|
506
506
|
if (s === "index")
|
|
507
507
|
return (n) => {
|
|
508
508
|
const a = f[n];
|
|
509
|
-
return
|
|
509
|
+
return d(a, [...e, n.toString()]);
|
|
510
510
|
};
|
|
511
511
|
if (s === "insert")
|
|
512
|
-
return (n) => (_(e), K(i, n, e, t),
|
|
512
|
+
return (n) => (_(e), K(i, n, e, t), d(
|
|
513
513
|
r.getState().cogsStateStore[t],
|
|
514
514
|
[]
|
|
515
515
|
));
|
|
516
516
|
if (s === "uniqueInsert")
|
|
517
517
|
return (n, a, c) => {
|
|
518
|
-
const o = r.getState().getNestedState(t, e),
|
|
518
|
+
const o = r.getState().getNestedState(t, e), u = G(n) ? n(o) : n;
|
|
519
519
|
let E = null;
|
|
520
|
-
if (!o.some((
|
|
520
|
+
if (!o.some((V) => {
|
|
521
521
|
if (a) {
|
|
522
522
|
const T = a.every(
|
|
523
|
-
(z) => M(
|
|
523
|
+
(z) => M(V[z], u[z])
|
|
524
524
|
);
|
|
525
|
-
return T && (E =
|
|
525
|
+
return T && (E = V), T;
|
|
526
526
|
}
|
|
527
|
-
const O = M(
|
|
528
|
-
return O && (E =
|
|
527
|
+
const O = M(V, u);
|
|
528
|
+
return O && (E = V), O;
|
|
529
529
|
}))
|
|
530
|
-
_(e), K(i,
|
|
530
|
+
_(e), K(i, u, e, t);
|
|
531
531
|
else if (c && E) {
|
|
532
|
-
const
|
|
533
|
-
(T) => M(T, E) ?
|
|
532
|
+
const V = c(E), O = o.map(
|
|
533
|
+
(T) => M(T, E) ? V : T
|
|
534
534
|
);
|
|
535
535
|
_(e), B(i, O, e);
|
|
536
536
|
}
|
|
@@ -551,14 +551,14 @@ function X(t, i, S, y) {
|
|
|
551
551
|
};
|
|
552
552
|
if (s === "stateFilter")
|
|
553
553
|
return (n) => {
|
|
554
|
-
const a = f.map((
|
|
555
|
-
...
|
|
554
|
+
const a = f.map((u, E) => ({
|
|
555
|
+
...u,
|
|
556
556
|
__origIndex: E.toString()
|
|
557
557
|
})), c = [], o = [];
|
|
558
|
-
for (let
|
|
559
|
-
n(a[
|
|
560
|
-
return g.clear(),
|
|
561
|
-
filtered: [...
|
|
558
|
+
for (let u = 0; u < a.length; u++)
|
|
559
|
+
n(a[u], u) && (c.push(u), o.push(a[u]));
|
|
560
|
+
return g.clear(), $++, d(o, e, {
|
|
561
|
+
filtered: [...y?.filtered || [], e],
|
|
562
562
|
validIndices: c
|
|
563
563
|
// Always pass validIndices, even if empty
|
|
564
564
|
});
|
|
@@ -599,7 +599,7 @@ function X(t, i, S, y) {
|
|
|
599
599
|
return r.getState().getSyncInfo(n);
|
|
600
600
|
}
|
|
601
601
|
if (s == "getLocalStorage")
|
|
602
|
-
return (n) => ft(
|
|
602
|
+
return (n) => ft(m + "-" + t + "-" + n);
|
|
603
603
|
if (s === "_selected") {
|
|
604
604
|
const n = e.slice(0, -1), a = n.join("."), c = r.getState().getNestedState(t, n);
|
|
605
605
|
return Array.isArray(c) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
|
|
@@ -608,8 +608,8 @@ function X(t, i, S, y) {
|
|
|
608
608
|
return (n) => {
|
|
609
609
|
const a = e.slice(0, -1), c = Number(e[e.length - 1]), o = a.join(".");
|
|
610
610
|
n ? r.getState().setSelectedIndex(t, o, c) : r.getState().setSelectedIndex(t, o, void 0);
|
|
611
|
-
const
|
|
612
|
-
B(i,
|
|
611
|
+
const u = r.getState().getNestedState(t, [...a]);
|
|
612
|
+
B(i, u, a), _(a);
|
|
613
613
|
};
|
|
614
614
|
if (e.length == 0) {
|
|
615
615
|
if (s === "validateZodSchema")
|
|
@@ -626,9 +626,9 @@ function X(t, i, S, y) {
|
|
|
626
626
|
o && o.length > 0 && o.forEach(([E]) => {
|
|
627
627
|
E && E.startsWith(n.key) && R(E);
|
|
628
628
|
});
|
|
629
|
-
const
|
|
630
|
-
return
|
|
631
|
-
const
|
|
629
|
+
const u = n.zodSchema.safeParse(c);
|
|
630
|
+
return u.success ? !0 : (u.error.errors.forEach((F) => {
|
|
631
|
+
const V = F.path, O = F.message, T = [n.key, ...V].join(".");
|
|
632
632
|
a(T, O);
|
|
633
633
|
}), St(t), !1);
|
|
634
634
|
} catch (o) {
|
|
@@ -658,13 +658,13 @@ function X(t, i, S, y) {
|
|
|
658
658
|
children: n,
|
|
659
659
|
hideMessage: a
|
|
660
660
|
}) => /* @__PURE__ */ ct(
|
|
661
|
-
|
|
661
|
+
Nt,
|
|
662
662
|
{
|
|
663
663
|
formOpts: a ? { validation: { message: "" } } : void 0,
|
|
664
664
|
path: e,
|
|
665
665
|
validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
|
|
666
666
|
stateKey: t,
|
|
667
|
-
validIndices:
|
|
667
|
+
validIndices: y?.validIndices,
|
|
668
668
|
children: n
|
|
669
669
|
}
|
|
670
670
|
);
|
|
@@ -674,7 +674,7 @@ function X(t, i, S, y) {
|
|
|
674
674
|
if (s === "update")
|
|
675
675
|
return (n, a) => {
|
|
676
676
|
if (a?.debounce)
|
|
677
|
-
|
|
677
|
+
wt(() => {
|
|
678
678
|
B(i, n, e, "");
|
|
679
679
|
const c = r.getState().getNestedState(t, e);
|
|
680
680
|
a?.afterUpdate && a.afterUpdate(c);
|
|
@@ -688,7 +688,7 @@ function X(t, i, S, y) {
|
|
|
688
688
|
};
|
|
689
689
|
if (s === "formElement")
|
|
690
690
|
return (n, a) => /* @__PURE__ */ ct(
|
|
691
|
-
|
|
691
|
+
Vt,
|
|
692
692
|
{
|
|
693
693
|
setState: i,
|
|
694
694
|
stateKey: t,
|
|
@@ -698,15 +698,15 @@ function X(t, i, S, y) {
|
|
|
698
698
|
}
|
|
699
699
|
);
|
|
700
700
|
const x = [...e, s], C = r.getState().getNestedState(t, x);
|
|
701
|
-
return
|
|
701
|
+
return d(C, x, y);
|
|
702
702
|
}
|
|
703
|
-
},
|
|
704
|
-
return g.set(
|
|
705
|
-
proxy:
|
|
706
|
-
stateVersion:
|
|
707
|
-
}),
|
|
703
|
+
}, h = new Proxy(N, p);
|
|
704
|
+
return g.set(b, {
|
|
705
|
+
proxy: h,
|
|
706
|
+
stateVersion: $
|
|
707
|
+
}), h;
|
|
708
708
|
}
|
|
709
|
-
return
|
|
709
|
+
return d(
|
|
710
710
|
r.getState().getNestedState(t, [])
|
|
711
711
|
);
|
|
712
712
|
}
|
|
@@ -722,7 +722,7 @@ function jt({
|
|
|
722
722
|
S,
|
|
723
723
|
t._path
|
|
724
724
|
).stateMapNoRender(
|
|
725
|
-
(g,
|
|
725
|
+
(g, $, _, v, d) => t._mapFn(g, $, _, v, d)
|
|
726
726
|
) : null;
|
|
727
727
|
}
|
|
728
728
|
function Ot({
|
|
@@ -730,9 +730,9 @@ function Ot({
|
|
|
730
730
|
}) {
|
|
731
731
|
const i = Z(null), S = `${t._stateKey}-${t._path.join(".")}`;
|
|
732
732
|
return nt(() => {
|
|
733
|
-
const
|
|
734
|
-
if (!
|
|
735
|
-
const g =
|
|
733
|
+
const m = i.current;
|
|
734
|
+
if (!m || !m.parentElement) return;
|
|
735
|
+
const g = m.parentElement, _ = Array.from(g.childNodes).indexOf(m);
|
|
736
736
|
let v = g.getAttribute("data-parent-id");
|
|
737
737
|
v || (v = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", v));
|
|
738
738
|
const f = {
|
|
@@ -743,21 +743,21 @@ function Ot({
|
|
|
743
743
|
};
|
|
744
744
|
r.getState().addSignalElement(S, f);
|
|
745
745
|
const e = r.getState().getNestedState(t._stateKey, t._path);
|
|
746
|
-
let
|
|
746
|
+
let y;
|
|
747
747
|
if (t._effect)
|
|
748
748
|
try {
|
|
749
|
-
|
|
749
|
+
y = new Function(
|
|
750
750
|
"state",
|
|
751
751
|
`return (${t._effect})(state)`
|
|
752
752
|
)(e);
|
|
753
|
-
} catch (
|
|
754
|
-
console.error("Error evaluating effect function during mount:",
|
|
753
|
+
} catch (N) {
|
|
754
|
+
console.error("Error evaluating effect function during mount:", N), y = e;
|
|
755
755
|
}
|
|
756
756
|
else
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const
|
|
760
|
-
|
|
757
|
+
y = e;
|
|
758
|
+
y !== null && typeof y == "object" && (y = JSON.stringify(y));
|
|
759
|
+
const b = document.createTextNode(String(y));
|
|
760
|
+
m.replaceWith(b);
|
|
761
761
|
}, [t._stateKey, t._path.join("."), t._effect]), Q("span", {
|
|
762
762
|
ref: i,
|
|
763
763
|
style: { display: "none" },
|
|
@@ -767,13 +767,13 @@ function Ot({
|
|
|
767
767
|
function Jt(t) {
|
|
768
768
|
const i = Et(
|
|
769
769
|
(S) => {
|
|
770
|
-
const
|
|
770
|
+
const m = r.getState().stateComponents.get(t._stateKey) || {
|
|
771
771
|
components: /* @__PURE__ */ new Map()
|
|
772
772
|
};
|
|
773
|
-
return
|
|
773
|
+
return m.components.set(t._stateKey, {
|
|
774
774
|
forceUpdate: S,
|
|
775
775
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
776
|
-
}), () =>
|
|
776
|
+
}), () => m.components.delete(t._stateKey);
|
|
777
777
|
},
|
|
778
778
|
() => r.getState().getNestedState(t._stateKey, t._path)
|
|
779
779
|
);
|