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