cogsbox-state 0.5.40 → 0.5.42
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 +161 -163
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.jsx +34 -34
- package/dist/Functions.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -8,8 +8,8 @@ import { getGlobalStore as o, formRefStore as lt } from "./store.js";
|
|
|
8
8
|
import { useCogsConfig as Nt } from "./CogsStateClient.jsx";
|
|
9
9
|
import tt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
10
|
function dt(t, a) {
|
|
11
|
-
const
|
|
12
|
-
return a.log && (console.log("setAndMergeOptions", t, a), console.log("setAndMergeOptions oldValue", d)),
|
|
11
|
+
const u = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, d = u(t) || {};
|
|
12
|
+
return a.log && (console.log("setAndMergeOptions", t, a), console.log("setAndMergeOptions oldValue", d)), f(t, {
|
|
13
13
|
...d,
|
|
14
14
|
...a
|
|
15
15
|
}), {
|
|
@@ -20,21 +20,21 @@ function dt(t, a) {
|
|
|
20
20
|
function ut({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: a,
|
|
23
|
-
initialOptionsPart:
|
|
23
|
+
initialOptionsPart: u
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
25
|
+
const f = et(t) || {}, E = { ...u?.[t] || {}, ...f };
|
|
26
26
|
let w = !1;
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if (a)
|
|
28
|
+
for (const m in a)
|
|
29
|
+
E.hasOwnProperty(m) || (w = !0, E[m] = a[m]);
|
|
30
|
+
w && o.getState().setInitialStateOptions(t, E);
|
|
31
31
|
}
|
|
32
|
-
function Wt(t, { formElements: a, validation:
|
|
33
|
-
return { initialState: t, formElements: a, validation:
|
|
32
|
+
function Wt(t, { formElements: a, validation: u }) {
|
|
33
|
+
return { initialState: t, formElements: a, validation: u };
|
|
34
34
|
}
|
|
35
35
|
const qt = (t, a) => {
|
|
36
|
-
let
|
|
37
|
-
const [
|
|
36
|
+
let u = t;
|
|
37
|
+
const [f, d] = _t(u);
|
|
38
38
|
(a?.formElements || a?.validation) && Object.keys(d).forEach((m) => {
|
|
39
39
|
d[m] = d[m] || {}, d[m].formElements = {
|
|
40
40
|
...a.formElements,
|
|
@@ -43,33 +43,33 @@ const qt = (t, a) => {
|
|
|
43
43
|
...d[m].formElements || {}
|
|
44
44
|
// State-specific overrides
|
|
45
45
|
};
|
|
46
|
-
}), o.getState().setInitialStates(
|
|
47
|
-
const E = (m,
|
|
48
|
-
const [p] = Y(
|
|
46
|
+
}), o.getState().setInitialStates(f);
|
|
47
|
+
const E = (m, I) => {
|
|
48
|
+
const [p] = Y(I?.componentId ?? tt());
|
|
49
49
|
ut({
|
|
50
50
|
stateKey: m,
|
|
51
|
-
options:
|
|
51
|
+
options: I
|
|
52
52
|
});
|
|
53
|
-
const s = o.getState().cogsStateStore[m] ||
|
|
54
|
-
|
|
55
|
-
const [
|
|
53
|
+
const s = o.getState().cogsStateStore[m] || f[m], e = I?.modifyState ? I.modifyState(s) : s;
|
|
54
|
+
I?.log && console.log("useCogsState", m, I);
|
|
55
|
+
const [v, N] = Ot(
|
|
56
56
|
e,
|
|
57
57
|
{
|
|
58
58
|
stateKey: m,
|
|
59
|
-
syncUpdate:
|
|
59
|
+
syncUpdate: I?.syncUpdate,
|
|
60
60
|
componentId: p,
|
|
61
|
-
localStorage:
|
|
62
|
-
middleware:
|
|
63
|
-
enabledSync:
|
|
64
|
-
reactiveType:
|
|
65
|
-
reactiveDeps:
|
|
66
|
-
initState:
|
|
61
|
+
localStorage: I?.localStorage,
|
|
62
|
+
middleware: I?.middleware,
|
|
63
|
+
enabledSync: I?.enabledSync,
|
|
64
|
+
reactiveType: I?.reactiveType,
|
|
65
|
+
reactiveDeps: I?.reactiveDeps,
|
|
66
|
+
initState: I?.initState
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
69
|
return N;
|
|
70
70
|
};
|
|
71
|
-
function w(m,
|
|
72
|
-
ut({ stateKey: m, options:
|
|
71
|
+
function w(m, I) {
|
|
72
|
+
ut({ stateKey: m, options: I, initialOptionsPart: d });
|
|
73
73
|
}
|
|
74
74
|
return { useCogsState: E, setCogsOptions: w };
|
|
75
75
|
}, {
|
|
@@ -91,31 +91,31 @@ const qt = (t, a) => {
|
|
|
91
91
|
} catch (a) {
|
|
92
92
|
return console.error("Error loading from localStorage:", a), null;
|
|
93
93
|
}
|
|
94
|
-
}, Tt = (t, a,
|
|
95
|
-
if (
|
|
94
|
+
}, Tt = (t, a, u, f) => {
|
|
95
|
+
if (u.log && console.log(
|
|
96
96
|
"saving to localstorage",
|
|
97
97
|
a,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
),
|
|
98
|
+
u.localStorage?.key,
|
|
99
|
+
f
|
|
100
|
+
), u.localStorage?.key && f) {
|
|
101
101
|
const d = {
|
|
102
102
|
state: t,
|
|
103
103
|
lastUpdated: Date.now(),
|
|
104
104
|
lastSyncedWithServer: o.getState().serverSyncLog[a]?.[0]?.timeStamp,
|
|
105
105
|
baseServerState: o.getState().serverState[a]
|
|
106
|
-
}, E = `${
|
|
106
|
+
}, E = `${f}-${a}-${u.localStorage?.key}`;
|
|
107
107
|
window.localStorage.setItem(E, JSON.stringify(d));
|
|
108
108
|
}
|
|
109
|
-
}, Ft = (t, a,
|
|
109
|
+
}, Ft = (t, a, u, f, d, E) => {
|
|
110
110
|
const w = {
|
|
111
111
|
initialState: a,
|
|
112
112
|
updaterState: Z(
|
|
113
113
|
t,
|
|
114
|
-
|
|
114
|
+
f,
|
|
115
115
|
d,
|
|
116
116
|
E
|
|
117
117
|
),
|
|
118
|
-
state:
|
|
118
|
+
state: u
|
|
119
119
|
};
|
|
120
120
|
J(() => {
|
|
121
121
|
nt(t, w.initialState), B(t, w.updaterState), x(t, w.state);
|
|
@@ -123,36 +123,36 @@ const qt = (t, a) => {
|
|
|
123
123
|
}, mt = (t) => {
|
|
124
124
|
const a = o.getState().stateComponents.get(t);
|
|
125
125
|
if (!a) return;
|
|
126
|
-
const
|
|
127
|
-
a.components.forEach((
|
|
128
|
-
|
|
126
|
+
const u = /* @__PURE__ */ new Set();
|
|
127
|
+
a.components.forEach((f) => {
|
|
128
|
+
u.add(() => f.forceUpdate());
|
|
129
129
|
}), queueMicrotask(() => {
|
|
130
130
|
J(() => {
|
|
131
|
-
|
|
131
|
+
u.forEach((f) => f());
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
}, zt = (t, a) => {
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
135
|
+
const u = o.getState().stateComponents.get(t);
|
|
136
|
+
if (u) {
|
|
137
|
+
const f = `${t}////${a}`, d = u.components.get(f);
|
|
138
138
|
d && d.forceUpdate();
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
function
|
|
141
|
+
function Ot(t, {
|
|
142
142
|
stateKey: a,
|
|
143
|
-
serverSync:
|
|
144
|
-
localStorage:
|
|
143
|
+
serverSync: u,
|
|
144
|
+
localStorage: f,
|
|
145
145
|
formElements: d,
|
|
146
146
|
middleware: E,
|
|
147
147
|
reactiveDeps: w,
|
|
148
148
|
reactiveType: m,
|
|
149
|
-
componentId:
|
|
149
|
+
componentId: I,
|
|
150
150
|
initState: p,
|
|
151
151
|
syncUpdate: s
|
|
152
152
|
} = {}) {
|
|
153
|
-
const [e,
|
|
154
|
-
let
|
|
155
|
-
const [c] = Y(a ?? tt()),
|
|
153
|
+
const [e, v] = Y({}), { sessionId: N } = Nt();
|
|
154
|
+
let k = !a;
|
|
155
|
+
const [c] = Y(a ?? tt()), R = o.getState().stateLog[c], P = z(/* @__PURE__ */ new Set()), i = z(I ?? tt()), $ = z(null);
|
|
156
156
|
$.current = et(c), K(() => {
|
|
157
157
|
if (s && s.stateKey === c && s.path?.[0]) {
|
|
158
158
|
x(c, (r) => ({
|
|
@@ -168,12 +168,10 @@ function jt(t, {
|
|
|
168
168
|
}, [s]), $.current.log && (console.log(
|
|
169
169
|
"latestInitialOptionsRef.current ",
|
|
170
170
|
$.current
|
|
171
|
-
), console.log("latestInitialOptionsRef.current localStorage",
|
|
171
|
+
), console.log("latestInitialOptionsRef.current localStorage", f)), K(() => {
|
|
172
172
|
const n = dt(c, {
|
|
173
|
-
initState: p
|
|
174
|
-
localStorage: u
|
|
173
|
+
initState: p
|
|
175
174
|
});
|
|
176
|
-
$.current = n;
|
|
177
175
|
let r = null;
|
|
178
176
|
n.log && console.log("newoptions", n), n.localStorage?.key && N && (r = St(
|
|
179
177
|
N + "-" + c + "-" + n.localStorage?.key
|
|
@@ -183,52 +181,52 @@ function jt(t, {
|
|
|
183
181
|
c,
|
|
184
182
|
p?.initialState,
|
|
185
183
|
l,
|
|
186
|
-
|
|
184
|
+
U,
|
|
187
185
|
i.current,
|
|
188
186
|
N
|
|
189
|
-
), mt(c),
|
|
190
|
-
}, [
|
|
191
|
-
|
|
192
|
-
serverSync:
|
|
187
|
+
), mt(c), v({}));
|
|
188
|
+
}, [...p?.dependencies || []]), vt(() => {
|
|
189
|
+
k && dt(c, {
|
|
190
|
+
serverSync: u,
|
|
193
191
|
formElements: d,
|
|
194
192
|
initState: p,
|
|
195
|
-
localStorage:
|
|
193
|
+
localStorage: f,
|
|
196
194
|
middleware: E
|
|
197
195
|
});
|
|
198
196
|
const n = `${c}////${i.current}`, r = o.getState().stateComponents.get(c) || {
|
|
199
197
|
components: /* @__PURE__ */ new Map()
|
|
200
198
|
};
|
|
201
199
|
return r.components.set(n, {
|
|
202
|
-
forceUpdate: () =>
|
|
200
|
+
forceUpdate: () => v({}),
|
|
203
201
|
paths: /* @__PURE__ */ new Set(),
|
|
204
202
|
deps: [],
|
|
205
203
|
depsFunction: w || void 0,
|
|
206
204
|
reactiveType: m ?? ["component", "deps"]
|
|
207
|
-
}), o.getState().stateComponents.set(c, r),
|
|
205
|
+
}), o.getState().stateComponents.set(c, r), v({}), () => {
|
|
208
206
|
const l = `${c}////${i.current}`;
|
|
209
207
|
r && (r.components.delete(l), r.components.size === 0 && o.getState().stateComponents.delete(c));
|
|
210
208
|
};
|
|
211
209
|
}, []);
|
|
212
|
-
const
|
|
210
|
+
const U = (n, r, l, g) => {
|
|
213
211
|
if (Array.isArray(r)) {
|
|
214
212
|
const S = `${c}-${r.join(".")}`;
|
|
215
|
-
|
|
213
|
+
P.current.add(S);
|
|
216
214
|
}
|
|
217
215
|
x(c, (S) => {
|
|
218
|
-
const _ = ft(n) ? n(S) : n,
|
|
219
|
-
if (
|
|
220
|
-
let M = !1,
|
|
221
|
-
if ((!
|
|
216
|
+
const _ = ft(n) ? n(S) : n, O = `${c}-${r.join(".")}`;
|
|
217
|
+
if (O) {
|
|
218
|
+
let M = !1, y = o.getState().signalDomElements.get(O);
|
|
219
|
+
if ((!y || y.size === 0) && (l.updateType === "insert" || l.updateType === "cut")) {
|
|
222
220
|
const h = r.slice(0, -1), C = L(_, h);
|
|
223
221
|
if (Array.isArray(C)) {
|
|
224
222
|
M = !0;
|
|
225
223
|
const V = `${c}-${h.join(".")}`;
|
|
226
|
-
|
|
224
|
+
y = o.getState().signalDomElements.get(V);
|
|
227
225
|
}
|
|
228
226
|
}
|
|
229
|
-
if (
|
|
227
|
+
if (y) {
|
|
230
228
|
const h = M ? L(_, r.slice(0, -1)) : L(_, r);
|
|
231
|
-
|
|
229
|
+
y.forEach(({ parentId: C, position: V, effect: D }) => {
|
|
232
230
|
const T = document.querySelector(
|
|
233
231
|
`[data-parent-id="${C}"]`
|
|
234
232
|
);
|
|
@@ -250,28 +248,28 @@ function jt(t, {
|
|
|
250
248
|
$.current?.validationKey + "." + A.join(".")
|
|
251
249
|
), l.updateType === "insert" && $.current?.validationKey && $t(
|
|
252
250
|
$.current?.validationKey + "." + A.join(".")
|
|
253
|
-
).filter(([
|
|
254
|
-
let C =
|
|
255
|
-
if (
|
|
256
|
-
let V =
|
|
257
|
-
b(
|
|
251
|
+
).filter(([y, h]) => {
|
|
252
|
+
let C = y?.split(".").length;
|
|
253
|
+
if (y == A.join(".") && C == A.length - 1) {
|
|
254
|
+
let V = y + "." + A;
|
|
255
|
+
b(y), At(V, h);
|
|
258
256
|
}
|
|
259
257
|
});
|
|
260
|
-
const
|
|
258
|
+
const j = L(S, r), F = L(_, r), W = l.updateType === "update" ? r.join(".") : [...r].slice(0, -1).join("."), rt = o.getState().stateComponents.get(c);
|
|
261
259
|
if (rt)
|
|
262
|
-
for (const [M,
|
|
260
|
+
for (const [M, y] of rt.components.entries()) {
|
|
263
261
|
let h = !1;
|
|
264
|
-
const C = Array.isArray(
|
|
262
|
+
const C = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
265
263
|
if (!C.includes("none")) {
|
|
266
264
|
if (C.includes("all")) {
|
|
267
|
-
|
|
265
|
+
y.forceUpdate();
|
|
268
266
|
continue;
|
|
269
267
|
}
|
|
270
|
-
if (C.includes("component") &&
|
|
271
|
-
const V =
|
|
272
|
-
typeof V == "boolean" ? V && (h = !0) : G(
|
|
268
|
+
if (C.includes("component") && y.paths && (y.paths.has(W) || y.paths.has("")) && (h = !0), !h && C.includes("deps") && y.depsFunction) {
|
|
269
|
+
const V = y.depsFunction(_);
|
|
270
|
+
typeof V == "boolean" ? V && (h = !0) : G(y.deps, V) || (y.deps = V, h = !0);
|
|
273
271
|
}
|
|
274
|
-
h &&
|
|
272
|
+
h && y.forceUpdate();
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
275
|
const ot = {
|
|
@@ -280,7 +278,7 @@ function jt(t, {
|
|
|
280
278
|
path: r,
|
|
281
279
|
updateType: l.updateType,
|
|
282
280
|
status: "new",
|
|
283
|
-
oldValue:
|
|
281
|
+
oldValue: j,
|
|
284
282
|
newValue: F
|
|
285
283
|
};
|
|
286
284
|
if (ht(c, (M) => {
|
|
@@ -295,14 +293,14 @@ function jt(t, {
|
|
|
295
293
|
$.current,
|
|
296
294
|
N
|
|
297
295
|
), E && E({
|
|
298
|
-
updateLog:
|
|
296
|
+
updateLog: R,
|
|
299
297
|
update: ot
|
|
300
298
|
}), $.current?.serverSync) {
|
|
301
|
-
const M = o.getState().serverState[c],
|
|
299
|
+
const M = o.getState().serverState[c], y = $.current?.serverSync;
|
|
302
300
|
Ct(c, {
|
|
303
|
-
syncKey: typeof
|
|
301
|
+
syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: _ }),
|
|
304
302
|
rollBackState: M,
|
|
305
|
-
actionTimeStamp: Date.now() + (
|
|
303
|
+
actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
|
|
306
304
|
status: "waiting"
|
|
307
305
|
});
|
|
308
306
|
}
|
|
@@ -313,46 +311,46 @@ function jt(t, {
|
|
|
313
311
|
c,
|
|
314
312
|
Z(
|
|
315
313
|
c,
|
|
316
|
-
|
|
314
|
+
U,
|
|
317
315
|
i.current,
|
|
318
316
|
N
|
|
319
317
|
)
|
|
320
318
|
), o.getState().cogsStateStore[c] || x(c, t), o.getState().initialStateGlobal[c] || nt(c, t));
|
|
321
319
|
const Q = It(() => Z(
|
|
322
320
|
c,
|
|
323
|
-
|
|
321
|
+
U,
|
|
324
322
|
i.current,
|
|
325
323
|
N
|
|
326
324
|
), [c]);
|
|
327
325
|
return [gt(c), Q];
|
|
328
326
|
}
|
|
329
|
-
function Z(t, a,
|
|
327
|
+
function Z(t, a, u, f) {
|
|
330
328
|
const d = /* @__PURE__ */ new Map();
|
|
331
329
|
let E = 0;
|
|
332
330
|
const w = (s) => {
|
|
333
331
|
const e = s.join(".");
|
|
334
|
-
for (const [
|
|
335
|
-
(
|
|
332
|
+
for (const [v] of d)
|
|
333
|
+
(v === e || v.startsWith(e + ".")) && d.delete(v);
|
|
336
334
|
E++;
|
|
337
|
-
}, m = /* @__PURE__ */ new Map(),
|
|
335
|
+
}, m = /* @__PURE__ */ new Map(), I = {
|
|
338
336
|
removeValidation: (s) => {
|
|
339
337
|
s?.validationKey && b(s.validationKey);
|
|
340
338
|
},
|
|
341
339
|
revertToInitialState: (s) => {
|
|
342
340
|
const e = o.getState().getInitialOptions(t)?.validation;
|
|
343
341
|
e?.key && b(e?.key), s?.validationKey && b(s.validationKey);
|
|
344
|
-
const
|
|
342
|
+
const v = o.getState().initialStateGlobal[t];
|
|
345
343
|
d.clear(), E++;
|
|
346
|
-
const N = p(
|
|
344
|
+
const N = p(v, []);
|
|
347
345
|
J(() => {
|
|
348
|
-
B(t, N), x(t,
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
346
|
+
B(t, N), x(t, v);
|
|
347
|
+
const k = o.getState().stateComponents.get(t);
|
|
348
|
+
k && k.components.forEach((R) => {
|
|
349
|
+
R.forceUpdate();
|
|
352
350
|
});
|
|
353
351
|
const c = et(t);
|
|
354
352
|
c?.localStorage?.key && localStorage.removeItem(
|
|
355
|
-
c?.initState ?
|
|
353
|
+
c?.initState ? f + "-" + t + "-" + c?.localStorage?.key : t
|
|
356
354
|
), localStorage.removeItem(t);
|
|
357
355
|
});
|
|
358
356
|
},
|
|
@@ -361,17 +359,17 @@ function Z(t, a, f, u) {
|
|
|
361
359
|
const e = Z(
|
|
362
360
|
t,
|
|
363
361
|
a,
|
|
364
|
-
|
|
365
|
-
|
|
362
|
+
u,
|
|
363
|
+
f
|
|
366
364
|
);
|
|
367
365
|
return J(() => {
|
|
368
366
|
nt(t, s), B(t, e), x(t, s);
|
|
369
|
-
const
|
|
370
|
-
|
|
367
|
+
const v = o.getState().stateComponents.get(t);
|
|
368
|
+
v && v.components.forEach((N) => {
|
|
371
369
|
N.forceUpdate();
|
|
372
370
|
}), localStorage.removeItem(t);
|
|
373
371
|
}), {
|
|
374
|
-
fetchId: (
|
|
372
|
+
fetchId: (v) => e.get()[v]
|
|
375
373
|
};
|
|
376
374
|
},
|
|
377
375
|
_initialState: o.getState().initialStateGlobal[t],
|
|
@@ -382,22 +380,22 @@ function Z(t, a, f, u) {
|
|
|
382
380
|
return !!(s && G(s, gt(t)));
|
|
383
381
|
}
|
|
384
382
|
};
|
|
385
|
-
function p(s, e = [],
|
|
383
|
+
function p(s, e = [], v) {
|
|
386
384
|
const N = e.map(String).join(".");
|
|
387
385
|
d.get(N);
|
|
388
|
-
const
|
|
386
|
+
const k = function() {
|
|
389
387
|
return o().getNestedState(t, e);
|
|
390
388
|
};
|
|
391
|
-
Object.keys(
|
|
392
|
-
|
|
389
|
+
Object.keys(I).forEach((P) => {
|
|
390
|
+
k[P] = I[P];
|
|
393
391
|
});
|
|
394
392
|
const c = {
|
|
395
|
-
apply(
|
|
393
|
+
apply(P, i, $) {
|
|
396
394
|
return o().getNestedState(t, e);
|
|
397
395
|
},
|
|
398
|
-
get(
|
|
396
|
+
get(P, i) {
|
|
399
397
|
if (i !== "then" && !i.startsWith("$") && i !== "stateMapNoRender") {
|
|
400
|
-
const n = e.join("."), r = `${t}////${
|
|
398
|
+
const n = e.join("."), r = `${t}////${u}`, l = o.getState().stateComponents.get(t);
|
|
401
399
|
if (l) {
|
|
402
400
|
const g = l.components.get(r);
|
|
403
401
|
g && (e.length > 0 || i === "get") && g.paths.add(n);
|
|
@@ -418,31 +416,31 @@ function Z(t, a, f, u) {
|
|
|
418
416
|
return p(
|
|
419
417
|
s[n],
|
|
420
418
|
[...e, n.toString()],
|
|
421
|
-
|
|
419
|
+
v
|
|
422
420
|
);
|
|
423
421
|
};
|
|
424
422
|
if (i === "stateMap" || i === "stateMapNoRender")
|
|
425
423
|
return (n) => {
|
|
426
|
-
const r =
|
|
424
|
+
const r = v?.filtered?.some(
|
|
427
425
|
(g) => g.join(".") === e.join(".")
|
|
428
426
|
), l = r ? s : o.getState().getNestedState(t, e);
|
|
429
427
|
return i !== "stateMapNoRender" && (d.clear(), E++), l.map((g, S) => {
|
|
430
|
-
const _ = r && g.__origIndex ? g.__origIndex : S,
|
|
428
|
+
const _ = r && g.__origIndex ? g.__origIndex : S, O = p(
|
|
431
429
|
g,
|
|
432
430
|
[...e, _.toString()],
|
|
433
|
-
|
|
431
|
+
v
|
|
434
432
|
);
|
|
435
433
|
return n(
|
|
436
434
|
g,
|
|
437
|
-
|
|
435
|
+
O,
|
|
438
436
|
S,
|
|
439
437
|
s,
|
|
440
|
-
p(s, e,
|
|
438
|
+
p(s, e, v)
|
|
441
439
|
);
|
|
442
440
|
});
|
|
443
441
|
};
|
|
444
442
|
if (i === "$stateMap")
|
|
445
|
-
return (n) => H(
|
|
443
|
+
return (n) => H(jt, {
|
|
446
444
|
proxy: {
|
|
447
445
|
_stateKey: t,
|
|
448
446
|
_path: e,
|
|
@@ -453,7 +451,7 @@ function Z(t, a, f, u) {
|
|
|
453
451
|
});
|
|
454
452
|
if (i === "stateFlattenOn")
|
|
455
453
|
return (n) => {
|
|
456
|
-
const l =
|
|
454
|
+
const l = v?.filtered?.some(
|
|
457
455
|
(S) => S.join(".") === e.join(".")
|
|
458
456
|
) ? s : o.getState().getNestedState(t, e);
|
|
459
457
|
d.clear(), E++;
|
|
@@ -463,7 +461,7 @@ function Z(t, a, f, u) {
|
|
|
463
461
|
return p(
|
|
464
462
|
g,
|
|
465
463
|
[...e, "[*]", n],
|
|
466
|
-
|
|
464
|
+
v
|
|
467
465
|
);
|
|
468
466
|
};
|
|
469
467
|
if (i === "findWith")
|
|
@@ -496,15 +494,15 @@ function Z(t, a, f, u) {
|
|
|
496
494
|
);
|
|
497
495
|
return F && (_ = A), F;
|
|
498
496
|
}
|
|
499
|
-
const
|
|
500
|
-
return
|
|
497
|
+
const j = G(A, S);
|
|
498
|
+
return j && (_ = A), j;
|
|
501
499
|
}))
|
|
502
500
|
w(e), st(a, S, e, t);
|
|
503
501
|
else if (l && _) {
|
|
504
|
-
const A = l(_),
|
|
502
|
+
const A = l(_), j = g.map(
|
|
505
503
|
(F) => G(F, _) ? A : F
|
|
506
504
|
);
|
|
507
|
-
w(e), q(a,
|
|
505
|
+
w(e), q(a, j, e);
|
|
508
506
|
}
|
|
509
507
|
};
|
|
510
508
|
if (i === "cut")
|
|
@@ -520,7 +518,7 @@ function Z(t, a, f, u) {
|
|
|
520
518
|
for (let S = 0; S < r.length; S++)
|
|
521
519
|
n(r[S], S) && (l.push(S), g.push(r[S]));
|
|
522
520
|
return d.clear(), E++, p(g, e, {
|
|
523
|
-
filtered: [...
|
|
521
|
+
filtered: [...v?.filtered || [], e],
|
|
524
522
|
validIndices: l
|
|
525
523
|
// Always pass validIndices, even if empty
|
|
526
524
|
});
|
|
@@ -565,7 +563,7 @@ function Z(t, a, f, u) {
|
|
|
565
563
|
return Array.isArray(l) ? Number(e[e.length - 1]) === m.get(r) : void 0;
|
|
566
564
|
}
|
|
567
565
|
if (i == "getLocalStorage")
|
|
568
|
-
return (n) => St(
|
|
566
|
+
return (n) => St(f + "-" + t + "-" + n);
|
|
569
567
|
if (i === "setSelected")
|
|
570
568
|
return (n) => {
|
|
571
569
|
const r = e.slice(0, -1), l = Number(e[e.length - 1]), g = r.join(".");
|
|
@@ -589,15 +587,15 @@ function Z(t, a, f, u) {
|
|
|
589
587
|
_ && _.startsWith(n.key) && b(_);
|
|
590
588
|
});
|
|
591
589
|
const S = n.zodSchema.safeParse(l);
|
|
592
|
-
return S.success ? !0 : (S.error.errors.forEach((
|
|
593
|
-
const A =
|
|
594
|
-
r(F,
|
|
590
|
+
return S.success ? !0 : (S.error.errors.forEach((O) => {
|
|
591
|
+
const A = O.path, j = O.message, F = [n.key, ...A].join(".");
|
|
592
|
+
r(F, j);
|
|
595
593
|
}), mt(t), !1);
|
|
596
594
|
} catch (g) {
|
|
597
595
|
return console.error("Zod schema validation failed", g), !1;
|
|
598
596
|
}
|
|
599
597
|
};
|
|
600
|
-
if (i === "_componentId") return
|
|
598
|
+
if (i === "_componentId") return u;
|
|
601
599
|
if (i === "getComponents")
|
|
602
600
|
return () => o().stateComponents.get(t);
|
|
603
601
|
if (i === "getAllFormRefs")
|
|
@@ -609,9 +607,9 @@ function Z(t, a, f, u) {
|
|
|
609
607
|
if (i === "_isLoading")
|
|
610
608
|
return o.getState().isLoadingGlobal[t];
|
|
611
609
|
if (i === "revertToInitialState")
|
|
612
|
-
return
|
|
613
|
-
if (i === "updateInitialState") return
|
|
614
|
-
if (i === "removeValidation") return
|
|
610
|
+
return I.revertToInitialState;
|
|
611
|
+
if (i === "updateInitialState") return I.updateInitialState;
|
|
612
|
+
if (i === "removeValidation") return I.removeValidation;
|
|
615
613
|
}
|
|
616
614
|
if (i === "getFormRef")
|
|
617
615
|
return () => lt.getState().getFormRef(t + "." + e.join("."));
|
|
@@ -626,13 +624,13 @@ function Z(t, a, f, u) {
|
|
|
626
624
|
path: e,
|
|
627
625
|
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
628
626
|
stateKey: t,
|
|
629
|
-
validIndices:
|
|
627
|
+
validIndices: v?.validIndices,
|
|
630
628
|
children: n
|
|
631
629
|
}
|
|
632
630
|
);
|
|
633
631
|
if (i === "_stateKey") return t;
|
|
634
632
|
if (i === "_path") return e;
|
|
635
|
-
if (i === "_isServerSynced") return
|
|
633
|
+
if (i === "_isServerSynced") return I._isServerSynced;
|
|
636
634
|
if (i === "update")
|
|
637
635
|
return (n, r) => {
|
|
638
636
|
if (r?.debounce)
|
|
@@ -659,14 +657,14 @@ function Z(t, a, f, u) {
|
|
|
659
657
|
formOpts: r
|
|
660
658
|
}
|
|
661
659
|
);
|
|
662
|
-
const
|
|
663
|
-
return p(Q,
|
|
660
|
+
const U = [...e, i], Q = o.getState().getNestedState(t, U);
|
|
661
|
+
return p(Q, U, v);
|
|
664
662
|
}
|
|
665
|
-
},
|
|
663
|
+
}, R = new Proxy(k, c);
|
|
666
664
|
return d.set(N, {
|
|
667
|
-
proxy:
|
|
665
|
+
proxy: R,
|
|
668
666
|
stateVersion: E
|
|
669
|
-
}),
|
|
667
|
+
}), R;
|
|
670
668
|
}
|
|
671
669
|
return p(
|
|
672
670
|
o.getState().getNestedState(t, [])
|
|
@@ -675,26 +673,26 @@ function Z(t, a, f, u) {
|
|
|
675
673
|
function X(t) {
|
|
676
674
|
return H(Mt, { proxy: t });
|
|
677
675
|
}
|
|
678
|
-
function
|
|
676
|
+
function jt({
|
|
679
677
|
proxy: t,
|
|
680
678
|
rebuildStateShape: a
|
|
681
679
|
}) {
|
|
682
|
-
const
|
|
683
|
-
return Array.isArray(
|
|
684
|
-
|
|
680
|
+
const u = o().getNestedState(t._stateKey, t._path);
|
|
681
|
+
return Array.isArray(u) ? a(
|
|
682
|
+
u,
|
|
685
683
|
t._path
|
|
686
684
|
).stateMapNoRender(
|
|
687
|
-
(d, E, w, m,
|
|
685
|
+
(d, E, w, m, I) => t._mapFn(d, E, w, m, I)
|
|
688
686
|
) : null;
|
|
689
687
|
}
|
|
690
688
|
function Mt({
|
|
691
689
|
proxy: t
|
|
692
690
|
}) {
|
|
693
|
-
const a = z(null),
|
|
691
|
+
const a = z(null), u = `${t._stateKey}-${t._path.join(".")}`;
|
|
694
692
|
return K(() => {
|
|
695
|
-
const
|
|
696
|
-
if (!
|
|
697
|
-
const d =
|
|
693
|
+
const f = a.current;
|
|
694
|
+
if (!f || !f.parentElement) return;
|
|
695
|
+
const d = f.parentElement, w = Array.from(d.childNodes).indexOf(f);
|
|
698
696
|
let m = d.getAttribute("data-parent-id");
|
|
699
697
|
m || (m = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", m));
|
|
700
698
|
const p = {
|
|
@@ -703,7 +701,7 @@ function Mt({
|
|
|
703
701
|
position: w,
|
|
704
702
|
effect: t._effect
|
|
705
703
|
};
|
|
706
|
-
o.getState().addSignalElement(
|
|
704
|
+
o.getState().addSignalElement(u, p);
|
|
707
705
|
const s = o.getState().getNestedState(t._stateKey, t._path);
|
|
708
706
|
let e;
|
|
709
707
|
if (t._effect)
|
|
@@ -718,24 +716,24 @@ function Mt({
|
|
|
718
716
|
else
|
|
719
717
|
e = s;
|
|
720
718
|
e !== null && typeof e == "object" && (e = JSON.stringify(e));
|
|
721
|
-
const
|
|
722
|
-
|
|
719
|
+
const v = document.createTextNode(String(e));
|
|
720
|
+
f.replaceWith(v);
|
|
723
721
|
}, [t._stateKey, t._path.join("."), t._effect]), H("span", {
|
|
724
722
|
ref: a,
|
|
725
723
|
style: { display: "none" },
|
|
726
|
-
"data-signal-id":
|
|
724
|
+
"data-signal-id": u
|
|
727
725
|
});
|
|
728
726
|
}
|
|
729
727
|
function Jt(t) {
|
|
730
728
|
const a = Et(
|
|
731
|
-
(
|
|
732
|
-
const
|
|
729
|
+
(u) => {
|
|
730
|
+
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
733
731
|
components: /* @__PURE__ */ new Map()
|
|
734
732
|
};
|
|
735
|
-
return
|
|
736
|
-
forceUpdate:
|
|
733
|
+
return f.components.set(t._stateKey, {
|
|
734
|
+
forceUpdate: u,
|
|
737
735
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
738
|
-
}), () =>
|
|
736
|
+
}), () => f.components.delete(t._stateKey);
|
|
739
737
|
},
|
|
740
738
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
741
739
|
);
|
|
@@ -747,6 +745,6 @@ export {
|
|
|
747
745
|
Wt as addStateOptions,
|
|
748
746
|
qt as createCogsState,
|
|
749
747
|
zt as notifyComponent,
|
|
750
|
-
|
|
748
|
+
Ot as useCogsStateFn
|
|
751
749
|
};
|
|
752
750
|
//# sourceMappingURL=CogsState.jsx.map
|