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