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