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