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