cogsbox-state 0.5.300 → 0.5.302
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 +415 -407
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +61 -63
package/dist/CogsState.jsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as wt } from "react/jsx-runtime";
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as pt, updateFn as at, cutFunc as
|
|
6
|
-
import
|
|
3
|
+
import { useState as et, useRef as J, useEffect as st, useLayoutEffect as gt, useMemo as Tt, createElement as it, useSyncExternalStore as Ot, startTransition as Rt, useCallback as It } from "react";
|
|
4
|
+
import { transformStateFunc as Ft, isDeepEqual as B, isFunction as X, getNestedValue as q, getDifferences as Et, debounce as Ut } from "./utility.js";
|
|
5
|
+
import { pushFunc as pt, updateFn as at, cutFunc as ut, ValidationWrapper as Dt, FormControlComponent as Wt } from "./Functions.jsx";
|
|
6
|
+
import Gt from "superjson";
|
|
7
7
|
import { v4 as At } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
9
|
import { getGlobalStore as o, formRefStore as kt } from "./store.js";
|
|
10
10
|
import { useCogsConfig as xt } from "./CogsStateClient.jsx";
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
11
|
+
import { applyPatch as Lt } from "fast-json-patch";
|
|
12
|
+
import Ht from "react-use-measure";
|
|
13
13
|
function bt(t, c) {
|
|
14
|
-
const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions,
|
|
14
|
+
const m = o.getState().getInitialOptions, f = o.getState().setInitialStateOptions, y = m(t) || {};
|
|
15
15
|
f(t, {
|
|
16
|
-
...
|
|
16
|
+
...y,
|
|
17
17
|
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -22,42 +22,42 @@ function Vt({
|
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const f =
|
|
25
|
+
const f = rt(t) || {}, y = m[t] || {}, k = o.getState().setInitialStateOptions, p = { ...y, ...f };
|
|
26
26
|
let I = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const a in c)
|
|
29
29
|
p.hasOwnProperty(a) ? (a == "localStorage" && c[a] && p[a].key !== c[a]?.key && (I = !0, p[a] = c[a]), a == "initialState" && c[a] && p[a] !== c[a] && // Different references
|
|
30
30
|
!B(p[a], c[a]) && (I = !0, p[a] = c[a])) : (I = !0, p[a] = c[a]);
|
|
31
|
-
I &&
|
|
31
|
+
I && k(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ge(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const fe = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [f,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
38
|
+
const [f, y] = Ft(m);
|
|
39
|
+
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
|
|
40
|
+
y[I] = y[I] || {}, y[I].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...c?.validation,
|
|
44
|
-
...
|
|
44
|
+
...y[I].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
46
|
+
}, rt(I) || o.getState().setInitialStateOptions(I, y[I]);
|
|
47
47
|
}), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
|
|
48
|
-
const
|
|
49
|
-
const [
|
|
48
|
+
const k = (I, a) => {
|
|
49
|
+
const [v] = et(a?.componentId ?? At());
|
|
50
50
|
Vt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
|
-
initialOptionsPart:
|
|
53
|
+
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [
|
|
55
|
+
const n = o.getState().cogsStateStore[I] || f[I], S = a?.modifyState ? a.modifyState(n) : n, [G, O] = Xt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: v,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
62
62
|
middleware: a?.middleware,
|
|
63
63
|
enabledSync: a?.enabledSync,
|
|
@@ -71,46 +71,46 @@ const Se = (t, c) => {
|
|
|
71
71
|
return O;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
|
-
Vt({ stateKey: I, options: a, initialOptionsPart:
|
|
74
|
+
Vt({ stateKey: I, options: a, initialOptionsPart: y }), a.localStorage && Yt(I, a), ht(I);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: k, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
78
|
+
setUpdaterState: ft,
|
|
79
|
+
setState: nt,
|
|
80
|
+
getInitialOptions: rt,
|
|
81
81
|
getKeyState: Pt,
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
82
|
+
getValidationErrors: zt,
|
|
83
|
+
setStateLog: Bt,
|
|
84
84
|
updateInitialStateGlobal: $t,
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(), Nt = (t, c, m, f,
|
|
85
|
+
addValidationError: qt,
|
|
86
|
+
removeValidationError: Z,
|
|
87
|
+
setServerSyncActions: Jt
|
|
88
|
+
} = o.getState(), Nt = (t, c, m, f, y) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
c,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
f
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const p = `${f}-${c}-${
|
|
95
|
+
const k = X(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
|
+
if (k && f) {
|
|
97
|
+
const p = `${f}-${c}-${k}`;
|
|
98
98
|
let I;
|
|
99
99
|
try {
|
|
100
|
-
I =
|
|
100
|
+
I = mt(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: y ?? I
|
|
107
|
+
}, v = Gt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
|
-
JSON.stringify(
|
|
110
|
+
JSON.stringify(v.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, mt = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
116
|
const c = window.localStorage.getItem(t);
|
|
@@ -118,29 +118,29 @@ const Se = (t, c) => {
|
|
|
118
118
|
} catch (c) {
|
|
119
119
|
return console.error("Error loading from localStorage:", c), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m = o.getState().cogsStateStore[t], { sessionId: f } = xt(),
|
|
123
|
-
if (
|
|
124
|
-
const
|
|
125
|
-
`${f}-${t}-${
|
|
121
|
+
}, Yt = (t, c) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: f } = xt(), y = X(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
|
+
if (y && f) {
|
|
124
|
+
const k = mt(
|
|
125
|
+
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if (k && k.lastUpdated > (k.lastSyncedWithServer || 0))
|
|
128
|
+
return nt(t, k.state), ht(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
}, _t = (t, c, m, f,
|
|
131
|
+
}, _t = (t, c, m, f, y, k) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: c,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: St(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
y,
|
|
138
|
+
k
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
$t(t, p.initialState),
|
|
143
|
-
},
|
|
142
|
+
$t(t, p.initialState), ft(t, p.updaterState), nt(t, p.state);
|
|
143
|
+
}, ht = (t) => {
|
|
144
144
|
const c = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!c) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -149,15 +149,15 @@ const Se = (t, c) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((f) => f());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, Se = (t, c) => {
|
|
153
153
|
const m = o.getState().stateComponents.get(t);
|
|
154
154
|
if (m) {
|
|
155
|
-
const f = `${t}////${c}`,
|
|
156
|
-
if ((
|
|
155
|
+
const f = `${t}////${c}`, y = m.components.get(f);
|
|
156
|
+
if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
|
-
|
|
158
|
+
y && y.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Zt = (t, c, m, f) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
@@ -180,37 +180,37 @@ const Se = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Xt(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: f,
|
|
187
|
-
formElements:
|
|
188
|
-
reactiveDeps:
|
|
187
|
+
formElements: y,
|
|
188
|
+
reactiveDeps: k,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: I,
|
|
191
191
|
initialState: a,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: v,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [h] =
|
|
196
|
+
const [G, O] = et({}), { sessionId: R } = xt();
|
|
197
|
+
let L = !c;
|
|
198
|
+
const [h] = et(c ?? At()), l = o.getState().stateLog[h], ct = J(/* @__PURE__ */ new Set()), Q = J(I ?? At()), M = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
M.current =
|
|
202
|
-
if (
|
|
203
|
-
|
|
201
|
+
M.current = rt(h) ?? null, st(() => {
|
|
202
|
+
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
+
nt(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
|
-
[
|
|
205
|
+
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
207
|
-
const e = `${
|
|
207
|
+
const e = `${v.stateKey}:${v.path.join(".")}`;
|
|
208
208
|
o.getState().setSyncInfo(e, {
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
209
|
+
timeStamp: v.timeStamp,
|
|
210
|
+
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [v]), st(() => {
|
|
214
214
|
if (a) {
|
|
215
215
|
bt(h, {
|
|
216
216
|
initialState: a
|
|
@@ -219,273 +219,273 @@ function Zt(t, {
|
|
|
219
219
|
if (!(i && !B(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
222
|
+
const T = X(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
T && R && (u = mt(`${R}-${h}-${T}`));
|
|
224
|
+
let w = a, $ = !1;
|
|
225
|
+
const P = s ? Date.now() : 0, C = u?.lastUpdated || 0, _ = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && P > C ? (w = e.serverState.data, $ = !0) : u && C > _ && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), _t(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
w,
|
|
230
|
+
ot,
|
|
231
|
+
Q.current,
|
|
232
232
|
R
|
|
233
|
-
),
|
|
233
|
+
), $ && T && R && Nt(w, h, e, R, Date.now()), ht(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || O({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
240
|
+
]), gt(() => {
|
|
241
|
+
L && bt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
|
-
formElements:
|
|
243
|
+
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: f,
|
|
246
246
|
middleware: M.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${h}////${
|
|
248
|
+
const e = `${h}////${Q.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
252
|
forceUpdate: () => O({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: k || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
257
|
}), o.getState().stateComponents.set(h, r), O({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const ot = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
263
|
const u = `${h}-${r.join(".")}`;
|
|
264
264
|
ct.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const g = o.getState();
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
267
|
+
nt(h, (u) => {
|
|
268
|
+
const T = X(e) ? e(u) : e, w = `${h}-${r.join(".")}`;
|
|
269
|
+
if (w) {
|
|
270
|
+
let b = !1, V = g.signalDomElements.get(w);
|
|
271
|
+
if ((!V || V.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const x = r.slice(0, -1), D = q(T, x);
|
|
273
|
+
if (Array.isArray(D)) {
|
|
274
|
+
b = !0;
|
|
275
|
+
const A = `${h}-${x.join(".")}`;
|
|
276
|
+
V = g.signalDomElements.get(A);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (V) {
|
|
280
|
+
const x = b ? q(T, r.slice(0, -1)) : q(T, r);
|
|
281
|
+
V.forEach(({ parentId: D, position: A, effect: F }) => {
|
|
282
|
+
const j = document.querySelector(
|
|
283
|
+
`[data-parent-id="${D}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (j) {
|
|
286
|
+
const E = Array.from(j.childNodes);
|
|
287
|
+
if (E[A]) {
|
|
288
|
+
const N = F ? new Function("state", `return (${F})(state)`)(x) : x;
|
|
289
|
+
E[A].textContent = String(N);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r &&
|
|
295
|
+
console.log("shadowState", g.shadowStateStore), s.updateType === "update" && (i || M.current?.validation?.key) && r && Z(
|
|
296
296
|
(i || M.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" && M.current?.validation?.key &&
|
|
300
|
-
M.current?.validation?.key + "." +
|
|
301
|
-
), s.updateType === "insert" && M.current?.validation?.key &&
|
|
302
|
-
M.current?.validation?.key + "." +
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
|
|
298
|
+
const $ = r.slice(0, r.length - 1);
|
|
299
|
+
s.updateType === "cut" && M.current?.validation?.key && Z(
|
|
300
|
+
M.current?.validation?.key + "." + $.join(".")
|
|
301
|
+
), s.updateType === "insert" && M.current?.validation?.key && zt(
|
|
302
|
+
M.current?.validation?.key + "." + $.join(".")
|
|
303
|
+
).filter(([V, x]) => {
|
|
304
|
+
let D = V?.split(".").length;
|
|
305
|
+
if (V == $.join(".") && D == $.length - 1) {
|
|
306
|
+
let A = V + "." + $;
|
|
307
|
+
Z(V), qt(A, x);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const P = g.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", P), P) {
|
|
312
|
+
const b = Et(u, T), V = new Set(b), x = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
] of
|
|
314
|
+
D,
|
|
315
|
+
A
|
|
316
|
+
] of P.components.entries()) {
|
|
317
317
|
let F = !1;
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
318
|
+
const j = Array.isArray(A.reactiveType) ? A.reactiveType : [A.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", A), !j.includes("none")) {
|
|
320
|
+
if (j.includes("all")) {
|
|
321
|
+
A.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (j.includes("component") && ((A.paths.has(x) || A.paths.has("")) && (F = !0), !F))
|
|
325
|
+
for (const E of V) {
|
|
326
|
+
let N = E;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
328
|
+
if (A.paths.has(N)) {
|
|
329
329
|
F = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const z = N.lastIndexOf(".");
|
|
333
|
+
if (z !== -1) {
|
|
334
|
+
const W = N.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
z
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
339
|
+
Number(N.substring(z + 1))
|
|
340
|
+
) && A.paths.has(W)) {
|
|
341
341
|
F = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
N = W;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
N = "";
|
|
347
|
+
if (N === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
350
|
if (F) break;
|
|
351
351
|
}
|
|
352
|
-
if (!F &&
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!F && j.includes("deps") && A.depsFunction) {
|
|
353
|
+
const E = A.depsFunction(T);
|
|
354
|
+
let N = !1;
|
|
355
|
+
typeof E == "boolean" ? E && (N = !0) : B(A.deps, E) || (A.deps = E, N = !0), N && (F = !0);
|
|
356
356
|
}
|
|
357
|
-
F &&
|
|
357
|
+
F && A.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const C = Date.now();
|
|
362
|
+
r = r.map((b, V) => {
|
|
363
|
+
const x = r.slice(0, -1), D = q(T, x);
|
|
364
|
+
return V === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : b;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: _, newValue: U } = Zt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
|
-
|
|
369
|
+
T,
|
|
370
370
|
r
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), H = {
|
|
372
|
+
timeStamp: C,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: _,
|
|
378
|
+
newValue: U
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
g.updateShadowAtPath(h, r,
|
|
382
|
+
g.updateShadowAtPath(h, r, T);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
g.insertShadowArrayElement(h,
|
|
385
|
+
const b = r.slice(0, -1);
|
|
386
|
+
g.insertShadowArrayElement(h, b, U);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
g.removeShadowArrayElement(h,
|
|
389
|
+
const V = r.slice(0, -1), x = parseInt(r[r.length - 1]);
|
|
390
|
+
g.removeShadowArrayElement(h, V, x);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const F = `${
|
|
396
|
-
return
|
|
393
|
+
if (Bt(h, (b) => {
|
|
394
|
+
const x = [...b ?? [], H].reduce((D, A) => {
|
|
395
|
+
const F = `${A.stateKey}:${JSON.stringify(A.path)}`, j = D.get(F);
|
|
396
|
+
return j ? (j.timeStamp = Math.max(j.timeStamp, A.timeStamp), j.newValue = A.newValue, j.oldValue = j.oldValue ?? A.oldValue, j.updateType = A.updateType) : D.set(F, { ...A }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
398
|
+
return Array.from(x.values());
|
|
399
399
|
}), Nt(
|
|
400
|
-
|
|
400
|
+
T,
|
|
401
401
|
h,
|
|
402
402
|
M.current,
|
|
403
403
|
R
|
|
404
404
|
), M.current?.middleware && M.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
406
|
+
update: H
|
|
407
407
|
}), M.current?.serverSync) {
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
408
|
+
const b = g.serverState[h], V = M.current?.serverSync;
|
|
409
|
+
Jt(h, {
|
|
410
|
+
syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: T }),
|
|
411
|
+
rollBackState: b,
|
|
412
|
+
actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return T;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[h] || (
|
|
419
|
+
o.getState().updaterState[h] || (ft(
|
|
420
420
|
h,
|
|
421
|
-
|
|
421
|
+
St(
|
|
422
422
|
h,
|
|
423
|
-
|
|
424
|
-
|
|
423
|
+
ot,
|
|
424
|
+
Q.current,
|
|
425
425
|
R
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] ||
|
|
428
|
-
const d = Tt(() =>
|
|
427
|
+
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || $t(h, t));
|
|
428
|
+
const d = Tt(() => St(
|
|
429
429
|
h,
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
ot,
|
|
431
|
+
Q.current,
|
|
432
432
|
R
|
|
433
433
|
), [h, R]);
|
|
434
434
|
return [Pt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
437
|
-
const
|
|
438
|
-
let
|
|
439
|
-
const p = (
|
|
440
|
-
const n =
|
|
441
|
-
for (const [S] of
|
|
442
|
-
(S === n || S.startsWith(n + ".")) &&
|
|
443
|
-
|
|
436
|
+
function St(t, c, m, f) {
|
|
437
|
+
const y = /* @__PURE__ */ new Map();
|
|
438
|
+
let k = 0;
|
|
439
|
+
const p = (v) => {
|
|
440
|
+
const n = v.join(".");
|
|
441
|
+
for (const [S] of y)
|
|
442
|
+
(S === n || S.startsWith(n + ".")) && y.delete(S);
|
|
443
|
+
k++;
|
|
444
444
|
}, I = {
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
445
|
+
removeValidation: (v) => {
|
|
446
|
+
v?.validationKey && Z(v.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
448
|
+
revertToInitialState: (v) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Z(n?.key), v?.validationKey && Z(v.validationKey);
|
|
451
451
|
const S = o.getState().initialStateGlobal[t];
|
|
452
|
-
o.getState().clearSelectedIndexesForState(t),
|
|
453
|
-
const
|
|
454
|
-
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), y.clear(), k++;
|
|
453
|
+
const G = a(S, []), O = rt(t), R = X(O?.localStorage?.key) ? O?.localStorage?.key(S) : O?.localStorage?.key, L = `${f}-${t}-${R}`;
|
|
454
|
+
L && localStorage.removeItem(L), ft(t, G), nt(t, S);
|
|
455
455
|
const h = o.getState().stateComponents.get(t);
|
|
456
456
|
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
462
|
-
const n =
|
|
460
|
+
updateInitialState: (v) => {
|
|
461
|
+
y.clear(), k++;
|
|
462
|
+
const n = St(
|
|
463
463
|
t,
|
|
464
464
|
c,
|
|
465
465
|
m,
|
|
466
466
|
f
|
|
467
|
-
), S = o.getState().initialStateGlobal[t],
|
|
468
|
-
return localStorage.getItem(R) && localStorage.removeItem(R),
|
|
469
|
-
$t(t,
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], G = rt(t), O = X(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, R = `${f}-${t}-${O}`;
|
|
468
|
+
return localStorage.getItem(R) && localStorage.removeItem(R), Rt(() => {
|
|
469
|
+
$t(t, v), o.getState().initializeShadowState(t, v), ft(t, n), nt(t, v);
|
|
470
|
+
const L = o.getState().stateComponents.get(t);
|
|
471
|
+
L && L.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (L) => n.get()[L]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
479
479
|
_serverState: o.getState().serverState[t],
|
|
480
480
|
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const v = o.getState().serverState[t];
|
|
483
|
+
return !!(v && B(v, Pt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function a(
|
|
487
|
-
const
|
|
488
|
-
|
|
486
|
+
function a(v, n = [], S) {
|
|
487
|
+
const G = n.map(String).join(".");
|
|
488
|
+
y.get(G);
|
|
489
489
|
const O = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
@@ -499,7 +499,7 @@ function ft(t, c, m, f) {
|
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
|
-
S?.validIndices && !Array.isArray(
|
|
502
|
+
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
503
|
const ct = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
@@ -554,8 +554,8 @@ function ft(t, c, m, f) {
|
|
|
554
554
|
const i = await e.action(r);
|
|
555
555
|
if (i && !i.success && i.errors && s) {
|
|
556
556
|
o.getState().removeValidationError(s), i.errors.forEach((u) => {
|
|
557
|
-
const
|
|
558
|
-
o.getState().addValidationError(
|
|
557
|
+
const T = [s, ...u.path].join(".");
|
|
558
|
+
o.getState().addValidationError(T, u.message);
|
|
559
559
|
});
|
|
560
560
|
const g = o.getState().stateComponents.get(t);
|
|
561
561
|
g && g.components.forEach((u) => {
|
|
@@ -581,7 +581,7 @@ function ft(t, c, m, f) {
|
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = o.getState().initialStateGlobal[t], e =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = rt(t), r = X(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${f}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -591,8 +591,8 @@ function ft(t, c, m, f) {
|
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
592
|
return o.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => S?.validIndices ?
|
|
594
|
+
if (Array.isArray(v)) {
|
|
595
|
+
const d = () => S?.validIndices ? v.map((r, s) => ({
|
|
596
596
|
item: r,
|
|
597
597
|
originalIndex: S.validIndices[s]
|
|
598
598
|
})) : o.getState().getNestedState(t, n).map((r, s) => ({
|
|
@@ -604,7 +604,7 @@ function ft(t, c, m, f) {
|
|
|
604
604
|
const e = o.getState().getSelectedIndex(t, n.join("."));
|
|
605
605
|
if (e !== void 0)
|
|
606
606
|
return a(
|
|
607
|
-
|
|
607
|
+
v[e],
|
|
608
608
|
[...n, e.toString()],
|
|
609
609
|
S
|
|
610
610
|
);
|
|
@@ -619,112 +619,120 @@ function ft(t, c, m, f) {
|
|
|
619
619
|
return (e) => {
|
|
620
620
|
const {
|
|
621
621
|
itemHeight: r = 50,
|
|
622
|
-
// Default/estimated height
|
|
623
622
|
overscan: s = 5,
|
|
624
623
|
stickToBottom: i = !1
|
|
625
|
-
} = e, g = J(null), [u,
|
|
624
|
+
} = e, g = J(null), [u, T] = et({
|
|
626
625
|
startIndex: 0,
|
|
627
626
|
endIndex: 10
|
|
628
|
-
}), [
|
|
629
|
-
() =>
|
|
627
|
+
}), [w, $] = et(0), P = It(
|
|
628
|
+
() => $((E) => E + 1),
|
|
630
629
|
[]
|
|
631
|
-
);
|
|
630
|
+
), C = J(i), _ = J(0), U = J(!0);
|
|
632
631
|
st(() => {
|
|
633
|
-
const
|
|
632
|
+
const E = o.getState().subscribeToShadowState(t, P), N = setTimeout(P, 50);
|
|
634
633
|
return () => {
|
|
635
|
-
|
|
634
|
+
E(), clearTimeout(N);
|
|
636
635
|
};
|
|
637
|
-
}, [t,
|
|
638
|
-
const
|
|
636
|
+
}, [t, P]);
|
|
637
|
+
const H = o().getNestedState(
|
|
639
638
|
t,
|
|
640
639
|
n
|
|
641
|
-
),
|
|
642
|
-
const
|
|
643
|
-
let
|
|
644
|
-
const
|
|
645
|
-
for (let
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
640
|
+
), b = H.length, { totalHeight: V, positions: x } = Tt(() => {
|
|
641
|
+
const E = o.getState().getShadowMetadata(t, n) || [];
|
|
642
|
+
let N = 0;
|
|
643
|
+
const z = [];
|
|
644
|
+
for (let W = 0; W < b; W++) {
|
|
645
|
+
z[W] = N;
|
|
646
|
+
const Y = E[W]?.virtualizer?.itemHeight;
|
|
647
|
+
N += Y || r;
|
|
649
648
|
}
|
|
650
|
-
return { totalHeight:
|
|
651
|
-
}, [
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
649
|
+
return { totalHeight: N, positions: z };
|
|
650
|
+
}, [b, t, n, r, w]), D = Tt(() => {
|
|
651
|
+
const E = Math.max(0, u.startIndex), N = Math.min(b, u.endIndex), z = Array.from(
|
|
652
|
+
{ length: N - E },
|
|
653
|
+
(Y, lt) => E + lt
|
|
654
|
+
), W = z.map((Y) => H[Y]);
|
|
655
|
+
return a(W, n, {
|
|
657
656
|
...S,
|
|
658
|
-
validIndices:
|
|
657
|
+
validIndices: z
|
|
659
658
|
});
|
|
660
|
-
}, [u.startIndex, u.endIndex,
|
|
661
|
-
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
const
|
|
667
|
-
const { scrollTop:
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
659
|
+
}, [u.startIndex, u.endIndex, H, b]);
|
|
660
|
+
gt(() => {
|
|
661
|
+
const E = g.current;
|
|
662
|
+
if (!E) return;
|
|
663
|
+
const N = C.current, z = b > _.current;
|
|
664
|
+
_.current = b;
|
|
665
|
+
const W = () => {
|
|
666
|
+
const { scrollTop: Y, clientHeight: lt, scrollHeight: Mt } = E;
|
|
667
|
+
C.current = Mt - Y - lt < 10;
|
|
668
|
+
let vt = 0, dt = b - 1;
|
|
669
|
+
for (; vt <= dt; ) {
|
|
670
|
+
const tt = Math.floor((vt + dt) / 2);
|
|
671
|
+
x[tt] < Y ? vt = tt + 1 : dt = tt - 1;
|
|
672
|
+
}
|
|
673
|
+
const yt = Math.max(0, dt - s);
|
|
674
|
+
let K = yt;
|
|
675
|
+
const jt = Y + lt;
|
|
676
|
+
for (; K < b && x[K] < jt; )
|
|
677
|
+
K++;
|
|
678
|
+
K = Math.min(b, K + s), T((tt) => tt.startIndex !== yt || tt.endIndex !== K ? { startIndex: yt, endIndex: K } : tt);
|
|
679
679
|
};
|
|
680
|
-
return
|
|
680
|
+
return E.addEventListener("scroll", W, {
|
|
681
681
|
passive: !0
|
|
682
|
-
}),
|
|
683
|
-
top:
|
|
682
|
+
}), i && (U.current ? E.scrollTo({
|
|
683
|
+
top: E.scrollHeight,
|
|
684
684
|
behavior: "auto"
|
|
685
|
-
})
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
685
|
+
}) : N && z && requestAnimationFrame(() => {
|
|
686
|
+
E.scrollTo({
|
|
687
|
+
top: E.scrollHeight,
|
|
688
|
+
behavior: "smooth"
|
|
689
|
+
});
|
|
690
|
+
})), U.current = !1, W(), () => E.removeEventListener("scroll", W);
|
|
691
|
+
}, [b, x, s, i]);
|
|
692
|
+
const A = It(
|
|
693
|
+
(E = "smooth") => {
|
|
689
694
|
g.current && g.current.scrollTo({
|
|
690
695
|
top: g.current.scrollHeight,
|
|
691
|
-
behavior:
|
|
696
|
+
behavior: E
|
|
692
697
|
});
|
|
693
698
|
},
|
|
694
699
|
[]
|
|
695
|
-
),
|
|
696
|
-
(
|
|
697
|
-
g.current && g.current.scrollTo({
|
|
698
|
-
top:
|
|
699
|
-
behavior:
|
|
700
|
+
), F = It(
|
|
701
|
+
(E, N = "smooth") => {
|
|
702
|
+
g.current && x[E] !== void 0 && g.current.scrollTo({
|
|
703
|
+
top: x[E],
|
|
704
|
+
behavior: N
|
|
700
705
|
});
|
|
701
706
|
},
|
|
702
|
-
[
|
|
703
|
-
),
|
|
707
|
+
[x]
|
|
708
|
+
), j = {
|
|
704
709
|
outer: {
|
|
705
710
|
ref: g,
|
|
706
711
|
style: { overflowY: "auto", height: "100%" }
|
|
707
712
|
},
|
|
708
713
|
inner: {
|
|
709
|
-
style: {
|
|
714
|
+
style: {
|
|
715
|
+
height: `${V}px`,
|
|
716
|
+
position: "relative"
|
|
717
|
+
}
|
|
710
718
|
},
|
|
711
719
|
list: {
|
|
712
720
|
style: {
|
|
713
|
-
transform: `translateY(${
|
|
721
|
+
transform: `translateY(${x[u.startIndex] || 0}px)`
|
|
714
722
|
}
|
|
715
723
|
}
|
|
716
724
|
};
|
|
717
725
|
return {
|
|
718
|
-
virtualState:
|
|
719
|
-
virtualizerProps:
|
|
720
|
-
scrollToBottom:
|
|
721
|
-
scrollToIndex:
|
|
726
|
+
virtualState: D,
|
|
727
|
+
virtualizerProps: j,
|
|
728
|
+
scrollToBottom: A,
|
|
729
|
+
scrollToIndex: F
|
|
722
730
|
};
|
|
723
731
|
};
|
|
724
732
|
if (l === "stateSort")
|
|
725
733
|
return (e) => {
|
|
726
734
|
const s = [...d()].sort(
|
|
727
|
-
(u,
|
|
735
|
+
(u, T) => e(u.item, T.item)
|
|
728
736
|
), i = s.map(({ item: u }) => u), g = {
|
|
729
737
|
...S,
|
|
730
738
|
validIndices: s.map(
|
|
@@ -736,7 +744,7 @@ function ft(t, c, m, f) {
|
|
|
736
744
|
if (l === "stateFilter")
|
|
737
745
|
return (e) => {
|
|
738
746
|
const s = d().filter(
|
|
739
|
-
({ item: u },
|
|
747
|
+
({ item: u }, T) => e(u, T)
|
|
740
748
|
), i = s.map(({ item: u }) => u), g = {
|
|
741
749
|
...S,
|
|
742
750
|
validIndices: s.map(
|
|
@@ -749,22 +757,22 @@ function ft(t, c, m, f) {
|
|
|
749
757
|
return (e) => {
|
|
750
758
|
const r = o.getState().getNestedState(t, n);
|
|
751
759
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
752
|
-
const u = r[i],
|
|
753
|
-
return e(u,
|
|
760
|
+
const u = r[i], T = [...n, i.toString()], w = a(u, T, S);
|
|
761
|
+
return e(u, w, {
|
|
754
762
|
register: () => {
|
|
755
|
-
const [,
|
|
756
|
-
|
|
757
|
-
const
|
|
763
|
+
const [, P] = et({}), C = `${m}-${n.join(".")}-${i}`;
|
|
764
|
+
gt(() => {
|
|
765
|
+
const _ = `${t}////${C}`, U = o.getState().stateComponents.get(t) || {
|
|
758
766
|
components: /* @__PURE__ */ new Map()
|
|
759
767
|
};
|
|
760
|
-
return
|
|
761
|
-
forceUpdate: () =>
|
|
762
|
-
paths: /* @__PURE__ */ new Set([
|
|
763
|
-
}), o.getState().stateComponents.set(t,
|
|
764
|
-
const
|
|
765
|
-
|
|
768
|
+
return U.components.set(_, {
|
|
769
|
+
forceUpdate: () => P({}),
|
|
770
|
+
paths: /* @__PURE__ */ new Set([T.join(".")])
|
|
771
|
+
}), o.getState().stateComponents.set(t, U), () => {
|
|
772
|
+
const H = o.getState().stateComponents.get(t);
|
|
773
|
+
H && H.components.delete(_);
|
|
766
774
|
};
|
|
767
|
-
}, [t,
|
|
775
|
+
}, [t, C]);
|
|
768
776
|
},
|
|
769
777
|
index: g,
|
|
770
778
|
originalIndex: i
|
|
@@ -775,20 +783,20 @@ function ft(t, c, m, f) {
|
|
|
775
783
|
), null);
|
|
776
784
|
};
|
|
777
785
|
if (l === "stateMapNoRender")
|
|
778
|
-
return (e) =>
|
|
786
|
+
return (e) => v.map((s, i) => {
|
|
779
787
|
let g;
|
|
780
788
|
S?.validIndices && S.validIndices[i] !== void 0 ? g = S.validIndices[i] : g = i;
|
|
781
|
-
const u = [...n, g.toString()],
|
|
789
|
+
const u = [...n, g.toString()], T = a(s, u, S);
|
|
782
790
|
return e(
|
|
783
791
|
s,
|
|
784
|
-
|
|
792
|
+
T,
|
|
785
793
|
i,
|
|
786
|
-
|
|
787
|
-
a(
|
|
794
|
+
v,
|
|
795
|
+
a(v, n, S)
|
|
788
796
|
);
|
|
789
797
|
});
|
|
790
798
|
if (l === "$stateMap")
|
|
791
|
-
return (e) => it(
|
|
799
|
+
return (e) => it(Qt, {
|
|
792
800
|
proxy: {
|
|
793
801
|
_stateKey: t,
|
|
794
802
|
_path: n,
|
|
@@ -801,15 +809,15 @@ function ft(t, c, m, f) {
|
|
|
801
809
|
return (e) => {
|
|
802
810
|
const r = o.getState().getNestedState(t, n);
|
|
803
811
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, g) => g)).map((i, g) => {
|
|
804
|
-
const u = r[i],
|
|
805
|
-
return it(
|
|
812
|
+
const u = r[i], T = [...n, i.toString()], w = a(u, T, S), $ = `${m}-${n.join(".")}-${i}`;
|
|
813
|
+
return it(te, {
|
|
806
814
|
key: i,
|
|
807
815
|
stateKey: t,
|
|
808
|
-
itemComponentId:
|
|
809
|
-
itemPath:
|
|
816
|
+
itemComponentId: $,
|
|
817
|
+
itemPath: T,
|
|
810
818
|
children: e(
|
|
811
819
|
u,
|
|
812
|
-
|
|
820
|
+
w,
|
|
813
821
|
g,
|
|
814
822
|
r,
|
|
815
823
|
a(r, n, S)
|
|
@@ -821,8 +829,8 @@ function ft(t, c, m, f) {
|
|
|
821
829
|
};
|
|
822
830
|
if (l === "stateFlattenOn")
|
|
823
831
|
return (e) => {
|
|
824
|
-
const r =
|
|
825
|
-
|
|
832
|
+
const r = v;
|
|
833
|
+
y.clear(), k++;
|
|
826
834
|
const s = r.flatMap(
|
|
827
835
|
(i) => i[e] ?? []
|
|
828
836
|
);
|
|
@@ -834,7 +842,7 @@ function ft(t, c, m, f) {
|
|
|
834
842
|
};
|
|
835
843
|
if (l === "index")
|
|
836
844
|
return (e) => {
|
|
837
|
-
const r =
|
|
845
|
+
const r = v[e];
|
|
838
846
|
return a(r, [...n, e.toString()]);
|
|
839
847
|
};
|
|
840
848
|
if (l === "last")
|
|
@@ -851,43 +859,43 @@ function ft(t, c, m, f) {
|
|
|
851
859
|
));
|
|
852
860
|
if (l === "uniqueInsert")
|
|
853
861
|
return (e, r, s) => {
|
|
854
|
-
const i = o.getState().getNestedState(t, n), g =
|
|
862
|
+
const i = o.getState().getNestedState(t, n), g = X(e) ? e(i) : e;
|
|
855
863
|
let u = null;
|
|
856
|
-
if (!i.some((
|
|
864
|
+
if (!i.some((w) => {
|
|
857
865
|
if (r) {
|
|
858
|
-
const
|
|
859
|
-
(
|
|
866
|
+
const P = r.every(
|
|
867
|
+
(C) => B(w[C], g[C])
|
|
860
868
|
);
|
|
861
|
-
return
|
|
869
|
+
return P && (u = w), P;
|
|
862
870
|
}
|
|
863
|
-
const
|
|
864
|
-
return
|
|
871
|
+
const $ = B(w, g);
|
|
872
|
+
return $ && (u = w), $;
|
|
865
873
|
}))
|
|
866
874
|
p(n), pt(c, g, n, t);
|
|
867
875
|
else if (s && u) {
|
|
868
|
-
const
|
|
869
|
-
(
|
|
876
|
+
const w = s(u), $ = i.map(
|
|
877
|
+
(P) => B(P, u) ? w : P
|
|
870
878
|
);
|
|
871
|
-
p(n), at(c,
|
|
879
|
+
p(n), at(c, $, n);
|
|
872
880
|
}
|
|
873
881
|
};
|
|
874
882
|
if (l === "cut")
|
|
875
883
|
return (e, r) => {
|
|
876
884
|
if (!r?.waitForSync)
|
|
877
|
-
return p(n),
|
|
885
|
+
return p(n), ut(c, n, t, e), a(
|
|
878
886
|
o.getState().getNestedState(t, n),
|
|
879
887
|
n
|
|
880
888
|
);
|
|
881
889
|
};
|
|
882
890
|
if (l === "cutByValue")
|
|
883
891
|
return (e) => {
|
|
884
|
-
for (let r = 0; r <
|
|
885
|
-
|
|
892
|
+
for (let r = 0; r < v.length; r++)
|
|
893
|
+
v[r] === e && ut(c, n, t, r);
|
|
886
894
|
};
|
|
887
895
|
if (l === "toggleByValue")
|
|
888
896
|
return (e) => {
|
|
889
|
-
const r =
|
|
890
|
-
r > -1 ?
|
|
897
|
+
const r = v.findIndex((s) => s === e);
|
|
898
|
+
r > -1 ? ut(c, n, t, r) : pt(c, e, n, t);
|
|
891
899
|
};
|
|
892
900
|
if (l === "stateFind")
|
|
893
901
|
return (e) => {
|
|
@@ -908,20 +916,20 @@ function ft(t, c, m, f) {
|
|
|
908
916
|
return a(i.item, g, S);
|
|
909
917
|
};
|
|
910
918
|
}
|
|
911
|
-
const
|
|
912
|
-
if (!isNaN(Number(
|
|
919
|
+
const Q = n[n.length - 1];
|
|
920
|
+
if (!isNaN(Number(Q))) {
|
|
913
921
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
914
922
|
if (Array.isArray(e) && l === "cut")
|
|
915
|
-
return () =>
|
|
923
|
+
return () => ut(
|
|
916
924
|
c,
|
|
917
925
|
d,
|
|
918
926
|
t,
|
|
919
|
-
Number(
|
|
927
|
+
Number(Q)
|
|
920
928
|
);
|
|
921
929
|
}
|
|
922
930
|
if (l === "get")
|
|
923
931
|
return () => {
|
|
924
|
-
if (S?.validIndices && Array.isArray(
|
|
932
|
+
if (S?.validIndices && Array.isArray(v)) {
|
|
925
933
|
const d = o.getState().getNestedState(t, n);
|
|
926
934
|
return S.validIndices.map((e) => d[e]);
|
|
927
935
|
}
|
|
@@ -943,7 +951,7 @@ function ft(t, c, m, f) {
|
|
|
943
951
|
return o.getState().getSyncInfo(d);
|
|
944
952
|
}
|
|
945
953
|
if (l == "getLocalStorage")
|
|
946
|
-
return (d) =>
|
|
954
|
+
return (d) => mt(f + "-" + t + "-" + d);
|
|
947
955
|
if (l === "_selected") {
|
|
948
956
|
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
949
957
|
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -969,7 +977,7 @@ function ft(t, c, m, f) {
|
|
|
969
977
|
if (n.length == 0) {
|
|
970
978
|
if (l === "applyJsonPatch")
|
|
971
979
|
return (d) => {
|
|
972
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
980
|
+
const e = o.getState().cogsStateStore[t], s = Lt(e, d).newDocument;
|
|
973
981
|
_t(
|
|
974
982
|
t,
|
|
975
983
|
o.getState().initialStateGlobal[t],
|
|
@@ -982,55 +990,55 @@ function ft(t, c, m, f) {
|
|
|
982
990
|
if (i) {
|
|
983
991
|
const g = Et(e, s), u = new Set(g);
|
|
984
992
|
for (const [
|
|
985
|
-
|
|
986
|
-
|
|
993
|
+
T,
|
|
994
|
+
w
|
|
987
995
|
] of i.components.entries()) {
|
|
988
|
-
let
|
|
989
|
-
const
|
|
990
|
-
if (!
|
|
991
|
-
if (
|
|
992
|
-
|
|
996
|
+
let $ = !1;
|
|
997
|
+
const P = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
998
|
+
if (!P.includes("none")) {
|
|
999
|
+
if (P.includes("all")) {
|
|
1000
|
+
w.forceUpdate();
|
|
993
1001
|
continue;
|
|
994
1002
|
}
|
|
995
|
-
if (
|
|
996
|
-
for (const
|
|
997
|
-
if (
|
|
998
|
-
|
|
1003
|
+
if (P.includes("component") && (w.paths.has("") && ($ = !0), !$))
|
|
1004
|
+
for (const C of u) {
|
|
1005
|
+
if (w.paths.has(C)) {
|
|
1006
|
+
$ = !0;
|
|
999
1007
|
break;
|
|
1000
1008
|
}
|
|
1001
|
-
let
|
|
1002
|
-
for (;
|
|
1003
|
-
const
|
|
1004
|
-
if (
|
|
1005
|
-
|
|
1009
|
+
let _ = C.lastIndexOf(".");
|
|
1010
|
+
for (; _ !== -1; ) {
|
|
1011
|
+
const U = C.substring(0, _);
|
|
1012
|
+
if (w.paths.has(U)) {
|
|
1013
|
+
$ = !0;
|
|
1006
1014
|
break;
|
|
1007
1015
|
}
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1016
|
+
const H = C.substring(
|
|
1017
|
+
_ + 1
|
|
1010
1018
|
);
|
|
1011
|
-
if (!isNaN(Number(
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1014
|
-
const
|
|
1019
|
+
if (!isNaN(Number(H))) {
|
|
1020
|
+
const b = U.lastIndexOf(".");
|
|
1021
|
+
if (b !== -1) {
|
|
1022
|
+
const V = U.substring(
|
|
1015
1023
|
0,
|
|
1016
|
-
|
|
1024
|
+
b
|
|
1017
1025
|
);
|
|
1018
|
-
if (
|
|
1019
|
-
|
|
1026
|
+
if (w.paths.has(V)) {
|
|
1027
|
+
$ = !0;
|
|
1020
1028
|
break;
|
|
1021
1029
|
}
|
|
1022
1030
|
}
|
|
1023
1031
|
}
|
|
1024
|
-
|
|
1032
|
+
_ = U.lastIndexOf(".");
|
|
1025
1033
|
}
|
|
1026
|
-
if (
|
|
1034
|
+
if ($) break;
|
|
1027
1035
|
}
|
|
1028
|
-
if (
|
|
1029
|
-
const
|
|
1030
|
-
let
|
|
1031
|
-
typeof
|
|
1036
|
+
if (!$ && P.includes("deps") && w.depsFunction) {
|
|
1037
|
+
const C = w.depsFunction(s);
|
|
1038
|
+
let _ = !1;
|
|
1039
|
+
typeof C == "boolean" ? C && (_ = !0) : B(w.deps, C) || (w.deps = C, _ = !0), _ && ($ = !0);
|
|
1032
1040
|
}
|
|
1033
|
-
|
|
1041
|
+
$ && w.forceUpdate();
|
|
1034
1042
|
}
|
|
1035
1043
|
}
|
|
1036
1044
|
}
|
|
@@ -1042,18 +1050,18 @@ function ft(t, c, m, f) {
|
|
|
1042
1050
|
throw new Error("Zod schema not found");
|
|
1043
1051
|
if (!d?.key)
|
|
1044
1052
|
throw new Error("Validation key not found");
|
|
1045
|
-
|
|
1053
|
+
Z(d.key);
|
|
1046
1054
|
const r = o.getState().cogsStateStore[t];
|
|
1047
1055
|
try {
|
|
1048
1056
|
const s = o.getState().getValidationErrors(d.key);
|
|
1049
1057
|
s && s.length > 0 && s.forEach(([g]) => {
|
|
1050
|
-
g && g.startsWith(d.key) &&
|
|
1058
|
+
g && g.startsWith(d.key) && Z(g);
|
|
1051
1059
|
});
|
|
1052
1060
|
const i = d.zodSchema.safeParse(r);
|
|
1053
1061
|
return i.success ? !0 : (i.error.errors.forEach((u) => {
|
|
1054
|
-
const
|
|
1055
|
-
e(
|
|
1056
|
-
}),
|
|
1062
|
+
const T = u.path, w = u.message, $ = [d.key, ...T].join(".");
|
|
1063
|
+
e($, w);
|
|
1064
|
+
}), ht(t), !1);
|
|
1057
1065
|
} catch (s) {
|
|
1058
1066
|
return console.error("Zod schema validation failed", s), !1;
|
|
1059
1067
|
}
|
|
@@ -1081,7 +1089,7 @@ function ft(t, c, m, f) {
|
|
|
1081
1089
|
children: d,
|
|
1082
1090
|
hideMessage: e
|
|
1083
1091
|
}) => /* @__PURE__ */ wt(
|
|
1084
|
-
|
|
1092
|
+
Dt,
|
|
1085
1093
|
{
|
|
1086
1094
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1087
1095
|
path: n,
|
|
@@ -1111,7 +1119,7 @@ function ft(t, c, m, f) {
|
|
|
1111
1119
|
};
|
|
1112
1120
|
if (l === "formElement")
|
|
1113
1121
|
return (d, e) => /* @__PURE__ */ wt(
|
|
1114
|
-
|
|
1122
|
+
Wt,
|
|
1115
1123
|
{
|
|
1116
1124
|
setState: c,
|
|
1117
1125
|
stateKey: t,
|
|
@@ -1120,23 +1128,23 @@ function ft(t, c, m, f) {
|
|
|
1120
1128
|
formOpts: e
|
|
1121
1129
|
}
|
|
1122
1130
|
);
|
|
1123
|
-
const M = [...n, l],
|
|
1124
|
-
return a(
|
|
1131
|
+
const M = [...n, l], ot = o.getState().getNestedState(t, M);
|
|
1132
|
+
return a(ot, M, S);
|
|
1125
1133
|
}
|
|
1126
|
-
},
|
|
1127
|
-
return
|
|
1128
|
-
proxy:
|
|
1129
|
-
stateVersion:
|
|
1130
|
-
}),
|
|
1134
|
+
}, L = new Proxy(O, R);
|
|
1135
|
+
return y.set(G, {
|
|
1136
|
+
proxy: L,
|
|
1137
|
+
stateVersion: k
|
|
1138
|
+
}), L;
|
|
1131
1139
|
}
|
|
1132
1140
|
return a(
|
|
1133
1141
|
o.getState().getNestedState(t, [])
|
|
1134
1142
|
);
|
|
1135
1143
|
}
|
|
1136
1144
|
function Ct(t) {
|
|
1137
|
-
return it(
|
|
1145
|
+
return it(Kt, { proxy: t });
|
|
1138
1146
|
}
|
|
1139
|
-
function
|
|
1147
|
+
function Qt({
|
|
1140
1148
|
proxy: t,
|
|
1141
1149
|
rebuildStateShape: c
|
|
1142
1150
|
}) {
|
|
@@ -1145,26 +1153,26 @@ function Xt({
|
|
|
1145
1153
|
m,
|
|
1146
1154
|
t._path
|
|
1147
1155
|
).stateMapNoRender(
|
|
1148
|
-
(
|
|
1156
|
+
(y, k, p, I, a) => t._mapFn(y, k, p, I, a)
|
|
1149
1157
|
) : null;
|
|
1150
1158
|
}
|
|
1151
|
-
function
|
|
1159
|
+
function Kt({
|
|
1152
1160
|
proxy: t
|
|
1153
1161
|
}) {
|
|
1154
1162
|
const c = J(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1155
1163
|
return st(() => {
|
|
1156
1164
|
const f = c.current;
|
|
1157
1165
|
if (!f || !f.parentElement) return;
|
|
1158
|
-
const
|
|
1159
|
-
let I =
|
|
1160
|
-
I || (I = `parent-${crypto.randomUUID()}`,
|
|
1161
|
-
const
|
|
1166
|
+
const y = f.parentElement, p = Array.from(y.childNodes).indexOf(f);
|
|
1167
|
+
let I = y.getAttribute("data-parent-id");
|
|
1168
|
+
I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
|
|
1169
|
+
const v = {
|
|
1162
1170
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1163
1171
|
parentId: I,
|
|
1164
1172
|
position: p,
|
|
1165
1173
|
effect: t._effect
|
|
1166
1174
|
};
|
|
1167
|
-
o.getState().addSignalElement(m,
|
|
1175
|
+
o.getState().addSignalElement(m, v);
|
|
1168
1176
|
const n = o.getState().getNestedState(t._stateKey, t._path);
|
|
1169
1177
|
let S;
|
|
1170
1178
|
if (t._effect)
|
|
@@ -1179,16 +1187,16 @@ function Qt({
|
|
|
1179
1187
|
else
|
|
1180
1188
|
S = n;
|
|
1181
1189
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1182
|
-
const
|
|
1183
|
-
f.replaceWith(
|
|
1190
|
+
const G = document.createTextNode(String(S));
|
|
1191
|
+
f.replaceWith(G);
|
|
1184
1192
|
}, [t._stateKey, t._path.join("."), t._effect]), it("span", {
|
|
1185
1193
|
ref: c,
|
|
1186
1194
|
style: { display: "none" },
|
|
1187
1195
|
"data-signal-id": m
|
|
1188
1196
|
});
|
|
1189
1197
|
}
|
|
1190
|
-
function
|
|
1191
|
-
const c =
|
|
1198
|
+
function me(t) {
|
|
1199
|
+
const c = Ot(
|
|
1192
1200
|
(m) => {
|
|
1193
1201
|
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1194
1202
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1202,38 +1210,38 @@ function he(t) {
|
|
|
1202
1210
|
);
|
|
1203
1211
|
return it("text", {}, String(c));
|
|
1204
1212
|
}
|
|
1205
|
-
function
|
|
1213
|
+
function te({
|
|
1206
1214
|
stateKey: t,
|
|
1207
1215
|
itemComponentId: c,
|
|
1208
1216
|
itemPath: m,
|
|
1209
1217
|
children: f
|
|
1210
1218
|
}) {
|
|
1211
|
-
const [,
|
|
1219
|
+
const [, y] = et({}), [k, p] = Ht(), I = J(null);
|
|
1212
1220
|
return st(() => {
|
|
1213
1221
|
p.height > 0 && p.height !== I.current && (I.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1214
1222
|
virtualizer: {
|
|
1215
1223
|
itemHeight: p.height
|
|
1216
1224
|
}
|
|
1217
1225
|
}));
|
|
1218
|
-
}, [p.height, t, m]),
|
|
1219
|
-
const a = `${t}////${c}`,
|
|
1226
|
+
}, [p.height, t, m]), gt(() => {
|
|
1227
|
+
const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
|
|
1220
1228
|
components: /* @__PURE__ */ new Map()
|
|
1221
1229
|
};
|
|
1222
|
-
return
|
|
1223
|
-
forceUpdate: () =>
|
|
1230
|
+
return v.components.set(a, {
|
|
1231
|
+
forceUpdate: () => y({}),
|
|
1224
1232
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1225
|
-
}), o.getState().stateComponents.set(t,
|
|
1233
|
+
}), o.getState().stateComponents.set(t, v), () => {
|
|
1226
1234
|
const n = o.getState().stateComponents.get(t);
|
|
1227
1235
|
n && n.components.delete(a);
|
|
1228
1236
|
};
|
|
1229
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */ wt("div", { ref:
|
|
1237
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ wt("div", { ref: k, children: f });
|
|
1230
1238
|
}
|
|
1231
1239
|
export {
|
|
1232
1240
|
Ct as $cogsSignal,
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1241
|
+
me as $cogsSignalStore,
|
|
1242
|
+
ge as addStateOptions,
|
|
1243
|
+
fe as createCogsState,
|
|
1244
|
+
Se as notifyComponent,
|
|
1245
|
+
Xt as useCogsStateFn
|
|
1238
1246
|
};
|
|
1239
1247
|
//# sourceMappingURL=CogsState.jsx.map
|