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