cogsbox-state 0.5.273 → 0.5.274
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 +393 -393
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +30 -33
package/dist/CogsState.jsx
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as et, useRef as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as dt, updateFn as tt, cutFunc as rt, ValidationWrapper as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as vt } from "react/jsx-runtime";
|
|
3
|
+
import { useState as et, useRef as H, useEffect as ut, useLayoutEffect as ft, useMemo as At, createElement as st, useSyncExternalStore as Nt, startTransition as Vt, useCallback as ht } from "react";
|
|
4
|
+
import { transformStateFunc as bt, isDeepEqual as L, isFunction as J, getNestedValue as B, getDifferences as gt, debounce as Ct } from "./utility.js";
|
|
5
|
+
import { pushFunc as dt, updateFn as tt, cutFunc as rt, ValidationWrapper as Pt, FormControlComponent as _t } from "./Functions.jsx";
|
|
6
|
+
import Mt from "superjson";
|
|
7
7
|
import { v4 as St } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as r, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
function
|
|
9
|
+
import { getGlobalStore as r, formRefStore as It } from "./store.js";
|
|
10
|
+
import { useCogsConfig as $t } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Ot } from "fast-json-patch";
|
|
12
|
+
function pt(t, i) {
|
|
13
13
|
const h = r.getState().getInitialOptions, f = r.getState().setInitialStateOptions, y = h(t) || {};
|
|
14
14
|
f(t, {
|
|
15
15
|
...y,
|
|
16
16
|
...i
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function wt({
|
|
20
20
|
stateKey: t,
|
|
21
21
|
options: i,
|
|
22
22
|
initialOptionsPart: h
|
|
23
23
|
}) {
|
|
24
|
-
const f =
|
|
24
|
+
const f = Z(t) || {}, y = h[t] || {}, $ = r.getState().setInitialStateOptions, E = { ...y, ...f };
|
|
25
25
|
let I = !1;
|
|
26
26
|
if (i)
|
|
27
27
|
for (const s in i)
|
|
28
|
-
|
|
29
|
-
!L(
|
|
30
|
-
I &&
|
|
28
|
+
E.hasOwnProperty(s) ? (s == "localStorage" && i[s] && E[s].key !== i[s]?.key && (I = !0, E[s] = i[s]), s == "initialState" && i[s] && E[s] !== i[s] && // Different references
|
|
29
|
+
!L(E[s], i[s]) && (I = !0, E[s] = i[s])) : (I = !0, E[s] = i[s]);
|
|
30
|
+
I && $(t, E);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function ee(t, { formElements: i, validation: h }) {
|
|
33
33
|
return { initialState: t, formElements: i, validation: h };
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const ne = (t, i) => {
|
|
36
36
|
let h = t;
|
|
37
|
-
const [f, y] =
|
|
37
|
+
const [f, y] = bt(h);
|
|
38
38
|
(Object.keys(y).length > 0 || i && Object.keys(i).length > 0) && Object.keys(y).forEach((I) => {
|
|
39
39
|
y[I] = y[I] || {}, y[I].formElements = {
|
|
40
40
|
...i?.formElements,
|
|
@@ -42,16 +42,16 @@ const ee = (t, i) => {
|
|
|
42
42
|
...i?.validation,
|
|
43
43
|
...y[I].formElements || {}
|
|
44
44
|
// State-specific overrides
|
|
45
|
-
},
|
|
45
|
+
}, Z(I) || r.getState().setInitialStateOptions(I, y[I]);
|
|
46
46
|
}), r.getState().setInitialStates(f), r.getState().setCreatedState(f);
|
|
47
|
-
const
|
|
47
|
+
const $ = (I, s) => {
|
|
48
48
|
const [v] = et(s?.componentId ?? St());
|
|
49
|
-
|
|
49
|
+
wt({
|
|
50
50
|
stateKey: I,
|
|
51
51
|
options: s,
|
|
52
52
|
initialOptionsPart: y
|
|
53
53
|
});
|
|
54
|
-
const
|
|
54
|
+
const o = r.getState().cogsStateStore[I] || f[I], g = s?.modifyState ? s.modifyState(o) : o, [G, j] = Wt(
|
|
55
55
|
g,
|
|
56
56
|
{
|
|
57
57
|
stateKey: I,
|
|
@@ -69,43 +69,43 @@ const ee = (t, i) => {
|
|
|
69
69
|
);
|
|
70
70
|
return j;
|
|
71
71
|
};
|
|
72
|
-
function
|
|
73
|
-
|
|
72
|
+
function E(I, s) {
|
|
73
|
+
wt({ stateKey: I, options: s, initialOptionsPart: y }), s.localStorage && Dt(I, s), ct(I);
|
|
74
74
|
}
|
|
75
|
-
return { useCogsState:
|
|
75
|
+
return { useCogsState: $, setCogsOptions: E };
|
|
76
76
|
}, {
|
|
77
|
-
setUpdaterState:
|
|
77
|
+
setUpdaterState: ot,
|
|
78
78
|
setState: Y,
|
|
79
|
-
getInitialOptions:
|
|
80
|
-
getKeyState:
|
|
81
|
-
getValidationErrors:
|
|
79
|
+
getInitialOptions: Z,
|
|
80
|
+
getKeyState: kt,
|
|
81
|
+
getValidationErrors: Rt,
|
|
82
82
|
setStateLog: jt,
|
|
83
83
|
updateInitialStateGlobal: mt,
|
|
84
84
|
addValidationError: Ft,
|
|
85
85
|
removeValidationError: z,
|
|
86
|
-
setServerSyncActions:
|
|
87
|
-
} = r.getState(),
|
|
86
|
+
setServerSyncActions: Ut
|
|
87
|
+
} = r.getState(), Et = (t, i, h, f, y) => {
|
|
88
88
|
h?.log && console.log(
|
|
89
89
|
"saving to localstorage",
|
|
90
90
|
i,
|
|
91
91
|
h.localStorage?.key,
|
|
92
92
|
f
|
|
93
93
|
);
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
94
|
+
const $ = J(h?.localStorage?.key) ? h.localStorage?.key(t) : h?.localStorage?.key;
|
|
95
|
+
if ($ && f) {
|
|
96
|
+
const E = `${f}-${i}-${$}`;
|
|
97
97
|
let I;
|
|
98
98
|
try {
|
|
99
|
-
I = it(
|
|
99
|
+
I = it(E)?.lastSyncedWithServer;
|
|
100
100
|
} catch {
|
|
101
101
|
}
|
|
102
102
|
const s = {
|
|
103
103
|
state: t,
|
|
104
104
|
lastUpdated: Date.now(),
|
|
105
105
|
lastSyncedWithServer: y ?? I
|
|
106
|
-
}, v =
|
|
106
|
+
}, v = Mt.serialize(s);
|
|
107
107
|
window.localStorage.setItem(
|
|
108
|
-
|
|
108
|
+
E,
|
|
109
109
|
JSON.stringify(v.json)
|
|
110
110
|
);
|
|
111
111
|
}
|
|
@@ -117,28 +117,28 @@ const ee = (t, i) => {
|
|
|
117
117
|
} catch (i) {
|
|
118
118
|
return console.error("Error loading from localStorage:", i), null;
|
|
119
119
|
}
|
|
120
|
-
},
|
|
121
|
-
const h = r.getState().cogsStateStore[t], { sessionId: f } =
|
|
120
|
+
}, Dt = (t, i) => {
|
|
121
|
+
const h = r.getState().cogsStateStore[t], { sessionId: f } = $t(), y = J(i?.localStorage?.key) ? i.localStorage.key(h) : i?.localStorage?.key;
|
|
122
122
|
if (y && f) {
|
|
123
|
-
const
|
|
123
|
+
const $ = it(
|
|
124
124
|
`${f}-${t}-${y}`
|
|
125
125
|
);
|
|
126
|
-
if (
|
|
127
|
-
return Y(t,
|
|
126
|
+
if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
|
|
127
|
+
return Y(t, $.state), ct(t), !0;
|
|
128
128
|
}
|
|
129
129
|
return !1;
|
|
130
|
-
},
|
|
131
|
-
const
|
|
130
|
+
}, xt = (t, i, h, f, y, $) => {
|
|
131
|
+
const E = {
|
|
132
132
|
initialState: i,
|
|
133
|
-
updaterState:
|
|
133
|
+
updaterState: at(
|
|
134
134
|
t,
|
|
135
135
|
f,
|
|
136
136
|
y,
|
|
137
|
-
|
|
137
|
+
$
|
|
138
138
|
),
|
|
139
139
|
state: h
|
|
140
140
|
};
|
|
141
|
-
mt(t,
|
|
141
|
+
mt(t, E.initialState), ot(t, E.updaterState), Y(t, E.state);
|
|
142
142
|
}, ct = (t) => {
|
|
143
143
|
const i = r.getState().stateComponents.get(t);
|
|
144
144
|
if (!i) return;
|
|
@@ -148,7 +148,7 @@ const ee = (t, i) => {
|
|
|
148
148
|
}), queueMicrotask(() => {
|
|
149
149
|
h.forEach((f) => f());
|
|
150
150
|
});
|
|
151
|
-
},
|
|
151
|
+
}, re = (t, i) => {
|
|
152
152
|
const h = r.getState().stateComponents.get(t);
|
|
153
153
|
if (h) {
|
|
154
154
|
const f = `${t}////${i}`, y = h.components.get(f);
|
|
@@ -156,7 +156,7 @@ const ee = (t, i) => {
|
|
|
156
156
|
return;
|
|
157
157
|
y && y.forceUpdate();
|
|
158
158
|
}
|
|
159
|
-
},
|
|
159
|
+
}, Gt = (t, i, h, f) => {
|
|
160
160
|
switch (t) {
|
|
161
161
|
case "update":
|
|
162
162
|
return {
|
|
@@ -179,25 +179,25 @@ const ee = (t, i) => {
|
|
|
179
179
|
return { oldValue: null, newValue: null };
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
function
|
|
182
|
+
function Wt(t, {
|
|
183
183
|
stateKey: i,
|
|
184
184
|
serverSync: h,
|
|
185
185
|
localStorage: f,
|
|
186
186
|
formElements: y,
|
|
187
|
-
reactiveDeps:
|
|
188
|
-
reactiveType:
|
|
187
|
+
reactiveDeps: $,
|
|
188
|
+
reactiveType: E,
|
|
189
189
|
componentId: I,
|
|
190
190
|
initialState: s,
|
|
191
191
|
syncUpdate: v,
|
|
192
|
-
dependencies:
|
|
192
|
+
dependencies: o,
|
|
193
193
|
serverState: g
|
|
194
194
|
} = {}) {
|
|
195
|
-
const [G, j] = et({}), { sessionId: F } =
|
|
195
|
+
const [G, j] = et({}), { sessionId: F } = $t();
|
|
196
196
|
let W = !i;
|
|
197
|
-
const [m] = et(i ?? St()), l = r.getState().stateLog[m], nt =
|
|
197
|
+
const [m] = et(i ?? St()), l = r.getState().stateLog[m], nt = H(/* @__PURE__ */ new Set()), q = H(I ?? St()), O = H(
|
|
198
198
|
null
|
|
199
199
|
);
|
|
200
|
-
|
|
200
|
+
O.current = Z(m) ?? null, ut(() => {
|
|
201
201
|
if (v && v.stateKey === m && v.path?.[0]) {
|
|
202
202
|
Y(m, (n) => ({
|
|
203
203
|
...n,
|
|
@@ -211,38 +211,38 @@ function Gt(t, {
|
|
|
211
211
|
}
|
|
212
212
|
}, [v]), ut(() => {
|
|
213
213
|
if (s) {
|
|
214
|
-
|
|
214
|
+
pt(m, {
|
|
215
215
|
initialState: s
|
|
216
216
|
});
|
|
217
|
-
const e =
|
|
218
|
-
if (!(c && !L(c, s) || !c) && !
|
|
217
|
+
const e = O.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = r.getState().initialStateGlobal[m];
|
|
218
|
+
if (!(c && !L(c, s) || !c) && !a)
|
|
219
219
|
return;
|
|
220
220
|
let u = null;
|
|
221
|
-
const N =
|
|
221
|
+
const N = J(e?.localStorage?.key) ? e?.localStorage?.key(s) : e?.localStorage?.key;
|
|
222
222
|
N && F && (u = it(`${F}-${m}-${N}`));
|
|
223
|
-
let p = s,
|
|
224
|
-
const C =
|
|
225
|
-
|
|
223
|
+
let p = s, A = !1;
|
|
224
|
+
const C = a ? Date.now() : 0, x = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
|
|
225
|
+
a && C > x ? (p = e.serverState.data, A = !0) : u && x > V && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), xt(
|
|
226
226
|
m,
|
|
227
227
|
s,
|
|
228
228
|
p,
|
|
229
|
-
|
|
229
|
+
X,
|
|
230
230
|
q.current,
|
|
231
231
|
F
|
|
232
|
-
),
|
|
232
|
+
), A && N && F && Et(p, m, e, F, Date.now()), ct(m), (Array.isArray(E) ? E : [E || "component"]).includes("none") || j({});
|
|
233
233
|
}
|
|
234
234
|
}, [
|
|
235
235
|
s,
|
|
236
236
|
g?.status,
|
|
237
237
|
g?.data,
|
|
238
|
-
...
|
|
238
|
+
...o || []
|
|
239
239
|
]), ft(() => {
|
|
240
|
-
W &&
|
|
240
|
+
W && pt(m, {
|
|
241
241
|
serverSync: h,
|
|
242
242
|
formElements: y,
|
|
243
243
|
initialState: s,
|
|
244
244
|
localStorage: f,
|
|
245
|
-
middleware:
|
|
245
|
+
middleware: O.current?.middleware
|
|
246
246
|
});
|
|
247
247
|
const e = `${m}////${q.current}`, n = r.getState().stateComponents.get(m) || {
|
|
248
248
|
components: /* @__PURE__ */ new Map()
|
|
@@ -251,119 +251,119 @@ function Gt(t, {
|
|
|
251
251
|
forceUpdate: () => j({}),
|
|
252
252
|
paths: /* @__PURE__ */ new Set(),
|
|
253
253
|
deps: [],
|
|
254
|
-
depsFunction:
|
|
255
|
-
reactiveType:
|
|
254
|
+
depsFunction: $ || void 0,
|
|
255
|
+
reactiveType: E ?? ["component", "deps"]
|
|
256
256
|
}), r.getState().stateComponents.set(m, n), j({}), () => {
|
|
257
|
-
const
|
|
258
|
-
n && (n.components.delete(
|
|
257
|
+
const a = `${m}////${q.current}`;
|
|
258
|
+
n && (n.components.delete(a), n.components.size === 0 && r.getState().stateComponents.delete(m));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const X = (e, n, a, c) => {
|
|
262
262
|
if (Array.isArray(n)) {
|
|
263
263
|
const S = `${m}-${n.join(".")}`;
|
|
264
264
|
nt.current.add(S);
|
|
265
265
|
}
|
|
266
266
|
Y(m, (S) => {
|
|
267
|
-
const u =
|
|
267
|
+
const u = J(e) ? e(S) : e, N = `${m}-${n.join(".")}`;
|
|
268
268
|
if (N) {
|
|
269
|
-
let
|
|
270
|
-
if ((!
|
|
271
|
-
const
|
|
272
|
-
if (Array.isArray(
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
|
|
269
|
+
let _ = !1, k = r.getState().signalDomElements.get(N);
|
|
270
|
+
if ((!k || k.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
|
|
271
|
+
const R = n.slice(0, -1), T = B(u, R);
|
|
272
|
+
if (Array.isArray(T)) {
|
|
273
|
+
_ = !0;
|
|
274
|
+
const w = `${m}-${R.join(".")}`;
|
|
275
|
+
k = r.getState().signalDomElements.get(w);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
`[data-parent-id="${
|
|
278
|
+
if (k) {
|
|
279
|
+
const R = _ ? B(u, n.slice(0, -1)) : B(u, n);
|
|
280
|
+
k.forEach(({ parentId: T, position: w, effect: P }) => {
|
|
281
|
+
const b = document.querySelector(
|
|
282
|
+
`[data-parent-id="${T}"]`
|
|
283
283
|
);
|
|
284
|
-
if (
|
|
285
|
-
const U = Array.from(
|
|
286
|
-
if (U[
|
|
287
|
-
const
|
|
288
|
-
U[
|
|
284
|
+
if (b) {
|
|
285
|
+
const U = Array.from(b.childNodes);
|
|
286
|
+
if (U[w]) {
|
|
287
|
+
const M = P ? new Function("state", `return (${P})(state)`)(R) : R;
|
|
288
|
+
U[w].textContent = String(M);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
|
|
295
|
-
(c ||
|
|
294
|
+
a.updateType === "update" && (c || O.current?.validation?.key) && n && z(
|
|
295
|
+
(c || O.current?.validation?.key) + "." + n.join(".")
|
|
296
296
|
);
|
|
297
297
|
const p = n.slice(0, n.length - 1);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
),
|
|
301
|
-
|
|
302
|
-
).filter(([
|
|
303
|
-
let
|
|
304
|
-
if (
|
|
305
|
-
let
|
|
306
|
-
z(
|
|
298
|
+
a.updateType === "cut" && O.current?.validation?.key && z(
|
|
299
|
+
O.current?.validation?.key + "." + p.join(".")
|
|
300
|
+
), a.updateType === "insert" && O.current?.validation?.key && Rt(
|
|
301
|
+
O.current?.validation?.key + "." + p.join(".")
|
|
302
|
+
).filter(([k, R]) => {
|
|
303
|
+
let T = k?.split(".").length;
|
|
304
|
+
if (k == p.join(".") && T == p.length - 1) {
|
|
305
|
+
let w = k + "." + p;
|
|
306
|
+
z(k), Ft(w, R);
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
|
-
const
|
|
310
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
311
|
-
const
|
|
309
|
+
const A = r.getState().stateComponents.get(m);
|
|
310
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", A), A) {
|
|
311
|
+
const _ = gt(S, u), k = new Set(_), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
|
|
312
312
|
for (const [
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
] of
|
|
316
|
-
let
|
|
317
|
-
const
|
|
318
|
-
if (console.log("component",
|
|
319
|
-
if (
|
|
320
|
-
|
|
313
|
+
T,
|
|
314
|
+
w
|
|
315
|
+
] of A.components.entries()) {
|
|
316
|
+
let P = !1;
|
|
317
|
+
const b = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
318
|
+
if (console.log("component", w), !b.includes("none")) {
|
|
319
|
+
if (b.includes("all")) {
|
|
320
|
+
w.forceUpdate();
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
324
|
-
for (const U of
|
|
325
|
-
let
|
|
323
|
+
if (b.includes("component") && ((w.paths.has(R) || w.paths.has("")) && (P = !0), !P))
|
|
324
|
+
for (const U of k) {
|
|
325
|
+
let M = U;
|
|
326
326
|
for (; ; ) {
|
|
327
|
-
if (
|
|
328
|
-
|
|
327
|
+
if (w.paths.has(M)) {
|
|
328
|
+
P = !0;
|
|
329
329
|
break;
|
|
330
330
|
}
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
const K =
|
|
331
|
+
const Q = M.lastIndexOf(".");
|
|
332
|
+
if (Q !== -1) {
|
|
333
|
+
const K = M.substring(
|
|
334
334
|
0,
|
|
335
|
-
|
|
335
|
+
Q
|
|
336
336
|
);
|
|
337
337
|
if (!isNaN(
|
|
338
|
-
Number(
|
|
339
|
-
) &&
|
|
340
|
-
|
|
338
|
+
Number(M.substring(Q + 1))
|
|
339
|
+
) && w.paths.has(K)) {
|
|
340
|
+
P = !0;
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
M = K;
|
|
344
344
|
} else
|
|
345
|
-
|
|
346
|
-
if (
|
|
345
|
+
M = "";
|
|
346
|
+
if (M === "")
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
|
-
if (
|
|
349
|
+
if (P) break;
|
|
350
350
|
}
|
|
351
|
-
if (!
|
|
352
|
-
const U =
|
|
353
|
-
let
|
|
354
|
-
typeof U == "boolean" ? U && (
|
|
351
|
+
if (!P && b.includes("deps") && w.depsFunction) {
|
|
352
|
+
const U = w.depsFunction(u);
|
|
353
|
+
let M = !1;
|
|
354
|
+
typeof U == "boolean" ? U && (M = !0) : L(w.deps, U) || (w.deps = U, M = !0), M && (P = !0);
|
|
355
355
|
}
|
|
356
|
-
|
|
356
|
+
P && w.forceUpdate();
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
const C = Date.now();
|
|
361
|
-
n = n.map((
|
|
362
|
-
const
|
|
363
|
-
return
|
|
361
|
+
n = n.map((_, k) => {
|
|
362
|
+
const R = n.slice(0, -1), T = B(u, R);
|
|
363
|
+
return k === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (T.length - 1).toString() : _;
|
|
364
364
|
});
|
|
365
|
-
const { oldValue:
|
|
366
|
-
|
|
365
|
+
const { oldValue: x, newValue: V } = Gt(
|
|
366
|
+
a.updateType,
|
|
367
367
|
S,
|
|
368
368
|
u,
|
|
369
369
|
n
|
|
@@ -371,94 +371,94 @@ function Gt(t, {
|
|
|
371
371
|
timeStamp: C,
|
|
372
372
|
stateKey: m,
|
|
373
373
|
path: n,
|
|
374
|
-
updateType:
|
|
374
|
+
updateType: a.updateType,
|
|
375
375
|
status: "new",
|
|
376
|
-
oldValue:
|
|
377
|
-
newValue:
|
|
376
|
+
oldValue: x,
|
|
377
|
+
newValue: V
|
|
378
378
|
};
|
|
379
|
-
if (jt(m, (
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
return
|
|
379
|
+
if (jt(m, (_) => {
|
|
380
|
+
const R = [..._ ?? [], D].reduce((T, w) => {
|
|
381
|
+
const P = `${w.stateKey}:${JSON.stringify(w.path)}`, b = T.get(P);
|
|
382
|
+
return b ? (b.timeStamp = Math.max(b.timeStamp, w.timeStamp), b.newValue = w.newValue, b.oldValue = b.oldValue ?? w.oldValue, b.updateType = w.updateType) : T.set(P, { ...w }), T;
|
|
383
383
|
}, /* @__PURE__ */ new Map());
|
|
384
|
-
return Array.from(
|
|
385
|
-
}),
|
|
384
|
+
return Array.from(R.values());
|
|
385
|
+
}), Et(
|
|
386
386
|
u,
|
|
387
387
|
m,
|
|
388
|
-
|
|
388
|
+
O.current,
|
|
389
389
|
F
|
|
390
|
-
),
|
|
390
|
+
), O.current?.middleware && O.current.middleware({
|
|
391
391
|
updateLog: l,
|
|
392
392
|
update: D
|
|
393
|
-
}),
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
syncKey: typeof
|
|
397
|
-
rollBackState:
|
|
398
|
-
actionTimeStamp: Date.now() + (
|
|
393
|
+
}), O.current?.serverSync) {
|
|
394
|
+
const _ = r.getState().serverState[m], k = O.current?.serverSync;
|
|
395
|
+
Ut(m, {
|
|
396
|
+
syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: u }),
|
|
397
|
+
rollBackState: _,
|
|
398
|
+
actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
|
|
399
399
|
status: "waiting"
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
402
|
return u;
|
|
403
403
|
});
|
|
404
404
|
};
|
|
405
|
-
r.getState().updaterState[m] || (
|
|
405
|
+
r.getState().updaterState[m] || (ot(
|
|
406
406
|
m,
|
|
407
|
-
|
|
407
|
+
at(
|
|
408
408
|
m,
|
|
409
|
-
|
|
409
|
+
X,
|
|
410
410
|
q.current,
|
|
411
411
|
F
|
|
412
412
|
)
|
|
413
413
|
), r.getState().cogsStateStore[m] || Y(m, t), r.getState().initialStateGlobal[m] || mt(m, t));
|
|
414
|
-
const d =
|
|
414
|
+
const d = At(() => at(
|
|
415
415
|
m,
|
|
416
|
-
|
|
416
|
+
X,
|
|
417
417
|
q.current,
|
|
418
418
|
F
|
|
419
419
|
), [m, F]);
|
|
420
|
-
return [
|
|
420
|
+
return [kt(m), d];
|
|
421
421
|
}
|
|
422
|
-
function
|
|
422
|
+
function at(t, i, h, f) {
|
|
423
423
|
const y = /* @__PURE__ */ new Map();
|
|
424
|
-
let
|
|
425
|
-
const
|
|
426
|
-
const
|
|
424
|
+
let $ = 0;
|
|
425
|
+
const E = (v) => {
|
|
426
|
+
const o = v.join(".");
|
|
427
427
|
for (const [g] of y)
|
|
428
|
-
(g ===
|
|
429
|
-
|
|
428
|
+
(g === o || g.startsWith(o + ".")) && y.delete(g);
|
|
429
|
+
$++;
|
|
430
430
|
}, I = {
|
|
431
431
|
removeValidation: (v) => {
|
|
432
432
|
v?.validationKey && z(v.validationKey);
|
|
433
433
|
},
|
|
434
434
|
revertToInitialState: (v) => {
|
|
435
|
-
const
|
|
436
|
-
|
|
435
|
+
const o = r.getState().getInitialOptions(t)?.validation;
|
|
436
|
+
o?.key && z(o?.key), v?.validationKey && z(v.validationKey);
|
|
437
437
|
const g = r.getState().initialStateGlobal[t];
|
|
438
|
-
r.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
439
|
-
const G = s(g, []), j =
|
|
440
|
-
W && localStorage.removeItem(W),
|
|
438
|
+
r.getState().clearSelectedIndexesForState(t), y.clear(), $++;
|
|
439
|
+
const G = s(g, []), j = Z(t), F = J(j?.localStorage?.key) ? j?.localStorage?.key(g) : j?.localStorage?.key, W = `${f}-${t}-${F}`;
|
|
440
|
+
W && localStorage.removeItem(W), ot(t, G), Y(t, g);
|
|
441
441
|
const m = r.getState().stateComponents.get(t);
|
|
442
442
|
return m && m.components.forEach((l) => {
|
|
443
443
|
l.forceUpdate();
|
|
444
444
|
}), g;
|
|
445
445
|
},
|
|
446
446
|
updateInitialState: (v) => {
|
|
447
|
-
y.clear(),
|
|
448
|
-
const
|
|
447
|
+
y.clear(), $++;
|
|
448
|
+
const o = at(
|
|
449
449
|
t,
|
|
450
450
|
i,
|
|
451
451
|
h,
|
|
452
452
|
f
|
|
453
|
-
), g = r.getState().initialStateGlobal[t], G =
|
|
454
|
-
return localStorage.getItem(F) && localStorage.removeItem(F),
|
|
455
|
-
mt(t, v),
|
|
453
|
+
), g = r.getState().initialStateGlobal[t], G = Z(t), j = J(G?.localStorage?.key) ? G?.localStorage?.key(g) : G?.localStorage?.key, F = `${f}-${t}-${j}`;
|
|
454
|
+
return localStorage.getItem(F) && localStorage.removeItem(F), Vt(() => {
|
|
455
|
+
mt(t, v), ot(t, o), Y(t, v);
|
|
456
456
|
const W = r.getState().stateComponents.get(t);
|
|
457
457
|
W && W.components.forEach((m) => {
|
|
458
458
|
m.forceUpdate();
|
|
459
459
|
});
|
|
460
460
|
}), {
|
|
461
|
-
fetchId: (W) =>
|
|
461
|
+
fetchId: (W) => o.get()[W]
|
|
462
462
|
};
|
|
463
463
|
},
|
|
464
464
|
_initialState: r.getState().initialStateGlobal[t],
|
|
@@ -466,14 +466,14 @@ function ot(t, i, h, f) {
|
|
|
466
466
|
_isLoading: r.getState().isLoadingGlobal[t],
|
|
467
467
|
_isServerSynced: () => {
|
|
468
468
|
const v = r.getState().serverState[t];
|
|
469
|
-
return !!(v && L(v,
|
|
469
|
+
return !!(v && L(v, kt(t)));
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
|
-
function s(v,
|
|
473
|
-
const G =
|
|
472
|
+
function s(v, o = [], g) {
|
|
473
|
+
const G = o.map(String).join(".");
|
|
474
474
|
y.get(G);
|
|
475
475
|
const j = function() {
|
|
476
|
-
return r().getNestedState(t,
|
|
476
|
+
return r().getNestedState(t, o);
|
|
477
477
|
};
|
|
478
478
|
Object.keys(I).forEach((m) => {
|
|
479
479
|
j[m] = I[m];
|
|
@@ -481,8 +481,8 @@ function ot(t, i, h, f) {
|
|
|
481
481
|
const F = {
|
|
482
482
|
apply(m, l, nt) {
|
|
483
483
|
return console.log(
|
|
484
|
-
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${
|
|
485
|
-
), console.trace("Apply trap stack trace"), r().getNestedState(t,
|
|
484
|
+
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${o.join(".")}`
|
|
485
|
+
), console.trace("Apply trap stack trace"), r().getNestedState(t, o);
|
|
486
486
|
},
|
|
487
487
|
get(m, l) {
|
|
488
488
|
g?.validIndices && !Array.isArray(v) && (g = { ...g, validIndices: void 0 });
|
|
@@ -514,14 +514,14 @@ function ot(t, i, h, f) {
|
|
|
514
514
|
if (e) {
|
|
515
515
|
const n = e.components.get(d);
|
|
516
516
|
if (n && !n.paths.has("")) {
|
|
517
|
-
const
|
|
517
|
+
const a = o.join(".");
|
|
518
518
|
let c = !0;
|
|
519
519
|
for (const S of n.paths)
|
|
520
|
-
if (
|
|
520
|
+
if (a.startsWith(S) && (a === S || a[S.length] === ".")) {
|
|
521
521
|
c = !1;
|
|
522
522
|
break;
|
|
523
523
|
}
|
|
524
|
-
c && n.paths.add(
|
|
524
|
+
c && n.paths.add(a);
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
}
|
|
@@ -530,17 +530,17 @@ function ot(t, i, h, f) {
|
|
|
530
530
|
r.getState().cogsStateStore[t],
|
|
531
531
|
r.getState().initialStateGlobal[t]
|
|
532
532
|
);
|
|
533
|
-
if (l === "sync" &&
|
|
533
|
+
if (l === "sync" && o.length === 0)
|
|
534
534
|
return async function() {
|
|
535
535
|
const d = r.getState().getInitialOptions(t), e = d?.sync;
|
|
536
536
|
if (!e)
|
|
537
537
|
return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
|
|
538
|
-
const n = r.getState().getNestedState(t, []),
|
|
538
|
+
const n = r.getState().getNestedState(t, []), a = d?.validation?.key;
|
|
539
539
|
try {
|
|
540
540
|
const c = await e.action(n);
|
|
541
|
-
if (c && !c.success && c.errors &&
|
|
542
|
-
r.getState().removeValidationError(
|
|
543
|
-
const N = [
|
|
541
|
+
if (c && !c.success && c.errors && a) {
|
|
542
|
+
r.getState().removeValidationError(a), c.errors.forEach((u) => {
|
|
543
|
+
const N = [a, ...u.path].join(".");
|
|
544
544
|
r.getState().addValidationError(N, u.message);
|
|
545
545
|
});
|
|
546
546
|
const S = r.getState().stateComponents.get(t);
|
|
@@ -554,99 +554,105 @@ function ot(t, i, h, f) {
|
|
|
554
554
|
}
|
|
555
555
|
};
|
|
556
556
|
if (l === "_status") {
|
|
557
|
-
const d = r.getState().getNestedState(t,
|
|
557
|
+
const d = r.getState().getNestedState(t, o), e = r.getState().initialStateGlobal[t], n = B(e, o);
|
|
558
558
|
return L(d, n) ? "fresh" : "stale";
|
|
559
559
|
}
|
|
560
560
|
if (l === "getStatus")
|
|
561
561
|
return function() {
|
|
562
562
|
const d = r().getNestedState(
|
|
563
563
|
t,
|
|
564
|
-
|
|
565
|
-
), e = r.getState().initialStateGlobal[t], n = B(e,
|
|
564
|
+
o
|
|
565
|
+
), e = r.getState().initialStateGlobal[t], n = B(e, o);
|
|
566
566
|
return L(d, n) ? "fresh" : "stale";
|
|
567
567
|
};
|
|
568
568
|
if (l === "removeStorage")
|
|
569
569
|
return () => {
|
|
570
|
-
const d = r.getState().initialStateGlobal[t], e =
|
|
571
|
-
|
|
570
|
+
const d = r.getState().initialStateGlobal[t], e = Z(t), n = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${f}-${t}-${n}`;
|
|
571
|
+
a && localStorage.removeItem(a);
|
|
572
572
|
};
|
|
573
573
|
if (l === "showValidationErrors")
|
|
574
574
|
return () => {
|
|
575
575
|
const d = r.getState().getInitialOptions(t)?.validation;
|
|
576
576
|
if (!d?.key)
|
|
577
577
|
throw new Error("Validation key not found");
|
|
578
|
-
return r.getState().getValidationErrors(d.key + "." +
|
|
578
|
+
return r.getState().getValidationErrors(d.key + "." + o.join("."));
|
|
579
579
|
};
|
|
580
580
|
if (Array.isArray(v)) {
|
|
581
|
-
const d = () => g?.validIndices ? v.map((n,
|
|
581
|
+
const d = () => g?.validIndices ? v.map((n, a) => ({
|
|
582
582
|
item: n,
|
|
583
|
-
originalIndex: g.validIndices[
|
|
584
|
-
})) : r.getState().getNestedState(t,
|
|
583
|
+
originalIndex: g.validIndices[a]
|
|
584
|
+
})) : r.getState().getNestedState(t, o).map((n, a) => ({
|
|
585
585
|
item: n,
|
|
586
|
-
originalIndex:
|
|
586
|
+
originalIndex: a
|
|
587
587
|
}));
|
|
588
588
|
if (l === "getSelected")
|
|
589
589
|
return () => {
|
|
590
|
-
const e = r.getState().getSelectedIndex(t,
|
|
590
|
+
const e = r.getState().getSelectedIndex(t, o.join("."));
|
|
591
591
|
if (e !== void 0)
|
|
592
592
|
return s(
|
|
593
593
|
v[e],
|
|
594
|
-
[...
|
|
594
|
+
[...o, e.toString()],
|
|
595
595
|
g
|
|
596
596
|
);
|
|
597
597
|
};
|
|
598
598
|
if (l === "clearSelected")
|
|
599
599
|
return () => {
|
|
600
|
-
r.getState().clearSelectedIndex({ stateKey: t, path:
|
|
600
|
+
r.getState().clearSelectedIndex({ stateKey: t, path: o });
|
|
601
601
|
};
|
|
602
602
|
if (l === "getSelectedIndex")
|
|
603
|
-
return () => r.getState().getSelectedIndex(t,
|
|
603
|
+
return () => r.getState().getSelectedIndex(t, o.join(".")) ?? -1;
|
|
604
604
|
if (l === "useVirtualView")
|
|
605
605
|
return (e) => {
|
|
606
606
|
const {
|
|
607
607
|
itemHeight: n,
|
|
608
|
-
overscan:
|
|
608
|
+
overscan: a = 5,
|
|
609
609
|
stickToBottom: c = !1
|
|
610
|
-
} = e, S =
|
|
610
|
+
} = e, S = H(null), [u, N] = et({
|
|
611
611
|
startIndex: 0,
|
|
612
612
|
endIndex: 10
|
|
613
|
-
}), p =
|
|
613
|
+
}), p = H(c), A = H(0), C = H(!0), x = r().getNestedState(
|
|
614
614
|
t,
|
|
615
|
-
|
|
616
|
-
),
|
|
617
|
-
const T = Math.max(0, u.startIndex),
|
|
618
|
-
{ length:
|
|
619
|
-
(
|
|
620
|
-
), b =
|
|
621
|
-
return s(b,
|
|
615
|
+
o
|
|
616
|
+
), V = x.length, D = At(() => {
|
|
617
|
+
const T = Math.max(0, u.startIndex), w = Math.min(V, u.endIndex), P = Array.from(
|
|
618
|
+
{ length: w - T },
|
|
619
|
+
(U, M) => T + M
|
|
620
|
+
), b = P.map((U) => x[U]);
|
|
621
|
+
return s(b, o, {
|
|
622
622
|
...g,
|
|
623
|
-
validIndices:
|
|
623
|
+
validIndices: P
|
|
624
624
|
});
|
|
625
|
-
}, [u.startIndex, u.endIndex,
|
|
625
|
+
}, [u.startIndex, u.endIndex, x, V]);
|
|
626
626
|
ft(() => {
|
|
627
627
|
const T = S.current;
|
|
628
628
|
if (!T) return;
|
|
629
|
-
const
|
|
630
|
-
|
|
629
|
+
const w = p.current, P = V > A.current;
|
|
630
|
+
A.current = V;
|
|
631
631
|
const b = () => {
|
|
632
|
-
const { scrollTop:
|
|
633
|
-
p.current =
|
|
634
|
-
const
|
|
632
|
+
const { scrollTop: U, clientHeight: M, scrollHeight: Q } = T;
|
|
633
|
+
p.current = Q - U - M < 10;
|
|
634
|
+
const K = Math.max(
|
|
635
635
|
0,
|
|
636
|
-
Math.floor(
|
|
637
|
-
),
|
|
638
|
-
|
|
639
|
-
Math.ceil((
|
|
636
|
+
Math.floor(U / n) - a
|
|
637
|
+
), yt = Math.min(
|
|
638
|
+
V,
|
|
639
|
+
Math.ceil((U + M) / n) + a
|
|
640
640
|
);
|
|
641
|
-
N((lt) => lt.startIndex !==
|
|
641
|
+
N((lt) => lt.startIndex !== K || lt.endIndex !== yt ? { startIndex: K, endIndex: yt } : lt);
|
|
642
642
|
};
|
|
643
643
|
return T.addEventListener("scroll", b, {
|
|
644
644
|
passive: !0
|
|
645
|
-
}), c &&
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
645
|
+
}), c && (C.current ? T.scrollTo({
|
|
646
|
+
top: T.scrollHeight,
|
|
647
|
+
behavior: "auto"
|
|
648
|
+
}) : w && P && requestAnimationFrame(() => {
|
|
649
|
+
T.scrollTo({
|
|
650
|
+
top: T.scrollHeight,
|
|
651
|
+
behavior: "smooth"
|
|
652
|
+
});
|
|
653
|
+
})), C.current = !1, b(), () => T.removeEventListener("scroll", b);
|
|
654
|
+
}, [V, n, a, c]);
|
|
655
|
+
const _ = ht(
|
|
650
656
|
(T = "smooth") => {
|
|
651
657
|
S.current && S.current.scrollTo({
|
|
652
658
|
top: S.current.scrollHeight,
|
|
@@ -654,115 +660,109 @@ function ot(t, i, h, f) {
|
|
|
654
660
|
});
|
|
655
661
|
},
|
|
656
662
|
[]
|
|
657
|
-
),
|
|
658
|
-
(T,
|
|
663
|
+
), k = ht(
|
|
664
|
+
(T, w = "smooth") => {
|
|
659
665
|
S.current && S.current.scrollTo({
|
|
660
666
|
top: T * n,
|
|
661
|
-
behavior:
|
|
667
|
+
behavior: w
|
|
662
668
|
});
|
|
663
669
|
},
|
|
664
670
|
[n]
|
|
665
|
-
),
|
|
671
|
+
), R = {
|
|
666
672
|
outer: {
|
|
667
673
|
ref: S,
|
|
668
|
-
style: {
|
|
669
|
-
overflowY: "auto",
|
|
670
|
-
height: "100%"
|
|
671
|
-
// Ensure the container has a defined height to scroll within
|
|
672
|
-
}
|
|
674
|
+
style: { overflowY: "auto", height: "100%" }
|
|
673
675
|
},
|
|
674
676
|
inner: {
|
|
675
677
|
style: {
|
|
676
|
-
height: `${
|
|
678
|
+
height: `${V * n}px`,
|
|
677
679
|
position: "relative"
|
|
678
|
-
// Added for containment
|
|
679
680
|
}
|
|
680
681
|
},
|
|
681
682
|
list: {
|
|
682
683
|
style: {
|
|
683
684
|
transform: `translateY(${u.startIndex * n}px)`
|
|
684
|
-
// Use transform for better performance
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
687
|
};
|
|
688
688
|
return {
|
|
689
|
-
virtualState:
|
|
690
|
-
virtualizerProps:
|
|
691
|
-
scrollToBottom:
|
|
692
|
-
scrollToIndex:
|
|
689
|
+
virtualState: D,
|
|
690
|
+
virtualizerProps: R,
|
|
691
|
+
scrollToBottom: _,
|
|
692
|
+
scrollToIndex: k
|
|
693
693
|
};
|
|
694
694
|
};
|
|
695
695
|
if (l === "stateSort")
|
|
696
696
|
return (e) => {
|
|
697
|
-
const
|
|
697
|
+
const a = [...d()].sort(
|
|
698
698
|
(u, N) => e(u.item, N.item)
|
|
699
|
-
), c =
|
|
699
|
+
), c = a.map(({ item: u }) => u), S = {
|
|
700
700
|
...g,
|
|
701
|
-
validIndices:
|
|
701
|
+
validIndices: a.map(
|
|
702
702
|
({ originalIndex: u }) => u
|
|
703
703
|
)
|
|
704
704
|
};
|
|
705
|
-
return s(c,
|
|
705
|
+
return s(c, o, S);
|
|
706
706
|
};
|
|
707
707
|
if (l === "stateFilter")
|
|
708
708
|
return (e) => {
|
|
709
|
-
const
|
|
709
|
+
const a = d().filter(
|
|
710
710
|
({ item: u }, N) => e(u, N)
|
|
711
|
-
), c =
|
|
711
|
+
), c = a.map(({ item: u }) => u), S = {
|
|
712
712
|
...g,
|
|
713
|
-
validIndices:
|
|
713
|
+
validIndices: a.map(
|
|
714
714
|
({ originalIndex: u }) => u
|
|
715
715
|
)
|
|
716
716
|
};
|
|
717
|
-
return s(c,
|
|
717
|
+
return s(c, o, S);
|
|
718
718
|
};
|
|
719
719
|
if (l === "stateMap")
|
|
720
720
|
return (e) => {
|
|
721
|
-
const n = r.getState().getNestedState(t,
|
|
721
|
+
const n = r.getState().getNestedState(t, o);
|
|
722
722
|
return Array.isArray(n) ? (g?.validIndices || Array.from({ length: n.length }, (c, S) => S)).map((c, S) => {
|
|
723
|
-
const u = n[c], N = [...
|
|
723
|
+
const u = n[c], N = [...o, c.toString()], p = s(u, N, g);
|
|
724
724
|
return e(u, p, {
|
|
725
725
|
register: () => {
|
|
726
|
-
const [, C] = et({}),
|
|
726
|
+
const [, C] = et({}), x = `${h}-${o.join(".")}-${c}`;
|
|
727
727
|
ft(() => {
|
|
728
|
-
const
|
|
728
|
+
const V = `${t}////${x}`, D = r.getState().stateComponents.get(t) || {
|
|
729
729
|
components: /* @__PURE__ */ new Map()
|
|
730
730
|
};
|
|
731
|
-
return D.components.set(
|
|
731
|
+
return D.components.set(V, {
|
|
732
732
|
forceUpdate: () => C({}),
|
|
733
733
|
paths: /* @__PURE__ */ new Set([N.join(".")])
|
|
734
734
|
}), r.getState().stateComponents.set(t, D), () => {
|
|
735
|
-
const
|
|
736
|
-
|
|
735
|
+
const _ = r.getState().stateComponents.get(t);
|
|
736
|
+
_ && _.components.delete(V);
|
|
737
737
|
};
|
|
738
|
-
}, [t,
|
|
738
|
+
}, [t, x]);
|
|
739
739
|
},
|
|
740
740
|
index: S,
|
|
741
741
|
originalIndex: c
|
|
742
742
|
});
|
|
743
743
|
}) : (console.warn(
|
|
744
|
-
`stateMap called on a non-array value at path: ${
|
|
744
|
+
`stateMap called on a non-array value at path: ${o.join(".")}. The current value is:`,
|
|
745
745
|
n
|
|
746
746
|
), null);
|
|
747
747
|
};
|
|
748
748
|
if (l === "stateMapNoRender")
|
|
749
|
-
return (e) => v.map((
|
|
749
|
+
return (e) => v.map((a, c) => {
|
|
750
750
|
let S;
|
|
751
751
|
g?.validIndices && g.validIndices[c] !== void 0 ? S = g.validIndices[c] : S = c;
|
|
752
|
-
const u = [...
|
|
752
|
+
const u = [...o, S.toString()], N = s(a, u, g);
|
|
753
753
|
return e(
|
|
754
|
-
|
|
754
|
+
a,
|
|
755
755
|
N,
|
|
756
756
|
c,
|
|
757
757
|
v,
|
|
758
|
-
s(v,
|
|
758
|
+
s(v, o, g)
|
|
759
759
|
);
|
|
760
760
|
});
|
|
761
761
|
if (l === "$stateMap")
|
|
762
|
-
return (e) => st(
|
|
762
|
+
return (e) => st(Lt, {
|
|
763
763
|
proxy: {
|
|
764
764
|
_stateKey: t,
|
|
765
|
-
_path:
|
|
765
|
+
_path: o,
|
|
766
766
|
_mapFn: e
|
|
767
767
|
// Pass the actual function, not string
|
|
768
768
|
},
|
|
@@ -771,81 +771,81 @@ function ot(t, i, h, f) {
|
|
|
771
771
|
if (l === "stateFlattenOn")
|
|
772
772
|
return (e) => {
|
|
773
773
|
const n = v;
|
|
774
|
-
y.clear(),
|
|
775
|
-
const
|
|
774
|
+
y.clear(), $++;
|
|
775
|
+
const a = n.flatMap(
|
|
776
776
|
(c) => c[e] ?? []
|
|
777
777
|
);
|
|
778
778
|
return s(
|
|
779
|
-
|
|
780
|
-
[...
|
|
779
|
+
a,
|
|
780
|
+
[...o, "[*]", e],
|
|
781
781
|
g
|
|
782
782
|
);
|
|
783
783
|
};
|
|
784
784
|
if (l === "index")
|
|
785
785
|
return (e) => {
|
|
786
786
|
const n = v[e];
|
|
787
|
-
return s(n, [...
|
|
787
|
+
return s(n, [...o, e.toString()]);
|
|
788
788
|
};
|
|
789
789
|
if (l === "last")
|
|
790
790
|
return () => {
|
|
791
|
-
const e = r.getState().getNestedState(t,
|
|
791
|
+
const e = r.getState().getNestedState(t, o);
|
|
792
792
|
if (e.length === 0) return;
|
|
793
|
-
const n = e.length - 1,
|
|
794
|
-
return s(
|
|
793
|
+
const n = e.length - 1, a = e[n], c = [...o, n.toString()];
|
|
794
|
+
return s(a, c);
|
|
795
795
|
};
|
|
796
796
|
if (l === "insert")
|
|
797
|
-
return (e) => (
|
|
798
|
-
r.getState().getNestedState(t,
|
|
799
|
-
|
|
797
|
+
return (e) => (E(o), dt(i, e, o, t), s(
|
|
798
|
+
r.getState().getNestedState(t, o),
|
|
799
|
+
o
|
|
800
800
|
));
|
|
801
801
|
if (l === "uniqueInsert")
|
|
802
|
-
return (e, n,
|
|
803
|
-
const c = r.getState().getNestedState(t,
|
|
802
|
+
return (e, n, a) => {
|
|
803
|
+
const c = r.getState().getNestedState(t, o), S = J(e) ? e(c) : e;
|
|
804
804
|
let u = null;
|
|
805
805
|
if (!c.some((p) => {
|
|
806
806
|
if (n) {
|
|
807
807
|
const C = n.every(
|
|
808
|
-
(
|
|
808
|
+
(x) => L(p[x], S[x])
|
|
809
809
|
);
|
|
810
810
|
return C && (u = p), C;
|
|
811
811
|
}
|
|
812
|
-
const
|
|
813
|
-
return
|
|
812
|
+
const A = L(p, S);
|
|
813
|
+
return A && (u = p), A;
|
|
814
814
|
}))
|
|
815
|
-
|
|
816
|
-
else if (
|
|
817
|
-
const p =
|
|
815
|
+
E(o), dt(i, S, o, t);
|
|
816
|
+
else if (a && u) {
|
|
817
|
+
const p = a(u), A = c.map(
|
|
818
818
|
(C) => L(C, u) ? p : C
|
|
819
819
|
);
|
|
820
|
-
|
|
820
|
+
E(o), tt(i, A, o);
|
|
821
821
|
}
|
|
822
822
|
};
|
|
823
823
|
if (l === "cut")
|
|
824
824
|
return (e, n) => {
|
|
825
825
|
if (!n?.waitForSync)
|
|
826
|
-
return
|
|
827
|
-
r.getState().getNestedState(t,
|
|
828
|
-
|
|
826
|
+
return E(o), rt(i, o, t, e), s(
|
|
827
|
+
r.getState().getNestedState(t, o),
|
|
828
|
+
o
|
|
829
829
|
);
|
|
830
830
|
};
|
|
831
831
|
if (l === "cutByValue")
|
|
832
832
|
return (e) => {
|
|
833
833
|
for (let n = 0; n < v.length; n++)
|
|
834
|
-
v[n] === e && rt(i,
|
|
834
|
+
v[n] === e && rt(i, o, t, n);
|
|
835
835
|
};
|
|
836
836
|
if (l === "toggleByValue")
|
|
837
837
|
return (e) => {
|
|
838
|
-
const n = v.findIndex((
|
|
839
|
-
n > -1 ? rt(i,
|
|
838
|
+
const n = v.findIndex((a) => a === e);
|
|
839
|
+
n > -1 ? rt(i, o, t, n) : dt(i, e, o, t);
|
|
840
840
|
};
|
|
841
841
|
if (l === "stateFind")
|
|
842
842
|
return (e) => {
|
|
843
|
-
const
|
|
843
|
+
const a = d().find(
|
|
844
844
|
({ item: S }, u) => e(S, u)
|
|
845
845
|
);
|
|
846
|
-
if (!
|
|
847
|
-
const c = [...
|
|
848
|
-
return s(
|
|
846
|
+
if (!a) return;
|
|
847
|
+
const c = [...o, a.originalIndex.toString()];
|
|
848
|
+
return s(a.item, c, g);
|
|
849
849
|
};
|
|
850
850
|
if (l === "findWith")
|
|
851
851
|
return (e, n) => {
|
|
@@ -853,13 +853,13 @@ function ot(t, i, h, f) {
|
|
|
853
853
|
({ item: u }) => u[e] === n
|
|
854
854
|
);
|
|
855
855
|
if (!c) return;
|
|
856
|
-
const S = [...
|
|
856
|
+
const S = [...o, c.originalIndex.toString()];
|
|
857
857
|
return s(c.item, S, g);
|
|
858
858
|
};
|
|
859
859
|
}
|
|
860
|
-
const q =
|
|
860
|
+
const q = o[o.length - 1];
|
|
861
861
|
if (!isNaN(Number(q))) {
|
|
862
|
-
const d =
|
|
862
|
+
const d = o.slice(0, -1), e = r.getState().getNestedState(t, d);
|
|
863
863
|
if (Array.isArray(e) && l === "cut")
|
|
864
864
|
return () => rt(
|
|
865
865
|
i,
|
|
@@ -871,115 +871,115 @@ function ot(t, i, h, f) {
|
|
|
871
871
|
if (l === "get")
|
|
872
872
|
return () => {
|
|
873
873
|
if (g?.validIndices && Array.isArray(v)) {
|
|
874
|
-
const d = r.getState().getNestedState(t,
|
|
874
|
+
const d = r.getState().getNestedState(t, o);
|
|
875
875
|
return g.validIndices.map((e) => d[e]);
|
|
876
876
|
}
|
|
877
|
-
return r.getState().getNestedState(t,
|
|
877
|
+
return r.getState().getNestedState(t, o);
|
|
878
878
|
};
|
|
879
879
|
if (l === "$derive")
|
|
880
|
-
return (d) =>
|
|
880
|
+
return (d) => Tt({
|
|
881
881
|
_stateKey: t,
|
|
882
|
-
_path:
|
|
882
|
+
_path: o,
|
|
883
883
|
_effect: d.toString()
|
|
884
884
|
});
|
|
885
885
|
if (l === "$get")
|
|
886
|
-
return () =>
|
|
886
|
+
return () => Tt({
|
|
887
887
|
_stateKey: t,
|
|
888
|
-
_path:
|
|
888
|
+
_path: o
|
|
889
889
|
});
|
|
890
890
|
if (l === "lastSynced") {
|
|
891
|
-
const d = `${t}:${
|
|
891
|
+
const d = `${t}:${o.join(".")}`;
|
|
892
892
|
return r.getState().getSyncInfo(d);
|
|
893
893
|
}
|
|
894
894
|
if (l == "getLocalStorage")
|
|
895
895
|
return (d) => it(f + "-" + t + "-" + d);
|
|
896
896
|
if (l === "_selected") {
|
|
897
|
-
const d =
|
|
898
|
-
return Array.isArray(n) ? Number(
|
|
897
|
+
const d = o.slice(0, -1), e = d.join("."), n = r.getState().getNestedState(t, d);
|
|
898
|
+
return Array.isArray(n) ? Number(o[o.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
|
|
899
899
|
}
|
|
900
900
|
if (l === "setSelected")
|
|
901
901
|
return (d) => {
|
|
902
|
-
const e =
|
|
903
|
-
d ? r.getState().setSelectedIndex(t,
|
|
902
|
+
const e = o.slice(0, -1), n = Number(o[o.length - 1]), a = e.join(".");
|
|
903
|
+
d ? r.getState().setSelectedIndex(t, a, n) : r.getState().setSelectedIndex(t, a, void 0);
|
|
904
904
|
const c = r.getState().getNestedState(t, [...e]);
|
|
905
|
-
tt(i, c, e),
|
|
905
|
+
tt(i, c, e), E(e);
|
|
906
906
|
};
|
|
907
907
|
if (l === "toggleSelected")
|
|
908
908
|
return () => {
|
|
909
|
-
const d =
|
|
909
|
+
const d = o.slice(0, -1), e = Number(o[o.length - 1]), n = d.join("."), a = r.getState().getSelectedIndex(t, n);
|
|
910
910
|
r.getState().setSelectedIndex(
|
|
911
911
|
t,
|
|
912
912
|
n,
|
|
913
|
-
|
|
913
|
+
a === e ? void 0 : e
|
|
914
914
|
);
|
|
915
915
|
const c = r.getState().getNestedState(t, [...d]);
|
|
916
|
-
tt(i, c, d),
|
|
916
|
+
tt(i, c, d), E(d);
|
|
917
917
|
};
|
|
918
|
-
if (
|
|
918
|
+
if (o.length == 0) {
|
|
919
919
|
if (l === "applyJsonPatch")
|
|
920
920
|
return (d) => {
|
|
921
|
-
const e = r.getState().cogsStateStore[t],
|
|
922
|
-
|
|
921
|
+
const e = r.getState().cogsStateStore[t], a = Ot(e, d).newDocument;
|
|
922
|
+
xt(
|
|
923
923
|
t,
|
|
924
924
|
r.getState().initialStateGlobal[t],
|
|
925
|
-
|
|
925
|
+
a,
|
|
926
926
|
i,
|
|
927
927
|
h,
|
|
928
928
|
f
|
|
929
929
|
);
|
|
930
930
|
const c = r.getState().stateComponents.get(t);
|
|
931
931
|
if (c) {
|
|
932
|
-
const S = gt(e,
|
|
932
|
+
const S = gt(e, a), u = new Set(S);
|
|
933
933
|
for (const [
|
|
934
934
|
N,
|
|
935
935
|
p
|
|
936
936
|
] of c.components.entries()) {
|
|
937
|
-
let
|
|
937
|
+
let A = !1;
|
|
938
938
|
const C = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
|
|
939
939
|
if (!C.includes("none")) {
|
|
940
940
|
if (C.includes("all")) {
|
|
941
941
|
p.forceUpdate();
|
|
942
942
|
continue;
|
|
943
943
|
}
|
|
944
|
-
if (C.includes("component") && (p.paths.has("") && (
|
|
945
|
-
for (const
|
|
946
|
-
if (p.paths.has(
|
|
947
|
-
|
|
944
|
+
if (C.includes("component") && (p.paths.has("") && (A = !0), !A))
|
|
945
|
+
for (const x of u) {
|
|
946
|
+
if (p.paths.has(x)) {
|
|
947
|
+
A = !0;
|
|
948
948
|
break;
|
|
949
949
|
}
|
|
950
|
-
let
|
|
951
|
-
for (;
|
|
952
|
-
const D =
|
|
950
|
+
let V = x.lastIndexOf(".");
|
|
951
|
+
for (; V !== -1; ) {
|
|
952
|
+
const D = x.substring(0, V);
|
|
953
953
|
if (p.paths.has(D)) {
|
|
954
|
-
|
|
954
|
+
A = !0;
|
|
955
955
|
break;
|
|
956
956
|
}
|
|
957
|
-
const
|
|
958
|
-
|
|
957
|
+
const _ = x.substring(
|
|
958
|
+
V + 1
|
|
959
959
|
);
|
|
960
|
-
if (!isNaN(Number(
|
|
961
|
-
const
|
|
962
|
-
if (
|
|
963
|
-
const
|
|
960
|
+
if (!isNaN(Number(_))) {
|
|
961
|
+
const k = D.lastIndexOf(".");
|
|
962
|
+
if (k !== -1) {
|
|
963
|
+
const R = D.substring(
|
|
964
964
|
0,
|
|
965
|
-
|
|
965
|
+
k
|
|
966
966
|
);
|
|
967
|
-
if (p.paths.has(
|
|
968
|
-
|
|
967
|
+
if (p.paths.has(R)) {
|
|
968
|
+
A = !0;
|
|
969
969
|
break;
|
|
970
970
|
}
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
|
-
|
|
973
|
+
V = D.lastIndexOf(".");
|
|
974
974
|
}
|
|
975
|
-
if (
|
|
975
|
+
if (A) break;
|
|
976
976
|
}
|
|
977
|
-
if (
|
|
978
|
-
const
|
|
979
|
-
let
|
|
980
|
-
typeof
|
|
977
|
+
if (!A && C.includes("deps") && p.depsFunction) {
|
|
978
|
+
const x = p.depsFunction(a);
|
|
979
|
+
let V = !1;
|
|
980
|
+
typeof x == "boolean" ? x && (V = !0) : L(p.deps, x) || (p.deps = x, V = !0), V && (A = !0);
|
|
981
981
|
}
|
|
982
|
-
|
|
982
|
+
A && p.forceUpdate();
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
985
|
}
|
|
@@ -994,24 +994,24 @@ function ot(t, i, h, f) {
|
|
|
994
994
|
z(d.key);
|
|
995
995
|
const n = r.getState().cogsStateStore[t];
|
|
996
996
|
try {
|
|
997
|
-
const
|
|
998
|
-
|
|
997
|
+
const a = r.getState().getValidationErrors(d.key);
|
|
998
|
+
a && a.length > 0 && a.forEach(([S]) => {
|
|
999
999
|
S && S.startsWith(d.key) && z(S);
|
|
1000
1000
|
});
|
|
1001
1001
|
const c = d.zodSchema.safeParse(n);
|
|
1002
1002
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1003
|
-
const N = u.path, p = u.message,
|
|
1004
|
-
e(
|
|
1003
|
+
const N = u.path, p = u.message, A = [d.key, ...N].join(".");
|
|
1004
|
+
e(A, p);
|
|
1005
1005
|
}), ct(t), !1);
|
|
1006
|
-
} catch (
|
|
1007
|
-
return console.error("Zod schema validation failed",
|
|
1006
|
+
} catch (a) {
|
|
1007
|
+
return console.error("Zod schema validation failed", a), !1;
|
|
1008
1008
|
}
|
|
1009
1009
|
};
|
|
1010
1010
|
if (l === "_componentId") return h;
|
|
1011
1011
|
if (l === "getComponents")
|
|
1012
1012
|
return () => r().stateComponents.get(t);
|
|
1013
1013
|
if (l === "getAllFormRefs")
|
|
1014
|
-
return () =>
|
|
1014
|
+
return () => It.getState().getFormRefsByStateKey(t);
|
|
1015
1015
|
if (l === "_initialState")
|
|
1016
1016
|
return r.getState().initialStateGlobal[t];
|
|
1017
1017
|
if (l === "_serverState")
|
|
@@ -1024,16 +1024,16 @@ function ot(t, i, h, f) {
|
|
|
1024
1024
|
if (l === "removeValidation") return I.removeValidation;
|
|
1025
1025
|
}
|
|
1026
1026
|
if (l === "getFormRef")
|
|
1027
|
-
return () =>
|
|
1027
|
+
return () => It.getState().getFormRef(t + "." + o.join("."));
|
|
1028
1028
|
if (l === "validationWrapper")
|
|
1029
1029
|
return ({
|
|
1030
1030
|
children: d,
|
|
1031
1031
|
hideMessage: e
|
|
1032
|
-
}) => /* @__PURE__ */
|
|
1033
|
-
|
|
1032
|
+
}) => /* @__PURE__ */ vt(
|
|
1033
|
+
Pt,
|
|
1034
1034
|
{
|
|
1035
1035
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1036
|
-
path:
|
|
1036
|
+
path: o,
|
|
1037
1037
|
validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1038
1038
|
stateKey: t,
|
|
1039
1039
|
validIndices: g?.validIndices,
|
|
@@ -1041,51 +1041,51 @@ function ot(t, i, h, f) {
|
|
|
1041
1041
|
}
|
|
1042
1042
|
);
|
|
1043
1043
|
if (l === "_stateKey") return t;
|
|
1044
|
-
if (l === "_path") return
|
|
1044
|
+
if (l === "_path") return o;
|
|
1045
1045
|
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1046
1046
|
if (l === "update")
|
|
1047
1047
|
return (d, e) => {
|
|
1048
1048
|
if (e?.debounce)
|
|
1049
1049
|
Ct(() => {
|
|
1050
|
-
tt(i, d,
|
|
1051
|
-
const n = r.getState().getNestedState(t,
|
|
1050
|
+
tt(i, d, o, "");
|
|
1051
|
+
const n = r.getState().getNestedState(t, o);
|
|
1052
1052
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1053
1053
|
}, e.debounce);
|
|
1054
1054
|
else {
|
|
1055
|
-
tt(i, d,
|
|
1056
|
-
const n = r.getState().getNestedState(t,
|
|
1055
|
+
tt(i, d, o, "");
|
|
1056
|
+
const n = r.getState().getNestedState(t, o);
|
|
1057
1057
|
e?.afterUpdate && e.afterUpdate(n);
|
|
1058
1058
|
}
|
|
1059
|
-
|
|
1059
|
+
E(o);
|
|
1060
1060
|
};
|
|
1061
1061
|
if (l === "formElement")
|
|
1062
|
-
return (d, e) => /* @__PURE__ */
|
|
1063
|
-
|
|
1062
|
+
return (d, e) => /* @__PURE__ */ vt(
|
|
1063
|
+
_t,
|
|
1064
1064
|
{
|
|
1065
1065
|
setState: i,
|
|
1066
1066
|
stateKey: t,
|
|
1067
|
-
path:
|
|
1067
|
+
path: o,
|
|
1068
1068
|
child: d,
|
|
1069
1069
|
formOpts: e
|
|
1070
1070
|
}
|
|
1071
1071
|
);
|
|
1072
|
-
const
|
|
1073
|
-
return s(
|
|
1072
|
+
const O = [...o, l], X = r.getState().getNestedState(t, O);
|
|
1073
|
+
return s(X, O, g);
|
|
1074
1074
|
}
|
|
1075
1075
|
}, W = new Proxy(j, F);
|
|
1076
1076
|
return y.set(G, {
|
|
1077
1077
|
proxy: W,
|
|
1078
|
-
stateVersion:
|
|
1078
|
+
stateVersion: $
|
|
1079
1079
|
}), W;
|
|
1080
1080
|
}
|
|
1081
1081
|
return s(
|
|
1082
1082
|
r.getState().getNestedState(t, [])
|
|
1083
1083
|
);
|
|
1084
1084
|
}
|
|
1085
|
-
function
|
|
1086
|
-
return st(
|
|
1085
|
+
function Tt(t) {
|
|
1086
|
+
return st(Bt, { proxy: t });
|
|
1087
1087
|
}
|
|
1088
|
-
function
|
|
1088
|
+
function Lt({
|
|
1089
1089
|
proxy: t,
|
|
1090
1090
|
rebuildStateShape: i
|
|
1091
1091
|
}) {
|
|
@@ -1094,39 +1094,39 @@ function Wt({
|
|
|
1094
1094
|
h,
|
|
1095
1095
|
t._path
|
|
1096
1096
|
).stateMapNoRender(
|
|
1097
|
-
(y,
|
|
1097
|
+
(y, $, E, I, s) => t._mapFn(y, $, E, I, s)
|
|
1098
1098
|
) : null;
|
|
1099
1099
|
}
|
|
1100
|
-
function
|
|
1100
|
+
function Bt({
|
|
1101
1101
|
proxy: t
|
|
1102
1102
|
}) {
|
|
1103
|
-
const i =
|
|
1103
|
+
const i = H(null), h = `${t._stateKey}-${t._path.join(".")}`;
|
|
1104
1104
|
return ut(() => {
|
|
1105
1105
|
const f = i.current;
|
|
1106
1106
|
if (!f || !f.parentElement) return;
|
|
1107
|
-
const y = f.parentElement,
|
|
1107
|
+
const y = f.parentElement, E = Array.from(y.childNodes).indexOf(f);
|
|
1108
1108
|
let I = y.getAttribute("data-parent-id");
|
|
1109
1109
|
I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
|
|
1110
1110
|
const v = {
|
|
1111
1111
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1112
1112
|
parentId: I,
|
|
1113
|
-
position:
|
|
1113
|
+
position: E,
|
|
1114
1114
|
effect: t._effect
|
|
1115
1115
|
};
|
|
1116
1116
|
r.getState().addSignalElement(h, v);
|
|
1117
|
-
const
|
|
1117
|
+
const o = r.getState().getNestedState(t._stateKey, t._path);
|
|
1118
1118
|
let g;
|
|
1119
1119
|
if (t._effect)
|
|
1120
1120
|
try {
|
|
1121
1121
|
g = new Function(
|
|
1122
1122
|
"state",
|
|
1123
1123
|
`return (${t._effect})(state)`
|
|
1124
|
-
)(
|
|
1124
|
+
)(o);
|
|
1125
1125
|
} catch (j) {
|
|
1126
|
-
console.error("Error evaluating effect function during mount:", j), g =
|
|
1126
|
+
console.error("Error evaluating effect function during mount:", j), g = o;
|
|
1127
1127
|
}
|
|
1128
1128
|
else
|
|
1129
|
-
g =
|
|
1129
|
+
g = o;
|
|
1130
1130
|
g !== null && typeof g == "object" && (g = JSON.stringify(g));
|
|
1131
1131
|
const G = document.createTextNode(String(g));
|
|
1132
1132
|
f.replaceWith(G);
|
|
@@ -1136,8 +1136,8 @@ function Lt({
|
|
|
1136
1136
|
"data-signal-id": h
|
|
1137
1137
|
});
|
|
1138
1138
|
}
|
|
1139
|
-
function
|
|
1140
|
-
const i =
|
|
1139
|
+
function oe(t) {
|
|
1140
|
+
const i = Nt(
|
|
1141
1141
|
(h) => {
|
|
1142
1142
|
const f = r.getState().stateComponents.get(t._stateKey) || {
|
|
1143
1143
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1152,11 +1152,11 @@ function re(t) {
|
|
|
1152
1152
|
return st("text", {}, String(i));
|
|
1153
1153
|
}
|
|
1154
1154
|
export {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1155
|
+
Tt as $cogsSignal,
|
|
1156
|
+
oe as $cogsSignalStore,
|
|
1157
|
+
ee as addStateOptions,
|
|
1158
|
+
ne as createCogsState,
|
|
1159
|
+
re as notifyComponent,
|
|
1160
|
+
Wt as useCogsStateFn
|
|
1161
1161
|
};
|
|
1162
1162
|
//# sourceMappingURL=CogsState.jsx.map
|