cogsbox-state 0.5.85 → 0.5.87
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 +214 -215
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -8,52 +8,52 @@ 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
|
|
12
|
-
|
|
13
|
-
...
|
|
11
|
+
const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, u = m(t) || {};
|
|
12
|
+
y(t, {
|
|
13
|
+
...u,
|
|
14
14
|
...i
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
function ut({
|
|
18
18
|
stateKey: t,
|
|
19
19
|
options: i,
|
|
20
|
-
initialOptionsPart:
|
|
20
|
+
initialOptionsPart: m
|
|
21
21
|
}) {
|
|
22
|
-
const
|
|
23
|
-
let
|
|
22
|
+
const y = q(t) || {}, u = m[t] || {}, $ = r.getState().setInitialStateOptions, _ = { ...u, ...y };
|
|
23
|
+
let v = !1;
|
|
24
24
|
if (i)
|
|
25
25
|
for (const l in i)
|
|
26
|
-
_.hasOwnProperty(l) ? l == "localStorage" && i[l] && _[l].key !== i[l]?.key && (
|
|
27
|
-
console.log("existingOptions",
|
|
26
|
+
_.hasOwnProperty(l) ? l == "localStorage" && i[l] && _[l].key !== i[l]?.key && (v = !0, _[l] = i[l]) : (v = !0, _[l] = i[l]);
|
|
27
|
+
console.log("existingOptions-------", _), v && $(t, _);
|
|
28
28
|
}
|
|
29
|
-
function qt(t, { formElements: i, validation:
|
|
30
|
-
return { initialState: t, formElements: i, validation:
|
|
29
|
+
function qt(t, { formElements: i, validation: m }) {
|
|
30
|
+
return { initialState: t, formElements: i, validation: m };
|
|
31
31
|
}
|
|
32
32
|
const zt = (t, i) => {
|
|
33
|
-
let
|
|
34
|
-
const [
|
|
35
|
-
(Object.keys(
|
|
36
|
-
|
|
33
|
+
let m = t;
|
|
34
|
+
const [y, u] = $t(m);
|
|
35
|
+
(Object.keys(u).length > 0 || i && Object.keys(i).length > 0) && Object.keys(u).forEach((v) => {
|
|
36
|
+
u[v] = u[v] || {}, u[v].formElements = {
|
|
37
37
|
...i?.formElements,
|
|
38
38
|
// Global defaults first
|
|
39
39
|
...i?.validation,
|
|
40
|
-
...
|
|
40
|
+
...u[v].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
42
|
};
|
|
43
|
-
const l = q(
|
|
44
|
-
console.log("existingOptions", l,
|
|
45
|
-
}), r.getState().setInitialStates(
|
|
46
|
-
const $ = (
|
|
43
|
+
const l = q(v);
|
|
44
|
+
console.log("existingOptions", l, u[v]), l || r.getState().setInitialStateOptions(v, u[v]);
|
|
45
|
+
}), r.getState().setInitialStates(y);
|
|
46
|
+
const $ = (v, l) => {
|
|
47
47
|
const [f] = et(l?.componentId ?? rt());
|
|
48
48
|
ut({
|
|
49
|
-
stateKey:
|
|
49
|
+
stateKey: v,
|
|
50
50
|
options: l,
|
|
51
|
-
initialOptionsPart:
|
|
51
|
+
initialOptionsPart: u
|
|
52
52
|
});
|
|
53
|
-
const e = r.getState().cogsStateStore[
|
|
54
|
-
|
|
53
|
+
const e = r.getState().cogsStateStore[v] || y[v], S = l?.modifyState ? l.modifyState(e) : e, [k, A] = Tt(
|
|
54
|
+
S,
|
|
55
55
|
{
|
|
56
|
-
stateKey:
|
|
56
|
+
stateKey: v,
|
|
57
57
|
syncUpdate: l?.syncUpdate,
|
|
58
58
|
componentId: f,
|
|
59
59
|
localStorage: l?.localStorage,
|
|
@@ -67,8 +67,8 @@ const zt = (t, i) => {
|
|
|
67
67
|
);
|
|
68
68
|
return A;
|
|
69
69
|
};
|
|
70
|
-
function _(
|
|
71
|
-
ut({ stateKey:
|
|
70
|
+
function _(v, l) {
|
|
71
|
+
ut({ stateKey: v, options: l, initialOptionsPart: u });
|
|
72
72
|
}
|
|
73
73
|
return { useCogsState: $, setCogsOptions: _ };
|
|
74
74
|
}, {
|
|
@@ -76,12 +76,12 @@ const zt = (t, i) => {
|
|
|
76
76
|
setState: D,
|
|
77
77
|
getInitialOptions: q,
|
|
78
78
|
getKeyState: gt,
|
|
79
|
-
getValidationErrors:
|
|
80
|
-
setStateLog:
|
|
79
|
+
getValidationErrors: pt,
|
|
80
|
+
setStateLog: xt,
|
|
81
81
|
updateInitialStateGlobal: ot,
|
|
82
|
-
addValidationError:
|
|
82
|
+
addValidationError: ht,
|
|
83
83
|
removeValidationError: P,
|
|
84
|
-
setServerSyncActions:
|
|
84
|
+
setServerSyncActions: kt
|
|
85
85
|
} = r.getState(), ft = (t) => {
|
|
86
86
|
if (!t) return null;
|
|
87
87
|
try {
|
|
@@ -90,33 +90,33 @@ const zt = (t, i) => {
|
|
|
90
90
|
} catch (i) {
|
|
91
91
|
return console.error("Error loading from localStorage:", i), null;
|
|
92
92
|
}
|
|
93
|
-
},
|
|
94
|
-
|
|
93
|
+
}, Ct = (t, i, m, y) => {
|
|
94
|
+
m?.log && console.log(
|
|
95
95
|
"saving to localstorage",
|
|
96
96
|
i,
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
m.localStorage?.key,
|
|
98
|
+
y
|
|
99
99
|
);
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
100
|
+
const u = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
101
|
+
if (u && y) {
|
|
102
102
|
const $ = {
|
|
103
103
|
state: t,
|
|
104
104
|
lastUpdated: Date.now(),
|
|
105
105
|
lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
|
|
106
106
|
baseServerState: r.getState().serverState[i]
|
|
107
|
-
}, _ = `${
|
|
107
|
+
}, _ = `${y}-${i}-${u}`;
|
|
108
108
|
window.localStorage.setItem(_, JSON.stringify($));
|
|
109
109
|
}
|
|
110
|
-
},
|
|
110
|
+
}, Ot = (t, i, m, y, u, $) => {
|
|
111
111
|
const _ = {
|
|
112
112
|
initialState: i,
|
|
113
113
|
updaterState: X(
|
|
114
114
|
t,
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
y,
|
|
116
|
+
u,
|
|
117
117
|
$
|
|
118
118
|
),
|
|
119
|
-
state:
|
|
119
|
+
state: m
|
|
120
120
|
};
|
|
121
121
|
H(() => {
|
|
122
122
|
ot(t, _.initialState), Y(t, _.updaterState), D(t, _.state);
|
|
@@ -124,38 +124,38 @@ const zt = (t, i) => {
|
|
|
124
124
|
}, St = (t) => {
|
|
125
125
|
const i = r.getState().stateComponents.get(t);
|
|
126
126
|
if (!i) return;
|
|
127
|
-
const
|
|
128
|
-
i.components.forEach((
|
|
129
|
-
|
|
127
|
+
const m = /* @__PURE__ */ new Set();
|
|
128
|
+
i.components.forEach((y) => {
|
|
129
|
+
m.add(() => y.forceUpdate());
|
|
130
130
|
}), queueMicrotask(() => {
|
|
131
131
|
H(() => {
|
|
132
|
-
|
|
132
|
+
m.forEach((y) => y());
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
135
|
}, Bt = (t, i) => {
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
const
|
|
139
|
-
|
|
136
|
+
const m = r.getState().stateComponents.get(t);
|
|
137
|
+
if (m) {
|
|
138
|
+
const y = `${t}////${i}`, u = m.components.get(y);
|
|
139
|
+
u && u.forceUpdate();
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
function
|
|
142
|
+
function Tt(t, {
|
|
143
143
|
stateKey: i,
|
|
144
|
-
serverSync:
|
|
145
|
-
localStorage:
|
|
146
|
-
formElements:
|
|
144
|
+
serverSync: m,
|
|
145
|
+
localStorage: y,
|
|
146
|
+
formElements: u,
|
|
147
147
|
middleware: $,
|
|
148
148
|
reactiveDeps: _,
|
|
149
|
-
reactiveType:
|
|
149
|
+
reactiveType: v,
|
|
150
150
|
componentId: l,
|
|
151
151
|
initialState: f,
|
|
152
152
|
syncUpdate: e,
|
|
153
|
-
dependencies:
|
|
153
|
+
dependencies: S
|
|
154
154
|
} = {}) {
|
|
155
|
-
const [
|
|
155
|
+
const [k, A] = et({}), { sessionId: C } = At();
|
|
156
156
|
let R = !i;
|
|
157
|
-
const [g] = et(i ?? rt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(l ?? rt()),
|
|
158
|
-
|
|
157
|
+
const [g] = et(i ?? rt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(l ?? rt()), x = Z(null);
|
|
158
|
+
x.current = q(g), nt(() => {
|
|
159
159
|
if (e && e.stateKey === g && e.path?.[0]) {
|
|
160
160
|
D(g, (o) => ({
|
|
161
161
|
...o,
|
|
@@ -171,28 +171,27 @@ function Ot(t, {
|
|
|
171
171
|
dt(g, {
|
|
172
172
|
initialState: f
|
|
173
173
|
});
|
|
174
|
-
const c =
|
|
174
|
+
const c = x.current;
|
|
175
175
|
let o = null;
|
|
176
|
-
c?.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
T + "-" + g + "-" + u
|
|
176
|
+
const d = L(c?.localStorage?.key) ? c?.localStorage?.key(f) : c?.localStorage?.key;
|
|
177
|
+
c?.log && (console.log("newoptions", c), console.log("localkey", d), console.log("initialState", f)), d && C && (o = ft(
|
|
178
|
+
C + "-" + g + "-" + d
|
|
180
179
|
));
|
|
181
180
|
let E = null;
|
|
182
|
-
f && (E = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state),
|
|
181
|
+
f && (E = f, o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state), Ot(
|
|
183
182
|
g,
|
|
184
183
|
f,
|
|
185
184
|
E,
|
|
186
185
|
n,
|
|
187
186
|
b.current,
|
|
188
|
-
|
|
187
|
+
C
|
|
189
188
|
), St(g), A({}));
|
|
190
|
-
}, [f, ...
|
|
189
|
+
}, [f, ...S || []]), It(() => {
|
|
191
190
|
R && dt(g, {
|
|
192
|
-
serverSync:
|
|
193
|
-
formElements:
|
|
191
|
+
serverSync: m,
|
|
192
|
+
formElements: u,
|
|
194
193
|
initialState: f,
|
|
195
|
-
localStorage:
|
|
194
|
+
localStorage: y,
|
|
196
195
|
middleware: $
|
|
197
196
|
});
|
|
198
197
|
const c = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
|
|
@@ -203,24 +202,24 @@ function Ot(t, {
|
|
|
203
202
|
paths: /* @__PURE__ */ new Set(),
|
|
204
203
|
deps: [],
|
|
205
204
|
depsFunction: _ || void 0,
|
|
206
|
-
reactiveType:
|
|
205
|
+
reactiveType: v ?? ["component", "deps"]
|
|
207
206
|
}), r.getState().stateComponents.set(g, o), A({}), () => {
|
|
208
|
-
const
|
|
209
|
-
o && (o.components.delete(
|
|
207
|
+
const d = `${g}////${b.current}`;
|
|
208
|
+
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
|
|
210
209
|
};
|
|
211
210
|
}, []);
|
|
212
|
-
const n = (c, o,
|
|
211
|
+
const n = (c, o, d, E) => {
|
|
213
212
|
if (Array.isArray(o)) {
|
|
214
|
-
const
|
|
215
|
-
G.current.add(
|
|
213
|
+
const O = `${g}-${o.join(".")}`;
|
|
214
|
+
G.current.add(O);
|
|
216
215
|
}
|
|
217
|
-
D(g, (
|
|
218
|
-
const N = L(c) ? c(
|
|
216
|
+
D(g, (O) => {
|
|
217
|
+
const N = L(c) ? c(O) : c, j = `${g}-${o.join(".")}`;
|
|
219
218
|
if (j) {
|
|
220
219
|
let F = !1, I = r.getState().signalDomElements.get(j);
|
|
221
|
-
if ((!I || I.size === 0) && (
|
|
222
|
-
const V = o.slice(0, -1),
|
|
223
|
-
if (Array.isArray(
|
|
220
|
+
if ((!I || I.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
|
|
221
|
+
const V = o.slice(0, -1), p = U(N, V);
|
|
222
|
+
if (Array.isArray(p)) {
|
|
224
223
|
F = !0;
|
|
225
224
|
const w = `${g}-${V.join(".")}`;
|
|
226
225
|
I = r.getState().signalDomElements.get(w);
|
|
@@ -228,12 +227,12 @@ function Ot(t, {
|
|
|
228
227
|
}
|
|
229
228
|
if (I) {
|
|
230
229
|
const V = F ? U(N, o.slice(0, -1)) : U(N, o);
|
|
231
|
-
I.forEach(({ parentId:
|
|
232
|
-
const
|
|
233
|
-
`[data-parent-id="${
|
|
230
|
+
I.forEach(({ parentId: p, position: w, effect: W }) => {
|
|
231
|
+
const T = document.querySelector(
|
|
232
|
+
`[data-parent-id="${p}"]`
|
|
234
233
|
);
|
|
235
|
-
if (
|
|
236
|
-
const st = Array.from(
|
|
234
|
+
if (T) {
|
|
235
|
+
const st = Array.from(T.childNodes);
|
|
237
236
|
if (st[w]) {
|
|
238
237
|
const vt = W ? new Function("state", `return (${W})(state)`)(V) : V;
|
|
239
238
|
st[w].textContent = String(vt);
|
|
@@ -242,32 +241,32 @@ function Ot(t, {
|
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
}
|
|
245
|
-
|
|
246
|
-
(E ||
|
|
244
|
+
d.updateType === "update" && (E || x.current?.validationKey) && o && P(
|
|
245
|
+
(E || x.current?.validationKey) + "." + o.join(".")
|
|
247
246
|
);
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
),
|
|
252
|
-
|
|
247
|
+
const h = o.slice(0, o.length - 1);
|
|
248
|
+
d.updateType === "cut" && x.current?.validationKey && P(
|
|
249
|
+
x.current?.validationKey + "." + h.join(".")
|
|
250
|
+
), d.updateType === "insert" && x.current?.validationKey && pt(
|
|
251
|
+
x.current?.validationKey + "." + h.join(".")
|
|
253
252
|
).filter(([I, V]) => {
|
|
254
|
-
let
|
|
255
|
-
if (I ==
|
|
256
|
-
let w = I + "." +
|
|
257
|
-
P(I),
|
|
253
|
+
let p = I?.split(".").length;
|
|
254
|
+
if (I == h.join(".") && p == h.length - 1) {
|
|
255
|
+
let w = I + "." + h;
|
|
256
|
+
P(I), ht(w, V);
|
|
258
257
|
}
|
|
259
258
|
});
|
|
260
|
-
const z = U(
|
|
259
|
+
const z = U(O, o), mt = U(N, o), yt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), at = r.getState().stateComponents.get(g);
|
|
261
260
|
if (at)
|
|
262
261
|
for (const [F, I] of at.components.entries()) {
|
|
263
262
|
let V = !1;
|
|
264
|
-
const
|
|
265
|
-
if (!
|
|
266
|
-
if (
|
|
263
|
+
const p = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
|
|
264
|
+
if (!p.includes("none")) {
|
|
265
|
+
if (p.includes("all")) {
|
|
267
266
|
I.forceUpdate();
|
|
268
267
|
continue;
|
|
269
268
|
}
|
|
270
|
-
if (
|
|
269
|
+
if (p.includes("component") && I.paths && (I.paths.has(yt) || I.paths.has("")) && (V = !0), !V && p.includes("deps") && I.depsFunction) {
|
|
271
270
|
const w = I.depsFunction(N);
|
|
272
271
|
typeof w == "boolean" ? w && (V = !0) : M(I.deps, w) || (I.deps = w, V = !0);
|
|
273
272
|
}
|
|
@@ -278,28 +277,28 @@ function Ot(t, {
|
|
|
278
277
|
timeStamp: Date.now(),
|
|
279
278
|
stateKey: g,
|
|
280
279
|
path: o,
|
|
281
|
-
updateType:
|
|
280
|
+
updateType: d.updateType,
|
|
282
281
|
status: "new",
|
|
283
282
|
oldValue: z,
|
|
284
283
|
newValue: mt
|
|
285
284
|
};
|
|
286
|
-
if (
|
|
287
|
-
const V = [...F ?? [], it].reduce((
|
|
288
|
-
const W = `${w.stateKey}:${JSON.stringify(w.path)}`,
|
|
289
|
-
return
|
|
285
|
+
if (xt(g, (F) => {
|
|
286
|
+
const V = [...F ?? [], it].reduce((p, w) => {
|
|
287
|
+
const W = `${w.stateKey}:${JSON.stringify(w.path)}`, T = p.get(W);
|
|
288
|
+
return T ? (T.timeStamp = Math.max(T.timeStamp, w.timeStamp), T.newValue = w.newValue, T.oldValue = T.oldValue ?? w.oldValue, T.updateType = w.updateType) : p.set(W, { ...w }), p;
|
|
290
289
|
}, /* @__PURE__ */ new Map());
|
|
291
290
|
return Array.from(V.values());
|
|
292
|
-
}),
|
|
291
|
+
}), Ct(
|
|
293
292
|
N,
|
|
294
293
|
g,
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
x.current,
|
|
295
|
+
C
|
|
297
296
|
), $ && $({
|
|
298
297
|
updateLog: s,
|
|
299
298
|
update: it
|
|
300
|
-
}),
|
|
301
|
-
const F = r.getState().serverState[g], I =
|
|
302
|
-
|
|
299
|
+
}), x.current?.serverSync) {
|
|
300
|
+
const F = r.getState().serverState[g], I = x.current?.serverSync;
|
|
301
|
+
kt(g, {
|
|
303
302
|
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: N }),
|
|
304
303
|
rollBackState: F,
|
|
305
304
|
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
@@ -315,59 +314,59 @@ function Ot(t, {
|
|
|
315
314
|
g,
|
|
316
315
|
n,
|
|
317
316
|
b.current,
|
|
318
|
-
|
|
317
|
+
C
|
|
319
318
|
)
|
|
320
319
|
), r.getState().cogsStateStore[g] || D(g, t), r.getState().initialStateGlobal[g] || ot(g, t));
|
|
321
320
|
const a = _t(() => X(
|
|
322
321
|
g,
|
|
323
322
|
n,
|
|
324
323
|
b.current,
|
|
325
|
-
|
|
324
|
+
C
|
|
326
325
|
), [g]);
|
|
327
326
|
return [gt(g), a];
|
|
328
327
|
}
|
|
329
|
-
function X(t, i,
|
|
330
|
-
const
|
|
328
|
+
function X(t, i, m, y) {
|
|
329
|
+
const u = /* @__PURE__ */ new Map();
|
|
331
330
|
let $ = 0;
|
|
332
331
|
const _ = (f) => {
|
|
333
332
|
const e = f.join(".");
|
|
334
|
-
for (const [
|
|
335
|
-
(
|
|
333
|
+
for (const [S] of u)
|
|
334
|
+
(S === e || S.startsWith(e + ".")) && u.delete(S);
|
|
336
335
|
$++;
|
|
337
|
-
},
|
|
336
|
+
}, v = {
|
|
338
337
|
removeValidation: (f) => {
|
|
339
338
|
f?.validationKey && P(f.validationKey);
|
|
340
339
|
},
|
|
341
340
|
revertToInitialState: (f) => {
|
|
342
341
|
const e = r.getState().getInitialOptions(t)?.validation;
|
|
343
342
|
e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
const
|
|
343
|
+
const S = r.getState().initialStateGlobal[t];
|
|
344
|
+
u.clear(), $++;
|
|
345
|
+
const k = l(S, []), A = q(t), C = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${C}`;
|
|
347
346
|
return R && localStorage.removeItem(R), H(() => {
|
|
348
|
-
Y(t,
|
|
347
|
+
Y(t, k), D(t, S);
|
|
349
348
|
const g = r.getState().stateComponents.get(t);
|
|
350
349
|
g && g.components.forEach((s) => {
|
|
351
350
|
s.forceUpdate();
|
|
352
351
|
});
|
|
353
|
-
}),
|
|
352
|
+
}), S;
|
|
354
353
|
},
|
|
355
354
|
updateInitialState: (f) => {
|
|
356
|
-
|
|
355
|
+
u.clear(), $++;
|
|
357
356
|
const e = X(
|
|
358
357
|
t,
|
|
359
358
|
i,
|
|
360
|
-
|
|
361
|
-
|
|
359
|
+
m,
|
|
360
|
+
y
|
|
362
361
|
);
|
|
363
362
|
return H(() => {
|
|
364
363
|
ot(t, f), Y(t, e), D(t, f);
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
364
|
+
const S = r.getState().stateComponents.get(t);
|
|
365
|
+
S && S.components.forEach((k) => {
|
|
366
|
+
k.forceUpdate();
|
|
368
367
|
});
|
|
369
368
|
}), {
|
|
370
|
-
fetchId: (
|
|
369
|
+
fetchId: (S) => e.get()[S]
|
|
371
370
|
};
|
|
372
371
|
},
|
|
373
372
|
_initialState: r.getState().initialStateGlobal[t],
|
|
@@ -378,16 +377,16 @@ function X(t, i, S, v) {
|
|
|
378
377
|
return !!(f && M(f, gt(t)));
|
|
379
378
|
}
|
|
380
379
|
};
|
|
381
|
-
function l(f, e = [],
|
|
382
|
-
const
|
|
383
|
-
|
|
380
|
+
function l(f, e = [], S) {
|
|
381
|
+
const k = e.map(String).join(".");
|
|
382
|
+
u.get(k);
|
|
384
383
|
const A = function() {
|
|
385
384
|
return r().getNestedState(t, e);
|
|
386
385
|
};
|
|
387
|
-
Object.keys(
|
|
388
|
-
A[g] =
|
|
386
|
+
Object.keys(v).forEach((g) => {
|
|
387
|
+
A[g] = v[g];
|
|
389
388
|
});
|
|
390
|
-
const
|
|
389
|
+
const C = {
|
|
391
390
|
apply(g, s, G) {
|
|
392
391
|
return console.log(
|
|
393
392
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
|
|
@@ -395,7 +394,7 @@ function X(t, i, S, v) {
|
|
|
395
394
|
},
|
|
396
395
|
get(g, s) {
|
|
397
396
|
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
398
|
-
const n = e.join("."), a = `${t}////${
|
|
397
|
+
const n = e.join("."), a = `${t}////${m}`, c = r.getState().stateComponents.get(t);
|
|
399
398
|
if (c) {
|
|
400
399
|
const o = c.components.get(a);
|
|
401
400
|
o && (e.length > 0 || s === "get") && o.paths.add(n);
|
|
@@ -415,7 +414,7 @@ function X(t, i, S, v) {
|
|
|
415
414
|
};
|
|
416
415
|
if (s === "removeStorage")
|
|
417
416
|
return () => {
|
|
418
|
-
const n = r.getState().initialStateGlobal[t], a = q(t), c = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${
|
|
417
|
+
const n = r.getState().initialStateGlobal[t], a = q(t), c = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${y}-${t}-${c}`;
|
|
419
418
|
console.log("removing storage", o), o && localStorage.removeItem(o);
|
|
420
419
|
};
|
|
421
420
|
if (s === "showValidationErrors")
|
|
@@ -433,41 +432,41 @@ function X(t, i, S, v) {
|
|
|
433
432
|
return l(
|
|
434
433
|
f[n],
|
|
435
434
|
[...e, n.toString()],
|
|
436
|
-
|
|
435
|
+
S
|
|
437
436
|
);
|
|
438
437
|
};
|
|
439
438
|
if (s === "getSelectedIndex")
|
|
440
439
|
return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
|
|
441
440
|
if (s === "stateSort")
|
|
442
441
|
return (n) => {
|
|
443
|
-
const o = [...r.getState().getNestedState(t, e).map((
|
|
444
|
-
...
|
|
442
|
+
const o = [...r.getState().getNestedState(t, e).map((d, E) => ({
|
|
443
|
+
...d,
|
|
445
444
|
__origIndex: E.toString()
|
|
446
445
|
}))].sort(n);
|
|
447
|
-
return
|
|
448
|
-
filtered: [...
|
|
446
|
+
return u.clear(), $++, l(o, e, {
|
|
447
|
+
filtered: [...S?.filtered || [], e],
|
|
449
448
|
validIndices: o.map(
|
|
450
|
-
(
|
|
449
|
+
(d) => parseInt(d.__origIndex)
|
|
451
450
|
)
|
|
452
451
|
});
|
|
453
452
|
};
|
|
454
453
|
if (s === "stateMap" || s === "stateMapNoRender")
|
|
455
454
|
return (n) => {
|
|
456
|
-
const a =
|
|
455
|
+
const a = S?.filtered?.some(
|
|
457
456
|
(o) => o.join(".") === e.join(".")
|
|
458
457
|
), c = a ? f : r.getState().getNestedState(t, e);
|
|
459
|
-
return s !== "stateMapNoRender" && (
|
|
460
|
-
const E = a && o.__origIndex ? o.__origIndex :
|
|
458
|
+
return s !== "stateMapNoRender" && (u.clear(), $++), c.map((o, d) => {
|
|
459
|
+
const E = a && o.__origIndex ? o.__origIndex : d, O = l(
|
|
461
460
|
o,
|
|
462
461
|
[...e, E.toString()],
|
|
463
|
-
|
|
462
|
+
S
|
|
464
463
|
);
|
|
465
464
|
return n(
|
|
466
465
|
o,
|
|
467
|
-
|
|
468
|
-
|
|
466
|
+
O,
|
|
467
|
+
d,
|
|
469
468
|
f,
|
|
470
|
-
l(f, e,
|
|
469
|
+
l(f, e, S)
|
|
471
470
|
);
|
|
472
471
|
});
|
|
473
472
|
};
|
|
@@ -483,17 +482,17 @@ function X(t, i, S, v) {
|
|
|
483
482
|
});
|
|
484
483
|
if (s === "stateFlattenOn")
|
|
485
484
|
return (n) => {
|
|
486
|
-
const c =
|
|
487
|
-
(
|
|
485
|
+
const c = S?.filtered?.some(
|
|
486
|
+
(d) => d.join(".") === e.join(".")
|
|
488
487
|
) ? f : r.getState().getNestedState(t, e);
|
|
489
|
-
|
|
488
|
+
u.clear(), $++;
|
|
490
489
|
const o = c.flatMap(
|
|
491
|
-
(
|
|
490
|
+
(d, E) => d[n] ?? []
|
|
492
491
|
);
|
|
493
492
|
return l(
|
|
494
493
|
o,
|
|
495
494
|
[...e, "[*]", n],
|
|
496
|
-
|
|
495
|
+
S
|
|
497
496
|
);
|
|
498
497
|
};
|
|
499
498
|
if (s === "findWith")
|
|
@@ -502,8 +501,8 @@ function X(t, i, S, v) {
|
|
|
502
501
|
(E) => E[n] === a
|
|
503
502
|
);
|
|
504
503
|
if (c === -1) return;
|
|
505
|
-
const o = f[c],
|
|
506
|
-
return
|
|
504
|
+
const o = f[c], d = [...e, c.toString()];
|
|
505
|
+
return u.clear(), $++, u.clear(), $++, l(o, d);
|
|
507
506
|
};
|
|
508
507
|
if (s === "index")
|
|
509
508
|
return (n) => {
|
|
@@ -517,22 +516,22 @@ function X(t, i, S, v) {
|
|
|
517
516
|
));
|
|
518
517
|
if (s === "uniqueInsert")
|
|
519
518
|
return (n, a, c) => {
|
|
520
|
-
const o = r.getState().getNestedState(t, e),
|
|
519
|
+
const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
|
|
521
520
|
let E = null;
|
|
522
521
|
if (!o.some((N) => {
|
|
523
522
|
if (a) {
|
|
524
|
-
const
|
|
525
|
-
(z) => M(N[z],
|
|
523
|
+
const h = a.every(
|
|
524
|
+
(z) => M(N[z], d[z])
|
|
526
525
|
);
|
|
527
|
-
return
|
|
526
|
+
return h && (E = N), h;
|
|
528
527
|
}
|
|
529
|
-
const j = M(N,
|
|
528
|
+
const j = M(N, d);
|
|
530
529
|
return j && (E = N), j;
|
|
531
530
|
}))
|
|
532
|
-
_(e), K(i,
|
|
531
|
+
_(e), K(i, d, e, t);
|
|
533
532
|
else if (c && E) {
|
|
534
533
|
const N = c(E), j = o.map(
|
|
535
|
-
(
|
|
534
|
+
(h) => M(h, E) ? N : h
|
|
536
535
|
);
|
|
537
536
|
_(e), B(i, j, e);
|
|
538
537
|
}
|
|
@@ -553,14 +552,14 @@ function X(t, i, S, v) {
|
|
|
553
552
|
};
|
|
554
553
|
if (s === "stateFilter")
|
|
555
554
|
return (n) => {
|
|
556
|
-
const a = f.map((
|
|
557
|
-
...
|
|
555
|
+
const a = f.map((d, E) => ({
|
|
556
|
+
...d,
|
|
558
557
|
__origIndex: E.toString()
|
|
559
558
|
})), c = [], o = [];
|
|
560
|
-
for (let
|
|
561
|
-
n(a[
|
|
562
|
-
return
|
|
563
|
-
filtered: [...
|
|
559
|
+
for (let d = 0; d < a.length; d++)
|
|
560
|
+
n(a[d], d) && (c.push(d), o.push(a[d]));
|
|
561
|
+
return u.clear(), $++, l(o, e, {
|
|
562
|
+
filtered: [...S?.filtered || [], e],
|
|
564
563
|
validIndices: c
|
|
565
564
|
// Always pass validIndices, even if empty
|
|
566
565
|
});
|
|
@@ -601,7 +600,7 @@ function X(t, i, S, v) {
|
|
|
601
600
|
return r.getState().getSyncInfo(n);
|
|
602
601
|
}
|
|
603
602
|
if (s == "getLocalStorage")
|
|
604
|
-
return (n) => ft(
|
|
603
|
+
return (n) => ft(y + "-" + t + "-" + n);
|
|
605
604
|
if (s === "_selected") {
|
|
606
605
|
const n = e.slice(0, -1), a = n.join("."), c = r.getState().getNestedState(t, n);
|
|
607
606
|
return Array.isArray(c) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
|
|
@@ -610,8 +609,8 @@ function X(t, i, S, v) {
|
|
|
610
609
|
return (n) => {
|
|
611
610
|
const a = e.slice(0, -1), c = Number(e[e.length - 1]), o = a.join(".");
|
|
612
611
|
n ? r.getState().setSelectedIndex(t, o, c) : r.getState().setSelectedIndex(t, o, void 0);
|
|
613
|
-
const
|
|
614
|
-
B(i,
|
|
612
|
+
const d = r.getState().getNestedState(t, [...a]);
|
|
613
|
+
B(i, d, a), _(a);
|
|
615
614
|
};
|
|
616
615
|
if (e.length == 0) {
|
|
617
616
|
if (s === "validateZodSchema")
|
|
@@ -628,16 +627,16 @@ function X(t, i, S, v) {
|
|
|
628
627
|
o && o.length > 0 && o.forEach(([E]) => {
|
|
629
628
|
E && E.startsWith(n.key) && P(E);
|
|
630
629
|
});
|
|
631
|
-
const
|
|
632
|
-
return
|
|
633
|
-
const N =
|
|
634
|
-
a(
|
|
630
|
+
const d = n.zodSchema.safeParse(c);
|
|
631
|
+
return d.success ? !0 : (d.error.errors.forEach((O) => {
|
|
632
|
+
const N = O.path, j = O.message, h = [n.key, ...N].join(".");
|
|
633
|
+
a(h, j);
|
|
635
634
|
}), St(t), !1);
|
|
636
635
|
} catch (o) {
|
|
637
636
|
return console.error("Zod schema validation failed", o), !1;
|
|
638
637
|
}
|
|
639
638
|
};
|
|
640
|
-
if (s === "_componentId") return
|
|
639
|
+
if (s === "_componentId") return m;
|
|
641
640
|
if (s === "getComponents")
|
|
642
641
|
return () => r().stateComponents.get(t);
|
|
643
642
|
if (s === "getAllFormRefs")
|
|
@@ -649,9 +648,9 @@ function X(t, i, S, v) {
|
|
|
649
648
|
if (s === "_isLoading")
|
|
650
649
|
return r.getState().isLoadingGlobal[t];
|
|
651
650
|
if (s === "revertToInitialState")
|
|
652
|
-
return
|
|
653
|
-
if (s === "updateInitialState") return
|
|
654
|
-
if (s === "removeValidation") return
|
|
651
|
+
return v.revertToInitialState;
|
|
652
|
+
if (s === "updateInitialState") return v.updateInitialState;
|
|
653
|
+
if (s === "removeValidation") return v.removeValidation;
|
|
655
654
|
}
|
|
656
655
|
if (s === "getFormRef")
|
|
657
656
|
return () => lt.getState().getFormRef(t + "." + e.join("."));
|
|
@@ -666,13 +665,13 @@ function X(t, i, S, v) {
|
|
|
666
665
|
path: e,
|
|
667
666
|
validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
|
|
668
667
|
stateKey: t,
|
|
669
|
-
validIndices:
|
|
668
|
+
validIndices: S?.validIndices,
|
|
670
669
|
children: n
|
|
671
670
|
}
|
|
672
671
|
);
|
|
673
672
|
if (s === "_stateKey") return t;
|
|
674
673
|
if (s === "_path") return e;
|
|
675
|
-
if (s === "_isServerSynced") return
|
|
674
|
+
if (s === "_isServerSynced") return v._isServerSynced;
|
|
676
675
|
if (s === "update")
|
|
677
676
|
return (n, a) => {
|
|
678
677
|
if (a?.debounce)
|
|
@@ -699,11 +698,11 @@ function X(t, i, S, v) {
|
|
|
699
698
|
formOpts: a
|
|
700
699
|
}
|
|
701
700
|
);
|
|
702
|
-
const b = [...e, s],
|
|
703
|
-
return l(
|
|
701
|
+
const b = [...e, s], x = r.getState().getNestedState(t, b);
|
|
702
|
+
return l(x, b, S);
|
|
704
703
|
}
|
|
705
|
-
}, R = new Proxy(A,
|
|
706
|
-
return
|
|
704
|
+
}, R = new Proxy(A, C);
|
|
705
|
+
return u.set(k, {
|
|
707
706
|
proxy: R,
|
|
708
707
|
stateVersion: $
|
|
709
708
|
}), R;
|
|
@@ -719,63 +718,63 @@ function jt({
|
|
|
719
718
|
proxy: t,
|
|
720
719
|
rebuildStateShape: i
|
|
721
720
|
}) {
|
|
722
|
-
const
|
|
723
|
-
return Array.isArray(
|
|
724
|
-
|
|
721
|
+
const m = r().getNestedState(t._stateKey, t._path);
|
|
722
|
+
return Array.isArray(m) ? i(
|
|
723
|
+
m,
|
|
725
724
|
t._path
|
|
726
725
|
).stateMapNoRender(
|
|
727
|
-
(
|
|
726
|
+
(u, $, _, v, l) => t._mapFn(u, $, _, v, l)
|
|
728
727
|
) : null;
|
|
729
728
|
}
|
|
730
729
|
function bt({
|
|
731
730
|
proxy: t
|
|
732
731
|
}) {
|
|
733
|
-
const i = Z(null),
|
|
732
|
+
const i = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
734
733
|
return nt(() => {
|
|
735
|
-
const
|
|
736
|
-
if (!
|
|
737
|
-
const
|
|
738
|
-
let
|
|
739
|
-
|
|
734
|
+
const y = i.current;
|
|
735
|
+
if (!y || !y.parentElement) return;
|
|
736
|
+
const u = y.parentElement, _ = Array.from(u.childNodes).indexOf(y);
|
|
737
|
+
let v = u.getAttribute("data-parent-id");
|
|
738
|
+
v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
|
|
740
739
|
const f = {
|
|
741
740
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
742
|
-
parentId:
|
|
741
|
+
parentId: v,
|
|
743
742
|
position: _,
|
|
744
743
|
effect: t._effect
|
|
745
744
|
};
|
|
746
|
-
r.getState().addSignalElement(
|
|
745
|
+
r.getState().addSignalElement(m, f);
|
|
747
746
|
const e = r.getState().getNestedState(t._stateKey, t._path);
|
|
748
|
-
let
|
|
747
|
+
let S;
|
|
749
748
|
if (t._effect)
|
|
750
749
|
try {
|
|
751
|
-
|
|
750
|
+
S = new Function(
|
|
752
751
|
"state",
|
|
753
752
|
`return (${t._effect})(state)`
|
|
754
753
|
)(e);
|
|
755
754
|
} catch (A) {
|
|
756
|
-
console.error("Error evaluating effect function during mount:", A),
|
|
755
|
+
console.error("Error evaluating effect function during mount:", A), S = e;
|
|
757
756
|
}
|
|
758
757
|
else
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
|
|
758
|
+
S = e;
|
|
759
|
+
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
760
|
+
const k = document.createTextNode(String(S));
|
|
761
|
+
y.replaceWith(k);
|
|
763
762
|
}, [t._stateKey, t._path.join("."), t._effect]), Q("span", {
|
|
764
763
|
ref: i,
|
|
765
764
|
style: { display: "none" },
|
|
766
|
-
"data-signal-id":
|
|
765
|
+
"data-signal-id": m
|
|
767
766
|
});
|
|
768
767
|
}
|
|
769
768
|
function Jt(t) {
|
|
770
769
|
const i = Et(
|
|
771
|
-
(
|
|
772
|
-
const
|
|
770
|
+
(m) => {
|
|
771
|
+
const y = r.getState().stateComponents.get(t._stateKey) || {
|
|
773
772
|
components: /* @__PURE__ */ new Map()
|
|
774
773
|
};
|
|
775
|
-
return
|
|
776
|
-
forceUpdate:
|
|
774
|
+
return y.components.set(t._stateKey, {
|
|
775
|
+
forceUpdate: m,
|
|
777
776
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
778
|
-
}), () =>
|
|
777
|
+
}), () => y.components.delete(t._stateKey);
|
|
779
778
|
},
|
|
780
779
|
() => r.getState().getNestedState(t._stateKey, t._path)
|
|
781
780
|
);
|
|
@@ -787,6 +786,6 @@ export {
|
|
|
787
786
|
qt as addStateOptions,
|
|
788
787
|
zt as createCogsState,
|
|
789
788
|
Bt as notifyComponent,
|
|
790
|
-
|
|
789
|
+
Tt as useCogsStateFn
|
|
791
790
|
};
|
|
792
791
|
//# sourceMappingURL=CogsState.jsx.map
|