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