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