cogsbox-state 0.5.382 → 0.5.383
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 +372 -370
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +53 -29
package/dist/CogsState.jsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as we } from "react/jsx-runtime";
|
|
3
|
+
import { useState as K, useRef as J, useEffect as oe, useLayoutEffect as ce, useMemo as Oe, createElement as le, useSyncExternalStore as De, startTransition as Ue, useCallback as $e } from "react";
|
|
4
|
+
import { transformStateFunc as je, isDeepEqual as q, isFunction as ee, getNestedValue as Y, getDifferences as _e, debounce as He } from "./utility.js";
|
|
5
|
+
import { pushFunc as Ee, updateFn as ie, cutFunc as me, ValidationWrapper as Fe, FormControlComponent as Be } from "./Functions.jsx";
|
|
6
|
+
import We from "superjson";
|
|
7
|
+
import { v4 as Ae } 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 ke } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Pe } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as ze } from "fast-json-patch";
|
|
12
|
+
import qe from "react-use-measure";
|
|
13
|
+
function be(e, i) {
|
|
14
14
|
const m = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, T = m(e) || {};
|
|
15
15
|
g(e, {
|
|
16
16
|
...T,
|
|
@@ -30,12 +30,12 @@ function xe({
|
|
|
30
30
|
!q(p[a], i[a]) && (v = !0, p[a] = i[a])) : (v = !0, p[a] = i[a]);
|
|
31
31
|
v && C(e, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function It(e, { formElements: i, validation: m }) {
|
|
34
34
|
return { initialState: e, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const ht = (e, i) => {
|
|
37
37
|
let m = e;
|
|
38
|
-
const [g, T] =
|
|
38
|
+
const [g, T] = je(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,
|
|
@@ -46,13 +46,13 @@ const mt = (e, i) => {
|
|
|
46
46
|
}, re(v) || r.getState().setInitialStateOptions(v, T[v]);
|
|
47
47
|
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
48
|
const C = (v, a) => {
|
|
49
|
-
const [h] =
|
|
49
|
+
const [h] = K(a?.componentId ?? Ae());
|
|
50
50
|
xe({
|
|
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, [
|
|
55
|
+
const n = r.getState().cogsStateStore[v] || g[v], S = a?.modifyState ? a.modifyState(n) : n, [B, R] = et(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
58
|
stateKey: v,
|
|
@@ -68,49 +68,49 @@ const mt = (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
|
-
xe({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage &&
|
|
74
|
+
xe({ stateKey: v, options: a, initialOptionsPart: T }), a.localStorage && Qe(v, a), ve(v);
|
|
75
75
|
}
|
|
76
76
|
return { useCogsState: C, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
78
|
+
setUpdaterState: Ie,
|
|
79
79
|
setState: ne,
|
|
80
80
|
getInitialOptions: re,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = r.getState(),
|
|
81
|
+
getKeyState: Le,
|
|
82
|
+
getValidationErrors: Je,
|
|
83
|
+
setStateLog: Ye,
|
|
84
|
+
updateInitialStateGlobal: Ne,
|
|
85
|
+
addValidationError: Ze,
|
|
86
|
+
removeValidationError: Q,
|
|
87
|
+
setServerSyncActions: Xe
|
|
88
|
+
} = r.getState(), Me = (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 C =
|
|
95
|
+
const C = ee(m?.localStorage?.key) ? m.localStorage?.key(e) : m?.localStorage?.key;
|
|
96
96
|
if (C && g) {
|
|
97
97
|
const p = `${g}-${i}-${C}`;
|
|
98
98
|
let v;
|
|
99
99
|
try {
|
|
100
|
-
v =
|
|
100
|
+
v = Te(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 = We.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
109
|
p,
|
|
110
110
|
JSON.stringify(h.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
113
|
+
}, Te = (e) => {
|
|
114
114
|
if (!e) return null;
|
|
115
115
|
try {
|
|
116
116
|
const i = window.localStorage.getItem(e);
|
|
@@ -118,20 +118,20 @@ const mt = (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
|
+
}, Qe = (e, i) => {
|
|
122
|
+
const m = r.getState().cogsStateStore[e], { sessionId: g } = Pe(), T = ee(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
123
|
if (T && g) {
|
|
124
|
-
const C =
|
|
124
|
+
const C = Te(
|
|
125
125
|
`${g}-${e}-${T}`
|
|
126
126
|
);
|
|
127
127
|
if (C && C.lastUpdated > (C.lastSyncedWithServer || 0))
|
|
128
|
-
return ne(e, C.state),
|
|
128
|
+
return ne(e, C.state), ve(e), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
131
|
+
}, Ge = (e, i, m, g, T, C) => {
|
|
132
132
|
const p = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
134
|
+
updaterState: he(
|
|
135
135
|
e,
|
|
136
136
|
g,
|
|
137
137
|
T,
|
|
@@ -139,8 +139,8 @@ const mt = (e, i) => {
|
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
142
|
+
Ne(e, p.initialState), Ie(e, p.updaterState), ne(e, p.state);
|
|
143
|
+
}, ve = (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 mt = (e, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, Tt = (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 mt = (e, i) => {
|
|
|
157
157
|
return;
|
|
158
158
|
T && T.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Ke = (e, i, m, g) => {
|
|
161
161
|
switch (e) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: Y(i, g),
|
|
165
|
+
newValue: Y(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: Y(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: Y(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,7 +180,7 @@ const mt = (e, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function et(e, {
|
|
184
184
|
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
@@ -193,12 +193,12 @@ function Ke(e, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [I] =
|
|
196
|
+
const [B, R] = K({}), { sessionId: D } = Pe();
|
|
197
|
+
let W = !i;
|
|
198
|
+
const [I] = K(i ?? Ae()), l = r.getState().stateLog[I], de = J(/* @__PURE__ */ new Set()), te = J(v ?? Ae()), L = J(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
201
|
+
L.current = re(I) ?? null, oe(() => {
|
|
202
202
|
if (h && h.stateKey === I && h.path?.[0]) {
|
|
203
203
|
ne(I, (o) => ({
|
|
204
204
|
...o,
|
|
@@ -212,228 +212,228 @@ function Ke(e, {
|
|
|
212
212
|
}
|
|
213
213
|
}, [h]), oe(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
be(I, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const t =
|
|
218
|
+
const t = L.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
|
-
const y =
|
|
223
|
-
y &&
|
|
222
|
+
const y = ee(t?.localStorage?.key) ? t?.localStorage?.key(a) : t?.localStorage?.key;
|
|
223
|
+
y && D && (u = Te(`${D}-${I}-${y}`));
|
|
224
224
|
let E = a, w = !1;
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
225
|
+
const N = s ? Date.now() : 0, k = u?.lastUpdated || 0, x = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && N > k ? (E = t.serverState.data, w = !0) : u && k > x && (E = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(E)), r.getState().initializeShadowState(I, a), Ge(
|
|
227
227
|
I,
|
|
228
228
|
a,
|
|
229
229
|
E,
|
|
230
230
|
ae,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
), w && y &&
|
|
231
|
+
te.current,
|
|
232
|
+
D
|
|
233
|
+
), w && y && D && Me(E, I, t, D, Date.now()), ve(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
|
-
|
|
240
|
+
]), ce(() => {
|
|
241
|
+
W && be(I, {
|
|
242
242
|
serverSync: m,
|
|
243
243
|
formElements: T,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: L.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const t = `${I}////${
|
|
248
|
+
const t = `${I}////${te.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
255
|
depsFunction: C || 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
|
+
de.current.add(u);
|
|
265
265
|
}
|
|
266
266
|
const f = r.getState();
|
|
267
267
|
ne(I, (u) => {
|
|
268
|
-
const y =
|
|
268
|
+
const y = ee(t) ? t(u) : t, E = `${I}-${o.join(".")}`;
|
|
269
269
|
if (E) {
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const _ = `${I}-${
|
|
276
|
-
|
|
270
|
+
let P = !1, A = f.signalDomElements.get(E);
|
|
271
|
+
if ((!A || A.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const M = o.slice(0, -1), O = Y(y, M);
|
|
273
|
+
if (Array.isArray(O)) {
|
|
274
|
+
P = !0;
|
|
275
|
+
const _ = `${I}-${M.join(".")}`;
|
|
276
|
+
A = f.signalDomElements.get(_);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (A) {
|
|
280
|
+
const M = P ? Y(y, o.slice(0, -1)) : Y(y, o);
|
|
281
|
+
A.forEach(({ parentId: O, position: _, effect: b }) => {
|
|
282
|
+
const G = document.querySelector(
|
|
283
|
+
`[data-parent-id="${O}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const z = Array.from(
|
|
285
|
+
if (G) {
|
|
286
|
+
const z = Array.from(G.childNodes);
|
|
287
287
|
if (z[_]) {
|
|
288
|
-
const
|
|
289
|
-
z[_].textContent = String(
|
|
288
|
+
const U = b ? new Function("state", `return (${b})(state)`)(M) : M;
|
|
289
|
+
z[_].textContent = String(U);
|
|
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 || L.current?.validation?.key) && o && Q(
|
|
296
|
+
(c || L.current?.validation?.key) + "." + o.join(".")
|
|
297
297
|
);
|
|
298
298
|
const w = o.slice(0, o.length - 1);
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let _ =
|
|
307
|
-
|
|
299
|
+
s.updateType === "cut" && L.current?.validation?.key && Q(
|
|
300
|
+
L.current?.validation?.key + "." + w.join(".")
|
|
301
|
+
), s.updateType === "insert" && L.current?.validation?.key && Je(
|
|
302
|
+
L.current?.validation?.key + "." + w.join(".")
|
|
303
|
+
).filter(([A, M]) => {
|
|
304
|
+
let O = A?.split(".").length;
|
|
305
|
+
if (A == w.join(".") && O == w.length - 1) {
|
|
306
|
+
let _ = A + "." + w;
|
|
307
|
+
Q(A), Ze(_, M);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const N = f.stateComponents.get(I);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", N), N) {
|
|
312
|
+
const P = _e(u, y), A = new Set(P), M = s.updateType === "update" ? o.join(".") : o.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
314
|
+
O,
|
|
315
315
|
_
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component", _), !
|
|
320
|
-
if (
|
|
316
|
+
] of N.components.entries()) {
|
|
317
|
+
let b = !1;
|
|
318
|
+
const G = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", _), !G.includes("none")) {
|
|
320
|
+
if (G.includes("all")) {
|
|
321
321
|
_.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const z of
|
|
326
|
-
let
|
|
324
|
+
if (G.includes("component") && ((_.paths.has(M) || _.paths.has("")) && (b = !0), !b))
|
|
325
|
+
for (const z of A) {
|
|
326
|
+
let U = z;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (_.paths.has(
|
|
329
|
-
|
|
328
|
+
if (_.paths.has(U)) {
|
|
329
|
+
b = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
332
|
+
const se = U.lastIndexOf(".");
|
|
333
|
+
if (se !== -1) {
|
|
334
|
+
const $ = U.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
se
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) && _.paths.has(
|
|
341
|
-
|
|
339
|
+
Number(U.substring(se + 1))
|
|
340
|
+
) && _.paths.has($)) {
|
|
341
|
+
b = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
U = $;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
U = "";
|
|
347
|
+
if (U === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (b) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
352
|
+
if (!b && G.includes("deps") && _.depsFunction) {
|
|
353
353
|
const z = _.depsFunction(y);
|
|
354
|
-
let
|
|
355
|
-
typeof z == "boolean" ? z && (
|
|
354
|
+
let U = !1;
|
|
355
|
+
typeof z == "boolean" ? z && (U = !0) : q(_.deps, z) || (_.deps = z, U = !0), U && (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 k = Date.now();
|
|
362
|
+
o = o.map((P, A) => {
|
|
363
|
+
const M = o.slice(0, -1), O = Y(y, M);
|
|
364
|
+
return A === o.length - 1 && ["insert", "cut"].includes(s.updateType) ? (O.length - 1).toString() : P;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: x, newValue: j } = Ke(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
369
|
y,
|
|
370
370
|
o
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
371
|
+
), Z = {
|
|
372
|
+
timeStamp: k,
|
|
373
373
|
stateKey: I,
|
|
374
374
|
path: o,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
378
|
-
newValue:
|
|
377
|
+
oldValue: x,
|
|
378
|
+
newValue: j
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
f.updateShadowAtPath(I, o, y);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(I,
|
|
385
|
+
const P = o.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(I, P, j);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
f.removeShadowArrayElement(I,
|
|
389
|
+
const A = o.slice(0, -1), M = parseInt(o[o.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(I, A, M);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (Ye(I, (P) => {
|
|
394
|
+
const M = [...P ?? [], Z].reduce((O, _) => {
|
|
395
|
+
const b = `${_.stateKey}:${JSON.stringify(_.path)}`, G = O.get(b);
|
|
396
|
+
return G ? (G.timeStamp = Math.max(G.timeStamp, _.timeStamp), G.newValue = _.newValue, G.oldValue = G.oldValue ?? _.oldValue, G.updateType = _.updateType) : O.set(b, { ..._ }), O;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
398
|
+
return Array.from(M.values());
|
|
399
|
+
}), Me(
|
|
400
400
|
y,
|
|
401
401
|
I,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
402
|
+
L.current,
|
|
403
|
+
D
|
|
404
|
+
), L.current?.middleware && L.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
406
|
+
update: Z
|
|
407
|
+
}), L.current?.serverSync) {
|
|
408
|
+
const P = f.serverState[I], A = L.current?.serverSync;
|
|
409
|
+
Xe(I, {
|
|
410
|
+
syncKey: typeof A.syncKey == "string" ? A.syncKey : A.syncKey({ state: y }),
|
|
411
|
+
rollBackState: P,
|
|
412
|
+
actionTimeStamp: Date.now() + (A.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
416
|
return y;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
r.getState().updaterState[I] || (
|
|
419
|
+
r.getState().updaterState[I] || (Ie(
|
|
420
420
|
I,
|
|
421
|
-
|
|
421
|
+
he(
|
|
422
422
|
I,
|
|
423
423
|
ae,
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
te.current,
|
|
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] || Ne(I, e));
|
|
428
|
+
const d = Oe(() => he(
|
|
429
429
|
I,
|
|
430
430
|
ae,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
), [I,
|
|
434
|
-
return [
|
|
431
|
+
te.current,
|
|
432
|
+
D
|
|
433
|
+
), [I, D]);
|
|
434
|
+
return [Le(I), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function he(e, i, m, g) {
|
|
437
437
|
const T = /* @__PURE__ */ new Map();
|
|
438
438
|
let C = 0;
|
|
439
439
|
const p = (h) => {
|
|
@@ -443,15 +443,15 @@ function me(e, i, m, g) {
|
|
|
443
443
|
C++;
|
|
444
444
|
}, v = {
|
|
445
445
|
removeValidation: (h) => {
|
|
446
|
-
h?.validationKey &&
|
|
446
|
+
h?.validationKey && Q(h.validationKey);
|
|
447
447
|
},
|
|
448
448
|
revertToInitialState: (h) => {
|
|
449
449
|
const n = r.getState().getInitialOptions(e)?.validation;
|
|
450
|
-
n?.key &&
|
|
450
|
+
n?.key && Q(n?.key), h?.validationKey && Q(h.validationKey);
|
|
451
451
|
const S = r.getState().initialStateGlobal[e];
|
|
452
452
|
r.getState().clearSelectedIndexesForState(e), T.clear(), C++;
|
|
453
|
-
const
|
|
454
|
-
|
|
453
|
+
const B = a(S, []), R = re(e), D = ee(R?.localStorage?.key) ? R?.localStorage?.key(S) : R?.localStorage?.key, W = `${g}-${e}-${D}`;
|
|
454
|
+
W && localStorage.removeItem(W), Ie(e, B), ne(e, S);
|
|
455
455
|
const I = r.getState().stateComponents.get(e);
|
|
456
456
|
return I && I.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
@@ -459,20 +459,20 @@ function me(e, i, m, g) {
|
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (h) => {
|
|
461
461
|
T.clear(), C++;
|
|
462
|
-
const n =
|
|
462
|
+
const n = he(
|
|
463
463
|
e,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S = r.getState().initialStateGlobal[e],
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
467
|
+
), S = r.getState().initialStateGlobal[e], B = re(e), R = ee(B?.localStorage?.key) ? B?.localStorage?.key(S) : B?.localStorage?.key, D = `${g}-${e}-${R}`;
|
|
468
|
+
return localStorage.getItem(D) && localStorage.removeItem(D), Ue(() => {
|
|
469
|
+
Ne(e, h), r.getState().initializeShadowState(e, h), Ie(e, n), ne(e, h);
|
|
470
|
+
const W = r.getState().stateComponents.get(e);
|
|
471
|
+
W && W.components.forEach((I) => {
|
|
472
472
|
I.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (W) => n.get()[W]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
478
|
_initialState: r.getState().initialStateGlobal[e],
|
|
@@ -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, Le(e)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(h, n = [], S) {
|
|
487
|
-
const
|
|
488
|
-
T.get(
|
|
489
|
-
const
|
|
487
|
+
const B = n.map(String).join(".");
|
|
488
|
+
T.get(B);
|
|
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, de) {
|
|
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 de = /* @__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" && !de.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);
|
|
@@ -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 = Y(t, n);
|
|
572
572
|
return q(d, o) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
@@ -576,12 +576,12 @@ 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 = Y(t, n);
|
|
580
580
|
return q(d, o) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d = r.getState().initialStateGlobal[e], t = re(e), o =
|
|
584
|
+
const d = r.getState().initialStateGlobal[e], t = re(e), o = ee(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, s = `${g}-${e}-${o}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
@@ -622,164 +622,166 @@ 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 = J(null), [y, E] = K({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [w,
|
|
628
|
+
}), [w, N] = K("IDLE_AT_TOP"), k = J(!1), x = J(0), j = J(f), [Z, P] = K(0), A = J(null);
|
|
629
629
|
oe(() => r.getState().subscribeToShadowState(e, () => {
|
|
630
|
-
|
|
630
|
+
P((V) => V + 1);
|
|
631
631
|
}), [e]);
|
|
632
|
-
const
|
|
632
|
+
const M = r().getNestedState(
|
|
633
633
|
e,
|
|
634
634
|
n
|
|
635
|
-
), O =
|
|
636
|
-
const
|
|
637
|
-
let
|
|
635
|
+
), O = M.length, { totalHeight: _, positions: b } = Oe(() => {
|
|
636
|
+
const $ = r.getState().getShadowMetadata(e, n) || [];
|
|
637
|
+
let V = 0;
|
|
638
638
|
const H = [];
|
|
639
|
-
for (let
|
|
640
|
-
H[
|
|
641
|
-
const
|
|
642
|
-
|
|
639
|
+
for (let F = 0; F < O; F++) {
|
|
640
|
+
H[F] = V;
|
|
641
|
+
const X = $[F]?.virtualizer?.itemHeight;
|
|
642
|
+
V += X || o;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: V, positions: H };
|
|
645
645
|
}, [
|
|
646
646
|
O,
|
|
647
647
|
e,
|
|
648
648
|
n.join("."),
|
|
649
649
|
o,
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
650
|
+
Z
|
|
651
|
+
]), G = Oe(() => {
|
|
652
|
+
const $ = Math.max(0, y.startIndex), V = Math.min(O, y.endIndex), H = Array.from(
|
|
653
|
+
{ length: V - $ },
|
|
654
|
+
(X, ue) => $ + ue
|
|
655
|
+
), F = H.map((X) => M[X]);
|
|
656
|
+
return a(F, n, {
|
|
657
657
|
...S,
|
|
658
658
|
validIndices: H
|
|
659
659
|
});
|
|
660
|
-
}, [y.startIndex, y.endIndex,
|
|
661
|
-
|
|
662
|
-
const
|
|
660
|
+
}, [y.startIndex, y.endIndex, M, O]);
|
|
661
|
+
ce(() => {
|
|
662
|
+
const $ = u.current;
|
|
663
|
+
if (!$) return;
|
|
664
|
+
const V = O > x.current;
|
|
665
|
+
!q(
|
|
663
666
|
f,
|
|
664
|
-
|
|
665
|
-
)
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
x && w === "LOCKED_AT_BOTTOM" && c && (console.log(
|
|
667
|
+
j.current
|
|
668
|
+
) ? (console.log(
|
|
669
|
+
"TRANSITION (Hard Reset): Deps changed -> IDLE_AT_TOP"
|
|
670
|
+
), N("IDLE_AT_TOP"), $.scrollTo({ top: 0 })) : V && w === "LOCKED_AT_BOTTOM" && c ? (console.log(
|
|
671
671
|
"TRANSITION: New items arrived while locked -> GETTING_HEIGHTS"
|
|
672
|
-
),
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
672
|
+
), N("GETTING_HEIGHTS")) : V && A.current && (console.log(
|
|
673
|
+
"ACTION: Maintaining scroll position after new items added."
|
|
674
|
+
), $.scrollTop = A.current.scrollTop + ($.scrollHeight - A.current.scrollHeight)), x.current = O, j.current = f, A.current = null;
|
|
675
|
+
}, [O, ...f]), ce(() => {
|
|
676
|
+
const $ = u.current;
|
|
677
|
+
if (!$) return;
|
|
678
|
+
let V;
|
|
677
679
|
if (w === "IDLE_AT_TOP" && c && O > 0)
|
|
678
680
|
console.log(
|
|
679
681
|
"ACTION (IDLE_AT_TOP): Data arrived -> GETTING_HEIGHTS"
|
|
680
|
-
),
|
|
682
|
+
), N("GETTING_HEIGHTS");
|
|
681
683
|
else if (w === "GETTING_HEIGHTS")
|
|
682
684
|
console.log("ACTION (GETTING_HEIGHTS): Setting range to end"), E({
|
|
683
685
|
startIndex: Math.max(0, O - 10 - s),
|
|
684
686
|
endIndex: O
|
|
685
|
-
}),
|
|
687
|
+
}), V = setInterval(() => {
|
|
686
688
|
const H = O - 1;
|
|
687
|
-
((r.getState().getShadowMetadata(e, n) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(
|
|
689
|
+
((r.getState().getShadowMetadata(e, n) || [])[H]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(V), console.log(
|
|
688
690
|
"ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
|
|
689
|
-
),
|
|
691
|
+
), N("SCROLLING_TO_BOTTOM"));
|
|
690
692
|
}, 100);
|
|
691
693
|
else if (w === "SCROLLING_TO_BOTTOM") {
|
|
692
694
|
console.log(
|
|
693
695
|
"ACTION (SCROLLING_TO_BOTTOM): Executing scroll."
|
|
694
|
-
),
|
|
695
|
-
const H =
|
|
696
|
-
|
|
697
|
-
top:
|
|
696
|
+
), k.current = !0;
|
|
697
|
+
const H = x.current === 0 ? "auto" : "smooth";
|
|
698
|
+
$.scrollTo({
|
|
699
|
+
top: $.scrollHeight,
|
|
698
700
|
behavior: H
|
|
699
701
|
});
|
|
700
|
-
const
|
|
702
|
+
const F = setTimeout(
|
|
701
703
|
() => {
|
|
702
|
-
|
|
704
|
+
k.current = !1, N("LOCKED_AT_BOTTOM");
|
|
703
705
|
},
|
|
704
706
|
H === "smooth" ? 500 : 50
|
|
705
707
|
);
|
|
706
|
-
return () => clearTimeout(
|
|
708
|
+
return () => clearTimeout(F);
|
|
707
709
|
}
|
|
708
710
|
return () => {
|
|
709
|
-
|
|
711
|
+
V && clearInterval(V);
|
|
710
712
|
};
|
|
711
|
-
}, [w, O,
|
|
712
|
-
const
|
|
713
|
-
if (
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
713
|
+
}, [w, O, b]), oe(() => {
|
|
714
|
+
const $ = u.current;
|
|
715
|
+
if (!$) return;
|
|
716
|
+
const V = 10, H = () => {
|
|
717
|
+
if (k.current)
|
|
716
718
|
return;
|
|
717
|
-
const { scrollTop:
|
|
718
|
-
|
|
719
|
+
const { scrollTop: F, clientHeight: X, scrollHeight: ue } = $;
|
|
720
|
+
A.current = { scrollTop: F, scrollHeight: ue }, ue - F - X < V ? w !== "LOCKED_AT_BOTTOM" && (console.log(
|
|
719
721
|
"SCROLL EVENT: Reached bottom -> LOCKED_AT_BOTTOM"
|
|
720
|
-
),
|
|
722
|
+
), N("LOCKED_AT_BOTTOM")) : w !== "IDLE_NOT_AT_BOTTOM" && (console.log(
|
|
721
723
|
"SCROLL EVENT: Scrolled up -> IDLE_NOT_AT_BOTTOM"
|
|
722
|
-
),
|
|
723
|
-
let
|
|
724
|
-
for (;
|
|
725
|
-
const
|
|
726
|
-
|
|
724
|
+
), N("IDLE_NOT_AT_BOTTOM"));
|
|
725
|
+
let ye = O - 1, pe = 0, Ce = 0;
|
|
726
|
+
for (; pe <= ye; ) {
|
|
727
|
+
const Se = Math.floor((pe + ye) / 2);
|
|
728
|
+
b[Se] < F ? (Ce = Se, pe = Se + 1) : ye = Se - 1;
|
|
727
729
|
}
|
|
728
|
-
const
|
|
730
|
+
const ge = Math.max(
|
|
729
731
|
0,
|
|
730
|
-
|
|
732
|
+
Ce - s
|
|
731
733
|
);
|
|
732
|
-
if (
|
|
734
|
+
if (ge === y.startIndex)
|
|
733
735
|
return;
|
|
734
|
-
let
|
|
735
|
-
const
|
|
736
|
-
for (;
|
|
737
|
-
|
|
736
|
+
let fe = ge;
|
|
737
|
+
const Re = F + X;
|
|
738
|
+
for (; fe < O && b[fe] < Re; )
|
|
739
|
+
fe++;
|
|
738
740
|
console.log(
|
|
739
|
-
`Index changed from ${y.startIndex} to ${
|
|
741
|
+
`Index changed from ${y.startIndex} to ${ge}. Updating range.`
|
|
740
742
|
), E({
|
|
741
|
-
startIndex:
|
|
742
|
-
endIndex: Math.min(O,
|
|
743
|
+
startIndex: ge,
|
|
744
|
+
endIndex: Math.min(O, fe + s)
|
|
743
745
|
});
|
|
744
746
|
};
|
|
745
|
-
return
|
|
747
|
+
return $.addEventListener("scroll", H, {
|
|
746
748
|
passive: !0
|
|
747
|
-
}), () =>
|
|
748
|
-
}, [O,
|
|
749
|
-
const
|
|
749
|
+
}), () => $.removeEventListener("scroll", H);
|
|
750
|
+
}, [O, b, w, y.startIndex]);
|
|
751
|
+
const z = $e(() => {
|
|
750
752
|
console.log(
|
|
751
753
|
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
752
|
-
), O !== 0 &&
|
|
753
|
-
}, [O]),
|
|
754
|
-
(
|
|
755
|
-
u.current &&
|
|
756
|
-
top:
|
|
757
|
-
behavior:
|
|
754
|
+
), O !== 0 && N("SCROLLING_TO_BOTTOM");
|
|
755
|
+
}, [O]), U = $e(
|
|
756
|
+
($, V = "smooth") => {
|
|
757
|
+
u.current && b[$] !== void 0 && (N("IDLE_NOT_AT_BOTTOM"), u.current.scrollTo({
|
|
758
|
+
top: b[$],
|
|
759
|
+
behavior: V
|
|
758
760
|
}));
|
|
759
761
|
},
|
|
760
|
-
[
|
|
761
|
-
),
|
|
762
|
+
[b]
|
|
763
|
+
), se = {
|
|
762
764
|
outer: {
|
|
763
765
|
ref: u,
|
|
764
766
|
style: { overflowY: "auto", height: "100%" }
|
|
765
767
|
},
|
|
766
768
|
inner: {
|
|
767
769
|
style: {
|
|
768
|
-
height: `${
|
|
770
|
+
height: `${_}px`,
|
|
769
771
|
position: "relative"
|
|
770
772
|
}
|
|
771
773
|
},
|
|
772
774
|
list: {
|
|
773
775
|
style: {
|
|
774
|
-
transform: `translateY(${
|
|
776
|
+
transform: `translateY(${b[y.startIndex] || 0}px)`
|
|
775
777
|
}
|
|
776
778
|
}
|
|
777
779
|
};
|
|
778
780
|
return {
|
|
779
|
-
virtualState:
|
|
780
|
-
virtualizerProps:
|
|
781
|
-
scrollToBottom:
|
|
782
|
-
scrollToIndex:
|
|
781
|
+
virtualState: G,
|
|
782
|
+
virtualizerProps: se,
|
|
783
|
+
scrollToBottom: z,
|
|
784
|
+
scrollToIndex: U
|
|
783
785
|
};
|
|
784
786
|
};
|
|
785
787
|
if (l === "stateSort")
|
|
@@ -813,19 +815,19 @@ function me(e, i, m, g) {
|
|
|
813
815
|
const u = o[c], y = [...n, c.toString()], E = a(u, y, S);
|
|
814
816
|
return t(u, E, {
|
|
815
817
|
register: () => {
|
|
816
|
-
const [,
|
|
817
|
-
|
|
818
|
-
const
|
|
818
|
+
const [, N] = K({}), k = `${m}-${n.join(".")}-${c}`;
|
|
819
|
+
ce(() => {
|
|
820
|
+
const x = `${e}////${k}`, j = r.getState().stateComponents.get(e) || {
|
|
819
821
|
components: /* @__PURE__ */ new Map()
|
|
820
822
|
};
|
|
821
|
-
return
|
|
822
|
-
forceUpdate: () =>
|
|
823
|
+
return j.components.set(x, {
|
|
824
|
+
forceUpdate: () => N({}),
|
|
823
825
|
paths: /* @__PURE__ */ new Set([y.join(".")])
|
|
824
|
-
}), r.getState().stateComponents.set(e,
|
|
825
|
-
const
|
|
826
|
-
|
|
826
|
+
}), r.getState().stateComponents.set(e, j), () => {
|
|
827
|
+
const Z = r.getState().stateComponents.get(e);
|
|
828
|
+
Z && Z.components.delete(x);
|
|
827
829
|
};
|
|
828
|
-
}, [e,
|
|
830
|
+
}, [e, k]);
|
|
829
831
|
},
|
|
830
832
|
index: f,
|
|
831
833
|
originalIndex: c
|
|
@@ -849,7 +851,7 @@ function me(e, i, m, g) {
|
|
|
849
851
|
);
|
|
850
852
|
});
|
|
851
853
|
if (l === "$stateMap")
|
|
852
|
-
return (t) =>
|
|
854
|
+
return (t) => le(tt, {
|
|
853
855
|
proxy: {
|
|
854
856
|
_stateKey: e,
|
|
855
857
|
_path: n,
|
|
@@ -863,7 +865,7 @@ function me(e, i, m, g) {
|
|
|
863
865
|
const o = r.getState().getNestedState(e, n);
|
|
864
866
|
return Array.isArray(o) ? (S?.validIndices || Array.from({ length: o.length }, (c, f) => f)).map((c, f) => {
|
|
865
867
|
const u = o[c], y = [...n, c.toString()], E = a(u, y, S), w = `${m}-${n.join(".")}-${c}`;
|
|
866
|
-
return
|
|
868
|
+
return le(rt, {
|
|
867
869
|
key: c,
|
|
868
870
|
stateKey: e,
|
|
869
871
|
itemComponentId: w,
|
|
@@ -906,36 +908,36 @@ function me(e, i, m, g) {
|
|
|
906
908
|
return a(s, c);
|
|
907
909
|
};
|
|
908
910
|
if (l === "insert")
|
|
909
|
-
return (t) => (p(n),
|
|
911
|
+
return (t) => (p(n), Ee(i, t, n, e), a(
|
|
910
912
|
r.getState().getNestedState(e, n),
|
|
911
913
|
n
|
|
912
914
|
));
|
|
913
915
|
if (l === "uniqueInsert")
|
|
914
916
|
return (t, o, s) => {
|
|
915
|
-
const c = r.getState().getNestedState(e, n), f =
|
|
917
|
+
const c = r.getState().getNestedState(e, n), f = ee(t) ? t(c) : t;
|
|
916
918
|
let u = null;
|
|
917
919
|
if (!c.some((E) => {
|
|
918
920
|
if (o) {
|
|
919
|
-
const
|
|
920
|
-
(
|
|
921
|
+
const N = o.every(
|
|
922
|
+
(k) => q(E[k], f[k])
|
|
921
923
|
);
|
|
922
|
-
return
|
|
924
|
+
return N && (u = E), N;
|
|
923
925
|
}
|
|
924
926
|
const w = q(E, f);
|
|
925
927
|
return w && (u = E), w;
|
|
926
928
|
}))
|
|
927
|
-
p(n),
|
|
929
|
+
p(n), Ee(i, f, n, e);
|
|
928
930
|
else if (s && u) {
|
|
929
931
|
const E = s(u), w = c.map(
|
|
930
|
-
(
|
|
932
|
+
(N) => q(N, u) ? E : N
|
|
931
933
|
);
|
|
932
|
-
p(n),
|
|
934
|
+
p(n), ie(i, w, n);
|
|
933
935
|
}
|
|
934
936
|
};
|
|
935
937
|
if (l === "cut")
|
|
936
938
|
return (t, o) => {
|
|
937
939
|
if (!o?.waitForSync)
|
|
938
|
-
return p(n),
|
|
940
|
+
return p(n), me(i, n, e, t), a(
|
|
939
941
|
r.getState().getNestedState(e, n),
|
|
940
942
|
n
|
|
941
943
|
);
|
|
@@ -943,12 +945,12 @@ function me(e, i, m, g) {
|
|
|
943
945
|
if (l === "cutByValue")
|
|
944
946
|
return (t) => {
|
|
945
947
|
for (let o = 0; o < h.length; o++)
|
|
946
|
-
h[o] === t &&
|
|
948
|
+
h[o] === t && me(i, n, e, o);
|
|
947
949
|
};
|
|
948
950
|
if (l === "toggleByValue")
|
|
949
951
|
return (t) => {
|
|
950
952
|
const o = h.findIndex((s) => s === t);
|
|
951
|
-
o > -1 ?
|
|
953
|
+
o > -1 ? me(i, n, e, o) : Ee(i, t, n, e);
|
|
952
954
|
};
|
|
953
955
|
if (l === "stateFind")
|
|
954
956
|
return (t) => {
|
|
@@ -969,15 +971,15 @@ function me(e, i, m, g) {
|
|
|
969
971
|
return a(c.item, f, S);
|
|
970
972
|
};
|
|
971
973
|
}
|
|
972
|
-
const
|
|
973
|
-
if (!isNaN(Number(
|
|
974
|
+
const te = n[n.length - 1];
|
|
975
|
+
if (!isNaN(Number(te))) {
|
|
974
976
|
const d = n.slice(0, -1), t = r.getState().getNestedState(e, d);
|
|
975
977
|
if (Array.isArray(t) && l === "cut")
|
|
976
|
-
return () =>
|
|
978
|
+
return () => me(
|
|
977
979
|
i,
|
|
978
980
|
d,
|
|
979
981
|
e,
|
|
980
|
-
Number(
|
|
982
|
+
Number(te)
|
|
981
983
|
);
|
|
982
984
|
}
|
|
983
985
|
if (l === "get")
|
|
@@ -989,13 +991,13 @@ function me(e, i, m, g) {
|
|
|
989
991
|
return r.getState().getNestedState(e, n);
|
|
990
992
|
};
|
|
991
993
|
if (l === "$derive")
|
|
992
|
-
return (d) =>
|
|
994
|
+
return (d) => Ve({
|
|
993
995
|
_stateKey: e,
|
|
994
996
|
_path: n,
|
|
995
997
|
_effect: d.toString()
|
|
996
998
|
});
|
|
997
999
|
if (l === "$get")
|
|
998
|
-
return () =>
|
|
1000
|
+
return () => Ve({
|
|
999
1001
|
_stateKey: e,
|
|
1000
1002
|
_path: n
|
|
1001
1003
|
});
|
|
@@ -1004,7 +1006,7 @@ function me(e, i, m, g) {
|
|
|
1004
1006
|
return r.getState().getSyncInfo(d);
|
|
1005
1007
|
}
|
|
1006
1008
|
if (l == "getLocalStorage")
|
|
1007
|
-
return (d) =>
|
|
1009
|
+
return (d) => Te(g + "-" + e + "-" + d);
|
|
1008
1010
|
if (l === "_selected") {
|
|
1009
1011
|
const d = n.slice(0, -1), t = d.join("."), o = r.getState().getNestedState(e, d);
|
|
1010
1012
|
return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(e, t) : void 0;
|
|
@@ -1014,7 +1016,7 @@ function me(e, i, m, g) {
|
|
|
1014
1016
|
const t = n.slice(0, -1), o = Number(n[n.length - 1]), s = t.join(".");
|
|
1015
1017
|
d ? r.getState().setSelectedIndex(e, s, o) : r.getState().setSelectedIndex(e, s, void 0);
|
|
1016
1018
|
const c = r.getState().getNestedState(e, [...t]);
|
|
1017
|
-
|
|
1019
|
+
ie(i, c, t), p(t);
|
|
1018
1020
|
};
|
|
1019
1021
|
if (l === "toggleSelected")
|
|
1020
1022
|
return () => {
|
|
@@ -1025,13 +1027,13 @@ function me(e, i, m, g) {
|
|
|
1025
1027
|
s === t ? void 0 : t
|
|
1026
1028
|
);
|
|
1027
1029
|
const c = r.getState().getNestedState(e, [...d]);
|
|
1028
|
-
|
|
1030
|
+
ie(i, c, d), p(d);
|
|
1029
1031
|
};
|
|
1030
1032
|
if (n.length == 0) {
|
|
1031
1033
|
if (l === "applyJsonPatch")
|
|
1032
1034
|
return (d) => {
|
|
1033
|
-
const t = r.getState().cogsStateStore[e], s =
|
|
1034
|
-
|
|
1035
|
+
const t = r.getState().cogsStateStore[e], s = ze(t, d).newDocument;
|
|
1036
|
+
Ge(
|
|
1035
1037
|
e,
|
|
1036
1038
|
r.getState().initialStateGlobal[e],
|
|
1037
1039
|
s,
|
|
@@ -1047,49 +1049,49 @@ function me(e, i, m, g) {
|
|
|
1047
1049
|
E
|
|
1048
1050
|
] of c.components.entries()) {
|
|
1049
1051
|
let w = !1;
|
|
1050
|
-
const
|
|
1051
|
-
if (!
|
|
1052
|
-
if (
|
|
1052
|
+
const N = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
1053
|
+
if (!N.includes("none")) {
|
|
1054
|
+
if (N.includes("all")) {
|
|
1053
1055
|
E.forceUpdate();
|
|
1054
1056
|
continue;
|
|
1055
1057
|
}
|
|
1056
|
-
if (
|
|
1057
|
-
for (const
|
|
1058
|
-
if (E.paths.has(
|
|
1058
|
+
if (N.includes("component") && (E.paths.has("") && (w = !0), !w))
|
|
1059
|
+
for (const k of u) {
|
|
1060
|
+
if (E.paths.has(k)) {
|
|
1059
1061
|
w = !0;
|
|
1060
1062
|
break;
|
|
1061
1063
|
}
|
|
1062
|
-
let
|
|
1063
|
-
for (;
|
|
1064
|
-
const
|
|
1065
|
-
if (E.paths.has(
|
|
1064
|
+
let x = k.lastIndexOf(".");
|
|
1065
|
+
for (; x !== -1; ) {
|
|
1066
|
+
const j = k.substring(0, x);
|
|
1067
|
+
if (E.paths.has(j)) {
|
|
1066
1068
|
w = !0;
|
|
1067
1069
|
break;
|
|
1068
1070
|
}
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1071
|
+
const Z = k.substring(
|
|
1072
|
+
x + 1
|
|
1071
1073
|
);
|
|
1072
|
-
if (!isNaN(Number(
|
|
1073
|
-
const
|
|
1074
|
-
if (
|
|
1075
|
-
const
|
|
1074
|
+
if (!isNaN(Number(Z))) {
|
|
1075
|
+
const P = j.lastIndexOf(".");
|
|
1076
|
+
if (P !== -1) {
|
|
1077
|
+
const A = j.substring(
|
|
1076
1078
|
0,
|
|
1077
|
-
|
|
1079
|
+
P
|
|
1078
1080
|
);
|
|
1079
|
-
if (E.paths.has(
|
|
1081
|
+
if (E.paths.has(A)) {
|
|
1080
1082
|
w = !0;
|
|
1081
1083
|
break;
|
|
1082
1084
|
}
|
|
1083
1085
|
}
|
|
1084
1086
|
}
|
|
1085
|
-
|
|
1087
|
+
x = j.lastIndexOf(".");
|
|
1086
1088
|
}
|
|
1087
1089
|
if (w) break;
|
|
1088
1090
|
}
|
|
1089
|
-
if (!w &&
|
|
1090
|
-
const
|
|
1091
|
-
let
|
|
1092
|
-
typeof
|
|
1091
|
+
if (!w && N.includes("deps") && E.depsFunction) {
|
|
1092
|
+
const k = E.depsFunction(s);
|
|
1093
|
+
let x = !1;
|
|
1094
|
+
typeof k == "boolean" ? k && (x = !0) : q(E.deps, k) || (E.deps = k, x = !0), x && (w = !0);
|
|
1093
1095
|
}
|
|
1094
1096
|
w && E.forceUpdate();
|
|
1095
1097
|
}
|
|
@@ -1103,18 +1105,18 @@ function me(e, i, m, g) {
|
|
|
1103
1105
|
throw new Error("Zod schema not found");
|
|
1104
1106
|
if (!d?.key)
|
|
1105
1107
|
throw new Error("Validation key not found");
|
|
1106
|
-
|
|
1108
|
+
Q(d.key);
|
|
1107
1109
|
const o = r.getState().cogsStateStore[e];
|
|
1108
1110
|
try {
|
|
1109
1111
|
const s = r.getState().getValidationErrors(d.key);
|
|
1110
1112
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1111
|
-
f && f.startsWith(d.key) &&
|
|
1113
|
+
f && f.startsWith(d.key) && Q(f);
|
|
1112
1114
|
});
|
|
1113
1115
|
const c = d.zodSchema.safeParse(o);
|
|
1114
1116
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1115
1117
|
const y = u.path, E = u.message, w = [d.key, ...y].join(".");
|
|
1116
1118
|
t(w, E);
|
|
1117
|
-
}),
|
|
1119
|
+
}), ve(e), !1);
|
|
1118
1120
|
} catch (s) {
|
|
1119
1121
|
return console.error("Zod schema validation failed", s), !1;
|
|
1120
1122
|
}
|
|
@@ -1123,7 +1125,7 @@ function me(e, i, m, g) {
|
|
|
1123
1125
|
if (l === "getComponents")
|
|
1124
1126
|
return () => r().stateComponents.get(e);
|
|
1125
1127
|
if (l === "getAllFormRefs")
|
|
1126
|
-
return () =>
|
|
1128
|
+
return () => ke.getState().getFormRefsByStateKey(e);
|
|
1127
1129
|
if (l === "_initialState")
|
|
1128
1130
|
return r.getState().initialStateGlobal[e];
|
|
1129
1131
|
if (l === "_serverState")
|
|
@@ -1136,13 +1138,13 @@ function me(e, i, m, g) {
|
|
|
1136
1138
|
if (l === "removeValidation") return v.removeValidation;
|
|
1137
1139
|
}
|
|
1138
1140
|
if (l === "getFormRef")
|
|
1139
|
-
return () =>
|
|
1141
|
+
return () => ke.getState().getFormRef(e + "." + n.join("."));
|
|
1140
1142
|
if (l === "validationWrapper")
|
|
1141
1143
|
return ({
|
|
1142
1144
|
children: d,
|
|
1143
1145
|
hideMessage: t
|
|
1144
|
-
}) => /* @__PURE__ */
|
|
1145
|
-
|
|
1146
|
+
}) => /* @__PURE__ */ we(
|
|
1147
|
+
Fe,
|
|
1146
1148
|
{
|
|
1147
1149
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
1148
1150
|
path: n,
|
|
@@ -1158,21 +1160,21 @@ function me(e, i, m, g) {
|
|
|
1158
1160
|
if (l === "update")
|
|
1159
1161
|
return (d, t) => {
|
|
1160
1162
|
if (t?.debounce)
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
+
He(() => {
|
|
1164
|
+
ie(i, d, n, "");
|
|
1163
1165
|
const o = r.getState().getNestedState(e, n);
|
|
1164
1166
|
t?.afterUpdate && t.afterUpdate(o);
|
|
1165
1167
|
}, t.debounce);
|
|
1166
1168
|
else {
|
|
1167
|
-
|
|
1169
|
+
ie(i, d, n, "");
|
|
1168
1170
|
const o = r.getState().getNestedState(e, n);
|
|
1169
1171
|
t?.afterUpdate && t.afterUpdate(o);
|
|
1170
1172
|
}
|
|
1171
1173
|
p(n);
|
|
1172
1174
|
};
|
|
1173
1175
|
if (l === "formElement")
|
|
1174
|
-
return (d, t) => /* @__PURE__ */
|
|
1175
|
-
|
|
1176
|
+
return (d, t) => /* @__PURE__ */ we(
|
|
1177
|
+
Be,
|
|
1176
1178
|
{
|
|
1177
1179
|
setState: i,
|
|
1178
1180
|
stateKey: e,
|
|
@@ -1181,23 +1183,23 @@ function me(e, i, m, g) {
|
|
|
1181
1183
|
formOpts: t
|
|
1182
1184
|
}
|
|
1183
1185
|
);
|
|
1184
|
-
const
|
|
1185
|
-
return a(ae,
|
|
1186
|
+
const L = [...n, l], ae = r.getState().getNestedState(e, L);
|
|
1187
|
+
return a(ae, L, S);
|
|
1186
1188
|
}
|
|
1187
|
-
},
|
|
1188
|
-
return T.set(
|
|
1189
|
-
proxy:
|
|
1189
|
+
}, W = new Proxy(R, D);
|
|
1190
|
+
return T.set(B, {
|
|
1191
|
+
proxy: W,
|
|
1190
1192
|
stateVersion: C
|
|
1191
|
-
}),
|
|
1193
|
+
}), W;
|
|
1192
1194
|
}
|
|
1193
1195
|
return a(
|
|
1194
1196
|
r.getState().getNestedState(e, [])
|
|
1195
1197
|
);
|
|
1196
1198
|
}
|
|
1197
|
-
function
|
|
1198
|
-
return
|
|
1199
|
+
function Ve(e) {
|
|
1200
|
+
return le(nt, { proxy: e });
|
|
1199
1201
|
}
|
|
1200
|
-
function
|
|
1202
|
+
function tt({
|
|
1201
1203
|
proxy: e,
|
|
1202
1204
|
rebuildStateShape: i
|
|
1203
1205
|
}) {
|
|
@@ -1209,10 +1211,10 @@ function et({
|
|
|
1209
1211
|
(T, C, p, v, a) => e._mapFn(T, C, p, v, a)
|
|
1210
1212
|
) : null;
|
|
1211
1213
|
}
|
|
1212
|
-
function
|
|
1214
|
+
function nt({
|
|
1213
1215
|
proxy: e
|
|
1214
1216
|
}) {
|
|
1215
|
-
const i =
|
|
1217
|
+
const i = J(null), m = `${e._stateKey}-${e._path.join(".")}`;
|
|
1216
1218
|
return oe(() => {
|
|
1217
1219
|
const g = i.current;
|
|
1218
1220
|
if (!g || !g.parentElement) return;
|
|
@@ -1234,22 +1236,22 @@ function tt({
|
|
|
1234
1236
|
"state",
|
|
1235
1237
|
`return (${e._effect})(state)`
|
|
1236
1238
|
)(n);
|
|
1237
|
-
} catch (
|
|
1238
|
-
console.error("Error evaluating effect function during mount:",
|
|
1239
|
+
} catch (R) {
|
|
1240
|
+
console.error("Error evaluating effect function during mount:", R), S = n;
|
|
1239
1241
|
}
|
|
1240
1242
|
else
|
|
1241
1243
|
S = n;
|
|
1242
1244
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1243
|
-
const
|
|
1244
|
-
g.replaceWith(
|
|
1245
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
1245
|
+
const B = document.createTextNode(String(S));
|
|
1246
|
+
g.replaceWith(B);
|
|
1247
|
+
}, [e._stateKey, e._path.join("."), e._effect]), le("span", {
|
|
1246
1248
|
ref: i,
|
|
1247
1249
|
style: { display: "none" },
|
|
1248
1250
|
"data-signal-id": m
|
|
1249
1251
|
});
|
|
1250
1252
|
}
|
|
1251
|
-
function
|
|
1252
|
-
const i =
|
|
1253
|
+
function vt(e) {
|
|
1254
|
+
const i = De(
|
|
1253
1255
|
(m) => {
|
|
1254
1256
|
const g = r.getState().stateComponents.get(e._stateKey) || {
|
|
1255
1257
|
components: /* @__PURE__ */ new Map()
|
|
@@ -1261,22 +1263,22 @@ function ht(e) {
|
|
|
1261
1263
|
},
|
|
1262
1264
|
() => r.getState().getNestedState(e._stateKey, e._path)
|
|
1263
1265
|
);
|
|
1264
|
-
return
|
|
1266
|
+
return le("text", {}, String(i));
|
|
1265
1267
|
}
|
|
1266
|
-
function
|
|
1268
|
+
function rt({
|
|
1267
1269
|
stateKey: e,
|
|
1268
1270
|
itemComponentId: i,
|
|
1269
1271
|
itemPath: m,
|
|
1270
1272
|
children: g
|
|
1271
1273
|
}) {
|
|
1272
|
-
const [, T] =
|
|
1274
|
+
const [, T] = K({}), [C, p] = qe(), v = J(null);
|
|
1273
1275
|
return oe(() => {
|
|
1274
1276
|
p.height > 0 && p.height !== v.current && (v.current = p.height, r.getState().setShadowMetadata(e, m, {
|
|
1275
1277
|
virtualizer: {
|
|
1276
1278
|
itemHeight: p.height
|
|
1277
1279
|
}
|
|
1278
1280
|
}));
|
|
1279
|
-
}, [p.height, e, m]),
|
|
1281
|
+
}, [p.height, e, m]), ce(() => {
|
|
1280
1282
|
const a = `${e}////${i}`, h = r.getState().stateComponents.get(e) || {
|
|
1281
1283
|
components: /* @__PURE__ */ new Map()
|
|
1282
1284
|
};
|
|
@@ -1287,14 +1289,14 @@ function nt({
|
|
|
1287
1289
|
const n = r.getState().stateComponents.get(e);
|
|
1288
1290
|
n && n.components.delete(a);
|
|
1289
1291
|
};
|
|
1290
|
-
}, [e, i, m.join(".")]), /* @__PURE__ */
|
|
1292
|
+
}, [e, i, m.join(".")]), /* @__PURE__ */ we("div", { ref: C, children: g });
|
|
1291
1293
|
}
|
|
1292
1294
|
export {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1295
|
+
Ve as $cogsSignal,
|
|
1296
|
+
vt as $cogsSignalStore,
|
|
1297
|
+
It as addStateOptions,
|
|
1298
|
+
ht as createCogsState,
|
|
1299
|
+
Tt as notifyComponent,
|
|
1300
|
+
et as useCogsStateFn
|
|
1299
1301
|
};
|
|
1300
1302
|
//# sourceMappingURL=CogsState.jsx.map
|