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