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