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