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