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