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