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