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