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