cogsbox-state 0.5.373 → 0.5.374
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 +375 -373
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +6 -2
package/dist/CogsState.jsx
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as Q, useRef as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as pe } from "react/jsx-runtime";
|
|
3
|
+
import { useState as Q, useRef as Y, useEffect as oe, useLayoutEffect as le, useMemo as Ee, createElement as de, useSyncExternalStore as Le, startTransition as Re, useCallback as Ne } from "react";
|
|
4
|
+
import { transformStateFunc as De, isDeepEqual as q, isFunction as K, getNestedValue as Z, getDifferences as we, debounce as Ue } from "./utility.js";
|
|
5
|
+
import { pushFunc as ye, updateFn as ce, cutFunc as Se, ValidationWrapper as je, FormControlComponent as He } from "./Functions.jsx";
|
|
6
|
+
import Fe from "superjson";
|
|
7
|
+
import { v4 as _e } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as r, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
9
|
+
import { getGlobalStore as r, formRefStore as Ce } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Me } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Be } from "fast-json-patch";
|
|
12
|
+
import We from "react-use-measure";
|
|
13
|
+
function $e(e, i) {
|
|
14
14
|
const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
|
|
15
15
|
g(e, {
|
|
16
16
|
...T,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function ke({
|
|
21
21
|
stateKey: e,
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = re(e) || {}, T = m[e] || {},
|
|
25
|
+
const g = re(e) || {}, T = m[e] || {}, N = r.getState().setInitialStateOptions, p = { ...T, ...g };
|
|
26
26
|
let v = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const a in i)
|
|
29
29
|
p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (v = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
|
|
30
30
|
!q(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
|
|
31
|
-
v &&
|
|
31
|
+
v && N(e, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function ft(e, { formElements: i, validation: m }) {
|
|
34
34
|
return { initialState: e, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const St = (e, i) => {
|
|
37
37
|
let m = e;
|
|
38
|
-
const [g, T] =
|
|
38
|
+
const [g, T] = De(m);
|
|
39
39
|
(Object.keys(T).length > 0 || i && Object.keys(i).length > 0) && Object.keys(T).forEach((v) => {
|
|
40
40
|
T[v] = T[v] || {}, T[v].formElements = {
|
|
41
41
|
...i?.formElements,
|
|
@@ -45,14 +45,14 @@ const ft = (e, i) => {
|
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, re(v) || r.getState().setInitialStateOptions(v, T[v]);
|
|
47
47
|
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
|
-
const
|
|
49
|
-
const [h] = Q(a?.componentId ??
|
|
50
|
-
|
|
48
|
+
const N = (v, a) => {
|
|
49
|
+
const [h] = Q(a?.componentId ?? _e());
|
|
50
|
+
ke({
|
|
51
51
|
stateKey: v,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: T
|
|
54
54
|
});
|
|
55
|
-
const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H,
|
|
55
|
+
const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [H, R] = Qe(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
@@ -68,49 +68,49 @@ const ft = (e, i) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return R;
|
|
72
72
|
};
|
|
73
73
|
function p(v, a) {
|
|
74
|
-
|
|
74
|
+
ke({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && Ze(v, a), Te(v);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: N, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
78
|
+
setUpdaterState: me,
|
|
79
79
|
setState: ne,
|
|
80
80
|
getInitialOptions: re,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
81
|
+
getKeyState: Pe,
|
|
82
|
+
getValidationErrors: ze,
|
|
83
|
+
setStateLog: qe,
|
|
84
|
+
updateInitialStateGlobal: Oe,
|
|
85
|
+
addValidationError: Je,
|
|
86
86
|
removeValidationError: X,
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = r.getState(),
|
|
87
|
+
setServerSyncActions: Ye
|
|
88
|
+
} = r.getState(), be = (e, i, m, g, T) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
i,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const p = `${g}-${i}-${
|
|
95
|
+
const N = K(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
96
|
+
if (N && g) {
|
|
97
|
+
const p = `${g}-${i}-${N}`;
|
|
98
98
|
let v;
|
|
99
99
|
try {
|
|
100
|
-
v =
|
|
100
|
+
v = he(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: e,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: T ?? v
|
|
107
|
-
}, h =
|
|
107
|
+
}, h = Fe.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(h.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, he = (e) => {
|
|
114
114
|
if (!e) return null;
|
|
115
115
|
try {
|
|
116
116
|
const i = window.localStorage.getItem(e);
|
|
@@ -118,29 +118,29 @@ const ft = (e, i) => {
|
|
|
118
118
|
} catch (i) {
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m = r.getState().cogsStateStore[e], { sessionId: g } =
|
|
121
|
+
}, Ze = (e, i) => {
|
|
122
|
+
const m = r.getState().cogsStateStore[e], { sessionId: g } = Me(), T = K(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (T && g) {
|
|
124
|
-
const
|
|
124
|
+
const N = he(
|
|
125
125
|
`${g}-${e}-${T}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return ne(e,
|
|
127
|
+
if (N && N.lastUpdated > (N.lastSyncedWithServer || 0))
|
|
128
|
+
return ne(e, N.state), Te(e), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ve = (e, i, m, g, T, N) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: Ie(
|
|
135
135
|
e,
|
|
136
136
|
g,
|
|
137
137
|
T,
|
|
138
|
-
|
|
138
|
+
N
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
Oe(e, p.initialState), me(e, p.updaterState), ne(e, p.state);
|
|
143
|
+
}, Te = (e) => {
|
|
144
144
|
const i = r.getState().stateComponents.get(e);
|
|
145
145
|
if (!i) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
@@ -149,7 +149,7 @@ const ft = (e, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, mt = (e, i) => {
|
|
153
153
|
const m = r.getState().stateComponents.get(e);
|
|
154
154
|
if (m) {
|
|
155
155
|
const g = `${e}////${i}`, T = m.components.get(g);
|
|
@@ -157,22 +157,22 @@ const ft = (e, i) => {
|
|
|
157
157
|
return;
|
|
158
158
|
T && T.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Xe = (e, i, m, g) => {
|
|
161
161
|
switch (e) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: Z(i, g),
|
|
165
|
+
newValue: Z(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: Z(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: Z(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,12 +180,12 @@ const ft = (e, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Qe(e, {
|
|
184
184
|
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: T,
|
|
188
|
-
reactiveDeps:
|
|
188
|
+
reactiveDeps: N,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: v,
|
|
191
191
|
initialState: a,
|
|
@@ -193,12 +193,12 @@ function Xe(e, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [H,
|
|
196
|
+
const [H, R] = Q({}), { sessionId: D } = Me();
|
|
197
197
|
let F = !i;
|
|
198
|
-
const [I] = Q(i ??
|
|
198
|
+
const [I] = Q(i ?? _e()), l = r.getState().stateLog[I], ue = Y(/* @__PURE__ */ new Set()), ee = Y(v ?? _e()), G = Y(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
G.current = re(I) ?? null, oe(() => {
|
|
202
202
|
if (h && h.stateKey === I && h.path?.[0]) {
|
|
203
203
|
ne(I, (o) => ({
|
|
204
204
|
...o,
|
|
@@ -212,164 +212,164 @@ function Xe(e, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [h]), oe(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
$e(I, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const t =
|
|
218
|
+
const t = G.current, s = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, c = r.getState().initialStateGlobal[I];
|
|
219
219
|
if (!(c && !q(c, a) || !c) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
222
|
const E = K(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
|
|
223
|
-
E &&
|
|
224
|
-
let y = a,
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
223
|
+
E && D && (u = he(`${D}-${I}-${E}`));
|
|
224
|
+
let y = a, w = !1;
|
|
225
|
+
const $ = s ? Date.now() : 0, O = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && $ > O ? (y = t.serverState.data, w = !0) : u && O > x && (y = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(y)), r.getState().initializeShadowState(I, a), Ve(
|
|
227
227
|
I,
|
|
228
228
|
a,
|
|
229
229
|
y,
|
|
230
230
|
ae,
|
|
231
231
|
ee.current,
|
|
232
|
-
|
|
233
|
-
),
|
|
232
|
+
D
|
|
233
|
+
), w && E && D && be(y, I, t, D, Date.now()), Te(I), (Array.isArray(p) ? p : [p || "component"]).includes("none") || R({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
F &&
|
|
240
|
+
]), le(() => {
|
|
241
|
+
F && $e(I, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: T,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: G.current?.middleware
|
|
247
247
|
});
|
|
248
248
|
const t = `${I}////${ee.current}`, o = r.getState().stateComponents.get(I) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
251
|
return o.components.set(t, {
|
|
252
|
-
forceUpdate: () =>
|
|
252
|
+
forceUpdate: () => R({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
255
|
+
depsFunction: N || void 0,
|
|
256
256
|
reactiveType: p ?? ["component", "deps"]
|
|
257
|
-
}), r.getState().stateComponents.set(I, o),
|
|
257
|
+
}), r.getState().stateComponents.set(I, o), R({}), () => {
|
|
258
258
|
o && (o.components.delete(t), o.components.size === 0 && r.getState().stateComponents.delete(I));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
261
|
const ae = (t, o, s, c) => {
|
|
262
262
|
if (Array.isArray(o)) {
|
|
263
263
|
const u = `${I}-${o.join(".")}`;
|
|
264
|
-
|
|
264
|
+
ue.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = r.getState();
|
|
267
267
|
ne(I, (u) => {
|
|
268
268
|
const E = K(t) ? t(u) : t, y = `${I}-${o.join(".")}`;
|
|
269
269
|
if (y) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
270
|
+
let V = !1, C = f.signalDomElements.get(y);
|
|
271
|
+
if ((!C || C.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const M = o.slice(0, -1), A = Z(E, M);
|
|
273
|
+
if (Array.isArray(A)) {
|
|
274
|
+
V = !0;
|
|
275
|
+
const _ = `${I}-${M.join(".")}`;
|
|
276
|
+
C = f.signalDomElements.get(_);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (C) {
|
|
280
|
+
const M = V ? Z(E, o.slice(0, -1)) : Z(E, o);
|
|
281
|
+
C.forEach(({ parentId: A, position: _, effect: b }) => {
|
|
282
|
+
const L = document.querySelector(
|
|
283
|
+
`[data-parent-id="${A}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const W = Array.from(
|
|
287
|
-
if (W[
|
|
288
|
-
const
|
|
289
|
-
W[
|
|
285
|
+
if (L) {
|
|
286
|
+
const W = Array.from(L.childNodes);
|
|
287
|
+
if (W[_]) {
|
|
288
|
+
const j = b ? new Function("state", `return (${b})(state)`)(M) : M;
|
|
289
|
+
W[_].textContent = String(j);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c ||
|
|
296
|
-
(c ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || G.current?.validation?.key) && o && X(
|
|
296
|
+
(c || G.current?.validation?.key) + "." + o.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
X(
|
|
298
|
+
const w = o.slice(0, o.length - 1);
|
|
299
|
+
s.updateType === "cut" && G.current?.validation?.key && X(
|
|
300
|
+
G.current?.validation?.key + "." + w.join(".")
|
|
301
|
+
), s.updateType === "insert" && G.current?.validation?.key && ze(
|
|
302
|
+
G.current?.validation?.key + "." + w.join(".")
|
|
303
|
+
).filter(([C, M]) => {
|
|
304
|
+
let A = C?.split(".").length;
|
|
305
|
+
if (C == w.join(".") && A == w.length - 1) {
|
|
306
|
+
let _ = C + "." + w;
|
|
307
|
+
X(C), Je(_, M);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const $ = f.stateComponents.get(I);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", $), $) {
|
|
312
|
+
const V = we(u, E), C = new Set(V), M = s.updateType === "update" ? o.join(".") : o.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
|
+
A,
|
|
315
|
+
_
|
|
316
|
+
] of $.components.entries()) {
|
|
317
|
+
let b = !1;
|
|
318
|
+
const L = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", _), !L.includes("none")) {
|
|
320
|
+
if (L.includes("all")) {
|
|
321
|
+
_.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const W of
|
|
326
|
-
let
|
|
324
|
+
if (L.includes("component") && ((_.paths.has(M) || _.paths.has("")) && (b = !0), !b))
|
|
325
|
+
for (const W of C) {
|
|
326
|
+
let j = W;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (_.paths.has(j)) {
|
|
329
|
+
b = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const se = j.lastIndexOf(".");
|
|
333
|
+
if (se !== -1) {
|
|
334
|
+
const k = j.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
se
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(j.substring(se + 1))
|
|
340
|
+
) && _.paths.has(k)) {
|
|
341
|
+
b = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
j = k;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
j = "";
|
|
347
|
+
if (j === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (b) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const W =
|
|
354
|
-
let
|
|
355
|
-
typeof W == "boolean" ? W && (
|
|
352
|
+
if (!b && L.includes("deps") && _.depsFunction) {
|
|
353
|
+
const W = _.depsFunction(E);
|
|
354
|
+
let j = !1;
|
|
355
|
+
typeof W == "boolean" ? W && (j = !0) : q(_.deps, W) || (_.deps = W, j = !0), j && (b = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
b && _.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
o = o.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const O = Date.now();
|
|
362
|
+
o = o.map((V, C) => {
|
|
363
|
+
const M = o.slice(0, -1), A = Z(E, M);
|
|
364
|
+
return C === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (A.length - 1).toString() : V;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue: x, newValue: U } =
|
|
366
|
+
const { oldValue: x, newValue: U } = Xe(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
369
|
E,
|
|
370
370
|
o
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), J = {
|
|
372
|
+
timeStamp: O,
|
|
373
373
|
stateKey: I,
|
|
374
374
|
path: o,
|
|
375
375
|
updateType: s.updateType,
|
|
@@ -382,65 +382,65 @@ function Xe(e, {
|
|
|
382
382
|
f.updateShadowAtPath(I, o, E);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(I,
|
|
385
|
+
const V = o.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(I, V, U);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
f.removeShadowArrayElement(I,
|
|
389
|
+
const C = o.slice(0, -1), M = parseInt(o[o.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(I, C, M);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (qe(I, (V) => {
|
|
394
|
+
const M = [...V ?? [], J].reduce((A, _) => {
|
|
395
|
+
const b = `${_.stateKey}:${JSON.stringify(_.path)}`, L = A.get(b);
|
|
396
|
+
return L ? (L.timeStamp = Math.max(L.timeStamp, _.timeStamp), L.newValue = _.newValue, L.oldValue = L.oldValue ?? _.oldValue, L.updateType = _.updateType) : A.set(b, { ..._ }), A;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(M.values());
|
|
399
|
+
}), be(
|
|
400
400
|
E,
|
|
401
401
|
I,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
G.current,
|
|
403
|
+
D
|
|
404
|
+
), G.current?.middleware && G.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
406
|
+
update: J
|
|
407
|
+
}), G.current?.serverSync) {
|
|
408
|
+
const V = f.serverState[I], C = G.current?.serverSync;
|
|
409
|
+
Ye(I, {
|
|
410
|
+
syncKey: typeof C.syncKey == "string" ? C.syncKey : C.syncKey({ state: E }),
|
|
411
|
+
rollBackState: V,
|
|
412
|
+
actionTimeStamp: Date.now() + (C.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
return E;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
r.getState().updaterState[I] || (
|
|
419
|
+
r.getState().updaterState[I] || (me(
|
|
420
420
|
I,
|
|
421
|
-
|
|
421
|
+
Ie(
|
|
422
422
|
I,
|
|
423
423
|
ae,
|
|
424
424
|
ee.current,
|
|
425
|
-
|
|
425
|
+
D
|
|
426
426
|
)
|
|
427
|
-
), r.getState().cogsStateStore[I] || ne(I, e), r.getState().initialStateGlobal[I] ||
|
|
428
|
-
const d =
|
|
427
|
+
), r.getState().cogsStateStore[I] || ne(I, e), r.getState().initialStateGlobal[I] || Oe(I, e));
|
|
428
|
+
const d = Ee(() => Ie(
|
|
429
429
|
I,
|
|
430
430
|
ae,
|
|
431
431
|
ee.current,
|
|
432
|
-
|
|
433
|
-
), [I,
|
|
434
|
-
return [
|
|
432
|
+
D
|
|
433
|
+
), [I, D]);
|
|
434
|
+
return [Pe(I), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function Ie(e, i, m, g) {
|
|
437
437
|
const T = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
438
|
+
let N = 0;
|
|
439
439
|
const p = (h) => {
|
|
440
440
|
const n = h.join(".");
|
|
441
441
|
for (const [S] of T)
|
|
442
442
|
(S === n || S.startsWith(n + ".")) && T.delete(S);
|
|
443
|
-
|
|
443
|
+
N++;
|
|
444
444
|
}, v = {
|
|
445
445
|
removeValidation: (h) => {
|
|
446
446
|
h?.validationKey && X(h.validationKey);
|
|
@@ -449,24 +449,24 @@ function me(e, i, m, g) {
|
|
|
449
449
|
const n = r.getState().getInitialOptions(e)?.validation;
|
|
450
450
|
n?.key && X(n?.key), h?.validationKey && X(h.validationKey);
|
|
451
451
|
const S = r.getState().initialStateGlobal[e];
|
|
452
|
-
r.getState().clearSelectedIndexesForState(e), T.clear(),
|
|
453
|
-
const H = a(S, []),
|
|
454
|
-
F && localStorage.removeItem(F),
|
|
452
|
+
r.getState().clearSelectedIndexesForState(e), T.clear(), N++;
|
|
453
|
+
const H = a(S, []), R = re(e), D = K(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, F = `${g}-${e}-${D}`;
|
|
454
|
+
F && localStorage.removeItem(F), me(e, H), ne(e, S);
|
|
455
455
|
const I = r.getState().stateComponents.get(e);
|
|
456
456
|
return I && I.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (h) => {
|
|
461
|
-
T.clear(),
|
|
462
|
-
const n =
|
|
461
|
+
T.clear(), N++;
|
|
462
|
+
const n = Ie(
|
|
463
463
|
e,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = r.getState().initialStateGlobal[e], H = re(e),
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
467
|
+
), S = r.getState().initialStateGlobal[e], H = re(e), R = K(H?.localStorage?.key) ? H?.localStorage?.key(S) : H?.localStorage?.key, D = `${g}-${e}-${R}`;
|
|
468
|
+
return localStorage.getItem(D) && localStorage.removeItem(D), Re(() => {
|
|
469
|
+
Oe(e, h), r.getState().initializeShadowState(e, h), me(e, n), ne(e, h);
|
|
470
470
|
const F = r.getState().stateComponents.get(e);
|
|
471
471
|
F && F.components.forEach((I) => {
|
|
472
472
|
I.forceUpdate();
|
|
@@ -480,27 +480,27 @@ function me(e, i, m, g) {
|
|
|
480
480
|
_isLoading: r.getState().isLoadingGlobal[e],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const h = r.getState().serverState[e];
|
|
483
|
-
return !!(h && q(h,
|
|
483
|
+
return !!(h && q(h, Pe(e)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(h, n = [], S) {
|
|
487
487
|
const H = n.map(String).join(".");
|
|
488
488
|
T.get(H);
|
|
489
|
-
const
|
|
489
|
+
const R = function() {
|
|
490
490
|
return r().getNestedState(e, n);
|
|
491
491
|
};
|
|
492
492
|
Object.keys(v).forEach((I) => {
|
|
493
|
-
|
|
493
|
+
R[I] = v[I];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(I, l,
|
|
495
|
+
const D = {
|
|
496
|
+
apply(I, l, ue) {
|
|
497
497
|
return console.log(
|
|
498
498
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${n.join(".")}`
|
|
499
499
|
), console.trace("Apply trap stack trace"), r().getNestedState(e, n);
|
|
500
500
|
},
|
|
501
501
|
get(I, l) {
|
|
502
502
|
S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const ue = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,7 +523,7 @@ function me(e, i, m, 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" && !ue.has(l)) {
|
|
527
527
|
const d = `${e}////${m}`, t = r.getState().stateComponents.get(e);
|
|
528
528
|
if (t) {
|
|
529
529
|
const o = t.components.get(d);
|
|
@@ -540,7 +540,7 @@ function me(e, i, m, g) {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
543
|
+
return () => we(
|
|
544
544
|
r.getState().cogsStateStore[e],
|
|
545
545
|
r.getState().initialStateGlobal[e]
|
|
546
546
|
);
|
|
@@ -568,7 +568,7 @@ function me(e, i, m, g) {
|
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o =
|
|
571
|
+
const d = r.getState().getNestedState(e, n), t = r.getState().initialStateGlobal[e], o = Z(t, n);
|
|
572
572
|
return q(d, o) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
@@ -576,7 +576,7 @@ function me(e, i, m, g) {
|
|
|
576
576
|
const d = r().getNestedState(
|
|
577
577
|
e,
|
|
578
578
|
n
|
|
579
|
-
), t = r.getState().initialStateGlobal[e], o =
|
|
579
|
+
), t = r.getState().initialStateGlobal[e], o = Z(t, n);
|
|
580
580
|
return q(d, o) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
@@ -622,157 +622,159 @@ function me(e, i, m, g) {
|
|
|
622
622
|
overscan: s = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} = t, u =
|
|
625
|
+
} = t, u = Y(!1), E = Y(null), [y, w] = Q({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
628
|
+
}), [$, O] = Q("IDLE_AT_TOP"), x = Y(!1), U = Y(0), J = Y(f), [V, C] = Q(0);
|
|
629
629
|
oe(() => r.getState().subscribeToShadowState(e, () => {
|
|
630
|
-
|
|
630
|
+
C((P) => P + 1);
|
|
631
631
|
}), [e]);
|
|
632
|
-
const
|
|
632
|
+
const M = r().getNestedState(
|
|
633
633
|
e,
|
|
634
634
|
n
|
|
635
|
-
),
|
|
636
|
-
const
|
|
637
|
-
let
|
|
635
|
+
), A = M.length, { totalHeight: _, positions: b } = Ee(() => {
|
|
636
|
+
const k = r.getState().getShadowMetadata(e, n) || [];
|
|
637
|
+
let P = 0;
|
|
638
638
|
const z = [];
|
|
639
|
-
for (let B = 0; B <
|
|
640
|
-
z[B] =
|
|
641
|
-
const te =
|
|
642
|
-
|
|
639
|
+
for (let B = 0; B < A; B++) {
|
|
640
|
+
z[B] = P;
|
|
641
|
+
const te = k[B]?.virtualizer?.itemHeight;
|
|
642
|
+
P += te || o;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: P, positions: z };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
646
|
+
A,
|
|
647
647
|
e,
|
|
648
648
|
n.join("."),
|
|
649
649
|
o,
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(te,
|
|
655
|
-
), B = z.map((te) =>
|
|
650
|
+
V
|
|
651
|
+
]), L = Ee(() => {
|
|
652
|
+
const k = Math.max(0, y.startIndex), P = Math.min(A, y.endIndex), z = Array.from(
|
|
653
|
+
{ length: P - k },
|
|
654
|
+
(te, ie) => k + ie
|
|
655
|
+
), B = z.map((te) => M[te]);
|
|
656
656
|
return a(B, n, {
|
|
657
657
|
...S,
|
|
658
658
|
validIndices: z
|
|
659
659
|
});
|
|
660
|
-
}, [y.startIndex, y.endIndex,
|
|
661
|
-
|
|
662
|
-
const
|
|
660
|
+
}, [y.startIndex, y.endIndex, M, A]);
|
|
661
|
+
le(() => {
|
|
662
|
+
const k = !q(
|
|
663
663
|
f,
|
|
664
|
-
|
|
665
|
-
),
|
|
666
|
-
if (
|
|
667
|
-
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"),
|
|
664
|
+
J.current
|
|
665
|
+
), P = A > U.current;
|
|
666
|
+
if (k) {
|
|
667
|
+
console.log("TRANSITION: Deps changed -> IDLE_AT_TOP"), O("IDLE_AT_TOP");
|
|
668
668
|
return;
|
|
669
669
|
}
|
|
670
|
-
|
|
670
|
+
P && $ === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
671
671
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
672
|
-
),
|
|
673
|
-
}, [
|
|
674
|
-
const
|
|
675
|
-
if (
|
|
676
|
-
let
|
|
677
|
-
if (
|
|
672
|
+
), O("GETTING_HEIGHTS")), U.current = A, J.current = f;
|
|
673
|
+
}, [A, ...f]), le(() => {
|
|
674
|
+
const k = E.current;
|
|
675
|
+
if (!k) return;
|
|
676
|
+
let P;
|
|
677
|
+
if ($ === "IDLE_AT_TOP" && c && A > 0)
|
|
678
678
|
console.log(
|
|
679
679
|
"ACTION (IDLE_AT_TOP): Data has arrived -> GETTING_HEIGHTS"
|
|
680
|
-
),
|
|
681
|
-
else if (
|
|
680
|
+
), O("GETTING_HEIGHTS");
|
|
681
|
+
else if ($ === "GETTING_HEIGHTS")
|
|
682
682
|
console.log(
|
|
683
683
|
"ACTION (GETTING_HEIGHTS): Setting range to end and starting loop."
|
|
684
|
-
),
|
|
685
|
-
startIndex: Math.max(0,
|
|
686
|
-
endIndex:
|
|
687
|
-
}),
|
|
688
|
-
const z =
|
|
689
|
-
((r.getState().getShadowMetadata(e, n) || [])[z]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(
|
|
684
|
+
), w({
|
|
685
|
+
startIndex: Math.max(0, A - 10 - s),
|
|
686
|
+
endIndex: A
|
|
687
|
+
}), P = setInterval(() => {
|
|
688
|
+
const z = A - 1;
|
|
689
|
+
((r.getState().getShadowMetadata(e, n) || [])[z]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(P), u.current || (console.log(
|
|
690
690
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
691
|
-
),
|
|
691
|
+
), O("SCROLLING_TO_BOTTOM")));
|
|
692
692
|
}, 100);
|
|
693
|
-
else if (
|
|
693
|
+
else if ($ === "SCROLLING_TO_BOTTOM") {
|
|
694
694
|
console.log(
|
|
695
695
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
696
|
-
);
|
|
697
|
-
const z =
|
|
698
|
-
|
|
699
|
-
top:
|
|
696
|
+
), x.current = !0;
|
|
697
|
+
const z = U.current === 0 ? "auto" : "smooth";
|
|
698
|
+
k.scrollTo({
|
|
699
|
+
top: k.scrollHeight,
|
|
700
700
|
behavior: z
|
|
701
701
|
});
|
|
702
702
|
const B = setTimeout(
|
|
703
703
|
() => {
|
|
704
704
|
console.log(
|
|
705
705
|
"ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
|
|
706
|
-
), u.current = !1,
|
|
706
|
+
), x.current = !1, u.current = !1, O("LOCKED_AT_BOTTOM");
|
|
707
707
|
},
|
|
708
708
|
z === "smooth" ? 500 : 50
|
|
709
709
|
);
|
|
710
710
|
return () => clearTimeout(B);
|
|
711
711
|
}
|
|
712
712
|
return () => {
|
|
713
|
-
|
|
713
|
+
P && clearInterval(P);
|
|
714
714
|
};
|
|
715
|
-
}, [
|
|
716
|
-
const
|
|
717
|
-
if (
|
|
718
|
-
const
|
|
719
|
-
|
|
715
|
+
}, [$, A, b]), oe(() => {
|
|
716
|
+
const k = E.current;
|
|
717
|
+
if (!k) return;
|
|
718
|
+
const P = () => {
|
|
719
|
+
if (x.current)
|
|
720
|
+
return;
|
|
721
|
+
k.scrollHeight - k.scrollTop - k.clientHeight < 1 ? u.current = !1 : (console.log(
|
|
720
722
|
"USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
|
|
721
|
-
), u.current = !0,
|
|
722
|
-
const { scrollTop: B, clientHeight: te } =
|
|
723
|
-
let
|
|
724
|
-
for (;
|
|
725
|
-
const
|
|
726
|
-
|
|
723
|
+
), u.current = !0, O("IDLE_NOT_AT_BOTTOM"));
|
|
724
|
+
const { scrollTop: B, clientHeight: te } = k;
|
|
725
|
+
let ie = 0, ge = A - 1;
|
|
726
|
+
for (; ie <= ge; ) {
|
|
727
|
+
const ve = Math.floor((ie + ge) / 2);
|
|
728
|
+
b[ve] < B ? ie = ve + 1 : ge = ve - 1;
|
|
727
729
|
}
|
|
728
|
-
const
|
|
729
|
-
let
|
|
730
|
-
const
|
|
731
|
-
for (;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
startIndex:
|
|
735
|
-
endIndex: Math.min(
|
|
730
|
+
const Ae = Math.max(0, ge - s);
|
|
731
|
+
let fe = Ae;
|
|
732
|
+
const Ge = B + te;
|
|
733
|
+
for (; fe < A && b[fe] < Ge; )
|
|
734
|
+
fe++;
|
|
735
|
+
w({
|
|
736
|
+
startIndex: Ae,
|
|
737
|
+
endIndex: Math.min(A, fe + s)
|
|
736
738
|
});
|
|
737
739
|
};
|
|
738
|
-
return
|
|
740
|
+
return k.addEventListener("scroll", P, {
|
|
739
741
|
passive: !0
|
|
740
|
-
}), () =>
|
|
741
|
-
}, [
|
|
742
|
-
const
|
|
742
|
+
}), () => k.removeEventListener("scroll", P);
|
|
743
|
+
}, [A, b, $]);
|
|
744
|
+
const W = Ne(() => {
|
|
743
745
|
console.log(
|
|
744
746
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
745
|
-
),
|
|
746
|
-
}, []),
|
|
747
|
-
(
|
|
748
|
-
E.current &&
|
|
749
|
-
top:
|
|
750
|
-
behavior:
|
|
747
|
+
), O("SCROLLING_TO_BOTTOM");
|
|
748
|
+
}, []), j = Ne(
|
|
749
|
+
(k, P = "smooth") => {
|
|
750
|
+
E.current && b[k] !== void 0 && (O("IDLE_NOT_AT_BOTTOM"), E.current.scrollTo({
|
|
751
|
+
top: b[k],
|
|
752
|
+
behavior: P
|
|
751
753
|
}));
|
|
752
754
|
},
|
|
753
|
-
[
|
|
754
|
-
),
|
|
755
|
+
[b]
|
|
756
|
+
), se = {
|
|
755
757
|
outer: {
|
|
756
758
|
ref: E,
|
|
757
759
|
style: { overflowY: "auto", height: "100%" }
|
|
758
760
|
},
|
|
759
761
|
inner: {
|
|
760
762
|
style: {
|
|
761
|
-
height: `${
|
|
763
|
+
height: `${_}px`,
|
|
762
764
|
position: "relative"
|
|
763
765
|
}
|
|
764
766
|
},
|
|
765
767
|
list: {
|
|
766
768
|
style: {
|
|
767
|
-
transform: `translateY(${
|
|
769
|
+
transform: `translateY(${b[y.startIndex] || 0}px)`
|
|
768
770
|
}
|
|
769
771
|
}
|
|
770
772
|
};
|
|
771
773
|
return {
|
|
772
|
-
virtualState:
|
|
773
|
-
virtualizerProps:
|
|
774
|
-
scrollToBottom:
|
|
775
|
-
scrollToIndex:
|
|
774
|
+
virtualState: L,
|
|
775
|
+
virtualizerProps: se,
|
|
776
|
+
scrollToBottom: W,
|
|
777
|
+
scrollToIndex: j
|
|
776
778
|
};
|
|
777
779
|
};
|
|
778
780
|
if (l === "stateSort")
|
|
@@ -806,19 +808,19 @@ function me(e, i, m, g) {
|
|
|
806
808
|
const u = o[c], E = [...n, c.toString()], y = a(u, E, S);
|
|
807
809
|
return t(u, y, {
|
|
808
810
|
register: () => {
|
|
809
|
-
const [,
|
|
810
|
-
|
|
811
|
-
const x = `${e}////${
|
|
811
|
+
const [, $] = Q({}), O = `${m}-${n.join(".")}-${c}`;
|
|
812
|
+
le(() => {
|
|
813
|
+
const x = `${e}////${O}`, U = r.getState().stateComponents.get(e) || {
|
|
812
814
|
components: /* @__PURE__ */ new Map()
|
|
813
815
|
};
|
|
814
816
|
return U.components.set(x, {
|
|
815
|
-
forceUpdate: () =>
|
|
817
|
+
forceUpdate: () => $({}),
|
|
816
818
|
paths: /* @__PURE__ */ new Set([E.join(".")])
|
|
817
819
|
}), r.getState().stateComponents.set(e, U), () => {
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
+
const J = r.getState().stateComponents.get(e);
|
|
821
|
+
J && J.components.delete(x);
|
|
820
822
|
};
|
|
821
|
-
}, [e,
|
|
823
|
+
}, [e, O]);
|
|
822
824
|
},
|
|
823
825
|
index: f,
|
|
824
826
|
originalIndex: c
|
|
@@ -842,7 +844,7 @@ function me(e, i, m, g) {
|
|
|
842
844
|
);
|
|
843
845
|
});
|
|
844
846
|
if (l === "$stateMap")
|
|
845
|
-
return (t) =>
|
|
847
|
+
return (t) => de(Ke, {
|
|
846
848
|
proxy: {
|
|
847
849
|
_stateKey: e,
|
|
848
850
|
_path: n,
|
|
@@ -855,11 +857,11 @@ function me(e, i, m, g) {
|
|
|
855
857
|
return (t) => {
|
|
856
858
|
const o = r.getState().getNestedState(e, n);
|
|
857
859
|
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
858
|
-
const u = o[c], E = [...n, c.toString()], y = a(u, E, S),
|
|
859
|
-
return
|
|
860
|
+
const u = o[c], E = [...n, c.toString()], y = a(u, E, S), w = `${m}-${n.join(".")}-${c}`;
|
|
861
|
+
return de(tt, {
|
|
860
862
|
key: c,
|
|
861
863
|
stateKey: e,
|
|
862
|
-
itemComponentId:
|
|
864
|
+
itemComponentId: w,
|
|
863
865
|
itemPath: E,
|
|
864
866
|
children: t(
|
|
865
867
|
u,
|
|
@@ -876,7 +878,7 @@ function me(e, i, m, g) {
|
|
|
876
878
|
if (l === "stateFlattenOn")
|
|
877
879
|
return (t) => {
|
|
878
880
|
const o = h;
|
|
879
|
-
T.clear(),
|
|
881
|
+
T.clear(), N++;
|
|
880
882
|
const s = o.flatMap(
|
|
881
883
|
(c) => c[t] ?? []
|
|
882
884
|
);
|
|
@@ -899,7 +901,7 @@ function me(e, i, m, g) {
|
|
|
899
901
|
return a(s, c);
|
|
900
902
|
};
|
|
901
903
|
if (l === "insert")
|
|
902
|
-
return (t) => (p(n),
|
|
904
|
+
return (t) => (p(n), ye(i, t, n, e), a(
|
|
903
905
|
r.getState().getNestedState(e, n),
|
|
904
906
|
n
|
|
905
907
|
));
|
|
@@ -909,26 +911,26 @@ function me(e, i, m, g) {
|
|
|
909
911
|
let u = null;
|
|
910
912
|
if (!c.some((y) => {
|
|
911
913
|
if (o) {
|
|
912
|
-
const
|
|
913
|
-
(
|
|
914
|
+
const $ = o.every(
|
|
915
|
+
(O) => q(y[O], f[O])
|
|
914
916
|
);
|
|
915
|
-
return
|
|
917
|
+
return $ && (u = y), $;
|
|
916
918
|
}
|
|
917
|
-
const
|
|
918
|
-
return
|
|
919
|
+
const w = q(y, f);
|
|
920
|
+
return w && (u = y), w;
|
|
919
921
|
}))
|
|
920
|
-
p(n),
|
|
922
|
+
p(n), ye(i, f, n, e);
|
|
921
923
|
else if (s && u) {
|
|
922
|
-
const y = s(u),
|
|
923
|
-
(
|
|
924
|
+
const y = s(u), w = c.map(
|
|
925
|
+
($) => q($, u) ? y : $
|
|
924
926
|
);
|
|
925
|
-
p(n),
|
|
927
|
+
p(n), ce(i, w, n);
|
|
926
928
|
}
|
|
927
929
|
};
|
|
928
930
|
if (l === "cut")
|
|
929
931
|
return (t, o) => {
|
|
930
932
|
if (!o?.waitForSync)
|
|
931
|
-
return p(n),
|
|
933
|
+
return p(n), Se(i, n, e, t), a(
|
|
932
934
|
r.getState().getNestedState(e, n),
|
|
933
935
|
n
|
|
934
936
|
);
|
|
@@ -936,12 +938,12 @@ function me(e, i, m, g) {
|
|
|
936
938
|
if (l === "cutByValue")
|
|
937
939
|
return (t) => {
|
|
938
940
|
for (let o = 0; o < h.length; o++)
|
|
939
|
-
h[o] === t &&
|
|
941
|
+
h[o] === t && Se(i, n, e, o);
|
|
940
942
|
};
|
|
941
943
|
if (l === "toggleByValue")
|
|
942
944
|
return (t) => {
|
|
943
945
|
const o = h.findIndex((s) => s === t);
|
|
944
|
-
o > -1 ?
|
|
946
|
+
o > -1 ? Se(i, n, e, o) : ye(i, t, n, e);
|
|
945
947
|
};
|
|
946
948
|
if (l === "stateFind")
|
|
947
949
|
return (t) => {
|
|
@@ -966,7 +968,7 @@ function me(e, i, m, g) {
|
|
|
966
968
|
if (!isNaN(Number(ee))) {
|
|
967
969
|
const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
|
|
968
970
|
if (Array.isArray(t) && l === "cut")
|
|
969
|
-
return () =>
|
|
971
|
+
return () => Se(
|
|
970
972
|
i,
|
|
971
973
|
d,
|
|
972
974
|
e,
|
|
@@ -982,13 +984,13 @@ function me(e, i, m, g) {
|
|
|
982
984
|
return r.getState().getNestedState(e, n);
|
|
983
985
|
};
|
|
984
986
|
if (l === "$derive")
|
|
985
|
-
return (d) =>
|
|
987
|
+
return (d) => xe({
|
|
986
988
|
_stateKey: e,
|
|
987
989
|
_path: n,
|
|
988
990
|
_effect: d.toString()
|
|
989
991
|
});
|
|
990
992
|
if (l === "$get")
|
|
991
|
-
return () =>
|
|
993
|
+
return () => xe({
|
|
992
994
|
_stateKey: e,
|
|
993
995
|
_path: n
|
|
994
996
|
});
|
|
@@ -997,7 +999,7 @@ function me(e, i, m, g) {
|
|
|
997
999
|
return r.getState().getSyncInfo(d);
|
|
998
1000
|
}
|
|
999
1001
|
if (l == "getLocalStorage")
|
|
1000
|
-
return (d) =>
|
|
1002
|
+
return (d) => he(g + "-" + e + "-" + d);
|
|
1001
1003
|
if (l === "_selected") {
|
|
1002
1004
|
const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
|
|
1003
1005
|
return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(e, t) : void 0;
|
|
@@ -1007,7 +1009,7 @@ function me(e, i, m, g) {
|
|
|
1007
1009
|
const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
|
|
1008
1010
|
d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
|
|
1009
1011
|
const c = r.getState().getNestedState(e, [...t]);
|
|
1010
|
-
|
|
1012
|
+
ce(i, c, t), p(t);
|
|
1011
1013
|
};
|
|
1012
1014
|
if (l === "toggleSelected")
|
|
1013
1015
|
return () => {
|
|
@@ -1018,13 +1020,13 @@ function me(e, i, m, g) {
|
|
|
1018
1020
|
s === t ? void 0 : t
|
|
1019
1021
|
);
|
|
1020
1022
|
const c = r.getState().getNestedState(e, [...d]);
|
|
1021
|
-
|
|
1023
|
+
ce(i, c, d), p(d);
|
|
1022
1024
|
};
|
|
1023
1025
|
if (n.length == 0) {
|
|
1024
1026
|
if (l === "applyJsonPatch")
|
|
1025
1027
|
return (d) => {
|
|
1026
|
-
const t = r.getState().cogsStateStore[e], s =
|
|
1027
|
-
|
|
1028
|
+
const t = r.getState().cogsStateStore[e], s = Be(t, d).newDocument;
|
|
1029
|
+
Ve(
|
|
1028
1030
|
e,
|
|
1029
1031
|
r.getState().initialStateGlobal[e],
|
|
1030
1032
|
s,
|
|
@@ -1034,57 +1036,57 @@ function me(e, i, m, g) {
|
|
|
1034
1036
|
);
|
|
1035
1037
|
const c = r.getState().stateComponents.get(e);
|
|
1036
1038
|
if (c) {
|
|
1037
|
-
const f =
|
|
1039
|
+
const f = we(t, s), u = new Set(f);
|
|
1038
1040
|
for (const [
|
|
1039
1041
|
E,
|
|
1040
1042
|
y
|
|
1041
1043
|
] of c.components.entries()) {
|
|
1042
|
-
let
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
if (
|
|
1044
|
+
let w = !1;
|
|
1045
|
+
const $ = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
1046
|
+
if (!$.includes("none")) {
|
|
1047
|
+
if ($.includes("all")) {
|
|
1046
1048
|
y.forceUpdate();
|
|
1047
1049
|
continue;
|
|
1048
1050
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
for (const
|
|
1051
|
-
if (y.paths.has(
|
|
1052
|
-
|
|
1051
|
+
if ($.includes("component") && (y.paths.has("") && (w = !0), !w))
|
|
1052
|
+
for (const O of u) {
|
|
1053
|
+
if (y.paths.has(O)) {
|
|
1054
|
+
w = !0;
|
|
1053
1055
|
break;
|
|
1054
1056
|
}
|
|
1055
|
-
let x =
|
|
1057
|
+
let x = O.lastIndexOf(".");
|
|
1056
1058
|
for (; x !== -1; ) {
|
|
1057
|
-
const U =
|
|
1059
|
+
const U = O.substring(0, x);
|
|
1058
1060
|
if (y.paths.has(U)) {
|
|
1059
|
-
|
|
1061
|
+
w = !0;
|
|
1060
1062
|
break;
|
|
1061
1063
|
}
|
|
1062
|
-
const
|
|
1064
|
+
const J = O.substring(
|
|
1063
1065
|
x + 1
|
|
1064
1066
|
);
|
|
1065
|
-
if (!isNaN(Number(
|
|
1066
|
-
const
|
|
1067
|
-
if (
|
|
1068
|
-
const
|
|
1067
|
+
if (!isNaN(Number(J))) {
|
|
1068
|
+
const V = U.lastIndexOf(".");
|
|
1069
|
+
if (V !== -1) {
|
|
1070
|
+
const C = U.substring(
|
|
1069
1071
|
0,
|
|
1070
|
-
|
|
1072
|
+
V
|
|
1071
1073
|
);
|
|
1072
|
-
if (y.paths.has(
|
|
1073
|
-
|
|
1074
|
+
if (y.paths.has(C)) {
|
|
1075
|
+
w = !0;
|
|
1074
1076
|
break;
|
|
1075
1077
|
}
|
|
1076
1078
|
}
|
|
1077
1079
|
}
|
|
1078
1080
|
x = U.lastIndexOf(".");
|
|
1079
1081
|
}
|
|
1080
|
-
if (
|
|
1082
|
+
if (w) break;
|
|
1081
1083
|
}
|
|
1082
|
-
if (!
|
|
1083
|
-
const
|
|
1084
|
+
if (!w && $.includes("deps") && y.depsFunction) {
|
|
1085
|
+
const O = y.depsFunction(s);
|
|
1084
1086
|
let x = !1;
|
|
1085
|
-
typeof
|
|
1087
|
+
typeof O == "boolean" ? O && (x = !0) : q(y.deps, O) || (y.deps = O, x = !0), x && (w = !0);
|
|
1086
1088
|
}
|
|
1087
|
-
|
|
1089
|
+
w && y.forceUpdate();
|
|
1088
1090
|
}
|
|
1089
1091
|
}
|
|
1090
1092
|
}
|
|
@@ -1105,9 +1107,9 @@ function me(e, i, m, g) {
|
|
|
1105
1107
|
});
|
|
1106
1108
|
const c = d.zodSchema.safeParse(o);
|
|
1107
1109
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1108
|
-
const E = u.path, y = u.message,
|
|
1109
|
-
t(
|
|
1110
|
-
}),
|
|
1110
|
+
const E = u.path, y = u.message, w = [d.key, ...E].join(".");
|
|
1111
|
+
t(w, y);
|
|
1112
|
+
}), Te(e), !1);
|
|
1111
1113
|
} catch (s) {
|
|
1112
1114
|
return console.error("Zod schema validation failed", s), !1;
|
|
1113
1115
|
}
|
|
@@ -1116,7 +1118,7 @@ function me(e, i, m, g) {
|
|
|
1116
1118
|
if (l === "getComponents")
|
|
1117
1119
|
return () => r().stateComponents.get(e);
|
|
1118
1120
|
if (l === "getAllFormRefs")
|
|
1119
|
-
return () =>
|
|
1121
|
+
return () => Ce.getState().getFormRefsByStateKey(e);
|
|
1120
1122
|
if (l === "_initialState")
|
|
1121
1123
|
return r.getState().initialStateGlobal[e];
|
|
1122
1124
|
if (l === "_serverState")
|
|
@@ -1129,13 +1131,13 @@ function me(e, i, m, g) {
|
|
|
1129
1131
|
if (l === "removeValidation") return v.removeValidation;
|
|
1130
1132
|
}
|
|
1131
1133
|
if (l === "getFormRef")
|
|
1132
|
-
return () =>
|
|
1134
|
+
return () => Ce.getState().getFormRef(e + "." + n.join("."));
|
|
1133
1135
|
if (l === "validationWrapper")
|
|
1134
1136
|
return ({
|
|
1135
1137
|
children: d,
|
|
1136
1138
|
hideMessage: t
|
|
1137
|
-
}) => /* @__PURE__ */
|
|
1138
|
-
|
|
1139
|
+
}) => /* @__PURE__ */ pe(
|
|
1140
|
+
je,
|
|
1139
1141
|
{
|
|
1140
1142
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1141
1143
|
path: n,
|
|
@@ -1151,21 +1153,21 @@ function me(e, i, m, g) {
|
|
|
1151
1153
|
if (l === "update")
|
|
1152
1154
|
return (d, t) => {
|
|
1153
1155
|
if (t?.debounce)
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
+
Ue(() => {
|
|
1157
|
+
ce(i, d, n, "");
|
|
1156
1158
|
const o = r.getState().getNestedState(e, n);
|
|
1157
1159
|
t?.afterUpdate && t.afterUpdate(o);
|
|
1158
1160
|
}, t.debounce);
|
|
1159
1161
|
else {
|
|
1160
|
-
|
|
1162
|
+
ce(i, d, n, "");
|
|
1161
1163
|
const o = r.getState().getNestedState(e, n);
|
|
1162
1164
|
t?.afterUpdate && t.afterUpdate(o);
|
|
1163
1165
|
}
|
|
1164
1166
|
p(n);
|
|
1165
1167
|
};
|
|
1166
1168
|
if (l === "formElement")
|
|
1167
|
-
return (d, t) => /* @__PURE__ */
|
|
1168
|
-
|
|
1169
|
+
return (d, t) => /* @__PURE__ */ pe(
|
|
1170
|
+
He,
|
|
1169
1171
|
{
|
|
1170
1172
|
setState: i,
|
|
1171
1173
|
stateKey: e,
|
|
@@ -1174,23 +1176,23 @@ function me(e, i, m, g) {
|
|
|
1174
1176
|
formOpts: t
|
|
1175
1177
|
}
|
|
1176
1178
|
);
|
|
1177
|
-
const
|
|
1178
|
-
return a(ae,
|
|
1179
|
+
const G = [...n, l], ae = r.getState().getNestedState(e, G);
|
|
1180
|
+
return a(ae, G, S);
|
|
1179
1181
|
}
|
|
1180
|
-
}, F = new Proxy(
|
|
1182
|
+
}, F = new Proxy(R, D);
|
|
1181
1183
|
return T.set(H, {
|
|
1182
1184
|
proxy: F,
|
|
1183
|
-
stateVersion:
|
|
1185
|
+
stateVersion: N
|
|
1184
1186
|
}), F;
|
|
1185
1187
|
}
|
|
1186
1188
|
return a(
|
|
1187
1189
|
r.getState().getNestedState(e, [])
|
|
1188
1190
|
);
|
|
1189
1191
|
}
|
|
1190
|
-
function
|
|
1191
|
-
return
|
|
1192
|
+
function xe(e) {
|
|
1193
|
+
return de(et, { proxy: e });
|
|
1192
1194
|
}
|
|
1193
|
-
function
|
|
1195
|
+
function Ke({
|
|
1194
1196
|
proxy: e,
|
|
1195
1197
|
rebuildStateShape: i
|
|
1196
1198
|
}) {
|
|
@@ -1199,13 +1201,13 @@ function Qe({
|
|
|
1199
1201
|
m,
|
|
1200
1202
|
e._path
|
|
1201
1203
|
).stateMapNoRender(
|
|
1202
|
-
(T,
|
|
1204
|
+
(T, N, p, v, a) => e._mapFn(T, N, p, v, a)
|
|
1203
1205
|
) : null;
|
|
1204
1206
|
}
|
|
1205
|
-
function
|
|
1207
|
+
function et({
|
|
1206
1208
|
proxy: e
|
|
1207
1209
|
}) {
|
|
1208
|
-
const i =
|
|
1210
|
+
const i = Y(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1209
1211
|
return oe(() => {
|
|
1210
1212
|
const g = i.current;
|
|
1211
1213
|
if (!g || !g.parentElement) return;
|
|
@@ -1227,22 +1229,22 @@ function Ke({
|
|
|
1227
1229
|
"state",
|
|
1228
1230
|
`return (${e._effect})(state)`
|
|
1229
1231
|
)(n);
|
|
1230
|
-
} catch (
|
|
1231
|
-
console.error("Error evaluating effect function during mount:",
|
|
1232
|
+
} catch (R) {
|
|
1233
|
+
console.error("Error evaluating effect function during mount:", R), S = n;
|
|
1232
1234
|
}
|
|
1233
1235
|
else
|
|
1234
1236
|
S = n;
|
|
1235
1237
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1236
1238
|
const H = document.createTextNode(String(S));
|
|
1237
1239
|
g.replaceWith(H);
|
|
1238
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
1240
|
+
}, [e._stateKey, e._path.join("."), e._effect]), de("span", {
|
|
1239
1241
|
ref: i,
|
|
1240
1242
|
style: { display: "none" },
|
|
1241
1243
|
"data-signal-id": m
|
|
1242
1244
|
});
|
|
1243
1245
|
}
|
|
1244
|
-
function
|
|
1245
|
-
const i =
|
|
1246
|
+
function It(e) {
|
|
1247
|
+
const i = Le(
|
|
1246
1248
|
(m) => {
|
|
1247
1249
|
const g = r.getState().stateComponents.get(e._stateKey) || {
|
|
1248
1250
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1254,22 +1256,22 @@ function mt(e) {
|
|
|
1254
1256
|
},
|
|
1255
1257
|
() => r.getState().getNestedState(e._stateKey, e._path)
|
|
1256
1258
|
);
|
|
1257
|
-
return
|
|
1259
|
+
return de("text", {}, String(i));
|
|
1258
1260
|
}
|
|
1259
|
-
function
|
|
1261
|
+
function tt({
|
|
1260
1262
|
stateKey: e,
|
|
1261
1263
|
itemComponentId: i,
|
|
1262
1264
|
itemPath: m,
|
|
1263
1265
|
children: g
|
|
1264
1266
|
}) {
|
|
1265
|
-
const [, T] = Q({}), [
|
|
1267
|
+
const [, T] = Q({}), [N, p] = We(), v = Y(null);
|
|
1266
1268
|
return oe(() => {
|
|
1267
1269
|
p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
|
|
1268
1270
|
virtualizer: {
|
|
1269
1271
|
itemHeight: p.height
|
|
1270
1272
|
}
|
|
1271
1273
|
}));
|
|
1272
|
-
}, [p.height, e, m]),
|
|
1274
|
+
}, [p.height, e, m]), le(() => {
|
|
1273
1275
|
const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
|
|
1274
1276
|
components: /* @__PURE__ */ new Map()
|
|
1275
1277
|
};
|
|
@@ -1280,14 +1282,14 @@ function et({
|
|
|
1280
1282
|
const n = r.getState().stateComponents.get(e);
|
|
1281
1283
|
n && n.components.delete(a);
|
|
1282
1284
|
};
|
|
1283
|
-
}, [e, i, m.join(".")]), /* @__PURE__ */
|
|
1285
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ pe("div", { ref: N, children: g });
|
|
1284
1286
|
}
|
|
1285
1287
|
export {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1288
|
+
xe as $cogsSignal,
|
|
1289
|
+
It as $cogsSignalStore,
|
|
1290
|
+
ft as addStateOptions,
|
|
1291
|
+
St as createCogsState,
|
|
1292
|
+
mt as notifyComponent,
|
|
1293
|
+
Qe as useCogsStateFn
|
|
1292
1294
|
};
|
|
1293
1295
|
//# sourceMappingURL=CogsState.jsx.map
|