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