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