cogsbox-state 0.5.328 → 0.5.330
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 +397 -397
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +19 -28
package/dist/CogsState.jsx
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
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 mt } from "react/jsx-runtime";
|
|
3
|
+
import { useState as Q, useRef as Z, useEffect as nt, useLayoutEffect as ct, useMemo as ht, createElement as at, useSyncExternalStore as xt, startTransition as Pt, useCallback as wt } from "react";
|
|
4
|
+
import { transformStateFunc as _t, isDeepEqual as B, isFunction as Y, getNestedValue as q, getDifferences as vt, debounce as Mt } from "./utility.js";
|
|
5
|
+
import { pushFunc as St, updateFn as ot, cutFunc as it, ValidationWrapper as jt, FormControlComponent as Rt } from "./Functions.jsx";
|
|
6
|
+
import Ot from "superjson";
|
|
7
|
+
import { v4 as yt } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as o, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
9
|
+
import { getGlobalStore as o, formRefStore as Tt } from "./store.js";
|
|
10
|
+
import { useCogsConfig as bt } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Ut } from "fast-json-patch";
|
|
12
|
+
import Ft from "react-use-measure";
|
|
13
|
+
function Et(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 At({
|
|
21
21
|
stateKey: t,
|
|
22
22
|
options: c,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const f =
|
|
26
|
-
let
|
|
25
|
+
const f = et(t) || {}, y = m[t] || {}, b = o.getState().setInitialStateOptions, w = { ...y, ...f };
|
|
26
|
+
let p = !1;
|
|
27
27
|
if (c)
|
|
28
28
|
for (const a in c)
|
|
29
|
-
w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (
|
|
30
|
-
!B(w[a], c[a]) && (
|
|
31
|
-
|
|
29
|
+
w.hasOwnProperty(a) ? (a == "localStorage" && c[a] && w[a].key !== c[a]?.key && (p = !0, w[a] = c[a]), a == "initialState" && c[a] && w[a] !== c[a] && // Different references
|
|
30
|
+
!B(w[a], c[a]) && (p = !0, w[a] = c[a])) : (p = !0, w[a] = c[a]);
|
|
31
|
+
p && b(t, w);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ie(t, { formElements: c, validation: m }) {
|
|
34
34
|
return { initialState: t, formElements: c, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const ce = (t, c) => {
|
|
37
37
|
let m = t;
|
|
38
|
-
const [f, y] =
|
|
39
|
-
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((
|
|
40
|
-
y[
|
|
38
|
+
const [f, y] = _t(m);
|
|
39
|
+
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((p) => {
|
|
40
|
+
y[p] = y[p] || {}, y[p].formElements = {
|
|
41
41
|
...c?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...c?.validation,
|
|
44
|
-
...y[
|
|
44
|
+
...y[p].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
46
|
+
}, et(p) || o.getState().setInitialStateOptions(p, y[p]);
|
|
47
47
|
}), o.getState().setInitialStates(f), o.getState().setCreatedState(f);
|
|
48
|
-
const b = (
|
|
49
|
-
const [v] =
|
|
50
|
-
|
|
51
|
-
stateKey:
|
|
48
|
+
const b = (p, a) => {
|
|
49
|
+
const [v] = Q(a?.componentId ?? yt());
|
|
50
|
+
At({
|
|
51
|
+
stateKey: p,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = o.getState().cogsStateStore[
|
|
55
|
+
const n = o.getState().cogsStateStore[p] || f[p], S = a?.modifyState ? a.modifyState(n) : n, [W, U] = Bt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
|
-
stateKey:
|
|
58
|
+
stateKey: p,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
60
|
componentId: v,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
@@ -68,49 +68,49 @@ const de = (t, c) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return U;
|
|
72
72
|
};
|
|
73
|
-
function w(
|
|
74
|
-
|
|
73
|
+
function w(p, a) {
|
|
74
|
+
At({ stateKey: p, options: a, initialOptionsPart: y }), a.localStorage && Ht(p, a), gt(p);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: b, setCogsOptions: w };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = o.getState(),
|
|
78
|
+
setUpdaterState: lt,
|
|
79
|
+
setState: K,
|
|
80
|
+
getInitialOptions: et,
|
|
81
|
+
getKeyState: Nt,
|
|
82
|
+
getValidationErrors: Dt,
|
|
83
|
+
setStateLog: Lt,
|
|
84
|
+
updateInitialStateGlobal: It,
|
|
85
|
+
addValidationError: Wt,
|
|
86
|
+
removeValidationError: J,
|
|
87
|
+
setServerSyncActions: Gt
|
|
88
|
+
} = o.getState(), $t = (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 = Y(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
96
|
if (b && f) {
|
|
97
97
|
const w = `${f}-${c}-${b}`;
|
|
98
|
-
let
|
|
98
|
+
let p;
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
p = ut(w)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer: y ??
|
|
107
|
-
}, v =
|
|
106
|
+
lastSyncedWithServer: y ?? p
|
|
107
|
+
}, v = Ot.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
w,
|
|
110
110
|
JSON.stringify(v.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, ut = (t) => {
|
|
114
114
|
if (!t) return null;
|
|
115
115
|
try {
|
|
116
116
|
const c = window.localStorage.getItem(t);
|
|
@@ -118,20 +118,20 @@ const de = (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 } =
|
|
121
|
+
}, Ht = (t, c) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: f } = bt(), y = Y(c?.localStorage?.key) ? c.localStorage.key(m) : c?.localStorage?.key;
|
|
123
123
|
if (y && f) {
|
|
124
|
-
const b =
|
|
124
|
+
const b = ut(
|
|
125
125
|
`${f}-${t}-${y}`
|
|
126
126
|
);
|
|
127
127
|
if (b && b.lastUpdated > (b.lastSyncedWithServer || 0))
|
|
128
|
-
return
|
|
128
|
+
return K(t, b.state), gt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Vt = (t, c, m, f, y, b) => {
|
|
132
132
|
const w = {
|
|
133
133
|
initialState: c,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: dt(
|
|
135
135
|
t,
|
|
136
136
|
f,
|
|
137
137
|
y,
|
|
@@ -139,8 +139,8 @@ const de = (t, c) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
It(t, w.initialState), lt(t, w.updaterState), K(t, w.state);
|
|
143
|
+
}, gt = (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 de = (t, c) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((f) => f());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, le = (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,7 +157,7 @@ const de = (t, c) => {
|
|
|
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,27 +180,27 @@ const de = (t, c) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Bt(t, {
|
|
184
184
|
stateKey: c,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: f,
|
|
187
187
|
formElements: y,
|
|
188
188
|
reactiveDeps: b,
|
|
189
189
|
reactiveType: w,
|
|
190
|
-
componentId:
|
|
190
|
+
componentId: p,
|
|
191
191
|
initialState: a,
|
|
192
192
|
syncUpdate: v,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [h] =
|
|
196
|
+
const [W, U] = Q({}), { sessionId: F } = bt();
|
|
197
|
+
let G = !c;
|
|
198
|
+
const [h] = Q(c ?? yt()), l = o.getState().stateLog[h], st = Z(/* @__PURE__ */ new Set()), X = Z(p ?? yt()), R = Z(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
R.current =
|
|
201
|
+
R.current = et(h) ?? null, nt(() => {
|
|
202
202
|
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
-
|
|
203
|
+
K(h, (r) => ({
|
|
204
204
|
...r,
|
|
205
205
|
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
@@ -210,35 +210,35 @@ function Jt(t, {
|
|
|
210
210
|
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [v]),
|
|
213
|
+
}, [v]), nt(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
Et(h, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
218
|
const e = R.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, i = o.getState().initialStateGlobal[h];
|
|
219
219
|
if (!(i && !B(i, a) || !i) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let g = null;
|
|
222
|
-
const E =
|
|
223
|
-
E &&
|
|
224
|
-
let T = a,
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
222
|
+
const E = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
E && F && (g = ut(`${F}-${h}-${E}`));
|
|
224
|
+
let T = a, A = !1;
|
|
225
|
+
const _ = s ? Date.now() : 0, P = g?.lastUpdated || 0, M = g?.lastSyncedWithServer || 0;
|
|
226
|
+
s && _ > P ? (T = e.serverState.data, A = !0) : g && P > M && (T = g.state, e?.localStorage?.onChange && e?.localStorage?.onChange(T)), o.getState().initializeShadowState(h, a), Vt(
|
|
227
227
|
h,
|
|
228
228
|
a,
|
|
229
229
|
T,
|
|
230
|
-
|
|
230
|
+
rt,
|
|
231
231
|
X.current,
|
|
232
|
-
|
|
233
|
-
),
|
|
232
|
+
F
|
|
233
|
+
), A && E && F && $t(T, h, e, F, Date.now()), gt(h), (Array.isArray(w) ? w : [w || "component"]).includes("none") || U({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
240
|
+
]), ct(() => {
|
|
241
|
+
G && Et(h, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
@@ -249,191 +249,191 @@ function Jt(t, {
|
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return r.components.set(e, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => U({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
255
|
depsFunction: b || void 0,
|
|
256
256
|
reactiveType: w ?? ["component", "deps"]
|
|
257
|
-
}), o.getState().stateComponents.set(h, r),
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), U({}), () => {
|
|
258
258
|
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
261
|
+
const rt = (e, r, s, i) => {
|
|
262
262
|
if (Array.isArray(r)) {
|
|
263
263
|
const g = `${h}-${r.join(".")}`;
|
|
264
|
-
|
|
264
|
+
st.current.add(g);
|
|
265
265
|
}
|
|
266
266
|
const u = o.getState();
|
|
267
|
-
|
|
268
|
-
const E =
|
|
267
|
+
K(h, (g) => {
|
|
268
|
+
const E = Y(e) ? e(g) : e, T = `${h}-${r.join(".")}`;
|
|
269
269
|
if (T) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const $ = `${h}-${
|
|
276
|
-
|
|
270
|
+
let x = !1, V = u.signalDomElements.get(T);
|
|
271
|
+
if ((!V || V.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const O = r.slice(0, -1), D = q(E, O);
|
|
273
|
+
if (Array.isArray(D)) {
|
|
274
|
+
x = !0;
|
|
275
|
+
const $ = `${h}-${O.join(".")}`;
|
|
276
|
+
V = u.signalDomElements.get($);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (V) {
|
|
280
|
+
const O = x ? q(E, r.slice(0, -1)) : q(E, r);
|
|
281
|
+
V.forEach(({ parentId: D, position: $, effect: I }) => {
|
|
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 j = Array.from(k.childNodes);
|
|
287
|
+
if (j[$]) {
|
|
288
|
+
const N = I ? new Function("state", `return (${I})(state)`)(O) : O;
|
|
289
|
+
j[$].textContent = String(N);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || R.current?.validation?.key) && r &&
|
|
295
|
+
console.log("shadowState", u.shadowStateStore), s.updateType === "update" && (i || R.current?.validation?.key) && r && J(
|
|
296
296
|
(i || R.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" && R.current?.validation?.key &&
|
|
300
|
-
R.current?.validation?.key + "." +
|
|
301
|
-
), s.updateType === "insert" && R.current?.validation?.key &&
|
|
302
|
-
R.current?.validation?.key + "." +
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let $ =
|
|
307
|
-
|
|
298
|
+
const A = r.slice(0, r.length - 1);
|
|
299
|
+
s.updateType === "cut" && R.current?.validation?.key && J(
|
|
300
|
+
R.current?.validation?.key + "." + A.join(".")
|
|
301
|
+
), s.updateType === "insert" && R.current?.validation?.key && Dt(
|
|
302
|
+
R.current?.validation?.key + "." + A.join(".")
|
|
303
|
+
).filter(([V, O]) => {
|
|
304
|
+
let D = V?.split(".").length;
|
|
305
|
+
if (V == A.join(".") && D == A.length - 1) {
|
|
306
|
+
let $ = V + "." + A;
|
|
307
|
+
J(V), Wt($, O);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const _ = u.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", _), _) {
|
|
312
|
+
const x = vt(g, E), V = new Set(x), O = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
314
|
+
D,
|
|
315
315
|
$
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", $), !
|
|
320
|
-
if (
|
|
316
|
+
] of _.components.entries()) {
|
|
317
|
+
let I = !1;
|
|
318
|
+
const k = Array.isArray($.reactiveType) ? $.reactiveType : [$.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", $), !k.includes("none")) {
|
|
320
|
+
if (k.includes("all")) {
|
|
321
321
|
$.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (k.includes("component") && (($.paths.has(O) || $.paths.has("")) && (I = !0), !I))
|
|
325
|
+
for (const j of V) {
|
|
326
|
+
let N = j;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if ($.paths.has(
|
|
329
|
-
|
|
328
|
+
if ($.paths.has(N)) {
|
|
329
|
+
I = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const L = N.lastIndexOf(".");
|
|
333
|
+
if (L !== -1) {
|
|
334
|
+
const H = N.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
L
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && $.paths.has(
|
|
341
|
-
|
|
339
|
+
Number(N.substring(L + 1))
|
|
340
|
+
) && $.paths.has(H)) {
|
|
341
|
+
I = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
N = H;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
N = "";
|
|
347
|
+
if (N === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (I) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!I && k.includes("deps") && $.depsFunction) {
|
|
353
|
+
const j = $.depsFunction(E);
|
|
354
|
+
let N = !1;
|
|
355
|
+
typeof j == "boolean" ? j && (N = !0) : B($.deps, j) || ($.deps = j, N = !0), N && (I = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
I && $.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
r = r.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const P = Date.now();
|
|
362
|
+
r = r.map((x, V) => {
|
|
363
|
+
const O = r.slice(0, -1), D = q(E, O);
|
|
364
|
+
return V === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (D.length - 1).toString() : x;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: M, newValue:
|
|
366
|
+
const { oldValue: M, newValue: C } = zt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
g,
|
|
369
369
|
E,
|
|
370
370
|
r
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), z = {
|
|
372
|
+
timeStamp: P,
|
|
373
373
|
stateKey: h,
|
|
374
374
|
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
377
|
oldValue: M,
|
|
378
|
-
newValue:
|
|
378
|
+
newValue: C
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
u.updateShadowAtPath(h, r, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
u.insertShadowArrayElement(h,
|
|
385
|
+
const x = r.slice(0, -1);
|
|
386
|
+
u.insertShadowArrayElement(h, x, C);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
u.removeShadowArrayElement(h,
|
|
389
|
+
const V = r.slice(0, -1), O = parseInt(r[r.length - 1]);
|
|
390
|
+
u.removeShadowArrayElement(h, V, O);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Lt(h, (x) => {
|
|
394
|
+
const O = [...x ?? [], z].reduce((D, $) => {
|
|
395
|
+
const I = `${$.stateKey}:${JSON.stringify($.path)}`, k = D.get(I);
|
|
396
|
+
return k ? (k.timeStamp = Math.max(k.timeStamp, $.timeStamp), k.newValue = $.newValue, k.oldValue = k.oldValue ?? $.oldValue, k.updateType = $.updateType) : D.set(I, { ...$ }), D;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(O.values());
|
|
399
|
+
}), $t(
|
|
400
400
|
E,
|
|
401
401
|
h,
|
|
402
402
|
R.current,
|
|
403
|
-
|
|
403
|
+
F
|
|
404
404
|
), R.current?.middleware && R.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
406
|
+
update: z
|
|
407
407
|
}), R.current?.serverSync) {
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
408
|
+
const x = u.serverState[h], V = R.current?.serverSync;
|
|
409
|
+
Gt(h, {
|
|
410
|
+
syncKey: typeof V.syncKey == "string" ? V.syncKey : V.syncKey({ state: E }),
|
|
411
|
+
rollBackState: x,
|
|
412
|
+
actionTimeStamp: Date.now() + (V.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
o.getState().updaterState[h] || (
|
|
419
|
+
o.getState().updaterState[h] || (lt(
|
|
420
420
|
h,
|
|
421
|
-
|
|
421
|
+
dt(
|
|
422
422
|
h,
|
|
423
|
-
|
|
423
|
+
rt,
|
|
424
424
|
X.current,
|
|
425
|
-
|
|
425
|
+
F
|
|
426
426
|
)
|
|
427
|
-
), o.getState().cogsStateStore[h] ||
|
|
428
|
-
const d =
|
|
427
|
+
), o.getState().cogsStateStore[h] || K(h, t), o.getState().initialStateGlobal[h] || It(h, t));
|
|
428
|
+
const d = ht(() => dt(
|
|
429
429
|
h,
|
|
430
|
-
|
|
430
|
+
rt,
|
|
431
431
|
X.current,
|
|
432
|
-
|
|
433
|
-
), [h,
|
|
434
|
-
return [
|
|
432
|
+
F
|
|
433
|
+
), [h, F]);
|
|
434
|
+
return [Nt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function dt(t, c, m, f) {
|
|
437
437
|
const y = /* @__PURE__ */ new Map();
|
|
438
438
|
let b = 0;
|
|
439
439
|
const w = (v) => {
|
|
@@ -441,17 +441,17 @@ function gt(t, c, m, f) {
|
|
|
441
441
|
for (const [S] of y)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && y.delete(S);
|
|
443
443
|
b++;
|
|
444
|
-
},
|
|
444
|
+
}, p = {
|
|
445
445
|
removeValidation: (v) => {
|
|
446
|
-
v?.validationKey &&
|
|
446
|
+
v?.validationKey && J(v.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (v) => {
|
|
449
449
|
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && J(n?.key), v?.validationKey && J(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, []), U = et(t), F = Y(U?.localStorage?.key) ? U?.localStorage?.key(S) : U?.localStorage?.key, G = `${f}-${t}-${F}`;
|
|
454
|
+
G && localStorage.removeItem(G), lt(t, W), K(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 gt(t, c, m, f) {
|
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (v) => {
|
|
461
461
|
y.clear(), b++;
|
|
462
|
-
const n =
|
|
462
|
+
const n = dt(
|
|
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 = et(t), U = Y(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, F = `${f}-${t}-${U}`;
|
|
468
|
+
return localStorage.getItem(F) && localStorage.removeItem(F), Pt(() => {
|
|
469
|
+
It(t, v), o.getState().initializeShadowState(t, v), lt(t, n), K(t, v);
|
|
470
|
+
const G = o.getState().stateComponents.get(t);
|
|
471
|
+
G && G.components.forEach((h) => {
|
|
472
472
|
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (G) => n.get()[G]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: o.getState().initialStateGlobal[t],
|
|
@@ -480,27 +480,27 @@ function gt(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 && B(v,
|
|
483
|
+
return !!(v && B(v, Nt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(v, n = [], S) {
|
|
487
|
-
const
|
|
488
|
-
y.get(
|
|
489
|
-
const
|
|
487
|
+
const W = n.map(String).join(".");
|
|
488
|
+
y.get(W);
|
|
489
|
+
const U = function() {
|
|
490
490
|
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(
|
|
493
|
-
|
|
492
|
+
Object.keys(p).forEach((h) => {
|
|
493
|
+
U[h] = p[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(h, l,
|
|
495
|
+
const F = {
|
|
496
|
+
apply(h, l, st) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
501
|
get(h, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const st = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function gt(t, c, m, f) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !st.has(l)) {
|
|
527
527
|
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
528
|
if (e) {
|
|
529
529
|
const r = e.components.get(d);
|
|
@@ -540,7 +540,7 @@ function gt(t, c, m, f) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => vt(
|
|
544
544
|
o.getState().cogsStateStore[t],
|
|
545
545
|
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
@@ -581,7 +581,7 @@ function gt(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 = et(t), r = Y(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,132 +621,132 @@ function gt(t, c, m, f) {
|
|
|
621
621
|
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 5,
|
|
623
623
|
stickToBottom: i = !1
|
|
624
|
-
} = e, u =
|
|
624
|
+
} = e, u = Z(null), [g, E] = Q({
|
|
625
625
|
startIndex: 0,
|
|
626
626
|
endIndex: 10
|
|
627
|
-
}), T =
|
|
628
|
-
|
|
629
|
-
P((
|
|
627
|
+
}), T = Z(i), A = Z(0), [_, P] = Q(0);
|
|
628
|
+
nt(() => o.getState().subscribeToShadowState(t, () => {
|
|
629
|
+
P((k) => k + 1);
|
|
630
630
|
}), [t]);
|
|
631
|
-
const
|
|
631
|
+
const M = o().getNestedState(
|
|
632
632
|
t,
|
|
633
633
|
n
|
|
634
|
-
),
|
|
635
|
-
const
|
|
636
|
-
let
|
|
637
|
-
const
|
|
638
|
-
for (let
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
|
|
634
|
+
), C = M.length, { totalHeight: z, positions: x } = ht(() => {
|
|
635
|
+
const I = o.getState().getShadowMetadata(t, n) || [];
|
|
636
|
+
let k = 0;
|
|
637
|
+
const j = [];
|
|
638
|
+
for (let N = 0; N < C; N++) {
|
|
639
|
+
j[N] = k;
|
|
640
|
+
const L = I[N]?.virtualizer?.itemHeight;
|
|
641
|
+
k += L || r;
|
|
642
642
|
}
|
|
643
|
-
return { totalHeight:
|
|
643
|
+
return { totalHeight: k, positions: j };
|
|
644
644
|
}, [
|
|
645
|
-
|
|
645
|
+
C,
|
|
646
646
|
t,
|
|
647
647
|
n.join("."),
|
|
648
648
|
r,
|
|
649
|
-
|
|
650
|
-
]),
|
|
651
|
-
const
|
|
652
|
-
{ length:
|
|
653
|
-
(
|
|
654
|
-
),
|
|
655
|
-
return a(
|
|
649
|
+
_
|
|
650
|
+
]), V = ht(() => {
|
|
651
|
+
const I = Math.max(0, g.startIndex), k = Math.min(C, g.endIndex), j = Array.from(
|
|
652
|
+
{ length: k - I },
|
|
653
|
+
(L, H) => I + H
|
|
654
|
+
), N = j.map((L) => M[L]);
|
|
655
|
+
return a(N, n, {
|
|
656
656
|
...S,
|
|
657
|
-
validIndices:
|
|
657
|
+
validIndices: j
|
|
658
658
|
});
|
|
659
|
-
}, [g.startIndex, g.endIndex,
|
|
660
|
-
|
|
661
|
-
if (i &&
|
|
662
|
-
const
|
|
663
|
-
|
|
659
|
+
}, [g.startIndex, g.endIndex, M, C]);
|
|
660
|
+
nt(() => {
|
|
661
|
+
if (i && C > 0 && u.current) {
|
|
662
|
+
const I = u.current, k = Math.ceil(
|
|
663
|
+
I.clientHeight / r
|
|
664
664
|
);
|
|
665
665
|
E({
|
|
666
666
|
startIndex: Math.max(
|
|
667
667
|
0,
|
|
668
|
-
|
|
668
|
+
C - k - s
|
|
669
669
|
),
|
|
670
|
-
endIndex:
|
|
670
|
+
endIndex: C
|
|
671
671
|
}), setTimeout(() => {
|
|
672
|
-
|
|
672
|
+
I.scrollTop = I.scrollHeight;
|
|
673
673
|
}, 100);
|
|
674
674
|
}
|
|
675
|
-
}, [
|
|
676
|
-
const
|
|
677
|
-
if (!
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
A[mt] < z ? Q = mt + 1 : ct = mt - 1;
|
|
675
|
+
}, [C]), ct(() => {
|
|
676
|
+
const I = u.current;
|
|
677
|
+
if (!I) return;
|
|
678
|
+
const k = () => {
|
|
679
|
+
if (!I) return;
|
|
680
|
+
const { scrollTop: N } = I;
|
|
681
|
+
let L = 0, H = C - 1;
|
|
682
|
+
for (; L <= H; ) {
|
|
683
|
+
const ft = Math.floor((L + H) / 2);
|
|
684
|
+
x[ft] < N ? L = ft + 1 : H = ft - 1;
|
|
686
685
|
}
|
|
687
|
-
const
|
|
688
|
-
let
|
|
689
|
-
const
|
|
690
|
-
for (;
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
},
|
|
694
|
-
T.current =
|
|
686
|
+
const pt = Math.max(0, H - s);
|
|
687
|
+
let tt = pt;
|
|
688
|
+
const Ct = N + I.clientHeight;
|
|
689
|
+
for (; tt < C && x[tt] < Ct; )
|
|
690
|
+
tt++;
|
|
691
|
+
tt = Math.min(C, tt + s), E({ startIndex: pt, endIndex: tt });
|
|
692
|
+
}, j = () => {
|
|
693
|
+
T.current = I.scrollHeight - I.scrollTop - I.clientHeight < 1, k();
|
|
695
694
|
};
|
|
696
|
-
if (
|
|
695
|
+
if (I.addEventListener("scroll", j, {
|
|
697
696
|
passive: !0
|
|
698
|
-
}), i) {
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
697
|
+
}), i && T.current) {
|
|
698
|
+
const N = I.scrollHeight;
|
|
699
|
+
if (N > A.current) {
|
|
700
|
+
const H = N - I.scrollTop - I.clientHeight > I.clientHeight * 2;
|
|
701
|
+
I.scrollTo({
|
|
702
702
|
top: 999999999,
|
|
703
|
-
behavior:
|
|
704
|
-
//
|
|
705
|
-
});
|
|
706
|
-
}
|
|
703
|
+
behavior: H ? "auto" : "smooth"
|
|
704
|
+
// Instant for big jumps, smooth for small
|
|
705
|
+
}), A.current = N;
|
|
706
|
+
}
|
|
707
707
|
}
|
|
708
|
-
return
|
|
709
|
-
|
|
708
|
+
return k(), () => {
|
|
709
|
+
I.removeEventListener("scroll", j);
|
|
710
710
|
};
|
|
711
|
-
}, [
|
|
712
|
-
const
|
|
713
|
-
(
|
|
711
|
+
}, [C, x, z, i]);
|
|
712
|
+
const O = wt(
|
|
713
|
+
(I = "smooth") => {
|
|
714
714
|
u.current && (T.current = !0, u.current.scrollTo({
|
|
715
715
|
top: u.current.scrollHeight,
|
|
716
|
-
behavior:
|
|
716
|
+
behavior: I
|
|
717
717
|
}));
|
|
718
718
|
},
|
|
719
719
|
[]
|
|
720
|
-
),
|
|
721
|
-
(
|
|
722
|
-
u.current &&
|
|
723
|
-
top:
|
|
724
|
-
behavior:
|
|
720
|
+
), D = wt(
|
|
721
|
+
(I, k = "smooth") => {
|
|
722
|
+
u.current && x[I] !== void 0 && (T.current = !1, u.current.scrollTo({
|
|
723
|
+
top: x[I],
|
|
724
|
+
behavior: k
|
|
725
725
|
}));
|
|
726
726
|
},
|
|
727
|
-
[
|
|
728
|
-
),
|
|
727
|
+
[x]
|
|
728
|
+
), $ = {
|
|
729
729
|
outer: {
|
|
730
730
|
ref: u,
|
|
731
731
|
style: { overflowY: "auto", height: "100%" }
|
|
732
732
|
},
|
|
733
733
|
inner: {
|
|
734
734
|
style: {
|
|
735
|
-
height: `${
|
|
735
|
+
height: `${z}px`,
|
|
736
736
|
position: "relative"
|
|
737
737
|
}
|
|
738
738
|
},
|
|
739
739
|
list: {
|
|
740
740
|
style: {
|
|
741
|
-
transform: `translateY(${
|
|
741
|
+
transform: `translateY(${x[g.startIndex] || 0}px)`
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
745
|
return {
|
|
746
|
-
virtualState:
|
|
747
|
-
virtualizerProps:
|
|
748
|
-
scrollToBottom:
|
|
749
|
-
scrollToIndex:
|
|
746
|
+
virtualState: V,
|
|
747
|
+
virtualizerProps: $,
|
|
748
|
+
scrollToBottom: O,
|
|
749
|
+
scrollToIndex: D
|
|
750
750
|
};
|
|
751
751
|
};
|
|
752
752
|
if (l === "stateSort")
|
|
@@ -780,19 +780,19 @@ function gt(t, c, m, f) {
|
|
|
780
780
|
const g = r[i], E = [...n, i.toString()], T = a(g, E, S);
|
|
781
781
|
return e(g, T, {
|
|
782
782
|
register: () => {
|
|
783
|
-
const [,
|
|
784
|
-
|
|
785
|
-
const M = `${t}////${
|
|
783
|
+
const [, _] = Q({}), P = `${m}-${n.join(".")}-${i}`;
|
|
784
|
+
ct(() => {
|
|
785
|
+
const M = `${t}////${P}`, C = o.getState().stateComponents.get(t) || {
|
|
786
786
|
components: /* @__PURE__ */ new Map()
|
|
787
787
|
};
|
|
788
|
-
return
|
|
789
|
-
forceUpdate: () =>
|
|
788
|
+
return C.components.set(M, {
|
|
789
|
+
forceUpdate: () => _({}),
|
|
790
790
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
791
|
-
}), o.getState().stateComponents.set(t,
|
|
792
|
-
const
|
|
793
|
-
|
|
791
|
+
}), o.getState().stateComponents.set(t, C), () => {
|
|
792
|
+
const z = o.getState().stateComponents.get(t);
|
|
793
|
+
z && z.components.delete(M);
|
|
794
794
|
};
|
|
795
|
-
}, [t,
|
|
795
|
+
}, [t, P]);
|
|
796
796
|
},
|
|
797
797
|
index: u,
|
|
798
798
|
originalIndex: i
|
|
@@ -816,7 +816,7 @@ function gt(t, c, m, f) {
|
|
|
816
816
|
);
|
|
817
817
|
});
|
|
818
818
|
if (l === "$stateMap")
|
|
819
|
-
return (e) =>
|
|
819
|
+
return (e) => at(qt, {
|
|
820
820
|
proxy: {
|
|
821
821
|
_stateKey: t,
|
|
822
822
|
_path: n,
|
|
@@ -829,11 +829,11 @@ function gt(t, c, m, f) {
|
|
|
829
829
|
return (e) => {
|
|
830
830
|
const r = o.getState().getNestedState(t, n);
|
|
831
831
|
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (i, u) => u)).map((i, u) => {
|
|
832
|
-
const g = r[i], E = [...n, i.toString()], T = a(g, E, S),
|
|
833
|
-
return
|
|
832
|
+
const g = r[i], E = [...n, i.toString()], T = a(g, E, S), A = `${m}-${n.join(".")}-${i}`;
|
|
833
|
+
return at(Yt, {
|
|
834
834
|
key: i,
|
|
835
835
|
stateKey: t,
|
|
836
|
-
itemComponentId:
|
|
836
|
+
itemComponentId: A,
|
|
837
837
|
itemPath: E,
|
|
838
838
|
children: e(
|
|
839
839
|
g,
|
|
@@ -873,36 +873,36 @@ function gt(t, c, m, f) {
|
|
|
873
873
|
return a(s, i);
|
|
874
874
|
};
|
|
875
875
|
if (l === "insert")
|
|
876
|
-
return (e) => (w(n),
|
|
876
|
+
return (e) => (w(n), St(c, e, n, t), a(
|
|
877
877
|
o.getState().getNestedState(t, n),
|
|
878
878
|
n
|
|
879
879
|
));
|
|
880
880
|
if (l === "uniqueInsert")
|
|
881
881
|
return (e, r, s) => {
|
|
882
|
-
const i = o.getState().getNestedState(t, n), u =
|
|
882
|
+
const i = o.getState().getNestedState(t, n), u = Y(e) ? e(i) : e;
|
|
883
883
|
let g = null;
|
|
884
884
|
if (!i.some((T) => {
|
|
885
885
|
if (r) {
|
|
886
|
-
const
|
|
887
|
-
(
|
|
886
|
+
const _ = r.every(
|
|
887
|
+
(P) => B(T[P], u[P])
|
|
888
888
|
);
|
|
889
|
-
return
|
|
889
|
+
return _ && (g = T), _;
|
|
890
890
|
}
|
|
891
|
-
const
|
|
892
|
-
return
|
|
891
|
+
const A = B(T, u);
|
|
892
|
+
return A && (g = T), A;
|
|
893
893
|
}))
|
|
894
|
-
w(n),
|
|
894
|
+
w(n), St(c, u, n, t);
|
|
895
895
|
else if (s && g) {
|
|
896
|
-
const T = s(g),
|
|
897
|
-
(
|
|
896
|
+
const T = s(g), A = i.map(
|
|
897
|
+
(_) => B(_, g) ? T : _
|
|
898
898
|
);
|
|
899
|
-
w(n),
|
|
899
|
+
w(n), ot(c, A, n);
|
|
900
900
|
}
|
|
901
901
|
};
|
|
902
902
|
if (l === "cut")
|
|
903
903
|
return (e, r) => {
|
|
904
904
|
if (!r?.waitForSync)
|
|
905
|
-
return w(n),
|
|
905
|
+
return w(n), it(c, n, t, e), a(
|
|
906
906
|
o.getState().getNestedState(t, n),
|
|
907
907
|
n
|
|
908
908
|
);
|
|
@@ -910,12 +910,12 @@ function gt(t, c, m, f) {
|
|
|
910
910
|
if (l === "cutByValue")
|
|
911
911
|
return (e) => {
|
|
912
912
|
for (let r = 0; r < v.length; r++)
|
|
913
|
-
v[r] === e &&
|
|
913
|
+
v[r] === e && it(c, n, t, r);
|
|
914
914
|
};
|
|
915
915
|
if (l === "toggleByValue")
|
|
916
916
|
return (e) => {
|
|
917
917
|
const r = v.findIndex((s) => s === e);
|
|
918
|
-
r > -1 ?
|
|
918
|
+
r > -1 ? it(c, n, t, r) : St(c, e, n, t);
|
|
919
919
|
};
|
|
920
920
|
if (l === "stateFind")
|
|
921
921
|
return (e) => {
|
|
@@ -940,7 +940,7 @@ function gt(t, c, m, f) {
|
|
|
940
940
|
if (!isNaN(Number(X))) {
|
|
941
941
|
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
942
942
|
if (Array.isArray(e) && l === "cut")
|
|
943
|
-
return () =>
|
|
943
|
+
return () => it(
|
|
944
944
|
c,
|
|
945
945
|
d,
|
|
946
946
|
t,
|
|
@@ -956,13 +956,13 @@ function gt(t, c, m, f) {
|
|
|
956
956
|
return o.getState().getNestedState(t, n);
|
|
957
957
|
};
|
|
958
958
|
if (l === "$derive")
|
|
959
|
-
return (d) =>
|
|
959
|
+
return (d) => kt({
|
|
960
960
|
_stateKey: t,
|
|
961
961
|
_path: n,
|
|
962
962
|
_effect: d.toString()
|
|
963
963
|
});
|
|
964
964
|
if (l === "$get")
|
|
965
|
-
return () =>
|
|
965
|
+
return () => kt({
|
|
966
966
|
_stateKey: t,
|
|
967
967
|
_path: n
|
|
968
968
|
});
|
|
@@ -971,7 +971,7 @@ function gt(t, c, m, f) {
|
|
|
971
971
|
return o.getState().getSyncInfo(d);
|
|
972
972
|
}
|
|
973
973
|
if (l == "getLocalStorage")
|
|
974
|
-
return (d) =>
|
|
974
|
+
return (d) => ut(f + "-" + t + "-" + d);
|
|
975
975
|
if (l === "_selected") {
|
|
976
976
|
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
977
977
|
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
@@ -981,7 +981,7 @@ function gt(t, c, m, f) {
|
|
|
981
981
|
const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
|
|
982
982
|
d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
|
|
983
983
|
const i = o.getState().getNestedState(t, [...e]);
|
|
984
|
-
|
|
984
|
+
ot(c, i, e), w(e);
|
|
985
985
|
};
|
|
986
986
|
if (l === "toggleSelected")
|
|
987
987
|
return () => {
|
|
@@ -992,13 +992,13 @@ function gt(t, c, m, f) {
|
|
|
992
992
|
s === e ? void 0 : e
|
|
993
993
|
);
|
|
994
994
|
const i = o.getState().getNestedState(t, [...d]);
|
|
995
|
-
|
|
995
|
+
ot(c, i, d), w(d);
|
|
996
996
|
};
|
|
997
997
|
if (n.length == 0) {
|
|
998
998
|
if (l === "applyJsonPatch")
|
|
999
999
|
return (d) => {
|
|
1000
|
-
const e = o.getState().cogsStateStore[t], s =
|
|
1001
|
-
|
|
1000
|
+
const e = o.getState().cogsStateStore[t], s = Ut(e, d).newDocument;
|
|
1001
|
+
Vt(
|
|
1002
1002
|
t,
|
|
1003
1003
|
o.getState().initialStateGlobal[t],
|
|
1004
1004
|
s,
|
|
@@ -1008,57 +1008,57 @@ function gt(t, c, m, f) {
|
|
|
1008
1008
|
);
|
|
1009
1009
|
const i = o.getState().stateComponents.get(t);
|
|
1010
1010
|
if (i) {
|
|
1011
|
-
const u =
|
|
1011
|
+
const u = vt(e, s), g = new Set(u);
|
|
1012
1012
|
for (const [
|
|
1013
1013
|
E,
|
|
1014
1014
|
T
|
|
1015
1015
|
] of i.components.entries()) {
|
|
1016
|
-
let
|
|
1017
|
-
const
|
|
1018
|
-
if (!
|
|
1019
|
-
if (
|
|
1016
|
+
let A = !1;
|
|
1017
|
+
const _ = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
|
|
1018
|
+
if (!_.includes("none")) {
|
|
1019
|
+
if (_.includes("all")) {
|
|
1020
1020
|
T.forceUpdate();
|
|
1021
1021
|
continue;
|
|
1022
1022
|
}
|
|
1023
|
-
if (
|
|
1024
|
-
for (const
|
|
1025
|
-
if (T.paths.has(
|
|
1026
|
-
|
|
1023
|
+
if (_.includes("component") && (T.paths.has("") && (A = !0), !A))
|
|
1024
|
+
for (const P of g) {
|
|
1025
|
+
if (T.paths.has(P)) {
|
|
1026
|
+
A = !0;
|
|
1027
1027
|
break;
|
|
1028
1028
|
}
|
|
1029
|
-
let M =
|
|
1029
|
+
let M = P.lastIndexOf(".");
|
|
1030
1030
|
for (; M !== -1; ) {
|
|
1031
|
-
const
|
|
1032
|
-
if (T.paths.has(
|
|
1033
|
-
|
|
1031
|
+
const C = P.substring(0, M);
|
|
1032
|
+
if (T.paths.has(C)) {
|
|
1033
|
+
A = !0;
|
|
1034
1034
|
break;
|
|
1035
1035
|
}
|
|
1036
|
-
const
|
|
1036
|
+
const z = P.substring(
|
|
1037
1037
|
M + 1
|
|
1038
1038
|
);
|
|
1039
|
-
if (!isNaN(Number(
|
|
1040
|
-
const
|
|
1041
|
-
if (
|
|
1042
|
-
const
|
|
1039
|
+
if (!isNaN(Number(z))) {
|
|
1040
|
+
const x = C.lastIndexOf(".");
|
|
1041
|
+
if (x !== -1) {
|
|
1042
|
+
const V = C.substring(
|
|
1043
1043
|
0,
|
|
1044
|
-
|
|
1044
|
+
x
|
|
1045
1045
|
);
|
|
1046
|
-
if (T.paths.has(
|
|
1047
|
-
|
|
1046
|
+
if (T.paths.has(V)) {
|
|
1047
|
+
A = !0;
|
|
1048
1048
|
break;
|
|
1049
1049
|
}
|
|
1050
1050
|
}
|
|
1051
1051
|
}
|
|
1052
|
-
M =
|
|
1052
|
+
M = C.lastIndexOf(".");
|
|
1053
1053
|
}
|
|
1054
|
-
if (
|
|
1054
|
+
if (A) break;
|
|
1055
1055
|
}
|
|
1056
|
-
if (!
|
|
1057
|
-
const
|
|
1056
|
+
if (!A && _.includes("deps") && T.depsFunction) {
|
|
1057
|
+
const P = T.depsFunction(s);
|
|
1058
1058
|
let M = !1;
|
|
1059
|
-
typeof
|
|
1059
|
+
typeof P == "boolean" ? P && (M = !0) : B(T.deps, P) || (T.deps = P, M = !0), M && (A = !0);
|
|
1060
1060
|
}
|
|
1061
|
-
|
|
1061
|
+
A && T.forceUpdate();
|
|
1062
1062
|
}
|
|
1063
1063
|
}
|
|
1064
1064
|
}
|
|
@@ -1070,18 +1070,18 @@ function gt(t, c, m, f) {
|
|
|
1070
1070
|
throw new Error("Zod schema not found");
|
|
1071
1071
|
if (!d?.key)
|
|
1072
1072
|
throw new Error("Validation key not found");
|
|
1073
|
-
|
|
1073
|
+
J(d.key);
|
|
1074
1074
|
const r = o.getState().cogsStateStore[t];
|
|
1075
1075
|
try {
|
|
1076
1076
|
const s = o.getState().getValidationErrors(d.key);
|
|
1077
1077
|
s && s.length > 0 && s.forEach(([u]) => {
|
|
1078
|
-
u && u.startsWith(d.key) &&
|
|
1078
|
+
u && u.startsWith(d.key) && J(u);
|
|
1079
1079
|
});
|
|
1080
1080
|
const i = d.zodSchema.safeParse(r);
|
|
1081
1081
|
return i.success ? !0 : (i.error.errors.forEach((g) => {
|
|
1082
|
-
const E = g.path, T = g.message,
|
|
1083
|
-
e(
|
|
1084
|
-
}),
|
|
1082
|
+
const E = g.path, T = g.message, A = [d.key, ...E].join(".");
|
|
1083
|
+
e(A, T);
|
|
1084
|
+
}), gt(t), !1);
|
|
1085
1085
|
} catch (s) {
|
|
1086
1086
|
return console.error("Zod schema validation failed", s), !1;
|
|
1087
1087
|
}
|
|
@@ -1090,7 +1090,7 @@ function gt(t, c, m, f) {
|
|
|
1090
1090
|
if (l === "getComponents")
|
|
1091
1091
|
return () => o().stateComponents.get(t);
|
|
1092
1092
|
if (l === "getAllFormRefs")
|
|
1093
|
-
return () =>
|
|
1093
|
+
return () => Tt.getState().getFormRefsByStateKey(t);
|
|
1094
1094
|
if (l === "_initialState")
|
|
1095
1095
|
return o.getState().initialStateGlobal[t];
|
|
1096
1096
|
if (l === "_serverState")
|
|
@@ -1098,18 +1098,18 @@ function gt(t, c, m, f) {
|
|
|
1098
1098
|
if (l === "_isLoading")
|
|
1099
1099
|
return o.getState().isLoadingGlobal[t];
|
|
1100
1100
|
if (l === "revertToInitialState")
|
|
1101
|
-
return
|
|
1102
|
-
if (l === "updateInitialState") return
|
|
1103
|
-
if (l === "removeValidation") return
|
|
1101
|
+
return p.revertToInitialState;
|
|
1102
|
+
if (l === "updateInitialState") return p.updateInitialState;
|
|
1103
|
+
if (l === "removeValidation") return p.removeValidation;
|
|
1104
1104
|
}
|
|
1105
1105
|
if (l === "getFormRef")
|
|
1106
|
-
return () =>
|
|
1106
|
+
return () => Tt.getState().getFormRef(t + "." + n.join("."));
|
|
1107
1107
|
if (l === "validationWrapper")
|
|
1108
1108
|
return ({
|
|
1109
1109
|
children: d,
|
|
1110
1110
|
hideMessage: e
|
|
1111
|
-
}) => /* @__PURE__ */
|
|
1112
|
-
|
|
1111
|
+
}) => /* @__PURE__ */ mt(
|
|
1112
|
+
jt,
|
|
1113
1113
|
{
|
|
1114
1114
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1115
1115
|
path: n,
|
|
@@ -1121,25 +1121,25 @@ function gt(t, c, m, f) {
|
|
|
1121
1121
|
);
|
|
1122
1122
|
if (l === "_stateKey") return t;
|
|
1123
1123
|
if (l === "_path") return n;
|
|
1124
|
-
if (l === "_isServerSynced") return
|
|
1124
|
+
if (l === "_isServerSynced") return p._isServerSynced;
|
|
1125
1125
|
if (l === "update")
|
|
1126
1126
|
return (d, e) => {
|
|
1127
1127
|
if (e?.debounce)
|
|
1128
|
-
|
|
1129
|
-
|
|
1128
|
+
Mt(() => {
|
|
1129
|
+
ot(c, d, n, "");
|
|
1130
1130
|
const r = o.getState().getNestedState(t, n);
|
|
1131
1131
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1132
1132
|
}, e.debounce);
|
|
1133
1133
|
else {
|
|
1134
|
-
|
|
1134
|
+
ot(c, d, n, "");
|
|
1135
1135
|
const r = o.getState().getNestedState(t, n);
|
|
1136
1136
|
e?.afterUpdate && e.afterUpdate(r);
|
|
1137
1137
|
}
|
|
1138
1138
|
w(n);
|
|
1139
1139
|
};
|
|
1140
1140
|
if (l === "formElement")
|
|
1141
|
-
return (d, e) => /* @__PURE__ */
|
|
1142
|
-
|
|
1141
|
+
return (d, e) => /* @__PURE__ */ mt(
|
|
1142
|
+
Rt,
|
|
1143
1143
|
{
|
|
1144
1144
|
setState: c,
|
|
1145
1145
|
stateKey: t,
|
|
@@ -1148,23 +1148,23 @@ function gt(t, c, m, f) {
|
|
|
1148
1148
|
formOpts: e
|
|
1149
1149
|
}
|
|
1150
1150
|
);
|
|
1151
|
-
const R = [...n, l],
|
|
1152
|
-
return a(
|
|
1151
|
+
const R = [...n, l], rt = o.getState().getNestedState(t, R);
|
|
1152
|
+
return a(rt, R, S);
|
|
1153
1153
|
}
|
|
1154
|
-
},
|
|
1155
|
-
return y.set(
|
|
1156
|
-
proxy:
|
|
1154
|
+
}, G = new Proxy(U, F);
|
|
1155
|
+
return y.set(W, {
|
|
1156
|
+
proxy: G,
|
|
1157
1157
|
stateVersion: b
|
|
1158
|
-
}),
|
|
1158
|
+
}), G;
|
|
1159
1159
|
}
|
|
1160
1160
|
return a(
|
|
1161
1161
|
o.getState().getNestedState(t, [])
|
|
1162
1162
|
);
|
|
1163
1163
|
}
|
|
1164
|
-
function
|
|
1165
|
-
return
|
|
1164
|
+
function kt(t) {
|
|
1165
|
+
return at(Jt, { proxy: t });
|
|
1166
1166
|
}
|
|
1167
|
-
function
|
|
1167
|
+
function qt({
|
|
1168
1168
|
proxy: t,
|
|
1169
1169
|
rebuildStateShape: c
|
|
1170
1170
|
}) {
|
|
@@ -1173,22 +1173,22 @@ function Yt({
|
|
|
1173
1173
|
m,
|
|
1174
1174
|
t._path
|
|
1175
1175
|
).stateMapNoRender(
|
|
1176
|
-
(y, b, w,
|
|
1176
|
+
(y, b, w, p, a) => t._mapFn(y, b, w, p, a)
|
|
1177
1177
|
) : null;
|
|
1178
1178
|
}
|
|
1179
|
-
function
|
|
1179
|
+
function Jt({
|
|
1180
1180
|
proxy: t
|
|
1181
1181
|
}) {
|
|
1182
|
-
const c =
|
|
1183
|
-
return
|
|
1182
|
+
const c = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1183
|
+
return nt(() => {
|
|
1184
1184
|
const f = c.current;
|
|
1185
1185
|
if (!f || !f.parentElement) return;
|
|
1186
1186
|
const y = f.parentElement, w = Array.from(y.childNodes).indexOf(f);
|
|
1187
|
-
let
|
|
1188
|
-
|
|
1187
|
+
let p = y.getAttribute("data-parent-id");
|
|
1188
|
+
p || (p = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", p));
|
|
1189
1189
|
const v = {
|
|
1190
1190
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1191
|
-
parentId:
|
|
1191
|
+
parentId: p,
|
|
1192
1192
|
position: w,
|
|
1193
1193
|
effect: t._effect
|
|
1194
1194
|
};
|
|
@@ -1201,22 +1201,22 @@ function Zt({
|
|
|
1201
1201
|
"state",
|
|
1202
1202
|
`return (${t._effect})(state)`
|
|
1203
1203
|
)(n);
|
|
1204
|
-
} catch (
|
|
1205
|
-
console.error("Error evaluating effect function during mount:",
|
|
1204
|
+
} catch (U) {
|
|
1205
|
+
console.error("Error evaluating effect function during mount:", U), S = n;
|
|
1206
1206
|
}
|
|
1207
1207
|
else
|
|
1208
1208
|
S = n;
|
|
1209
1209
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1210
|
-
const
|
|
1211
|
-
f.replaceWith(
|
|
1212
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1210
|
+
const W = document.createTextNode(String(S));
|
|
1211
|
+
f.replaceWith(W);
|
|
1212
|
+
}, [t._stateKey, t._path.join("."), t._effect]), at("span", {
|
|
1213
1213
|
ref: c,
|
|
1214
1214
|
style: { display: "none" },
|
|
1215
1215
|
"data-signal-id": m
|
|
1216
1216
|
});
|
|
1217
1217
|
}
|
|
1218
|
-
function
|
|
1219
|
-
const c =
|
|
1218
|
+
function de(t) {
|
|
1219
|
+
const c = xt(
|
|
1220
1220
|
(m) => {
|
|
1221
1221
|
const f = o.getState().stateComponents.get(t._stateKey) || {
|
|
1222
1222
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1228,22 +1228,22 @@ function ge(t) {
|
|
|
1228
1228
|
},
|
|
1229
1229
|
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1230
1230
|
);
|
|
1231
|
-
return
|
|
1231
|
+
return at("text", {}, String(c));
|
|
1232
1232
|
}
|
|
1233
|
-
function
|
|
1233
|
+
function Yt({
|
|
1234
1234
|
stateKey: t,
|
|
1235
1235
|
itemComponentId: c,
|
|
1236
1236
|
itemPath: m,
|
|
1237
1237
|
children: f
|
|
1238
1238
|
}) {
|
|
1239
|
-
const [, y] =
|
|
1240
|
-
return
|
|
1241
|
-
w.height > 0 && w.height !==
|
|
1239
|
+
const [, y] = Q({}), [b, w] = Ft(), p = Z(null);
|
|
1240
|
+
return nt(() => {
|
|
1241
|
+
w.height > 0 && w.height !== p.current && (p.current = w.height, o.getState().setShadowMetadata(t, m, {
|
|
1242
1242
|
virtualizer: {
|
|
1243
1243
|
itemHeight: w.height
|
|
1244
1244
|
}
|
|
1245
1245
|
}));
|
|
1246
|
-
}, [w.height, t, m]),
|
|
1246
|
+
}, [w.height, t, m]), ct(() => {
|
|
1247
1247
|
const a = `${t}////${c}`, v = o.getState().stateComponents.get(t) || {
|
|
1248
1248
|
components: /* @__PURE__ */ new Map()
|
|
1249
1249
|
};
|
|
@@ -1254,14 +1254,14 @@ function Xt({
|
|
|
1254
1254
|
const n = o.getState().stateComponents.get(t);
|
|
1255
1255
|
n && n.components.delete(a);
|
|
1256
1256
|
};
|
|
1257
|
-
}, [t, c, m.join(".")]), /* @__PURE__ */
|
|
1257
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ mt("div", { ref: b, children: f });
|
|
1258
1258
|
}
|
|
1259
1259
|
export {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1260
|
+
kt as $cogsSignal,
|
|
1261
|
+
de as $cogsSignalStore,
|
|
1262
|
+
ie as addStateOptions,
|
|
1263
|
+
ce as createCogsState,
|
|
1264
|
+
le as notifyComponent,
|
|
1265
|
+
Bt as useCogsStateFn
|
|
1266
1266
|
};
|
|
1267
1267
|
//# sourceMappingURL=CogsState.jsx.map
|