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