cogsbox-state 0.5.102 → 0.5.103
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 +412 -436
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as et, useRef as Z, useEffect as nt, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as
|
|
2
|
+
import { jsx as ct } from "react/jsx-runtime";
|
|
3
|
+
import { useState as et, useRef as Z, useEffect as nt, useLayoutEffect as It, useMemo as _t, createElement as Q, useSyncExternalStore as Et, startTransition as H } from "react";
|
|
4
|
+
import { transformStateFunc as wt, isFunction as L, getNestedValue as U, isDeepEqual as M, debounce as $t } from "./utility.js";
|
|
5
5
|
import { pushFunc as K, updateFn as B, cutFunc as J, ValidationWrapper as Nt, FormControlComponent as Vt } from "./Functions.jsx";
|
|
6
6
|
import "zod";
|
|
7
|
-
import { getGlobalStore as r, formRefStore as
|
|
7
|
+
import { getGlobalStore as r, formRefStore as lt } from "./store.js";
|
|
8
8
|
import { useCogsConfig as At } from "./CogsStateClient.jsx";
|
|
9
9
|
import rt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
...
|
|
14
|
-
...
|
|
10
|
+
function dt(t, i) {
|
|
11
|
+
const m = r.getState().getInitialOptions, y = r.getState().setInitialStateOptions, u = m(t) || {};
|
|
12
|
+
y(t, {
|
|
13
|
+
...u,
|
|
14
|
+
...i
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function ut({
|
|
18
18
|
stateKey: t,
|
|
19
|
-
options:
|
|
20
|
-
initialOptionsPart:
|
|
19
|
+
options: i,
|
|
20
|
+
initialOptionsPart: m
|
|
21
21
|
}) {
|
|
22
|
-
const
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
-
for (const l in
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, E = { ...u, ...y };
|
|
23
|
+
let v = !1;
|
|
24
|
+
if (i)
|
|
25
|
+
for (const l in i)
|
|
26
|
+
E.hasOwnProperty(l) ? l == "localStorage" && i[l] && E[l].key !== i[l]?.key && (v = !0, E[l] = i[l]) : (v = !0, E[l] = i[l]);
|
|
27
|
+
v && w(t, E);
|
|
28
28
|
}
|
|
29
|
-
function qt(t, { formElements:
|
|
30
|
-
return { initialState: t, formElements:
|
|
29
|
+
function qt(t, { formElements: i, validation: m }) {
|
|
30
|
+
return { initialState: t, formElements: i, validation: m };
|
|
31
31
|
}
|
|
32
|
-
const zt = (t,
|
|
33
|
-
let
|
|
34
|
-
const [
|
|
35
|
-
(Object.keys(
|
|
36
|
-
|
|
37
|
-
...
|
|
32
|
+
const zt = (t, i) => {
|
|
33
|
+
let m = t;
|
|
34
|
+
const [y, u] = wt(m);
|
|
35
|
+
(Object.keys(u).length > 0 || i && Object.keys(i).length > 0) && Object.keys(u).forEach((v) => {
|
|
36
|
+
u[v] = u[v] || {}, u[v].formElements = {
|
|
37
|
+
...i?.formElements,
|
|
38
38
|
// Global defaults first
|
|
39
|
-
...
|
|
40
|
-
...
|
|
39
|
+
...i?.validation,
|
|
40
|
+
...u[v].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
|
-
}, q(
|
|
43
|
-
}), r.getState().setInitialStates(
|
|
44
|
-
const
|
|
45
|
-
const [
|
|
46
|
-
|
|
47
|
-
stateKey:
|
|
42
|
+
}, q(v) || r.getState().setInitialStateOptions(v, u[v]);
|
|
43
|
+
}), r.getState().setInitialStates(y);
|
|
44
|
+
const w = (v, l) => {
|
|
45
|
+
const [f] = et(l?.componentId ?? rt());
|
|
46
|
+
ut({
|
|
47
|
+
stateKey: v,
|
|
48
48
|
options: l,
|
|
49
|
-
initialOptionsPart:
|
|
49
|
+
initialOptionsPart: u
|
|
50
50
|
});
|
|
51
|
-
const e = r.getState().cogsStateStore[
|
|
51
|
+
const e = r.getState().cogsStateStore[v] || y[v], S = l?.modifyState ? l.modifyState(e) : e, [x, A] = Ot(
|
|
52
52
|
S,
|
|
53
53
|
{
|
|
54
|
-
stateKey:
|
|
54
|
+
stateKey: v,
|
|
55
55
|
syncUpdate: l?.syncUpdate,
|
|
56
|
-
componentId:
|
|
56
|
+
componentId: f,
|
|
57
57
|
localStorage: l?.localStorage,
|
|
58
58
|
middleware: l?.middleware,
|
|
59
59
|
enabledSync: l?.enabledSync,
|
|
@@ -63,110 +63,99 @@ const zt = (t, s) => {
|
|
|
63
63
|
dependencies: l?.dependencies
|
|
64
64
|
}
|
|
65
65
|
);
|
|
66
|
-
return
|
|
66
|
+
return A;
|
|
67
67
|
};
|
|
68
|
-
function
|
|
69
|
-
|
|
68
|
+
function E(v, l) {
|
|
69
|
+
ut({ stateKey: v, options: l, initialOptionsPart: u });
|
|
70
70
|
}
|
|
71
|
-
return { useCogsState:
|
|
71
|
+
return { useCogsState: w, setCogsOptions: E };
|
|
72
72
|
}, {
|
|
73
73
|
setUpdaterState: Y,
|
|
74
|
-
setState:
|
|
74
|
+
setState: D,
|
|
75
75
|
getInitialOptions: q,
|
|
76
|
-
getKeyState:
|
|
77
|
-
getValidationErrors:
|
|
78
|
-
setStateLog:
|
|
79
|
-
updateInitialStateGlobal:
|
|
80
|
-
addValidationError:
|
|
81
|
-
removeValidationError:
|
|
82
|
-
setServerSyncActions:
|
|
83
|
-
} = r.getState(),
|
|
76
|
+
getKeyState: gt,
|
|
77
|
+
getValidationErrors: ht,
|
|
78
|
+
setStateLog: Ct,
|
|
79
|
+
updateInitialStateGlobal: ot,
|
|
80
|
+
addValidationError: kt,
|
|
81
|
+
removeValidationError: P,
|
|
82
|
+
setServerSyncActions: pt
|
|
83
|
+
} = r.getState(), ft = (t) => {
|
|
84
84
|
if (!t) return null;
|
|
85
85
|
try {
|
|
86
|
-
const
|
|
87
|
-
return
|
|
88
|
-
} catch (
|
|
89
|
-
return console.error("Error loading from localStorage:",
|
|
86
|
+
const i = window.localStorage.getItem(t);
|
|
87
|
+
return i ? JSON.parse(i) : null;
|
|
88
|
+
} catch (i) {
|
|
89
|
+
return console.error("Error loading from localStorage:", i), null;
|
|
90
90
|
}
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
f = {
|
|
108
|
-
state: t,
|
|
109
|
-
// !!! --- REMOVED '?? null' --- !!!
|
|
110
|
-
baseServerState: l?.baseServerState,
|
|
111
|
-
// Preserve existing base (will be T | null | undefined)
|
|
112
|
-
lastUpdated: Date.now()
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
window.localStorage.setItem(_, JSON.stringify(f));
|
|
116
|
-
} catch (f) {
|
|
117
|
-
console.error("Error saving to localStorage:", _, f);
|
|
91
|
+
}, xt = (t, i, m, y) => {
|
|
92
|
+
m?.log && console.log(
|
|
93
|
+
"saving to localstorage",
|
|
94
|
+
i,
|
|
95
|
+
m.localStorage?.key,
|
|
96
|
+
y
|
|
97
|
+
);
|
|
98
|
+
const u = L(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
99
|
+
if (u && y) {
|
|
100
|
+
const w = {
|
|
101
|
+
state: t,
|
|
102
|
+
lastUpdated: Date.now(),
|
|
103
|
+
lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
|
|
104
|
+
baseServerState: r.getState().serverState[i]
|
|
105
|
+
}, E = `${y}-${i}-${u}`;
|
|
106
|
+
window.localStorage.setItem(E, JSON.stringify(w));
|
|
118
107
|
}
|
|
119
|
-
},
|
|
120
|
-
const
|
|
121
|
-
initialState:
|
|
108
|
+
}, Tt = (t, i, m, y, u, w) => {
|
|
109
|
+
const E = {
|
|
110
|
+
initialState: i,
|
|
122
111
|
updaterState: X(
|
|
123
112
|
t,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
113
|
+
y,
|
|
114
|
+
u,
|
|
115
|
+
w
|
|
127
116
|
),
|
|
128
|
-
state:
|
|
117
|
+
state: m
|
|
129
118
|
};
|
|
130
119
|
H(() => {
|
|
131
|
-
|
|
120
|
+
ot(t, E.initialState), Y(t, E.updaterState), D(t, E.state);
|
|
132
121
|
});
|
|
133
122
|
}, St = (t) => {
|
|
134
|
-
const
|
|
135
|
-
if (!
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
123
|
+
const i = r.getState().stateComponents.get(t);
|
|
124
|
+
if (!i) return;
|
|
125
|
+
const m = /* @__PURE__ */ new Set();
|
|
126
|
+
i.components.forEach((y) => {
|
|
127
|
+
m.add(() => y.forceUpdate());
|
|
139
128
|
}), queueMicrotask(() => {
|
|
140
129
|
H(() => {
|
|
141
|
-
|
|
130
|
+
m.forEach((y) => y());
|
|
142
131
|
});
|
|
143
132
|
});
|
|
144
|
-
}, Bt = (t,
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
const
|
|
148
|
-
|
|
133
|
+
}, Bt = (t, i) => {
|
|
134
|
+
const m = r.getState().stateComponents.get(t);
|
|
135
|
+
if (m) {
|
|
136
|
+
const y = `${t}////${i}`, u = m.components.get(y);
|
|
137
|
+
u && u.forceUpdate();
|
|
149
138
|
}
|
|
150
139
|
};
|
|
151
|
-
function
|
|
152
|
-
stateKey:
|
|
153
|
-
serverSync:
|
|
154
|
-
localStorage:
|
|
155
|
-
formElements:
|
|
156
|
-
middleware:
|
|
157
|
-
reactiveDeps:
|
|
158
|
-
reactiveType:
|
|
140
|
+
function Ot(t, {
|
|
141
|
+
stateKey: i,
|
|
142
|
+
serverSync: m,
|
|
143
|
+
localStorage: y,
|
|
144
|
+
formElements: u,
|
|
145
|
+
middleware: w,
|
|
146
|
+
reactiveDeps: E,
|
|
147
|
+
reactiveType: v,
|
|
159
148
|
componentId: l,
|
|
160
|
-
initialState:
|
|
149
|
+
initialState: f,
|
|
161
150
|
syncUpdate: e,
|
|
162
151
|
dependencies: S
|
|
163
152
|
} = {}) {
|
|
164
|
-
const [
|
|
165
|
-
let
|
|
166
|
-
const [
|
|
167
|
-
|
|
168
|
-
if (e && e.stateKey ===
|
|
169
|
-
|
|
153
|
+
const [x, A] = et({}), { sessionId: T } = At();
|
|
154
|
+
let R = !i;
|
|
155
|
+
const [g] = et(i ?? rt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(l ?? rt()), C = Z(null);
|
|
156
|
+
C.current = q(g), nt(() => {
|
|
157
|
+
if (e && e.stateKey === g && e.path?.[0]) {
|
|
158
|
+
D(g, (o) => ({
|
|
170
159
|
...o,
|
|
171
160
|
[e.path[0]]: e.newValue
|
|
172
161
|
}));
|
|
@@ -177,218 +166,205 @@ function kt(t, {
|
|
|
177
166
|
});
|
|
178
167
|
}
|
|
179
168
|
}, [e]), nt(() => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
169
|
+
dt(g, {
|
|
170
|
+
initialState: f
|
|
171
|
+
});
|
|
172
|
+
const c = C.current;
|
|
173
|
+
let o = null;
|
|
174
|
+
const d = L(c?.localStorage?.key) ? c?.localStorage?.key(f) : c?.localStorage?.key;
|
|
175
|
+
console.log("newoptions", c), console.log("localkey", d), console.log("initialState", f), d && T && (o = ft(
|
|
176
|
+
T + "-" + g + "-" + d
|
|
186
177
|
));
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
N,
|
|
200
|
-
n,
|
|
201
|
-
j.current,
|
|
202
|
-
b
|
|
203
|
-
), ft(
|
|
204
|
-
N,
|
|
205
|
-
u,
|
|
206
|
-
c,
|
|
207
|
-
b,
|
|
208
|
-
w
|
|
209
|
-
), T && c?.localStorage?.onChange && c.localStorage.onChange(N), St(u), C({}));
|
|
210
|
-
}
|
|
211
|
-
}, [m, ...S || []]), vt(() => {
|
|
212
|
-
U && ht(
|
|
213
|
-
u,
|
|
178
|
+
let I = null, k = !1;
|
|
179
|
+
o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (I = o.state, k = !0), f && (I = f), I && (console.log("newState thius is newstate", I), Tt(
|
|
180
|
+
g,
|
|
181
|
+
f,
|
|
182
|
+
I,
|
|
183
|
+
n,
|
|
184
|
+
b.current,
|
|
185
|
+
T
|
|
186
|
+
), k && c?.localStorage?.onChange && c?.localStorage?.onChange(I), St(g), A({}));
|
|
187
|
+
}, [f, ...S || []]), It(() => {
|
|
188
|
+
R && dt(
|
|
189
|
+
g,
|
|
214
190
|
{
|
|
215
|
-
serverSync:
|
|
216
|
-
formElements:
|
|
217
|
-
initialState:
|
|
218
|
-
localStorage:
|
|
219
|
-
middleware:
|
|
191
|
+
serverSync: m,
|
|
192
|
+
formElements: u,
|
|
193
|
+
initialState: f,
|
|
194
|
+
localStorage: y,
|
|
195
|
+
middleware: w
|
|
220
196
|
}
|
|
221
197
|
);
|
|
222
|
-
const c = `${
|
|
198
|
+
const c = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
|
|
223
199
|
components: /* @__PURE__ */ new Map()
|
|
224
200
|
};
|
|
225
201
|
return o.components.set(c, {
|
|
226
|
-
forceUpdate: () =>
|
|
202
|
+
forceUpdate: () => A({}),
|
|
227
203
|
paths: /* @__PURE__ */ new Set(),
|
|
228
204
|
deps: [],
|
|
229
|
-
depsFunction:
|
|
230
|
-
reactiveType:
|
|
231
|
-
}), r.getState().stateComponents.set(
|
|
232
|
-
const d = `${
|
|
233
|
-
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(
|
|
205
|
+
depsFunction: E || void 0,
|
|
206
|
+
reactiveType: v ?? ["component", "deps"]
|
|
207
|
+
}), r.getState().stateComponents.set(g, o), A({}), () => {
|
|
208
|
+
const d = `${g}////${b.current}`;
|
|
209
|
+
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
|
|
234
210
|
};
|
|
235
211
|
}, []);
|
|
236
|
-
const n = (c, o, d,
|
|
212
|
+
const n = (c, o, d, I) => {
|
|
237
213
|
if (Array.isArray(o)) {
|
|
238
|
-
const
|
|
239
|
-
|
|
214
|
+
const k = `${g}-${o.join(".")}`;
|
|
215
|
+
G.current.add(k);
|
|
240
216
|
}
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
let
|
|
245
|
-
if ((!
|
|
246
|
-
const
|
|
247
|
-
if (Array.isArray(
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
217
|
+
D(g, (k) => {
|
|
218
|
+
const N = L(c) ? c(k) : c, j = `${g}-${o.join(".")}`;
|
|
219
|
+
if (j) {
|
|
220
|
+
let F = !1, _ = r.getState().signalDomElements.get(j);
|
|
221
|
+
if ((!_ || _.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
|
|
222
|
+
const V = o.slice(0, -1), h = U(N, V);
|
|
223
|
+
if (Array.isArray(h)) {
|
|
224
|
+
F = !0;
|
|
225
|
+
const $ = `${g}-${V.join(".")}`;
|
|
226
|
+
_ = r.getState().signalDomElements.get($);
|
|
251
227
|
}
|
|
252
228
|
}
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
`[data-parent-id="${
|
|
229
|
+
if (_) {
|
|
230
|
+
const V = F ? U(N, o.slice(0, -1)) : U(N, o);
|
|
231
|
+
_.forEach(({ parentId: h, position: $, effect: W }) => {
|
|
232
|
+
const O = document.querySelector(
|
|
233
|
+
`[data-parent-id="${h}"]`
|
|
258
234
|
);
|
|
259
|
-
if (
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
262
|
-
const
|
|
263
|
-
|
|
235
|
+
if (O) {
|
|
236
|
+
const st = Array.from(O.childNodes);
|
|
237
|
+
if (st[$]) {
|
|
238
|
+
const vt = W ? new Function("state", `return (${W})(state)`)(V) : V;
|
|
239
|
+
st[$].textContent = String(vt);
|
|
264
240
|
}
|
|
265
241
|
}
|
|
266
242
|
});
|
|
267
243
|
}
|
|
268
244
|
}
|
|
269
|
-
d.updateType === "update" && (
|
|
270
|
-
(
|
|
245
|
+
d.updateType === "update" && (I || C.current?.validationKey) && o && P(
|
|
246
|
+
(I || C.current?.validationKey) + "." + o.join(".")
|
|
271
247
|
);
|
|
272
|
-
const
|
|
273
|
-
d.updateType === "cut" &&
|
|
274
|
-
|
|
275
|
-
), d.updateType === "insert" &&
|
|
276
|
-
|
|
277
|
-
).filter(([
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
280
|
-
let
|
|
281
|
-
|
|
248
|
+
const p = o.slice(0, o.length - 1);
|
|
249
|
+
d.updateType === "cut" && C.current?.validationKey && P(
|
|
250
|
+
C.current?.validationKey + "." + p.join(".")
|
|
251
|
+
), d.updateType === "insert" && C.current?.validationKey && ht(
|
|
252
|
+
C.current?.validationKey + "." + p.join(".")
|
|
253
|
+
).filter(([_, V]) => {
|
|
254
|
+
let h = _?.split(".").length;
|
|
255
|
+
if (_ == p.join(".") && h == p.length - 1) {
|
|
256
|
+
let $ = _ + "." + p;
|
|
257
|
+
P(_), kt($, V);
|
|
282
258
|
}
|
|
283
259
|
});
|
|
284
|
-
const z =
|
|
285
|
-
if (
|
|
286
|
-
for (const [
|
|
287
|
-
let
|
|
288
|
-
const
|
|
289
|
-
if (!
|
|
290
|
-
if (
|
|
291
|
-
|
|
260
|
+
const z = U(k, o), mt = U(N, o), yt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), at = r.getState().stateComponents.get(g);
|
|
261
|
+
if (at)
|
|
262
|
+
for (const [F, _] of at.components.entries()) {
|
|
263
|
+
let V = !1;
|
|
264
|
+
const h = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
|
|
265
|
+
if (!h.includes("none")) {
|
|
266
|
+
if (h.includes("all")) {
|
|
267
|
+
_.forceUpdate();
|
|
292
268
|
continue;
|
|
293
269
|
}
|
|
294
|
-
if (
|
|
295
|
-
const
|
|
296
|
-
typeof
|
|
270
|
+
if (h.includes("component") && _.paths && (_.paths.has(yt) || _.paths.has("")) && (V = !0), !V && h.includes("deps") && _.depsFunction) {
|
|
271
|
+
const $ = _.depsFunction(N);
|
|
272
|
+
typeof $ == "boolean" ? $ && (V = !0) : M(_.deps, $) || (_.deps = $, V = !0);
|
|
297
273
|
}
|
|
298
|
-
|
|
274
|
+
V && _.forceUpdate();
|
|
299
275
|
}
|
|
300
276
|
}
|
|
301
|
-
const
|
|
277
|
+
const it = {
|
|
302
278
|
timeStamp: Date.now(),
|
|
303
|
-
stateKey:
|
|
279
|
+
stateKey: g,
|
|
304
280
|
path: o,
|
|
305
281
|
updateType: d.updateType,
|
|
306
282
|
status: "new",
|
|
307
283
|
oldValue: z,
|
|
308
284
|
newValue: mt
|
|
309
285
|
};
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
const W = `${
|
|
313
|
-
return
|
|
286
|
+
if (Ct(g, (F) => {
|
|
287
|
+
const V = [...F ?? [], it].reduce((h, $) => {
|
|
288
|
+
const W = `${$.stateKey}:${JSON.stringify($.path)}`, O = h.get(W);
|
|
289
|
+
return O ? (O.timeStamp = Math.max(O.timeStamp, $.timeStamp), O.newValue = $.newValue, O.oldValue = O.oldValue ?? $.oldValue, O.updateType = $.updateType) : h.set(W, { ...$ }), h;
|
|
314
290
|
}, /* @__PURE__ */ new Map());
|
|
315
|
-
return Array.from(
|
|
316
|
-
}),
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
),
|
|
322
|
-
updateLog:
|
|
323
|
-
update:
|
|
324
|
-
}),
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
syncKey: typeof
|
|
328
|
-
rollBackState:
|
|
329
|
-
actionTimeStamp: Date.now() + (
|
|
291
|
+
return Array.from(V.values());
|
|
292
|
+
}), xt(
|
|
293
|
+
N,
|
|
294
|
+
g,
|
|
295
|
+
C.current,
|
|
296
|
+
T
|
|
297
|
+
), w && w({
|
|
298
|
+
updateLog: s,
|
|
299
|
+
update: it
|
|
300
|
+
}), C.current?.serverSync) {
|
|
301
|
+
const F = r.getState().serverState[g], _ = C.current?.serverSync;
|
|
302
|
+
pt(g, {
|
|
303
|
+
syncKey: typeof _.syncKey == "string" ? _.syncKey : _.syncKey({ state: N }),
|
|
304
|
+
rollBackState: F,
|
|
305
|
+
actionTimeStamp: Date.now() + (_.debounce ?? 3e3),
|
|
330
306
|
status: "waiting"
|
|
331
307
|
});
|
|
332
308
|
}
|
|
333
|
-
return
|
|
309
|
+
return N;
|
|
334
310
|
});
|
|
335
311
|
};
|
|
336
|
-
r.getState().updaterState[
|
|
337
|
-
|
|
312
|
+
r.getState().updaterState[g] || (Y(
|
|
313
|
+
g,
|
|
338
314
|
X(
|
|
339
|
-
|
|
315
|
+
g,
|
|
340
316
|
n,
|
|
341
|
-
|
|
342
|
-
|
|
317
|
+
b.current,
|
|
318
|
+
T
|
|
343
319
|
)
|
|
344
|
-
), r.getState().cogsStateStore[
|
|
320
|
+
), r.getState().cogsStateStore[g] || D(g, t), r.getState().initialStateGlobal[g] || ot(g, t));
|
|
345
321
|
const a = _t(() => X(
|
|
346
|
-
|
|
322
|
+
g,
|
|
347
323
|
n,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
), [
|
|
351
|
-
return [
|
|
324
|
+
b.current,
|
|
325
|
+
T
|
|
326
|
+
), [g]);
|
|
327
|
+
return [gt(g), a];
|
|
352
328
|
}
|
|
353
|
-
function X(t,
|
|
354
|
-
const
|
|
355
|
-
let
|
|
356
|
-
const
|
|
357
|
-
const e =
|
|
358
|
-
for (const [S] of
|
|
359
|
-
(S === e || S.startsWith(e + ".")) &&
|
|
360
|
-
|
|
361
|
-
},
|
|
362
|
-
removeValidation: (
|
|
363
|
-
|
|
329
|
+
function X(t, i, m, y) {
|
|
330
|
+
const u = /* @__PURE__ */ new Map();
|
|
331
|
+
let w = 0;
|
|
332
|
+
const E = (f) => {
|
|
333
|
+
const e = f.join(".");
|
|
334
|
+
for (const [S] of u)
|
|
335
|
+
(S === e || S.startsWith(e + ".")) && u.delete(S);
|
|
336
|
+
w++;
|
|
337
|
+
}, v = {
|
|
338
|
+
removeValidation: (f) => {
|
|
339
|
+
f?.validationKey && P(f.validationKey);
|
|
364
340
|
},
|
|
365
|
-
revertToInitialState: (
|
|
341
|
+
revertToInitialState: (f) => {
|
|
366
342
|
const e = r.getState().getInitialOptions(t)?.validation;
|
|
367
|
-
e?.key &&
|
|
343
|
+
e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
|
|
368
344
|
const S = r.getState().initialStateGlobal[t];
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
return
|
|
372
|
-
Y(t,
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
345
|
+
u.clear(), w++;
|
|
346
|
+
const x = l(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
|
|
347
|
+
return R && localStorage.removeItem(R), H(() => {
|
|
348
|
+
Y(t, x), D(t, S);
|
|
349
|
+
const g = r.getState().stateComponents.get(t);
|
|
350
|
+
g && g.components.forEach((s) => {
|
|
351
|
+
s.forceUpdate();
|
|
376
352
|
});
|
|
377
353
|
}), S;
|
|
378
354
|
},
|
|
379
|
-
updateInitialState: (
|
|
380
|
-
|
|
355
|
+
updateInitialState: (f) => {
|
|
356
|
+
u.clear(), w++;
|
|
381
357
|
const e = X(
|
|
382
358
|
t,
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
359
|
+
i,
|
|
360
|
+
m,
|
|
361
|
+
y
|
|
386
362
|
);
|
|
387
363
|
return H(() => {
|
|
388
|
-
|
|
364
|
+
ot(t, f), Y(t, e), D(t, f);
|
|
389
365
|
const S = r.getState().stateComponents.get(t);
|
|
390
|
-
S && S.components.forEach((
|
|
391
|
-
|
|
366
|
+
S && S.components.forEach((x) => {
|
|
367
|
+
x.forceUpdate();
|
|
392
368
|
});
|
|
393
369
|
}), {
|
|
394
370
|
fetchId: (S) => e.get()[S]
|
|
@@ -398,105 +374,105 @@ function X(t, s, y, I) {
|
|
|
398
374
|
_serverState: r.getState().serverState[t],
|
|
399
375
|
_isLoading: r.getState().isLoadingGlobal[t],
|
|
400
376
|
_isServerSynced: () => {
|
|
401
|
-
const
|
|
402
|
-
return !!(
|
|
377
|
+
const f = r.getState().serverState[t];
|
|
378
|
+
return !!(f && M(f, gt(t)));
|
|
403
379
|
}
|
|
404
380
|
};
|
|
405
|
-
function l(
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
const
|
|
381
|
+
function l(f, e = [], S) {
|
|
382
|
+
const x = e.map(String).join(".");
|
|
383
|
+
u.get(x);
|
|
384
|
+
const A = function() {
|
|
409
385
|
return r().getNestedState(t, e);
|
|
410
386
|
};
|
|
411
|
-
Object.keys(
|
|
412
|
-
|
|
387
|
+
Object.keys(v).forEach((g) => {
|
|
388
|
+
A[g] = v[g];
|
|
413
389
|
});
|
|
414
|
-
const
|
|
415
|
-
apply(
|
|
390
|
+
const T = {
|
|
391
|
+
apply(g, s, G) {
|
|
416
392
|
return console.log(
|
|
417
393
|
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${e.join(".")}`
|
|
418
394
|
), console.trace("Apply trap stack trace"), r().getNestedState(t, e);
|
|
419
395
|
},
|
|
420
|
-
get(
|
|
421
|
-
if (
|
|
422
|
-
const n = e.join("."), a = `${t}////${
|
|
396
|
+
get(g, s) {
|
|
397
|
+
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
398
|
+
const n = e.join("."), a = `${t}////${m}`, c = r.getState().stateComponents.get(t);
|
|
423
399
|
if (c) {
|
|
424
400
|
const o = c.components.get(a);
|
|
425
|
-
o && (e.length > 0 ||
|
|
401
|
+
o && (e.length > 0 || s === "get") && o.paths.add(n);
|
|
426
402
|
}
|
|
427
403
|
}
|
|
428
|
-
if (
|
|
429
|
-
const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], c =
|
|
430
|
-
return
|
|
404
|
+
if (s === "_status") {
|
|
405
|
+
const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], c = U(a, e);
|
|
406
|
+
return M(n, c) ? "fresh" : "stale";
|
|
431
407
|
}
|
|
432
|
-
if (
|
|
408
|
+
if (s === "getStatus")
|
|
433
409
|
return function() {
|
|
434
410
|
const n = r().getNestedState(
|
|
435
411
|
t,
|
|
436
412
|
e
|
|
437
|
-
), a = r.getState().initialStateGlobal[t], c =
|
|
438
|
-
return
|
|
413
|
+
), a = r.getState().initialStateGlobal[t], c = U(a, e);
|
|
414
|
+
return M(n, c) ? "fresh" : "stale";
|
|
439
415
|
};
|
|
440
|
-
if (
|
|
416
|
+
if (s === "removeStorage")
|
|
441
417
|
return () => {
|
|
442
|
-
const n = r.getState().initialStateGlobal[t], a = q(t), c =
|
|
418
|
+
const n = r.getState().initialStateGlobal[t], a = q(t), c = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${y}-${t}-${c}`;
|
|
443
419
|
console.log("removing storage", o), o && localStorage.removeItem(o);
|
|
444
420
|
};
|
|
445
|
-
if (
|
|
421
|
+
if (s === "showValidationErrors")
|
|
446
422
|
return () => {
|
|
447
423
|
const n = r.getState().getInitialOptions(t)?.validation;
|
|
448
424
|
if (!n?.key)
|
|
449
425
|
throw new Error("Validation key not found");
|
|
450
426
|
return r.getState().getValidationErrors(n.key + "." + e.join("."));
|
|
451
427
|
};
|
|
452
|
-
if (Array.isArray(
|
|
453
|
-
if (
|
|
428
|
+
if (Array.isArray(f)) {
|
|
429
|
+
if (s === "getSelected")
|
|
454
430
|
return () => {
|
|
455
431
|
const n = r.getState().getSelectedIndex(t, e.join("."));
|
|
456
432
|
if (n !== void 0)
|
|
457
433
|
return l(
|
|
458
|
-
|
|
434
|
+
f[n],
|
|
459
435
|
[...e, n.toString()],
|
|
460
436
|
S
|
|
461
437
|
);
|
|
462
438
|
};
|
|
463
|
-
if (
|
|
439
|
+
if (s === "getSelectedIndex")
|
|
464
440
|
return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
|
|
465
|
-
if (
|
|
441
|
+
if (s === "stateSort")
|
|
466
442
|
return (n) => {
|
|
467
|
-
const o = [...r.getState().getNestedState(t, e).map((d,
|
|
443
|
+
const o = [...r.getState().getNestedState(t, e).map((d, I) => ({
|
|
468
444
|
...d,
|
|
469
|
-
__origIndex:
|
|
445
|
+
__origIndex: I.toString()
|
|
470
446
|
}))].sort(n);
|
|
471
|
-
return
|
|
447
|
+
return u.clear(), w++, l(o, e, {
|
|
472
448
|
filtered: [...S?.filtered || [], e],
|
|
473
449
|
validIndices: o.map(
|
|
474
450
|
(d) => parseInt(d.__origIndex)
|
|
475
451
|
)
|
|
476
452
|
});
|
|
477
453
|
};
|
|
478
|
-
if (
|
|
454
|
+
if (s === "stateMap" || s === "stateMapNoRender")
|
|
479
455
|
return (n) => {
|
|
480
456
|
const a = S?.filtered?.some(
|
|
481
457
|
(o) => o.join(".") === e.join(".")
|
|
482
|
-
), c = a ?
|
|
483
|
-
return
|
|
484
|
-
const
|
|
458
|
+
), c = a ? f : r.getState().getNestedState(t, e);
|
|
459
|
+
return s !== "stateMapNoRender" && (u.clear(), w++), c.map((o, d) => {
|
|
460
|
+
const I = a && o.__origIndex ? o.__origIndex : d, k = l(
|
|
485
461
|
o,
|
|
486
|
-
[...e,
|
|
462
|
+
[...e, I.toString()],
|
|
487
463
|
S
|
|
488
464
|
);
|
|
489
465
|
return n(
|
|
490
466
|
o,
|
|
491
|
-
|
|
467
|
+
k,
|
|
492
468
|
d,
|
|
493
|
-
|
|
494
|
-
l(
|
|
469
|
+
f,
|
|
470
|
+
l(f, e, S)
|
|
495
471
|
);
|
|
496
472
|
});
|
|
497
473
|
};
|
|
498
|
-
if (
|
|
499
|
-
return (n) => Q(
|
|
474
|
+
if (s === "$stateMap")
|
|
475
|
+
return (n) => Q(jt, {
|
|
500
476
|
proxy: {
|
|
501
477
|
_stateKey: t,
|
|
502
478
|
_path: e,
|
|
@@ -505,14 +481,14 @@ function X(t, s, y, I) {
|
|
|
505
481
|
},
|
|
506
482
|
rebuildStateShape: l
|
|
507
483
|
});
|
|
508
|
-
if (
|
|
484
|
+
if (s === "stateFlattenOn")
|
|
509
485
|
return (n) => {
|
|
510
486
|
const c = S?.filtered?.some(
|
|
511
487
|
(d) => d.join(".") === e.join(".")
|
|
512
|
-
) ?
|
|
513
|
-
|
|
488
|
+
) ? f : r.getState().getNestedState(t, e);
|
|
489
|
+
u.clear(), w++;
|
|
514
490
|
const o = c.flatMap(
|
|
515
|
-
(d,
|
|
491
|
+
(d, I) => d[n] ?? []
|
|
516
492
|
);
|
|
517
493
|
return l(
|
|
518
494
|
o,
|
|
@@ -520,170 +496,170 @@ function X(t, s, y, I) {
|
|
|
520
496
|
S
|
|
521
497
|
);
|
|
522
498
|
};
|
|
523
|
-
if (
|
|
499
|
+
if (s === "findWith")
|
|
524
500
|
return (n, a) => {
|
|
525
|
-
const c =
|
|
526
|
-
(
|
|
501
|
+
const c = f.findIndex(
|
|
502
|
+
(I) => I[n] === a
|
|
527
503
|
);
|
|
528
504
|
if (c === -1) return;
|
|
529
|
-
const o =
|
|
530
|
-
return
|
|
505
|
+
const o = f[c], d = [...e, c.toString()];
|
|
506
|
+
return u.clear(), w++, u.clear(), w++, l(o, d);
|
|
531
507
|
};
|
|
532
|
-
if (
|
|
508
|
+
if (s === "index")
|
|
533
509
|
return (n) => {
|
|
534
|
-
const a =
|
|
510
|
+
const a = f[n];
|
|
535
511
|
return l(a, [...e, n.toString()]);
|
|
536
512
|
};
|
|
537
|
-
if (
|
|
538
|
-
return (n) => (
|
|
513
|
+
if (s === "insert")
|
|
514
|
+
return (n) => (E(e), K(i, n, e, t), l(
|
|
539
515
|
r.getState().cogsStateStore[t],
|
|
540
516
|
[]
|
|
541
517
|
));
|
|
542
|
-
if (
|
|
518
|
+
if (s === "uniqueInsert")
|
|
543
519
|
return (n, a, c) => {
|
|
544
|
-
const o = r.getState().getNestedState(t, e), d =
|
|
545
|
-
let
|
|
546
|
-
if (!o.some((
|
|
520
|
+
const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
|
|
521
|
+
let I = null;
|
|
522
|
+
if (!o.some((N) => {
|
|
547
523
|
if (a) {
|
|
548
|
-
const
|
|
549
|
-
(z) =>
|
|
524
|
+
const p = a.every(
|
|
525
|
+
(z) => M(N[z], d[z])
|
|
550
526
|
);
|
|
551
|
-
return
|
|
527
|
+
return p && (I = N), p;
|
|
552
528
|
}
|
|
553
|
-
const
|
|
554
|
-
return
|
|
529
|
+
const j = M(N, d);
|
|
530
|
+
return j && (I = N), j;
|
|
555
531
|
}))
|
|
556
|
-
|
|
557
|
-
else if (c &&
|
|
558
|
-
const
|
|
559
|
-
(
|
|
532
|
+
E(e), K(i, d, e, t);
|
|
533
|
+
else if (c && I) {
|
|
534
|
+
const N = c(I), j = o.map(
|
|
535
|
+
(p) => M(p, I) ? N : p
|
|
560
536
|
);
|
|
561
|
-
|
|
537
|
+
E(e), B(i, j, e);
|
|
562
538
|
}
|
|
563
539
|
};
|
|
564
|
-
if (
|
|
540
|
+
if (s === "cut")
|
|
565
541
|
return (n, a) => {
|
|
566
|
-
a?.waitForSync || (
|
|
542
|
+
a?.waitForSync || (E(e), J(i, e, t, n));
|
|
567
543
|
};
|
|
568
|
-
if (
|
|
544
|
+
if (s === "cutByValue")
|
|
569
545
|
return (n) => {
|
|
570
|
-
for (let a = 0; a <
|
|
571
|
-
|
|
546
|
+
for (let a = 0; a < f.length; a++)
|
|
547
|
+
f[a] === n && J(i, e, t, a);
|
|
572
548
|
};
|
|
573
|
-
if (
|
|
549
|
+
if (s === "toggleByValue")
|
|
574
550
|
return (n) => {
|
|
575
|
-
const a =
|
|
576
|
-
a > -1 ? J(
|
|
551
|
+
const a = f.findIndex((c) => c === n);
|
|
552
|
+
a > -1 ? J(i, e, t, a) : K(i, n, e, t);
|
|
577
553
|
};
|
|
578
|
-
if (
|
|
554
|
+
if (s === "stateFilter")
|
|
579
555
|
return (n) => {
|
|
580
|
-
const a =
|
|
556
|
+
const a = f.map((d, I) => ({
|
|
581
557
|
...d,
|
|
582
|
-
__origIndex:
|
|
558
|
+
__origIndex: I.toString()
|
|
583
559
|
})), c = [], o = [];
|
|
584
560
|
for (let d = 0; d < a.length; d++)
|
|
585
561
|
n(a[d], d) && (c.push(d), o.push(a[d]));
|
|
586
|
-
return
|
|
562
|
+
return u.clear(), w++, l(o, e, {
|
|
587
563
|
filtered: [...S?.filtered || [], e],
|
|
588
564
|
validIndices: c
|
|
589
565
|
// Always pass validIndices, even if empty
|
|
590
566
|
});
|
|
591
567
|
};
|
|
592
568
|
}
|
|
593
|
-
const
|
|
594
|
-
if (!isNaN(Number(
|
|
569
|
+
const G = e[e.length - 1];
|
|
570
|
+
if (!isNaN(Number(G))) {
|
|
595
571
|
const n = e.slice(0, -1), a = r.getState().getNestedState(t, n);
|
|
596
|
-
if (Array.isArray(a) &&
|
|
572
|
+
if (Array.isArray(a) && s === "cut")
|
|
597
573
|
return () => J(
|
|
598
|
-
|
|
574
|
+
i,
|
|
599
575
|
n,
|
|
600
576
|
t,
|
|
601
|
-
Number(
|
|
577
|
+
Number(G)
|
|
602
578
|
);
|
|
603
579
|
}
|
|
604
|
-
if (
|
|
580
|
+
if (s === "get")
|
|
605
581
|
return () => r.getState().getNestedState(t, e);
|
|
606
|
-
if (
|
|
582
|
+
if (s === "$derive")
|
|
607
583
|
return (n) => tt({
|
|
608
584
|
_stateKey: t,
|
|
609
585
|
_path: e,
|
|
610
586
|
_effect: n.toString()
|
|
611
587
|
});
|
|
612
|
-
if (
|
|
588
|
+
if (s === "$derive")
|
|
613
589
|
return (n) => tt({
|
|
614
590
|
_stateKey: t,
|
|
615
591
|
_path: e,
|
|
616
592
|
_effect: n.toString()
|
|
617
593
|
});
|
|
618
|
-
if (
|
|
594
|
+
if (s === "$get")
|
|
619
595
|
return () => tt({
|
|
620
596
|
_stateKey: t,
|
|
621
597
|
_path: e
|
|
622
598
|
});
|
|
623
|
-
if (
|
|
599
|
+
if (s === "lastSynced") {
|
|
624
600
|
const n = `${t}:${e.join(".")}`;
|
|
625
601
|
return r.getState().getSyncInfo(n);
|
|
626
602
|
}
|
|
627
|
-
if (
|
|
628
|
-
return (n) =>
|
|
629
|
-
if (
|
|
603
|
+
if (s == "getLocalStorage")
|
|
604
|
+
return (n) => ft(y + "-" + t + "-" + n);
|
|
605
|
+
if (s === "_selected") {
|
|
630
606
|
const n = e.slice(0, -1), a = n.join("."), c = r.getState().getNestedState(t, n);
|
|
631
607
|
return Array.isArray(c) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
|
|
632
608
|
}
|
|
633
|
-
if (
|
|
609
|
+
if (s === "setSelected")
|
|
634
610
|
return (n) => {
|
|
635
611
|
const a = e.slice(0, -1), c = Number(e[e.length - 1]), o = a.join(".");
|
|
636
612
|
n ? r.getState().setSelectedIndex(t, o, c) : r.getState().setSelectedIndex(t, o, void 0);
|
|
637
613
|
const d = r.getState().getNestedState(t, [...a]);
|
|
638
|
-
B(
|
|
614
|
+
B(i, d, a), E(a);
|
|
639
615
|
};
|
|
640
616
|
if (e.length == 0) {
|
|
641
|
-
if (
|
|
617
|
+
if (s === "validateZodSchema")
|
|
642
618
|
return () => {
|
|
643
619
|
const n = r.getState().getInitialOptions(t)?.validation, a = r.getState().addValidationError;
|
|
644
620
|
if (!n?.zodSchema)
|
|
645
621
|
throw new Error("Zod schema not found");
|
|
646
622
|
if (!n?.key)
|
|
647
623
|
throw new Error("Validation key not found");
|
|
648
|
-
|
|
624
|
+
P(n.key);
|
|
649
625
|
const c = r.getState().cogsStateStore[t];
|
|
650
626
|
try {
|
|
651
627
|
const o = r.getState().getValidationErrors(n.key);
|
|
652
|
-
o && o.length > 0 && o.forEach(([
|
|
653
|
-
|
|
628
|
+
o && o.length > 0 && o.forEach(([I]) => {
|
|
629
|
+
I && I.startsWith(n.key) && P(I);
|
|
654
630
|
});
|
|
655
631
|
const d = n.zodSchema.safeParse(c);
|
|
656
|
-
return d.success ? !0 : (d.error.errors.forEach((
|
|
657
|
-
const
|
|
658
|
-
a(
|
|
632
|
+
return d.success ? !0 : (d.error.errors.forEach((k) => {
|
|
633
|
+
const N = k.path, j = k.message, p = [n.key, ...N].join(".");
|
|
634
|
+
a(p, j);
|
|
659
635
|
}), St(t), !1);
|
|
660
636
|
} catch (o) {
|
|
661
637
|
return console.error("Zod schema validation failed", o), !1;
|
|
662
638
|
}
|
|
663
639
|
};
|
|
664
|
-
if (
|
|
665
|
-
if (
|
|
640
|
+
if (s === "_componentId") return m;
|
|
641
|
+
if (s === "getComponents")
|
|
666
642
|
return () => r().stateComponents.get(t);
|
|
667
|
-
if (
|
|
668
|
-
return () =>
|
|
669
|
-
if (
|
|
643
|
+
if (s === "getAllFormRefs")
|
|
644
|
+
return () => lt.getState().getFormRefsByStateKey(t);
|
|
645
|
+
if (s === "_initialState")
|
|
670
646
|
return r.getState().initialStateGlobal[t];
|
|
671
|
-
if (
|
|
647
|
+
if (s === "_serverState")
|
|
672
648
|
return r.getState().serverState[t];
|
|
673
|
-
if (
|
|
649
|
+
if (s === "_isLoading")
|
|
674
650
|
return r.getState().isLoadingGlobal[t];
|
|
675
|
-
if (
|
|
676
|
-
return
|
|
677
|
-
if (
|
|
678
|
-
if (
|
|
651
|
+
if (s === "revertToInitialState")
|
|
652
|
+
return v.revertToInitialState;
|
|
653
|
+
if (s === "updateInitialState") return v.updateInitialState;
|
|
654
|
+
if (s === "removeValidation") return v.removeValidation;
|
|
679
655
|
}
|
|
680
|
-
if (
|
|
681
|
-
return () =>
|
|
682
|
-
if (
|
|
656
|
+
if (s === "getFormRef")
|
|
657
|
+
return () => lt.getState().getFormRef(t + "." + e.join("."));
|
|
658
|
+
if (s === "validationWrapper")
|
|
683
659
|
return ({
|
|
684
660
|
children: n,
|
|
685
661
|
hideMessage: a
|
|
686
|
-
}) => /* @__PURE__ */
|
|
662
|
+
}) => /* @__PURE__ */ ct(
|
|
687
663
|
Nt,
|
|
688
664
|
{
|
|
689
665
|
formOpts: a ? { validation: { message: "" } } : void 0,
|
|
@@ -694,80 +670,80 @@ function X(t, s, y, I) {
|
|
|
694
670
|
children: n
|
|
695
671
|
}
|
|
696
672
|
);
|
|
697
|
-
if (
|
|
698
|
-
if (
|
|
699
|
-
if (
|
|
700
|
-
if (
|
|
673
|
+
if (s === "_stateKey") return t;
|
|
674
|
+
if (s === "_path") return e;
|
|
675
|
+
if (s === "_isServerSynced") return v._isServerSynced;
|
|
676
|
+
if (s === "update")
|
|
701
677
|
return (n, a) => {
|
|
702
678
|
if (a?.debounce)
|
|
703
|
-
|
|
704
|
-
B(
|
|
679
|
+
$t(() => {
|
|
680
|
+
B(i, n, e, "");
|
|
705
681
|
const c = r.getState().getNestedState(t, e);
|
|
706
682
|
a?.afterUpdate && a.afterUpdate(c);
|
|
707
683
|
}, a.debounce);
|
|
708
684
|
else {
|
|
709
|
-
B(
|
|
685
|
+
B(i, n, e, "");
|
|
710
686
|
const c = r.getState().getNestedState(t, e);
|
|
711
687
|
a?.afterUpdate && a.afterUpdate(c);
|
|
712
688
|
}
|
|
713
|
-
|
|
689
|
+
E(e);
|
|
714
690
|
};
|
|
715
|
-
if (
|
|
716
|
-
return (n, a) => /* @__PURE__ */
|
|
691
|
+
if (s === "formElement")
|
|
692
|
+
return (n, a) => /* @__PURE__ */ ct(
|
|
717
693
|
Vt,
|
|
718
694
|
{
|
|
719
|
-
setState:
|
|
695
|
+
setState: i,
|
|
720
696
|
stateKey: t,
|
|
721
697
|
path: e,
|
|
722
698
|
child: n,
|
|
723
699
|
formOpts: a
|
|
724
700
|
}
|
|
725
701
|
);
|
|
726
|
-
const
|
|
727
|
-
return l(
|
|
702
|
+
const b = [...e, s], C = r.getState().getNestedState(t, b);
|
|
703
|
+
return l(C, b, S);
|
|
728
704
|
}
|
|
729
|
-
},
|
|
730
|
-
return
|
|
731
|
-
proxy:
|
|
732
|
-
stateVersion:
|
|
733
|
-
}),
|
|
705
|
+
}, R = new Proxy(A, T);
|
|
706
|
+
return u.set(x, {
|
|
707
|
+
proxy: R,
|
|
708
|
+
stateVersion: w
|
|
709
|
+
}), R;
|
|
734
710
|
}
|
|
735
711
|
return l(
|
|
736
712
|
r.getState().getNestedState(t, [])
|
|
737
713
|
);
|
|
738
714
|
}
|
|
739
715
|
function tt(t) {
|
|
740
|
-
return Q(
|
|
716
|
+
return Q(bt, { proxy: t });
|
|
741
717
|
}
|
|
742
|
-
function
|
|
718
|
+
function jt({
|
|
743
719
|
proxy: t,
|
|
744
|
-
rebuildStateShape:
|
|
720
|
+
rebuildStateShape: i
|
|
745
721
|
}) {
|
|
746
|
-
const
|
|
747
|
-
return Array.isArray(
|
|
748
|
-
|
|
722
|
+
const m = r().getNestedState(t._stateKey, t._path);
|
|
723
|
+
return Array.isArray(m) ? i(
|
|
724
|
+
m,
|
|
749
725
|
t._path
|
|
750
726
|
).stateMapNoRender(
|
|
751
|
-
(
|
|
727
|
+
(u, w, E, v, l) => t._mapFn(u, w, E, v, l)
|
|
752
728
|
) : null;
|
|
753
729
|
}
|
|
754
|
-
function
|
|
730
|
+
function bt({
|
|
755
731
|
proxy: t
|
|
756
732
|
}) {
|
|
757
|
-
const
|
|
733
|
+
const i = Z(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
758
734
|
return nt(() => {
|
|
759
|
-
const
|
|
760
|
-
if (!
|
|
761
|
-
const
|
|
762
|
-
let
|
|
763
|
-
|
|
764
|
-
const
|
|
735
|
+
const y = i.current;
|
|
736
|
+
if (!y || !y.parentElement) return;
|
|
737
|
+
const u = y.parentElement, E = Array.from(u.childNodes).indexOf(y);
|
|
738
|
+
let v = u.getAttribute("data-parent-id");
|
|
739
|
+
v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
|
|
740
|
+
const f = {
|
|
765
741
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
766
|
-
parentId:
|
|
767
|
-
position:
|
|
742
|
+
parentId: v,
|
|
743
|
+
position: E,
|
|
768
744
|
effect: t._effect
|
|
769
745
|
};
|
|
770
|
-
r.getState().addSignalElement(
|
|
746
|
+
r.getState().addSignalElement(m, f);
|
|
771
747
|
const e = r.getState().getNestedState(t._stateKey, t._path);
|
|
772
748
|
let S;
|
|
773
749
|
if (t._effect)
|
|
@@ -776,34 +752,34 @@ function Ot({
|
|
|
776
752
|
"state",
|
|
777
753
|
`return (${t._effect})(state)`
|
|
778
754
|
)(e);
|
|
779
|
-
} catch (
|
|
780
|
-
console.error("Error evaluating effect function during mount:",
|
|
755
|
+
} catch (A) {
|
|
756
|
+
console.error("Error evaluating effect function during mount:", A), S = e;
|
|
781
757
|
}
|
|
782
758
|
else
|
|
783
759
|
S = e;
|
|
784
760
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
785
|
-
const
|
|
786
|
-
|
|
761
|
+
const x = document.createTextNode(String(S));
|
|
762
|
+
y.replaceWith(x);
|
|
787
763
|
}, [t._stateKey, t._path.join("."), t._effect]), Q("span", {
|
|
788
|
-
ref:
|
|
764
|
+
ref: i,
|
|
789
765
|
style: { display: "none" },
|
|
790
|
-
"data-signal-id":
|
|
766
|
+
"data-signal-id": m
|
|
791
767
|
});
|
|
792
768
|
}
|
|
793
769
|
function Jt(t) {
|
|
794
|
-
const
|
|
795
|
-
(
|
|
796
|
-
const
|
|
770
|
+
const i = Et(
|
|
771
|
+
(m) => {
|
|
772
|
+
const y = r.getState().stateComponents.get(t._stateKey) || {
|
|
797
773
|
components: /* @__PURE__ */ new Map()
|
|
798
774
|
};
|
|
799
|
-
return
|
|
800
|
-
forceUpdate:
|
|
775
|
+
return y.components.set(t._stateKey, {
|
|
776
|
+
forceUpdate: m,
|
|
801
777
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
802
|
-
}), () =>
|
|
778
|
+
}), () => y.components.delete(t._stateKey);
|
|
803
779
|
},
|
|
804
780
|
() => r.getState().getNestedState(t._stateKey, t._path)
|
|
805
781
|
);
|
|
806
|
-
return Q("text", {}, String(
|
|
782
|
+
return Q("text", {}, String(i));
|
|
807
783
|
}
|
|
808
784
|
export {
|
|
809
785
|
tt as $cogsSignal,
|
|
@@ -811,6 +787,6 @@ export {
|
|
|
811
787
|
qt as addStateOptions,
|
|
812
788
|
zt as createCogsState,
|
|
813
789
|
Bt as notifyComponent,
|
|
814
|
-
|
|
790
|
+
Ot as useCogsStateFn
|
|
815
791
|
};
|
|
816
792
|
//# sourceMappingURL=CogsState.jsx.map
|