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