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