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