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