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