cogsbox-state 0.5.357 → 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 +551 -556
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +100 -87
package/dist/CogsState.jsx
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as Q, useRef as Z, useEffect as et, useLayoutEffect 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
|
|
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
15
|
g(t, {
|
|
16
16
|
...y,
|
|
17
|
-
...
|
|
17
|
+
...c
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function wt({
|
|
21
21
|
stateKey: t,
|
|
22
|
-
options:
|
|
23
|
-
initialOptionsPart:
|
|
22
|
+
options: c,
|
|
23
|
+
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g = tt(t) || {}, y =
|
|
25
|
+
const g = tt(t) || {}, y = m[t] || {}, N = r.getState().setInitialStateOptions, p = { ...y, ...g };
|
|
26
26
|
let I = !1;
|
|
27
|
-
if (
|
|
28
|
-
for (const a in
|
|
29
|
-
p.hasOwnProperty(a) ? (a == "localStorage" &&
|
|
30
|
-
!
|
|
31
|
-
I &&
|
|
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
|
|
37
|
-
let
|
|
38
|
-
const [g, y] =
|
|
39
|
-
(Object.keys(y).length > 0 ||
|
|
36
|
+
const ae = (t, c) => {
|
|
37
|
+
let m = t;
|
|
38
|
+
const [g, y] = Vt(m);
|
|
39
|
+
(Object.keys(y).length > 0 || c && Object.keys(c).length > 0) && Object.keys(y).forEach((I) => {
|
|
40
40
|
y[I] = y[I] || {}, y[I].formElements = {
|
|
41
|
-
...
|
|
41
|
+
...c?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
|
-
...
|
|
43
|
+
...c?.validation,
|
|
44
44
|
...y[I].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
46
|
}, tt(I) || r.getState().setInitialStateOptions(I, y[I]);
|
|
47
47
|
}), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
|
|
48
|
-
const
|
|
49
|
-
const [v] = Q(a?.componentId ??
|
|
50
|
-
|
|
48
|
+
const N = (I, a) => {
|
|
49
|
+
const [v] = Q(a?.componentId ?? ht());
|
|
50
|
+
wt({
|
|
51
51
|
stateKey: I,
|
|
52
52
|
options: a,
|
|
53
53
|
initialOptionsPart: y
|
|
54
54
|
});
|
|
55
|
-
const n = r.getState().cogsStateStore[I] || g[I], f = a?.modifyState ? a.modifyState(n) : n, [G,
|
|
55
|
+
const n = r.getState().cogsStateStore[I] || g[I], f = a?.modifyState ? a.modifyState(n) : n, [G, U] = Wt(
|
|
56
56
|
f,
|
|
57
57
|
{
|
|
58
58
|
stateKey: I,
|
|
@@ -68,111 +68,111 @@ const fe = (t, i) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return U;
|
|
72
72
|
};
|
|
73
73
|
function p(I, a) {
|
|
74
|
-
|
|
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:
|
|
78
|
+
setUpdaterState: ct,
|
|
79
79
|
setState: K,
|
|
80
80
|
getInitialOptions: tt,
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
81
|
+
getKeyState: kt,
|
|
82
|
+
getValidationErrors: Ut,
|
|
83
|
+
setStateLog: jt,
|
|
84
|
+
updateInitialStateGlobal: vt,
|
|
85
|
+
addValidationError: Lt,
|
|
86
86
|
removeValidationError: J,
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} = r.getState(),
|
|
89
|
-
|
|
87
|
+
setServerSyncActions: Dt
|
|
88
|
+
} = r.getState(), Et = (t, c, m, g, y) => {
|
|
89
|
+
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
c,
|
|
92
|
+
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const p = `${g}-${
|
|
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
98
|
let I;
|
|
99
99
|
try {
|
|
100
|
-
I =
|
|
100
|
+
I = dt(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
104
|
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
106
|
lastSyncedWithServer: y ?? I
|
|
107
|
-
}, v =
|
|
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
|
|
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
123
|
if (y && g) {
|
|
124
|
-
const
|
|
124
|
+
const N = dt(
|
|
125
125
|
`${g}-${t}-${y}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return K(t,
|
|
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
136
|
g,
|
|
137
137
|
y,
|
|
138
|
-
|
|
138
|
+
N
|
|
139
139
|
),
|
|
140
|
-
state:
|
|
140
|
+
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") ||
|
|
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
|
+
const m = /* @__PURE__ */ new Set();
|
|
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
|
-
|
|
150
|
+
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
const g = `${t}////${
|
|
152
|
+
}, se = (t, c) => {
|
|
153
|
+
const m = r.getState().stateComponents.get(t);
|
|
154
|
+
if (m) {
|
|
155
|
+
const g = `${t}////${c}`, y = m.components.get(g);
|
|
156
156
|
if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
158
|
y && y.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
160
|
+
}, Gt = (t, c, m, g) => {
|
|
161
161
|
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
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:
|
|
171
|
+
newValue: z(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: z(c, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,12 +180,12 @@ const fe = (t, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
184
|
-
stateKey:
|
|
185
|
-
serverSync:
|
|
183
|
+
function Wt(t, {
|
|
184
|
+
stateKey: c,
|
|
185
|
+
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
187
|
formElements: y,
|
|
188
|
-
reactiveDeps:
|
|
188
|
+
reactiveDeps: N,
|
|
189
189
|
reactiveType: p,
|
|
190
190
|
componentId: I,
|
|
191
191
|
initialState: a,
|
|
@@ -193,14 +193,14 @@ function Xt(t, {
|
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: f
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [G,
|
|
197
|
-
let
|
|
198
|
-
const [
|
|
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
|
-
|
|
202
|
-
if (v && v.stateKey ===
|
|
203
|
-
K(
|
|
201
|
+
_.current = tt(h) ?? null, et(() => {
|
|
202
|
+
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
+
K(h, (o) => ({
|
|
204
204
|
...o,
|
|
205
205
|
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
@@ -212,235 +212,235 @@ function Xt(t, {
|
|
|
212
212
|
}
|
|
213
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
|
|
221
|
+
let d = null;
|
|
222
222
|
const w = Y(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
-
w && j && (
|
|
224
|
-
let
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
227
|
-
|
|
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
|
+
h,
|
|
228
228
|
a,
|
|
229
|
-
|
|
229
|
+
E,
|
|
230
230
|
nt,
|
|
231
231
|
X.current,
|
|
232
232
|
j
|
|
233
|
-
), T && w && 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
237
|
f?.status,
|
|
238
238
|
f?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
242
|
-
serverSync:
|
|
240
|
+
]), it(() => {
|
|
241
|
+
W && pt(h, {
|
|
242
|
+
serverSync: m,
|
|
243
243
|
formElements: y,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: _.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const e = `${
|
|
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(
|
|
258
|
-
o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(
|
|
257
|
+
}), r.getState().stateComponents.set(h, o), U({}), () => {
|
|
258
|
+
o && (o.components.delete(e), o.components.size === 0 && r.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const nt = (e, o, s,
|
|
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
|
-
K(
|
|
268
|
-
const w = Y(e) ? e(
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
if ((
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
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
298
|
const T = o.slice(0, o.length - 1);
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
J(
|
|
299
|
+
s.updateType === "cut" && _.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
|
-
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
314
|
+
F,
|
|
315
|
+
$
|
|
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
|
+
$.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 (
|
|
329
|
-
|
|
328
|
+
if ($.paths.has(V)) {
|
|
329
|
+
L = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
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(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(V.substring(H + 1))
|
|
340
|
+
) && $.paths.has(q)) {
|
|
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
|
-
const
|
|
362
|
-
o = o.map((
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const P = Date.now();
|
|
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:
|
|
366
|
+
const { oldValue: O, newValue: D } = Gt(
|
|
367
367
|
s.updateType,
|
|
368
|
-
|
|
368
|
+
d,
|
|
369
369
|
w,
|
|
370
370
|
o
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
373
|
-
stateKey:
|
|
371
|
+
), M = {
|
|
372
|
+
timeStamp: P,
|
|
373
|
+
stateKey: h,
|
|
374
374
|
path: o,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: O,
|
|
378
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
|
-
}),
|
|
398
|
+
return Array.from(R.values());
|
|
399
|
+
}), Et(
|
|
400
400
|
w,
|
|
401
|
-
|
|
402
|
-
|
|
401
|
+
h,
|
|
402
|
+
_.current,
|
|
403
403
|
j
|
|
404
|
-
),
|
|
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
416
|
return w;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
r.getState().updaterState[
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
r.getState().updaterState[h] || (ct(
|
|
420
|
+
h,
|
|
421
|
+
lt(
|
|
422
|
+
h,
|
|
423
423
|
nt,
|
|
424
424
|
X.current,
|
|
425
425
|
j
|
|
426
426
|
)
|
|
427
|
-
), r.getState().cogsStateStore[
|
|
428
|
-
const
|
|
429
|
-
|
|
427
|
+
), r.getState().cogsStateStore[h] || K(h, t), r.getState().initialStateGlobal[h] || vt(h, t));
|
|
428
|
+
const u = St(() => lt(
|
|
429
|
+
h,
|
|
430
430
|
nt,
|
|
431
431
|
X.current,
|
|
432
432
|
j
|
|
433
|
-
), [
|
|
434
|
-
return [
|
|
433
|
+
), [h, j]);
|
|
434
|
+
return [kt(h), u];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
436
|
+
function lt(t, c, m, g) {
|
|
437
437
|
const y = /* @__PURE__ */ new Map();
|
|
438
|
-
let
|
|
438
|
+
let N = 0;
|
|
439
439
|
const p = (v) => {
|
|
440
440
|
const n = v.join(".");
|
|
441
441
|
for (const [f] of y)
|
|
442
442
|
(f === n || f.startsWith(n + ".")) && y.delete(f);
|
|
443
|
-
|
|
443
|
+
N++;
|
|
444
444
|
}, I = {
|
|
445
445
|
removeValidation: (v) => {
|
|
446
446
|
v?.validationKey && J(v.validationKey);
|
|
@@ -449,30 +449,30 @@ function St(t, i, S, g) {
|
|
|
449
449
|
const n = r.getState().getInitialOptions(t)?.validation;
|
|
450
450
|
n?.key && J(n?.key), v?.validationKey && J(v.validationKey);
|
|
451
451
|
const f = r.getState().initialStateGlobal[t];
|
|
452
|
-
r.getState().clearSelectedIndexesForState(t), y.clear(),
|
|
453
|
-
const G = a(f, []),
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
return
|
|
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
|
+
const h = r.getState().stateComponents.get(t);
|
|
456
|
+
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), f;
|
|
459
459
|
},
|
|
460
460
|
updateInitialState: (v) => {
|
|
461
|
-
y.clear(),
|
|
462
|
-
const n =
|
|
461
|
+
y.clear(), N++;
|
|
462
|
+
const n = lt(
|
|
463
463
|
t,
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
c,
|
|
465
|
+
m,
|
|
466
466
|
g
|
|
467
|
-
), f = r.getState().initialStateGlobal[t], G = tt(t),
|
|
468
|
-
return localStorage.getItem(j) && localStorage.removeItem(j),
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
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
|
+
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 St(t, i, S, g) {
|
|
|
480
480
|
_isLoading: r.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
482
|
const v = r.getState().serverState[t];
|
|
483
|
-
return !!(v &&
|
|
483
|
+
return !!(v && B(v, kt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
function a(v, n = [], f) {
|
|
487
487
|
const G = n.map(String).join(".");
|
|
488
488
|
y.get(G);
|
|
489
|
-
const
|
|
489
|
+
const U = function() {
|
|
490
490
|
return r().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(I).forEach((
|
|
493
|
-
|
|
492
|
+
Object.keys(I).forEach((h) => {
|
|
493
|
+
U[h] = I[h];
|
|
494
494
|
});
|
|
495
495
|
const j = {
|
|
496
|
-
apply(
|
|
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
|
-
get(
|
|
501
|
+
get(h, l) {
|
|
502
502
|
f?.validIndices && !Array.isArray(v) && (f = { ...f, validIndices: void 0 });
|
|
503
|
-
const
|
|
503
|
+
const at = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,76 +523,76 @@ function St(t, i, S, g) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
527
|
-
const
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !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 w = [s, ...
|
|
558
|
-
r.getState().addValidationError(w,
|
|
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
|
|
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
|
-
), e = r.getState().initialStateGlobal[t], o =
|
|
580
|
-
return
|
|
579
|
+
), e = r.getState().initialStateGlobal[t], o = z(e, n);
|
|
580
|
+
return B(u, o) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const
|
|
584
|
+
const u = r.getState().initialStateGlobal[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
597
|
originalIndex: f.validIndices[s]
|
|
598
598
|
})) : r.getState().getNestedState(t, n).map((o, s) => ({
|
|
@@ -620,178 +620,173 @@ function St(t, i, S, g) {
|
|
|
620
620
|
const {
|
|
621
621
|
itemHeight: o = 50,
|
|
622
622
|
overscan: s = 6,
|
|
623
|
-
stickToBottom:
|
|
624
|
-
dependencies:
|
|
625
|
-
} = e,
|
|
623
|
+
stickToBottom: i = !1,
|
|
624
|
+
dependencies: S = []
|
|
625
|
+
} = e, d = Z(null), [w, E] = Q({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), T = Z(
|
|
628
|
+
}), T = Z(i), k = Z(null), [P, O] = Q(0);
|
|
629
629
|
et(() => r.getState().subscribeToShadowState(t, () => {
|
|
630
|
-
|
|
630
|
+
O((b) => b + 1);
|
|
631
631
|
}), [t]);
|
|
632
632
|
const D = r().getNestedState(
|
|
633
633
|
t,
|
|
634
634
|
n
|
|
635
|
-
),
|
|
636
|
-
const
|
|
637
|
-
let
|
|
638
|
-
const
|
|
639
|
-
for (let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
635
|
+
), M = D.length, { totalHeight: x, positions: C } = St(() => {
|
|
636
|
+
const A = r.getState().getShadowMetadata(t, n) || [];
|
|
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;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: b, positions: V };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
646
|
+
M,
|
|
647
647
|
t,
|
|
648
648
|
n.join("."),
|
|
649
649
|
o,
|
|
650
|
-
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
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
657
|
...f,
|
|
658
|
-
validIndices:
|
|
658
|
+
validIndices: V
|
|
659
659
|
});
|
|
660
|
-
}, [w.startIndex, w.endIndex, D,
|
|
661
|
-
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
660
|
+
}, [w.startIndex, w.endIndex, D, M]);
|
|
661
|
+
it(() => {
|
|
662
|
+
const A = d.current;
|
|
663
|
+
if (!A || !i || !T.current)
|
|
664
|
+
return;
|
|
665
|
+
k.current && clearInterval(k.current), console.log("ALGORITHM: Starting..."), E({
|
|
666
|
+
startIndex: Math.max(0, M - 10 - s),
|
|
667
|
+
endIndex: M
|
|
668
|
+
}), console.log(
|
|
669
|
+
"ALGORITHM: Starting LOOP to wait for measurement."
|
|
670
|
+
);
|
|
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;
|
|
670
678
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
const Rt = rt + Tt;
|
|
674
|
-
for (; dt < x && $[dt] < Rt; )
|
|
675
|
-
dt++;
|
|
676
|
-
A({
|
|
677
|
-
startIndex: $t,
|
|
678
|
-
endIndex: Math.min(x, dt + s)
|
|
679
|
-
});
|
|
680
|
-
};
|
|
681
|
-
let B;
|
|
682
|
-
P ? (console.log("ALGORITHM: Auto-scroll triggered."), console.log(
|
|
683
|
-
"...Setting range to the end to render last item."
|
|
684
|
-
), A({
|
|
685
|
-
startIndex: Math.max(0, x - 10 - s),
|
|
686
|
-
endIndex: x
|
|
687
|
-
}), console.log("...Starting loop to wait for measurement."), B = setInterval(() => {
|
|
688
|
-
const rt = x - 1;
|
|
689
|
-
((r.getState().getShadowMetadata(t, n) || [])[rt]?.virtualizer?.itemHeight || 0) > 0 ? (console.log(
|
|
690
|
-
"%c...SUCCESS: Last item measured. Scrolling.",
|
|
679
|
+
((r.getState().getShadowMetadata(t, n) || [])[V]?.virtualizer?.itemHeight || 0) > 0 ? (console.log(
|
|
680
|
+
"%cSUCCESS: Last item is measured. Scrolling.",
|
|
691
681
|
"color: green; font-weight: bold;"
|
|
692
|
-
), clearInterval(
|
|
693
|
-
top:
|
|
682
|
+
), clearInterval(k.current), k.current = null, A.scrollTo({
|
|
683
|
+
top: A.scrollHeight,
|
|
694
684
|
behavior: "smooth"
|
|
695
|
-
})) : console.log("...WAITING
|
|
696
|
-
}, 100))
|
|
697
|
-
|
|
698
|
-
E.scrollHeight - E.scrollTop - E.clientHeight < 1 || (T.current = !1), W();
|
|
685
|
+
})) : (console.log("...WAITING. Height is not ready."), b > 30 && (console.error("LOOP TIMEOUT. Stopping."), clearInterval(k.current), k.current = null));
|
|
686
|
+
}, 100), () => {
|
|
687
|
+
k.current && clearInterval(k.current);
|
|
699
688
|
};
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
689
|
+
}, [M, ...S]), et(() => {
|
|
690
|
+
const A = d.current;
|
|
691
|
+
if (!A) return;
|
|
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.")));
|
|
704
698
|
};
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
699
|
+
return A.addEventListener("scroll", b, {
|
|
700
|
+
passive: !0
|
|
701
|
+
}), () => A.removeEventListener("scroll", b);
|
|
702
|
+
}, [M, C, ...S]);
|
|
703
|
+
const F = yt(
|
|
704
|
+
(A = "smooth") => {
|
|
705
|
+
d.current && (T.current = !0, console.log("USER ACTION: Scroll lock ENABLED."), d.current.scrollTo({
|
|
706
|
+
top: d.current.scrollHeight,
|
|
707
|
+
behavior: A
|
|
713
708
|
}));
|
|
714
709
|
},
|
|
715
710
|
[]
|
|
716
|
-
),
|
|
717
|
-
(
|
|
718
|
-
|
|
719
|
-
top:
|
|
720
|
-
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
|
|
721
716
|
}));
|
|
722
717
|
},
|
|
723
|
-
[
|
|
724
|
-
),
|
|
718
|
+
[C]
|
|
719
|
+
), L = {
|
|
725
720
|
outer: {
|
|
726
|
-
ref:
|
|
721
|
+
ref: d,
|
|
727
722
|
style: { overflowY: "auto", height: "100%" }
|
|
728
723
|
},
|
|
729
724
|
inner: {
|
|
730
725
|
style: {
|
|
731
|
-
height: `${
|
|
726
|
+
height: `${x}px`,
|
|
732
727
|
position: "relative"
|
|
733
728
|
}
|
|
734
729
|
},
|
|
735
730
|
list: {
|
|
736
731
|
style: {
|
|
737
|
-
transform: `translateY(${
|
|
732
|
+
transform: `translateY(${C[w.startIndex] || 0}px)`
|
|
738
733
|
}
|
|
739
734
|
}
|
|
740
735
|
};
|
|
741
736
|
return {
|
|
742
|
-
virtualState:
|
|
743
|
-
virtualizerProps:
|
|
744
|
-
scrollToBottom:
|
|
745
|
-
scrollToIndex:
|
|
737
|
+
virtualState: R,
|
|
738
|
+
virtualizerProps: L,
|
|
739
|
+
scrollToBottom: F,
|
|
740
|
+
scrollToIndex: $
|
|
746
741
|
};
|
|
747
742
|
};
|
|
748
743
|
if (l === "stateSort")
|
|
749
744
|
return (e) => {
|
|
750
|
-
const s = [...
|
|
751
|
-
(
|
|
752
|
-
),
|
|
745
|
+
const s = [...u()].sort(
|
|
746
|
+
(d, w) => e(d.item, w.item)
|
|
747
|
+
), i = s.map(({ item: d }) => d), S = {
|
|
753
748
|
...f,
|
|
754
749
|
validIndices: s.map(
|
|
755
|
-
({ originalIndex:
|
|
750
|
+
({ originalIndex: d }) => d
|
|
756
751
|
)
|
|
757
752
|
};
|
|
758
|
-
return a(
|
|
753
|
+
return a(i, n, S);
|
|
759
754
|
};
|
|
760
755
|
if (l === "stateFilter")
|
|
761
756
|
return (e) => {
|
|
762
|
-
const s =
|
|
763
|
-
({ item:
|
|
764
|
-
),
|
|
757
|
+
const s = u().filter(
|
|
758
|
+
({ item: d }, w) => e(d, w)
|
|
759
|
+
), i = s.map(({ item: d }) => d), S = {
|
|
765
760
|
...f,
|
|
766
761
|
validIndices: s.map(
|
|
767
|
-
({ originalIndex:
|
|
762
|
+
({ originalIndex: d }) => d
|
|
768
763
|
)
|
|
769
764
|
};
|
|
770
|
-
return a(
|
|
765
|
+
return a(i, n, S);
|
|
771
766
|
};
|
|
772
767
|
if (l === "stateMap")
|
|
773
768
|
return (e) => {
|
|
774
769
|
const o = r.getState().getNestedState(t, n);
|
|
775
|
-
return Array.isArray(o) ? (f?.validIndices || Array.from({ length: o.length }, (
|
|
776
|
-
const
|
|
777
|
-
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, {
|
|
778
773
|
register: () => {
|
|
779
|
-
const [,
|
|
780
|
-
|
|
781
|
-
const
|
|
774
|
+
const [, k] = Q({}), P = `${m}-${n.join(".")}-${i}`;
|
|
775
|
+
it(() => {
|
|
776
|
+
const O = `${t}////${P}`, D = r.getState().stateComponents.get(t) || {
|
|
782
777
|
components: /* @__PURE__ */ new Map()
|
|
783
778
|
};
|
|
784
|
-
return D.components.set(
|
|
785
|
-
forceUpdate: () =>
|
|
779
|
+
return D.components.set(O, {
|
|
780
|
+
forceUpdate: () => k({}),
|
|
786
781
|
paths: /* @__PURE__ */ new Set([w.join(".")])
|
|
787
782
|
}), r.getState().stateComponents.set(t, D), () => {
|
|
788
|
-
const
|
|
789
|
-
|
|
783
|
+
const M = r.getState().stateComponents.get(t);
|
|
784
|
+
M && M.components.delete(O);
|
|
790
785
|
};
|
|
791
|
-
}, [t,
|
|
786
|
+
}, [t, P]);
|
|
792
787
|
},
|
|
793
|
-
index:
|
|
794
|
-
originalIndex:
|
|
788
|
+
index: S,
|
|
789
|
+
originalIndex: i
|
|
795
790
|
});
|
|
796
791
|
}) : (console.warn(
|
|
797
792
|
`stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
|
|
@@ -799,20 +794,20 @@ function St(t, i, S, g) {
|
|
|
799
794
|
), null);
|
|
800
795
|
};
|
|
801
796
|
if (l === "stateMapNoRender")
|
|
802
|
-
return (e) => v.map((s,
|
|
803
|
-
let
|
|
804
|
-
f?.validIndices && f.validIndices[
|
|
805
|
-
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);
|
|
806
801
|
return e(
|
|
807
802
|
s,
|
|
808
803
|
w,
|
|
809
|
-
|
|
804
|
+
i,
|
|
810
805
|
v,
|
|
811
806
|
a(v, n, f)
|
|
812
807
|
);
|
|
813
808
|
});
|
|
814
809
|
if (l === "$stateMap")
|
|
815
|
-
return (e) =>
|
|
810
|
+
return (e) => ot(Ht, {
|
|
816
811
|
proxy: {
|
|
817
812
|
_stateKey: t,
|
|
818
813
|
_path: n,
|
|
@@ -824,17 +819,17 @@ function St(t, i, S, g) {
|
|
|
824
819
|
if (l === "stateList")
|
|
825
820
|
return (e) => {
|
|
826
821
|
const o = r.getState().getNestedState(t, n);
|
|
827
|
-
return Array.isArray(o) ? (f?.validIndices || Array.from({ length: o.length }, (
|
|
828
|
-
const
|
|
829
|
-
return
|
|
830
|
-
key:
|
|
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,
|
|
831
826
|
stateKey: t,
|
|
832
827
|
itemComponentId: T,
|
|
833
828
|
itemPath: w,
|
|
834
829
|
children: e(
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
830
|
+
d,
|
|
831
|
+
E,
|
|
832
|
+
S,
|
|
838
833
|
o,
|
|
839
834
|
a(o, n, f)
|
|
840
835
|
)
|
|
@@ -846,9 +841,9 @@ function St(t, i, S, g) {
|
|
|
846
841
|
if (l === "stateFlattenOn")
|
|
847
842
|
return (e) => {
|
|
848
843
|
const o = v;
|
|
849
|
-
y.clear(),
|
|
844
|
+
y.clear(), N++;
|
|
850
845
|
const s = o.flatMap(
|
|
851
|
-
(
|
|
846
|
+
(i) => i[e] ?? []
|
|
852
847
|
);
|
|
853
848
|
return a(
|
|
854
849
|
s,
|
|
@@ -865,40 +860,40 @@ function St(t, i, S, g) {
|
|
|
865
860
|
return () => {
|
|
866
861
|
const e = r.getState().getNestedState(t, n);
|
|
867
862
|
if (e.length === 0) return;
|
|
868
|
-
const o = e.length - 1, s = e[o],
|
|
869
|
-
return a(s,
|
|
863
|
+
const o = e.length - 1, s = e[o], i = [...n, o.toString()];
|
|
864
|
+
return a(s, i);
|
|
870
865
|
};
|
|
871
866
|
if (l === "insert")
|
|
872
|
-
return (e) => (p(n),
|
|
867
|
+
return (e) => (p(n), gt(c, e, n, t), a(
|
|
873
868
|
r.getState().getNestedState(t, n),
|
|
874
869
|
n
|
|
875
870
|
));
|
|
876
871
|
if (l === "uniqueInsert")
|
|
877
872
|
return (e, o, s) => {
|
|
878
|
-
const
|
|
879
|
-
let
|
|
880
|
-
if (!
|
|
873
|
+
const i = r.getState().getNestedState(t, n), S = Y(e) ? e(i) : e;
|
|
874
|
+
let d = null;
|
|
875
|
+
if (!i.some((E) => {
|
|
881
876
|
if (o) {
|
|
882
|
-
const
|
|
883
|
-
(
|
|
877
|
+
const k = o.every(
|
|
878
|
+
(P) => B(E[P], S[P])
|
|
884
879
|
);
|
|
885
|
-
return
|
|
880
|
+
return k && (d = E), k;
|
|
886
881
|
}
|
|
887
|
-
const T =
|
|
888
|
-
return T && (
|
|
882
|
+
const T = B(E, S);
|
|
883
|
+
return T && (d = E), T;
|
|
889
884
|
}))
|
|
890
|
-
p(n),
|
|
891
|
-
else if (s &&
|
|
892
|
-
const
|
|
893
|
-
(
|
|
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
|
|
894
889
|
);
|
|
895
|
-
p(n),
|
|
890
|
+
p(n), rt(c, T, n);
|
|
896
891
|
}
|
|
897
892
|
};
|
|
898
893
|
if (l === "cut")
|
|
899
894
|
return (e, o) => {
|
|
900
895
|
if (!o?.waitForSync)
|
|
901
|
-
return p(n),
|
|
896
|
+
return p(n), st(c, n, t, e), a(
|
|
902
897
|
r.getState().getNestedState(t, n),
|
|
903
898
|
n
|
|
904
899
|
);
|
|
@@ -906,39 +901,39 @@ function St(t, i, S, g) {
|
|
|
906
901
|
if (l === "cutByValue")
|
|
907
902
|
return (e) => {
|
|
908
903
|
for (let o = 0; o < v.length; o++)
|
|
909
|
-
v[o] === e &&
|
|
904
|
+
v[o] === e && st(c, n, t, o);
|
|
910
905
|
};
|
|
911
906
|
if (l === "toggleByValue")
|
|
912
907
|
return (e) => {
|
|
913
908
|
const o = v.findIndex((s) => s === e);
|
|
914
|
-
o > -1 ?
|
|
909
|
+
o > -1 ? st(c, n, t, o) : gt(c, e, n, t);
|
|
915
910
|
};
|
|
916
911
|
if (l === "stateFind")
|
|
917
912
|
return (e) => {
|
|
918
|
-
const s =
|
|
919
|
-
({ item:
|
|
913
|
+
const s = u().find(
|
|
914
|
+
({ item: S }, d) => e(S, d)
|
|
920
915
|
);
|
|
921
916
|
if (!s) return;
|
|
922
|
-
const
|
|
923
|
-
return a(s.item,
|
|
917
|
+
const i = [...n, s.originalIndex.toString()];
|
|
918
|
+
return a(s.item, i, f);
|
|
924
919
|
};
|
|
925
920
|
if (l === "findWith")
|
|
926
921
|
return (e, o) => {
|
|
927
|
-
const
|
|
928
|
-
({ item:
|
|
922
|
+
const i = u().find(
|
|
923
|
+
({ item: d }) => d[e] === o
|
|
929
924
|
);
|
|
930
|
-
if (!
|
|
931
|
-
const
|
|
932
|
-
return a(
|
|
925
|
+
if (!i) return;
|
|
926
|
+
const S = [...n, i.originalIndex.toString()];
|
|
927
|
+
return a(i.item, S, f);
|
|
933
928
|
};
|
|
934
929
|
}
|
|
935
930
|
const X = n[n.length - 1];
|
|
936
931
|
if (!isNaN(Number(X))) {
|
|
937
|
-
const
|
|
932
|
+
const u = n.slice(0, -1), e = r.getState().getNestedState(t, u);
|
|
938
933
|
if (Array.isArray(e) && l === "cut")
|
|
939
|
-
return () =>
|
|
940
|
-
|
|
941
|
-
|
|
934
|
+
return () => st(
|
|
935
|
+
c,
|
|
936
|
+
u,
|
|
942
937
|
t,
|
|
943
938
|
Number(X)
|
|
944
939
|
);
|
|
@@ -946,147 +941,147 @@ function St(t, i, S, g) {
|
|
|
946
941
|
if (l === "get")
|
|
947
942
|
return () => {
|
|
948
943
|
if (f?.validIndices && Array.isArray(v)) {
|
|
949
|
-
const
|
|
950
|
-
return f.validIndices.map((e) =>
|
|
944
|
+
const u = r.getState().getNestedState(t, n);
|
|
945
|
+
return f.validIndices.map((e) => u[e]);
|
|
951
946
|
}
|
|
952
947
|
return r.getState().getNestedState(t, n);
|
|
953
948
|
};
|
|
954
949
|
if (l === "$derive")
|
|
955
|
-
return (
|
|
950
|
+
return (u) => At({
|
|
956
951
|
_stateKey: t,
|
|
957
952
|
_path: n,
|
|
958
|
-
_effect:
|
|
953
|
+
_effect: u.toString()
|
|
959
954
|
});
|
|
960
955
|
if (l === "$get")
|
|
961
|
-
return () =>
|
|
956
|
+
return () => At({
|
|
962
957
|
_stateKey: t,
|
|
963
958
|
_path: n
|
|
964
959
|
});
|
|
965
960
|
if (l === "lastSynced") {
|
|
966
|
-
const
|
|
967
|
-
return r.getState().getSyncInfo(
|
|
961
|
+
const u = `${t}:${n.join(".")}`;
|
|
962
|
+
return r.getState().getSyncInfo(u);
|
|
968
963
|
}
|
|
969
964
|
if (l == "getLocalStorage")
|
|
970
|
-
return (
|
|
965
|
+
return (u) => dt(g + "-" + t + "-" + u);
|
|
971
966
|
if (l === "_selected") {
|
|
972
|
-
const
|
|
967
|
+
const u = n.slice(0, -1), e = u.join("."), o = r.getState().getNestedState(t, u);
|
|
973
968
|
return Array.isArray(o) ? Number(n[n.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
|
|
974
969
|
}
|
|
975
970
|
if (l === "setSelected")
|
|
976
|
-
return (
|
|
971
|
+
return (u) => {
|
|
977
972
|
const e = n.slice(0, -1), o = Number(n[n.length - 1]), s = e.join(".");
|
|
978
|
-
|
|
979
|
-
const
|
|
980
|
-
|
|
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);
|
|
981
976
|
};
|
|
982
977
|
if (l === "toggleSelected")
|
|
983
978
|
return () => {
|
|
984
|
-
const
|
|
979
|
+
const u = n.slice(0, -1), e = Number(n[n.length - 1]), o = u.join("."), s = r.getState().getSelectedIndex(t, o);
|
|
985
980
|
r.getState().setSelectedIndex(
|
|
986
981
|
t,
|
|
987
982
|
o,
|
|
988
983
|
s === e ? void 0 : e
|
|
989
984
|
);
|
|
990
|
-
const
|
|
991
|
-
|
|
985
|
+
const i = r.getState().getNestedState(t, [...u]);
|
|
986
|
+
rt(c, i, u), p(u);
|
|
992
987
|
};
|
|
993
988
|
if (n.length == 0) {
|
|
994
989
|
if (l === "applyJsonPatch")
|
|
995
|
-
return (
|
|
996
|
-
const e = r.getState().cogsStateStore[t], s =
|
|
997
|
-
|
|
990
|
+
return (u) => {
|
|
991
|
+
const e = r.getState().cogsStateStore[t], s = Mt(e, u).newDocument;
|
|
992
|
+
$t(
|
|
998
993
|
t,
|
|
999
994
|
r.getState().initialStateGlobal[t],
|
|
1000
995
|
s,
|
|
1001
|
-
|
|
1002
|
-
|
|
996
|
+
c,
|
|
997
|
+
m,
|
|
1003
998
|
g
|
|
1004
999
|
);
|
|
1005
|
-
const
|
|
1006
|
-
if (
|
|
1007
|
-
const
|
|
1000
|
+
const i = r.getState().stateComponents.get(t);
|
|
1001
|
+
if (i) {
|
|
1002
|
+
const S = mt(e, s), d = new Set(S);
|
|
1008
1003
|
for (const [
|
|
1009
1004
|
w,
|
|
1010
|
-
|
|
1011
|
-
] of
|
|
1005
|
+
E
|
|
1006
|
+
] of i.components.entries()) {
|
|
1012
1007
|
let T = !1;
|
|
1013
|
-
const
|
|
1014
|
-
if (!
|
|
1015
|
-
if (
|
|
1016
|
-
|
|
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();
|
|
1017
1012
|
continue;
|
|
1018
1013
|
}
|
|
1019
|
-
if (
|
|
1020
|
-
for (const
|
|
1021
|
-
if (
|
|
1014
|
+
if (k.includes("component") && (E.paths.has("") && (T = !0), !T))
|
|
1015
|
+
for (const P of d) {
|
|
1016
|
+
if (E.paths.has(P)) {
|
|
1022
1017
|
T = !0;
|
|
1023
1018
|
break;
|
|
1024
1019
|
}
|
|
1025
|
-
let
|
|
1026
|
-
for (;
|
|
1027
|
-
const D =
|
|
1028
|
-
if (
|
|
1020
|
+
let O = P.lastIndexOf(".");
|
|
1021
|
+
for (; O !== -1; ) {
|
|
1022
|
+
const D = P.substring(0, O);
|
|
1023
|
+
if (E.paths.has(D)) {
|
|
1029
1024
|
T = !0;
|
|
1030
1025
|
break;
|
|
1031
1026
|
}
|
|
1032
|
-
const
|
|
1033
|
-
|
|
1027
|
+
const M = P.substring(
|
|
1028
|
+
O + 1
|
|
1034
1029
|
);
|
|
1035
|
-
if (!isNaN(Number(
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
const
|
|
1030
|
+
if (!isNaN(Number(M))) {
|
|
1031
|
+
const x = D.lastIndexOf(".");
|
|
1032
|
+
if (x !== -1) {
|
|
1033
|
+
const C = D.substring(
|
|
1039
1034
|
0,
|
|
1040
|
-
|
|
1035
|
+
x
|
|
1041
1036
|
);
|
|
1042
|
-
if (
|
|
1037
|
+
if (E.paths.has(C)) {
|
|
1043
1038
|
T = !0;
|
|
1044
1039
|
break;
|
|
1045
1040
|
}
|
|
1046
1041
|
}
|
|
1047
1042
|
}
|
|
1048
|
-
|
|
1043
|
+
O = D.lastIndexOf(".");
|
|
1049
1044
|
}
|
|
1050
1045
|
if (T) break;
|
|
1051
1046
|
}
|
|
1052
|
-
if (!T &&
|
|
1053
|
-
const
|
|
1054
|
-
let
|
|
1055
|
-
typeof
|
|
1047
|
+
if (!T && k.includes("deps") && E.depsFunction) {
|
|
1048
|
+
const P = E.depsFunction(s);
|
|
1049
|
+
let O = !1;
|
|
1050
|
+
typeof P == "boolean" ? P && (O = !0) : B(E.deps, P) || (E.deps = P, O = !0), O && (T = !0);
|
|
1056
1051
|
}
|
|
1057
|
-
T &&
|
|
1052
|
+
T && E.forceUpdate();
|
|
1058
1053
|
}
|
|
1059
1054
|
}
|
|
1060
1055
|
}
|
|
1061
1056
|
};
|
|
1062
1057
|
if (l === "validateZodSchema")
|
|
1063
1058
|
return () => {
|
|
1064
|
-
const
|
|
1065
|
-
if (!
|
|
1059
|
+
const u = r.getState().getInitialOptions(t)?.validation, e = r.getState().addValidationError;
|
|
1060
|
+
if (!u?.zodSchema)
|
|
1066
1061
|
throw new Error("Zod schema not found");
|
|
1067
|
-
if (!
|
|
1062
|
+
if (!u?.key)
|
|
1068
1063
|
throw new Error("Validation key not found");
|
|
1069
|
-
J(
|
|
1064
|
+
J(u.key);
|
|
1070
1065
|
const o = r.getState().cogsStateStore[t];
|
|
1071
1066
|
try {
|
|
1072
|
-
const s = r.getState().getValidationErrors(
|
|
1073
|
-
s && s.length > 0 && s.forEach(([
|
|
1074
|
-
|
|
1067
|
+
const s = r.getState().getValidationErrors(u.key);
|
|
1068
|
+
s && s.length > 0 && s.forEach(([S]) => {
|
|
1069
|
+
S && S.startsWith(u.key) && J(S);
|
|
1075
1070
|
});
|
|
1076
|
-
const
|
|
1077
|
-
return
|
|
1078
|
-
const w =
|
|
1079
|
-
e(T,
|
|
1080
|
-
}),
|
|
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);
|
|
1081
1076
|
} catch (s) {
|
|
1082
1077
|
return console.error("Zod schema validation failed", s), !1;
|
|
1083
1078
|
}
|
|
1084
1079
|
};
|
|
1085
|
-
if (l === "_componentId") return
|
|
1080
|
+
if (l === "_componentId") return m;
|
|
1086
1081
|
if (l === "getComponents")
|
|
1087
1082
|
return () => r().stateComponents.get(t);
|
|
1088
1083
|
if (l === "getAllFormRefs")
|
|
1089
|
-
return () =>
|
|
1084
|
+
return () => It.getState().getFormRefsByStateKey(t);
|
|
1090
1085
|
if (l === "_initialState")
|
|
1091
1086
|
return r.getState().initialStateGlobal[t];
|
|
1092
1087
|
if (l === "_serverState")
|
|
@@ -1099,85 +1094,85 @@ function St(t, i, S, g) {
|
|
|
1099
1094
|
if (l === "removeValidation") return I.removeValidation;
|
|
1100
1095
|
}
|
|
1101
1096
|
if (l === "getFormRef")
|
|
1102
|
-
return () =>
|
|
1097
|
+
return () => It.getState().getFormRef(t + "." + n.join("."));
|
|
1103
1098
|
if (l === "validationWrapper")
|
|
1104
1099
|
return ({
|
|
1105
|
-
children:
|
|
1100
|
+
children: u,
|
|
1106
1101
|
hideMessage: e
|
|
1107
|
-
}) => /* @__PURE__ */
|
|
1108
|
-
|
|
1102
|
+
}) => /* @__PURE__ */ ft(
|
|
1103
|
+
xt,
|
|
1109
1104
|
{
|
|
1110
1105
|
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1111
1106
|
path: n,
|
|
1112
1107
|
validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1113
1108
|
stateKey: t,
|
|
1114
1109
|
validIndices: f?.validIndices,
|
|
1115
|
-
children:
|
|
1110
|
+
children: u
|
|
1116
1111
|
}
|
|
1117
1112
|
);
|
|
1118
1113
|
if (l === "_stateKey") return t;
|
|
1119
1114
|
if (l === "_path") return n;
|
|
1120
1115
|
if (l === "_isServerSynced") return I._isServerSynced;
|
|
1121
1116
|
if (l === "update")
|
|
1122
|
-
return (
|
|
1117
|
+
return (u, e) => {
|
|
1123
1118
|
if (e?.debounce)
|
|
1124
|
-
|
|
1125
|
-
|
|
1119
|
+
Pt(() => {
|
|
1120
|
+
rt(c, u, n, "");
|
|
1126
1121
|
const o = r.getState().getNestedState(t, n);
|
|
1127
1122
|
e?.afterUpdate && e.afterUpdate(o);
|
|
1128
1123
|
}, e.debounce);
|
|
1129
1124
|
else {
|
|
1130
|
-
|
|
1125
|
+
rt(c, u, n, "");
|
|
1131
1126
|
const o = r.getState().getNestedState(t, n);
|
|
1132
1127
|
e?.afterUpdate && e.afterUpdate(o);
|
|
1133
1128
|
}
|
|
1134
1129
|
p(n);
|
|
1135
1130
|
};
|
|
1136
1131
|
if (l === "formElement")
|
|
1137
|
-
return (
|
|
1138
|
-
|
|
1132
|
+
return (u, e) => /* @__PURE__ */ ft(
|
|
1133
|
+
_t,
|
|
1139
1134
|
{
|
|
1140
|
-
setState:
|
|
1135
|
+
setState: c,
|
|
1141
1136
|
stateKey: t,
|
|
1142
1137
|
path: n,
|
|
1143
|
-
child:
|
|
1138
|
+
child: u,
|
|
1144
1139
|
formOpts: e
|
|
1145
1140
|
}
|
|
1146
1141
|
);
|
|
1147
|
-
const
|
|
1148
|
-
return a(nt,
|
|
1142
|
+
const _ = [...n, l], nt = r.getState().getNestedState(t, _);
|
|
1143
|
+
return a(nt, _, f);
|
|
1149
1144
|
}
|
|
1150
|
-
},
|
|
1145
|
+
}, W = new Proxy(U, j);
|
|
1151
1146
|
return y.set(G, {
|
|
1152
|
-
proxy:
|
|
1153
|
-
stateVersion:
|
|
1154
|
-
}),
|
|
1147
|
+
proxy: W,
|
|
1148
|
+
stateVersion: N
|
|
1149
|
+
}), W;
|
|
1155
1150
|
}
|
|
1156
1151
|
return a(
|
|
1157
1152
|
r.getState().getNestedState(t, [])
|
|
1158
1153
|
);
|
|
1159
1154
|
}
|
|
1160
|
-
function
|
|
1161
|
-
return
|
|
1155
|
+
function At(t) {
|
|
1156
|
+
return ot(Bt, { proxy: t });
|
|
1162
1157
|
}
|
|
1163
|
-
function
|
|
1158
|
+
function Ht({
|
|
1164
1159
|
proxy: t,
|
|
1165
|
-
rebuildStateShape:
|
|
1160
|
+
rebuildStateShape: c
|
|
1166
1161
|
}) {
|
|
1167
|
-
const
|
|
1168
|
-
return Array.isArray(
|
|
1169
|
-
|
|
1162
|
+
const m = r().getNestedState(t._stateKey, t._path);
|
|
1163
|
+
return Array.isArray(m) ? c(
|
|
1164
|
+
m,
|
|
1170
1165
|
t._path
|
|
1171
1166
|
).stateMapNoRender(
|
|
1172
|
-
(y,
|
|
1167
|
+
(y, N, p, I, a) => t._mapFn(y, N, p, I, a)
|
|
1173
1168
|
) : null;
|
|
1174
1169
|
}
|
|
1175
|
-
function
|
|
1170
|
+
function Bt({
|
|
1176
1171
|
proxy: t
|
|
1177
1172
|
}) {
|
|
1178
|
-
const
|
|
1173
|
+
const c = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1179
1174
|
return et(() => {
|
|
1180
|
-
const g =
|
|
1175
|
+
const g = c.current;
|
|
1181
1176
|
if (!g || !g.parentElement) return;
|
|
1182
1177
|
const y = g.parentElement, p = Array.from(y.childNodes).indexOf(g);
|
|
1183
1178
|
let I = y.getAttribute("data-parent-id");
|
|
@@ -1188,7 +1183,7 @@ function Kt({
|
|
|
1188
1183
|
position: p,
|
|
1189
1184
|
effect: t._effect
|
|
1190
1185
|
};
|
|
1191
|
-
r.getState().addSignalElement(
|
|
1186
|
+
r.getState().addSignalElement(m, v);
|
|
1192
1187
|
const n = r.getState().getNestedState(t._stateKey, t._path);
|
|
1193
1188
|
let f;
|
|
1194
1189
|
if (t._effect)
|
|
@@ -1197,67 +1192,67 @@ function Kt({
|
|
|
1197
1192
|
"state",
|
|
1198
1193
|
`return (${t._effect})(state)`
|
|
1199
1194
|
)(n);
|
|
1200
|
-
} catch (
|
|
1201
|
-
console.error("Error evaluating effect function during mount:",
|
|
1195
|
+
} catch (U) {
|
|
1196
|
+
console.error("Error evaluating effect function during mount:", U), f = n;
|
|
1202
1197
|
}
|
|
1203
1198
|
else
|
|
1204
1199
|
f = n;
|
|
1205
1200
|
f !== null && typeof f == "object" && (f = JSON.stringify(f));
|
|
1206
1201
|
const G = document.createTextNode(String(f));
|
|
1207
1202
|
g.replaceWith(G);
|
|
1208
|
-
}, [t._stateKey, t._path.join("."), t._effect]),
|
|
1209
|
-
ref:
|
|
1203
|
+
}, [t._stateKey, t._path.join("."), t._effect]), ot("span", {
|
|
1204
|
+
ref: c,
|
|
1210
1205
|
style: { display: "none" },
|
|
1211
|
-
"data-signal-id":
|
|
1206
|
+
"data-signal-id": m
|
|
1212
1207
|
});
|
|
1213
1208
|
}
|
|
1214
|
-
function
|
|
1215
|
-
const
|
|
1216
|
-
(
|
|
1209
|
+
function ie(t) {
|
|
1210
|
+
const c = Nt(
|
|
1211
|
+
(m) => {
|
|
1217
1212
|
const g = r.getState().stateComponents.get(t._stateKey) || {
|
|
1218
1213
|
components: /* @__PURE__ */ new Map()
|
|
1219
1214
|
};
|
|
1220
1215
|
return g.components.set(t._stateKey, {
|
|
1221
|
-
forceUpdate:
|
|
1216
|
+
forceUpdate: m,
|
|
1222
1217
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1223
1218
|
}), () => g.components.delete(t._stateKey);
|
|
1224
1219
|
},
|
|
1225
1220
|
() => r.getState().getNestedState(t._stateKey, t._path)
|
|
1226
1221
|
);
|
|
1227
|
-
return
|
|
1222
|
+
return ot("text", {}, String(c));
|
|
1228
1223
|
}
|
|
1229
|
-
function
|
|
1224
|
+
function zt({
|
|
1230
1225
|
stateKey: t,
|
|
1231
|
-
itemComponentId:
|
|
1232
|
-
itemPath:
|
|
1226
|
+
itemComponentId: c,
|
|
1227
|
+
itemPath: m,
|
|
1233
1228
|
children: g
|
|
1234
1229
|
}) {
|
|
1235
|
-
const [, y] = Q({}), [
|
|
1230
|
+
const [, y] = Q({}), [N, p] = Rt(), I = Z(null);
|
|
1236
1231
|
return et(() => {
|
|
1237
|
-
p.height > 0 && p.height !== I.current && (I.current = p.height, r.getState().setShadowMetadata(t,
|
|
1232
|
+
p.height > 0 && p.height !== I.current && (I.current = p.height, r.getState().setShadowMetadata(t, m, {
|
|
1238
1233
|
virtualizer: {
|
|
1239
1234
|
itemHeight: p.height
|
|
1240
1235
|
}
|
|
1241
1236
|
}));
|
|
1242
|
-
}, [p.height, t,
|
|
1243
|
-
const a = `${t}////${
|
|
1237
|
+
}, [p.height, t, m]), it(() => {
|
|
1238
|
+
const a = `${t}////${c}`, v = r.getState().stateComponents.get(t) || {
|
|
1244
1239
|
components: /* @__PURE__ */ new Map()
|
|
1245
1240
|
};
|
|
1246
1241
|
return v.components.set(a, {
|
|
1247
1242
|
forceUpdate: () => y({}),
|
|
1248
|
-
paths: /* @__PURE__ */ new Set([
|
|
1243
|
+
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1249
1244
|
}), r.getState().stateComponents.set(t, v), () => {
|
|
1250
1245
|
const n = r.getState().stateComponents.get(t);
|
|
1251
1246
|
n && n.components.delete(a);
|
|
1252
1247
|
};
|
|
1253
|
-
}, [t,
|
|
1248
|
+
}, [t, c, m.join(".")]), /* @__PURE__ */ ft("div", { ref: N, children: g });
|
|
1254
1249
|
}
|
|
1255
1250
|
export {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1251
|
+
At as $cogsSignal,
|
|
1252
|
+
ie as $cogsSignalStore,
|
|
1253
|
+
oe as addStateOptions,
|
|
1254
|
+
ae as createCogsState,
|
|
1255
|
+
se as notifyComponent,
|
|
1256
|
+
Wt as useCogsStateFn
|
|
1262
1257
|
};
|
|
1263
1258
|
//# sourceMappingURL=CogsState.jsx.map
|