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