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