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