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