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