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