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