cogsbox-state 0.5.114 → 0.5.116
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 +180 -182
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.js +60 -43
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -19,12 +19,12 @@ function dt({
|
|
|
19
19
|
options: i,
|
|
20
20
|
initialOptionsPart: m
|
|
21
21
|
}) {
|
|
22
|
-
const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions,
|
|
22
|
+
const y = q(t) || {}, u = m[t] || {}, w = r.getState().setInitialStateOptions, _ = { ...u, ...y };
|
|
23
23
|
let v = !1;
|
|
24
24
|
if (i)
|
|
25
|
-
for (const
|
|
26
|
-
|
|
27
|
-
v && w(t,
|
|
25
|
+
for (const c in i)
|
|
26
|
+
_.hasOwnProperty(c) ? (c == "localStorage" && i[c] && _[c].key !== i[c]?.key && (v = !0, _[c] = i[c]), c == "initialState" && i[c] && _[c] !== i[c] && (v = !0, _[c] = i[c])) : (v = !0, _[c] = i[c]);
|
|
27
|
+
v && w(t, _);
|
|
28
28
|
}
|
|
29
29
|
function qt(t, { formElements: i, validation: m }) {
|
|
30
30
|
return { initialState: t, formElements: i, validation: m };
|
|
@@ -40,47 +40,47 @@ const zt = (t, i) => {
|
|
|
40
40
|
...u[v].formElements || {}
|
|
41
41
|
// State-specific overrides
|
|
42
42
|
}, q(v) || r.getState().setInitialStateOptions(v, u[v]);
|
|
43
|
-
}), r.getState().setInitialStates(y);
|
|
44
|
-
const w = (v,
|
|
45
|
-
const [f] = tt(
|
|
43
|
+
}), r.getState().setInitialStates(y), r.getState().setCreatedState(y);
|
|
44
|
+
const w = (v, c) => {
|
|
45
|
+
const [f] = tt(c?.componentId ?? nt());
|
|
46
46
|
dt({
|
|
47
47
|
stateKey: v,
|
|
48
|
-
options:
|
|
48
|
+
options: c,
|
|
49
49
|
initialOptionsPart: u
|
|
50
50
|
});
|
|
51
|
-
const e = r.getState().cogsStateStore[v] || y[v], S =
|
|
51
|
+
const e = r.getState().cogsStateStore[v] || y[v], S = c?.modifyState ? c.modifyState(e) : e, [x, A] = jt(
|
|
52
52
|
S,
|
|
53
53
|
{
|
|
54
54
|
stateKey: v,
|
|
55
|
-
syncUpdate:
|
|
55
|
+
syncUpdate: c?.syncUpdate,
|
|
56
56
|
componentId: f,
|
|
57
|
-
localStorage:
|
|
58
|
-
middleware:
|
|
59
|
-
enabledSync:
|
|
60
|
-
reactiveType:
|
|
61
|
-
reactiveDeps:
|
|
62
|
-
initialState:
|
|
63
|
-
dependencies:
|
|
57
|
+
localStorage: c?.localStorage,
|
|
58
|
+
middleware: c?.middleware,
|
|
59
|
+
enabledSync: c?.enabledSync,
|
|
60
|
+
reactiveType: c?.reactiveType,
|
|
61
|
+
reactiveDeps: c?.reactiveDeps,
|
|
62
|
+
initialState: c?.initialState,
|
|
63
|
+
dependencies: c?.dependencies
|
|
64
64
|
}
|
|
65
65
|
);
|
|
66
66
|
return A;
|
|
67
67
|
};
|
|
68
|
-
function
|
|
69
|
-
dt({ stateKey: v, options:
|
|
68
|
+
function _(v, c) {
|
|
69
|
+
dt({ stateKey: v, options: c, initialOptionsPart: u });
|
|
70
70
|
}
|
|
71
|
-
return { useCogsState: w, setCogsOptions:
|
|
71
|
+
return { useCogsState: w, setCogsOptions: _ };
|
|
72
72
|
}, {
|
|
73
73
|
setUpdaterState: H,
|
|
74
74
|
setState: D,
|
|
75
75
|
getInitialOptions: q,
|
|
76
|
-
getKeyState:
|
|
77
|
-
getValidationErrors:
|
|
78
|
-
setStateLog:
|
|
76
|
+
getKeyState: gt,
|
|
77
|
+
getValidationErrors: Ct,
|
|
78
|
+
setStateLog: ht,
|
|
79
79
|
updateInitialStateGlobal: rt,
|
|
80
80
|
addValidationError: kt,
|
|
81
81
|
removeValidationError: P,
|
|
82
|
-
setServerSyncActions:
|
|
83
|
-
} = r.getState(),
|
|
82
|
+
setServerSyncActions: xt
|
|
83
|
+
} = r.getState(), ut = (t) => {
|
|
84
84
|
if (!t) return null;
|
|
85
85
|
try {
|
|
86
86
|
const i = window.localStorage.getItem(t);
|
|
@@ -88,7 +88,7 @@ const zt = (t, i) => {
|
|
|
88
88
|
} catch (i) {
|
|
89
89
|
return console.error("Error loading from localStorage:", i), null;
|
|
90
90
|
}
|
|
91
|
-
},
|
|
91
|
+
}, Tt = (t, i, m, y) => {
|
|
92
92
|
m?.log && console.log(
|
|
93
93
|
"saving to localstorage",
|
|
94
94
|
i,
|
|
@@ -102,11 +102,11 @@ const zt = (t, i) => {
|
|
|
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
|
+
}, _ = `${y}-${i}-${u}`;
|
|
106
|
+
window.localStorage.setItem(_, JSON.stringify(w));
|
|
107
107
|
}
|
|
108
|
-
},
|
|
109
|
-
const
|
|
108
|
+
}, Ot = (t, i, m, y, u, w) => {
|
|
109
|
+
const _ = {
|
|
110
110
|
initialState: i,
|
|
111
111
|
updaterState: Y(
|
|
112
112
|
t,
|
|
@@ -116,7 +116,7 @@ const zt = (t, i) => {
|
|
|
116
116
|
),
|
|
117
117
|
state: m
|
|
118
118
|
};
|
|
119
|
-
rt(t,
|
|
119
|
+
rt(t, _.initialState), H(t, _.updaterState), D(t, _.state);
|
|
120
120
|
}, ft = (t) => {
|
|
121
121
|
const i = r.getState().stateComponents.get(t);
|
|
122
122
|
if (!i) return;
|
|
@@ -133,55 +133,53 @@ const zt = (t, i) => {
|
|
|
133
133
|
u && u.forceUpdate();
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
|
-
function
|
|
136
|
+
function jt(t, {
|
|
137
137
|
stateKey: i,
|
|
138
138
|
serverSync: m,
|
|
139
139
|
localStorage: y,
|
|
140
140
|
formElements: u,
|
|
141
141
|
middleware: w,
|
|
142
|
-
reactiveDeps:
|
|
142
|
+
reactiveDeps: _,
|
|
143
143
|
reactiveType: v,
|
|
144
|
-
componentId:
|
|
144
|
+
componentId: c,
|
|
145
145
|
initialState: f,
|
|
146
146
|
syncUpdate: e,
|
|
147
147
|
dependencies: S
|
|
148
148
|
} = {}) {
|
|
149
149
|
const [x, A] = tt({}), { sessionId: T } = At();
|
|
150
150
|
let R = !i;
|
|
151
|
-
const [g] = tt(i ?? nt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(
|
|
152
|
-
|
|
151
|
+
const [g] = tt(i ?? nt()), s = r.getState().stateLog[g], G = Z(/* @__PURE__ */ new Set()), b = Z(c ?? nt()), h = Z(null);
|
|
152
|
+
h.current = q(g), et(() => {
|
|
153
153
|
if (e && e.stateKey === g && e.path?.[0]) {
|
|
154
154
|
D(g, (o) => ({
|
|
155
155
|
...o,
|
|
156
156
|
[e.path[0]]: e.newValue
|
|
157
157
|
}));
|
|
158
|
-
const
|
|
159
|
-
r.getState().setSyncInfo(
|
|
158
|
+
const l = `${e.stateKey}:${e.path.join(".")}`;
|
|
159
|
+
r.getState().setSyncInfo(l, {
|
|
160
160
|
timeStamp: e.timeStamp,
|
|
161
161
|
userId: e.userId
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
}, [e]), et(() => {
|
|
165
|
-
|
|
166
|
-
return;
|
|
167
|
-
lt(g, {
|
|
165
|
+
f && lt(g, {
|
|
168
166
|
initialState: f
|
|
169
167
|
});
|
|
170
|
-
const
|
|
168
|
+
const l = h.current;
|
|
171
169
|
let o = null;
|
|
172
|
-
const d = L(
|
|
173
|
-
console.log("newoptions",
|
|
170
|
+
const d = L(l?.localStorage?.key) ? l?.localStorage?.key(f) : l?.localStorage?.key;
|
|
171
|
+
console.log("newoptions", l), console.log("localkey", d), console.log("initialState", f), d && T && (o = ut(
|
|
174
172
|
T + "-" + g + "-" + d
|
|
175
173
|
));
|
|
176
|
-
let
|
|
177
|
-
o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (
|
|
174
|
+
let E = f ?? r.getState().iniitialCreatedState[g];
|
|
175
|
+
o && o.lastUpdated > (o.lastSyncedWithServer || 0) && (E = o.state, l?.localStorage?.onChange && l?.localStorage?.onChange(E)), console.log("newState thius is newstate", E), Ot(
|
|
178
176
|
g,
|
|
179
177
|
f,
|
|
180
|
-
|
|
178
|
+
E,
|
|
181
179
|
n,
|
|
182
180
|
b.current,
|
|
183
181
|
T
|
|
184
|
-
),
|
|
182
|
+
), ft(g), A({});
|
|
185
183
|
}, [f, ...S || []]), vt(() => {
|
|
186
184
|
R && lt(g, {
|
|
187
185
|
serverSync: m,
|
|
@@ -190,45 +188,45 @@ function Ot(t, {
|
|
|
190
188
|
localStorage: y,
|
|
191
189
|
middleware: w
|
|
192
190
|
});
|
|
193
|
-
const
|
|
191
|
+
const l = `${g}////${b.current}`, o = r.getState().stateComponents.get(g) || {
|
|
194
192
|
components: /* @__PURE__ */ new Map()
|
|
195
193
|
};
|
|
196
|
-
return o.components.set(
|
|
194
|
+
return o.components.set(l, {
|
|
197
195
|
forceUpdate: () => A({}),
|
|
198
196
|
paths: /* @__PURE__ */ new Set(),
|
|
199
197
|
deps: [],
|
|
200
|
-
depsFunction:
|
|
198
|
+
depsFunction: _ || void 0,
|
|
201
199
|
reactiveType: v ?? ["component", "deps"]
|
|
202
200
|
}), r.getState().stateComponents.set(g, o), A({}), () => {
|
|
203
201
|
const d = `${g}////${b.current}`;
|
|
204
202
|
o && (o.components.delete(d), o.components.size === 0 && r.getState().stateComponents.delete(g));
|
|
205
203
|
};
|
|
206
204
|
}, []);
|
|
207
|
-
const n = (
|
|
205
|
+
const n = (l, o, d, E) => {
|
|
208
206
|
if (Array.isArray(o)) {
|
|
209
|
-
const
|
|
210
|
-
G.current.add(
|
|
207
|
+
const O = `${g}-${o.join(".")}`;
|
|
208
|
+
G.current.add(O);
|
|
211
209
|
}
|
|
212
|
-
D(g, (
|
|
213
|
-
const N = L(
|
|
214
|
-
if (
|
|
215
|
-
let F = !1,
|
|
216
|
-
if ((!
|
|
217
|
-
const V = o.slice(0, -1),
|
|
218
|
-
if (Array.isArray(
|
|
210
|
+
D(g, (O) => {
|
|
211
|
+
const N = L(l) ? l(O) : l, p = `${g}-${o.join(".")}`;
|
|
212
|
+
if (p) {
|
|
213
|
+
let F = !1, I = r.getState().signalDomElements.get(p);
|
|
214
|
+
if ((!I || I.size === 0) && (d.updateType === "insert" || d.updateType === "cut")) {
|
|
215
|
+
const V = o.slice(0, -1), C = U(N, V);
|
|
216
|
+
if (Array.isArray(C)) {
|
|
219
217
|
F = !0;
|
|
220
218
|
const $ = `${g}-${V.join(".")}`;
|
|
221
|
-
|
|
219
|
+
I = r.getState().signalDomElements.get($);
|
|
222
220
|
}
|
|
223
221
|
}
|
|
224
|
-
if (
|
|
222
|
+
if (I) {
|
|
225
223
|
const V = F ? U(N, o.slice(0, -1)) : U(N, o);
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
`[data-parent-id="${
|
|
224
|
+
I.forEach(({ parentId: C, position: $, effect: W }) => {
|
|
225
|
+
const j = document.querySelector(
|
|
226
|
+
`[data-parent-id="${C}"]`
|
|
229
227
|
);
|
|
230
|
-
if (
|
|
231
|
-
const it = Array.from(
|
|
228
|
+
if (j) {
|
|
229
|
+
const it = Array.from(j.childNodes);
|
|
232
230
|
if (it[$]) {
|
|
233
231
|
const yt = W ? new Function("state", `return (${W})(state)`)(V) : V;
|
|
234
232
|
it[$].textContent = String(yt);
|
|
@@ -237,36 +235,36 @@ function Ot(t, {
|
|
|
237
235
|
});
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
|
-
d.updateType === "update" && (
|
|
241
|
-
(
|
|
238
|
+
d.updateType === "update" && (E || h.current?.validationKey) && o && P(
|
|
239
|
+
(E || h.current?.validationKey) + "." + o.join(".")
|
|
242
240
|
);
|
|
243
|
-
const
|
|
244
|
-
d.updateType === "cut" &&
|
|
245
|
-
|
|
246
|
-
), d.updateType === "insert" &&
|
|
247
|
-
|
|
248
|
-
).filter(([
|
|
249
|
-
let
|
|
250
|
-
if (
|
|
251
|
-
let $ =
|
|
252
|
-
P(
|
|
241
|
+
const k = o.slice(0, o.length - 1);
|
|
242
|
+
d.updateType === "cut" && h.current?.validationKey && P(
|
|
243
|
+
h.current?.validationKey + "." + k.join(".")
|
|
244
|
+
), d.updateType === "insert" && h.current?.validationKey && Ct(
|
|
245
|
+
h.current?.validationKey + "." + k.join(".")
|
|
246
|
+
).filter(([I, V]) => {
|
|
247
|
+
let C = I?.split(".").length;
|
|
248
|
+
if (I == k.join(".") && C == k.length - 1) {
|
|
249
|
+
let $ = I + "." + k;
|
|
250
|
+
P(I), kt($, V);
|
|
253
251
|
}
|
|
254
252
|
});
|
|
255
|
-
const z = U(
|
|
253
|
+
const z = U(O, o), St = U(N, o), mt = d.updateType === "update" ? o.join(".") : [...o].slice(0, -1).join("."), ot = r.getState().stateComponents.get(g);
|
|
256
254
|
if (ot)
|
|
257
|
-
for (const [F,
|
|
255
|
+
for (const [F, I] of ot.components.entries()) {
|
|
258
256
|
let V = !1;
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
261
|
-
if (
|
|
262
|
-
|
|
257
|
+
const C = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
|
|
258
|
+
if (!C.includes("none")) {
|
|
259
|
+
if (C.includes("all")) {
|
|
260
|
+
I.forceUpdate();
|
|
263
261
|
continue;
|
|
264
262
|
}
|
|
265
|
-
if (
|
|
266
|
-
const $ =
|
|
267
|
-
typeof $ == "boolean" ? $ && (V = !0) : M(
|
|
263
|
+
if (C.includes("component") && I.paths && (I.paths.has(mt) || I.paths.has("")) && (V = !0), !V && C.includes("deps") && I.depsFunction) {
|
|
264
|
+
const $ = I.depsFunction(N);
|
|
265
|
+
typeof $ == "boolean" ? $ && (V = !0) : M(I.deps, $) || (I.deps = $, V = !0);
|
|
268
266
|
}
|
|
269
|
-
V &&
|
|
267
|
+
V && I.forceUpdate();
|
|
270
268
|
}
|
|
271
269
|
}
|
|
272
270
|
const at = {
|
|
@@ -278,26 +276,26 @@ function Ot(t, {
|
|
|
278
276
|
oldValue: z,
|
|
279
277
|
newValue: St
|
|
280
278
|
};
|
|
281
|
-
if (
|
|
282
|
-
const V = [...F ?? [], at].reduce((
|
|
283
|
-
const W = `${$.stateKey}:${JSON.stringify($.path)}`,
|
|
284
|
-
return
|
|
279
|
+
if (ht(g, (F) => {
|
|
280
|
+
const V = [...F ?? [], at].reduce((C, $) => {
|
|
281
|
+
const W = `${$.stateKey}:${JSON.stringify($.path)}`, j = C.get(W);
|
|
282
|
+
return j ? (j.timeStamp = Math.max(j.timeStamp, $.timeStamp), j.newValue = $.newValue, j.oldValue = j.oldValue ?? $.oldValue, j.updateType = $.updateType) : C.set(W, { ...$ }), C;
|
|
285
283
|
}, /* @__PURE__ */ new Map());
|
|
286
284
|
return Array.from(V.values());
|
|
287
|
-
}),
|
|
285
|
+
}), Tt(
|
|
288
286
|
N,
|
|
289
287
|
g,
|
|
290
|
-
|
|
288
|
+
h.current,
|
|
291
289
|
T
|
|
292
290
|
), w && w({
|
|
293
291
|
updateLog: s,
|
|
294
292
|
update: at
|
|
295
|
-
}),
|
|
296
|
-
const F = r.getState().serverState[g],
|
|
297
|
-
|
|
298
|
-
syncKey: typeof
|
|
293
|
+
}), h.current?.serverSync) {
|
|
294
|
+
const F = r.getState().serverState[g], I = h.current?.serverSync;
|
|
295
|
+
xt(g, {
|
|
296
|
+
syncKey: typeof I.syncKey == "string" ? I.syncKey : I.syncKey({ state: N }),
|
|
299
297
|
rollBackState: F,
|
|
300
|
-
actionTimeStamp: Date.now() + (
|
|
298
|
+
actionTimeStamp: Date.now() + (I.debounce ?? 3e3),
|
|
301
299
|
status: "waiting"
|
|
302
300
|
});
|
|
303
301
|
}
|
|
@@ -319,12 +317,12 @@ function Ot(t, {
|
|
|
319
317
|
b.current,
|
|
320
318
|
T
|
|
321
319
|
), [g]);
|
|
322
|
-
return [
|
|
320
|
+
return [gt(g), a];
|
|
323
321
|
}
|
|
324
322
|
function Y(t, i, m, y) {
|
|
325
323
|
const u = /* @__PURE__ */ new Map();
|
|
326
324
|
let w = 0;
|
|
327
|
-
const
|
|
325
|
+
const _ = (f) => {
|
|
328
326
|
const e = f.join(".");
|
|
329
327
|
for (const [S] of u)
|
|
330
328
|
(S === e || S.startsWith(e + ".")) && u.delete(S);
|
|
@@ -338,7 +336,7 @@ function Y(t, i, m, y) {
|
|
|
338
336
|
e?.key && P(e?.key), f?.validationKey && P(f.validationKey);
|
|
339
337
|
const S = r.getState().initialStateGlobal[t];
|
|
340
338
|
r.getState().clearSelectedIndexesForState(t), u.clear(), w++;
|
|
341
|
-
const x =
|
|
339
|
+
const x = c(S, []), A = q(t), T = L(A?.localStorage?.key) ? A?.localStorage?.key(S) : A?.localStorage?.key, R = `${y}-${t}-${T}`;
|
|
342
340
|
R && localStorage.removeItem(R), H(t, x), D(t, S);
|
|
343
341
|
const g = r.getState().stateComponents.get(t);
|
|
344
342
|
return g && g.components.forEach((s) => {
|
|
@@ -368,10 +366,10 @@ function Y(t, i, m, y) {
|
|
|
368
366
|
_isLoading: r.getState().isLoadingGlobal[t],
|
|
369
367
|
_isServerSynced: () => {
|
|
370
368
|
const f = r.getState().serverState[t];
|
|
371
|
-
return !!(f && M(f,
|
|
369
|
+
return !!(f && M(f, gt(t)));
|
|
372
370
|
}
|
|
373
371
|
};
|
|
374
|
-
function
|
|
372
|
+
function c(f, e = [], S) {
|
|
375
373
|
const x = e.map(String).join(".");
|
|
376
374
|
u.get(x);
|
|
377
375
|
const A = function() {
|
|
@@ -388,27 +386,27 @@ function Y(t, i, m, y) {
|
|
|
388
386
|
},
|
|
389
387
|
get(g, s) {
|
|
390
388
|
if (s !== "then" && !s.startsWith("$") && s !== "stateMapNoRender") {
|
|
391
|
-
const n = e.join("."), a = `${t}////${m}`,
|
|
392
|
-
if (
|
|
393
|
-
const o =
|
|
389
|
+
const n = e.join("."), a = `${t}////${m}`, l = r.getState().stateComponents.get(t);
|
|
390
|
+
if (l) {
|
|
391
|
+
const o = l.components.get(a);
|
|
394
392
|
o && (e.length > 0 || s === "get") && o.paths.add(n);
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
395
|
if (s === "_status") {
|
|
398
|
-
const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t],
|
|
399
|
-
return M(n,
|
|
396
|
+
const n = r.getState().getNestedState(t, e), a = r.getState().initialStateGlobal[t], l = U(a, e);
|
|
397
|
+
return M(n, l) ? "fresh" : "stale";
|
|
400
398
|
}
|
|
401
399
|
if (s === "getStatus")
|
|
402
400
|
return function() {
|
|
403
401
|
const n = r().getNestedState(
|
|
404
402
|
t,
|
|
405
403
|
e
|
|
406
|
-
), a = r.getState().initialStateGlobal[t],
|
|
407
|
-
return M(n,
|
|
404
|
+
), a = r.getState().initialStateGlobal[t], l = U(a, e);
|
|
405
|
+
return M(n, l) ? "fresh" : "stale";
|
|
408
406
|
};
|
|
409
407
|
if (s === "removeStorage")
|
|
410
408
|
return () => {
|
|
411
|
-
const n = r.getState().initialStateGlobal[t], a = q(t),
|
|
409
|
+
const n = r.getState().initialStateGlobal[t], a = q(t), l = L(a?.localStorage?.key) ? a?.localStorage?.key(n) : a?.localStorage?.key, o = `${y}-${t}-${l}`;
|
|
412
410
|
console.log("removing storage", o), o && localStorage.removeItem(o);
|
|
413
411
|
};
|
|
414
412
|
if (s === "showValidationErrors")
|
|
@@ -423,7 +421,7 @@ function Y(t, i, m, y) {
|
|
|
423
421
|
return () => {
|
|
424
422
|
const n = r.getState().getSelectedIndex(t, e.join("."));
|
|
425
423
|
if (n !== void 0)
|
|
426
|
-
return
|
|
424
|
+
return c(
|
|
427
425
|
f[n],
|
|
428
426
|
[...e, n.toString()],
|
|
429
427
|
S
|
|
@@ -433,11 +431,11 @@ function Y(t, i, m, y) {
|
|
|
433
431
|
return () => r.getState().getSelectedIndex(t, e.join(".")) ?? -1;
|
|
434
432
|
if (s === "stateSort")
|
|
435
433
|
return (n) => {
|
|
436
|
-
const o = [...r.getState().getNestedState(t, e).map((d,
|
|
434
|
+
const o = [...r.getState().getNestedState(t, e).map((d, E) => ({
|
|
437
435
|
...d,
|
|
438
|
-
__origIndex:
|
|
436
|
+
__origIndex: E.toString()
|
|
439
437
|
}))].sort(n);
|
|
440
|
-
return u.clear(), w++,
|
|
438
|
+
return u.clear(), w++, c(o, e, {
|
|
441
439
|
filtered: [...S?.filtered || [], e],
|
|
442
440
|
validIndices: o.map(
|
|
443
441
|
(d) => parseInt(d.__origIndex)
|
|
@@ -448,42 +446,42 @@ function Y(t, i, m, y) {
|
|
|
448
446
|
return (n) => {
|
|
449
447
|
const a = S?.filtered?.some(
|
|
450
448
|
(o) => o.join(".") === e.join(".")
|
|
451
|
-
),
|
|
452
|
-
return s !== "stateMapNoRender" && (u.clear(), w++),
|
|
453
|
-
const
|
|
449
|
+
), l = a ? f : r.getState().getNestedState(t, e);
|
|
450
|
+
return s !== "stateMapNoRender" && (u.clear(), w++), l.map((o, d) => {
|
|
451
|
+
const E = a && o.__origIndex ? o.__origIndex : d, O = c(
|
|
454
452
|
o,
|
|
455
|
-
[...e,
|
|
453
|
+
[...e, E.toString()],
|
|
456
454
|
S
|
|
457
455
|
);
|
|
458
456
|
return n(
|
|
459
457
|
o,
|
|
460
|
-
|
|
458
|
+
O,
|
|
461
459
|
d,
|
|
462
460
|
f,
|
|
463
|
-
|
|
461
|
+
c(f, e, S)
|
|
464
462
|
);
|
|
465
463
|
});
|
|
466
464
|
};
|
|
467
465
|
if (s === "$stateMap")
|
|
468
|
-
return (n) => X(
|
|
466
|
+
return (n) => X(pt, {
|
|
469
467
|
proxy: {
|
|
470
468
|
_stateKey: t,
|
|
471
469
|
_path: e,
|
|
472
470
|
_mapFn: n
|
|
473
471
|
// Pass the actual function, not string
|
|
474
472
|
},
|
|
475
|
-
rebuildStateShape:
|
|
473
|
+
rebuildStateShape: c
|
|
476
474
|
});
|
|
477
475
|
if (s === "stateFlattenOn")
|
|
478
476
|
return (n) => {
|
|
479
|
-
const
|
|
477
|
+
const l = S?.filtered?.some(
|
|
480
478
|
(d) => d.join(".") === e.join(".")
|
|
481
479
|
) ? f : r.getState().getNestedState(t, e);
|
|
482
480
|
u.clear(), w++;
|
|
483
|
-
const o =
|
|
484
|
-
(d,
|
|
481
|
+
const o = l.flatMap(
|
|
482
|
+
(d, E) => d[n] ?? []
|
|
485
483
|
);
|
|
486
|
-
return
|
|
484
|
+
return c(
|
|
487
485
|
o,
|
|
488
486
|
[...e, "[*]", n],
|
|
489
487
|
S
|
|
@@ -491,48 +489,48 @@ function Y(t, i, m, y) {
|
|
|
491
489
|
};
|
|
492
490
|
if (s === "findWith")
|
|
493
491
|
return (n, a) => {
|
|
494
|
-
const
|
|
495
|
-
(
|
|
492
|
+
const l = f.findIndex(
|
|
493
|
+
(E) => E[n] === a
|
|
496
494
|
);
|
|
497
|
-
if (
|
|
498
|
-
const o = f[
|
|
499
|
-
return u.clear(), w++, u.clear(), w++,
|
|
495
|
+
if (l === -1) return;
|
|
496
|
+
const o = f[l], d = [...e, l.toString()];
|
|
497
|
+
return u.clear(), w++, u.clear(), w++, c(o, d);
|
|
500
498
|
};
|
|
501
499
|
if (s === "index")
|
|
502
500
|
return (n) => {
|
|
503
501
|
const a = f[n];
|
|
504
|
-
return
|
|
502
|
+
return c(a, [...e, n.toString()]);
|
|
505
503
|
};
|
|
506
504
|
if (s === "insert")
|
|
507
|
-
return (n) => (
|
|
505
|
+
return (n) => (_(e), Q(i, n, e, t), c(
|
|
508
506
|
r.getState().cogsStateStore[t],
|
|
509
507
|
[]
|
|
510
508
|
));
|
|
511
509
|
if (s === "uniqueInsert")
|
|
512
|
-
return (n, a,
|
|
510
|
+
return (n, a, l) => {
|
|
513
511
|
const o = r.getState().getNestedState(t, e), d = L(n) ? n(o) : n;
|
|
514
|
-
let
|
|
512
|
+
let E = null;
|
|
515
513
|
if (!o.some((N) => {
|
|
516
514
|
if (a) {
|
|
517
|
-
const
|
|
515
|
+
const k = a.every(
|
|
518
516
|
(z) => M(N[z], d[z])
|
|
519
517
|
);
|
|
520
|
-
return
|
|
518
|
+
return k && (E = N), k;
|
|
521
519
|
}
|
|
522
|
-
const
|
|
523
|
-
return
|
|
520
|
+
const p = M(N, d);
|
|
521
|
+
return p && (E = N), p;
|
|
524
522
|
}))
|
|
525
|
-
|
|
526
|
-
else if (
|
|
527
|
-
const N =
|
|
528
|
-
(
|
|
523
|
+
_(e), Q(i, d, e, t);
|
|
524
|
+
else if (l && E) {
|
|
525
|
+
const N = l(E), p = o.map(
|
|
526
|
+
(k) => M(k, E) ? N : k
|
|
529
527
|
);
|
|
530
|
-
|
|
528
|
+
_(e), B(i, p, e);
|
|
531
529
|
}
|
|
532
530
|
};
|
|
533
531
|
if (s === "cut")
|
|
534
532
|
return (n, a) => {
|
|
535
|
-
a?.waitForSync || (
|
|
533
|
+
a?.waitForSync || (_(e), J(i, e, t, n));
|
|
536
534
|
};
|
|
537
535
|
if (s === "cutByValue")
|
|
538
536
|
return (n) => {
|
|
@@ -541,20 +539,20 @@ function Y(t, i, m, y) {
|
|
|
541
539
|
};
|
|
542
540
|
if (s === "toggleByValue")
|
|
543
541
|
return (n) => {
|
|
544
|
-
const a = f.findIndex((
|
|
542
|
+
const a = f.findIndex((l) => l === n);
|
|
545
543
|
a > -1 ? J(i, e, t, a) : Q(i, n, e, t);
|
|
546
544
|
};
|
|
547
545
|
if (s === "stateFilter")
|
|
548
546
|
return (n) => {
|
|
549
|
-
const a = f.map((d,
|
|
547
|
+
const a = f.map((d, E) => ({
|
|
550
548
|
...d,
|
|
551
|
-
__origIndex:
|
|
552
|
-
})),
|
|
549
|
+
__origIndex: E.toString()
|
|
550
|
+
})), l = [], o = [];
|
|
553
551
|
for (let d = 0; d < a.length; d++)
|
|
554
|
-
n(a[d], d) && (
|
|
555
|
-
return u.clear(), w++,
|
|
552
|
+
n(a[d], d) && (l.push(d), o.push(a[d]));
|
|
553
|
+
return u.clear(), w++, c(o, e, {
|
|
556
554
|
filtered: [...S?.filtered || [], e],
|
|
557
|
-
validIndices:
|
|
555
|
+
validIndices: l
|
|
558
556
|
// Always pass validIndices, even if empty
|
|
559
557
|
});
|
|
560
558
|
};
|
|
@@ -594,17 +592,17 @@ function Y(t, i, m, y) {
|
|
|
594
592
|
return r.getState().getSyncInfo(n);
|
|
595
593
|
}
|
|
596
594
|
if (s == "getLocalStorage")
|
|
597
|
-
return (n) =>
|
|
595
|
+
return (n) => ut(y + "-" + t + "-" + n);
|
|
598
596
|
if (s === "_selected") {
|
|
599
|
-
const n = e.slice(0, -1), a = n.join("."),
|
|
600
|
-
return Array.isArray(
|
|
597
|
+
const n = e.slice(0, -1), a = n.join("."), l = r.getState().getNestedState(t, n);
|
|
598
|
+
return Array.isArray(l) ? Number(e[e.length - 1]) === r.getState().getSelectedIndex(t, a) : void 0;
|
|
601
599
|
}
|
|
602
600
|
if (s === "setSelected")
|
|
603
601
|
return (n) => {
|
|
604
|
-
const a = e.slice(0, -1),
|
|
605
|
-
n ? r.getState().setSelectedIndex(t, o,
|
|
602
|
+
const a = e.slice(0, -1), l = Number(e[e.length - 1]), o = a.join(".");
|
|
603
|
+
n ? r.getState().setSelectedIndex(t, o, l) : r.getState().setSelectedIndex(t, o, void 0);
|
|
606
604
|
const d = r.getState().getNestedState(t, [...a]);
|
|
607
|
-
B(i, d, a),
|
|
605
|
+
B(i, d, a), _(a);
|
|
608
606
|
};
|
|
609
607
|
if (e.length == 0) {
|
|
610
608
|
if (s === "validateZodSchema")
|
|
@@ -615,16 +613,16 @@ function Y(t, i, m, y) {
|
|
|
615
613
|
if (!n?.key)
|
|
616
614
|
throw new Error("Validation key not found");
|
|
617
615
|
P(n.key);
|
|
618
|
-
const
|
|
616
|
+
const l = r.getState().cogsStateStore[t];
|
|
619
617
|
try {
|
|
620
618
|
const o = r.getState().getValidationErrors(n.key);
|
|
621
|
-
o && o.length > 0 && o.forEach(([
|
|
622
|
-
|
|
619
|
+
o && o.length > 0 && o.forEach(([E]) => {
|
|
620
|
+
E && E.startsWith(n.key) && P(E);
|
|
623
621
|
});
|
|
624
|
-
const d = n.zodSchema.safeParse(
|
|
625
|
-
return d.success ? !0 : (d.error.errors.forEach((
|
|
626
|
-
const N =
|
|
627
|
-
a(
|
|
622
|
+
const d = n.zodSchema.safeParse(l);
|
|
623
|
+
return d.success ? !0 : (d.error.errors.forEach((O) => {
|
|
624
|
+
const N = O.path, p = O.message, k = [n.key, ...N].join(".");
|
|
625
|
+
a(k, p);
|
|
628
626
|
}), ft(t), !1);
|
|
629
627
|
} catch (o) {
|
|
630
628
|
return console.error("Zod schema validation failed", o), !1;
|
|
@@ -671,15 +669,15 @@ function Y(t, i, m, y) {
|
|
|
671
669
|
if (a?.debounce)
|
|
672
670
|
$t(() => {
|
|
673
671
|
B(i, n, e, "");
|
|
674
|
-
const
|
|
675
|
-
a?.afterUpdate && a.afterUpdate(
|
|
672
|
+
const l = r.getState().getNestedState(t, e);
|
|
673
|
+
a?.afterUpdate && a.afterUpdate(l);
|
|
676
674
|
}, a.debounce);
|
|
677
675
|
else {
|
|
678
676
|
B(i, n, e, "");
|
|
679
|
-
const
|
|
680
|
-
a?.afterUpdate && a.afterUpdate(
|
|
677
|
+
const l = r.getState().getNestedState(t, e);
|
|
678
|
+
a?.afterUpdate && a.afterUpdate(l);
|
|
681
679
|
}
|
|
682
|
-
|
|
680
|
+
_(e);
|
|
683
681
|
};
|
|
684
682
|
if (s === "formElement")
|
|
685
683
|
return (n, a) => /* @__PURE__ */ st(
|
|
@@ -692,8 +690,8 @@ function Y(t, i, m, y) {
|
|
|
692
690
|
formOpts: a
|
|
693
691
|
}
|
|
694
692
|
);
|
|
695
|
-
const b = [...e, s],
|
|
696
|
-
return
|
|
693
|
+
const b = [...e, s], h = r.getState().getNestedState(t, b);
|
|
694
|
+
return c(h, b, S);
|
|
697
695
|
}
|
|
698
696
|
}, R = new Proxy(A, T);
|
|
699
697
|
return u.set(x, {
|
|
@@ -701,14 +699,14 @@ function Y(t, i, m, y) {
|
|
|
701
699
|
stateVersion: w
|
|
702
700
|
}), R;
|
|
703
701
|
}
|
|
704
|
-
return
|
|
702
|
+
return c(
|
|
705
703
|
r.getState().getNestedState(t, [])
|
|
706
704
|
);
|
|
707
705
|
}
|
|
708
706
|
function K(t) {
|
|
709
707
|
return X(bt, { proxy: t });
|
|
710
708
|
}
|
|
711
|
-
function
|
|
709
|
+
function pt({
|
|
712
710
|
proxy: t,
|
|
713
711
|
rebuildStateShape: i
|
|
714
712
|
}) {
|
|
@@ -717,7 +715,7 @@ function jt({
|
|
|
717
715
|
m,
|
|
718
716
|
t._path
|
|
719
717
|
).stateMapNoRender(
|
|
720
|
-
(u, w,
|
|
718
|
+
(u, w, _, v, c) => t._mapFn(u, w, _, v, c)
|
|
721
719
|
) : null;
|
|
722
720
|
}
|
|
723
721
|
function bt({
|
|
@@ -727,13 +725,13 @@ function bt({
|
|
|
727
725
|
return et(() => {
|
|
728
726
|
const y = i.current;
|
|
729
727
|
if (!y || !y.parentElement) return;
|
|
730
|
-
const u = y.parentElement,
|
|
728
|
+
const u = y.parentElement, _ = Array.from(u.childNodes).indexOf(y);
|
|
731
729
|
let v = u.getAttribute("data-parent-id");
|
|
732
730
|
v || (v = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", v));
|
|
733
731
|
const f = {
|
|
734
732
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
735
733
|
parentId: v,
|
|
736
|
-
position:
|
|
734
|
+
position: _,
|
|
737
735
|
effect: t._effect
|
|
738
736
|
};
|
|
739
737
|
r.getState().addSignalElement(m, f);
|
|
@@ -780,6 +778,6 @@ export {
|
|
|
780
778
|
qt as addStateOptions,
|
|
781
779
|
zt as createCogsState,
|
|
782
780
|
Bt as notifyComponent,
|
|
783
|
-
|
|
781
|
+
jt as useCogsStateFn
|
|
784
782
|
};
|
|
785
783
|
//# sourceMappingURL=CogsState.jsx.map
|